Skip to content

Commit

Permalink
Move compiler-debug into Debug namespace, which allows the compiler t…
Browse files Browse the repository at this point in the history
…o be tree shaken

This debug code was added quite a while ago, constructed such that we
wouldn't have to ship this code to our users.

However, this is the sole place in the compiler project where the ts
namespace "escapes" the bundle. By moving this debug code into the
compiler itself, we no longer have any references to the ts namespace
itself for our bundles that don't export anything (tsc,
typingsInstaller). This lets bundlers tree shake the compiler, reducing
the size of our output by _5.7 MB_ (a ridiculous improvement for
_adding_ code).
  • Loading branch information
jakebailey committed Nov 7, 2022
1 parent c5a9573 commit 25a85d1
Show file tree
Hide file tree
Showing 5 changed files with 391 additions and 574 deletions.
19 changes: 5 additions & 14 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,6 @@ function entrypointBuildTask(options) {
return { build, bundle, shim, main, watch };
}

const { main: compilerDebug } = entrypointBuildTask({
name: "compiler-debug",
buildDeps: [generateDiagnostics],
project: "src/debug",
srcEntrypoint: "./src/debug/compilerDebug.ts",
builtEntrypoint: "./built/local/debug/compilerDebug.js",
output: "./built/local/compiler-debug.js",
});


const { main: tsc, watch: watchTsc } = entrypointBuildTask({
name: "tsc",
Expand All @@ -382,7 +373,7 @@ const { main: tsc, watch: watchTsc } = entrypointBuildTask({
srcEntrypoint: "./src/tsc/tsc.ts",
builtEntrypoint: "./built/local/tsc/tsc.js",
output: "./built/local/tsc.js",
mainDeps: [generateLibs, compilerDebug],
mainDeps: [generateLibs],
});
export { tsc, watchTsc };

Expand All @@ -395,7 +386,7 @@ const { main: services, build: buildServices, watch: watchServices } = entrypoin
srcEntrypoint: "./src/typescript/typescript.ts",
builtEntrypoint: "./built/local/typescript/typescript.js",
output: "./built/local/typescript.js",
mainDeps: [generateLibs, compilerDebug],
mainDeps: [generateLibs],
bundlerOptions: { exportIsTsObject: true },
});
export { services, watchServices };
Expand All @@ -420,7 +411,7 @@ const { main: tsserver, watch: watchTsserver } = entrypointBuildTask({
srcEntrypoint: "./src/tsserver/server.ts",
builtEntrypoint: "./built/local/tsserver/server.js",
output: "./built/local/tsserver.js",
mainDeps: [generateLibs, compilerDebug],
mainDeps: [generateLibs],
// Even though this seems like an exectuable, so could be the default CJS,
// this is used in the browser too. Do the same thing that we do for our
// libraries and generate an IIFE with name `ts`, as to not pollute the global
Expand Down Expand Up @@ -453,7 +444,7 @@ const { main: lssl, build: buildLssl, watch: watchLssl } = entrypointBuildTask({
srcEntrypoint: "./src/tsserverlibrary/tsserverlibrary.ts",
builtEntrypoint: "./built/local/tsserverlibrary/tsserverlibrary.js",
output: "./built/local/tsserverlibrary.js",
mainDeps: [generateLibs, compilerDebug],
mainDeps: [generateLibs],
bundlerOptions: { exportIsTsObject: true },
});
export { lssl, watchLssl };
Expand Down Expand Up @@ -485,7 +476,7 @@ const { main: tests, watch: watchTests } = entrypointBuildTask({
srcEntrypoint: "./src/testRunner/_namespaces/Harness.ts",
builtEntrypoint: "./built/local/testRunner/runner.js",
output: testRunner,
mainDeps: [generateLibs, compilerDebug],
mainDeps: [generateLibs],
bundlerOptions: {
// Ensure we never drop any dead code, which might be helpful while debugging.
treeShaking: false,
Expand Down
Loading

0 comments on commit 25a85d1

Please sign in to comment.