perf(build): stop unpacking node_modules wholesale from the Windows asar #5877
main fromrefs/pull/5877/headmerged by shivamhwp(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- scripts/lib/cli-external-packages.test.ts line 274OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +98,21 @@98+ manifest = require(`${name}/package.json`);99+ } catch {100+ // Not installed on this platform (or reached only by prefix); nothing101+ // to check. The globs still cover it if it does get installed.102+ continue;103+ }104+105+ for (const dependency of Object.keys(manifest.dependencies ?? {})) {106+ if (!isExternal(dependency)) {107+ violations.push(`${name} -> ${dependency}`);108+ }109+ if (!seen.has(dependency)) queue.push(dependency);110+ }111+ }112+113+ assert.deepStrictEqual(114+ violations,115+ [],116+ `these dependencies of external packages would be bundled away, and fail to resolve under WSL: ${violations.join(", ")}`,117+ );118+ });
- apps/desktop/src/wsl/DesktopWslEnvironment.ts line 473Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -462,8 +465,9 @@462465 } as const;463466 }464467465- // Server dependencies (e.g. "effect") couldn't be resolved on the WSL466- // filesystem — a packaging regression, since the server bundle needs its467- // node_modules unpacked from the asar. Fatal so wsl-only mode falls back to468- // Windows and dual mode surfaces the reason inline, instead of the server469- // crash-looping on ERR_MODULE_NOT_FOUND once it actually launches.468+ // The packages the server bundle leaves external (node-pty and the other469+ // native addons) couldn't be resolved on the WSL filesystem — a packaging470+ // regression, since those must be unpacked from the asar. Fatal so wsl-only471+ // mode falls back to Windows and dual mode surfaces the reason inline,472+ // instead of the server crash-looping on ERR_MODULE_NOT_FOUND once it473+ // actually launches.
- scripts/lib/cli-external-packages.ts line 128Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +91,21 @@91+ * paths are unpacked for the link target to exist on disk.92+ */93+export const CLI_EXTERNAL_PACKAGE_UNPACK_GLOBS = CLI_EXTERNAL_PACKAGE_PREFIXES.flatMap(94+ (prefix) =>95+ [`node_modules/${prefix}*/**/*`, `node_modules/.pnpm/**/node_modules/${prefix}*/**/*`] as const,96+);97+98+/**99+ * Scan an emitted bundle chunk for runtime-external packages that were inlined.100+ *101+ * Configuring the bundler is not the same as checking what it produced. The102+ * `alwaysBundle` predicate only forces packages IN; returning false from it103+ * means "no opinion", so a transitive dependency still gets bundled by default.104+ * msgpackr-extract, node-gyp-build-optional-packages and detect-libc were105+ * inlined that way while every list-based test passed, which is why this reads106+ * the artifact instead.107+ *108+ * `regionCount` is reported so the caller can tell "nothing was inlined" apart109+ * from "the marker format changed and this scan no longer sees anything".110+ */111+export function findInlinedExternalPackages(source: string): {
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -1180,0 +1398,21 @@1398+ return yield* new BundleNotSelfContainedError({1399+ exitCode: -1,1400+ output: `Expected the server entry at ${entryPoint}.`,1401+ });1402+ }1403+1404+ // --version exercises the eagerly loaded module graph, which is where a1405+ // missing dependency shows up, without starting a server or touching disk1406+ // state. It does not cover lazily imported externals: node-pty is checked1407+ // by the WSL preflight probe at runtime, while ffi-rs, @ff-labs/fff-node1408+ // and the bun adapters are only covered by the unpack globs and the1409+ // inlined-native check below.1410+ yield* runCommand(1411+ ChildProcess.make(process.execPath, [entryPoint, "--version"], {1412+ cwd: probeApp,1413+ stdout: "pipe",1414+ stderr: "pipe",1415+ // NODE_PATH would let a createRequire call inside the bundle resolve a1416+ // missing external from outside the packaged tree, which is the whole1417+ // thing this is trying to rule out.1418+ env: { ...process.env, NODE_PATH: "" },
SunkenInTime(GitHub profile, opens in a new tab) approved these changes
t3-code-bot[bot](GitHub profile, opens in a new tab) approved these changes
t3-code-bot[bot](GitHub profile, opens in a new tab) requested changes
- scripts/build-desktop-artifact.ts line 1387OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1180,0 +1367,21 @@1367+ destinationDirectory: string,1368+ ): Effect.Effect<void, PlatformError> =>1369+ Effect.gen(function* () {1370+ for (const entry of yield* fs.readDirectory(sourceDirectory)) {1371+ const sourceEntry = path.join(sourceDirectory, entry);1372+ const destinationEntry = path.join(destinationDirectory, entry);1373+ const linkTarget = yield* fs.readLink(sourceEntry).pipe(Effect.option);1374+ if (Option.isSome(linkTarget)) {1375+ const sourceRelativeTarget = path.isAbsolute(linkTarget.value)1376+ ? path.relative(source, linkTarget.value)1377+ : null;1378+ const target =1379+ sourceRelativeTarget !== null &&1380+ sourceRelativeTarget !== ".." &&1381+ !sourceRelativeTarget.startsWith(`..${path.sep}`) &&1382+ !path.isAbsolute(sourceRelativeTarget)1383+ ? path.relative(1384+ path.dirname(destinationEntry),1385+ path.join(destination, sourceRelativeTarget),1386+ )1387+ : linkTarget.value;
t3-code-bot[bot](GitHub profile, opens in a new tab) approved these changes
UtkarshUsername(GitHub profile, opens in a new tab) approved these changes
shivamhwp(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
f64d68f4-cfe1-4e3c-949a-2d2df8a347cfYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share