Skip to content

Commit 210de32

Browse files
committed
Merge branch 'master' into typesVersions
2 parents 5f6a2cb + 838110a commit 210de32

39 files changed

+11361
-10418
lines changed

Gulpfile.js

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const exec = require("./scripts/build/exec");
2626
const browserify = require("./scripts/build/browserify");
2727
const prepend = require("./scripts/build/prepend");
2828
const { removeSourceMaps } = require("./scripts/build/sourcemaps");
29-
const { CancellationTokenSource, CancelError, delay, Semaphore } = require("prex");
29+
const { CancellationTokenSource, CancelError, delay, Semaphore } = require("prex");
3030
const { libraryTargets, generateLibs } = require("./scripts/build/lib");
3131
const { runConsoleTests, cleanTestDirs, writeTestConfigFile, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } = require("./scripts/build/tests");
3232

@@ -533,34 +533,39 @@ gulp.task(
533533
["watch-diagnostics", "watch-lib"].concat(useCompilerDeps),
534534
() => project.watch(tsserverProject, { typescript: useCompiler }));
535535

536-
gulp.task(
537-
"watch-local",
538-
/*help*/ false,
539-
["watch-lib", "watch-tsc", "watch-services", "watch-server"]);
540-
541536
gulp.task(
542537
"watch-runner",
543538
/*help*/ false,
544539
useCompilerDeps,
545540
() => project.watch(testRunnerProject, { typescript: useCompiler }));
546541

547-
const watchPatterns = [
548-
runJs,
549-
typescriptDts,
550-
tsserverlibraryDts
551-
];
542+
gulp.task(
543+
"watch-local",
544+
"Watches for changes to projects in src/ (but does not execute tests).",
545+
["watch-lib", "watch-tsc", "watch-services", "watch-server", "watch-runner", "watch-lssl"]);
552546

