@scriptc/compiler 0.2.10 → 0.3.1

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 (584) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +7 -38
  2. package/ambient/scriptc-overrides.d.ts +1 -25
  3. package/ambient/scriptc.d.ts +1 -9
  4. package/dist/backend/cycle-analysis.test.js +1 -1
  5. package/dist/backend/cycle-mutability.d.ts +1 -1
  6. package/dist/backend/cycle-mutability.js +1 -18
  7. package/dist/backend/cycle-mutability.js.map +1 -1
  8. package/dist/backend/executable-features.d.ts +1 -1
  9. package/dist/backend/executable-features.js +3 -8
  10. package/dist/backend/executable-features.js.map +1 -1
  11. package/dist/backend/immutability.d.ts +1 -1
  12. package/dist/backend/immutability.js +1 -1
  13. package/dist/backend/immutability.test.js +1 -1
  14. package/dist/backend/library-pack.js +0 -2
  15. package/dist/backend/library-pack.js.map +1 -1
  16. package/dist/backend/linker.js +1 -1
  17. package/dist/backend/linker.js.map +1 -1
  18. package/dist/backend/llvm/bigint-wrap.d.ts +4 -0
  19. package/dist/backend/llvm/bigint-wrap.js +590 -0
  20. package/dist/backend/llvm/bigint-wrap.js.map +1 -0
  21. package/dist/backend/llvm/blocks.d.ts +2 -0
  22. package/dist/backend/llvm/blocks.js +4 -0
  23. package/dist/backend/llvm/blocks.js.map +1 -1
  24. package/dist/backend/llvm/call-lifetimes.js +15 -4
  25. package/dist/backend/llvm/call-lifetimes.js.map +1 -1
  26. package/dist/backend/llvm/call-lifetimes.test.js +14 -3
  27. package/dist/backend/llvm/call-lifetimes.test.js.map +1 -1
  28. package/dist/backend/llvm/checked-narrows.test.js +2 -2
  29. package/dist/backend/llvm/checked-narrows.test.js.map +1 -1
  30. package/dist/backend/llvm/classes.js +60 -21
  31. package/dist/backend/llvm/classes.js.map +1 -1
  32. package/dist/backend/llvm/classes.test.js +11 -11
  33. package/dist/backend/llvm/classes.test.js.map +1 -1
  34. package/dist/backend/llvm/common.d.ts +7 -5
  35. package/dist/backend/llvm/common.js +7 -5
  36. package/dist/backend/llvm/common.js.map +1 -1
  37. package/dist/backend/llvm/constant-callbacks.d.ts +1 -1
  38. package/dist/backend/llvm/constant-callbacks.js +13 -31
  39. package/dist/backend/llvm/constant-callbacks.js.map +1 -1
  40. package/dist/backend/llvm/constant-callbacks.test.js +1 -1
  41. package/dist/backend/llvm/dense-array-access.js +133 -45
  42. package/dist/backend/llvm/dense-array-access.js.map +1 -1
  43. package/dist/backend/llvm/dense-array-access.test.js +54 -2
  44. package/dist/backend/llvm/dense-array-access.test.js.map +1 -1
  45. package/dist/backend/llvm/dyn.d.ts +2 -1
  46. package/dist/backend/llvm/dyn.js +4 -73
  47. package/dist/backend/llvm/dyn.js.map +1 -1
  48. package/dist/backend/llvm/emitter.d.ts +123 -23
  49. package/dist/backend/llvm/emitter.js +729 -258
  50. package/dist/backend/llvm/emitter.js.map +1 -1
  51. package/dist/backend/llvm/emitter.test.js +17 -10
  52. package/dist/backend/llvm/emitter.test.js.map +1 -1
  53. package/dist/backend/llvm/expr-async.js +120 -43
  54. package/dist/backend/llvm/expr-async.js.map +1 -1
  55. package/dist/backend/llvm/expr-async.test.js +2 -2
  56. package/dist/backend/llvm/expr-async.test.js.map +1 -1
  57. package/dist/backend/llvm/expr-bytes.js +51 -36
  58. package/dist/backend/llvm/expr-bytes.js.map +1 -1
  59. package/dist/backend/llvm/expr-callbacks.js +72 -3
  60. package/dist/backend/llvm/expr-callbacks.js.map +1 -1
  61. package/dist/backend/llvm/expr-calls.d.ts +1 -1
  62. package/dist/backend/llvm/expr-calls.js +159 -30
  63. package/dist/backend/llvm/expr-calls.js.map +1 -1
  64. package/dist/backend/llvm/expr-calls.test.js +132 -0
  65. package/dist/backend/llvm/expr-calls.test.js.map +1 -0
  66. package/dist/backend/llvm/expr-containers.js +25 -8
  67. package/dist/backend/llvm/expr-containers.js.map +1 -1
  68. package/dist/backend/llvm/expr-context.d.ts +2 -0
  69. package/dist/backend/llvm/expr-control.js +4 -107
  70. package/dist/backend/llvm/expr-control.js.map +1 -1
  71. package/dist/backend/llvm/expr-dispatch.d.ts +1 -2
  72. package/dist/backend/llvm/expr-dispatch.js +3 -41
  73. package/dist/backend/llvm/expr-dispatch.js.map +1 -1
  74. package/dist/backend/llvm/expr-dynamic.d.ts +1 -1
  75. package/dist/backend/llvm/expr-dynamic.js +39 -31
  76. package/dist/backend/llvm/expr-dynamic.js.map +1 -1
  77. package/dist/backend/llvm/expr-primitives.d.ts +7 -0
  78. package/dist/backend/llvm/expr-primitives.js +80 -22
  79. package/dist/backend/llvm/expr-primitives.js.map +1 -1
  80. package/dist/backend/llvm/expr-primitives.test.js +97 -7
  81. package/dist/backend/llvm/expr-primitives.test.js.map +1 -1
  82. package/dist/backend/llvm/expr-records.d.ts +9 -0
  83. package/dist/backend/llvm/expr-records.js +134 -16
  84. package/dist/backend/llvm/expr-records.js.map +1 -1
  85. package/dist/backend/llvm/expr-stream-bridges.d.ts +1 -1
  86. package/dist/backend/llvm/expr-stream-bridges.js +80 -1
  87. package/dist/backend/llvm/expr-stream-bridges.js.map +1 -1
  88. package/dist/backend/llvm/expr-stream-bridges.test.js +51 -2
  89. package/dist/backend/llvm/expr-stream-bridges.test.js.map +1 -1
  90. package/dist/backend/llvm/int32-abi.d.ts +31 -0
  91. package/dist/backend/llvm/int32-abi.js +62 -0
  92. package/dist/backend/llvm/int32-abi.js.map +1 -0
  93. package/dist/backend/llvm/int32-abi.test.js +107 -0
  94. package/dist/backend/llvm/int32-abi.test.js.map +1 -0
  95. package/dist/backend/llvm/int32-locals.d.ts +30 -0
  96. package/dist/backend/llvm/int32-locals.js +95 -0
  97. package/dist/backend/llvm/int32-locals.js.map +1 -0
  98. package/dist/backend/llvm/integer-values.d.ts +4 -0
  99. package/dist/backend/llvm/integer-values.js +30 -1
  100. package/dist/backend/llvm/integer-values.js.map +1 -1
  101. package/dist/backend/llvm/integer-views.d.ts +8 -1
  102. package/dist/backend/llvm/integer-views.js +47 -2
  103. package/dist/backend/llvm/integer-views.js.map +1 -1
  104. package/dist/backend/llvm/lazy-captures.d.ts +16 -0
  105. package/dist/backend/llvm/lazy-captures.js +88 -2
  106. package/dist/backend/llvm/lazy-captures.js.map +1 -1
  107. package/dist/backend/llvm/lazy-captures.test.js +48 -0
  108. package/dist/backend/llvm/lazy-captures.test.js.map +1 -1
  109. package/dist/backend/llvm/lib-dispatch.js +14 -1
  110. package/dist/backend/llvm/lib-dispatch.js.map +1 -1
  111. package/dist/backend/llvm/lib-filesystem.js +3 -13
  112. package/dist/backend/llvm/lib-filesystem.js.map +1 -1
  113. package/dist/backend/llvm/lib-shared.js +7 -8
  114. package/dist/backend/llvm/lib-shared.js.map +1 -1
  115. package/dist/backend/llvm/local-array-reads.js +21 -2
  116. package/dist/backend/llvm/local-array-reads.js.map +1 -1
  117. package/dist/backend/llvm/local-array-reads.test.js +4 -3
  118. package/dist/backend/llvm/local-array-reads.test.js.map +1 -1
  119. package/dist/backend/llvm/local-union-storage.test.js +3 -3
  120. package/dist/backend/llvm/local-union-storage.test.js.map +1 -1
  121. package/dist/backend/llvm/map-number-lookup.d.ts +7 -0
  122. package/dist/backend/llvm/map-number-lookup.js +16 -2
  123. package/dist/backend/llvm/map-number-lookup.js.map +1 -1
  124. package/dist/backend/llvm/map-read-lifetimes.js +7 -1
  125. package/dist/backend/llvm/map-read-lifetimes.js.map +1 -1
  126. package/dist/backend/llvm/map-read-lifetimes.test.js +25 -8
  127. package/dist/backend/llvm/map-read-lifetimes.test.js.map +1 -1
  128. package/dist/backend/llvm/reference-effects.js +2 -0
  129. package/dist/backend/llvm/reference-effects.js.map +1 -1
  130. package/dist/backend/llvm/reference-writes.d.ts +3 -0
  131. package/dist/backend/llvm/reference-writes.js +10 -2
  132. package/dist/backend/llvm/reference-writes.js.map +1 -1
  133. package/dist/backend/llvm/regex-matchers.d.ts +39 -0
  134. package/dist/backend/llvm/regex-matchers.js +1649 -0
  135. package/dist/backend/llvm/regex-matchers.js.map +1 -0
  136. package/dist/backend/llvm/regex-matchers.test.js +96 -0
  137. package/dist/backend/llvm/regex-matchers.test.js.map +1 -0
  138. package/dist/backend/llvm/shapes.d.ts +36 -1
  139. package/dist/backend/llvm/shapes.js +128 -16
  140. package/dist/backend/llvm/shapes.js.map +1 -1
  141. package/dist/backend/llvm/shapes.test.js +3 -3
  142. package/dist/backend/llvm/stack-unions.test.js +2 -2
  143. package/dist/backend/llvm/stack-unions.test.js.map +1 -1
  144. package/dist/backend/llvm/string-construction.test.js +3 -3
  145. package/dist/backend/llvm/string-construction.test.js.map +1 -1
  146. package/dist/backend/llvm/string-lifetimes.test.js +6 -6
  147. package/dist/backend/llvm/string-lifetimes.test.js.map +1 -1
  148. package/dist/backend/llvm/string-literal-equality.d.ts +22 -0
  149. package/dist/backend/llvm/string-literal-equality.js +78 -0
  150. package/dist/backend/llvm/string-literal-equality.js.map +1 -0
  151. package/dist/backend/llvm/switch-dispatch.js +59 -13
  152. package/dist/backend/llvm/switch-dispatch.js.map +1 -1
  153. package/dist/backend/llvm/switch-dispatch.test.js +72 -7
  154. package/dist/backend/llvm/switch-dispatch.test.js.map +1 -1
  155. package/dist/backend/llvm/union-retype.test.d.ts +1 -0
  156. package/dist/backend/llvm/union-retype.test.js +229 -0
  157. package/dist/backend/llvm/union-retype.test.js.map +1 -0
  158. package/dist/backend/llvm/wrapping-sums.d.ts +17 -0
  159. package/dist/backend/llvm/wrapping-sums.js +113 -0
  160. package/dist/backend/llvm/wrapping-sums.js.map +1 -0
  161. package/dist/backend/loop-polls.js +1 -0
  162. package/dist/backend/loop-polls.js.map +1 -1
  163. package/dist/backend/mangle.d.ts +9 -0
  164. package/dist/backend/mangle.js +15 -0
  165. package/dist/backend/mangle.js.map +1 -1
  166. package/dist/backend/may-throw.js +6 -12
  167. package/dist/backend/may-throw.js.map +1 -1
  168. package/dist/backend/may-throw.test.js +1 -1
  169. package/dist/backend/native/artifact-stamps.js +0 -2
  170. package/dist/backend/native/artifact-stamps.js.map +1 -1
  171. package/dist/backend/native/cache-warm.d.ts +1 -1
  172. package/dist/backend/native/cache-warm.js +2 -3
  173. package/dist/backend/native/cache-warm.js.map +1 -1
  174. package/dist/backend/native/compiler-fingerprint.d.ts +1 -1
  175. package/dist/backend/native/compiler-fingerprint.js +4 -7
  176. package/dist/backend/native/compiler-fingerprint.js.map +1 -1
  177. package/dist/backend/native/contracts.d.ts +3 -28
  178. package/dist/backend/native/driver.js +1 -3
  179. package/dist/backend/native/driver.js.map +1 -1
  180. package/dist/backend/native/executable.d.ts +0 -15
  181. package/dist/backend/native/executable.js +17 -172
  182. package/dist/backend/native/executable.js.map +1 -1
  183. package/dist/backend/native/tool-identity.js +0 -1
  184. package/dist/backend/native/tool-identity.js.map +1 -1
  185. package/dist/backend/native/vendor.d.ts +1 -1
  186. package/dist/backend/native/vendor.js +1 -1
  187. package/dist/backend/native/vendor.js.map +1 -1
  188. package/dist/backend/native-link-info-core.d.ts +0 -2
  189. package/dist/backend/native-link-info-core.js.map +1 -1
  190. package/dist/backend/native-toolchain.test.js +23 -33
  191. package/dist/backend/native-toolchain.test.js.map +1 -1
  192. package/dist/backend/publication.test.js +1 -1
  193. package/dist/backend/runtime-abi.d.ts +2 -2
  194. package/dist/backend/runtime-abi.js +2 -2
  195. package/dist/backend/runtime-pack-core.d.ts +1 -2
  196. package/dist/backend/runtime-pack-core.js +5 -14
  197. package/dist/backend/runtime-pack-core.js.map +1 -1
  198. package/dist/backend/runtime-pack-targets.test.js +3 -8
  199. package/dist/backend/runtime-pack-targets.test.js.map +1 -1
  200. package/dist/backend/runtime-pack.test.js +22 -19
  201. package/dist/backend/runtime-pack.test.js.map +1 -1
  202. package/dist/backend/target-diagnostics.d.ts +0 -5
  203. package/dist/backend/target-diagnostics.js +1 -11
  204. package/dist/backend/target-diagnostics.js.map +1 -1
  205. package/dist/backend/target-diagnostics.test.js +1 -1
  206. package/dist/backend/vendor-archives.d.ts +1 -7
  207. package/dist/backend/vendor-archives.js +9 -189
  208. package/dist/backend/vendor-archives.js.map +1 -1
  209. package/dist/backend/vendor-inputs.d.ts +0 -1
  210. package/dist/backend/vendor-inputs.js +0 -1
  211. package/dist/backend/vendor-inputs.js.map +1 -1
  212. package/dist/backend/warm-cache.js +3 -5
  213. package/dist/backend/warm-cache.js.map +1 -1
  214. package/dist/cli/command.js +4 -8
  215. package/dist/cli/command.js.map +1 -1
  216. package/dist/cli/host.d.ts +1 -1
  217. package/dist/cli/usage.d.ts +1 -5
  218. package/dist/cli/usage.js +4 -9
  219. package/dist/cli/usage.js.map +1 -1
  220. package/dist/compat/fetch-profile.d.ts +2 -2
  221. package/dist/compat/fetch-profile.js +16 -25
  222. package/dist/compat/fetch-profile.js.map +1 -1
  223. package/dist/compile-types.d.ts +2 -17
  224. package/dist/contracts/check.js +6 -6
  225. package/dist/contracts/check.js.map +1 -1
  226. package/dist/coverage/report.d.ts +5 -22
  227. package/dist/coverage/report.js +12 -76
  228. package/dist/coverage/report.js.map +1 -1
  229. package/dist/coverage/surface-manifest.d.ts +3 -3
  230. package/dist/coverage/surface-manifest.js +22 -27
  231. package/dist/coverage/surface-manifest.js.map +1 -1
  232. package/dist/coverage/verdict-cache.d.ts +1 -3
  233. package/dist/coverage/verdict-cache.js +2 -7
  234. package/dist/coverage/verdict-cache.js.map +1 -1
  235. package/dist/diagnostics/diagnostic.d.ts +11 -60
  236. package/dist/diagnostics/diagnostic.js +39 -118
  237. package/dist/diagnostics/diagnostic.js.map +1 -1
  238. package/dist/diagnostics/envelope.d.ts +3 -4
  239. package/dist/diagnostics/envelope.js +0 -9
  240. package/dist/diagnostics/envelope.js.map +1 -1
  241. package/dist/diagnostics/envelope.test.js +1 -1
  242. package/dist/diagnostics/envelope.test.js.map +1 -1
  243. package/dist/executable/executable-cache.d.ts +0 -3
  244. package/dist/executable/executable-cache.js +2 -4
  245. package/dist/executable/executable-cache.js.map +1 -1
  246. package/dist/executable/executable-cache.test.js +0 -4
  247. package/dist/executable/executable-cache.test.js.map +1 -1
  248. package/dist/executable/prepare.js +5 -2
  249. package/dist/executable/prepare.js.map +1 -1
  250. package/dist/frontend/analysis.js +10 -10
  251. package/dist/frontend/analysis.js.map +1 -1
  252. package/dist/frontend/cjs-syntax.js +0 -88
  253. package/dist/frontend/cjs-syntax.js.map +1 -1
  254. package/dist/frontend/dts-paths.d.ts +1 -1
  255. package/dist/frontend/dts-paths.js +1 -1
  256. package/dist/frontend/lowering/abstract-equality.js +1 -4
  257. package/dist/frontend/lowering/abstract-equality.js.map +1 -1
  258. package/dist/frontend/lowering/array-values.d.ts +14 -0
  259. package/dist/frontend/lowering/array-values.js +33 -11
  260. package/dist/frontend/lowering/array-values.js.map +1 -1
  261. package/dist/frontend/lowering/builtins/arguments.js +0 -13
  262. package/dist/frontend/lowering/builtins/arguments.js.map +1 -1
  263. package/dist/frontend/lowering/builtins/crypto.d.ts +0 -4
  264. package/dist/frontend/lowering/builtins/crypto.js +0 -4
  265. package/dist/frontend/lowering/builtins/crypto.js.map +1 -1
  266. package/dist/frontend/lowering/builtins/json.js +1 -39
  267. package/dist/frontend/lowering/builtins/json.js.map +1 -1
  268. package/dist/frontend/lowering/builtins/module-resolution.d.ts +0 -15
  269. package/dist/frontend/lowering/builtins/module-resolution.js +5 -44
  270. package/dist/frontend/lowering/builtins/module-resolution.js.map +1 -1
  271. package/dist/frontend/lowering/builtins/numbers.d.ts +0 -6
  272. package/dist/frontend/lowering/builtins/numbers.js +6 -57
  273. package/dist/frontend/lowering/builtins/numbers.js.map +1 -1
  274. package/dist/frontend/lowering/builtins/promises.js +4 -67
  275. package/dist/frontend/lowering/builtins/promises.js.map +1 -1
  276. package/dist/frontend/lowering/builtins/workers.js +1 -1
  277. package/dist/frontend/lowering/builtins/workers.js.map +1 -1
  278. package/dist/frontend/lowering/call-arguments.d.ts +1 -37
  279. package/dist/frontend/lowering/call-arguments.js +11 -94
  280. package/dist/frontend/lowering/call-arguments.js.map +1 -1
  281. package/dist/frontend/lowering/call-signatures.d.ts +1 -6
  282. package/dist/frontend/lowering/call-signatures.js +16 -68
  283. package/dist/frontend/lowering/call-signatures.js.map +1 -1
  284. package/dist/frontend/lowering/class-dynamic-dispatch.d.ts +19 -4
  285. package/dist/frontend/lowering/class-dynamic-dispatch.js +168 -98
  286. package/dist/frontend/lowering/class-dynamic-dispatch.js.map +1 -1
  287. package/dist/frontend/lowering/class-dynamic-dispatch.test.js +44 -4
  288. package/dist/frontend/lowering/class-dynamic-dispatch.test.js.map +1 -1
  289. package/dist/frontend/lowering/class-method-mutations.js +0 -2
  290. package/dist/frontend/lowering/class-method-mutations.js.map +1 -1
  291. package/dist/frontend/lowering/class-protocols.js +1 -1
  292. package/dist/frontend/lowering/class-protocols.js.map +1 -1
  293. package/dist/frontend/lowering/coercions/function-adapters.js +5 -35
  294. package/dist/frontend/lowering/coercions/function-adapters.js.map +1 -1
  295. package/dist/frontend/lowering/coercions/state.d.ts +0 -1
  296. package/dist/frontend/lowering/coercions/state.js +0 -1
  297. package/dist/frontend/lowering/coercions/state.js.map +1 -1
  298. package/dist/frontend/lowering/coercions/structural-plans.js +2 -4
  299. package/dist/frontend/lowering/coercions/structural-plans.js.map +1 -1
  300. package/dist/frontend/lowering/coercions/structural.js +2 -12
  301. package/dist/frontend/lowering/coercions/structural.js.map +1 -1
  302. package/dist/frontend/lowering/coercions/unions.js +0 -1
  303. package/dist/frontend/lowering/coercions/unions.js.map +1 -1
  304. package/dist/frontend/lowering/containers/array-callbacks.js +49 -28
  305. package/dist/frontend/lowering/containers/array-callbacks.js.map +1 -1
  306. package/dist/frontend/lowering/containers/array-construction.js +2 -3
  307. package/dist/frontend/lowering/containers/array-construction.js.map +1 -1
  308. package/dist/frontend/lowering/containers/array-methods.js +10 -54
  309. package/dist/frontend/lowering/containers/array-methods.js.map +1 -1
  310. package/dist/frontend/lowering/containers/array-pipelines.d.ts +54 -0
  311. package/dist/frontend/lowering/containers/array-pipelines.js +1827 -0
  312. package/dist/frontend/lowering/containers/array-pipelines.js.map +1 -0
  313. package/dist/frontend/lowering/containers/bytes.js +0 -1
  314. package/dist/frontend/lowering/containers/bytes.js.map +1 -1
  315. package/dist/frontend/lowering/containers/callback-arguments.js +2 -10
  316. package/dist/frontend/lowering/containers/callback-arguments.js.map +1 -1
  317. package/dist/frontend/lowering/containers/collection-methods.js +1 -6
  318. package/dist/frontend/lowering/containers/collection-methods.js.map +1 -1
  319. package/dist/frontend/lowering/containers/exec-result-uses.d.ts +10 -0
  320. package/dist/frontend/lowering/containers/exec-result-uses.js +88 -0
  321. package/dist/frontend/lowering/containers/exec-result-uses.js.map +1 -0
  322. package/dist/frontend/lowering/containers/indexed-objects.js +0 -2
  323. package/dist/frontend/lowering/containers/indexed-objects.js.map +1 -1
  324. package/dist/frontend/lowering/containers/string-and-regexp.d.ts +0 -6
  325. package/dist/frontend/lowering/containers/string-and-regexp.js +17 -17
  326. package/dist/frontend/lowering/containers/string-and-regexp.js.map +1 -1
  327. package/dist/frontend/lowering/containers/string-replacement.d.ts +2 -1
  328. package/dist/frontend/lowering/containers/string-replacement.js +32 -136
  329. package/dist/frontend/lowering/containers/string-replacement.js.map +1 -1
  330. package/dist/frontend/lowering/devirtualize.d.ts +33 -0
  331. package/dist/frontend/lowering/devirtualize.js +199 -0
  332. package/dist/frontend/lowering/devirtualize.js.map +1 -0
  333. package/dist/frontend/lowering/expressions/evaluation-safety.js +0 -3
  334. package/dist/frontend/lowering/expressions/evaluation-safety.js.map +1 -1
  335. package/dist/frontend/lowering/expressions/native-proxy.js +1 -1
  336. package/dist/frontend/lowering/expressions/native-proxy.js.map +1 -1
  337. package/dist/frontend/lowering/expressions/nullish-assignment.js +55 -8
  338. package/dist/frontend/lowering/expressions/nullish-assignment.js.map +1 -1
  339. package/dist/frontend/lowering/expressions/object-literals.d.ts +0 -8
  340. package/dist/frontend/lowering/expressions/object-literals.js +8 -35
  341. package/dist/frontend/lowering/expressions/object-literals.js.map +1 -1
  342. package/dist/frontend/lowering/expressions/optional-chains.d.ts +0 -4
  343. package/dist/frontend/lowering/expressions/optional-chains.js +3 -66
  344. package/dist/frontend/lowering/expressions/optional-chains.js.map +1 -1
  345. package/dist/frontend/lowering/function-context.js +0 -1
  346. package/dist/frontend/lowering/function-context.js.map +1 -1
  347. package/dist/frontend/lowering/generic-functions.js +0 -1
  348. package/dist/frontend/lowering/generic-functions.js.map +1 -1
  349. package/dist/frontend/lowering/identifier-uses.d.ts +7 -0
  350. package/dist/frontend/lowering/identifier-uses.js +23 -0
  351. package/dist/frontend/lowering/identifier-uses.js.map +1 -0
  352. package/dist/frontend/lowering/iterator-adapters.js +51 -3
  353. package/dist/frontend/lowering/iterator-adapters.js.map +1 -1
  354. package/dist/frontend/lowering/lib-boundary.js +10 -77
  355. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  356. package/dist/frontend/lowering/lower-array-sort.js +14 -10
  357. package/dist/frontend/lowering/lower-array-sort.js.map +1 -1
  358. package/dist/frontend/lowering/lower-array-sort.test.js +2 -2
  359. package/dist/frontend/lowering/lower-array-sort.test.js.map +1 -1
  360. package/dist/frontend/lowering/lower-assert.js +2 -3
  361. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  362. package/dist/frontend/lowering/lower-async-iteration.js +1 -1
  363. package/dist/frontend/lowering/lower-calls.d.ts +2 -27
  364. package/dist/frontend/lowering/lower-calls.js +111 -493
  365. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  366. package/dist/frontend/lowering/lower-classes.js +12 -60
  367. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  368. package/dist/frontend/lowering/lower-comptime.js +2 -3
  369. package/dist/frontend/lowering/lower-comptime.js.map +1 -1
  370. package/dist/frontend/lowering/lower-console.d.ts +14 -0
  371. package/dist/frontend/lowering/lower-console.js +195 -0
  372. package/dist/frontend/lowering/lower-console.js.map +1 -0
  373. package/dist/frontend/lowering/lower-enums.js +5 -8
  374. package/dist/frontend/lowering/lower-enums.js.map +1 -1
  375. package/dist/frontend/lowering/lower-event-emitter.js +3 -4
  376. package/dist/frontend/lowering/lower-event-emitter.js.map +1 -1
  377. package/dist/frontend/lowering/lower-expando.js +3 -5
  378. package/dist/frontend/lowering/lower-expando.js.map +1 -1
  379. package/dist/frontend/lowering/lower-exprs.d.ts +0 -8
  380. package/dist/frontend/lowering/lower-exprs.js +180 -905
  381. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  382. package/dist/frontend/lowering/lower-functions.js +9 -8
  383. package/dist/frontend/lowering/lower-functions.js.map +1 -1
  384. package/dist/frontend/lowering/lower-generators.d.ts +10 -0
  385. package/dist/frontend/lowering/lower-generators.js +108 -41
  386. package/dist/frontend/lowering/lower-generators.js.map +1 -1
  387. package/dist/frontend/lowering/lower-inspect.js +1 -50
  388. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  389. package/dist/frontend/lowering/lower-modules.d.ts +0 -43
  390. package/dist/frontend/lowering/lower-modules.js +29 -329
  391. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  392. package/dist/frontend/lowering/lower-modules.test.js +5 -5
  393. package/dist/frontend/lowering/lower-modules.test.js.map +1 -1
  394. package/dist/frontend/lowering/lower-server.js +0 -30
  395. package/dist/frontend/lowering/lower-server.js.map +1 -1
  396. package/dist/frontend/lowering/lower-stdlib.d.ts +98 -0
  397. package/dist/frontend/lowering/{lower-island.js → lower-stdlib.js} +97 -1160
  398. package/dist/frontend/lowering/lower-stdlib.js.map +1 -0
  399. package/dist/frontend/lowering/lower-stmts.d.ts +0 -16
  400. package/dist/frontend/lowering/lower-stmts.js +58 -1016
  401. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  402. package/dist/frontend/lowering/lower-stmts.test.js +1 -1
  403. package/dist/frontend/lowering/lower-stmts.test.js.map +1 -1
  404. package/dist/frontend/lowering/lower-stream.js +14 -13
  405. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  406. package/dist/frontend/lowering/lowerer.d.ts +42 -155
  407. package/dist/frontend/lowering/lowerer.js +192 -816
  408. package/dist/frontend/lowering/lowerer.js.map +1 -1
  409. package/dist/frontend/lowering/lowerer.test.js +4 -51
  410. package/dist/frontend/lowering/lowerer.test.js.map +1 -1
  411. package/dist/frontend/lowering/nan-coded-reads.d.ts +16 -0
  412. package/dist/frontend/lowering/nan-coded-reads.js +108 -1
  413. package/dist/frontend/lowering/nan-coded-reads.js.map +1 -1
  414. package/dist/frontend/lowering/narrowing-stability.js +1 -1
  415. package/dist/frontend/lowering/narrowing-stability.js.map +1 -1
  416. package/dist/frontend/lowering/optional-arguments.js +0 -2
  417. package/dist/frontend/lowering/optional-arguments.js.map +1 -1
  418. package/dist/frontend/lowering/runtime-optional-bounds.d.ts +4 -0
  419. package/dist/frontend/lowering/runtime-optional-bounds.js +2 -0
  420. package/dist/frontend/lowering/runtime-optional-bounds.js.map +1 -1
  421. package/dist/frontend/lowering/runtime-optional-bounds.test.js +27 -0
  422. package/dist/frontend/lowering/runtime-optional-bounds.test.js.map +1 -1
  423. package/dist/frontend/lowering/sanitize-class-types.test.js +2 -2
  424. package/dist/frontend/lowering/split-consumers.js +2 -18
  425. package/dist/frontend/lowering/split-consumers.js.map +1 -1
  426. package/dist/frontend/lowering/strict-equality.js +1 -1
  427. package/dist/frontend/lowering/strict-equality.js.map +1 -1
  428. package/dist/frontend/lowering/surfaces.d.ts +6 -45
  429. package/dist/frontend/lowering/surfaces.js +8 -73
  430. package/dist/frontend/lowering/surfaces.js.map +1 -1
  431. package/dist/frontend/lowering/union-retag.d.ts +6 -1
  432. package/dist/frontend/lowering/union-retag.js +64 -1
  433. package/dist/frontend/lowering/union-retag.js.map +1 -1
  434. package/dist/frontend/lowering/union-retag.test.js +46 -0
  435. package/dist/frontend/lowering/union-retag.test.js.map +1 -1
  436. package/dist/frontend/module-syntax.d.ts +0 -3
  437. package/dist/frontend/module-syntax.js.map +1 -1
  438. package/dist/frontend/npm-node.d.ts +0 -7
  439. package/dist/frontend/npm-node.js +0 -7
  440. package/dist/frontend/npm-node.js.map +1 -1
  441. package/dist/frontend/npm-static-rewrite-syntax.d.ts +1 -1
  442. package/dist/frontend/npm-static-rewrite-syntax.js +6 -82
  443. package/dist/frontend/npm-static-rewrite-syntax.js.map +1 -1
  444. package/dist/frontend/npm-static.d.ts +1 -1
  445. package/dist/frontend/npm-static.js +6 -71
  446. package/dist/frontend/npm-static.js.map +1 -1
  447. package/dist/frontend/npm.d.ts +3 -319
  448. package/dist/frontend/npm.js +6 -1007
  449. package/dist/frontend/npm.js.map +1 -1
  450. package/dist/frontend/npm.test.js +2 -197
  451. package/dist/frontend/npm.test.js.map +1 -1
  452. package/dist/frontend/pipeline-native.js +1 -2
  453. package/dist/frontend/pipeline-native.js.map +1 -1
  454. package/dist/frontend/pipeline.d.ts +3 -11
  455. package/dist/frontend/pipeline.js +37 -56
  456. package/dist/frontend/pipeline.js.map +1 -1
  457. package/dist/frontend/pipeline.test.js +12 -6
  458. package/dist/frontend/pipeline.test.js.map +1 -1
  459. package/dist/frontend/program.d.ts +0 -34
  460. package/dist/frontend/program.js +12 -97
  461. package/dist/frontend/program.js.map +1 -1
  462. package/dist/frontend/provenance-core.d.ts +0 -4
  463. package/dist/frontend/provenance-core.js +4 -37
  464. package/dist/frontend/provenance-core.js.map +1 -1
  465. package/dist/frontend/provenance-registry.d.ts +0 -4
  466. package/dist/frontend/provenance-registry.js +0 -20
  467. package/dist/frontend/provenance-registry.js.map +1 -1
  468. package/dist/frontend/resolve.d.ts +0 -12
  469. package/dist/frontend/resolve.js +0 -34
  470. package/dist/frontend/resolve.js.map +1 -1
  471. package/dist/frontend/runtime-resolve.js +2 -2
  472. package/dist/frontend/runtime-resolve.js.map +1 -1
  473. package/dist/frontend/services-node.js +2 -3
  474. package/dist/frontend/services-node.js.map +1 -1
  475. package/dist/frontend/services.d.ts +1 -8
  476. package/dist/frontend/services.js +2 -22
  477. package/dist/frontend/services.js.map +1 -1
  478. package/dist/frontend/services.test.js +0 -38
  479. package/dist/frontend/services.test.js.map +1 -1
  480. package/dist/frontend/tsc-codes.js +0 -11
  481. package/dist/frontend/tsc-codes.js.map +1 -1
  482. package/dist/frontend/type-mapper.d.ts +2 -27
  483. package/dist/frontend/type-mapper.js +58 -156
  484. package/dist/frontend/type-mapper.js.map +1 -1
  485. package/dist/index.d.ts +1 -1
  486. package/dist/index.js +7 -10
  487. package/dist/index.js.map +1 -1
  488. package/dist/ir/api.d.ts +1 -1
  489. package/dist/ir/api.js +1 -1
  490. package/dist/ir/api.js.map +1 -1
  491. package/dist/ir/builtin-effects.js +2 -5
  492. package/dist/ir/builtin-effects.js.map +1 -1
  493. package/dist/ir/builtin-signatures.d.ts +1 -1
  494. package/dist/ir/builtin-signatures.js +13 -56
  495. package/dist/ir/builtin-signatures.js.map +1 -1
  496. package/dist/ir/constant-globals.test.js +1 -1
  497. package/dist/ir/constant-tables.test.js +1 -1
  498. package/dist/ir/final-fields.test.js +1 -1
  499. package/dist/ir/function-references.d.ts +12 -0
  500. package/dist/ir/function-references.js +29 -0
  501. package/dist/ir/function-references.js.map +1 -0
  502. package/dist/ir/function-references.test.d.ts +1 -0
  503. package/dist/ir/function-references.test.js +276 -0
  504. package/dist/ir/function-references.test.js.map +1 -0
  505. package/dist/ir/initializer-bindings.test.js +1 -1
  506. package/dist/ir/int32-slots.d.ts +10 -7
  507. package/dist/ir/int32-slots.js +219 -68
  508. package/dist/ir/int32-slots.js.map +1 -1
  509. package/dist/ir/int32-slots.test.js +39 -2
  510. package/dist/ir/int32-slots.test.js.map +1 -1
  511. package/dist/ir/integer-ranges.d.ts +4 -4
  512. package/dist/ir/integer-ranges.js +89 -64
  513. package/dist/ir/integer-ranges.js.map +1 -1
  514. package/dist/ir/integer-ranges.test.js +71 -9
  515. package/dist/ir/integer-ranges.test.js.map +1 -1
  516. package/dist/ir/intrinsic-signatures.js +1 -0
  517. package/dist/ir/intrinsic-signatures.js.map +1 -1
  518. package/dist/ir/ir.d.ts +64 -290
  519. package/dist/ir/ir.js +11 -259
  520. package/dist/ir/ir.js.map +1 -1
  521. package/dist/ir/ir.test.js +2 -7
  522. package/dist/ir/ir.test.js.map +1 -1
  523. package/dist/ir/runtime-features.d.ts +3 -30
  524. package/dist/ir/runtime-features.js +8 -43
  525. package/dist/ir/runtime-features.js.map +1 -1
  526. package/dist/ir/scalar-records.test.js +1 -1
  527. package/dist/ir/serialize.d.ts +1 -1
  528. package/dist/ir/serialize.js +3 -3
  529. package/dist/ir/serialize.js.map +1 -1
  530. package/dist/ir/traverse.js +4 -21
  531. package/dist/ir/traverse.js.map +1 -1
  532. package/dist/ir/unshare.test.js +1 -1
  533. package/dist/ir/validate.js +66 -213
  534. package/dist/ir/validate.js.map +1 -1
  535. package/dist/ir/validate.test.js +31 -13
  536. package/dist/ir/validate.test.js.map +1 -1
  537. package/dist/library/fence-eval.test.js +1 -1
  538. package/dist/library/int-infer.test.js +4 -4
  539. package/dist/library/library-cache.test.js +5 -5
  540. package/dist/library/prepare.js +5 -20
  541. package/dist/library/prepare.js.map +1 -1
  542. package/dist/native/cli.js +0 -2
  543. package/dist/native/cli.js.map +1 -1
  544. package/dist/native/compiler.test.js +2 -4
  545. package/dist/native/compiler.test.js.map +1 -1
  546. package/dist/native/prepare.js +2 -4
  547. package/dist/native/prepare.js.map +1 -1
  548. package/dist/native/sanitizer.js +2 -16
  549. package/dist/native/sanitizer.js.map +1 -1
  550. package/dist/native/sanitizer.test.js +0 -3
  551. package/dist/native/sanitizer.test.js.map +1 -1
  552. package/dist/startup-cache.js +0 -2
  553. package/dist/startup-cache.js.map +1 -1
  554. package/package.json +20 -20
  555. package/surface-manifest.json +80 -104
  556. package/dist/backend/llvm/expr-island.d.ts +0 -15
  557. package/dist/backend/llvm/expr-island.js +0 -709
  558. package/dist/backend/llvm/expr-island.js.map +0 -1
  559. package/dist/frontend/lowering/coercions/island.d.ts +0 -37
  560. package/dist/frontend/lowering/coercions/island.js +0 -350
  561. package/dist/frontend/lowering/coercions/island.js.map +0 -1
  562. package/dist/frontend/lowering/lower-island.d.ts +0 -229
  563. package/dist/frontend/lowering/lower-island.js.map +0 -1
  564. package/dist/frontend/lowering/lower-island.test.js +0 -56
  565. package/dist/frontend/lowering/lower-island.test.js.map +0 -1
  566. package/dist/frontend/npm-fetch-analysis.d.ts +0 -17
  567. package/dist/frontend/npm-fetch-analysis.js +0 -109
  568. package/dist/frontend/npm-fetch-analysis.js.map +0 -1
  569. package/dist/frontend/npm-fetch-analysis.test.js +0 -130
  570. package/dist/frontend/npm-fetch-analysis.test.js.map +0 -1
  571. package/dist/frontend/npm-fetch-node.d.ts +0 -2
  572. package/dist/frontend/npm-fetch-node.js +0 -12
  573. package/dist/frontend/npm-fetch-node.js.map +0 -1
  574. package/dist/frontend/npm-fetch-syntax.d.ts +0 -6
  575. package/dist/frontend/npm-fetch-syntax.js +0 -202
  576. package/dist/frontend/npm-fetch-syntax.js.map +0 -1
  577. package/dist/native/runtime-typescript.d.ts +0 -4
  578. package/dist/native/runtime-typescript.js +0 -74
  579. package/dist/native/runtime-typescript.js.map +0 -1
  580. package/dist/native/runtime-typescript.test.js +0 -41
  581. package/dist/native/runtime-typescript.test.js.map +0 -1
  582. /package/dist/{frontend/lowering/lower-island.test.d.ts → backend/llvm/expr-calls.test.d.ts} +0 -0
  583. /package/dist/{frontend/npm-fetch-analysis.test.d.ts → backend/llvm/int32-abi.test.d.ts} +0 -0
  584. /package/dist/{native/runtime-typescript.test.d.ts → backend/llvm/regex-matchers.test.d.ts} +0 -0
