sliftutils 1.7.7 → 1.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,10 +12,22 @@ async function main() {
12
12
  if (!outputFolder) {
13
13
  throw new Error("No output folder provided. Please use the --outputFolder option.");
14
14
  }
15
- // We prefer production, as this is what the bundler uses internally. This ensures that in the build and when run, we will have the same environment, which will result in the same requires being called.
15
+ // We prefer production, as this is what the bundler uses internally. This ensures that in the build and when run, we will have the same environment, which will result in the same requires being called.
16
16
  process.env.NODE_ENV = process.env.NODE_ENV || "production";
17
17
  require(entryPoint);
18
18
 
19
+ // Warm pass: this process only exists to compile the entry's whole graph
20
+ // (and this bundler's own modules, compiled at our startup) into typenode's
21
+ // on-disk cache, then exit. The caller runs a SECOND, fresh process for the
22
+ // real bundle — that process reads everything from the warm cache and so
23
+ // never has typenode lazy-load the TypeScript compiler. Without this, a
24
+ // cold-cache build (e.g. a fresh CI/server checkout, or an entry whose files
25
+ // no other entry imports) leaves `typescript` in require.cache and the
26
+ // bundler serializes the entire 9 MB+ compiler into the output bundle.
27
+ if (process.argv[4] === "--warm") {
28
+ return;
29
+ }
30
+
19
31
  let name = path.basename(entryPoint);
20
32
  if (name.endsWith(".ts") || name.endsWith(".tsx")) {
21
33
  name = name.split(".").slice(0, -1).join(".");
@@ -10,5 +10,13 @@ export async function bundleEntryCaller(config: {
10
10
  entryPoint = path.resolve(entryPoint).replace(/\\/g, "/");
11
11
  outputFolder = path.resolve(outputFolder).replace(/\\/g, "/");
12
12
  let bundleEntryPath = path.resolve(__dirname, "bundleEntry.ts").replace(/\\/g, "/");
13
- await runPromise(`node -r ./node_modules/typenode/index.js ${JSON.stringify(bundleEntryPath)} ${JSON.stringify(entryPoint)} ${JSON.stringify(outputFolder)}`);
13
+ let base = `node -r ./node_modules/typenode/index.js ${JSON.stringify(bundleEntryPath)} ${JSON.stringify(entryPoint)} ${JSON.stringify(outputFolder)}`;
14
+ // Run twice in SEPARATE processes. The first ("--warm") only imports the
15
+ // entry, which compiles its whole graph into typenode's on-disk cache. The
16
+ // second is a fresh process that imports from that warm cache — so typenode
17
+ // never has to compile anything and never lazy-loads the TypeScript compiler,
18
+ // which would otherwise be captured in require.cache and serialized (9 MB+)
19
+ // into the output bundle. See bundleEntry.ts.
20
+ await runPromise(`${base} --warm`);
21
+ await runPromise(base);
14
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sliftutils",
3
- "version": "1.7.7",
3
+ "version": "1.7.8",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "files": [