Skip to content
Permalink
Browse files
Remove unused cancellation from build (#50658)
  • Loading branch information
jakebailey committed Sep 6, 2022
1 parent 66fbf05 commit 5c2f770d9714276567e6ef9ec805368756539725
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 73 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -90,7 +90,6 @@
"mocha-fivemat-progress-reporter": "latest",
"ms": "^2.1.3",
"node-fetch": "^2.6.7",
"prex": "^0.4.7",
"source-map-support": "latest",
"typescript": "^4.8.2",
"vinyl": "latest",
@@ -6,7 +6,6 @@ const path = require("path");
const mkdirP = require("mkdirp");
const log = require("fancy-log");
const cmdLineOptions = require("./options");
const { CancellationToken } = require("prex");
const { exec } = require("./utils");
const { findUpFile } = require("./findUpDir");

@@ -22,9 +21,8 @@ exports.localTest262Baseline = "internal/baselines/test262/local";
* @param {string} defaultReporter
* @param {boolean} runInParallel
* @param {boolean} watchMode
* @param {import("prex").CancellationToken} [cancelToken]
*/
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode, cancelToken = CancellationToken.none) {
async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode) {
let testTimeout = cmdLineOptions.timeout;
const tests = cmdLineOptions.tests;
const inspect = cmdLineOptions.break || cmdLineOptions.inspect;
@@ -38,7 +36,6 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
const shardId = +cmdLineOptions.shardId || undefined;
if (!cmdLineOptions.dirty) {
await cleanTestDirs();
cancelToken.throwIfCancellationRequested();
}

if (fs.existsSync(testConfigFile)) {
@@ -121,9 +118,7 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,

try {
setNodeEnvToDevelopment();
const { exitCode } = await exec(process.execPath, args, {
cancelToken,
});
const { exitCode } = await exec(process.execPath, args);
if (exitCode !== 0) {
errorStatus = exitCode;
error = new Error(`Process exited with status code ${errorStatus}.`);
@@ -132,8 +127,8 @@ async function runConsoleTests(runJs, defaultReporter, runInParallel, watchMode,
// finally, do a sanity check and build the compiler with the built version of itself
log.info("Starting sanity check build...");
// Cleanup everything except lint rules (we'll need those later and would rather not waste time rebuilding them)
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"], { cancelToken });
const { exitCode } = await exec("gulp", ["local", "--lkg=false"], { cancelToken });
await exec("gulp", ["clean-tsc", "clean-services", "clean-tsserver", "clean-lssl", "clean-tests"]);
const { exitCode } = await exec("gulp", ["local", "--lkg=false"]);
if (exitCode !== 0) {
errorStatus = exitCode;
error = new Error(`Sanity check build process exited with status code ${errorStatus}.`);
@@ -14,7 +14,6 @@ const ts = require("../../lib/typescript");
const chalk = require("chalk");
const which = require("which");
const { spawn } = require("child_process");
const { CancellationToken, CancelError, Deferred } = require("prex");
const { Readable, Duplex } = require("stream");

/**
@@ -25,26 +24,17 @@ const { Readable, Duplex } = require("stream");
*
* @typedef ExecOptions
* @property {boolean} [ignoreExitCode]
* @property {import("prex").CancellationToken} [cancelToken]
* @property {boolean} [hidePrompt]
* @property {boolean} [waitForExit=true]
*/
async function exec(cmd, args, options = {}) {
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
const { ignoreExitCode, cancelToken = CancellationToken.none, waitForExit = true } = options;
cancelToken.throwIfCancellationRequested();
const { ignoreExitCode, waitForExit = true } = options;

if (!options.hidePrompt) log(`> ${chalk.green(cmd)} ${args.join(" ")}`);
const proc = spawn(which.sync(cmd), args, { stdio: waitForExit ? "inherit" : "ignore" });
const registration = cancelToken.register(() => {
log(`${chalk.red("killing")} '${chalk.green(cmd)} ${args.join(" ")}'...`);
proc.kill("SIGINT");
proc.kill("SIGTERM");
reject(new CancelError());
});
if (waitForExit) {
proc.on("exit", exitCode => {
registration.unregister();
if (exitCode === 0 || ignoreExitCode) {
resolve({ exitCode });
}
@@ -53,7 +43,6 @@ async function exec(cmd, args, options = {}) {
}
});
proc.on("error", error => {
registration.unregister();
reject(error);
});
}
@@ -395,6 +384,15 @@ function rm(dest, opts) {
}
exports.rm = rm;

class Deferred {
constructor() {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
}
}

class Debouncer {
/**
* @param {number} timeout

0 comments on commit 5c2f770

Please sign in to comment.