Skip to content

Commit ad4338d

Browse files
committed
Remove excess exports from exec.js
1 parent 21c23d4 commit ad4338d

File tree

3 files changed

+18
-237
lines changed

3 files changed

+18
-237
lines changed

Gulpfile.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const needsUpdate = require("./scripts/build/needsUpdate");
2929
const getDiffTool = require("./scripts/build/getDiffTool");
3030
const baselineAccept = require("./scripts/build/baselineAccept");
3131
const cmdLineOptions = require("./scripts/build/options");
32-
const { execAsync } = require("./scripts/build/exec");
32+
const exec = require("./scripts/build/exec");
3333
const { runConsoleTests, cleanTestDirs, writeTestConfigFile, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } = require("./scripts/build/tests");
3434

3535
Error.stackTraceLimit = 1000;
@@ -67,14 +67,14 @@ gulp.task(
6767
"configure-nightly",
6868
"Runs scripts/configurePrerelease.ts to prepare a build for nightly publishing",
6969
[configurePrereleaseJs],
70-
() => execAsync(host, [configurePrereleaseJs, "dev", "package.json", "src/compiler/core.ts"]));
70+
() => exec(host, [configurePrereleaseJs, "dev", "package.json", "src/compiler/core.ts"]));
7171

7272
gulp.task(
7373
"publish-nightly",
7474
"Runs `npm publish --tag next` to create a new nightly build on npm",
7575
["LKG"],
7676
() => runSequence("clean", "useDebugMode", "runtests-parallel",
77-
() => execAsync("npm", ["publish", "--tag", "next"])));
77+
() => exec("npm", ["publish", "--tag", "next"])));
7878

7979
const importDefinitelyTypedTestsProject = "scripts/importDefinitelyTypedTests/tsconfig.json";
8080
const importDefinitelyTypedTestsJs = "scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js";
@@ -85,7 +85,7 @@ gulp.task(
8585
"importDefinitelyTypedTests",
8686
"Runs scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.ts to copy DT's tests to the TS-internal RWC tests",
8787
[importDefinitelyTypedTestsJs],
88-
() => execAsync(host, [importDefinitelyTypedTestsJs, "./", "../DefinitelyTyped"]));
88+
() => exec(host, [importDefinitelyTypedTestsJs, "./", "../DefinitelyTyped"]));
8989

