The best way to control Claude Code, Codex and more from any computer or phone
fix(release): stop npm from pruning the platform packages' shipped node_modules (#11750)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Julius Marminge committed
Sep 14, 2026 at 09:10 UTC
ae67c5b8159cb49a68c16f96f7bb64a2e3c6b1c6
2 files changed
+67
-4
scripts/build-npm-platform-packages.test.ts
+21
-1
@@ -55,9 +55,22 @@ const makeFakeArchives = Effect.fn("test.makeFakeArchives")(function* () {
55
const stem = `t3-${VERSION}-${key}`;
56
const stage = path.join(root, "stage", key);
57
const contentDir = path.join(stage, stem);
58
- for (const dir of ["client", "resource-monitor", "node_modules/node-pty"]) {
58
+ for (const dir of [
59
+ "client",
60
+ "resource-monitor",
61
+ "node_modules/node-pty",
62
+ "node_modules/@ff-labs/fff-node",
63
+ ]) {
64
yield* fs.makeDirectory(path.join(contentDir, dir), { recursive: true });
65
}
66
+ yield* fs.writeFileString(
67
+ path.join(contentDir, "node_modules/node-pty/package.json"),
68
+ '{ "name": "node-pty", "version": "1.1.0" }\n',
69
+ );
70
+ yield* fs.writeFileString(
71
+ path.join(contentDir, "node_modules/@ff-labs/fff-node/package.json"),
72
+ '{ "name": "@ff-labs/fff-node", "version": "0.9.4" }\n',
73
+ );
74
yield* fs.writeFileString(path.join(contentDir, "client/index.html"), "<html></html>\n");
75
yield* fs.writeFileString(
76
path.join(contentDir, "t3"),
@@ -127,6 +140,13 @@ it.layer(NodeServices.layer)("build-npm-platform-packages", (it) => {
140
]);
141
assert.equal(linuxManifest.preferUnplugged, true);
142
assert.isUndefined(linuxManifest.bin);
143
+ // The shipped node_modules is declared, or npm prunes it as extraneous
144
+ // on the next install in the same project and the executable breaks.
145
+ assert.deepStrictEqual(linuxManifest.dependencies, {
146
+ "@ff-labs/fff-node": "0.9.4",
147
+ "node-pty": "1.1.0",
148
+ });
149
+ assert.deepStrictEqual(linuxManifest.bundleDependencies, ["@ff-labs/fff-node", "node-pty"]);
150
// Archive contents sit at the package root, not under the archive stem.
151
assert.isTrue(yield* fs.exists(path.join(linuxDir, "client/index.html")));
152
// A root README, or npm would display a bundled dependency's.
scripts/build-npm-platform-packages.ts
+46
-3
@@ -88,9 +88,22 @@ export function npmPlatformPackageName(platformKey: CliArchivePlatformKey): stri
88
return `${NPM_PLATFORM_PACKAGE_SCOPE}/t3-${platformKey}`;
89
}
90
91
-/** package.json for one platform package; `os`/`cpu` let npm skip the other five. */
92
-export function npmPlatformPackageManifest(platformKey: CliArchivePlatformKey, version: string) {
91
+/**
92
+ * package.json for one platform package; `os`/`cpu` let npm skip the other
93
+ * five. The archive's runtime `node_modules` (native addons and their
94
+ * loaders) ships inside the tarball, and npm only keeps a nested tree it can
95
+ * account for: anything not declared is extraneous and pruned on the next
96
+ * `npm install` in that project, which then breaks the executable. Declaring
97
+ * every bundled package as a bundled dependency at the exact version on disk
98
+ * makes npm treat the tree as part of this package and leave it alone.
99
+ */
100
+export function npmPlatformPackageManifest(
101
+ platformKey: CliArchivePlatformKey,
102
+ version: string,
103
+ bundled: Readonly<Record<string, string>>,
104
+) {
105
const [os, cpu] = platformKey.split("-") as [string, string];
106
+ const bundleDependencies = Object.keys(bundled).sort();
107
return {
108
name: npmPlatformPackageName(platformKey),
109
version,
@@ -101,9 +114,38 @@ export function npmPlatformPackageManifest(platformKey: CliArchivePlatformKey, v
114
cpu: [cpu],
115
files: ["t3", "t3.exe", "client", "resource-monitor", "node_modules"],
116
preferUnplugged: true,
117
+ dependencies: Object.fromEntries(bundleDependencies.map((name) => [name, bundled[name]])),
118
+ bundleDependencies,
119
};
120
}
121
122
+const PackageVersion = Schema.Struct({ version: Schema.String });
123
+const decodePackageVersion = Schema.decodeUnknownEffect(Schema.fromJsonString(PackageVersion));
124
+
125
+/** Every top-level package under `node_modules`, scoped ones included, at the version its manifest names. */
126
+const readBundledPackages = Effect.fn("readBundledPackages")(function* (nodeModulesDir: string) {
127
+ const fs = yield* FileSystem.FileSystem;
128
+ const path = yield* Path.Path;
129
+ const bundled: Record<string, string> = {};
130
+ const packageDirs: Array<{ readonly name: string; readonly dir: string }> = [];
131
+ for (const entry of yield* fs.readDirectory(nodeModulesDir)) {
132
+ if (entry.startsWith(".")) continue;
133
+ const dir = path.join(nodeModulesDir, entry);
134
+ if (entry.startsWith("@")) {
135
+ for (const scoped of yield* fs.readDirectory(dir)) {
136
+ packageDirs.push({ name: `${entry}/${scoped}`, dir: path.join(dir, scoped) });
137
+ }
138
+ } else {
139
+ packageDirs.push({ name: entry, dir });
140
+ }
141
+ }
142
+ for (const { name, dir } of packageDirs) {
143
+ const manifest = yield* fs.readFileString(path.join(dir, "package.json"));
144
+ bundled[name] = (yield* decodePackageVersion(manifest)).version;
145
+ }
146
+ return bundled;
147
+});
148
+
149
/**
150
* README for one platform package. Without one at the package root, npm
151
* shows the first README it finds in the tarball, which is a bundled
@@ -302,9 +344,10 @@ const stagePlatformPackage = Effect.fn("stagePlatformPackage")(function* (input:
344
if (executableName === "t3") {
345
yield* fs.chmod(executable, 0o755);
346
}
347
+ const bundled = yield* readBundledPackages(path.join(contentDir, "node_modules"));
348
yield* fs.writeFileString(
349
path.join(contentDir, "package.json"),
307
- `${yield* encodePackageJson(npmPlatformPackageManifest(input.key, input.version))}\n`,
350
+ `${yield* encodePackageJson(npmPlatformPackageManifest(input.key, input.version, bundled))}\n`,
351
);
352
yield* fs.writeFileString(
353
path.join(contentDir, "README.md"),