@@ -1,261 +1,13 @@
1
- /* The npm RUNTIME graph: what --dynamic builds embed.
2
- *
3
- * Types come from declarations or TypeScript source (program.ts resolves
4
- * those through TypeScript itself); the CODE that runs is the package's shipped
5
- * JS (or JavaScript emitted from a TypeScript runtime entry), resolved
6
- * HERE at build time with Node's own resolution algorithm —
7
- * for every (importer, specifier) pair, node_modules directories are
8
- * probed from the importing FILE upward to the filesystem root, symlinks
9
- * are resolved with realpath (pnpm/bun virtual stores are symlink farms —
10
- * a package's dependencies live next to its REAL location, not its link),
11
- * package.json "exports" and package-scoped "imports" maps are honored
12
- * (import/require conditions, subpath patterns with '*'), with main/module
13
- * fallbacks and extension/directory-index resolution for the rest. The internal module graph
14
- * (the package's own relative imports/requires plus its dependencies')
15
- * is scanned with a real TypeScript parse collecting every module edge —
16
- * import/export declarations (including `export * as ns from`, which
17
- * ts.preProcessFile silently drops), dynamic import() of string literals,
18
- * and CommonJS require() calls — never a regex.
19
- *
20
- * Every reached module's SOURCE is embedded into the emitted LLVM as a static
21
- * string keyed by its REALPATH — one physical module embeds once, however
22
- * many symlink aliases reach it; scr_island.c serves the engine's module
23
- * loader (and a CommonJS require shim) from that map, so binaries never
24
- * read node_modules at runtime. Each CommonJS module additionally embeds a
25
- * synthesized ESM FACADE — default plus the named exports lexed from its
26
- * source with the compiler's quirk-faithful port of Node's vendored CJS
27
- * lexer (cjs-lexer.ts, the merve port program.ts also answers with) — so
28
- * ES modules inside the graph named-import CJS files exactly like under
29
- * Node, including the failures: a name Node's lexer cannot see is absent
30
- * from the facade and the embedded import fails at engine link time just
31
- * as Node's instantiate would.
32
- * Node builtins are NOT embedded: the island
33
- * ships shims for the set CLIs actually drive — the pure-JS tier (util,
34
- * assert, buffer, string_decoder, querystring, punycode, console, timers,
35
- * readline, async_hooks' two classes, events, module, tty) and the host
36
- * bridges riding the same C implementations the static lowerings use
37
- * (fs + fs/promises, path both families, url's WHATWG parser and file
38
- * converters, crypto's hashing/random slice, zlib, process, os) — the
39
- * worker_threads tier stays unshimmed (SHIMMED_BUILTINS is
40
- * the source of truth).
41
- *
42
- * EDGE-KIND SEMANTICS match Node's per kind, TRANSITIVELY. A STATIC
43
- * import/export edge in an eagerly-reached module is EAGER — Node links the
44
- * whole static graph before anything evaluates — so a static edge that
45
- * reaches an unshimmed builtin or does not resolve is a build-time
46
- * diagnostic naming the builtin/specifier, the requiring package, and the
47
- * dependency chain that reached it. A require() or dynamic import() edge is
48
- * LAZY — Node fails require at the CALL and import() at evaluation — and so
49
- * is EVERY edge of a module only reachable through lazy edges: Node links
50
- * that whole subgraph at the boundary call (a CLI's launcher shim
51
- * import()s its real CLI, so the CLI graph's own static imports fail at
52
- * that import(), never sooner). A blocked lazy edge embeds a runtime trap
53
- * instead of failing the build:
54
- * an unshimmed builtin keeps the island's own lazy throw (the edge embeds
55
- * pointing at the "node:x" key the shim table refuses at the call), an
56
- * unresolvable require() gets Node's MODULE_NOT_FOUND shape from the
57
- * island's require shim (message carrying the live Require stack, code,
58
- * requireStack — NO edge embeds; the shim owns the throw), and an
59
- * unresolvable import() embeds a throwing ESM stub with Node's
60
- * ERR_MODULE_NOT_FOUND shape (the addDynamicImport
61
- * ERR_UNKNOWN_FILE_EXTENSION stub's pattern). Blocked-but-lazy edges stay in
62
- * the build-time inventory (builtins/lazyTraps) so the coverage report says
63
- * exactly what the binary cannot reach. esbuild-published bundles route
64
- * external requires through a `__require` helper; its literal call sites
65
- * collect as require edges too, so esbuild dists get the same honest
66
- * build-time inventory. A specifier that RESOLVES to a .node native addon
67
- * embeds a throwing ERR_DLOPEN_FAILED stub instead of the addon's machine
68
- * code (the island has no process.dlopen; napi binding packages require()
69
- * their .node lazily next to a fallback, so the stub is the "addon
70
- * missing" path they already handle) — those keep an inventory row too
71
- * (lazyTraps, native: true).
72
- *
73
- * CONDITION SETS come from the CALL FORM, never the importer's format —
74
- * Node resolves import/export declarations and import() with
75
- * ["node","import"] and require() with ["node","require"] — so a DUAL
76
- * package (smol-toml's shape: "exports" whose "import" and "require"
77
- * conditions name different files) embeds BOTH entries, each behind its
78
- * own kind-tagged edge; the island's module loader looks edges up with
79
- * the import kind, its require shim with the require kind (the dual-
80
- * package hazard included: the two entries are distinct module
81
- * instances, exactly Node). And a require edge ATTRIBUTES to the module
82
- * whose scope defines the require function being called: esbuild's
83
- * `__require` lives in a shared chunk whose banner createRequire it
84
- * closed over, so a call site in ANOTHER chunk resolves — at build time
85
- * here and at runtime in Node — from the DEFINING chunk, and the edge
86
- * lives under its key (requireHelperOriginOf follows the import and
87
- * re-export hops).
88
- */
89
- import { dirname, extname, join, resolve } from "node:path";
90
- import { fileURLToPath, pathToFileURL } from "node:url";
91
- import { moduleSpecifiersOfFile } from "./module-syntax.js";
1
+ /** Node package resolution shared by preflight and native module introspection. */
2
+ import { dirname, join, resolve } from "node:path";
92
3
  import { packageNameOfSpecifier as packageNameOf } from "./workspace-registry.js";
