Skip to content

Commit 5dd52e5

Browse files
committed
Clean up some TODOs
1 parent 497c663 commit 5dd52e5

File tree

3 files changed

+57
-44
lines changed

3 files changed

+57
-44
lines changed

Gulpfile.js

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const copyright = "CopyrightNotice.txt";
1919
const cleanTasks = [];
2020

2121

22-
// TODO(jakebailey): This is really gross. Waiting on: https://github.com/microsoft/TypeScript/issues/25613
22+
// TODO(jakebailey): This is really gross. Waiting on https://github.com/microsoft/TypeScript/issues/25613,
23+
// or at least control over noEmit / emitDeclarationOnly in build mode.
2324
let currentlyBuilding = 0;
2425
let oldTsconfigBase;
2526

@@ -166,18 +167,16 @@ function esbuildTask(entrypoint, outfile, exportIsTsObject = false, performanceM
166167
bundle: true,
167168
outfile: performanceMatters ? preBabel : outfile,
168169
platform: "node",
169-
// TODO: also specify minimal browser targets
170-
target: "node10", // Node 10 is the oldest benchmarker.
170+
target: "es2018", // This covers Node 10.
171171
format: "cjs",
172172
sourcemap: true,
173-
external: ["./node_modules/*"], // TODO(jakebailey): does the test runner import relatively from scripts?
173+
external: ["./node_modules/*"],
174174
conditions: ["require"],
175175
supported: {
176-
// "const-and-let": false, // Unfortunately, no: https://github.com/evanw/esbuild/issues/297
177-
"object-rest-spread": false, // See: https://github.com/evanw/esbuild/releases/tag/v0.14.46
176+
// "const-and-let": false, // https://github.com/evanw/esbuild/issues/297
177+
"object-rest-spread": false, // Performance enhancement, see: https://github.com/evanw/esbuild/releases/tag/v0.14.46
178178
},
179-
// legalComments: "none", // TODO(jakebailey): enable once we add copyright headers to our source files.
180-
// logLevel: "info",
179+
// legalComments: "none", // If we add copyright headers to the source files, uncomment.
181180
};
182181

