@itwin/build-tools 4.0.0-dev.10 → 4.0.0-dev.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,60 @@
1
1
  # Change Log - @itwin/build-tools
2
2
 
3
- This log was last generated on Thu, 26 Jan 2023 22:53:27 GMT and should not be manually modified.
3
+ This log was last generated on Tue, 25 Apr 2023 17:50:35 GMT and should not be manually modified.
4
+
5
+ ## 3.7.4
6
+ Tue, 25 Apr 2023 17:50:35 GMT
7
+
8
+ _Version update only_
9
+
10
+ ## 3.7.3
11
+ Thu, 20 Apr 2023 13:19:28 GMT
12
+
13
+ _Version update only_
14
+
15
+ ## 3.7.2
16
+ Wed, 12 Apr 2023 13:12:42 GMT
17
+
18
+ _Version update only_
19
+
20
+ ## 3.7.1
21
+ Mon, 03 Apr 2023 15:15:36 GMT
22
+
23
+ _Version update only_
24
+
25
+ ## 3.7.0
26
+ Wed, 29 Mar 2023 15:02:27 GMT
27
+
28
+ _Version update only_
29
+
30
+ ## 3.6.3
31
+ Mon, 27 Mar 2023 16:26:47 GMT
32
+
33
+ _Version update only_
34
+
35
+ ## 3.6.2
36
+ Fri, 17 Mar 2023 17:52:32 GMT
37
+
38
+ _Version update only_
39
+
40
+ ## 3.6.1
41
+ Fri, 24 Feb 2023 22:00:48 GMT
42
+
43
+ _Version update only_
44
+
45
+ ## 3.6.0
46
+ Wed, 08 Feb 2023 14:58:39 GMT
47
+
48
+ ### Updates
49
+
50
+ - Fix script paths for situation when repository path has spaces
51
+ - add copy-assets script to betools command
52
+ - Added ability to override default exclude pattern for tests when generating docs
53
+
54
+ ## 3.5.6
55
+ Fri, 24 Feb 2023 16:02:47 GMT
56
+
57
+ _Version update only_
4
58
 
5
59
  ## 3.5.5
6
60
  Thu, 26 Jan 2023 22:53:27 GMT
package/bin/betools.js CHANGED
@@ -71,7 +71,7 @@ yargs.strict(true)
71
71
  })
72
72
  },
73
73
  (argv) => { extractCommand(argv) })
