@itwin/build-tools 3.6.0-dev.36 → 3.6.0-dev.38
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/bin/betools.js +27 -1
- package/mocha-reporter/index.js +97 -97
- package/package.json +2 -2
- package/scripts/copy-assets.js +61 -0
- package/scripts/docs.js +2 -1
package/bin/betools.js
CHANGED
@@ -40,6 +40,9 @@ yargs.strict(true)
|
|
40
40
|
"excludeGlob": {
|
41
41
|
describe: "Specify a directory, filename, or pattern to be excluded"
|
42
42
|
},
|
43
|
+
"testExcludeGlob": {
|
44
|
+
describe: "Specify a directory, filename, or pattern to exclude tests. Default value: '**/*test*/**/*'"
|
45
|
+
},
|
43
46
|
"tsIndexFile": {
|
44
47
|
describe: "The barrel file containing the module documentation. This file is copied to the output folder for parsing."
|
45
48
|
},
|
@@ -92,6 +95,21 @@ yargs.strict(true)
|
|
92
95
|
})
|
93
96
|
},
|
94
97
|
(argv) => { pseudolocalizeCommand(argv) })
|
98
|
+
.command("copy-assets", "copy assets from @itwin or @bentley dependencies into a destination directory",
|
99
|
+
function (yargs) {
|
100
|
+
return yargs.options({
|
101
|
+
"packageJsonDir": {
|
102
|
+
describe: "The path at which the package.json listing deps that need their assets copied can be found. defaults to '.'"
|
103
|
+
},
|
104
|
+
"nodeModulesDir": {
|
105
|
+
describe: "The path to the node_modules directory where the deps that need their assets copied can be found. defaults to '.'"
|
106
|
+
},
|
107
|
+
"destinationDir": {
|
108
|
+
describe: "the location to copy the assets to. defaults to './lib/assets'"
|
109
|
+
},
|
110
|
+
})
|
111
|
+
},
|
112
|
+
(argv) => { copyAssetsCommand(argv) })
|
95
113
|
.help()
|
96
114
|
.argv;
|
97
115
|
|
@@ -112,11 +130,12 @@ function docsCommand(options) {
|
|
112
130
|
const includesOpt = options.includes ? ["--includes", options.includes] : [];
|
113
131
|
const excludesOpt = options.excludes ? ["--excludes", options.excludes] : [];
|
114
132
|
const excludesGlobOpt = options.excludeGlob ? ["--excludeGlob", options.excludeGlob] : [];
|
133
|
+
const testExcludeGlobOpt = options.testExcludeGlob ? ["--testExcludeGlob", options.testExcludeGlob] : [];
|
115
134
|
const indexFileOpt = options.tsIndexFile ? ["--tsIndexFile", options.tsIndexFile] : [];
|
116
135
|
const onlyJsonOpt = options.onlyJson ? ["--onlyJson"] : [];
|
117
136
|
exec(["node", getScriptPath("docs.js"),
|
118
137
|
...sourceOpt, ...outOpt, ...jsonOpt, ...baseUrlOpt, ...includesOpt,
|
119
|
-
...excludesOpt, ...excludesGlobOpt, ...indexFileOpt, ...onlyJsonOpt]);
|
138
|
+
...excludesOpt, ...excludesGlobOpt, ...testExcludeGlobOpt, ...indexFileOpt, ...onlyJsonOpt]);
|
120
139
|
}
|
121
140
|
|
122
141
|
function extractCommand(options) {
|
@@ -139,6 +158,13 @@ function pseudolocalizeCommand(options) {
|
|
139
158
|
exec(["node", getScriptPath("pseudolocalize"), ...englishDir, ...outOpt]);
|
140
159
|
}
|
141
160
|
|
161
|
+
function copyAssetsCommand(options) {
|
162
|
+
const packageJsonDir = options.packageJsonDir ? ["--packageJsonDir", options.packageJsonDir] : [];
|
163
|
+
const nodeModulesDir = options.nodeModulesDir ? ["--nodeModulesDir", options.nodeModulesDir] : [];
|
164
|
+
const destinationDir = options.destinationDir ? ["--destinationDir", options.destinationDir] : [];
|
165
|
+
exec(["node", path.resolve(__dirname, "../scripts/copy-assets.js"), ...packageJsonDir, ...nodeModulesDir, ...destinationDir]);
|
166
|
+
}
|
167
|
+
|
142
168
|
function exec(cmd) {
|
143
169
|
console.log("Running command:");
|
144
170
|
console.log(cmd.join(" "));
|
package/mocha-reporter/index.js
CHANGED
@@ -1,97 +1,97 @@
|
|
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
|
+
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;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@itwin/build-tools",
|
3
|
-
"version": "3.6.0-dev.
|
3
|
+
"version": "3.6.0-dev.38",
|
4
4
|
"description": "Bentley build tools",
|
5
5
|
"license": "MIT",
|
6
6
|
"repository": {
|
@@ -37,7 +37,7 @@
|
|
37
37
|
"yargs": "^17.4.0"
|
38
38
|
},
|
39
39
|
"devDependencies": {
|
40
|
-
"@itwin/eslint-plugin": "3.6.0-dev.
|
40
|
+
"@itwin/eslint-plugin": "3.6.0-dev.38",
|
41
41
|
"@types/node": "18.11.5",
|
42
42
|
"eslint": "^7.11.0"
|
43
43
|
},
|
@@ -0,0 +1,61 @@
|
|
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
|
+
"use strict"
|
7
|
+
|
8
|
+
const argv = require("yargs").argv;
|
9
|
+
const fs = require("fs-extra");
|
10
|
+
const path = require("path");
|
11
|
+
|
12
|
+
// example usage
|
13
|
+
// betools copy-assets --nodeModulesDir=../../../../
|
14
|
+
|
15
|
+
const packageJsonDir = argv.packageJsonDir ?? ".";
|
16
|
+
const nodeModulesDir = argv.nodeModulesDir ?? ".";
|
17
|
+
const destinationDir = argv.destinationDir ?? "./lib/assets";
|
18
|
+
|
19
|
+
// find all dependencies that should have their assets copied from
|
20
|
+
// currently this logic will find only packages with the @itwin or @bentley scope
|
21
|
+
const getBentleyPackageDeps = () => {
|
22
|
+
const packageJsonPath = `${packageJsonDir}/package.json`;
|
23
|
+
const packageJsonRaw = fs.readFileSync(packageJsonPath);
|
24
|
+
const packageJson = JSON.parse(packageJsonRaw);
|
25
|
+
const deps = new Set();
|
26
|
+
|
27
|
+
for (const packageName in packageJson.dependencies) {
|
28
|
+
if (packageName.includes("@itwin") || packageName.includes("@bentley")) {
|
29
|
+
deps.add(packageName);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
return Array.from(deps);
|
34
|
+
}
|
35
|
+
|
36
|
+
const copySync = (fromPath, toPath) => {
|
37
|
+
if (fs.existsSync(fromPath)) {
|
38
|
+
try {
|
39
|
+
fs.copySync(fromPath, toPath);
|
40
|
+
console.log(`successfully copied from ${fromPath} to ${toPath}`)
|
41
|
+
} catch (ex) {
|
42
|
+
console.error(`failed to copy from ${fromPath} to ${toPath}`, ex);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
// finds all applicable dependences with assets and copies them into the destination folder
|
48
|
+
const copyBentleyPackageDepAssets = () => {
|
49
|
+
if (!fs.existsSync(destinationDir)) {
|
50
|
+
fs.mkdirSync(destinationDir, { recursive: true });
|
51
|
+
}
|
52
|
+
|
53
|
+
// check for assets found in lib as well as lib/cjs
|
54
|
+
for (const target of getBentleyPackageDeps()) {
|
55
|
+
copySync(path.join(nodeModulesDir, "node_modules", target, "lib/assets"), destinationDir);
|
56
|
+
copySync(path.join(nodeModulesDir, "node_modules", target, "lib/cjs/assets"), destinationDir);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
copyBentleyPackageDepAssets();
|
61
|
+
console.log("finished copying assets");
|
package/scripts/docs.js
CHANGED
@@ -29,7 +29,8 @@ const json = (argv.json === undefined) ? paths.appJsonDocs : argv.json;
|
|
29
29
|
const baseUrlOptions = (argv.baseUrl === undefined) ? [] : ["--baseUrl", argv.baseUrl];
|
30
30
|
const includeOptions = (argv.includes === undefined) ? [] : ["--includes", argv.includes];
|
31
31
|
|
32
|
-
|
32
|
+
const testExclude = argv.testExcludeGlob ?? "**/*test*/**/*";
|
33
|
+
let excludeList = `**/node_modules/**/*,${testExclude}`;
|
33
34
|
if (argv.excludes !== undefined)
|
34
35
|
excludeList += ",**/" + argv.excludes + "/**/*";
|
35
36
|
if (argv.excludeGlob !== undefined)
|