@nimbus-sh/worker 0.9.0 → 0.11.0

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.
Files changed (286) hide show
  1. package/NOTICE.md +5 -0
  2. package/README.md +10 -0
  3. package/dist/_shared/session-router.d.ts +7 -0
  4. package/dist/_shared/session-router.d.ts.map +1 -1
  5. package/dist/_shared/session-router.js +7 -0
  6. package/dist/bindings/body.d.ts +6 -0
  7. package/dist/bindings/body.d.ts.map +1 -0
  8. package/dist/bindings/body.js +37 -0
  9. package/dist/bindings/kv.d.ts +0 -2
  10. package/dist/bindings/kv.d.ts.map +1 -1
  11. package/dist/bindings/kv.js +3 -42
  12. package/dist/bindings/r2.d.ts +0 -2
  13. package/dist/bindings/r2.d.ts.map +1 -1
  14. package/dist/bindings/r2.js +4 -44
  15. package/dist/esbuild-cli-artifact.generated.d.ts +18 -0
  16. package/dist/esbuild-cli-artifact.generated.d.ts.map +1 -0
  17. package/dist/esbuild-cli-artifact.generated.js +17 -0
  18. package/dist/esbuild-wasm-bundle.generated.d.ts +24 -24
  19. package/dist/esbuild-wasm-bundle.generated.d.ts.map +1 -1
  20. package/dist/esbuild-wasm-bundle.generated.js +24 -24
  21. package/dist/facets/cirrus-real.d.ts.map +1 -1
  22. package/dist/facets/cirrus-real.js +11 -6
  23. package/dist/facets/compose.d.ts +11 -7
  24. package/dist/facets/compose.d.ts.map +1 -1
  25. package/dist/facets/compose.js +8 -31
  26. package/dist/facets/data-plan.d.ts +79 -0
  27. package/dist/facets/data-plan.d.ts.map +1 -0
  28. package/dist/facets/data-plan.js +477 -0
  29. package/dist/facets/esbuild-bundle-pool.d.ts +1 -1
  30. package/dist/facets/esbuild-bundle-pool.js +3 -3
  31. package/dist/facets/esbuild-transform.d.ts +38 -8
  32. package/dist/facets/esbuild-transform.d.ts.map +1 -1
  33. package/dist/facets/esbuild-transform.js +219 -19
  34. package/dist/facets/exec-telemetry.d.ts +7 -3
  35. package/dist/facets/exec-telemetry.d.ts.map +1 -1
  36. package/dist/facets/manager.d.ts +198 -69
  37. package/dist/facets/manager.d.ts.map +1 -1
  38. package/dist/facets/manager.js +1276 -652
  39. package/dist/facets/opencode-staging.d.ts +0 -2
  40. package/dist/facets/opencode-staging.d.ts.map +1 -1
  41. package/dist/facets/opencode-staging.js +5 -11
  42. package/dist/facets/process.d.ts +4 -0
  43. package/dist/facets/process.d.ts.map +1 -1
  44. package/dist/facets/process.js +3 -0
  45. package/dist/facets/read-profile.d.ts +149 -0
  46. package/dist/facets/read-profile.d.ts.map +1 -0
  47. package/dist/facets/read-profile.js +483 -0
  48. package/dist/facets/real-vite-hmr.d.ts +2 -0
  49. package/dist/facets/real-vite-hmr.d.ts.map +1 -1
  50. package/dist/facets/real-vite-hmr.js +3 -2
  51. package/dist/facets/resident-identity.d.ts +0 -1
  52. package/dist/facets/resident-identity.d.ts.map +1 -1
  53. package/dist/facets/resident-identity.js +0 -3
  54. package/dist/facets/wasm-swap-registry.d.ts +34 -25
  55. package/dist/facets/wasm-swap-registry.d.ts.map +1 -1
  56. package/dist/facets/wasm-swap-registry.js +62 -56
  57. package/dist/facets/ws-terminal.d.ts +4 -4
  58. package/dist/facets/ws-terminal.d.ts.map +1 -1
  59. package/dist/facets/ws-terminal.js +4 -5
  60. package/dist/git/commands.d.ts +33 -10
  61. package/dist/git/commands.d.ts.map +1 -1
  62. package/dist/git/commands.js +1891 -197
  63. package/dist/git/network-facet.d.ts +12 -2
  64. package/dist/git/network-facet.d.ts.map +1 -1
  65. package/dist/git/network-facet.js +69 -18
  66. package/dist/git/unified-diff.d.ts +74 -0
  67. package/dist/git/unified-diff.d.ts.map +1 -0
  68. package/dist/git/unified-diff.js +676 -0
  69. package/dist/git-bundle.generated.d.ts +7 -11
  70. package/dist/git-bundle.generated.d.ts.map +1 -1
  71. package/dist/git-bundle.generated.js +7 -11
  72. package/dist/hosted/commands.d.ts.map +1 -1
  73. package/dist/hosted/commands.js +64 -245
  74. package/dist/hosted/runtime.d.ts +22 -15
  75. package/dist/hosted/runtime.d.ts.map +1 -1
  76. package/dist/hosted/runtime.js +72 -14
  77. package/dist/hosted/services.d.ts +8 -1
  78. package/dist/hosted/services.d.ts.map +1 -1
  79. package/dist/hosted/services.js +12 -13
  80. package/dist/hosted/session.d.ts +165 -0
  81. package/dist/hosted/session.d.ts.map +1 -0
  82. package/dist/hosted/session.js +132 -0
  83. package/dist/loaders/generated-workers.d.ts +6 -3
  84. package/dist/loaders/generated-workers.d.ts.map +1 -1
  85. package/dist/loaders/generated-workers.js +8 -5
  86. package/dist/loaders/npm-resolve-preamble.d.ts.map +1 -1
  87. package/dist/loaders/npm-resolve-preamble.js +0 -27
  88. package/dist/loaders/pre-bundle-preamble.d.ts +6 -3
  89. package/dist/loaders/pre-bundle-preamble.d.ts.map +1 -1
  90. package/dist/loaders/pre-bundle-preamble.js +13 -8
  91. package/dist/node-shims-artifact.generated.d.ts +13 -4
  92. package/dist/node-shims-artifact.generated.d.ts.map +1 -1
  93. package/dist/node-shims-artifact.generated.js +16 -7
  94. package/dist/npm/bin-links.d.ts +3 -1
  95. package/dist/npm/bin-links.d.ts.map +1 -1
  96. package/dist/npm/bin-links.js +32 -8
  97. package/dist/npm/cache.d.ts +11 -1
  98. package/dist/npm/cache.d.ts.map +1 -1
  99. package/dist/npm/cache.js +21 -7
  100. package/dist/npm/install-batch-facet.d.ts +4 -2
  101. package/dist/npm/install-batch-facet.d.ts.map +1 -1
  102. package/dist/npm/install-batch-facet.js +32 -18
  103. package/dist/npm/installer.d.ts +23 -3
  104. package/dist/npm/installer.d.ts.map +1 -1
  105. package/dist/npm/installer.js +330 -131
  106. package/dist/npm/npx-install.d.ts +3 -1
  107. package/dist/npm/npx-install.d.ts.map +1 -1
  108. package/dist/npm/npx-install.js +4 -1
  109. package/dist/npm/package-lock.d.ts +32 -0
  110. package/dist/npm/package-lock.d.ts.map +1 -0
  111. package/dist/npm/package-lock.js +65 -0
  112. package/dist/npm/placement.d.ts +16 -0
  113. package/dist/npm/placement.d.ts.map +1 -0
  114. package/dist/npm/placement.js +33 -0
  115. package/dist/npm/pre-bundle-facet.d.ts +1 -30
  116. package/dist/npm/pre-bundle-facet.d.ts.map +1 -1
  117. package/dist/npm/pre-bundle-facet.js +3 -5
  118. package/dist/npm/r2-cache.d.ts +12 -6
  119. package/dist/npm/r2-cache.d.ts.map +1 -1
  120. package/dist/npm/r2-cache.js +34 -16
  121. package/dist/npm/resolve-one-facet.d.ts +3 -0
  122. package/dist/npm/resolve-one-facet.d.ts.map +1 -1
  123. package/dist/npm/resolve-one-facet.js +15 -3
  124. package/dist/npm/resolver.d.ts +11 -13
  125. package/dist/npm/resolver.d.ts.map +1 -1
  126. package/dist/npm/resolver.js +12 -25
  127. package/dist/opencode-artifact.generated.js +2 -2
  128. package/dist/replica/routing.d.ts +2 -38
  129. package/dist/replica/routing.d.ts.map +1 -1
  130. package/dist/replica/routing.js +3 -55
  131. package/dist/router/index.d.ts.map +1 -1
  132. package/dist/router/index.js +15 -2
  133. package/dist/router/public-directory.d.ts +18 -0
  134. package/dist/router/public-directory.d.ts.map +1 -1
  135. package/dist/router/public-directory.js +1 -1
  136. package/dist/router/remote-api.d.ts +3 -1
  137. package/dist/router/remote-api.d.ts.map +1 -1
  138. package/dist/router/remote-api.js +42 -79
  139. package/dist/runtime/bash-repl.js +2 -2
  140. package/dist/runtime/bun-repl.d.ts.map +1 -1
  141. package/dist/runtime/bun-repl.js +2 -13
  142. package/dist/runtime/cpython-resident.d.ts.map +1 -1
  143. package/dist/runtime/cpython-resident.js +2 -10
  144. package/dist/runtime/esbuild-wasm-bytes.d.ts +37 -18
  145. package/dist/runtime/esbuild-wasm-bytes.d.ts.map +1 -1
  146. package/dist/runtime/esbuild-wasm-bytes.js +66 -92
  147. package/dist/runtime/facet-loader-host.d.ts.map +1 -1
  148. package/dist/runtime/facet-loader-host.js +0 -7
  149. package/dist/runtime/git-bundle-artifact.d.ts +17 -0
  150. package/dist/runtime/git-bundle-artifact.d.ts.map +1 -0
  151. package/dist/runtime/git-bundle-artifact.js +25 -0
  152. package/dist/runtime/node-repl.d.ts.map +1 -1
  153. package/dist/runtime/node-repl.js +2 -13
  154. package/dist/runtime/node-shims-artifact.d.ts +22 -23
  155. package/dist/runtime/node-shims-artifact.d.ts.map +1 -1
  156. package/dist/runtime/node-shims-artifact.js +48 -78
  157. package/dist/runtime/node-shims.d.ts.map +1 -1
  158. package/dist/runtime/node-shims.js +2358 -996
  159. package/dist/runtime/opencode-artifact.d.ts.map +1 -1
  160. package/dist/runtime/opencode-artifact.js +17 -53
  161. package/dist/runtime/opencode-facet-runner.d.ts +3 -6
  162. package/dist/runtime/opencode-facet-runner.d.ts.map +1 -1
  163. package/dist/runtime/opencode-facet-runner.js +45 -10
  164. package/dist/runtime/opentui-wasm-bytes.d.ts.map +1 -1
  165. package/dist/runtime/opentui-wasm-bytes.js +16 -49
  166. package/dist/runtime/package-manager.d.ts +0 -2
  167. package/dist/runtime/package-manager.d.ts.map +1 -1
  168. package/dist/runtime/package-manager.js +0 -3
  169. package/dist/runtime/python-repl.d.ts.map +1 -1
  170. package/dist/runtime/python-repl.js +4 -35
  171. package/dist/runtime/repl-session.d.ts +10 -0
  172. package/dist/runtime/repl-session.d.ts.map +1 -1
  173. package/dist/runtime/repl-session.js +7 -0
  174. package/dist/runtime/ruby-repl.d.ts.map +1 -1
  175. package/dist/runtime/ruby-repl.js +2 -2
  176. package/dist/runtime/ruby-resident.d.ts.map +1 -1
  177. package/dist/runtime/ruby-resident.js +41 -51
  178. package/dist/runtime/runtime-catalog.d.ts +10 -3
  179. package/dist/runtime/runtime-catalog.d.ts.map +1 -1
  180. package/dist/runtime/runtime-catalog.js +125 -15
  181. package/dist/runtime/sqlite-wasm-bytes.d.ts +4 -4
  182. package/dist/runtime/sqlite-wasm-bytes.d.ts.map +1 -1
  183. package/dist/runtime/sqlite-wasm-bytes.js +21 -57
  184. package/dist/runtime/staged-source.d.ts +67 -0
  185. package/dist/runtime/staged-source.d.ts.map +1 -0
  186. package/dist/runtime/staged-source.js +113 -0
  187. package/dist/runtime/wasi/preamble.d.ts +0 -22
  188. package/dist/runtime/wasi/preamble.d.ts.map +1 -1
  189. package/dist/runtime/wasi/preamble.js +98 -1425
  190. package/dist/runtime-catalog.generated.js +1 -1
  191. package/dist/session/agent.d.ts +14 -2
  192. package/dist/session/agent.d.ts.map +1 -1
  193. package/dist/session/agent.js +57 -19
  194. package/dist/session/ai.d.ts +0 -11
  195. package/dist/session/ai.d.ts.map +1 -1
  196. package/dist/session/ai.js +0 -4
  197. package/dist/session/fs-watch.d.ts +0 -11
  198. package/dist/session/fs-watch.d.ts.map +1 -1
  199. package/dist/session/fs-watch.js +0 -21
  200. package/dist/session/hibernation.d.ts +68 -2
  201. package/dist/session/hibernation.d.ts.map +1 -1
  202. package/dist/session/hibernation.js +95 -1
  203. package/dist/session/init-phases.d.ts +1 -2
  204. package/dist/session/init-phases.d.ts.map +1 -1
  205. package/dist/session/init-phases.js +1 -2
  206. package/dist/session/init.d.ts.map +1 -1
  207. package/dist/session/init.js +7 -20
  208. package/dist/session/keys.d.ts +0 -3
  209. package/dist/session/keys.d.ts.map +1 -1
  210. package/dist/session/keys.js +0 -3
  211. package/dist/session/legacy-reset.d.ts +11 -0
  212. package/dist/session/legacy-reset.d.ts.map +1 -0
  213. package/dist/session/legacy-reset.js +16 -0
  214. package/dist/session/nimbus-session.d.ts +50 -16
  215. package/dist/session/nimbus-session.d.ts.map +1 -1
  216. package/dist/session/nimbus-session.js +77 -71
  217. package/dist/session/npm-install-port.d.ts.map +1 -1
  218. package/dist/session/npm-install-port.js +2 -0
  219. package/dist/session/programmatic.d.ts +13 -18
  220. package/dist/session/programmatic.d.ts.map +1 -1
  221. package/dist/session/programmatic.js +53 -39
  222. package/dist/session/replica-routes.d.ts +2 -3
  223. package/dist/session/replica-routes.d.ts.map +1 -1
  224. package/dist/session/replica-routes.js +3 -10
  225. package/dist/session/routes.d.ts.map +1 -1
  226. package/dist/session/routes.js +11 -12
  227. package/dist/session/rpc.d.ts +108 -21
  228. package/dist/session/rpc.d.ts.map +1 -1
  229. package/dist/session/rpc.js +194 -39
  230. package/dist/session/start-real-vite.js +2 -2
  231. package/dist/session/state-store.d.ts +1 -17
  232. package/dist/session/state-store.d.ts.map +1 -1
  233. package/dist/session/state-store.js +3 -53
  234. package/dist/session/supervisor-op.d.ts +7 -0
  235. package/dist/session/supervisor-op.d.ts.map +1 -1
  236. package/dist/session/supervisor-op.js +6 -1
  237. package/dist/session/supervisor-rpc.d.ts +116 -19
  238. package/dist/session/supervisor-rpc.d.ts.map +1 -1
  239. package/dist/session/supervisor-rpc.js +194 -84
  240. package/dist/session/vite-command.d.ts.map +1 -1
  241. package/dist/session/vite-command.js +17 -14
  242. package/dist/session/ws.d.ts.map +1 -1
  243. package/dist/session/ws.js +20 -8
  244. package/dist/shell/npm-bin-entrypoints.d.ts.map +1 -1
  245. package/dist/shell/npm-bin-entrypoints.js +30 -5
  246. package/dist/vfs/facet-resident-limits.d.ts +33 -0
  247. package/dist/vfs/facet-resident-limits.d.ts.map +1 -0
  248. package/dist/vfs/facet-resident-limits.js +33 -0
  249. package/dist/vfs/facet-resident-store.d.ts +2 -10
  250. package/dist/vfs/facet-resident-store.d.ts.map +1 -1
  251. package/dist/vfs/facet-resident-store.js +1594 -219
  252. package/dist/workspace-host.d.ts +3 -1
  253. package/dist/workspace-host.d.ts.map +1 -1
  254. package/dist/workspace-host.js +2 -0
  255. package/dist/wrangler/nimbus-wrangler.d.ts +0 -2
  256. package/dist/wrangler/nimbus-wrangler.d.ts.map +1 -1
  257. package/dist/wrangler/nimbus-wrangler.js +8 -22
  258. package/package.json +34 -7
  259. package/public/_assets/esbuild-0.24.2.js +2380 -0
  260. package/public/_assets/opencode/1.16.2/index-attach.js +2 -2
  261. package/public/_assets/runtime/esbuild-cli-c4fda380d52befc1.js +6892 -0
  262. package/public/_assets/runtime/git-de3e60c9f3ff006a.js +103 -0
  263. package/public/_assets/runtime/{node-shims-acaa037e6d26ec0d.js → node-shims-06565b121555c194.js} +2879 -992
  264. package/public/_assets/runtime/resident-store-6ffb1939c53d982f.js +2264 -0
  265. package/public/_assets/runtime/vfs-write-ledger-e501e8fc793bc2c1.js +889 -0
  266. package/scripts/build-opencode-attach-entry.mjs +51 -1
  267. package/scripts/bundle-esbuild-wasm.mjs +55 -39
  268. package/scripts/bundle-facet-workers.mjs +159 -10
  269. package/scripts/bundle-git.mjs +88 -27
  270. package/scripts/bundle-node-shims.mjs +72 -46
  271. package/scripts/bundle-runtime.mjs +18 -421
  272. package/scripts/cf-git-patch.mjs +137 -0
  273. package/scripts/patch-install-deps.mjs +49 -96
  274. package/scripts/runtime-specs.mjs +435 -0
  275. package/vendor/git-http.generated.d.ts +82 -0
  276. package/vendor/git-upstream.generated.d.ts +4378 -0
  277. package/vendor/git.LICENSE +7 -0
  278. package/vendor/git.generated.d.mts +21 -0
  279. package/vendor/git.generated.mjs +103 -0
  280. package/dist/replica/suspension.d.ts +0 -36
  281. package/dist/replica/suspension.d.ts.map +0 -1
  282. package/dist/replica/suspension.js +0 -49
  283. package/dist/runtime/static-server.d.ts +0 -3
  284. package/dist/runtime/static-server.d.ts.map +0 -1
  285. package/dist/runtime/static-server.js +0 -133
  286. package/scripts/clean-dist.mjs +0 -7