74
- .command("extract-api", "Extracts the API of the Typescript library starting from an entry file with a default presets. Powered by @microsoft/api-extractor (https://api-extractor.com)",
74
+ .command("extract-api", "Extracts the API of the Typescript library starting from an entry file with a default presets. Powered by @microsoft/api-extractor (https://api-extractor.com)",
75
75
  function (yargs) {
76
76
  return yargs.options({
77
77
  "entry": {
@@ -79,6 +79,15 @@ yargs.strict(true)
79
79
  },
80
80
  "ignoreMissingTags": {
81
81
  describe: "Turns off the 'ae-missing-release-tag' option which returns an error when a missing release tag is detected"
82
+ },
83
+ "apiReportFolder": {
84
+ describe: "Directory for the API report. Defaults to `<Rush repository root>/common/api`."
85
+ },
86
+ "apiReportTempFolder": {
87
+ describe: "Directory for the API report. Defaults to `<Rush repository root>/temp/api`."
88
+ },
89
+ "apiSummaryFolder": {
90
+ describe: "Directory for the API summary. Defaults to `<Rush repository root>/common/api/summary`."
82
91
  }
83
92
  })
84
93
  },
@@ -149,7 +158,10 @@ function extractCommand(options) {
149
158
  function extractApiCommand(options) {
150
159
  const entryOpt = options.entry ? ["--entry", options.entry] : [];
151
160
  const ignoreTagsOpt = options.ignoreMissingTags ? ["--ignoreMissingTags"] : [];
152
- exec(["node", getScriptPath("extract-api.js"), ...entryOpt, ...ignoreTagsOpt]);
161
+ const apiReportFolderOpt = options.apiReportFolder ? ["--apiReportFolder", options.apiReportFolder] : [];
162
+ const apiReportTempFolderOpt = options.apiReportTempFolder ? ["--apiReportTempFolder", options.apiReportTempFolder] : [];
163
+ const apiSummaryFolderOpt = options.apiSummaryFolder ? ["--apiSummaryFolder", options.apiSummaryFolder] : [];
164
+ exec(["node", getScriptPath("extract-api.js"), ...entryOpt, ...ignoreTagsOpt, ...apiReportFolderOpt, ...apiReportTempFolderOpt, ...apiSummaryFolderOpt]);
153
165
  }
154
166
 
155
167
  function pseudolocalizeCommand(options) {
@@ -1,97 +1,96 @@
1
- "use strict";
2
- var _a, _b;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- /*---------------------------------------------------------------------------------------------
5
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
- * See LICENSE.md in the project root for license terms and full copyright notice.
7
- *--------------------------------------------------------------------------------------------*/
8
- /* eslint-disable @typescript-eslint/naming-convention */
9
- /* eslint-disable @typescript-eslint/no-var-requires */
10
- /* eslint-disable no-console */
11
- const debugLeaks = process.env.DEBUG_LEAKS;
12
- if (debugLeaks)
13
- require("wtfnode");
14
- const path = require("path");
15
- const fs = require("fs-extra");
16
- const { logBuildWarning, logBuildError, failBuild } = require("../scripts/utils/utils");
17
- const Base = require("mocha/lib/reporters/base");
18
- const Spec = require("mocha/lib/reporters/spec");
19
- const MochaJUnitReporter = require("mocha-junit-reporter");
20
- function withStdErr(callback) {
21
- const originalConsoleLog = Base.consoleLog;
22
- Base.consoleLog = console.error;
23
- callback();
24
- Base.consoleLog = originalConsoleLog;
25
- }
26
- const isCI = process.env.CI || process.env.TF_BUILD;
27
- // Force rush test to fail CI builds if describe.only or it.only is used.
28
- // These should only be used for debugging and must not be committed, otherwise we may be accidentally skipping lots of tests.
29
- if (isCI) {
30
- if (typeof (mocha) !== "undefined")
31
- mocha.forbidOnly();
32
- else
33
- require.cache[require.resolve("mocha/lib/mocharc.json", { paths: (_b = (_a = require.main) === null || _a === void 0 ? void 0 : _a.paths) !== null && _b !== void 0 ? _b : module.paths })].exports.forbidOnly = true;
34
- }
35
- // This is necessary to enable colored output when running in rush test:
36
- Object.defineProperty(Base, "color", {
37
- get: () => process.env.FORCE_COLOR !== "false" && process.env.FORCE_COLOR !== "0",
38
- set: () => { },
39
- });
40
- class BentleyMochaReporter extends Spec {
41
- constructor(_runner, _options) {
42
- super(...arguments);
43
- this._junitReporter = new MochaJUnitReporter(...arguments);
44
- }
45
- epilogue(...args) {
46
- // Force test errors to be printed to stderr instead of stdout.
47
- // This will allow rush to correctly summarize test failure when running rush test.
48
- if (this.stats.failures) {
49
- withStdErr(() => super.epilogue(...args));
50
- }
51
- else {
52
- super.epilogue(...args);
53
- if (0 === this.stats.passes) {
54
- logBuildError("There were 0 passing tests. That doesn't seem right."
55
- + "\nIf there are really no passing tests and no failures, then what was even the point?"
56
- + "\nIt seems likely that tests were skipped by it.only, it.skip, or grep filters, so I'm going to fail now.");
57
- failBuild();
58
- }
59
- }
60
- // Detect hangs caused by tests that leave timers/other handles open - not possible in electron frontends.
61
- if (!("electron" in process.versions)) {
62
- // NB: By calling unref() on this timer, we stop it from keeping the process alive, so it will only fire if _something else_ is still keeping
63
- // the process alive after 5 seconds. This also has the benefit of preventing the timer from showing up in wtfnode's dump of open handles.
64
- setTimeout(() => {
65
- logBuildError(`Handle leak detected. Node was still running 5 seconds after tests completed.`);
66
- if (debugLeaks) {
67
- const wtf = require("wtfnode");
68
- wtf.setLogger("info", console.error);
69
- wtf.dump();
70
- }
71
- else {
72
- console.error("Try running with the DEBUG_LEAKS env var set to see open handles.");
73
- }
74
- // Not sure why, but process.exit(1) wasn't working here...
75
- process.kill(process.pid);
76
- }, 5000).unref();
77
- }
78
- if (!this.stats.pending)
79
- return;
80
- // Also log warnings in CI builds when tests have been skipped.
81
- const currentPkgJson = path.join(process.cwd(), "package.json");
82
- if (fs.existsSync(currentPkgJson)) {
83
- const currentPackage = require(currentPkgJson).name;
84
- if (this.stats.pending === 1)
85
- logBuildWarning(`1 test skipped in ${currentPackage}`);
86
- else
87
- logBuildWarning(`${this.stats.pending} tests skipped in ${currentPackage}`);
88
- }
89
- else {
90
- if (this.stats.pending === 1)
91
- logBuildWarning(`1 test skipped`);
92
- else
93
- logBuildWarning(`${this.stats.pending} tests skipped`);
94
- }
95
- }
96
- }
97
- module.exports = BentleyMochaReporter;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*---------------------------------------------------------------------------------------------
4
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
5
+ * See LICENSE.md in the project root for license terms and full copyright notice.
6
+ *--------------------------------------------------------------------------------------------*/
7
+ /* eslint-disable @typescript-eslint/naming-convention */
8
+ /* eslint-disable @typescript-eslint/no-var-requires */
9
+ /* eslint-disable no-console */
10
+ const debugLeaks = process.env.DEBUG_LEAKS;
11
+ if (debugLeaks)
12
+ require("wtfnode");
13
+ const path = require("path");
14
+ const fs = require("fs-extra");
15
+ const { logBuildWarning, logBuildError, failBuild } = require("../scripts/utils/utils");
16
+ const Base = require("mocha/lib/reporters/base");
17
+ const Spec = require("mocha/lib/reporters/spec");
18
+ const MochaJUnitReporter = require("mocha-junit-reporter");
19
+ function withStdErr(callback) {
20
+ const originalConsoleLog = Base.consoleLog;
21
+ Base.consoleLog = console.error;
22
+ callback();
23
+ Base.consoleLog = originalConsoleLog;
24
+ }
25
+ const isCI = process.env.CI || process.env.TF_BUILD;
26
+ // Force rush test to fail CI builds if describe.only or it.only is used.
27
+ // These should only be used for debugging and must not be committed, otherwise we may be accidentally skipping lots of tests.
28
+ if (isCI) {
29
+ if (typeof (mocha) !== "undefined")
30
+ mocha.forbidOnly();
31
+ else
32
+ require.cache[require.resolve("mocha/lib/mocharc.json", { paths: require.main?.paths ?? module.paths })].exports.forbidOnly = true;
33
+ }
34
+ // This is necessary to enable colored output when running in rush test:
35
+ Object.defineProperty(Base, "color", {
36
+ get: () => process.env.FORCE_COLOR !== "false" && process.env.FORCE_COLOR !== "0",
37
+ set: () => { },
38
+ });
39
+ class BentleyMochaReporter extends Spec {
40
+ constructor(_runner, _options) {
41
+ super(...arguments);
42
+ this._junitReporter = new MochaJUnitReporter(...arguments);
43
+ }
44
+ epilogue(...args) {
45
+ // Force test errors to be printed to stderr instead of stdout.
46
+ // This will allow rush to correctly summarize test failure when running rush test.
47
+ if (this.stats.failures) {
48
+ withStdErr(() => super.epilogue(...args));
49
+ }
50
+ else {
51
+ super.epilogue(...args);
52
+ if (0 === this.stats.passes) {
53
+ logBuildError("There were 0 passing tests. That doesn't seem right."
54
+ + "\nIf there are really no passing tests and no failures, then what was even the point?"
55
+ + "\nIt seems likely that tests were skipped by it.only, it.skip, or grep filters, so I'm going to fail now.");
56
+ failBuild();
57
+ }
58
+ }
59
+ // Detect hangs caused by tests that leave timers/other handles open - not possible in electron frontends.
60
+ if (!("electron" in process.versions)) {
61
+ // NB: By calling unref() on this timer, we stop it from keeping the process alive, so it will only fire if _something else_ is still keeping
62
+ // the process alive after 5 seconds. This also has the benefit of preventing the timer from showing up in wtfnode's dump of open handles.
63
+ setTimeout(() => {
64
+ logBuildError(`Handle leak detected. Node was still running 5 seconds after tests completed.`);
65
+ if (debugLeaks) {
66
+ const wtf = require("wtfnode");
67
+ wtf.setLogger("info", console.error);
68
+ wtf.dump();
69
+ }
70
+ else {
71
+ console.error("Try running with the DEBUG_LEAKS env var set to see open handles.");
72
+ }
73
+ // Not sure why, but process.exit(1) wasn't working here...
74
+ process.kill(process.pid);
75
+ }, 5000).unref();
76
+ }
77
+ if (!this.stats.pending)
78
+ return;
79
+ // Also log warnings in CI builds when tests have been skipped.
80
+ const currentPkgJson = path.join(process.cwd(), "package.json");
81
+ if (fs.existsSync(currentPkgJson)) {
82
+ const currentPackage = require(currentPkgJson).name;
83
+ if (this.stats.pending === 1)
84
+ logBuildWarning(`1 test skipped in ${currentPackage}`);
85
+ else
86
+ logBuildWarning(`${this.stats.pending} tests skipped in ${currentPackage}`);
87
+ }
88
+ else {
89
+ if (this.stats.pending === 1)
90
+ logBuildWarning(`1 test skipped`);
91
+ else
92
+ logBuildWarning(`${this.stats.pending} tests skipped`);
93
+ }
94
+ }
95
+ }
96
+ module.exports = BentleyMochaReporter;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@itwin/build-tools",
3
- "version": "4.0.0-dev.10",
3
+ "version": "4.0.0-dev.101",
4
4
  "description": "Bentley build tools",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/iTwin/itwinjs-core/tree/master/tools/build"
8
+ "url": "https://github.com/iTwin/itwinjs-core.git",
9
+ "directory": "tools/build"
9
10
  },
10
11
  "bin": {
11
12
  "betools": "bin/betools.js"
@@ -20,7 +21,7 @@
20
21
  "url": "http://www.bentley.com"
21
22
  },
22
23
  "dependencies": {
23
- "@microsoft/api-extractor": "7.23.2",
24
+ "@microsoft/api-extractor": "7.34.4",
24
25
  "chalk": "^3.0.0",
25
26
  "cpx2": "^3.0.0",
26
27
  "cross-spawn": "^7.0.1",
@@ -30,16 +31,16 @@
30
31
  "mocha-junit-reporter": "^2.0.2",
31
32
  "rimraf": "^3.0.2",
32
33
  "tree-kill": "^1.2.0",
33
- "typedoc": "^0.22.11",
34
- "typedoc-plugin-merge-modules": "^3.0.2",
35
- "typescript": "~4.4.0",
34
+ "typedoc": "^0.23.28",
35
+ "typedoc-plugin-merge-modules": "^4.0.1",
36
+ "typescript": "~5.0.2",
36
37
  "wtfnode": "^0.9.1",
37
38
  "yargs": "^17.4.0"
38
39
  },
39
40
  "devDependencies": {
40
- "@itwin/eslint-plugin": "4.0.0-dev.10",
41
- "@types/node": "18.11.5",
42
- "eslint": "^7.11.0"
41
+ "@itwin/eslint-plugin": "^4.0.0-dev.33",
42
+ "@types/node": "^18.11.5",
43
+ "eslint": "^8.36.0"
43
44
  },
44
45
  "eslintConfig": {
45
46
  "plugins": [
@@ -52,12 +53,10 @@
52
53
  },
53
54
  "scripts": {
54
55
  "build": "tsc 1>&2",
55
- "build:ci": "npm run -s build",
56
56
  "clean": "rimraf ../../modules .rush/temp/package-deps*.json",
57
57
  "docs": "",
58
58
  "lint": "eslint -f visualstudio --config package.json --no-eslintrc \"./src/**/*.ts\" 1>&2",
59
59
  "test": "",
60
60
  "cover": ""
61
- },
62
- "readme": "# @itwin/build-tools\r\n\r\nCopyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.\r\n\r\n## Description\r\n\r\nThe **@itwin/build-tools** is a package for developers to consolidate the steps for building TypeScript-based packages. The tools contained in this package are written in either Typescript or Javascript within the src/ directory, and compiled for use into the lib/ directory. As a developer package, this package has only dependencies, no devDependencies.\r\n\r\n### tsconfig-base\r\n\r\nLocation: tsconfig-base.json\\\r\nRequires build: no\r\n\r\nThis file contains common tsconfig settings across all iTwin.js packages. Packages should extend this file in their own tsconfig.json file, and then overwrite and set new properties as needed. Note that this file is different from the tsconfig.json file for this package, as that contains different settings for bentleyjs-tools only.\r\n\r\n### NPM Scripts\r\n\r\nLocation: scripts/\\\r\nRequires build: no\r\n\r\nThe following node scripts are delivered in this package's scripts folder in order to ease development of iTwin.js packages with npm scripts. These scripts may require that additional packages be installed as dependencies of your package.\r\n\r\nThe default behaviors of the scripts (without parameters) assume that the directory structure of your package mirrors the following:\r\n\r\n- root\r\n - source\r\n - test\r\n - assets\r\n - lib\r\n - package.json\r\n - tsconfig.json\r\n\r\nThe following is a list of some of the most commonly used scripts within this package:\r\n\r\n#### docs.js\r\n\r\nThis script runs a TypeDoc command, with specific parameters, to generate html TypeScript documentation as well as a json representation of the documentation to be consumed for other purposes. It includes the following parameters:\r\n\r\n- source - specify the TypeScript source directory\r\n- out - specify the directory of the html output\r\n- json - specify the directory and filename of the json output\r\n- baseUrl - specify a baseUrl to resolve modules\r\n- onlyJson - including this option will skip the html output and only output the json file\r\n- includes - directory of files to include in documentation (ex: for sample code)\r\n- excludes - name of directory, files, or file extensions to exclude.\r\n - A list can be provided using a `,` as a separator\r\n - Each of the provided to exclude is added to a glob pattern which checks all directories within the source.\r\n - i.e `--excludes=test,docs/*.md` will translate to `**/{test,docs/*.md}/**/*`\r\n\r\n#### extract.js\r\n\r\nThis is a script designed to extract sample code from test.ts files in a specific directory. The sample code should be surrounded by comments containing \"\\_\\_PUBLISH_EXTRACT_START\\_\\_\" and \"\\_\\_PUBLISH_EXTRACT_END\\_\\_\" directives.\r\n\r\n- extractDir - the path at which the sample code files are located\r\n- outDir - the path at which to output the selected code\r\n\r\n#### pseudolocalize.js\r\n\r\nThis script handles translating an English localization JSON file into a pseudoLocalization file.\r\n"
61
+ }
63
62
  }
package/scripts/docs.js CHANGED
@@ -12,7 +12,7 @@ const cpx = require("cpx2");
12
12
  const fs = require("fs");
13
13
  const { spawn, handleInterrupts } = require("./utils/simpleSpawn");
14
14
  const { validateTags } = require("./utils/validateTags");
15
- const { addSourceDir } = require("./utils/addSourceDir");
15
+ const { addPackageMetadata } = require("./utils/addPackageMetadata");
16
16
  const argv = require("yargs").argv;
17
17
 
18
18
  // Makes the script crash on unhandled rejections instead of silently
@@ -85,13 +85,14 @@ spawn(require.resolve(".bin/typedoc"), args).then((code) => {
85
85
  cpx.copySync(path.join(source, argv.tsIndexFile), outputDir);
86
86
  fs.renameSync(path.join(outputDir, argv.tsIndexFile), path.join(outputDir, 'index.ts'));
87
87
  }
88
+
88
89
  // Copy CHANGELOG.json to json output folder
89
90
  if (fs.existsSync(path.join(process.cwd(), 'CHANGELOG.json'))) {
90
91
  cpx.copySync(path.join(process.cwd(), 'CHANGELOG.json'), outputDir);
91
92
  }
92
93
 
93
- // Append the directory of the package to the output
94
- addSourceDir(json, process.cwd());
94
+ // Append the directory of the package, version and repository URL to the output
95
+ addPackageMetadata(json, process.cwd());
95
96
 
96
97
  if (code === 0) {
97
98
  let tagErrors = validateTags(json);
@@ -31,7 +31,16 @@ const resolveRoot = relativePath => {
31
31
  }
32
32
  process.stderr.write("Root of the Rush repository not found. Missing a rush.json file?");
33
33
  };
34
- const rushCommon = resolveRoot("common");
34
+ const rushCommon = () => {
35
+ let resolved;
36
+ if (!resolved)
37
+ resolved = resolveRoot("common");
38
+ return resolved;
39
+ };
40
+
41
+ const apiReportFolder = argv.apiReportFolder ?? path.join(rushCommon(), "/api");
42
+ const apiReportTempFolder = argv.apiReportTempFolder ?? path.join(rushCommon(), "/temp/api");
43
+ const apiSummaryFolder = argv.apiSummaryFolder ?? path.join(rushCommon(), "/api/summary");
35
44
 
36
45
  const config = {
37
46
  $schema: "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
@@ -42,8 +51,8 @@ const config = {
42
51
  mainEntryPointFilePath: `${entryPointFileName}.d.ts`,
43
52
  apiReport: {
44
53
  enabled: true,
45
- reportFolder: path.resolve(path.join(rushCommon, "/api")),
46
- reportTempFolder: path.resolve(path.join(rushCommon, "/temp/api")),
54
+ reportFolder: path.resolve(apiReportFolder),
55
+ reportTempFolder: path.resolve(apiReportTempFolder),
47
56
  },
48
57
  docModel: {
49
58
  enabled: false
@@ -94,7 +103,7 @@ const config = {
94
103
  };
95
104
 
96
105
  if (!fs.existsSync("lib")) {
97
- process.stderr.write("lib folder not found. Run `rush build` before extract-api");
106
+ process.stderr.write("`lib` folder not found. Build the package(s) before running `extract-api`");
98
107
  process.exit(1);
99
108
  }
100
109
 
@@ -118,8 +127,8 @@ spawn(require.resolve(".bin/api-extractor"), args).then((code) => {
118
127
 
119
128
  const extractSummaryArgs = [
120
129
  path.resolve(__dirname, "extract-api-summary.js"),
121
- "--apiSignature", path.resolve(path.join(rushCommon, `/api/${entryPointFileName}.api.md`)),
122
- "--outDir", path.resolve(path.join(rushCommon, "/api/summary")),
130
+ "--apiSignature", path.resolve(path.join(apiReportFolder, `${entryPointFileName}.api.md`)),
131
+ "--outDir", path.resolve(apiSummaryFolder),
123
132
  ];
124
133
 
125
134
  spawn("node", extractSummaryArgs).then((code) => {
@@ -0,0 +1,50 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+
6
+ const FS = require("fs-extra");
7
+ const path = require("path");
8
+
9
+ // We cannot guarantee the folder structure of a project
10
+ // so find the project root using rush env variable if available.
11
+ const rootPackageJson = process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER
12
+ ? path.join(process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER, "package.json")
13
+ : "../../../../package.json";
14
+
15
+ // Check if path to root package.json is valid.
16
+ const rootPackageJsonPath = require.resolve(rootPackageJson);
17
+
18
+ //Find the package.json of the project and retrieve the version and repository URL
19
+ const packageJsonPath = path.join(process.cwd(), "package.json");
20
+ const packageJson = JSON.parse(FS.readFileSync(packageJsonPath));
21
+ const version = packageJson.version;
22
+ const repositoryUrl = packageJson.repository?.url;
23
+ const repositoryDirectory = packageJson.repository?.directory;
24
+
25
+ if (!version || !repositoryUrl || !repositoryDirectory) {
26
+ throw new Error("version or repository info not found in package.json");
27
+ }
28
+
29
+ // Appends the directory of the package root to the Typedoc JSON output
30
+ function addPackageMetadata(file, directory) {
31
+ if (FS.existsSync(file) && FS.statSync(file).isFile()) {
32
+ const contents = FS.readFileSync(file, "utf-8");
33
+ const pathToRootFolder = path.dirname(rootPackageJsonPath);
34
+ const packageRoot = directory.substring(pathToRootFolder.length + 1);
35
+ const jsonContents = JSON.parse(contents);
36
+
37
+ jsonContents["packageRoot"] = packageRoot.endsWith("src")
38
+ ? packageRoot
39
+ : `${packageRoot}\\${"src"}`;
40
+ jsonContents["version"] = version;
41
+ jsonContents["repositoryUrl"] = repositoryUrl;
42
+ jsonContents["repositoryDirectory"] = repositoryDirectory;
43
+
44
+ FS.writeFileSync(file, Buffer.from(JSON.stringify(jsonContents, null, 2)));
45
+ }
46
+ }
47
+
48
+ module.exports = {
49
+ addPackageMetadata,
50
+ };
@@ -23,6 +23,6 @@
23
23
  "strict": true,
24
24
  "strictNullChecks": true,
25
25
  "stripInternal": false,
26
- "target": "ES2019"
26
+ "target": "ES2021"
27
27
  }
28
- }
28
+ }
@@ -1,39 +0,0 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
-
6
- const FS = require("fs-extra");
7
- const path = require("path");
8
-
9
- // We cannot guarantee the folder structure of a project
10
- // so find the project root using rush env variable if available.
11
- if (process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER) {
12
- rootPackageJsonPath = path.resolve(
13
- process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER,
14
- "package.json"
15
- );
16
- } else {
17
- rootPackageJsonPath = path.resolve("../../../../package.json");
18
- }
19
-
20
- const rootPackageJson = require(rootPackageJsonPath);
21
-
22
- // Appends the directory of the package root to the Typedoc JSON output
23
- function addSourceDir(file, directory) {
24
- if (FS.existsSync(file) && FS.statSync(file).isFile()) {
25
- const contents = FS.readFileSync(file, "utf-8");
26
- const packageRoot = directory.substring(
27
- directory.indexOf(rootPackageJson.name) + rootPackageJson.name.length + 1
28
- );
29
- const jsonContents = JSON.parse(contents);
30
- jsonContents["packageRoot"] = packageRoot.endsWith("src")
31
- ? packageRoot
32
- : `${packageRoot}\\${"src"}`;
33
- FS.writeFileSync(file, Buffer.from(JSON.stringify(jsonContents, null, 2)));
34
- }
35
- }
36
-
37
- module.exports = {
38
- addSourceDir,
39
- };