Skip to content

Commit c8c0428

Browse files
committed
Cleanup, remove some unneeded dependencies, make it easier to add gulp.watch support later
1 parent 5bc8f95 commit c8c0428

14 files changed

+525
-664
lines changed

Gulpfile.js

+59-63
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,24 @@ const getDirSize = require("./scripts/build/getDirSize");
2424
const project = require("./scripts/build/project");
2525
const replace = require("./scripts/build/replace");
2626
const convertConstEnums = require("./scripts/build/convertConstEnum");
27-
const makeLibraryTargets = require("./scripts/build/lib");
2827
const needsUpdate = require("./scripts/build/needsUpdate");
2928
const getDiffTool = require("./scripts/build/getDiffTool");
3029
const baselineAccept = require("./scripts/build/baselineAccept");
3130
const cmdLineOptions = require("./scripts/build/options");
3231
const exec = require("./scripts/build/exec");
32+
const _debugMode = require("./scripts/build/debugMode");
33+
const { libraryTargets, generateLibs } = require("./scripts/build/lib");
3334
const { runConsoleTests, cleanTestDirs, writeTestConfigFile, refBaseline, localBaseline, refRwcBaseline, localRwcBaseline } = require("./scripts/build/tests");
3435

3536
Error.stackTraceLimit = 1000;
3637

3738
// Constants
3839
const host = cmdLineOptions.host;
3940
const copyright = "CopyrightNotice.txt";
40-
const libraryTargets = makeLibraryTargets([copyright]);
4141

42-
// Compile using the LKG compiler
4342
project.addTypeScript("lkg", "./lib/typescript.js");
44-
project.addTypeScript("default", "lkg");
43+
project.addTypeScript("built", "./built/local/typescriptServices.js");
44+
project.addTypeScript("default", "lkg"); // Compile using the LKG compiler by default
4545

