Skip to content

Commit 438d60c

Browse files
committed
Add dts bundling
This adds a "small" d.ts bundler script. This script is very basic, using Node printing to produce its output. Generally speaking, this is inadvisable as it completely disregards name shadowing, globals, etc. However, in our case, we don't care about the globals, and we can opt to restructure our codebase in order to avoid conflict, which we largely had to do anyway when we were namespaces and everything was in scope.
1 parent e13f8d7 commit 438d60c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8005
-7801
lines changed

Diff for: Gulpfile.mjs

+31-6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ task("build-src", series(preSrc, buildSrc));
128128
const cleanSrc = () => cleanProject("src");
129129
task("clean-src", cleanSrc);
130130

131+
/**
132+
* @param {string} entrypoint
133+
* @param {string} output
134+
*/
135+
async function runDtsBundler(entrypoint, output) {
136+
await exec(process.execPath, [
137+
"./scripts/dtsBundler.mjs",
138+
"--entrypoint",
139+
entrypoint,
140+
"--output",
141+
output,
142+
]);
143+
}
131144

132145
/** @type {string | undefined} */
133146
let copyrightHeader;
@@ -275,6 +288,7 @@ const esbuildServices = esbuildTask("./src/typescript/typescript.ts", "./built/l
275288
const writeServicesCJSShim = () => writeCJSReexport("./built/local/typescript/typescript.js", "./built/local/typescript.js");
276289
const buildServicesProject = () => buildProject("src/typescript");
277290

291+
// TODO(jakebailey): rename this; no longer "services".
278292
const buildServices = () => {
279293
if (cmdLineOptions.bundle) return esbuildServices.build();
280294
writeServicesCJSShim();
@@ -304,6 +318,9 @@ task("watch-services").flags = {
304318
" --built": "Compile using the built version of the compiler."
305319
};
306320

321+
const dtsServices = () => runDtsBundler("./built/local/typescript/typescript.d.ts", "./built/local/typescript.d.ts");
322+
task("dts-services", series(preBuild, buildServicesProject, dtsServices));
323+
task("dts-services").description = "Builds typescript.d.ts";
307324

308325
const esbuildServer = esbuildTask("./src/tsserver/server.ts", "./built/local/tsserver.js", /* exportIsTsObject */ true);
309326
const writeServerCJSShim = () => writeCJSReexport("./built/local/tsserver/server.js", "./built/local/tsserver.js");
@@ -355,10 +372,11 @@ task("watch-min").flags = {
355372
const esbuildLssl = esbuildTask("./src/tsserverlibrary/tsserverlibrary.ts", "./built/local/tsserverlibrary.js", /* exportIsTsObject */ true);
356373
const writeLsslCJSShim = () => writeCJSReexport("./built/local/tsserverlibrary/tsserverlibrary.js", "./built/local/tsserverlibrary.js");
357374

375+
const buildLsslProject = () => buildProject("src/tsserverlibrary");
358376
const buildLssl = () => {
359377
if (cmdLineOptions.bundle) return esbuildLssl.build();
360378
writeLsslCJSShim();
361-
return buildProject("src/tsserverlibrary");
379+
return buildLsslProject();
362380
};
363381
task("lssl", series(preBuild, buildLssl));
364382
task("lssl").description = "Builds language service server library";
@@ -382,6 +400,14 @@ task("watch-lssl").flags = {
382400
" --built": "Compile using the built version of the compiler."
383401
};
384402

403+
const dtsLssl = () => runDtsBundler("./built/local/tsserverlibrary/tsserverlibrary.d.ts", "./built/local/tsserverlibrary.d.ts");
404+
task("dts-lssl", series(preBuild, buildLsslProject, dtsLssl));
405+
task("dts-lssl").description = "Builds tsserverlibrary.d.ts";
406+
407+
// TODO(jakebailey): this is probably not efficient, but, gulp.
408+
const dts = series(preBuild, parallel(buildServicesProject, buildLsslProject), parallel(dtsServices, dtsLssl));
409+
task("dts", dts);
410+
385411
const testRunner = "./built/local/run.js";
386412
const esbuildTests = esbuildTask("./src/testRunner/_namespaces/Harness.ts", testRunner);
387413
const writeTestsCJSShim = () => writeCJSReexport("./built/local/testRunner/runner.js", testRunner);
@@ -492,7 +518,7 @@ const buildOtherOutputs = parallel(buildCancellationToken, buildTypingsInstaller
492518
task("other-outputs", series(preBuild, buildOtherOutputs));
493519
task("other-outputs").description = "Builds miscelaneous scripts and documents distributed with the LKG";
494520

495-
task("local", series(preBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildOtherOutputs)));
521+
task("local", series(preBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildOtherOutputs, dts)));
496522
task("local").description = "Builds the full compiler and services";
497523
task("local").flags = {
498524
" --built": "Compile using the built version of the compiler."
@@ -508,7 +534,7 @@ const preTest = parallel(buildTsc, buildTests, buildServices, buildLssl);
508534
preTest.displayName = "preTest";
509535

510536
const runTests = () => runConsoleTests(testRunner, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ false);
511-
task("runtests", series(preBuild, preTest, runTests));
537+
task("runtests", series(preBuild, preTest, dts, runTests));
512538
task("runtests").description = "Runs the tests using the built run.js file.";
513539
task("runtests").flags = {
514540
"-t --tests=<regex>": "Pattern for tests to run.",
@@ -527,7 +553,7 @@ task("runtests").flags = {
527553
};
528554

529555
const runTestsParallel = () => runConsoleTests(testRunner, "min", /*runInParallel*/ cmdLineOptions.workers > 1, /*watchMode*/ false);
530-
task("runtests-parallel", series(preBuild, preTest, runTestsParallel));
556+
task("runtests-parallel", series(preBuild, preTest, dts, runTestsParallel));
531557
task("runtests-parallel").description = "Runs all the tests in parallel using the built run.js file.";
532558
task("runtests-parallel").flags = {
533559
" --light": "Run tests in light mode (fewer verifications, but tests run faster).",
@@ -613,8 +639,7 @@ const produceLKG = async () => {
613639
}
614640
};
615641

616-
// TODO(jakebailey): dependencies on dts
617-
task("LKG", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildOtherOutputs), produceLKG));
642+
task("LKG", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildOtherOutputs, dts), produceLKG));
618643
task("LKG").description = "Makes a new LKG out of the built js files";
619644
task("LKG").flags = {
620645
" --built": "Compile using the built version of the compiler.",

0 commit comments

Comments
 (0)