@@ -73,5 +73,7 @@ export interface NpxResolveResult {
73
73
  * Callers can use describeNpxSelfInvocation()/formatNpxHelp() before calling
74
74
  * this resolver.
75
75
  */
76
- export declare function resolveNpxBinary(installer: NpmInstaller, vfs: CredentialedVfs, cwd: string, rawArgs: string[], log: (msg: string) => void, pid?: number): Promise<NpxResolveResult>;
76
+ export declare function resolveNpxBinary(installer: NpmInstaller, vfs: CredentialedVfs, cwd: string, rawArgs: string[], log: (msg: string) => void, pid?: number,
77
+ /** The command's `NPM_REGISTRY`; the npx cache install reads from it too. */
78
+ registry?: string): Promise<NpxResolveResult>;
77
79
  //# sourceMappingURL=npx-install.d.ts.map
@@ -1 +1 @@
1
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,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,EAC1B,GAAG,CAAC,EAAE,MAAM;AACZ,6EAA6E;AAC7E,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,gBAAgB,CAAC,CAoE3B"}
@@ -281,7 +281,9 @@ function ensureNpxCachePackageJson(vfs, pkgName, pkgRange) {
281
281
  * Callers can use describeNpxSelfInvocation()/formatNpxHelp() before calling
282
282
  * this resolver.
283
283
  */
284
- export async function resolveNpxBinary(installer, vfs, cwd, rawArgs, log, pid) {
284
+ export async function resolveNpxBinary(installer, vfs, cwd, rawArgs, log, pid,
285
+ /** The command's `NPM_REGISTRY`; the npx cache install reads from it too. */
286
+ registry) {
285
287
  const parsed = parseNpxArgs(rawArgs);
286
288
  if ('error' in parsed) {
287
289
  return { ok: false, error: parsed.error };
@@ -310,6 +312,7 @@ export async function resolveNpxBinary(installer, vfs, cwd, rawArgs, log, pid) {
310
312
  const result = await installer.install(NPX_CACHE_DIR, {
311
313
  packages: [installSpec],
312
314
  pid,
315
+ registry,
313
316
  });
314
317
  if ((result.failed?.length || 0) > 0) {
315
318
  // Partial install — some package failed to resolve. The fix is
@@ -0,0 +1,32 @@
1
+ export interface PackageLockEntry {
2
+ name?: unknown;
3
+ version?: unknown;
4
+ resolved?: unknown;
5
+ integrity?: unknown;
6
+ link?: unknown;
7
+ dev?: unknown;
8
+ optional?: unknown;
9
+ dependencies?: unknown;
10
+ devDependencies?: unknown;
11
+ optionalDependencies?: unknown;
12
+ peerDependencies?: unknown;
13
+ bin?: unknown;
14
+ os?: unknown;
15
+ cpu?: unknown;
16
+ libc?: unknown;
17
+ }
18
+ export interface PackageLock {
19
+ lockfileVersion: number;
20
+ packages: Record<string, PackageLockEntry>;
21
+ }
22
+ export declare function parsePackageLock(text: string, lockName: string): PackageLock;
23
+ /**
24
+ * Why the lock no longer describes package.json, one line per disagreement;
25
+ * empty when they agree. Every declared dependency must be locked at a
26
+ * version its range accepts, and the lock's root must declare the same
27
+ * dependency set, so a dependency removed from package.json is caught too.
28
+ */
29
+ export declare function packageLockMismatches(pkgJson: Record<string, unknown>, lock: PackageLock): string[];
30
+ export declare function stringRecord(value: unknown): Record<string, string>;
31
+ export declare function stringList(value: unknown): string[] | undefined;
32
+ //# sourceMappingURL=package-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-lock.d.ts","sourceRoot":"","sources":["../../src/npm/package-lock.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC5C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAU5E;AAID;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,EAAE,CA2BnG;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKnE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS,CAE/D"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * npm's package-lock.json / npm-shrinkwrap.json (lockfileVersion 2 and 3),
3
+ * read for `npm ci`: the `packages` map keyed by install path, and the check
4
+ * that the lock still describes what package.json declares.
5
+ */
6
+ import { isSemverRange, satisfiesRange } from './semver.js';
7
+ import { parseRegistryRequest } from './resolve-one-facet.js';
8
+ export function parsePackageLock(text, lockName) {
9
+ const lock = JSON.parse(text);
10
+ const version = typeof lock.lockfileVersion === 'number' ? lock.lockfileVersion : 0;
11
+ if (version < 2 || lock.packages === null || typeof lock.packages !== 'object') {
12
+ throw new Error(`${lockName} has lockfileVersion ${version || 'unknown'}; \`npm ci\` here reads lockfileVersion 2 or 3. ` +
13
+ 'Run `npm install` with npm 7 or newer to upgrade it.');
14
+ }
15
+ return { lockfileVersion: version, packages: lock.packages };
16
+ }
17
+ const DEPENDENCY_FIELDS = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies'];
18
+ /**
19
+ * Why the lock no longer describes package.json, one line per disagreement;
20
+ * empty when they agree. Every declared dependency must be locked at a
21
+ * version its range accepts, and the lock's root must declare the same
22
+ * dependency set, so a dependency removed from package.json is caught too.
23
+ */
24
+ export function packageLockMismatches(pkgJson, lock) {
25
+ const out = [];
26
+ const root = lock.packages[''] ?? {};
27
+ for (const field of DEPENDENCY_FIELDS) {
28
+ const declared = stringRecord(pkgJson[field]);
29
+ const locked = stringRecord(root[field]);
30
+ for (const [name, spec] of Object.entries(declared)) {
31
+ if (locked[name] !== spec) {
32
+ out.push(`Invalid: lock file's root ${field} has ${name}@${locked[name] ?? '(none)'}, package.json has ${name}@${spec}`);
33
+ continue;
34
+ }
35
+ const entry = lock.packages[`node_modules/${name}`];
36
+ if (!entry) {
37
+ if (field !== 'peerDependencies' && field !== 'optionalDependencies')
38
+ out.push(`Missing: ${name}@${spec} from lock file`);
39
+ continue;
40
+ }
41
+ const range = parseRegistryRequest(name, spec).range;
42
+ const version = typeof entry.version === 'string' ? entry.version : '';
43
+ if (isSemverRange(range) && !satisfiesRange(version, range)) {
44
+ out.push(`Invalid: lock file's ${name}@${version || '(none)'} does not satisfy ${name}@${spec}`);
45
+ }
46
+ }
47
+ for (const name of Object.keys(locked)) {
48
+ if (!Object.hasOwn(declared, name))
49
+ out.push(`Invalid: lock file's root ${field} has ${name}, which package.json does not declare`);
50
+ }
51
+ }
52
+ return out;
53
+ }
54
+ export function stringRecord(value) {
55
+ const out = {};
56
+ if (value === null || typeof value !== 'object')
57
+ return out;
58
+ for (const [key, v] of Object.entries(value))
59
+ if (typeof v === 'string')
60
+ out[key] = v;
61
+ return out;
62
+ }
63
+ export function stringList(value) {
64
+ return Array.isArray(value) ? value.filter((v) => typeof v === 'string') : undefined;
65
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Placement paths: where a package lands, relative to the project's
3
+ * `node_modules` — `react` at root, `pkg-types/node_modules/confbox` nested
4
+ * under the dependent whose range root does not satisfy. Node walks
5
+ * `node_modules` upward from the importer, so a nested copy is found by its
6
+ * dependent (and what is beneath it) and by nobody else.
7
+ */
8
+ /** `name` under `parent`; `''` is the project itself. */
9
+ export declare function nestedPlacement(parent: string, name: string): string;
10
+ /** The containing placement, `''` at root. */
11
+ export declare function parentPlacement(placement: string): string;
12
+ /** The package name a placement holds. */
13
+ export declare function placementName(placement: string): string;
14
+ /** Placements Node's walk visits for `name` from inside `from`, nearest first, root last. */
15
+ export declare function visiblePlacements(from: string, name: string): string[];
16
+ //# sourceMappingURL=placement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"placement.d.ts","sourceRoot":"","sources":["../../src/npm/placement.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,yDAAyD;AACzD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,8CAA8C;AAC9C,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGzD;AAED,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED,6FAA6F;AAC7F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAStE"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Placement paths: where a package lands, relative to the project's
3
+ * `node_modules` — `react` at root, `pkg-types/node_modules/confbox` nested
4
+ * under the dependent whose range root does not satisfy. Node walks
5
+ * `node_modules` upward from the importer, so a nested copy is found by its
6
+ * dependent (and what is beneath it) and by nobody else.
7
+ */
8
+ const NM = '/node_modules/';
9
+ /** `name` under `parent`; `''` is the project itself. */
10
+ export function nestedPlacement(parent, name) {
11
+ return parent ? `${parent}${NM}${name}` : name;
12
+ }
13
+ /** The containing placement, `''` at root. */
14
+ export function parentPlacement(placement) {
15
+ const i = placement.lastIndexOf(NM);
16
+ return i < 0 ? '' : placement.slice(0, i);
17
+ }
18
+ /** The package name a placement holds. */
19
+ export function placementName(placement) {
20
+ const i = placement.lastIndexOf(NM);
21
+ return i < 0 ? placement : placement.slice(i + NM.length);
22
+ }
23
+ /** Placements Node's walk visits for `name` from inside `from`, nearest first, root last. */
24
+ export function visiblePlacements(from, name) {
25
+ const out = [];
26
+ let dir = from;
27
+ while (dir) {
28
+ out.push(`${dir}${NM}${name}`);
29
+ dir = parentPlacement(dir);
30
+ }
31
+ out.push(name);
32
+ return out;
33
+ }
@@ -4,7 +4,7 @@
4
4
  * Why this exists
5
5
  * ───────────────
6
6
  * Pre-bundling npm packages (the `Pre-bundling N modules…` step in
7
- * src/npm-installer.ts:704) used to call `EsbuildService.build(...)`
7
+ * src/npm/installer.ts) used to call `EsbuildService.build(...)`
8
8
  * inside the supervisor DO isolate. Each `esbuild.build` allocates
9
9
  * 30–80 MiB of WASM linear memory plus the input/output graph; against
10
10
  * the 128 MB DO heap cap this OOM-killed the supervisor on installs
@@ -104,35 +104,6 @@ export interface PrebundleResult {
104
104
  /** Non-fatal warnings the supervisor should surface. */
105
105
  warnings: string[];
106
106
  }
107
- /**
108
- * Walk node_modules to collect every file the pre-bundle of `specifier`
109
- * may read. Runs in the supervisor (cheap — direct VFS access).
110
- *
111
- * Algorithm:
112
- * 1. Compute the externals via getSharedRuntimeExternals(specifier).
113
- * These are the bare specifiers esbuild will leave external; their
114
- * files do NOT need to be in the slice.
115
- * 2. Resolve the spec's package directory and add every file beneath
116
- * it to the slice.
117
- * 3. Read its package.json `dependencies` and recurse into each one
118
- * that is NOT in the externals set. Deps that walked up are
119
- * visited at most once (visited set).
120
- *
121
- * Lives here (alongside the facet function) so changes to the slice
122
- * shape touch one file — the supervisor caller in npm-installer.ts is
123
- * a thin orchestrator.
124
- */
125
- export interface BuildSliceOptions {
126
- /** Cap on total bytes shipped to the facet. 24 MiB leaves headroom under
127
- * the 32 MiB workerd RPC cap. Returns `null` if the cap is exceeded so
128
- * the caller can decide whether to bail or split (bf41d1c precedent).
129
- */
130
- maxBytes?: number;
131
- }
132
- export declare function buildSliceForSpecifier(vfs: CredentialedVfs, specifier: string, nmDir: string): {
133
- slice: SliceEntry[];
134
- totalBytes: number;
135
- } | null;
136
107
  export declare function buildSliceForSpecifierWithCap(vfs: CredentialedVfs, specifier: string, nmDir: string, capBytes: number): {
137
108
  slice: SliceEntry[];
138
109
  totalBytes: number;
@@ -1 +1 @@
1
- {"version":3,"file":"pre-bundle-facet.d.ts","sourceRoot":"","sources":["../../src/npm/pre-bundle-facet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC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,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;KAAE,CAAC;CAC7D,KACA,OAAO,CAAC,eAAe,CAiazB,CAAC;AAGF,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,MAAM,MAAM,gBAAgB,GAAG,eAAe,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * Why this exists
5
5
  * ───────────────
6
6
  * Pre-bundling npm packages (the `Pre-bundling N modules…` step in
7
- * src/npm-installer.ts:704) used to call `EsbuildService.build(...)`
7
+ * src/npm/installer.ts) used to call `EsbuildService.build(...)`
8
8
  * inside the supervisor DO isolate. Each `esbuild.build` allocates
9
9
  * 30–80 MiB of WASM linear memory plus the input/output graph; against
10
10
  * the 128 MB DO heap cap this OOM-killed the supervisor on installs
@@ -45,9 +45,7 @@
45
45
  * contract.
46
46
  */
47
47
  import { getSharedRuntimeExternals, BUNDLER_VERSION } from '@nimbus-sh/core/runtime/esbuild-service.js';
48
- export function buildSliceForSpecifier(vfs, specifier, nmDir) {
49
- return buildSliceForSpecifierWithCap(vfs, specifier, nmDir, 24 * 1024 * 1024);
50
- }
48
+ // ── Supervisor-side: build the slice for one specifier ──────────────────
51
49
  export function buildSliceForSpecifierWithCap(vfs, specifier, nmDir, capBytes) {
52
50
  const externals = new Set();
53
51
  for (const e of getSharedRuntimeExternals(specifier)) {
@@ -286,7 +284,7 @@ export const prebundleOne = async function prebundleOne(spec, _env) {
286
284
  initPromise = (async () => {
287
285
  // Read the WebAssembly.Module the pool registered. The key matches
288
286
  // the name passed to IsolatePool's `wasmModules` option (see
289
- // src/npm-installer.ts:prebundleUsedModules dispatch site).
287
+ // src/npm/installer.ts:prebundleUsedModules dispatch site).
290
288
  const wasmRegistry = globalThis.__NIMBUS_WASM;
291
289
  const wasmModule = wasmRegistry && wasmRegistry['esbuild.wasm'];
292
290
  if (!wasmModule) {
@@ -16,6 +16,8 @@
16
16
  * Two buckets, two key shapes:
17
17
  * tarball: `${R2_CACHE_PREFIX}/t/<sri-algo>/<sri-digest-hex>.tgz`
18
18
  * packument: `${R2_CACHE_PREFIX}/pc/<name>.json (corgi/abbreviated format)`
19
+ * The tarball bucket also holds read profiles under `read-profiles/v1/`
20
+ * (facets/read-profile.ts): package-relative paths per tarball integrity.
19
21
  *
20
22
  * Why two buckets:
21
23
  * Tarballs are content-addressed and never expire. Packuments must
@@ -57,6 +59,7 @@
57
59
  * stream directly from npm.
58
60
  * - npm publish webhook -> cache invalidation.
59
61
  */
62
+ import { NPM_REGISTRY_ORIGIN, npmRegistryOrigin } from '@nimbus-sh/core/substrate/lifo/commands/system/npm.js';
60
63
  import type { CacheTier, CacheKind } from '@nimbus-sh/core/_shared/cache-stats.js';
61
64
  /**
62
65
  * Per-call cache-stat event (cache metrics support). R2CacheClient
@@ -117,8 +120,9 @@ export declare const R2_CACHE_PREFIX = "v2";
117
120
  * No data migration; existing R2 packument entries' customMetadata
118
121
  * .expiresAt stamps remain valid against either TTL. */
119
122
  export declare const PACKUMENT_TTL_MS: number;
123
+ export { NPM_REGISTRY_ORIGIN, npmRegistryOrigin };
120
124
  /** The registry URL a packument is read from — also what `npm http` lines report. */
121
- export declare function packumentUrl(name: string): string;
125
+ export declare function packumentUrl(name: string, registry?: string): string;
122
126
  /** Cap on tarball bytes returned via this RPC. Workerd structured-clone
123
127
  * cap is 32 MiB; we keep a comfortable margin to leave room for RPC
124
128
  * framing + the call's own arg bytes. Tarballs above this size skip
@@ -171,7 +175,7 @@ type R2BucketLike = {
171
175
  * encodeURIComponent on the name so '@scope/pkg' becomes a single path
172
176
  * segment (R2 keys allow any UTF-8, but URL paths need encoding).
173
177
  */
174
- export declare function packumentL2Url(name: string): string;
178
+ export declare function packumentL2Url(name: string, registry?: string): string;
175
179
  /** L2 cache-key URL for a tarball content address. Hex + the SRI algo
176
180
  * name are already URL-safe, so the R2 key doubles as the URL path. */
177
181
  export declare function tarballL2Url(address: TarballAddress): string;
@@ -211,7 +215,7 @@ export declare function parseTarballAddress(integrity: string): TarballAddress |
211
215
  */
212
216
  export declare function tarballKey(address: TarballAddress): string;
213
217
  /** Compose the R2 object key for a packument. */
214
- export declare function packumentKey(name: string): string;
218
+ export declare function packumentKey(name: string, registry?: string): string;
215
219
  /**
216
220
  * Per-instance counters surfaced for tests / probes. Read via
217
221
  * `R2CacheClient.stats()`. Track at the FUNCTION boundary level so a
@@ -308,7 +312,7 @@ export declare class R2CacheClient {
308
312
  * write back to L2 with a 5-min `Cache-Control: max-age=300`
309
313
  * (matching the existing R2 customMetadata.expiresAt semantic).
310
314
  */
311
- getPackument(name: string): Promise<CachedPackument | null>;
315
+ getPackument(name: string, registry?: string): Promise<CachedPackument | null>;
312
316
  /**
313
317
  * Resolve a packument through the whole stack: cache read, and on a
314
318
  * miss (or an expired entry) the registry fetch plus the cache fill.
@@ -323,6 +327,8 @@ export declare class R2CacheClient {
323
327
  * attacker would be choosing the address too. Here, the only bytes
324
328
  * that reach `pc/<name>.json` are the ones registry.npmjs.org served
325
329
  * for that exact name, one line below the fetch that produced them.
330
+ * Another registry (`options.registry`) fills and reads only its own
331
+ * namespace of the cache, so it can neither poison nor borrow those.
326
332
  *
327
333
  * `status` is set when the registry answered 4xx (no such package);
328
334
  * `failure` when every attempt failed. Both leave `json` null.
@@ -330,6 +336,7 @@ export declare class R2CacheClient {
330
336
  readThroughPackument(name: string, options?: {
331
337
  retries?: number;
332
338
  timeoutMs?: number;
339
+ registry?: string;
333
340
  }): Promise<PackumentReadThrough>;
334
341
  /**
335
342
  * Write a packument JSON to R2 with a TTL stamp in customMetadata.
@@ -342,11 +349,10 @@ export declare class R2CacheClient {
342
349
  * Returns true on success, false on failure (same best-effort posture
343
350
  * as putTarball).
344
351
  */
345
- putPackument(name: string, json: string): Promise<boolean>;
352
+ putPackument(name: string, json: string, registry?: string): Promise<boolean>;
346
353
  /** Lightweight feature-detection for callers that want to log path. */
347
354
  hasTarballBucket(): boolean;
348
355
  /** Lightweight feature-detection for callers that want to log path. */
349
356
  hasPackumentBucket(): boolean;
350
357
  }
351
- export {};
352
358
  //# sourceMappingURL=r2-cache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"r2-cache.d.ts","sourceRoot":"","sources":["../../src/npm/r2-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAEnF;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,SAAS,CAAA;CAAE,CAAC;AAE5D;;;;;;;;mBAQmB;AACnB,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yDA6ByD;AACzD,eAAO,MAAM,gBAAgB,QAAc,CAAC;AAQ5C,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKjD;AAED;;;;0DAI0D;AAC1D,eAAO,MAAM,oBAAoB,QAAmB,CAAC;AAIrD,uDAAuD;AACvD,MAAM,WAAW,oBAAoB;IACnC,yEAAyE;IACzE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,2BAA2B;IAC3B,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IAC/B,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B;;sCAEkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb;8DAC0D;IAC1D,KAAK,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M,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IAwE/D;;;;;;;;;OASG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBtF;;;;;;;;;;;;;;;;OAgBG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAA4B,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IA8EzG;;;;;;;;;;;;;;;;;;;OAmBG;IACG,oBAAoB,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GACpE,OAAO,CAAC,oBAAoB,CAAC;IA6DhC;;;;;;;;;;OAUG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAA4B,GAAG,OAAO,CAAC,OAAO,CAAC;IAexG,uEAAuE;IACvE,gBAAgB,IAAI,OAAO;IAI3B,uEAAuE;IACvE,kBAAkB,IAAI,OAAO;CAG9B"}
@@ -16,6 +16,8 @@
16
16
  * Two buckets, two key shapes:
17
17
  * tarball: `${R2_CACHE_PREFIX}/t/<sri-algo>/<sri-digest-hex>.tgz`
18
18
  * packument: `${R2_CACHE_PREFIX}/pc/<name>.json (corgi/abbreviated format)`
19
+ * The tarball bucket also holds read profiles under `read-profiles/v1/`
20
+ * (facets/read-profile.ts): package-relative paths per tarball integrity.
19
21
  *
20
22
  * Why two buckets:
21
23
  * Tarballs are content-addressed and never expire. Packuments must
@@ -57,6 +59,7 @@
57
59
  * stream directly from npm.
58
60
  * - npm publish webhook -> cache invalidation.
59
61
  */
62
+ import { NPM_REGISTRY_ORIGIN, npmRegistryOrigin } from '@nimbus-sh/core/substrate/lifo/commands/system/npm.js';
60
63
  /** Schema version baked into every cache key. Bump to invalidate
61
64
  * everything atomically (e.g. if the storage shape changes or a bug
62
65
  * poisoned a class of keys).
@@ -98,16 +101,28 @@ export const R2_CACHE_PREFIX = 'v2';
98
101
  * No data migration; existing R2 packument entries' customMetadata
99
102
  * .expiresAt stamps remain valid against either TTL. */
100
103
  export const PACKUMENT_TTL_MS = 60 * 60_000;
101
- /** npm registry origin. The only host the packument cache is filled from. */
102
- const NPM_REGISTRY_ORIGIN = 'https://registry.npmjs.org';
104
+ // The origin rule lives with the command that reads NPM_REGISTRY; the cache
105
+ // keys by the same value.
106
+ export { NPM_REGISTRY_ORIGIN, npmRegistryOrigin };
103
107
  /** Jittered backoff between packument fetch attempts. */
104
108
  const PACKUMENT_BACKOFF_MS = [500, 1500, 4500];
105
109
  /** The registry URL a packument is read from — also what `npm http` lines report. */
106
- export function packumentUrl(name) {
110
+ export function packumentUrl(name, registry = NPM_REGISTRY_ORIGIN) {
107
111
  const safeName = name.startsWith('@')
108
112
  ? '@' + encodeURIComponent(name.slice(1))
109
113
  : encodeURIComponent(name);
110
- return `${NPM_REGISTRY_ORIGIN}/${safeName}`;
114
+ return `${registry}/${safeName}`;
115
+ }
116
+ /**
117
+ * The cache path segment for a packument: `<name>.json` for the default
118
+ * registry (the keys warm caches already hold), and `<origin>/<name>.json`
119
+ * for any other, so a private registry never reads or fills the entries
120
+ * registry.npmjs.org served.
121
+ */
122
+ function packumentCachePath(name, registry) {
123
+ return registry === NPM_REGISTRY_ORIGIN
124
+ ? `${name}.json`
125
+ : `${encodeURIComponent(registry)}/${name}.json`;
111
126
  }
112
127
  /** Cap on tarball bytes returned via this RPC. Workerd structured-clone
113
128
  * cap is 32 MiB; we keep a comfortable margin to leave room for RPC
@@ -136,8 +151,8 @@ const L2_KEY_HOST = 'https://nimbus-cache.invalid';
136
151
  * encodeURIComponent on the name so '@scope/pkg' becomes a single path
137
152
  * segment (R2 keys allow any UTF-8, but URL paths need encoding).
138
153
  */
139
- export function packumentL2Url(name) {
140
- return `${L2_KEY_HOST}/${R2_CACHE_PREFIX}/pc/${encodeURIComponent(name)}.json`;
154
+ export function packumentL2Url(name, registry = NPM_REGISTRY_ORIGIN) {
155
+ return `${L2_KEY_HOST}/${R2_CACHE_PREFIX}/pc/${encodeURIComponent(packumentCachePath(name, registry))}`;
141
156
  }
142
157
  /** L2 cache-key URL for a tarball content address. Hex + the SRI algo
143
158
  * name are already URL-safe, so the R2 key doubles as the URL path. */
@@ -253,8 +268,8 @@ export function tarballKey(address) {
253
268
  return `${R2_CACHE_PREFIX}/t/${address.algo}/${address.hex}.tgz`;
254
269
  }
255
270
  /** Compose the R2 object key for a packument. */
256
- export function packumentKey(name) {
257
- return `${R2_CACHE_PREFIX}/pc/${name}.json`;
271
+ export function packumentKey(name, registry = NPM_REGISTRY_ORIGIN) {
272
+ return `${R2_CACHE_PREFIX}/pc/${packumentCachePath(name, registry)}`;
258
273
  }
259
274
  /**
260
275
  * R2-backed npm cache client. Wraps two R2 bindings (tarballs + packuments)
@@ -437,9 +452,9 @@ export class R2CacheClient {
437
452
  * write back to L2 with a 5-min `Cache-Control: max-age=300`
438
453
  * (matching the existing R2 customMetadata.expiresAt semantic).
439
454
  */
440
- async getPackument(name) {
455
+ async getPackument(name, registry = NPM_REGISTRY_ORIGIN) {
441
456
  // ── L2 fast path (per-colo) ───────────────────────────────────
442
- const l2Key = new Request(packumentL2Url(name));
457
+ const l2Key = new Request(packumentL2Url(name, registry));
443
458
  const l2Hit = await l2Get(l2Key);
444
459
  if (l2Hit) {
445
460
  this._l2HitsPackument++;
@@ -475,7 +490,7 @@ export class R2CacheClient {
475
490
  return null;
476
491
  }
477
492
  this._l3GetsPackument++;
478
- const obj = await this.packumentBucket.get(packumentKey(name));
493
+ const obj = await this.packumentBucket.get(packumentKey(name, registry));
479
494
  if (!obj) {
480
495
  this._recordMiss('L3', 'packument');
481
496
  return null;
@@ -528,16 +543,19 @@ export class R2CacheClient {
528
543
  * attacker would be choosing the address too. Here, the only bytes
529
544
  * that reach `pc/<name>.json` are the ones registry.npmjs.org served
530
545
  * for that exact name, one line below the fetch that produced them.
546
+ * Another registry (`options.registry`) fills and reads only its own
547
+ * namespace of the cache, so it can neither poison nor borrow those.
531
548
  *
532
549
  * `status` is set when the registry answered 4xx (no such package);
533
550
  * `failure` when every attempt failed. Both leave `json` null.
534
551
  */
535
552
  async readThroughPackument(name, options) {
536
- const cached = await this.getPackument(name);
553
+ const registry = options?.registry ?? NPM_REGISTRY_ORIGIN;
554
+ const cached = await this.getPackument(name, registry);
537
555
  if (cached && !cached.expired && cached.json) {
538
556
  return { json: cached.json, source: 'r2-cache' };
539
557
  }
540
- const url = packumentUrl(name);
558
+ const url = packumentUrl(name, registry);
541
559
  const retries = Math.max(0, options?.retries ?? 3);
542
560
  const timeoutMs = options?.timeoutMs ?? 15_000;
543
561
  let lastErr;
@@ -566,7 +584,7 @@ export class R2CacheClient {
566
584
  this._recordHit('L4', 'packument', json.length);
567
585
  // Best-effort fill, awaited so a follow-up read in the same
568
586
  // install sees it.
569
- await this.putPackument(name, json);
587
+ await this.putPackument(name, json, registry);
570
588
  return { json, source: 'network' };
571
589
  }
572
590
  if (resp.status >= 400 && resp.status < 500) {
@@ -605,12 +623,12 @@ export class R2CacheClient {
605
623
  * Returns true on success, false on failure (same best-effort posture
606
624
  * as putTarball).
607
625
  */
608
- async putPackument(name, json) {
626
+ async putPackument(name, json, registry = NPM_REGISTRY_ORIGIN) {
609
627
  if (!this.packumentBucket)
610
628
  return false;
611
629
  const expiresAt = Date.now() + PACKUMENT_TTL_MS;
612
630
  try {
613
- await this.packumentBucket.put(packumentKey(name), json, {
631
+ await this.packumentBucket.put(packumentKey(name, registry), json, {
614
632
  httpMetadata: { contentType: 'application/json' },
615
633
  customMetadata: { expiresAt: String(expiresAt) },
616
634
  });
@@ -80,6 +80,8 @@ export interface ResolveOneSpec {
80
80
  fetchTimeoutMs: number;
81
81
  /** Retries for transient failures. Default 3. */
82
82
  retries: number;
83
+ /** Registry origin the packument is read from (the install's `NPM_REGISTRY`). */
84
+ registry: string;
83
85
  }
84
86
  export interface ResolveOneResult {
85
87
  /** Resolved package, or null if a registry policy filtered it out. */
@@ -201,6 +203,7 @@ export declare const resolveOnePackumentInFacet: (spec: ResolveOneSpec, env: {
201
203
  getPackument: (name: string, options: {
202
204
  retries: number;
203
205
  timeoutMs: number;
206
+ registry: string;
204
207
  }) => Promise<{
205
208
  json: string | null;
206
209
  source: "r2-cache" | "network";
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-one-facet.d.ts","sourceRoot":"","sources":["../../src/npm/resolve-one-facet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AA4B/E;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,aAAa,EAAE,gBAAgB,EAAE,CAAC;IAClC;+EAC2E;IAC3E,UAAU,EAAE,OAAO,CAAC;IACpB,8CAA8C;IAC9C,cAAc,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,GAAG,EAAE,eAAe,GAAG,IAAI,CAAC;IAC5B;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,mBAAmB,EAAE,MAAM,CAAC,MAAM,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;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;EAsB/D;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,GACrC,MAAM,cAAc,EACpB,KAAK;IACH,UAAU,EAAE;QACV;;;;WAIG;QACH,YAAY,EAAE,CACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,KAC9D,OAAO,CAAC;YACX,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;YACpB,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;YAC/B,MAAM,EAAE,KAAK,CACT;gBAAE,IAAI,EAAE,KAAK,CAAC;gBAAC,IAAI,EAAE,MAAM,CAAC;gBAAC,SAAS,EAAE,MAAM,CAAC;gBAAC,KAAK,EAAE,MAAM,CAAA;aAAE,GAC/D;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,IAAI,EAAE,MAAM,CAAC;gBAAC,SAAS,EAAE,MAAM,CAAA;aAAE,CACpD,CAAC;YACF,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,OAAO,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC,CAAC;KACJ,CAAC;CACH,KACA,OAAO,CAAC,gBAAgB,CAiX1B,CAAC"}
@@ -175,9 +175,19 @@ export const resolveOnePackumentInFacet = async function resolveOnePackumentInFa
175
175
  });
176
176
  };
177
177
  // 1. Registry policy.
178
+ //
179
+ // A swap is an npm alias the policy declares for the package: the
180
+ // packument comes from the swap target, the package installs under the
181
+ // requested name (`request.installName`) — exactly the shape an explicit
182
+ // `name@npm:target@range` spec already has. Policy applies to the
183
+ // REGISTRY identity, placement to the declared name: a top-level swap the
184
+ // supervisor already rewrote (applySwaps, which also announced it)
185
+ // arrives naming the WASM target and is not swapped again, while a user's
186
+ // explicit alias to the native package (`build@npm:esbuild`) still needs
187
+ // its target swapped — and keeps its own install name.
178
188
  let effName = request.registryName;
179
189
  // @ts-ignore — preamble.
180
- const __swap = SHOULD_SWAP(spec.name);
190
+ const __swap = SHOULD_SWAP(request.registryName);
181
191
  if (__swap) {
182
192
  messages.push(`[npm] \x1b[33m[swap]\x1b[0m ${__swap.from} → ${__swap.to}`);
183
193
  events.push({ type: 'swap', from: __swap.from, to: __swap.to, ctx: 'transitive' });
@@ -185,9 +195,10 @@ export const resolveOnePackumentInFacet = async function resolveOnePackumentInFa
185
195
  }
186
196
  else {
187
197
  // @ts-ignore — preamble.
188
- const __fail = SHOULD_REJECT_FAIL(spec.name);
198
+ const __fail = SHOULD_REJECT_FAIL(request.registryName);
189
199
  // A listed package resolves and installs — npm parity; the
190
- // advisory names the reason it cannot run here.
200
+ // advisory names the reason it cannot run here. An alias of a listed
201
+ // package (`img@npm:sharp`) is that package.
191
202
  if (__fail)
192
203
  emitAdvisory(__fail);
193
204
  }
@@ -282,6 +293,7 @@ export const resolveOnePackumentInFacet = async function resolveOnePackumentInFa
282
293
  const result = await __nimbusUseRpcResult(env.SUPERVISOR.getPackument(effName, {
283
294
  retries: Math.max(0, spec.retries ?? 3),
284
295
  timeoutMs: spec.fetchTimeoutMs ?? 15_000,
296
+ registry: spec.registry,
285
297
  }), (r) => ({ json: r.json, source: r.source, events: r.events, status: r.status, failure: r.failure }));
286
298
  packumentElapsedMs = Date.now() - packumentStart;
287
299
  // Splice the supervisor's per-tier events into our accumulator.
@@ -4,7 +4,6 @@
4
4
  * Registry resolution runs in fanout facets; this module contains only the
5
5
  * supervisor-side contracts and computations consumed after resolution.
6
6
  */
7
- import type { RegistryCacheEntry } from './cache.js';
8
7
  /**
9
8
  * Injectable fetch function used by the installer's facet-backed registry
10
9
  * transport.
@@ -32,18 +31,17 @@ export interface ResolvedPackage {
32
31
  export interface HoistPlan {
33
32
  /** Root-level hoisted packages: name → ResolvedPackage. */
34
33
  root: Map<string, ResolvedPackage>;
35
- /**
36
- * Packages that could not be hoisted due to version conflicts.
37
- * Key: "parentName/childName", value: ResolvedPackage.
38
- */
34
+ /** Packages nested under a dependent root does not satisfy, by placement path (placement.ts). */
39
35
  nested: Map<string, ResolvedPackage>;
40
36
  }
41
- /**
42
- * Serialize a resolved package into the registry-cache row shape. Facet task
43
- * bodies keep inline literals of this shape because `fn.toString()` isolates
44
- * cannot import supervisor modules.
45
- */
46
- export declare function registryEntryFromResolved(pkg: ResolvedPackage): RegistryCacheEntry;
47
- /** Compute the flat hoist plan used by the current one-version-per-name resolver. */
48
- export declare function computeHoistPlan(resolved: Map<string, ResolvedPackage>): HoistPlan;
37
+ /** One package at one placement: the unit diff, fetch and lockfile work in. */
38
+ export interface PackagePlacement {
39
+ /** Placement path relative to the project's `node_modules`. */
40
+ placement: string;
41
+ pkg: ResolvedPackage;
42
+ }
43
+ /** The walk's placement decisions carried forward: first version per name at root, the rest nested. */
44
+ export declare function computeHoistPlan(resolved: Map<string, ResolvedPackage>, nested?: Map<string, ResolvedPackage>): HoistPlan;
45
+ /** Every placement in the plan, root first. */
46
+ export declare function hoistPlacements(plan: HoistPlan): PackagePlacement[];
49
47
  //# sourceMappingURL=resolver.d.ts.map