93
- import { cjsLexedExportsOfFile } from "./cjs-syntax.js";
94
4
  import { trackedDirectoryExists, trackedFileExists, trackedReadFile, trackedRealpath, } from "./input-tracker.js";
95
5
  import { resolveExports, resolvePackageImports } from "./resolve.js";
96
- const LAZY_CALL_FORMS = [
97
- "require",
98
- "import()",
99
- "import",
100
- ];
101
6
  const NODE_IMPORT_CONDITIONS = new Set(["import", "node", "default"]);
102
7
  const NODE_REQUIRE_CONDITIONS = new Set(["require", "node", "default"]);
103
8
  function nodeExportConditions(mode) {
104
9
  return mode === "import" ? NODE_IMPORT_CONDITIONS : NODE_REQUIRE_CONDITIONS;
105
10
  }
106
- /* Node synthesizes named exports for CommonJS modules imported from ESM by
107
- * LEXING the CJS source at link time: `exports.x =` / `module.exports.x =`
108
- * assignments, `module.exports = {…}` object literals including esbuild's
109
- * dead `0 && (module.exports = {…})` annotation,
110
- * `Object.defineProperty(exports, "x", …)`, `module.exports = require(…)`
111
- * re-export forwarding, and the tsc/babel star-copy patterns. scriptc
112
- * holds every embedded CJS source at BUILD time, so the same detection
113
- * runs here through cjs-lexer.ts — the compiler's probed port of merve,
114
- * Node v24.15.0's vendored lexer. The npm package cjs-module-lexer is NOT
115
- * that lexer anymore and disagrees with it (a phantom "get" export for
116
- * `{ get a() {…} }` tables, missed `k: require(…)` value reexports), so
117
- * the port is the single source of truth for program CJS files and
118
- * embedded npm modules alike. */
119
- /** The ESM facade for an embedded CommonJS module, matching Node's interop
120
- * exactly (verified against Node 24): `default` IS module.exports;
121
- * "module.exports" is a named alias for it (Node ships that export name);
122
- * every lexed name binds the exports object's OWN property when one exists
123
- * at facade evaluation (getters read once — a snapshot, like Node's
124
- * loop over the lexed set) and stays undefined otherwise (a lexed-but-
125
- * never-assigned name is a live binding of undefined, not an error;
126
- * inherited properties do NOT leak through, hence the hasOwnProperty
127
- * guard). Export names that aren't identifiers ("dash-name") use string
128
- * ModuleExportNames — every name does, uniformly; the locals are e0, e1, …
129
- * temps. */
130
- function cjsEsmFacadeSource(key, names) {
131
- const uniq = [...new Set(names)].filter((n) => n !== "default" && n !== "module.exports");
132
- const parts = [`const m=globalThis.__scr_require(${JSON.stringify(key)});`, `export default m;`];
133
- if (uniq.length > 0)
134
- parts.push(`const H=Object.prototype.hasOwnProperty;`);
135
- const bound = uniq.map((n, i) => {
136
- const name = JSON.stringify(n);
137
- parts.push(`let e${i};if(H.call(m,${name}))e${i}=m[${name}];`);
138
- return `,e${i} as ${name}`;
139
- });
140
- parts.push(`export{m as "module.exports"${bound.join("")}};`);
141
- return parts.join("\n");
142
- }
143
- /** Builtins the island provides shims for (scr_island.c). Both spellings
144
- * resolve to the canonical "node:" key. Subpath forms ("fs/promises") are
145
- * NOT shimmed unless listed here explicitly. */
146
- const SHIMMED_BUILTINS = new Set([
147
- "events",
148
- "path",
149
- "process",
150
- "fs",
151
- "child_process",
152
- "os",
153
- "diagnostics_channel",
154
- "module",
155
- "url",
156
- "tty",
157
- "util",
158
- "util/types",
159
- "buffer",
160
- "string_decoder",
161
- "crypto",
162
- "stream",
163
- "stream/promises",
164
- "stream/consumers",
165
- "stream/web",
166
- "fs/promises",
167
- "async_hooks",
168
- "readline",
169
- "path/posix",
170
- "path/win32",
171
- "assert",
172
- "assert/strict",
173
- "punycode",
174
- "querystring",
175
- "constants",
176
- "console",
177
- "timers",
178
- "timers/promises",
179
- "zlib",
180
- // The deprecated legacy module, kept loadable because @sentry/node (the
181
- // a crash reporter) requires it at load on every path while
182
- // only driving it on Node < 14.
183
- "domain",
184
- // DNS imports load before any lookup. The callback and promise APIs
185
- // fence network queries through their own error channels at the call.
186
- "dns",
187
- "dns/promises",
188
- // The main-thread worker_threads surface (real in-process MessageChannel
189
- // ports, Worker fences at construction) and perf_hooks' performance —
190
- // undici requires both UNGUARDED at load.
191
- "worker_threads",
192
- "perf_hooks",
193
- // The socket tier (scr_net_island.c + the bootstrap's shims): http/https
194
- // are working CLIENTS over the socket units; net/tls load and fence
195
- // their socket surfaces loudly at the call (isIP and friends are real).
196
- "http",
197
- "https",
198
- "net",
199
- "tls",
200
- // Loadable with Node's surface: startupSnapshot answers for real (never
201
- // a snapshot build; the mutators throw Node's ERR_NOT_BUILDING_SNAPSHOT),
202
- // heap statistics are inert-but-typed, and the V8 serialization format
203
- // fences at the call. Prettier's bundled error helpers call
204
- // startupSnapshot.isBuildingSnapshot() on every CLI start.
205
- "v8",
206
- ]);
207
- /** Node builtins importable WITHOUT the "node:" prefix — used to tell
208
- * "missing builtin shim" apart from "missing package" for bare specifiers.
209
- * ("node:"-prefixed specifiers are always builtins: the prefix cannot name
210
- * an npm package.) */
211
- const KNOWN_BUILTINS = new Set([
212
- ...SHIMMED_BUILTINS,
213
- "assert",
214
- "async_hooks",
215
- "buffer",
216
- "cluster",
217
- "console",
218
- "constants",
219
- "crypto",
220
- "dgram",
221
- "diagnostics_channel",
222
- "dns",
223
- "domain",
224
- "http",
225
- "https",
226
- "http2",
227
- "inspector",
228
- "module",
229
- "net",
230
- "os",
231
- "perf_hooks",
232
- "punycode",
233
- "querystring",
234
- "readline",
235
- "repl",
236
- "stream",
237
- "string_decoder",
238
- "sys",
239
- "timers",
240
- "tls",
241
- "trace_events",
242
- "tty",
243
- "url",
244
- "util",
245
- "v8",
246
- "vm",
247
- "wasi",
248
- "worker_threads",
249
- "zlib",
250
- ]);
251
- function builtinKeyOf(specifier) {
252
- if (specifier.startsWith("node:"))
253
- return specifier; // forced builtin
254
- const root = specifier.split("/")[0]; // fs/promises → fs
255
- if (!KNOWN_BUILTINS.has(root))
256
- return null;
257
- return `node:${specifier}`;
258
- }
259
11
  export const realNpmGraphHost = {
260
12
  readFile: (path) => {
261
13
  return trackedReadFile(path);
@@ -264,9 +16,6 @@ export const realNpmGraphHost = {
264
16
  isDirectory: (path) => trackedDirectoryExists(path),
265
17
  realpath: (path) => trackedRealpath(path) ?? path,
266
18
  };
267
- /** Package name from a PATH into node_modules ("…/node_modules/@s/p/d/x.js"
268
- * → "@s/p"), for diagnostics/chains when the entry is a file, not a bare
269
- * specifier. Null when the path holds no node_modules segment. */
270
19
  export function packageNameOfPath(path) {
271
20
  const norm = path.split("\\").join("/");
272
21
  const idx = norm.lastIndexOf("/node_modules/");
@@ -353,17 +102,6 @@ export function probeNodeImportRefusal(fromFile, specifier, host = realNpmGraphH
353
102
  dir = parent;
354
103
  }
355
104
  }
356
- /** A bare-specifier `require()` edge Node's CJS resolution REFUSES because
357
- * NOTHING INSTALLED resolves it: no node_modules/<name> from the requiring
358
- * file up to the filesystem root, and no self-scope whose "name" matches.
359
- * Answers Node's exact require-site Error message (MODULE_NOT_FOUND's
360
- * "Cannot find module '<spec>'" with the one-entry require stack — the
361
- * message property really carries both lines). Everything else — installed
362
- * packages (whatever their exports say), builtins, relative and "#"
363
- * specifiers — answers null: the callers' existing stories stand. Unlike
364
- * the ESM startup-crash channel (SEMANTICS.md 287), this refusal is a
365
- * RUNTIME throw at the require site, catchable — the optional-dependency
366
- * try/require pattern depends on exactly that. */
367
105
  export function probeNodeRequireRefusal(fromFile, specifier, host = realNpmGraphHost) {
368
106
  if (specifier.startsWith("./") ||
369
107
  specifier.startsWith("../") ||
@@ -400,45 +138,14 @@ export function probeNodeRequireRefusal(fromFile, specifier, host = realNpmGraph
400
138
  message: `Cannot find module '${specifier}'\nRequire stack:\n- ${importer}`,
401
139
  };
402
140
  }
403
- export class NpmGraphBuilder {
404
- services;
141
+ export class NodePackageResolver {
405
142
  host;
406
- modules = new Map();
407
- edges = [];
408
- edgeSeen = new Set();
409
- entries = new Map(); // fromDir\0spec → key
410
143
  errors = [];
411
144
  pkgJsonCache = new Map();
412
- /** Modules whose format the RESOLUTION decided (the "module" field names
413
- * ESM sources regardless of the package's "type"). */
414
145
  formatOverrides = new Map();
415
- /** Canonical "node:x" → packages whose code imports it. */
416
- builtinsSeen = new Map();
417
- /** Canonical "node:x" keys some STATIC import reaches — those keep the
418
- * eager build error, so their builtins never mark lazy. */
419
- builtinsEager = new Set();
420
- /** Unresolvable (or native-addon) lazily-reached specifiers → merged
421
- * call forms/packages. */
422
- lazyTrapsSeen = new Map();
423
- /** Synthetic keys for embedded import()-not-found stubs. */
424
- importTrapCount = 0;
425
- /** moduleSpecifiersOf per module key — sweepEdges parses each module
426
- * once; the `__require` attribution chain re-reads helper chunks
427
- * through this cache. */
428
- specifiersCache = new Map();
429
- /** Helper attribution can read a module before walk reaches it. Share
430
- * preparation so its edges and embedded source always use the same JS. */
431
- sourceCache = new Map();
432
- constructor(services, host = realNpmGraphHost) {
433
- this.services = services;
146
+ constructor(host = realNpmGraphHost) {
434
147
  this.host = host;
435
148
  }
436
- /** Resolve one runtime module without embedding it. This is the package
437
- * half of import.meta.resolve/require.resolve: the answer is executable
438
- * source under Node's import/require conditions, never the declaration-file
439
- * answer from resolve.ts. Diagnostics produced by the graph-oriented
440
- * resolver are discarded here; the introspection lowering supplies Node's
441
- * public error shape separately. */
442
149
  resolveForIntrospection(fromFile, specifier, mode) {
443
150
  const before = this.errors.length;
444
151
  const key = this.resolvePackage(dirname(resolve(fromFile)), specifier, mode, {
@@ -449,329 +156,6 @@ export class NpmGraphBuilder {
449
156
  this.errors.length = before;
450
157
  return key;
451
158
  }
452
- /** Registers one user-level npm import and walks everything it reaches.
453
- * Idempotent per (importing dir, specifier). */
454
- addImport(fromFile, specifier) {
455
- this.resolveEntry(fromFile, specifier, false);
456
- }
457
- /** Registers one user-level RELATIVE import whose target lives inside
458
- * node_modules — the e2e driver shape (`import "../node_modules/vercel/
459
- * dist/index.js"`): tsc resolves the FILE into the program, but shipped
460
- * package code has exactly one execution home, the embedded engine.
461
- * Resolves with Node's file rules, embeds the reached graph EAGERLY (a
462
- * static import links at the root), and answers the runtime entry key.
463
- * Idempotent per (importing dir, specifier). */
464
- addFileImport(fromFile, specifier) {
465
- const cacheKey = this.entryKeyFor(fromFile, specifier);
466
- const cached = this.entries.get(cacheKey);
467
- if (cached !== undefined) {
468
- if (cached !== "")
469
- this.walk(cached, [packageNameOfPath(cached) ?? cached], false);
470
- return cached === "" ? null : cached;
471
- }
472
- const abs = resolve(dirname(resolve(fromFile)), specifier);
473
- const file = this.resolveFile(abs);
474
- if (file === null) {
475
- this.errors.push({ message: `cannot resolve '${specifier}' from ${fromFile}` });
476
- this.entries.set(cacheKey, "");
477
- return null;
478
- }
479
- const key = this.host.realpath(file);
480
- this.entries.set(cacheKey, key);
481
- this.walk(key, [packageNameOfPath(key) ?? key], false);
482
- return key;
483
- }
484
- /** Registers one user-level dynamic `import(specifier)` and embeds what
485
- * it reaches, returning the build-time classification the lowering acts
486
- * on. Bare package specifiers take the same path as static imports;
487
- * builtins map to their island shim keys ("fs" → "node:fs") or report
488
- * the missing shim; RELATIVE specifiers — the shape static imports never
489
- * see, because tsc compiles those — resolve against the importing FILE
490
- * with Node's file/extension/directory rules and embed the reached JS
491
- * graph. A relative target that is TypeScript is the program's own
492
- * module (compiled natively and exposed through the import lowering), and one
493
- * with an extension no loader executes (.wasm, .node, ...) embeds a stub
494
- * whose EVALUATION throws Node's exact ERR_UNKNOWN_FILE_EXTENSION
495
- * TypeError — the build succeeds and the import() rejects at runtime,
496
- * which is precisely what Node does. */
497
- addDynamicImport(fromFile, specifier) {
498
- if (specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/")) {
499
- const abs = specifier.startsWith("/")
500
- ? specifier
501
- : resolve(dirname(resolve(fromFile)), specifier);
502
- const file = this.resolveFile(abs);
503
- if (!file) {
504
- return {
505
- kind: "unresolved",
506
- message: `cannot resolve '${specifier}' from ${fromFile}`,
507
- };
508
- }
509
- const key = this.host.realpath(file);
510
- if (/\.(ts|tsx|mts|cts)$/.test(key))
511
- return { kind: "program-module" };
512
- const ext = extname(key);
513
- if (ext !== ".js" && ext !== ".mjs" && ext !== ".cjs" && ext !== ".json") {
514
- if (!this.modules.has(key)) {
515
- const msg = `Unknown file extension "${ext}" for ${key}`;
516
- this.modules.set(key, {
517
- key,
518
- source: `throw Object.assign(new TypeError(${JSON.stringify(msg)}),` +
519
- `{code:"ERR_UNKNOWN_FILE_EXTENSION"});\n`,
520
- format: "esm",
521
- });
522
- }
523
- return { kind: "module", key };
524
- }
525
- // The reached subgraph sits behind THIS import() — a lazy boundary:
526
- // blocked edges inside it (static ones included) trap at runtime,
527
- // where Node fails the import()'s link.
528
- this.walk(key, [specifier], true);
529
- return { kind: "module", key };
530
- }
531
- const builtin = builtinKeyOf(specifier);
532
- if (builtin) {
533
- if (!SHIMMED_BUILTINS.has(builtin.slice(5))) {
534
- return { kind: "unsupported-builtin", builtin };
535
- }
536
- return { kind: "module", key: builtin };
537
- }
538
- const errorsBefore = this.errors.length;
539
- const key = this.resolveEntry(fromFile, specifier, true);
540
- if (key === null) {
541
- // A refusal NODE ITSELF would answer at runtime — the package isn't
542
- // installed, its exports refuse the subpath, or the matched target
543
- // file doesn't exist — is not a build error: Node evaluates the
544
- // import() and REJECTS it with exactly this error (the program may
545
- // never even call it). Embed the throwing stub with Node's message
546
- // and code, exactly like the ERR_UNKNOWN_FILE_EXTENSION stub above;
547
- // the resolveEntry error text it superseded comes off the list.
548
- // Failures that are NOT Node-shaped refusals (unreadable manifests,
549
- // deep-graph embed problems) stay build errors.
550
- const refusal = probeNodeImportRefusal(fromFile, specifier, this.host);
551
- if (refusal !== null) {
552
- this.errors.length = errorsBefore;
553
- return { kind: "module", key: this.refusalTrap(refusal) };
554
- }
555
- return {
556
- kind: "unresolved",
557
- message: this.errors[this.errors.length - 1]?.message ??
558
- `cannot resolve '${specifier}' from ${fromFile}`,
559
- };
560
- }
561
- return { kind: "module", key };
562
- }
563
- /** Embeds (once per distinct refusal) the ESM stub whose EVALUATION
564
- * throws a probed Node refusal — the import() rejects at runtime with
565
- * Node's exact message and code, the build succeeds. */
566
- refusalTrap(refusal) {
567
- const key = `scr:import-trap:${this.importTrapCount++}`;
568
- const props = `{code:${JSON.stringify(refusal.code)}` +
569
- (refusal.url === undefined ? `}` : `,url:${JSON.stringify(refusal.url)}}`);
570
- this.modules.set(key, {
571
- key,
572
- source: `throw Object.assign(new Error(${JSON.stringify(refusal.message)}),${props});\n`,
573
- format: "esm",
574
- });
575
- return key;
576
- }
577
- /** The runtime entry key a previously-added import resolved to. */
578
- entryOf(fromFile, specifier) {
579
- const key = this.entries.get(this.entryKeyFor(fromFile, specifier));
580
- return key === undefined || key === "" ? null : key;
581
- }
582
- /** Registers one user-level createRequire(...) require and walks what
583
- * it reaches, answering the runtime entry key — resolveEntry's twin
584
- * under Node's "require" condition (a dual package embeds its CJS arm,
585
- * exactly what Node's createRequire loads). The cache key carries the
586
- * mode so a file both importing and requiring one specifier keeps two
587
- * entries, like the graph's own kind-split edges. */
588
- addRequire(fromFile, specifier) {
589
- const cacheKey = `require\u0000${this.entryKeyFor(fromFile, specifier)}`;
590
- const cached = this.entries.get(cacheKey);
591
- if (cached !== undefined) {
592
- if (cached !== "")
593
- this.walk(cached, [packageNameOf(specifier)], false);
594
- return cached === "" ? null : cached;
595
- }
596
- const key = this.resolvePackage(dirname(resolve(fromFile)), specifier, "require", {
597
- importer: resolve(fromFile),
598
- chain: [],
599
- });
600
- this.entries.set(cacheKey, key ?? "");
601
- if (key)
602
- this.walk(key, [packageNameOf(specifier)], false);
603
- return key;
604
- }
605
- /** The embedded format of a resolved module key ("cjs"/"esm"/"json") —
606
- * the require lowering picks its export name by it (a CJS facade's
607
- * default IS module.exports; an ESM entry answers its namespace, the
608
- * require(esm) shape). */
609
- moduleFormatOf(key) {
610
- return this.modules.get(key)?.format ?? null;
611
- }
612
- entryKeyFor(fromFile, specifier) {
613
- return `${dirname(resolve(fromFile))}\u0000${specifier}`;
614
- }
615
- resolveEntry(fromFile, specifier, lazy) {
616
- const cacheKey = this.entryKeyFor(fromFile, specifier);
617
- const cached = this.entries.get(cacheKey);
618
- if (cached !== undefined) {
619
- // A static import of an entry first reached through import():
620
- // re-walk eagerly so the subgraph promotes (Node links it now).
621
- if (cached !== "" && !lazy)
622
- this.walk(cached, [packageNameOf(specifier)], false);
623
- return cached === "" ? null : cached;
624
- }
625
- // User-level entries prefer the ESM ("import") condition — the engine
626
- // loads real ES modules natively; CJS-only packages fall back to the
627
- // require shim.
628
- const key = this.resolvePackage(dirname(resolve(fromFile)), specifier, "import", {
629
- importer: resolve(fromFile),
630
- chain: [],
631
- });
632
- this.entries.set(cacheKey, key ?? "");
633
- if (key)
634
- this.walk(key, [packageNameOf(specifier)], lazy);
635
- return key;
636
- }
637
- /** The cjs-lexer.ts pass over every embedded CommonJS module: lex the
638
- * export names exactly as Node's vendored lexer would, follow the
639
- * re-export forms (`module.exports = require(…)`, table spreads/values,
640
- * the tsc/babel star patterns) through the ALREADY-RESOLVED edges
641
- * (builtin and unresolved targets are skipped; a require cycle
642
- * contributes what is known when re-entered, like Node's seen-set), then
643
- * synthesize each module's ESM facade. */
644
- synthesizeCjsFacades() {
645
- const target = new Map();
646
- // Following a CJS re-export IS a require: when a dual package embeds
647
- // kind-split edges, the "require" one names the module whose exports
648
- // Node's lexer chain would read.
649
- for (const e of this.edges) {
650
- const k = `${e.from}\u0000${e.specifier}`;
651
- if (e.kind === "require" || !target.has(k))
652
- target.set(k, e.to);
653
- }
654
- const memo = new Map();
655
- const namesOf = (key) => {
656
- let names = memo.get(key);
657
- if (names)
658
- return names;
659
- memo.set(key, (names = new Set()));
660
- const mod = this.modules.get(key);
661
- if (!mod || mod.format !== "cjs")
662
- return names;
663
- const lexed = cjsLexedExportsOfFile(this.services.parse(key, mod.source, "js"));
664
- for (const n of lexed.exports)
665
- names.add(n);
666
- for (const spec of lexed.reexports) {
667
- const to = target.get(`${key}\u0000${spec}`);
668
- if (to !== undefined && !to.startsWith("node:")) {
669
- for (const n of namesOf(to))
670
- names.add(n);
671
- }
672
- }
673
- return names;
674
- };
675
- for (const mod of this.modules.values()) {
676
- if (mod.format === "cjs" && mod.esm === undefined) {
677
- mod.esm = cjsEsmFacadeSource(mod.key, [...namesOf(mod.key)]);
678
- }
679
- }
680
- }
681
- finish() {
682
- this.synthesizeCjsFacades();
683
- for (const key of this.services.globalFetchModules([...this.modules.values()])) {
684
- const mod = this.modules.get(key);
685
- if (mod !== undefined)
686
- mod.usesFetch = true;
687
- }
688
- return {
689
- modules: [...this.modules.values()],
690
- edges: this.edges,
691
- entryOf: (fromFile, specifier) => {
692
- const key = this.entries.get(this.entryKeyFor(fromFile, specifier));
693
- return key === undefined || key === "" ? null : key;
694
- },
695
- builtins: [...this.builtinsSeen.entries()]
696
- .map(([builtin, packages]) => {
697
- const shimmed = SHIMMED_BUILTINS.has(builtin.slice(5));
698
- return {
699
- builtin,
700
- shimmed,
701
- lazy: !shimmed && !this.builtinsEager.has(builtin),
702
- packages: [...packages].sort(),
703
- };
704
- })
705
- .sort((a, b) => a.builtin.localeCompare(b.builtin)),
706
- lazyTraps: [...this.lazyTrapsSeen.entries()]
707
- .map(([specifier, t]) => ({
708
- specifier,
709
- via: LAZY_CALL_FORMS.filter((v) => t.via.has(v)),
710
- packages: [...t.packages].sort(),
711
- ...(t.native ? { native: true } : {}),
712
- }))
713
- .sort((a, b) => a.specifier.localeCompare(b.specifier)),
714
- errors: this.errors,
715
- };
716
- }
717
- /* ── lazy runtime traps (require()/import() edges Node fails at the
718
- * call — the build embeds the failure instead of refusing) ─────────── */
719
- /** Records one unresolvable lazily-reached specifier for the build-time
720
- * inventory (the coverage report's lazy-trap rows). `via` carries only
721
- * the call forms whose OWN resolution failed — with per-kind condition
722
- * resolution, one form of a specifier can fail while another succeeds. */
723
- noteLazyTrap(spec, via, pkgName, moduleLazy, native = false) {
724
- let t = this.lazyTrapsSeen.get(spec);
725
- if (!t)
726
- this.lazyTrapsSeen.set(spec, (t = { via: new Set(), packages: new Set(), native }));
727
- if (via.require)
728
- t.via.add("require");
729
- if (via.dynamicImport)
730
- t.via.add("import()");
731
- if (via.static && moduleLazy)
732
- t.via.add("import");
733
- t.packages.add(pkgName);
734
- }
735
- /** Embeds the throwing ESM stub for an unresolvable dynamic import()
736
- * edge — Node's exact ERR_MODULE_NOT_FOUND shape at evaluation: bare
737
- * specifiers say `Cannot find package 'x' imported from <file>`,
738
- * relative ones resolve against the importer first and say `Cannot find
739
- * module '<abs>' imported from <file>` carrying the file:// url, which
740
- * is what Node's ESM resolver rejects with. Returns the stub's key (the
741
- * edge target). require() never reaches these: unresolvable require
742
- * edges embed NO edge and the island's require shim throws Node's
743
- * MODULE_NOT_FOUND at the call, with the LIVE require stack. */
744
- importNotFoundTrap(from, spec) {
745
- const key = `scr:import-trap:${this.importTrapCount++}`;
746
- let msg;
747
- let url = null;
748
- if (spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("/")) {
749
- const abs = spec.startsWith("/") ? spec : resolve(dirname(from), spec);
750
- msg = `Cannot find module '${abs}' imported from ${from}`;
751
- url = `file://${abs}`;
752
- }
753
- else {
754
- msg = `Cannot find package '${packageNameOf(spec)}' imported from ${from}`;
755
- }
756
- const props = `{code:"ERR_MODULE_NOT_FOUND"` + (url === null ? `}` : `,url:${JSON.stringify(url)}}`);
757
- this.modules.set(key, {
758
- key,
759
- source: `throw Object.assign(new Error(${JSON.stringify(msg)}),${props});\n`,
760
- format: "esm",
761
- });
762
- return key;
763
- }
764
- /** The throwing stub embedded for a resolved .node native addon: Node's
765
- * ERR_DLOPEN_FAILED code (what a broken dlopen throws) with the island's
766
- * honest message. Evaluation throws — at the require() call, at a
767
- * facade-mediated import, at import() — and the CJS cache keeps no entry
768
- * for a throwing module, so every retry throws again, like Node. */
769
- static nativeAddonStub(key) {
770
- const msg = `Cannot load native addon '${key}': scriptc binaries cannot load .node addons ` +
771
- `(the island has no process.dlopen)`;
772
- return `throw Object.assign(new Error(${JSON.stringify(msg)}),{code:"ERR_DLOPEN_FAILED"});\n`;
773
- }
774
- /* ── resolution ─────────────────────────────────────────────────── */
775
159
  pkgJsonOf(dir) {
776
160
  let cached = this.pkgJsonCache.get(dir);
777
161
  if (cached === undefined) {
@@ -781,37 +165,6 @@ export class NpmGraphBuilder {
781
165
  }
782
166
  return cached;
783
167
  }
784
- /** The nearest package.json "type" above `file` — the .js format rule.
785
- * Resolution-time overrides (the "module" field) win. */
786
- formatOf(file) {
787
- if (file.endsWith(".mts"))
788
- return "esm";
789
- if (file.endsWith(".cts"))
790
- return "cjs";
791
- const override = this.formatOverrides.get(file);
792
- if (override)
793
- return override;
794
- if (file.endsWith(".mjs"))
795
- return "esm";
796
- if (file.endsWith(".cjs"))
797
- return "cjs";
798
- if (file.endsWith(".json"))
799
- return "json";
800
- for (let dir = dirname(file);;) {
801
- const pkg = this.pkgJsonOf(dir);
802
- if (pkg)
803
- return pkg.type === "module" ? "esm" : "cjs";
804
- const parent = dirname(dir);
805
- if (parent === dir)
806
- return "cjs";
807
- dir = parent;
808
- }
809
- }
810
- /** Node-style file resolution: exact file, extension candidates
811
- * (commander requires './suggestSimilar'; ".node" is in Node's require
812
- * probe list — the resolved addon embeds as a throwing dlopen stub),
813
- * then directory resolution (the directory's package.json "main", else
814
- * its index files). */
815
168
  resolveFile(path, depth = 0) {
816
169
  if (depth > 8)
817
170
  return null; // a "main" cycle — refuse quietly
@@ -837,19 +190,10 @@ export class NpmGraphBuilder {
837
190
  }
838
191
  return null;
839
192
  }
840
- /** "a → b → c" — the package chain from the user's import to the point
841
- * of failure, for diagnostics. */
842
193
  static chainOf(chain, last) {
843
194
  const full = last === undefined ? chain : [...chain, last];
844
195
  return full.join(" → ");
845
196
  }
846
- /** Locates node_modules/<name> by walking up from `fromDir` to the
847
- * filesystem ROOT (dependencies hoist arbitrarily far in workspace
848
- * layouts), following symlinks with realpath (pnpm/bun virtual stores),
849
- * then resolves the runtime entry: package.json "exports" with the
850
- * given condition (strict — an exports map that doesn't match is an
851
- * error, like Node's ERR_PACKAGE_PATH_NOT_EXPORTED), else the "module"/
852
- * "main" fallbacks. Returns the realpath'd entry key. */
853
197
  resolvePackage(fromDir, specifier, mode, ctx) {
854
198
  if (specifier.startsWith("#")) {
855
199
  return this.resolvePackageImport(fromDir, specifier, mode, ctx);
@@ -858,7 +202,7 @@ export class NpmGraphBuilder {
858
202
  const parts = specifier.split("/");
859
203
  const subparts = specifier.startsWith("@") ? parts.slice(2) : parts.slice(1);
860
204
  const subpath = subparts.length > 0 ? `./${subparts.join("/")}` : ".";
861
- const chain = NpmGraphBuilder.chainOf(ctx.chain, name);
205
+ const chain = NodePackageResolver.chainOf(ctx.chain, name);
862
206
  // Node's PACKAGE_SELF_RESOLVE runs BEFORE any node_modules lookup: the
863
207
  // nearest package scope above the importing module whose "name" equals
864
208
  // the specifier's package name AND that carries "exports" answers the
@@ -955,10 +299,6 @@ export class NpmGraphBuilder {
955
299
  dir = parent;
956
300
  }
957
301
  }
958
- /** Resolves a package-internal "#" specifier from the nearest package
959
- * scope. Relative targets stay in that package; bare package targets
960
- * re-enter the same runtime resolver so edge-kind conditions and package
961
- * self-resolution remain consistent. */
962
302
  resolvePackageImport(fromDir, specifier, mode, ctx) {
963
303
  let pkgDir = null;
964
304
  let pkg = null;
@@ -974,7 +314,7 @@ export class NpmGraphBuilder {
974
314
  break;
975
315
  dir = parent;
976
316
  }
977
- const chain = NpmGraphBuilder.chainOf(ctx.chain);
317
+ const chain = NodePackageResolver.chainOf(ctx.chain);
978
318
  if (pkgDir === null || pkg === null) {
979
319
  this.errors.push({
980
320
  message: `package import '${specifier}' has no enclosing package.json` +
@@ -1021,346 +361,5 @@ export class NpmGraphBuilder {
1021
361
  }
1022
362
  return this.resolvePackage(pkgDir, target, mode, ctx);
1023
363
  }
1024
- /* ── the walk ─────────────────────────────────────────────────── */
1025
- /** Modules reached ONLY through lazy edges so far. Node has not linked
1026
- * these at the root: the whole subgraph behind a require()/import()
1027
- * boundary links AT THE CALL, so every blocked edge inside it — static
1028
- * imports included — fails there at runtime, never at build time. A
1029
- * later STATIC path promotes the module to eager: its edges re-sweep so
1030
- * blocked static ones become build errors, exactly the graph Node would
1031
- * refuse at link. */
1032
- lazilyReached = new Set();
1033
- /** Embeds `key` and everything it reaches. `chain` is the package path
1034
- * from the user's import to this module's package — diagnostics name it
1035
- * so a failure five dependencies deep is attributable. `lazy` is the
1036
- * REACHABILITY mode: true when every path from the user's import to this
1037
- * module crosses a require()/dynamic-import() edge. */
1038
- walk(key, chain, lazy) {
1039
- const existing = this.modules.get(key);
1040
- if (existing) {
1041
- if (!lazy && this.lazilyReached.has(key)) {
1042
- // Promotion: a static path reached a module first seen behind a
1043
- // lazy boundary — Node links it at the root now, so its edge
1044
- // sweep re-runs eagerly (pushes dedupe through edgeSeen).
1045
- this.lazilyReached.delete(key);
1046
- if (existing.format !== "json") {
1047
- this.sweepEdges(key, existing.source, chain, false);
1048
- }
1049
- }
1050
- return;
1051
- }
1052
- if (key.endsWith(".node")) {
1053
- // A native addon: Node process.dlopen()s it; the island has no
1054
- // dlopen, so the resolved edge embeds a throwing CJS STUB (Node's
1055
- // ERR_DLOPEN_FAILED code) instead of megabytes of machine code the
1056
- // engine could never execute — rolldown/oxc-style binding packages
1057
- // require() their .node next to a wasm/js fallback, so the stub is
1058
- // exactly the "addon missing" path those packages already handle.
1059
- // The require sites are lazy by construction (an eager static
1060
- // import of a .node would refuse under Node too), so the throw
1061
- // lands at the call, the only point Node would have dlopen'd.
1062
- this.modules.set(key, { key, source: NpmGraphBuilder.nativeAddonStub(key), format: "cjs" });
1063
- return;
1064
- }
1065
- const prepared = this.sourceOf(key);
1066
- if ("error" in prepared) {
1067
- this.errors.push({
1068
- message: `${prepared.error} (dependency chain: ${NpmGraphBuilder.chainOf(chain)})`,
1069
- });
1070
- return;
1071
- }
1072
- const source = prepared.source;
1073
- const format = this.formatOf(key);
1074
- this.modules.set(key, { key, source, format });
1075
- if (lazy)
1076
- this.lazilyReached.add(key);
1077
- if (format === "json")
1078
- return;
1079
- this.sweepEdges(key, source, chain, lazy);
1080
- }
1081
- sourceOf(key) {
1082
- const cached = this.sourceCache.get(key);
1083
- if (cached !== undefined)
1084
- return cached;
1085
- const source = this.host.readFile(key);
1086
- let result;
1087
- if (source === null) {
1088
- result = { error: `cannot read embedded module '${key}'` };
1089
- }
1090
- else if (/\.(?:[cm]?ts|tsx)$/.test(key)) {
1091
- try {
1092
- const format = this.formatOf(key);
1093
- result = {
1094
- source: this.services.emitRuntimeTypeScript(key, source, format === "esm" ? "esm" : "cjs"),
1095
- };
1096
- }
1097
- catch (error) {
1098
- result = {
1099
- error: `cannot emit TypeScript module '${key}': ${error instanceof Error ? error.message : String(error)}`,
1100
- };
1101
- }
1102
- }
1103
- else {
1104
- result = { source };
1105
- }
1106
- this.sourceCache.set(key, result);
1107
- return result;
1108
- }
1109
- /** moduleSpecifiersOf through the per-module cache (each module parses
1110
- * once even across promotion re-sweeps, and the `__require` attribution
1111
- * chain re-reads helper chunks it never sweeps itself). */
1112
- specifiersOf(key, source) {
1113
- let cached = this.specifiersCache.get(key);
1114
- if (cached === undefined) {
1115
- const prepared = source === undefined ? this.sourceOf(key) : { source };
1116
- const text = "source" in prepared ? prepared.source : null;
1117
- cached = text === null ? null : moduleSpecifiersOfFile(this.services.parse(key, text, "js"));
1118
- this.specifiersCache.set(key, cached);
1119
- }
1120
- return cached;
1121
- }
1122
- /** The module whose scope DEFINES the `__require` helper that `key`'s
1123
- * call sites invoke, or null when it is key's own (or unresolvable).
1124
- * esbuild splits the helper into a shared chunk that every other chunk
1125
- * imports; the helper closed over THAT chunk's banner require
1126
- * (createRequire(import.meta.url)), so Node resolves its calls from the
1127
- * DEFINING chunk — and the island's require shim looks the edge up
1128
- * under that key at the call. Follows import → re-export hops through
1129
- * intermediate chunks, bounded. */
1130
- requireHelperOriginOf(key) {
1131
- let cur = key;
1132
- for (let hops = 0; hops < 8; hops++) {
1133
- const specs = this.specifiersOf(cur);
1134
- const next = specs === null
1135
- ? null
1136
- : cur === key
1137
- ? specs.requireHelperImport
1138
- : (specs.requireHelperImport ?? specs.requireHelperReexport);
1139
- if (next === null)
1140
- break;
1141
- let target = null;
1142
- if (next.startsWith("./") || next.startsWith("../")) {
1143
- const file = this.resolveFile(resolve(dirname(cur), next));
1144
- target = file === null ? null : this.host.realpath(file);
1145
- }
1146
- else if (builtinKeyOf(next) === null) {
1147
- const errorsBefore = this.errors.length;
1148
- target = this.resolvePackage(dirname(cur), next, "import", { importer: cur, chain: [] });
1149
- if (target === null)
1150
- this.errors.length = errorsBefore;
1151
- }
1152
- if (target === null)
1153
- break;
1154
- cur = target;
1155
- }
1156
- return cur === key ? null : cur;
1157
- }
1158
- /** One module's edge sweep. Per-edge semantics match Node's: an edge is
1159
- * EAGER only when the module itself is eagerly reached AND the site is a
1160
- * static import/export declaration — Node's link-time surface, where a
1161
- * blocked edge fails the BUILD. Everything else is LAZY — Node fails
1162
- * require at the CALL and import() at evaluation, and a subgraph behind
1163
- * either boundary (its static edges included) links at that call — so a
1164
- * blocked lazy edge embeds a runtime trap and the build succeeds: a
1165
- * program that never executes the call runs fine under Node too. */
1166
- sweepEdges(key, source, chain, lazy) {
1167
- const pkgName = chain[chain.length - 1] ?? key;
1168
- const pushEdge = (from, spec, to, kind) => {
1169
- const edgeKey = `${from}\u0000${spec}\u0000${kind}`;
1170
- if (this.edgeSeen.has(edgeKey))
1171
- return;
1172
- this.edgeSeen.add(edgeKey);
1173
- this.edges.push({ from, specifier: spec, to, kind });
1174
- };
1175
- const specifiers = this.specifiersOf(key, source);
1176
- if (specifiers === null)
1177
- return;
1178
- for (const use of specifiers.uses) {
1179
- const spec = use.specifier;
1180
- const eager = !lazy && use.static;
1181
- // CommonJS treats bare "." and ".." as directory-relative requires.
1182
- const requireDirectory = (spec === "." || spec === "..") && use.require && !use.static && !use.dynamicImport;
1183
- if (spec.startsWith("./") || spec.startsWith("../") || requireDirectory) {
1184
- if (use.importMetaResolve && !use.static && !use.dynamicImport && !use.require) {
1185
- continue;
1186
- }
1187
- // ESM percent escapes name decoded filesystem paths; CommonJS
1188
- // keeps the literal filename. Most specs share an edge, but a
1189
- // percent-escaped spec used by both forms needs separate targets.
1190
- const importing = use.static || use.dynamicImport;
1191
- const requests = [];
1192
- let importPath = resolve(dirname(key), spec);
1193
- if (importing && spec.includes("%")) {
1194
- try {
1195
- const url = new URL(spec, pathToFileURL(key));
1196
- if (url.search || url.hash) {
1197
- this.errors.push({
1198
- message: `package '${pkgName}' cannot embed '${spec}' from ${key}: distinct URL query or fragment module instances are not supported`,
1199
- });
1200
- continue;
1201
- }
1202
- importPath = fileURLToPath(url);
1203
- }
1204
- catch {
1205
- importPath = null;
1206
- }
1207
- }
1208
- if (use.require && importing && spec.includes("%")) {
1209
- requests.push({ kind: "require", path: resolve(dirname(key), spec) }, { kind: "import", path: importPath });
1210
- }
1211
- else {
1212
- requests.push({ kind: "any", path: importPath });
1213
- }
1214
- for (const request of requests) {
1215
- const importRequest = request.kind !== "require" && importing;
1216
- const requestVia = {
1217
- require: request.kind !== "import" && use.require,
1218
- dynamicImport: importRequest && use.dynamicImport,
1219
- static: importRequest && use.static,
1220
- };
1221
- const file = request.path === null ? null : this.resolveFile(request.path);
1222
- const to = file === null ? null : this.host.realpath(file);
1223
- if (!to) {
1224
- if (!lazy && requestVia.static) {
1225
- this.errors.push({
1226
- message: `package '${pkgName}' cannot resolve '${spec}' from ${key}` +
1227
- ` (dependency chain: ${NpmGraphBuilder.chainOf(chain)})`,
1228
- });
1229
- }
1230
- else {
1231
- this.noteLazyTrap(spec, requestVia, pkgName, lazy);
1232
- if (requestVia.dynamicImport || (lazy && requestVia.static)) {
1233
- pushEdge(key, spec, this.importNotFoundTrap(key, spec), "import");
1234
- }
1235
- }
1236
- continue;
1237
- }
1238
- if (to.endsWith(".node"))
1239
- this.noteLazyTrap(spec, requestVia, pkgName, lazy, true);
1240
- pushEdge(key, spec, to, request.kind);
1241
- this.walk(to, chain, lazy || !requestVia.static);
1242
- }
1243
- continue;
1244
- }
1245
- if (use.importMetaResolve &&
1246
- !use.static &&
1247
- !use.dynamicImport &&
1248
- !use.require &&
1249
- (/^[A-Za-z][A-Za-z\d+.-]*:/.test(spec) || spec.startsWith("/"))) {
1250
- continue;
1251
- }
1252
- const builtin = builtinKeyOf(spec);
1253
- if (builtin) {
1254
- let seen = this.builtinsSeen.get(builtin);
1255
- if (!seen)
1256
- this.builtinsSeen.set(builtin, (seen = new Set()));
1257
- seen.add(pkgName);
1258
- if (eager)
1259
- this.builtinsEager.add(builtin);
1260
- if (eager && !SHIMMED_BUILTINS.has(builtin.slice(5))) {
1261
- this.errors.push({
1262
- message: `package '${pkgName}' requires '${spec}', a Node builtin the island does not provide ` +
1263
- `(available: ${[...SHIMMED_BUILTINS].map((b) => `node:${b}`).join(", ")}; ` +
1264
- `imported from ${key}; dependency chain: ${NpmGraphBuilder.chainOf(chain)})`,
1265
- });
1266
- continue;
1267
- }
1268
- // The edge embeds pointing at the "node:x" key (for an unshimmed
1269
- // builtin reached lazily, the island's require shim — "the island
1270
- // does not provide the 'node:x' builtin" — or module loader
1271
- // throws at the CALL, the only point Node would have loaded the
1272
- // module either). Builtin resolution is location-independent
1273
- // under Node, but the EDGE isn't: a call through the imported
1274
- // `__require` helper asks from the DEFINING chunk's key at
1275
- // runtime, so the edge registers there too (sentry's
1276
- // `__require("domain")` sites live in one chunk, the helper in
1277
- // another).
1278
- pushEdge(key, spec, builtin, "any");
1279
- if (use.requireViaHelper) {
1280
- const origin = this.requireHelperOriginOf(key);
1281
- if (origin !== null)
1282
- pushEdge(origin, spec, builtin, "require");
1283
- }
1284
- continue;
1285
- }
1286
- // A bare dependency package: Node picks the "exports" condition set
1287
- // from the EDGE KIND, never from the importer's format — import/
1288
- // export declarations and import() resolve with ["node","import"],
1289
- // require() with ["node","require"] — so a dual package legitimately
1290
- // embeds TWO targets for one specifier, each behind its own
1291
- // kind-tagged edge (the island's module loader asks with the import
1292
- // kind, its require shim with the require kind).
1293
- const depName = packageNameOf(spec);
1294
- const nextChain = depName === pkgName || spec.startsWith("#") ? chain : [...chain, depName];
1295
- const targetChain = (to) => {
1296
- if (!spec.startsWith("#"))
1297
- return nextChain;
1298
- const targetPkg = packageNameOfPath(to);
1299
- return targetPkg === null || targetPkg === pkgName ? chain : [...chain, targetPkg];
1300
- };
1301
- if (use.require) {
1302
- // require edges attribute to the module whose scope DEFINES the
1303
- // require function being called: a direct require() is this file's
1304
- // own (its banner createRequire), but an esbuild `__require`
1305
- // imported from a shared chunk closed over THAT chunk's require,
1306
- // so Node resolves from the defining chunk — and the island's
1307
- // require shim looks the edge up under its key at the call.
1308
- const froms = new Set();
1309
- if (use.requireLocal)
1310
- froms.add(key);
1311
- if (use.requireViaHelper)
1312
- froms.add(this.requireHelperOriginOf(key) ?? key);
1313
- for (const from of froms) {
1314
- const errorsBefore = this.errors.length;
1315
- const to = this.resolvePackage(dirname(from), spec, "require", {
1316
- importer: from,
1317
- chain,
1318
- });
1319
- if (to === null) {
1320
- // require failures are ALWAYS lazy — no edge embeds; the
1321
- // island's require shim throws Node's MODULE_NOT_FOUND with
1322
- // the live require stack at the call.
1323
- this.errors.length = errorsBefore;
1324
- this.noteLazyTrap(spec, { require: true, dynamicImport: false, static: false }, pkgName, lazy);
1325
- continue;
1326
- }
1327
- // A package whose entry IS a .node addon (napi per-platform
1328
- // binding packages: "main" names the addon) embeds the dlopen
1329
- // stub — inventory row like the relative-specifier shape.
1330
- if (to.endsWith(".node")) {
1331
- this.noteLazyTrap(spec, { require: true, dynamicImport: false, static: false }, pkgName, lazy, true);
1332
- }
1333
- pushEdge(from, spec, to, "require");
1334
- this.walk(to, targetChain(to), true);
1335
- }
1336
- }
1337
- if (use.static || use.dynamicImport || use.importMetaResolve) {
1338
- const errorsBefore = this.errors.length;
1339
- const to = this.resolvePackage(dirname(key), spec, "import", { importer: key, chain });
1340
- if (to === null) {
1341
- if (!eager) {
1342
- // Roll the resolver's diagnostics back off the build — the
1343
- // blocked edge is lazy, so the failure belongs to the runtime
1344
- // trap (and the coverage inventory), not the error list. The
1345
- // trap is an ESM stub with Node's ERR_MODULE_NOT_FOUND shape,
1346
- // behind an import-kind edge the require shim never matches.
1347
- this.errors.length = errorsBefore;
1348
- this.noteLazyTrap(spec, { require: false, dynamicImport: use.dynamicImport, static: use.static }, pkgName, lazy);
1349
- if (use.dynamicImport || (lazy && use.static)) {
1350
- pushEdge(key, spec, this.importNotFoundTrap(key, spec), "import");
1351
- }
1352
- }
1353
- continue; // eager: error already recorded
1354
- }
1355
- if (to.endsWith(".node")) {
1356
- this.noteLazyTrap(spec, { require: false, dynamicImport: use.dynamicImport, static: use.static }, pkgName, lazy, true);
1357
- }
1358
- pushEdge(key, spec, to, "import");
1359
- if (!use.importMetaResolve || use.static || use.dynamicImport) {
1360
- this.walk(to, targetChain(to), lazy || !use.static);
1361
- }
1362
- }
1363
- }
1364
- }
1365
364
  }
1366
365
  //# sourceMappingURL=npm.js.map