4646
const scriptsProject = "scripts/tsconfig.json";
4747
const configurePrereleaseJs = "scripts/configurePrerelease.js";
@@ -50,7 +50,7 @@ const generateLocalizedDiagnosticMessagesJs = "scripts/generateLocalizedDiagnost
5050
const buildProtocolJs = "scripts/buildProtocol.js";
5151
const produceLKGJs = "scripts/produceLKG.js";
5252
const word2mdJs = "scripts/word2md.js";
53-
gulp.task("scripts", /*help*/ false, [project(scriptsProject)], undefined, {
53+
gulp.task("scripts", /*help*/ false, () => project.compile(scriptsProject), {
5454
aliases: [
5555
configurePrereleaseJs,
5656
processDiagnosticMessagesJs,
@@ -60,7 +60,7 @@ gulp.task("scripts", /*help*/ false, [project(scriptsProject)], undefined, {
6060
word2mdJs
6161
]
6262
});
63-
gulp.task("clean-scripts", /*help*/ false, [project.clean(scriptsProject)]);
63+
gulp.task("clean-scripts", /*help*/ false, () => project.clean(scriptsProject));
6464

6565
// Nightly management tasks
6666
gulp.task(
@@ -78,8 +78,8 @@ gulp.task(
7878

7979
const importDefinitelyTypedTestsProject = "scripts/importDefinitelyTypedTests/tsconfig.json";
8080
const importDefinitelyTypedTestsJs = "scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js";
81-
gulp.task(importDefinitelyTypedTestsJs, /*help*/ false, [project(importDefinitelyTypedTestsProject)]);
82-
gulp.task("clean:" + importDefinitelyTypedTestsJs, /*help*/ false, [project.clean(importDefinitelyTypedTestsProject)]);
81+
gulp.task(importDefinitelyTypedTestsJs, /*help*/ false, () => project.compile(importDefinitelyTypedTestsProject));
82+
gulp.task("clean:" + importDefinitelyTypedTestsJs, /*help*/ false, () => project.clean(importDefinitelyTypedTestsProject));
8383

8484
gulp.task(
8585
"importDefinitelyTypedTests",
@@ -90,7 +90,7 @@ gulp.task(
9090
gulp.task(
9191
"lib",
9292
"Builds the library targets",
93-
libraryTargets);
93+
() => generateLibs([copyright]));
9494

9595
// The generated diagnostics map; built for the compiler and for the "generate-diagnostics" task
9696
const diagnosticInformationMapTs = "src/compiler/diagnosticInformationMap.generated.ts";
@@ -145,20 +145,18 @@ gulp.task(typescriptServicesProject, /*help*/ false, () => {
145145
// NOTE: flatten services so that we can properly strip @internal
146146
project.flatten("src/services/tsconfig.json", typescriptServicesProject, {
147147
compilerOptions: {
148+
"removeComments": true,
148149
"stripInternal": true,
149150
"outFile": "typescriptServices.js"
150151
}
151152
});
152-
})
153+
});
153154

154155
const typescriptServicesJs = "built/local/typescriptServices.js";
155156
const typescriptServicesDts = "built/local/typescriptServices.d.ts";
156-
const typescriptServicesProjectTask = project.defer(typescriptServicesProject, {
157-
dts: files => files.pipe(convertConstEnums()),
158-
release: { compilerOptions: { removeComments: true } }
159-
});
160-
161-
gulp.task(typescriptServicesJs, /*help*/ false, ["lib", "generate-diagnostics", typescriptServicesProject], typescriptServicesProjectTask, { aliases: [typescriptServicesDts] });
157+
gulp.task(typescriptServicesJs, /*help*/ false, ["lib", "generate-diagnostics", typescriptServicesProject], () =>
158+
project.compile(typescriptServicesProject, { dts: convertConstEnums() }),
159+
{ aliases: [typescriptServicesDts] });
162160

163161
const typescriptJs = "built/local/typescript.js";
164162
gulp.task(typescriptJs, /*help*/ false, [typescriptServicesJs], () =>
@@ -186,28 +184,25 @@ gulp.task(typescriptStandaloneDts, /*help*/ false, [typescriptServicesDts], () =
186184
// build all 'typescriptServices'-related outputs
187185
gulp.task("typescriptServices", /*help*/ false, [typescriptServicesJs, typescriptServicesDts, typescriptJs, typescriptDts, typescriptStandaloneDts]);
188186

189-
// Add the "built" compiler with a dependency on the built version of the compiler.
190-
project.addTypeScript("built", "./built/local/typescriptServices.js", [typescriptServicesJs]);
191-
192187
const tscProject = "src/tsc/tsconfig.json";
193188
const tscJs = "built/local/tsc.js";
194-
gulp.task(tscJs, /*help*/ false, [project(tscProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })]);
189+
gulp.task(tscJs, /*help*/ false, [typescriptServicesJs], () => project.compile(tscProject, { typescript: "built" }));
195190

196191
const cancellationTokenProject = "src/cancellationToken/tsconfig.json";
197192
const cancellationTokenJs = "built/local/cancellationToken.js";
198-
gulp.task(cancellationTokenJs, /*help*/ false, [project(cancellationTokenProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })]);
193+
gulp.task(cancellationTokenJs, /*help*/ false, [typescriptServicesJs], () => project.compile(cancellationTokenProject, { typescript: "built" }));
199194

200195
const typingsInstallerProject = "src/typingsInstaller/tsconfig.json";
201196
const typingsInstallerJs = "built/local/typingsInstaller.js";
202-
gulp.task(typingsInstallerJs, /*help*/ false, [project(typingsInstallerProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })]);
197+
gulp.task(typingsInstallerJs, /*help*/ false, [typescriptServicesJs], () => project.compile(typingsInstallerProject, { typescript: "built" }));
203198

204199
const tsserverProject = "src/tsserver/tsconfig.json";
205200
const tsserverJs = "built/local/tsserver.js";
206-
gulp.task(tsserverJs, /*help*/ false, [project(tsserverProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })]);
201+
gulp.task(tsserverJs, /*help*/ false, [typescriptServicesJs], () => project.compile(tsserverProject, { typescript: "built" }));
207202

208203
const watchGuardProject = "src/watchGuard/tsconfig.json";
209204
const watchGuardJs = "built/local/watchGuard.js";
210-
gulp.task(watchGuardJs, /*help*/ false, [project(watchGuardProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })]);
205+
gulp.task(watchGuardJs, /*help*/ false, [typescriptServicesJs], () => project.compile(watchGuardProject, { typescript: "built" }));
211206

212207
const typesMapJson = "built/local/typesMap.json";
213208
gulp.task(typesMapJson, /*help*/ false, [], () =>
@@ -249,42 +244,43 @@ gulp.task(
249244
"Generates a Markdown version of the Language Specification",
250245
[specMd]);
251246

247+
gulp.task("produce-LKG", /*help*/ false, ["scripts", "local", cancellationTokenJs, typingsInstallerJs, watchGuardJs], () => {
248+
const expectedFiles = [
249+
tscJs,
250+
typescriptServicesJs,
251+
tsserverJs,
252+
typescriptJs,
253+
typescriptDts,
254+
typescriptServicesDts,
255+
tsserverlibraryDts,
256+
tsserverlibraryDts,
257+
typingsInstallerJs,
258+
cancellationTokenJs
259+
].concat(libraryTargets);
260+
const missingFiles = expectedFiles
261+
.concat(localizationTargets)
262+
.filter(f => !fs.existsSync(f));
263+
if (missingFiles.length > 0) {
264+
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"));
265+
}
266+
const sizeBefore = getDirSize("lib");
267+
return exec(host, [produceLKGJs]).then(() => {
268+
const sizeAfter = getDirSize("lib");
269+
if (sizeAfter > (sizeBefore * 1.10)) {
270+
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
271+
}
272+
});
273+
});
274+
252275
gulp.task(
253276
"LKG",
254277
"Makes a new LKG out of the built js files",
255-
() => runSequence("clean-built", "dontUseDebugMode", ["scripts", "local", cancellationTokenJs, typingsInstallerJs, watchGuardJs],
256-
() => {
257-
const expectedFiles = [
258-
tscJs,
259-
typescriptServicesJs,
260-
tsserverJs,
261-
typescriptJs,
262-
typescriptDts,
263-
typescriptServicesDts,
264-
tsserverlibraryDts,
265-
tsserverlibraryDts,
266-
typingsInstallerJs,
267-
cancellationTokenJs
268-
].concat(libraryTargets);
269-
const missingFiles = expectedFiles
270-
.concat(localizationTargets)
271-
.filter(f => !fs.existsSync(f));
272-
if (missingFiles.length > 0) {
273-
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"));
274-
}
275-
const sizeBefore = getDirSize("lib");
276-
return exec(host, [produceLKGJs]).then(() => {
277-
const sizeAfter = getDirSize("lib");
278-
if (sizeAfter > (sizeBefore * 1.10)) {
279-
throw new Error("The lib folder increased by 10% or more. This likely indicates a bug.");
280-
}
281-
});
282-
}));
278+
() => runSequence("clean-built", "dontUseDebugMode", "produce-LKG"));
283279

284280
// Task to build the tests infrastructure using the built compiler
285281
const testRunnerProject = "src/testRunner/tsconfig.json";
286282
const runJs = "built/local/run.js";
287-
gulp.task(runJs, /*help*/ false, [project(testRunnerProject, { typescript: "built", deps: [tsserverlibraryDts] })]);
283+
gulp.task(runJs, /*help*/ false, [typescriptServicesJs, tsserverlibraryDts], () => project.compile(testRunnerProject, { typescript: "built" }));
288284

289285
gulp.task(
290286
"tests",
@@ -310,8 +306,8 @@ gulp.task(
310306

311307
const webTestServerProject = "tests/webTestServer.tsconfig.json";
312308
const webTestServerJs = "tests/webTestServer.js";
313-
gulp.task(webTestServerJs, /*help*/ false, [project(webTestServerProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })])
314-
gulp.task("clean:" + webTestServerJs, /*help*/ false, [project.clean(webTestServerProject, { typescript: "built" })])
309+
gulp.task(webTestServerJs, /*help*/ false, [typescriptServicesJs], () => project.compile(webTestServerProject, { typescript: "built" }));
310+
gulp.task("clean:" + webTestServerJs, /*help*/ false, () => project.clean(webTestServerProject));
315311

316312
const bundlePath = path.resolve("built/local/bundle.js");
317313

@@ -447,8 +443,8 @@ gulp.task(
447443
// Webhost
448444
const webtscProject = "tests/webhost/webtsc.tsconfig.json";
449445
const webtscJs = "tests/webhost/webtsc.js";
450-
gulp.task(webtscJs, /*help*/ false, [project(webtscProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })]);
451-
gulp.task("clean:" + webtscJs, /*help*/ false, [project.clean(webtscProject, { typescript: "built" })]);
446+
gulp.task(webtscJs, /*help*/ false, [typescriptServicesJs], () => project.compile(webtscProject, { typescript: "built" }));
447+
gulp.task("clean:" + webtscJs, /*help*/ false, () => project.clean(webtscProject));
452448

453449
gulp.task("webhost", "Builds the tsc web host", [webtscJs], () =>
454450
gulp.src("built/local/lib.d.ts")
@@ -457,8 +453,8 @@ gulp.task("webhost", "Builds the tsc web host", [webtscJs], () =>
457453
// Perf compiler
458454
const perftscProject = "tests/perftsc.tsconfig.json";
459455
const perftscJs = "built/local/perftsc.js";
460-
gulp.task(perftscJs, /*help*/ false, [project(perftscProject, { typescript: "built", release: { compilerOptions: { removeComments: true } } })]);
461-
gulp.task("clean:" + perftscJs, /*help*/ false, [project.clean(perftscProject, { typescript: "built" })]);
456+
gulp.task(perftscJs, /*help*/ false, [typescriptServicesJs], () => project.compile(perftscProject, { typescript: "built" }));
457+
gulp.task("clean:" + perftscJs, /*help*/ false, () => project.clean(perftscProject));
462458

463459
gulp.task(
464460
"perftsc",
@@ -477,8 +473,8 @@ gulp.task(loggedIOJs, /*help*/ false, [], (done) => {
477473

478474
const instrumenterProject = "src/instrumenter/tsconfig.json";
479475
const instrumenterJs = "built/local/instrumenter.js";
480-
gulp.task(instrumenterJs, /*help*/ false, [project(instrumenterProject)]);
481-
gulp.task("clean:" + instrumenterJs, /*help*/ false, [project.clean(instrumenterProject)]);
476+
gulp.task(instrumenterJs, /*help*/ false, () => project.compile(instrumenterProject));
477+
gulp.task("clean:" + instrumenterJs, /*help*/ false, () => project.clean(instrumenterProject));
482478

483479
gulp.task(
484480
"tsc-instrumented",
@@ -497,9 +493,9 @@ gulp.task(
497493
gulp.task(
498494
"build-rules",
499495
"Compiles tslint rules to js",
500-
[project("scripts/tslint/tsconfig.json")]);
496+
() => project.compile("scripts/tslint/tsconfig.json"));
501497

502-
gulp.task("clean-rules", /*help*/ false, [project.clean("scripts/tslint/tsconfig.json")]);
498+
gulp.task("clean-rules", /*help*/ false, () => project.clean("scripts/tslint/tsconfig.json"));
503499

504500
gulp.task(
505501
"lint",

0 commit comments

Comments
 (0)