183182
if (exportIsTsObject) {
@@ -237,11 +236,12 @@ const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnost
237236

238237

239238
const esbuildTsc = esbuildTask("./src/tsc/tsc.ts", "./built/local/tsc.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
239+
const writeTscCJSShim = () => writeCJSReexport("./built/local/tsc/tsc.js", "./built/local/tsc.js");
240240

241241

242242
const buildTsc = () => {
243243
if (cmdLineOptions.bundle) return esbuildTsc.build();
244-
writeCJSReexport("./built/local/tsc/tsc.js", "./built/local/tsc.js");
244+
writeTscCJSShim();
245245
return buildProject("src/tsc");
246246
};
247247
task("tsc", series(lkgPreBuild, buildTsc));
@@ -252,8 +252,11 @@ cleanTasks.push(cleanTsc);
252252
task("clean-tsc", cleanTsc);
253253
task("clean-tsc").description = "Cleans outputs for the command-line compiler";
254254

255-
// TODO(jakebailey): watch mode doesn't mix with --bundle=false.
256-
const watchTsc = () => cmdLineOptions.bundle ? esbuildTsc.watch() : watchProject("src/tsc");
255+
const watchTsc = () => {
256+
if (cmdLineOptions.bundle) return esbuildTsc.watch();
257+
writeTscCJSShim();
258+
return watchProject("src/tsc");
259+
};
257260
task("watch-tsc", series(lkgPreBuild, parallel(watchLib, watchDiagnostics, watchTsc)));
258261
task("watch-tsc").description = "Watch for changes and rebuild the command-line compiler only.";
259262

@@ -263,15 +266,15 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
263266
// Pre-build steps to use based on supplied options.
264267
const preBuild = cmdLineOptions.lkg ? lkgPreBuild : localPreBuild;
265268

266-
const esbuildServices = esbuildTask("./src/typescript/typescript.ts", "./built/local/typescript.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
267-
268269
// TODO(jakebailey): rename this; no longer "services".
269270

271+
const esbuildServices = esbuildTask("./src/typescript/typescript.ts", "./built/local/typescript.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
272+
const writeServicesCJSShim = () => writeCJSReexport("./built/local/typescript/typescript.js", "./built/local/typescript.js");
270273
const buildServicesProject = () => buildProject("src/typescript");
271274

272275
const buildServices = () => {
273276
if (cmdLineOptions.bundle) return esbuildServices.build();
274-
writeCJSReexport("./built/local/typescript/typescript.js", "./built/local/typescript.js");
277+
writeServicesCJSShim();
275278
return buildServicesProject();
276279
};
277280

@@ -287,8 +290,11 @@ cleanTasks.push(cleanServices);
287290
task("clean-services", cleanServices);
288291
task("clean-services").description = "Cleans outputs for the language service";
289292

290-
// TODO(jakebailey): watch mode doesn't mix with --bundle=false.
291-
const watchServices = () => cmdLineOptions.bundle ? esbuildServices.watch() : watchProject("src/typescript");
293+
const watchServices = () => {
294+
if (cmdLineOptions.bundle) return esbuildServices.watch();
295+
writeServicesCJSShim();
296+
return watchProject("src/typescript");
297+
};
292298
task("watch-services", series(preBuild, parallel(watchLib, watchDiagnostics, watchServices)));
293299
task("watch-services").description = "Watches for changes and rebuild language service only";
294300
task("watch-services").flags = {
@@ -300,10 +306,11 @@ task("dts-services", series(preBuild, buildServicesProject, dtsServices));
300306
task("dts-services").description = "Builds typescript.d.ts";
301307

302308
const esbuildServer = esbuildTask("./src/tsserver/server.ts", "./built/local/tsserver.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
309+
const writeServerCJSShim = () => writeCJSReexport("./built/local/tsserver/server.js", "./built/local/tsserver.js");
303310

304311
const buildServer = () => {
305312
if (cmdLineOptions.bundle) return esbuildServer.build();
306-
writeCJSReexport("./built/local/tsserver/server.js", "./built/local/tsserver.js");
313+
writeServerCJSShim();
307314
return buildProject("src/tsserver");
308315
};
309316
buildServer.displayName = "buildServer";
@@ -319,8 +326,11 @@ cleanTasks.push(cleanServer);
319326
task("clean-tsserver", cleanServer);
320327
task("clean-tsserver").description = "Cleans outputs for the language server";
321328

322-
// TODO(jakebailey): watch mode doesn't mix with --bundle=false.
323-
const watchServer = () => cmdLineOptions.bundle ? esbuildServer.watch() : watchProject("src/tsserver");
329+
const watchServer = () => {
330+
if (cmdLineOptions.bundle) return esbuildServer.watch();
331+
writeServerCJSShim();
332+
return watchProject("src/tsserver");
333+
};
324334
task("watch-tsserver", series(preBuild, parallel(watchLib, watchDiagnostics, watchServer)));
325335
task("watch-tsserver").description = "Watch for changes and rebuild the language server only";
326336
task("watch-tsserver").flags = {
@@ -343,11 +353,12 @@ task("watch-min").flags = {
343353
};
344354

345355
const esbuildLssl = esbuildTask("./src/tsserverlibrary/tsserverlibrary.ts", "./built/local/tsserverlibrary.js", /* exportIsTsObject */ true, /* performanceMatters */ true);
356+
const writeLsslCJSShim = () => writeCJSReexport("./built/local/tsserverlibrary/tsserverlibrary.js", "./built/local/tsserverlibrary.js");
346357

347358
const buildLsslProject = () => buildProject("src/tsserverlibrary");
348359
const buildLssl = () => {
349360
if (cmdLineOptions.bundle) return esbuildLssl.build();
350-
writeCJSReexport("./built/local/tsserverlibrary/tsserverlibrary.js", "./built/local/tsserverlibrary.js");
361+
writeLsslCJSShim();
351362
return buildLsslProject();
352363
};
353364
task("lssl", series(preBuild, buildLssl));
@@ -361,9 +372,11 @@ cleanTasks.push(cleanLssl);
361372
task("clean-lssl", cleanLssl);
362373
task("clean-lssl").description = "Clean outputs for the language service server library";
363374

364-
// TODO(jakebailey): watch mode doesn't mix with --bundle=false.
365-
const watchLssl = () => cmdLineOptions.bundle ? esbuildLssl.watch() : watchProject("src/tsserverlibrary");
366-
375+
const watchLssl = () => {
376+
if (cmdLineOptions.bundle) return esbuildLssl.watch();
377+
writeLsslCJSShim();
378+
return watchProject("src/tsserverlibrary");
379+
};
367380
task("watch-lssl", series(preBuild, parallel(watchLib, watchDiagnostics, watchLssl)));
368381
task("watch-lssl").description = "Watch for changes and rebuild tsserverlibrary only";
369382
task("watch-lssl").flags = {
@@ -380,10 +393,11 @@ task("dts", dts);
380393

381394
const testRunner = "./built/local/run.js";
382395
const esbuildTests = esbuildTask("./src/testRunner/_namespaces/Harness.ts", testRunner);
396+
const writeTestsCJSShim = () => writeCJSReexport("./built/local/testRunner/runner.js", testRunner);
383397

384398
const buildTests = () => {
385399
if (cmdLineOptions.bundle) return esbuildTests.build();
386-
writeCJSReexport("./built/local/testRunner/runner.js", testRunner);
400+
writeTestsCJSShim();
387401
return buildProject("src/testRunner");
388402
};
389403
task("tests", series(preBuild, parallel(buildLssl, buildTests)));
@@ -397,8 +411,11 @@ cleanTasks.push(cleanTests);
397411
task("clean-tests", cleanTests);
398412
task("clean-tests").description = "Cleans the outputs for the test infrastructure";
399413

400-
// TODO(jakebailey): watch mode doesn't mix with --bundle=false.
401-
const watchTests = () => cmdLineOptions.bundle ? esbuildTests.watch() : watchProject("src/testRunner");
414+
const watchTests = () => {
415+
if (cmdLineOptions.bundle) return esbuildTests.watch();
416+
writeTestsCJSShim();
417+
return watchProject("src/testRunner");
418+
};
402419

403420
const buildEslintRules = () => buildProject("scripts/eslint");
404421
task("build-eslint-rules", buildEslintRules);
@@ -450,7 +467,6 @@ const esbuildTypingsInstaller = esbuildTask("./src/typingsInstaller/nodeTypingsI
450467

451468
const buildTypingsInstaller = () => {
452469
if (cmdLineOptions.bundle) return esbuildTypingsInstaller.build();
453-
// TODO(jakebailey): In --bundle=false, can we emit to this directly?
454470
writeCJSReexport("./built/typingsInstaller/nodeTypingsInstaller.js", "./built/local/typingsInstaller.js");
455471
return buildProject("src/typingsInstaller");
456472
};
@@ -584,16 +600,19 @@ task("importDefinitelyTypedTests").description = "Runs the importDefinitelyTyped
584600
const cleanBuilt = () => del("built");
585601

586602
const produceLKG = async () => {
587-
// TODO(jakebailey): there are probably more files here that are needed.
603+
if (!cmdLineOptions.bundle) {
604+
throw new Error("LKG cannot be created when --bundle=false");
605+
}
606+
588607
const expectedFiles = [
608+
"built/local/cancellationToken.js",
589609
"built/local/tsc.js",
590610
"built/local/tsserver.js",
591-
"built/local/typescript.js",
592-
"built/local/typescript.d.ts",
593611
"built/local/tsserverlibrary.js",
594612
"built/local/tsserverlibrary.d.ts",
613+
"built/local/typescript.js",
614+
"built/local/typescript.d.ts",
595615
"built/local/typingsInstaller.js",
596-
"built/local/cancellationToken.js",
597616
"built/local/watchGuard.js",
598617
].concat(libs.map(lib => lib.target));
599618
const missingFiles = expectedFiles
@@ -624,8 +643,6 @@ task("generate-spec").description = "Generates a Markdown version of the Languag
624643
task("clean", series(parallel(cleanTasks), cleanBuilt));
625644
task("clean").description = "Cleans build outputs";
626645

627-
// TODO(jakebailey): Figure out what needs to change below.
628-
629646
const configureNightly = () => exec(process.execPath, ["scripts/configurePrerelease.js", "dev", "package.json", "src/compiler/corePublic.ts"]);
630647
task("configure-nightly", series(buildScripts, configureNightly));
631648
task("configure-nightly").description = "Runs scripts/configurePrerelease.ts to prepare a build for nightly publishing";

scripts/dtsBundler.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ function getDeclarationStatement(node: ts.Declaration): ts.Statement | undefined
6161

6262
const nullTransformationContext: ts.TransformationContext = (ts as any).nullTransformationContext;
6363

64-
// TODO(jakebailey): I can't seem to figure out how to load the real tsconfig, so, this will have to do.
65-
// But, why don't we get trailing commas?
6664
const program = ts.createProgram([entrypoint], { target: ts.ScriptTarget.ES5 });
6765

6866
const typeChecker = program.getTypeChecker();

scripts/produceLKG.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as glob from "glob";
88
const root = path.join(__dirname, "..");
99
const source = path.join(root, "built/local");
1010
const dest = path.join(root, "lib");
11-
const copyright = fs.readFileSync(path.join(__dirname, "../CopyrightNotice.txt"), "utf-8");
1211

1312
async function produceLKG() {
1413
console.log(`Building LKG from ${source} to ${dest}`);
@@ -65,8 +64,6 @@ async function copyTypesMap() {
6564
}
6665

6766
async function copyScriptOutputs() {
68-
// TODO(jakebailey): This does not work when unbundled.
69-
// TODO(jakebailey): Copyright is added by esbuild; maybe we should do it here?
7067
await copyFromBuiltLocal("cancellationToken.js");
7168
await copyFromBuiltLocal("tsc.js");
7269
await copyFromBuiltLocal("tsserver.js");
@@ -77,18 +74,19 @@ async function copyScriptOutputs() {
7774
}
7875

7976
async function copyDeclarationOutputs() {
80-
await copyWithCopyright("tsserverlibrary.d.ts");
81-
await copyWithCopyright("typescript.d.ts");
77+
await copyFromBuiltLocal("tsserverlibrary.d.ts");
78+
await copyFromBuiltLocal("typescript.d.ts");
8279
}
8380

8481
async function writeGitAttributes() {
8582
await fs.writeFile(path.join(dest, ".gitattributes"), `* text eol=lf`, "utf-8");
8683
}
8784

88-
async function copyWithCopyright(fileName: string, destName = fileName) {
89-
const content = await fs.readFile(path.join(source, fileName), "utf-8");
90-
await fs.writeFile(path.join(dest, destName), copyright + "\n" + content);
91-
}
85+
// const copyright = fs.readFileSync(path.join(__dirname, "../CopyrightNotice.txt"), "utf-8");
86+
// async function copyWithCopyright(fileName: string, destName = fileName) {
87+
// const content = await fs.readFile(path.join(source, fileName), "utf-8");
88+
// await fs.writeFile(path.join(dest, destName), copyright + "\n" + content);
89+
// }
9290

9391
async function copyFromBuiltLocal(fileName: string) {
9492
await fs.copy(path.join(source, fileName), path.join(dest, fileName));

0 commit comments

Comments
 (0)