9090
gulp.task(
9191
"lib",
@@ -98,7 +98,7 @@ const diagnosticMessagesJson = "src/compiler/diagnosticMessages.json";
9898
const diagnosticMessagesGeneratedJson = "src/compiler/diagnosticMessages.generated.json";
9999
gulp.task(diagnosticInformationMapTs, /*help*/ false, [processDiagnosticMessagesJs], () => {
100100
if (needsUpdate(diagnosticMessagesJson, [diagnosticMessagesGeneratedJson, diagnosticInformationMapTs])) {
101-
return execAsync(host, [processDiagnosticMessagesJs, diagnosticMessagesJson]);
101+
return exec(host, [processDiagnosticMessagesJs, diagnosticMessagesJson]);
102102
}
103103
});
104104
gulp.task("clean:" + diagnosticInformationMapTs, /*help*/ false, () => del([diagnosticInformationMapTs, diagnosticMessagesGeneratedJson]));
@@ -134,7 +134,7 @@ const localizationTargets = ["cs", "de", "es", "fr", "it", "ja", "ko", "pl", "pt
134134

135135
gulp.task(generatedLCGFile, /*help*/ false, [generateLocalizedDiagnosticMessagesJs, diagnosticInformationMapTs], (done) => {
136136
if (needsUpdate(diagnosticMessagesGeneratedJson, generatedLCGFile)) {
137-
return execAsync(host, [generateLocalizedDiagnosticMessagesJs, "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
137+
return exec(host, [generateLocalizedDiagnosticMessagesJs, "src/loc/lcl", "built/local", diagnosticMessagesGeneratedJson], { ignoreExitCode: true });
138138
}
139139
});
140140

@@ -242,7 +242,7 @@ gulp.task(
242242
// Generate Markdown spec
243243
const specMd = "doc/spec.md";
244244
gulp.task(specMd, /*help*/ false, [word2mdJs], () =>
245-
execAsync("cscript", ["//nologo", word2mdJs, path.resolve(specMd), path.resolve("doc/TypeScript Language Specification.docx")]));
245+
exec("cscript", ["//nologo", word2mdJs, path.resolve(specMd), path.resolve("doc/TypeScript Language Specification.docx")]));
246246

247247
gulp.task(
248248
"generate-spec",
@@ -273,7 +273,7 @@ gulp.task(
273273
throw new Error("Cannot replace the LKG unless all built targets are present in directory 'built/local/'. The following files are missing:\n" + missingFiles.join("\n"));
274274
}
275275
const sizeBefore = getDirSize("lib");
276-
return execAsync(host, [produceLKGJs]).then(() => {
276+
return exec(host, [produceLKGJs]).then(() => {
277277
const sizeAfter = getDirSize("lib");
278278
if (sizeAfter > (sizeBefore * 1.10)) {
279279
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
@@ -409,25 +409,25 @@ gulp.task(
409409
if (tests) {
410410
args.push(JSON.stringify(tests));
411411
}
412-
return execAsync("node", args);
412+
return exec("node", args);
413413
}));
414414

415415
gulp.task(
416416
"generate-code-coverage",
417417
"Generates code coverage data via istanbul",
418418
["tests"],
419-
() => execAsync("istanbul", ["cover", "node_modules/mocha/bin/_mocha", "--", "-R", "min", "-t", "" + cmdLineOptions.testTimeout, runJs]));
419+
() => exec("istanbul", ["cover", "node_modules/mocha/bin/_mocha", "--", "-R", "min", "-t", "" + cmdLineOptions.testTimeout, runJs]));
420420

421421

422422
gulp.task(
423423
"diff",
424424
"Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable",
425-
() => execAsync(getDiffTool(), [refBaseline, localBaseline], { ignoreExitCode: true }));
425+
() => exec(getDiffTool(), [refBaseline, localBaseline], { ignoreExitCode: true }));
426426

427427
gulp.task(
428428
"diff-rwc",
429429
"Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable",
430-
() => execAsync(getDiffTool(), [refRwcBaseline, localRwcBaseline], { ignoreExitCode: true }));
430+
() => exec(getDiffTool(), [refRwcBaseline, localRwcBaseline], { ignoreExitCode: true }));
431431

432432
gulp.task(
433433
"baseline-accept",
@@ -470,7 +470,7 @@ const loggedIOTs = "src/harness/loggedIO.ts";
470470
const loggedIOJs = "built/local/loggedIO.js";
471471
gulp.task(loggedIOJs, /*help*/ false, [], (done) => {
472472
return mkdirp("built/local/temp")
473-
.then(() => execAsync(host, ["lib/tsc.js", "--types", "--target es5", "--lib es5", "--outdir", "built/local/temp", loggedIOTs]))
473+
.then(() => exec(host, ["lib/tsc.js", "--types", "--target es5", "--lib es5", "--outdir", "built/local/temp", loggedIOTs]))
474474
.then(() => { fs.renameSync(path.join("built/local/temp", "/harness/loggedIO.js"), loggedIOJs); })
475475
.then(() => del("built/local/temp"));
476476
});
@@ -484,7 +484,7 @@ gulp.task(
484484
"tsc-instrumented",
485485
"Builds an instrumented tsc.js - run with --test=[testname]",
486486
["local", loggedIOJs, instrumenterJs, typescriptServicesJs],
487-
() => execAsync(host, [instrumenterJs, "record", cmdLineOptions.tests || "iocapture", "built/local"]));
487+
() => exec(host, [instrumenterJs, "record", cmdLineOptions.tests || "iocapture", "built/local"]));
488488

489489
gulp.task(
490490
"update-sublime",

scripts/build/exec.js

Lines changed: 2 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
// @ts-check
2-
const { Duplex } = require("stream");
32
const cp = require("child_process");
4-
const Vinyl = require("vinyl");
53
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
64
const isWin = /^win/.test(process.platform);
75
const { addColor, color } = require("./colors");
8-
module.exports = exports = exec;
96

10-
/**
11-
* Execute the provided command
12-
* @param {string} cmd
13-
* @param {(string|ExecArg)[]} args
14-
*/
15-
function exec(cmd, args) {
16-
switch (getArity(args)) {
17-
case "one": return execEach(cmd, /**@type {(string|ExecArgEach)[]}*/(args));
18-
case "many": return execAll(cmd, /**@type {(string|ExecArgAll)[]}*/(args));
19-
case "underspecified": throw new Error("Supplied arguments do not specify input file arity.")
20-
case "overspecified": throw new Error("Supplied arguments have a conflicting arity.");
21-
}
22-
}
23-
exports.exec = exec;
7+
module.exports = exec;
248

259
/**
2610
* Executes the provided command once with the supplied arguments.
@@ -29,14 +13,7 @@ exports.exec = exec;
2913
* @param {object} [options]
3014
* @param {boolean} [options.ignoreExitCode]
3115
*/
32-
function execAsync(cmd, args, options = {}) {
33-
switch (getArity(args)) {
34-
case "underspecified": break;
35-
case "one": break;
36-
case "many":
37-
case "overspecified": throw new Error("Supplied arguments have the wrong arity.");
38-
}
39-
16+
function exec(cmd, args, options = {}) {
4017
return /**@type {Promise<{exitCode: number}>}*/(new Promise((resolve, reject) => {
4118
log(addColor(`${cmd} ${args.join(" ")}`, color.gray));
4219
// TODO (weswig): Update child_process types to add windowsVerbatimArguments to the type definition
@@ -54,206 +31,10 @@ function execAsync(cmd, args, options = {}) {
5431
ex.on("error", reject);
5532
}));
5633
}
57-
exports.execAsync = execAsync;
58-
59-
/**
60-
* Execute the provided command once for each input file.
61-
* @param {string} cmd
62-
* @param {(string|ExecArgEach)[]} args
63-
*/
64-
function execEach(cmd, args) {
65-
switch (getArity(args)) {
66-
case "one": break;
67-
case "underspecified":
68-
args = [...args, each.path];
69-
break;
70-
71-
case "many":
72-
case "overspecified": throw new Error("Supplied arguments have the wrong arity.");
73-
}
74-
75-
const duplex = new Duplex({
76-
objectMode: true,
77-
/**
78-
* @param {string|Buffer|File} file
79-
* @param {(err?: Error) => void} cb
80-
*/
81-
write(file, _, cb) {
82-
if (!Vinyl.isVinyl(file)) throw new Error();
83-
execAsync(cmd, getExecArgs(args, [file])).then(() => cb(), cb);
84-
},
85-
final(cb) {
86-
duplex.push(null);
87-
cb();
88-
},
89-
read() {
90-
}
91-
});
92-
93-
return duplex;
94-
}
95-
exports.execEach = execEach;
96-
97-
/**
98-
* Execute the provided command once for all input files.
99-
* @param {string} cmd
100-
* @param {(string|ExecArgAll)[]} args
101-
*/
102-
function execAll(cmd, args) {
103-
switch (getArity(args)) {
104-
case "many": break;
105-
case "underspecified":
106-
args = [...args, all.path];
107-
break;
108-
109-
case "one":
110-
case "overspecified": throw new Error("Supplied arguments have the wrong arity.");
111-
}
112-
113-
/** @type {File[]} */
114-
const files = [];
115-
const duplex = new Duplex({
116-
objectMode: true,
117-
/**
118-
* @param {string|Buffer|File} file
119-
* @param {(err?: Error) => void} cb
120-
*/
121-
write(file, _, cb) {
122-
if (!Vinyl.isVinyl(file)) throw new Error();
123-
files.push(file);
124-
cb();
125-
},
126-
final(cb) {
127-
execAsync(cmd, getExecArgs(args, files)).then(() => {
128-
duplex.push(null);
129-
cb();
130-
}, cb);
131-
},
132-
read() {
133-
}
134-
});
135-
136-
return duplex;
137-
}
138-
exports.execAll = execAll;
139-
140-
/**
141-
* @param {(string|ExecArg)[]} args
142-
* @param {File[]} files
143-
*/
144-
function getExecArgs(args, files) {
145-
/**@type {string[]}*/
146-
let execArgs = [];
147-
for (const arg of args) {
148-
if (typeof arg === "object" && isExecArg(arg)) {
149-
const kind = arg.kind;
150-
execArgs = execArgs.concat(files.map(file => file[kind]));
151-
}
152-
else {
153-
execArgs.push("" + arg);
154-
}
155-
}
156-
return execArgs;
157-
}
15834

15935
/**
16036
* @param {string} cmd
16137
*/
16238
function possiblyQuote(cmd) {
16339
return cmd.indexOf(" ") >= 0 ? `"${cmd}"` : cmd;
16440
}
165-
166-
class ExecArgBase {
167-
/**
168-
* @param {ExecArgKind} kind
169-
*/
170-
constructor(kind) {
171-
this.kind = kind;
172-
}
173-
}
174-
175-
class ExecArgEach extends ExecArgBase {
176-
/**
177-
* @param {ExecArgKind} kind
178-
*/
179-
constructor(kind) {
180-
super(kind);
181-
/** @type {"one"} */
182-
this.arity = "one";
183-
Object.freeze(this);
184-
}
185-
}
186-
187-
class ExecArgAll extends ExecArgBase {
188-
/**
189-
* @param {ExecArgKind} kind
190-
*/
191-
constructor(kind) {
192-
super(kind);
193-
/** @type {"many"} */
194-
this.arity = "many";
195-
Object.freeze(this);
196-
}
197-
}
198-
199-
const each = exports.each = Object.freeze({
200-
path: new ExecArgEach("path"),
201-
dirname: new ExecArgEach("dirname"),
202-
basename: new ExecArgEach("basename"),
203-
extname: new ExecArgEach("extname"),
204-
});
205-
206-
const all = exports.all = Object.freeze({
207-
path: new ExecArgAll("path"),
208-
dirname: new ExecArgAll("dirname"),
209-
basename: new ExecArgAll("basename"),
210-
extname: new ExecArgAll("extname"),
211-
});
212-
213-
/**
214-
* @param {string|ExecArg} arg
215-
*/
216-
function isExecArg(arg) {
217-
return !!arg && typeof arg === "object" && "kind" in arg;
218-
}
219-
220-
/**
221-
* @param {string|ExecArg} arg
222-
*/
223-
function isExecArgOne(arg) {
224-
return !!arg && typeof arg === "object" && "kind" in arg && arg.arity === "one";
225-
}
226-
227-
/**
228-
* @param {string|ExecArg} arg
229-
*/
230-
function isExecArgMany(arg) {
231-
return !!arg && typeof arg === "object" && "kind" in arg && arg.arity === "many";
232-
}
233-
234-
/**
235-
* @param {(string | ExecArg)[]} args
236-
*/
237-
function getArity(args) {
238-
let arity = /** @type {"underspecified"|"one"|"many"} */("underspecified");
239-
for (const arg of args) {
240-
if (isExecArgOne(arg)) {
241-
if (arity === "many") return "overspecified";
242-
arity = "one";
243-
}
244-
else if (isExecArgMany(arg)) {
245-
if (arity === "one") return "overspecified";
246-
arity = "many";
247-
}
248-
}
249-
return arity;
250-
}
251-
252-
/**
253-
* @typedef {import("vinyl")} File
254-
*
255-
* @typedef {"path"|"dirname"|"basename"|"extname"} ExecArgKind
256-
*
257-
* @typedef {ExecArgEach|ExecArgAll} ExecArg
258-
*/
259-
void 0;

scripts/build/tests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const os = require("os");
55
const path = require("path");
66
const mkdirP = require("./mkdirp");
77
const cmdLineOptions = require("./options");
8-
const { execAsync } = require("./exec");
8+
const exec = require("./exec");
99
const runSequence = require("run-sequence");
1010
const finished = require("./finished");
1111
const log = require("fancy-log"); // was `require("gulp-util").log (see https://github.com/gulpjs/gulp-util)
@@ -103,7 +103,7 @@ function runConsoleTests(runJs, defaultReporter, runInParallel) {
103103
args.push(runJs);
104104
}
105105
setNodeEnvToDevelopment();
106-
return execAsync(host, [runJs]);
106+
return exec(host, [runJs]);
107107
})
108108
.then(({ exitCode }) => {
109109
if (exitCode !== 0) return finish(undefined, exitCode);

0 commit comments

Comments
 (0)