553547
gulp.task(
554548
"watch",
555-
"Watches for changes to the build inputs for built/local/run.js, then executes runtests-parallel.",
549+
"Watches for changes to the build inputs for built/local/run.js, then runs tests.",
556550
["build-rules", "watch-runner", "watch-services", "watch-lssl"],
557551
() => {
558-
const runTestsSemaphore = new Semaphore(1);
559-
const fn = async () => {
552+
const sem = new Semaphore(1);
553+
554+
gulp.watch([runJs, typescriptDts, tsserverlibraryDts], () => {
555+
runTests();
556+
});
557+
558+
// NOTE: gulp.watch is far too slow when watching tests/cases/**/* as it first enumerates *every* file
559+
const testFilePattern = /(\.ts|[\\/]tsconfig\.json)$/;
560+
fs.watch("tests/cases", { recursive: true }, (_, file) => {
561+
if (testFilePattern.test(file)) runTests();
562+
});
563+
564+
async function runTests() {
560565
try {
561566
// Ensure only one instance of the test runner is running at any given time.
562-
if (runTestsSemaphore.count > 0) {
563-
await runTestsSemaphore.wait();
567+
if (sem.count > 0) {
568+
await sem.wait();
564569
try {
565570
// Wait for any concurrent recompilations to complete...
566571
try {
@@ -576,20 +581,20 @@ gulp.task(
576581
}
577582

578583
// cancel any pending or active test run if a new recompilation is triggered
579-
const runTestsSource = new CancellationTokenSource();
584+
const source = new CancellationTokenSource();
580585
project.waitForWorkToStart().then(() => {
581-
runTestsSource.cancel();
586+
source.cancel();
582587
});
583588

584589
if (cmdLineOptions.tests || cmdLineOptions.failed) {
585-
await runConsoleTests(runJs, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ true, runTestsSource.token);
590+
await runConsoleTests(runJs, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ true, source.token);
586591
}
587592
else {
588-
await runConsoleTests(runJs, "min", /*runInParallel*/ true, /*watchMode*/ true, runTestsSource.token);
593+
await runConsoleTests(runJs, "min", /*runInParallel*/ true, /*watchMode*/ true, source.token);
589594
}
590595
}
591596
finally {
592-
runTestsSemaphore.release();
597+
sem.release();
593598
}
594599
}
595600
}
@@ -602,14 +607,6 @@ gulp.task(
602607
}
603608
}
604609
};
605-
606-
gulp.watch(watchPatterns, (e) => fn());
607-
608-
// NOTE: gulp.watch is far too slow when watching tests/cases/**/* as it first enumerates *every* file
609-
const testFilePattern = /(\.ts|[\\/]tsconfig\.json)$/;
610-
fs.watch("tests/cases", { recursive: true }, (_, file) => {
611-
if (testFilePattern.test(file)) fn();
612-
});
613610
});
614611

615612
gulp.task("clean-built", /*help*/ false, [`clean:${diagnosticInformationMapTs}`], () => del(["built"]));

scripts/build/exec.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const cp = require("child_process");
33
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
44
const isWin = /^win/.test(process.platform);
55
const chalk = require("./chalk");
6-
const { CancelError } = require("prex");
6+
const { CancellationToken, CancelError } = require("prex");
77

88
module.exports = exec;
99

@@ -19,33 +19,32 @@ module.exports = exec;
1919
*/
2020
function exec(cmd, args, options = {}) {
2121
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
22-
if (options.cancelToken) {
23-
options.cancelToken.throwIfCancellationRequested();
24-
}
25-
26-
log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
22+
const { ignoreExitCode, cancelToken = CancellationToken.none } = options;
23+
cancelToken.throwIfCancellationRequested();
24+
2725
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
2826
const subshellFlag = isWin ? "/c" : "-c";
2927
const command = isWin ? [possiblyQuote(cmd), ...args] : [`${cmd} ${args.join(" ")}`];
30-
const ex = cp.spawn(isWin ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true });
31-
const subscription = options.cancelToken && options.cancelToken.register(() => {
28+
29+
log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
30+
const proc = cp.spawn(isWin ? "cmd" : "/bin/sh", [subshellFlag, ...command], { stdio: "inherit", windowsVerbatimArguments: true });
31+
const registration = cancelToken.register(() => {
3232
log(`${chalk.red("killing")} '${chalk.green(cmd)} ${args.join(" ")}'...`);
33-
ex.kill("SIGINT");
34-
ex.kill("SIGTERM");
35-
ex.kill();
33+
proc.kill("SIGINT");
34+
proc.kill("SIGTERM");
3635
reject(new CancelError());
3736
});
38-
ex.on("exit", exitCode => {
39-
if (subscription) subscription.unregister();
40-
if (exitCode === 0 || options.ignoreExitCode) {
37+
proc.on("exit", exitCode => {
38+
registration.unregister();
39+
if (exitCode === 0 || ignoreExitCode) {
4140
resolve({ exitCode });
4241
}
4342
else {
4443
reject(new Error(`Process exited with code: ${exitCode}`));
4544
}
4645
});
47-
ex.on("error", error => {
48-
if (subscription) subscription.unregister();
46+
proc.on("error", error => {
47+
registration.unregister();
4948
reject(error);
5049
});
5150
}));

scripts/build/project.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const needsUpdate = require("./needsUpdate");
1616
const mkdirp = require("./mkdirp");
1717
const prettyTime = require("pretty-hrtime");
1818
const { reportDiagnostics } = require("./diagnostics");
19-
const { CountdownEvent, Pulsar } = require("prex");
19+
const { CountdownEvent, ManualResetEvent } = require("prex");
2020

21-
const workStartedEvent = new Pulsar();
21+
const workStartedEvent = new ManualResetEvent();
2222
const countdown = new CountdownEvent(0);
2323

2424
class CompilationGulp extends gulp.Gulp {
@@ -30,7 +30,8 @@ class CompilationGulp extends gulp.Gulp {
3030
child.on("task_start", e => {
3131
if (countdown.remainingCount === 0) {
3232
countdown.reset(1);
33-
workStartedEvent.pulseAll();
33+
workStartedEvent.set();
34+
workStartedEvent.reset();
3435
}
3536
else {
3637
countdown.add();

scripts/build/tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const mkdirP = require("./mkdirp");
88
const cmdLineOptions = require("./options");
99
const exec = require("./exec");
1010
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
11+
const { CancellationToken } = require("prex");
1112
const mochaJs = require.resolve("mocha/bin/_mocha");
1213

1314
exports.localBaseline = "tests/baselines/local/";
@@ -23,7 +24,7 @@ exports.localTest262Baseline = "internal/baselines/test262/local";
2324
* @param {boolean} watchMode
2425
* @param {import("prex").CancellationToken} [cancelToken]
2526
*/
26-
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, cancelToken) {
27+
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, cancelToken = CancellationToken.none) {
2728
let testTimeout = cmdLineOptions.timeout;
2829
let tests = cmdLineOptions.tests;
2930
const lintFlag = cmdLineOptions.lint;
@@ -37,7 +38,7 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
3738
const keepFailed = cmdLineOptions.keepFailed;
3839
if (!cmdLineOptions.dirty) {
3940
await cleanTestDirs();
40-
if (cancelToken) cancelToken.throwIfCancellationRequested();
41+
cancelToken.throwIfCancellationRequested();
4142
}
4243

4344
if (fs.existsSync(testConfigFile)) {

0 commit comments

Comments
 (0)