-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckInternal.js
43 lines (35 loc) · 1.87 KB
/
checkInternal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/**
* Purpose of this script is to detect @internal APIs exposed through the barrel file of the given package.
* That's a problem because:
* - @internal APIs may expose dependencies that don't need to be specified as peer dependencies, making it difficult
* to identify whether a specific import should be a peer dependency or not.
* - Consumers import contents of our package through the barrel file. Including @internal APIs there causes consumers
* to see those APIs as available for them to use.
*/
"use strict";
const fs = require("fs");
const path = require("path");
const yargs = require("yargs");
const argv = yargs(process.argv).argv;
const apiSummaryPath = argv.apiSummary;
if (!apiSummaryPath) {
console.error(`Fail! Please specify the "apiSummary" argument as a path to the API summary file to check.`);
process.exit(1);
}
if (!fs.existsSync(apiSummaryPath)) {
console.error(`Fail! Provided API summary file path does not exist: "${apiSummaryPath}".`);
process.exit(1);
}
// only look for non-indented tags which target root level APIs - we still want to allow things
// like @internal class functions and interface attributes
const content = fs.readFileSync(apiSummaryPath, { encoding: "utf8" });
if (content.includes("@internal")) {
console.error("Fail! Detected exposed @internal APIs.");
console.error("Please make sure they're not exported through barrel file and re-generate API summary.");
process.exit(1);
}
console.log(`OK! API summary "${path.basename(apiSummaryPath)}" does not contain root level @internal APIs.`);