@unbrained/pm-cli 2026.11.16 → 2026.11.17

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 (399) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/cli/main.js +2 -2
  3. package/dist/cli/register-mutation.js +3 -2
  4. package/dist/cli/runtime/invocation-rewrites.js +2 -0
  5. package/dist/cli-bundle/bundle-manifest.json +1 -1
  6. package/dist/cli-bundle/chunks/{chunk-ERD2RYWM.js → chunk-2WHXFKMY.js} +31 -31
  7. package/dist/cli-bundle/chunks/{chunk-VJLZHOTP.js → chunk-36R3JTAD.js} +2 -2
  8. package/dist/cli-bundle/chunks/{chunk-FZ4XWWLO.js → chunk-3IU2S5UQ.js} +43 -43
  9. package/dist/cli-bundle/chunks/chunk-4FIN2XWC.js +2 -0
  10. package/dist/cli-bundle/chunks/{chunk-NHNM3GIP.js → chunk-5OFMWP3Q.js} +3 -3
  11. package/dist/cli-bundle/chunks/{chunk-2WNORBVN.js → chunk-77MGDTK4.js} +83 -83
  12. package/dist/cli-bundle/chunks/{chunk-F7P42FL5.js → chunk-7K2RUKMK.js} +4 -4
  13. package/dist/cli-bundle/chunks/chunk-7UUPLMCU.js +115 -0
  14. package/dist/cli-bundle/chunks/chunk-ABFHWRLE.js +2 -0
  15. package/dist/cli-bundle/chunks/{chunk-KGOGLKL2.js → chunk-ACLBUVQG.js} +2 -2
  16. package/dist/cli-bundle/chunks/{chunk-DZWRNL6R.js → chunk-ADKDFCVT.js} +2 -2
  17. package/dist/cli-bundle/chunks/chunk-AM26RAG7.js +124 -0
  18. package/dist/cli-bundle/chunks/chunk-CR5GC3VO.js +9 -0
  19. package/dist/cli-bundle/chunks/chunk-DXSZL3T6.js +3 -0
  20. package/dist/cli-bundle/chunks/chunk-FXSLODOK.js +2 -0
  21. package/dist/cli-bundle/chunks/chunk-H64BNM4A.js +8 -0
  22. package/dist/cli-bundle/chunks/{chunk-2D26HRXB.js → chunk-HQYIKAC6.js} +2 -2
  23. package/dist/cli-bundle/chunks/{chunk-I3T2FVUA.js → chunk-KIQNEOKJ.js} +2 -2
  24. package/dist/cli-bundle/chunks/chunk-O4ZSIMNC.js +8 -0
  25. package/dist/cli-bundle/chunks/chunk-QANUQMDL.js +6 -0
  26. package/dist/cli-bundle/chunks/{chunk-4I7YG3VZ.js → chunk-QZNL5XDT.js} +2 -2
  27. package/dist/cli-bundle/chunks/chunk-RXNBNF6O.js +2 -0
  28. package/dist/cli-bundle/chunks/chunk-VLKCFZY6.js +2 -0
  29. package/dist/cli-bundle/chunks/{chunk-J257NZRD.js → chunk-X5TFNFTS.js} +11 -11
  30. package/dist/cli-bundle/chunks/chunk-XP35IEHT.js +2 -0
  31. package/dist/cli-bundle/chunks/chunk-XPBADEUK.js +2 -0
  32. package/dist/cli-bundle/chunks/{chunk-NYN5OR2T.js → chunk-Y4LXVPA5.js} +2 -2
  33. package/dist/cli-bundle/chunks/{indexed-receipt-blobs-HNLN6UXH.js → indexed-receipt-blobs-ELEMA7IW.js} +2 -2
  34. package/dist/cli-bundle/chunks/{item-revision-PSOL5I4H.js → item-revision-7RVMVXTE.js} +2 -2
  35. package/dist/cli-bundle/chunks/item-transaction-NVX6P3FK.js +2 -0
  36. package/dist/cli-bundle/chunks/{mutation-actor-BDBBH3ZS.js → mutation-actor-DDYJW5B4.js} +2 -2
  37. package/dist/cli-bundle/chunks/mutation-admission-3PKQOAYK.js +2 -0
  38. package/dist/cli-bundle/chunks/{register-list-query-AESCVO6H.js → register-list-query-TPZLHFHQ.js} +2 -2
  39. package/dist/cli-bundle/chunks/register-mutation-JG5AEBRJ.js +21 -0
  40. package/dist/cli-bundle/chunks/register-operations-3CNXP46P.js +2 -0
  41. package/dist/cli-bundle/chunks/register-setup-4N56VL2P.js +2 -0
  42. package/dist/cli-bundle/chunks/{settlement-hook-MVVVUIVZ.js → settlement-hook-E5LHZ4RD.js} +2 -2
  43. package/dist/cli-bundle/chunks/{stage-RMU3JAWM.js → stage-XGWW3T64.js} +2 -2
  44. package/dist/cli-bundle/focused-chunks/chunk-2MQNIDKG.js +2 -0
  45. package/dist/cli-bundle/focused-chunks/{chunk-DFBHW7HP.js → chunk-5JVB42Z7.js} +3 -3
  46. package/dist/cli-bundle/focused-chunks/{chunk-SFATIM77.js → chunk-6JQXDGHM.js} +9 -9
  47. package/dist/cli-bundle/focused-chunks/{chunk-HHMMIHZP.js → chunk-7RF2YPZ5.js} +2 -2
  48. package/dist/cli-bundle/focused-chunks/chunk-7Z2NYAK4.js +2 -0
  49. package/dist/cli-bundle/focused-chunks/chunk-A2CLYPDA.js +102 -0
  50. package/dist/cli-bundle/focused-chunks/chunk-BNLLST32.js +2 -0
  51. package/dist/cli-bundle/focused-chunks/{chunk-7SEPCQV2.js → chunk-DH4DHL6V.js} +2 -2
  52. package/dist/cli-bundle/focused-chunks/chunk-EZXLY6S4.js +2 -0
  53. package/dist/cli-bundle/focused-chunks/{chunk-KRNF3WTC.js → chunk-FPPYE6CY.js} +2 -2
  54. package/dist/cli-bundle/focused-chunks/{chunk-ONM2R32I.js → chunk-GD2YWUAD.js} +50 -50
  55. package/dist/cli-bundle/focused-chunks/chunk-HO2YUD4P.js +91 -0
  56. package/dist/cli-bundle/focused-chunks/{chunk-BEHIMEV2.js → chunk-ICEHI4SN.js} +2 -2
  57. package/dist/cli-bundle/focused-chunks/{chunk-PDXSMSO5.js → chunk-IXYBN6D2.js} +3 -3
  58. package/dist/cli-bundle/focused-chunks/chunk-MTBC32ZR.js +8 -0
  59. package/dist/cli-bundle/focused-chunks/chunk-OAIAZHRG.js +2 -0
  60. package/dist/cli-bundle/focused-chunks/chunk-OPY43DNJ.js +2 -0
  61. package/dist/cli-bundle/focused-chunks/{chunk-DZMP3VYQ.js → chunk-SESMRMEE.js} +2 -2
  62. package/dist/cli-bundle/focused-chunks/{chunk-PEL4SQXV.js → chunk-VBA4BIHN.js} +2 -2
  63. package/dist/cli-bundle/focused-chunks/{chunk-UBBTBNUY.js → chunk-XJS4COL2.js} +2 -2
  64. package/dist/cli-bundle/focused-chunks/chunk-XS2YZCT5.js +2 -0
  65. package/dist/cli-bundle/focused-chunks/chunk-YWPLBFPC.js +44 -0
  66. package/dist/cli-bundle/focused-chunks/{chunk-6E4X7MQA.js → chunk-ZDY5L2C2.js} +7 -7
  67. package/dist/cli-bundle/focused-chunks/chunk-ZFUZ4YYN.js +8 -0
  68. package/dist/cli-bundle/focused-chunks/{indexed-receipt-blobs-ADMQXF3N.js → indexed-receipt-blobs-ZTRFCPH7.js} +2 -2
  69. package/dist/cli-bundle/focused-chunks/item-revision-U7GDVAH7.js +2 -0
  70. package/dist/cli-bundle/focused-chunks/item-transaction-7C4BH47O.js +2 -0
  71. package/dist/cli-bundle/focused-chunks/mutation-actor-2SVBO324.js +2 -0
  72. package/dist/cli-bundle/focused-chunks/mutation-admission-SKXVITP5.js +2 -0
  73. package/dist/cli-bundle/focused-chunks/{settlement-hook-5U2M75BY.js → settlement-hook-OUBUN45C.js} +2 -2
  74. package/dist/cli-bundle/focused-chunks/stage-LVAGKCEE.js +2 -0
  75. package/dist/cli-bundle/main.js +27 -27
  76. package/dist/cli-bundle/sdk-authoring.js +1 -1
  77. package/dist/cli-bundle/sdk-contracts.js +2 -2
  78. package/dist/cli-bundle/sdk-core.js +1 -1
  79. package/dist/cli-bundle/sdk-governance.js +1 -1
  80. package/dist/cli-bundle/sdk-graph.js +1 -1
  81. package/dist/cli-bundle/sdk-merge.js +57 -57
  82. package/dist/cli-bundle/sdk-query.js +1 -1
  83. package/dist/cli-bundle/sdk-runtime.js +1 -1
  84. package/dist/cli-bundle/sdk-testing.js +1 -1
  85. package/dist/cli-bundle/sdk.js +4 -4
  86. package/dist/core/extensions/extension-hook-runtime.d.ts +14 -2
  87. package/dist/core/extensions/extension-hook-runtime.js +1 -1
  88. package/dist/core/extensions/extension-types.d.ts +14 -0
  89. package/dist/core/extensions/extension-types.js +1 -1
  90. package/dist/core/extensions/index.d.ts +1 -1
  91. package/dist/core/extensions/index.js +1 -1
  92. package/dist/core/policy/workflow-policy-store.js +1 -1
  93. package/dist/core/store/item-mutation-precondition.d.ts +32 -1
  94. package/dist/core/store/item-mutation-precondition.js +1 -1
  95. package/dist/core/store/item-store.js +1 -1
  96. package/dist/core/store/transaction-coordinator-scope.js +2 -0
  97. package/dist/sdk/authoring.d.ts +1 -1
  98. package/dist/sdk/authoring.js +1 -1
  99. package/dist/sdk/cli-bootstrap.js +1 -1
  100. package/dist/sdk/item-transaction.js +1 -1
  101. package/dist/sdk/lifecycle/copy.js +1 -1
  102. package/dist/sdk/lifecycle/create.js +1 -1
  103. package/dist/sdk/lifecycle/restore.js +1 -1
  104. package/dist/sdk/package-import-adapters.d.ts +14 -1
  105. package/dist/sdk/package-import-adapters.js +1 -1
  106. package/dist/sdk/public-surface.json +1 -1
  107. package/dist/sdk/testing.d.ts +21 -3
  108. package/dist/sdk/testing.js +2 -2
  109. package/dist/sdk/workspace-transaction.js +2 -2
  110. package/docs/EXTENSIONS.md +1 -1
  111. package/docs/MIGRATION_CLI_SIMPLIFICATION.md +1 -1
  112. package/docs/SDK.md +40 -3
  113. package/docs/WORKFLOW_POLICIES.md +23 -0
  114. package/marketplace.json +1 -1
  115. package/node_modules/@opentelemetry/core/build/esm/version.d.ts +1 -1
  116. package/node_modules/@opentelemetry/core/build/esm/version.js +1 -1
  117. package/node_modules/@opentelemetry/core/build/esnext/version.d.ts +1 -1
  118. package/node_modules/@opentelemetry/core/build/esnext/version.js +1 -1
  119. package/node_modules/@opentelemetry/core/build/src/version.d.ts +1 -1
  120. package/node_modules/@opentelemetry/core/build/src/version.js +1 -1
  121. package/node_modules/@opentelemetry/core/package.json +2 -2
  122. package/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/execAsync.d.ts +1 -0
  123. package/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/execAsync.js +1 -0
  124. package/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/getMachineId-bsd.js +3 -2
  125. package/node_modules/@opentelemetry/resources/build/esm/detectors/platform/node/machine-id/getMachineId-darwin.js +3 -2
  126. package/node_modules/@opentelemetry/resources/build/esm/version.d.ts +1 -1
  127. package/node_modules/@opentelemetry/resources/build/esm/version.js +1 -1
  128. package/node_modules/@opentelemetry/resources/build/esnext/detectors/platform/node/machine-id/execAsync.d.ts +1 -0
  129. package/node_modules/@opentelemetry/resources/build/esnext/detectors/platform/node/machine-id/execAsync.js +1 -0
  130. package/node_modules/@opentelemetry/resources/build/esnext/detectors/platform/node/machine-id/getMachineId-bsd.js +3 -2
  131. package/node_modules/@opentelemetry/resources/build/esnext/detectors/platform/node/machine-id/getMachineId-darwin.js +3 -2
  132. package/node_modules/@opentelemetry/resources/build/esnext/version.d.ts +1 -1
  133. package/node_modules/@opentelemetry/resources/build/esnext/version.js +1 -1
  134. package/node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/execAsync.d.ts +1 -0
  135. package/node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/execAsync.js +2 -1
  136. package/node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-bsd.js +2 -1
  137. package/node_modules/@opentelemetry/resources/build/src/detectors/platform/node/machine-id/getMachineId-darwin.js +2 -1
  138. package/node_modules/@opentelemetry/resources/build/src/version.d.ts +1 -1
  139. package/node_modules/@opentelemetry/resources/build/src/version.js +1 -1
  140. package/node_modules/@opentelemetry/resources/package.json +3 -3
  141. package/node_modules/@opentelemetry/sdk-trace/build/esm/version.d.ts +1 -1
  142. package/node_modules/@opentelemetry/sdk-trace/build/esm/version.js +1 -1
  143. package/node_modules/@opentelemetry/sdk-trace/build/esnext/version.d.ts +1 -1
  144. package/node_modules/@opentelemetry/sdk-trace/build/esnext/version.js +1 -1
  145. package/node_modules/@opentelemetry/sdk-trace/build/src/version.d.ts +1 -1
  146. package/node_modules/@opentelemetry/sdk-trace/build/src/version.js +1 -1
  147. package/node_modules/@opentelemetry/sdk-trace/package.json +5 -5
  148. package/node_modules/@opentelemetry/sdk-trace-base/build/esm/version.d.ts +1 -1
  149. package/node_modules/@opentelemetry/sdk-trace-base/build/esm/version.js +1 -1
  150. package/node_modules/@opentelemetry/sdk-trace-base/build/esnext/version.d.ts +1 -1
  151. package/node_modules/@opentelemetry/sdk-trace-base/build/esnext/version.js +1 -1
  152. package/node_modules/@opentelemetry/sdk-trace-base/build/src/version.d.ts +1 -1
  153. package/node_modules/@opentelemetry/sdk-trace-base/build/src/version.js +1 -1
  154. package/node_modules/@opentelemetry/sdk-trace-base/package.json +7 -7
  155. package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.cjs +18202 -0
  156. package/node_modules/@opentelemetry/semantic-conventions/{build/src/experimental_attributes.js → dist/experimental_attributes.d.cts} +3328 -1993
  157. package/node_modules/@opentelemetry/semantic-conventions/{build/esnext/experimental_attributes.js → dist/experimental_attributes.d.mts} +3328 -1935
  158. package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.mjs +16385 -0
  159. package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.cjs +325 -0
  160. package/node_modules/@opentelemetry/semantic-conventions/{build/esnext/experimental_events.js → dist/experimental_events.d.cts} +37 -41
  161. package/node_modules/@opentelemetry/semantic-conventions/{build/esm/experimental_events.js → dist/experimental_events.d.mts} +37 -41
  162. package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.mjs +295 -0
  163. package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.cjs +4929 -0
  164. package/node_modules/@opentelemetry/semantic-conventions/{build/esnext/experimental_metrics.js → dist/experimental_metrics.d.cts} +955 -597
  165. package/node_modules/@opentelemetry/semantic-conventions/{build/esm/experimental_metrics.js → dist/experimental_metrics.d.mts} +955 -597
  166. package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.mjs +4419 -0
  167. package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.cjs +2619 -0
  168. package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.d.cts +7 -0
  169. package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.d.mts +7 -0
  170. package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.mjs +7 -0
  171. package/node_modules/@opentelemetry/semantic-conventions/dist/index.cjs +670 -0
  172. package/node_modules/@opentelemetry/semantic-conventions/dist/index.d.cts +6 -0
  173. package/node_modules/@opentelemetry/semantic-conventions/dist/index.d.mts +6 -0
  174. package/node_modules/@opentelemetry/semantic-conventions/dist/index.mjs +6 -0
  175. package/node_modules/@opentelemetry/semantic-conventions/dist/internal/utils.cjs +20 -0
  176. package/node_modules/@opentelemetry/semantic-conventions/dist/internal/utils.mjs +20 -0
  177. package/node_modules/@opentelemetry/semantic-conventions/dist/resource/SemanticResourceAttributes.cjs +1326 -0
  178. package/node_modules/@opentelemetry/semantic-conventions/{build/esnext/resource/SemanticResourceAttributes.d.ts → dist/resource/SemanticResourceAttributes.d.cts} +600 -597
  179. package/node_modules/@opentelemetry/semantic-conventions/{build/src/resource/SemanticResourceAttributes.d.ts → dist/resource/SemanticResourceAttributes.d.mts} +600 -597
  180. package/node_modules/@opentelemetry/semantic-conventions/dist/resource/SemanticResourceAttributes.mjs +1188 -0
  181. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.cjs +2038 -0
  182. package/node_modules/@opentelemetry/semantic-conventions/{build/esm/stable_attributes.js → dist/stable_attributes.d.cts} +327 -220
  183. package/node_modules/@opentelemetry/semantic-conventions/{build/esnext/stable_attributes.js → dist/stable_attributes.d.mts} +327 -220
  184. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.mjs +1841 -0
  185. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_events.cjs +9 -0
  186. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_events.d.cts +8 -0
  187. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_events.d.mts +8 -0
  188. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_events.mjs +9 -0
  189. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.cjs +378 -0
  190. package/node_modules/@opentelemetry/semantic-conventions/{build/src/stable_metrics.js → dist/stable_metrics.d.cts} +69 -63
  191. package/node_modules/@opentelemetry/semantic-conventions/{build/esm/stable_metrics.js → dist/stable_metrics.d.mts} +69 -59
  192. package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.mjs +326 -0
  193. package/node_modules/@opentelemetry/semantic-conventions/dist/trace/SemanticAttributes.cjs +2508 -0
  194. package/node_modules/@opentelemetry/semantic-conventions/{build/esnext/trace/SemanticAttributes.d.ts → dist/trace/SemanticAttributes.d.cts} +1097 -1094
  195. package/node_modules/@opentelemetry/semantic-conventions/{build/src/trace/SemanticAttributes.d.ts → dist/trace/SemanticAttributes.d.mts} +1097 -1094
  196. package/node_modules/@opentelemetry/semantic-conventions/dist/trace/SemanticAttributes.mjs +2236 -0
  197. package/node_modules/@opentelemetry/semantic-conventions/package.json +27 -42
  198. package/node_modules/@sentry/core/build/cjs/client.js +14 -5
  199. package/node_modules/@sentry/core/build/cjs/integrations/express/patch-layer.js +15 -1
  200. package/node_modules/@sentry/core/build/cjs/integrations/http/client-subscriptions.js +10 -1
  201. package/node_modules/@sentry/core/build/cjs/scope.js +0 -1
  202. package/node_modules/@sentry/core/build/cjs/tracing/openai/utils.js +1 -7
  203. package/node_modules/@sentry/core/build/cjs/tracing/sentrySpan.js +11 -0
  204. package/node_modules/@sentry/core/build/cjs/utils/envelope.js +1 -1
  205. package/node_modules/@sentry/core/build/cjs/utils/sql.js +1 -1
  206. package/node_modules/@sentry/core/build/cjs/utils/tunnel.js +9 -0
  207. package/node_modules/@sentry/core/build/cjs/utils/version.js +1 -1
  208. package/node_modules/@sentry/core/build/esm/client.js +14 -5
  209. package/node_modules/@sentry/core/build/esm/integrations/express/patch-layer.js +15 -1
  210. package/node_modules/@sentry/core/build/esm/integrations/http/client-subscriptions.js +10 -1
  211. package/node_modules/@sentry/core/build/esm/package.json +1 -1
  212. package/node_modules/@sentry/core/build/esm/scope.js +0 -1
  213. package/node_modules/@sentry/core/build/esm/tracing/openai/utils.js +1 -7
  214. package/node_modules/@sentry/core/build/esm/tracing/sentrySpan.js +11 -0
  215. package/node_modules/@sentry/core/build/esm/utils/envelope.js +1 -1
  216. package/node_modules/@sentry/core/build/esm/utils/sql.js +1 -1
  217. package/node_modules/@sentry/core/build/esm/utils/tunnel.js +9 -1
  218. package/node_modules/@sentry/core/build/esm/utils/version.js +1 -1
  219. package/node_modules/@sentry/core/build/types/types/datacategory.d.ts +1 -1
  220. package/node_modules/@sentry/core/build/types/utils/tunnel.d.ts +1 -0
  221. package/node_modules/@sentry/core/build/types-ts3.8/types/datacategory.d.ts +1 -1
  222. package/node_modules/@sentry/core/build/types-ts3.8/utils/tunnel.d.ts +1 -0
  223. package/node_modules/@sentry/core/package.json +1 -1
  224. package/node_modules/@sentry/node/build/cjs/integrations/tracing/redis/index.js +1 -1
  225. package/node_modules/@sentry/node/build/esm/package.json +1 -1
  226. package/node_modules/@sentry/node/package.json +6 -6
  227. package/node_modules/@sentry/node-core/build/cjs/integrations/anr/index.js +1 -1
  228. package/node_modules/@sentry/node-core/build/cjs/integrations/contextlines.js +6 -4
  229. package/node_modules/@sentry/node-core/build/cjs/integrations/local-variables/local-variables-async.js +1 -1
  230. package/node_modules/@sentry/node-core/build/cjs/integrations/modules.js +21 -2
  231. package/node_modules/@sentry/node-core/build/cjs/integrations/node-fetch/undici-instrumentation.js +8 -0
  232. package/node_modules/@sentry/node-core/build/esm/integrations/anr/index.js +1 -1
  233. package/node_modules/@sentry/node-core/build/esm/integrations/anr/worker-script.js +2 -2
  234. package/node_modules/@sentry/node-core/build/esm/integrations/contextlines.js +7 -5
  235. package/node_modules/@sentry/node-core/build/esm/integrations/local-variables/local-variables-async.js +1 -1
  236. package/node_modules/@sentry/node-core/build/esm/integrations/local-variables/worker-script.js +1 -1
  237. package/node_modules/@sentry/node-core/build/esm/integrations/node-fetch/undici-instrumentation.js +8 -0
  238. package/node_modules/@sentry/node-core/build/esm/package.json +1 -1
  239. package/node_modules/@sentry/node-core/package.json +9 -9
  240. package/node_modules/@sentry/opentelemetry/build/esm/package.json +1 -1
  241. package/node_modules/@sentry/opentelemetry/package.json +6 -6
  242. package/node_modules/@sentry/server-utils/build/THIRD-PARTY-LICENSES.txt +32 -32
  243. package/node_modules/@sentry/server-utils/build/cjs/integrations/tracing-channel/express/instrumentation.js +12 -1
  244. package/node_modules/@sentry/server-utils/build/esm/integrations/tracing-channel/express/instrumentation.js +13 -2
  245. package/node_modules/@sentry/server-utils/build/esm/package.json +1 -1
  246. package/node_modules/@sentry/server-utils/build/types/integrations/tracing-channel/express/types.d.ts +1 -1
  247. package/node_modules/@sentry/server-utils/build/types-ts3.8/integrations/tracing-channel/express/types.d.ts +1 -1
  248. package/node_modules/@sentry/server-utils/package.json +2 -2
  249. package/node_modules/debug/package.json +1 -1
  250. package/node_modules/es-module-lexer/dist/lexer.asm.js +2 -2
  251. package/node_modules/es-module-lexer/dist/lexer.cjs +1 -1
  252. package/node_modules/es-module-lexer/dist/lexer.js +2 -2
  253. package/node_modules/es-module-lexer/dist/lexer.minimal.asm.js +2 -2
  254. package/node_modules/es-module-lexer/dist/lexer.minimal.cjs +1 -1
  255. package/node_modules/es-module-lexer/dist/lexer.minimal.js +2 -2
  256. package/node_modules/es-module-lexer/package.json +1 -1
  257. package/node_modules/import-in-the-middle/CHANGELOG.md +35 -0
  258. package/node_modules/import-in-the-middle/README.md +15 -1
  259. package/node_modules/import-in-the-middle/create-hook.mjs +370 -155
  260. package/node_modules/import-in-the-middle/index.d.ts +8 -2
  261. package/node_modules/import-in-the-middle/index.js +80 -53
  262. package/node_modules/import-in-the-middle/lib/get-esm-exports.mjs +37 -3
  263. package/node_modules/import-in-the-middle/lib/get-exports.mjs +33 -40
  264. package/node_modules/import-in-the-middle/lib/register.js +81 -16
  265. package/node_modules/import-in-the-middle/package.json +9 -5
  266. package/node_modules/supports-color/browser.js +21 -2
  267. package/node_modules/supports-color/index.js +41 -24
  268. package/node_modules/supports-color/license +1 -1
  269. package/node_modules/supports-color/package.json +11 -6
  270. package/node_modules/supports-color/readme.md +8 -7
  271. package/package.json +4 -4
  272. package/packages/pm-beads/package.json +1 -1
  273. package/packages/pm-calendar/package.json +1 -1
  274. package/packages/pm-command-kit/package.json +1 -1
  275. package/packages/pm-digital-twin/package.json +1 -1
  276. package/packages/pm-governance-audit/package.json +1 -1
  277. package/packages/pm-guide-shell/package.json +1 -1
  278. package/packages/pm-kanban/package.json +1 -1
  279. package/packages/pm-lifecycle-hooks/package.json +1 -1
  280. package/packages/pm-linked-test-adapters/package.json +1 -1
  281. package/packages/pm-search-advanced/package.json +1 -1
  282. package/packages/pm-templates/package.json +1 -1
  283. package/packages/pm-todos/package.json +1 -1
  284. package/packages/pm-vcs/package.json +1 -1
  285. package/plugins/pm-claude/.claude-plugin/plugin.json +1 -1
  286. package/plugins/pm-claude/package.json +1 -1
  287. package/plugins/pm-codex/.codex-plugin/plugin.json +1 -1
  288. package/plugins/pm-codex/package.json +1 -1
  289. package/plugins/pm-codex/plugin.json +1 -1
  290. package/runtime-dependencies.json +1 -1
  291. package/dist/cli-bundle/chunks/chunk-4WIVCOA7.js +0 -2
  292. package/dist/cli-bundle/chunks/chunk-A3WCP4TU.js +0 -6
  293. package/dist/cli-bundle/chunks/chunk-AB5S6TWE.js +0 -124
  294. package/dist/cli-bundle/chunks/chunk-BV7J3LRH.js +0 -114
  295. package/dist/cli-bundle/chunks/chunk-E4BQRZF2.js +0 -10
  296. package/dist/cli-bundle/chunks/chunk-IGEBFNWE.js +0 -2
  297. package/dist/cli-bundle/chunks/chunk-IYICNCK2.js +0 -2
  298. package/dist/cli-bundle/chunks/chunk-JD3XWF66.js +0 -3
  299. package/dist/cli-bundle/chunks/chunk-JLHD7OQ2.js +0 -2
  300. package/dist/cli-bundle/chunks/chunk-LC4DJVXR.js +0 -2
  301. package/dist/cli-bundle/chunks/chunk-OFZQEQ6X.js +0 -2
  302. package/dist/cli-bundle/chunks/chunk-QGL5IAP4.js +0 -8
  303. package/dist/cli-bundle/chunks/chunk-R24NZ2TB.js +0 -8
  304. package/dist/cli-bundle/chunks/chunk-VO2HSB5F.js +0 -2
  305. package/dist/cli-bundle/chunks/item-transaction-55QTCU2M.js +0 -2
  306. package/dist/cli-bundle/chunks/mutation-admission-WUN7JYVJ.js +0 -2
  307. package/dist/cli-bundle/chunks/register-mutation-SKCEP5QU.js +0 -20
  308. package/dist/cli-bundle/chunks/register-operations-ZT4OYCF3.js +0 -2
  309. package/dist/cli-bundle/chunks/register-setup-JVWNS2TY.js +0 -2
  310. package/dist/cli-bundle/focused-chunks/chunk-3WVMEA2A.js +0 -6
  311. package/dist/cli-bundle/focused-chunks/chunk-5UVJOAUP.js +0 -91
  312. package/dist/cli-bundle/focused-chunks/chunk-5WQ3LNUK.js +0 -78
  313. package/dist/cli-bundle/focused-chunks/chunk-7XHE335U.js +0 -2
  314. package/dist/cli-bundle/focused-chunks/chunk-CZFZCSOX.js +0 -2
  315. package/dist/cli-bundle/focused-chunks/chunk-HPC2M6JD.js +0 -6
  316. package/dist/cli-bundle/focused-chunks/chunk-HR5FEUUL.js +0 -2
  317. package/dist/cli-bundle/focused-chunks/chunk-J7ESCE7M.js +0 -24
  318. package/dist/cli-bundle/focused-chunks/chunk-KWZLY35A.js +0 -2
  319. package/dist/cli-bundle/focused-chunks/chunk-M4IA4LC6.js +0 -8
  320. package/dist/cli-bundle/focused-chunks/chunk-NASE6JC2.js +0 -2
  321. package/dist/cli-bundle/focused-chunks/chunk-QJ647CQE.js +0 -2
  322. package/dist/cli-bundle/focused-chunks/chunk-ZCN35TCK.js +0 -2
  323. package/dist/cli-bundle/focused-chunks/chunk-ZSQ2FT22.js +0 -44
  324. package/dist/cli-bundle/focused-chunks/item-revision-GNKYO6GZ.js +0 -2
  325. package/dist/cli-bundle/focused-chunks/item-transaction-AUUQHR5Z.js +0 -2
  326. package/dist/cli-bundle/focused-chunks/mutation-actor-OBRD7HFZ.js +0 -2
  327. package/dist/cli-bundle/focused-chunks/mutation-admission-6TX3EOJX.js +0 -2
  328. package/dist/cli-bundle/focused-chunks/stage-LERF2YJU.js +0 -2
  329. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.d.ts +0 -14984
  330. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_attributes.js +0 -14991
  331. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_events.d.ts +0 -291
  332. package/node_modules/@opentelemetry/semantic-conventions/build/esm/experimental_metrics.d.ts +0 -4053
  333. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.d.ts +0 -7
  334. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index-incubating.js +0 -13
  335. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.d.ts +0 -6
  336. package/node_modules/@opentelemetry/semantic-conventions/build/esm/index.js +0 -16
  337. package/node_modules/@opentelemetry/semantic-conventions/build/esm/internal/utils.d.ts +0 -7
  338. package/node_modules/@opentelemetry/semantic-conventions/build/esm/internal/utils.js +0 -23
  339. package/node_modules/@opentelemetry/semantic-conventions/build/esm/resource/SemanticResourceAttributes.d.ts +0 -1453
  340. package/node_modules/@opentelemetry/semantic-conventions/build/esm/resource/SemanticResourceAttributes.js +0 -1250
  341. package/node_modules/@opentelemetry/semantic-conventions/build/esm/resource/index.d.ts +0 -2
  342. package/node_modules/@opentelemetry/semantic-conventions/build/esm/resource/index.js +0 -10
  343. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.d.ts +0 -1726
  344. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.d.ts +0 -5
  345. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_events.js +0 -12
  346. package/node_modules/@opentelemetry/semantic-conventions/build/esm/stable_metrics.d.ts +0 -308
  347. package/node_modules/@opentelemetry/semantic-conventions/build/esm/trace/SemanticAttributes.d.ts +0 -2664
  348. package/node_modules/@opentelemetry/semantic-conventions/build/esm/trace/SemanticAttributes.js +0 -2360
  349. package/node_modules/@opentelemetry/semantic-conventions/build/esm/trace/index.d.ts +0 -2
  350. package/node_modules/@opentelemetry/semantic-conventions/build/esm/trace/index.js +0 -10
  351. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.d.ts +0 -2
  352. package/node_modules/@opentelemetry/semantic-conventions/build/esm/version.js +0 -7
  353. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_attributes.d.ts +0 -14984
  354. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_events.d.ts +0 -291
  355. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/experimental_metrics.d.ts +0 -4053
  356. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.d.ts +0 -7
  357. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index-incubating.js +0 -13
  358. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.d.ts +0 -6
  359. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/index.js +0 -16
  360. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/internal/utils.d.ts +0 -7
  361. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/internal/utils.js +0 -23
  362. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/resource/SemanticResourceAttributes.js +0 -1250
  363. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/resource/index.d.ts +0 -2
  364. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/resource/index.js +0 -10
  365. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_attributes.d.ts +0 -1726
  366. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.d.ts +0 -5
  367. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_events.js +0 -12
  368. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_metrics.d.ts +0 -308
  369. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/stable_metrics.js +0 -315
  370. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/trace/SemanticAttributes.js +0 -2360
  371. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/trace/index.d.ts +0 -2
  372. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/trace/index.js +0 -10
  373. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.d.ts +0 -2
  374. package/node_modules/@opentelemetry/semantic-conventions/build/esnext/version.js +0 -7
  375. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_attributes.d.ts +0 -14984
  376. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.d.ts +0 -291
  377. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_events.js +0 -301
  378. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.d.ts +0 -4053
  379. package/node_modules/@opentelemetry/semantic-conventions/build/src/experimental_metrics.js +0 -4072
  380. package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.d.ts +0 -7
  381. package/node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.js +0 -29
  382. package/node_modules/@opentelemetry/semantic-conventions/build/src/index.d.ts +0 -6
  383. package/node_modules/@opentelemetry/semantic-conventions/build/src/index.js +0 -32
  384. package/node_modules/@opentelemetry/semantic-conventions/build/src/internal/utils.d.ts +0 -7
  385. package/node_modules/@opentelemetry/semantic-conventions/build/src/internal/utils.js +0 -27
  386. package/node_modules/@opentelemetry/semantic-conventions/build/src/resource/SemanticResourceAttributes.js +0 -1255
  387. package/node_modules/@opentelemetry/semantic-conventions/build/src/resource/index.d.ts +0 -2
  388. package/node_modules/@opentelemetry/semantic-conventions/build/src/resource/index.js +0 -26
  389. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.d.ts +0 -1726
  390. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_attributes.js +0 -1759
  391. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.d.ts +0 -5
  392. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_events.js +0 -15
  393. package/node_modules/@opentelemetry/semantic-conventions/build/src/stable_metrics.d.ts +0 -308
  394. package/node_modules/@opentelemetry/semantic-conventions/build/src/trace/SemanticAttributes.js +0 -2368
  395. package/node_modules/@opentelemetry/semantic-conventions/build/src/trace/index.d.ts +0 -2
  396. package/node_modules/@opentelemetry/semantic-conventions/build/src/trace/index.js +0 -26
  397. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.d.ts +0 -2
  398. package/node_modules/@opentelemetry/semantic-conventions/build/src/version.js +0 -10
  399. /package/node_modules/import-in-the-middle/{register-hooks.d.ts → register-hooks.d.mts} +0 -0
@@ -5,7 +5,9 @@
5
5
  import { URL, fileURLToPath } from 'url'
6
6
  import { inspect } from 'util'
7
7
  import { builtinModules } from 'module'
8
+ import { isAbsolute } from 'path'
8
9
  import { getModuleExports } from './lib/get-exports.mjs'
10
+ import { sourceToString } from './lib/get-esm-exports.mjs'
9
11
  import { RESOLVE, driveSync, driveAsync } from './lib/io.mjs'
10
12
  import { supportsSyncHooks } from './supports-sync-hooks.mjs'
11
13
 
@@ -34,54 +36,47 @@ const HANDLED_FORMATS = new Set([
34
36
  const TRACE_WARNINGS = process.execArgv.includes('--trace-warnings')
35
37
 
36
38
  /** @typedef {import('node:module').LoadHookContext} LoadContext */
39
+ /** @typedef {import('node:module').ResolveHookContext} ResolveContext */
40
+ /** @typedef {import('node:module').ResolveFnOutput} ResolveResult */
37
41
  /** @typedef {import('node:module').LoadFnOutput} LoadResult */
38
42
  /** @typedef {string | { specifier: string, format: 'module-typescript' | 'commonjs-typescript' }} SpecifierData */
39
43
  /** @typedef {{ name: string, origin: string }} StarBinding */
44
+ /** @typedef {{ url: string, format?: string, importAttributes: Record<string, string>, graph?: ModuleImportGraph }} ModuleImportTarget */
45
+ /** @typedef {{ targets: ModuleImportTarget[], acyclic: boolean }} ModuleImportGraph */
46
+ /** @typedef {(url: string, context: LoadContext) => Generator<Array, ModuleImportGraph>} ResolveImports */
40
47
  /**
41
48
  * @typedef {object} ProcessResult
42
49
  * @property {string[] | Map<string, string | StarBinding>} bindings
43
50
  * @property {Map<string, string> | undefined} origins
51
+ * @property {string | undefined} format
52
+ * @property {Set<string> | undefined} [cyclicImports]
53
+ */
54
+ /**
55
+ * @typedef {object} CycleState
56
+ * @property {string} rootUrl
57
+ * @property {Set<string> | undefined} imports
44
58
  */
45
59
 
46
- function hasIitm (url) {
47
- // Fast path: avoid URL parsing on the hot path when there's clearly no iitm.
48
- if (typeof url !== 'string' || url.indexOf('iitm') === -1) {
49
- return false
50
- }
60
+ /** @param {string} url The module URL or specifier. */
61
+ function parseIitm (url) {
62
+ const queryIndex = url.indexOf('?')
63
+ if (queryIndex === -1 || url.indexOf('iitm', queryIndex) === -1) return
51
64
  try {
52
- return new URL(url).searchParams.has('iitm')
53
- } catch {
54
- return false
55
- }
65
+ const parsed = new URL(url)
66
+ if (parsed.searchParams.has('iitm')) return parsed
67
+ } catch {}
56
68
  }
57
69
 
58
- function isIitm (url, meta) {
59
- return url === meta.url || url === meta.url.replace('hook.mjs', 'create-hook.mjs')
70
+ /** @param {string} url The module URL or specifier. */
71
+ function hasIitm (url) {
72
+ return parseIitm(url) !== undefined
60
73
  }
61
74
 
62
- function deleteIitm (url) {
63
- // Fast path: avoid URL parsing / try-catch on bare specifiers and normal file URLs.
64
- if (typeof url !== 'string' || url.indexOf('iitm') === -1) {
65
- return url
66
- }
67
- let resultUrl
68
- const stackTraceLimit = Error.stackTraceLimit
69
- try {
70
- Error.stackTraceLimit = 0
71
- const urlObj = new URL(url)
72
- if (urlObj.searchParams.has('iitm')) {
73
- urlObj.searchParams.delete('iitm')
74
- resultUrl = urlObj.href
75
- if (resultUrl.startsWith('file:///node:')) {
76
- resultUrl = resultUrl.replace('file:///', '')
77
- }
78
- } else {
79
- resultUrl = urlObj.href
80
- }
81
- } catch {
82
- resultUrl = url
83
- }
84
- Error.stackTraceLimit = stackTraceLimit
75
+ /** @param {URL} parsedURL The parsed wrapper URL. */
76
+ function deleteIitm (parsedURL) {
77
+ parsedURL.searchParams.delete('iitm')
78
+ const resultUrl = parsedURL.href
79
+ if (resultUrl.startsWith('file:///node:')) return resultUrl.slice('file:///'.length)
85
80
  return resultUrl
86
81
  }
87
82
 
@@ -212,6 +207,7 @@ function shouldExcludeExport (name, sourceUrl) {
212
207
  * @param {object} params
213
208
  * @param {string} params.srcUrl The full URL to the module to process.
214
209
  * @param {LoadContext} params.context Provided by the loaders API.
210
+ * @param {ResolveImports} params.resolveImports The cached static-import resolver.
215
211
  * @param {boolean} [params.excludeDefault = false] Exclude the default export.
216
212
  * @param {number} [params.depth = 0] Star-re-export recursion depth. Used to
217
213
  * detect `export *` cycles (`a` re-exports `b`, `b` re-exports `a`) cheaply:
@@ -221,20 +217,28 @@ function shouldExcludeExport (name, sourceUrl) {
221
217
  * created lazily once `depth` crosses {@link STAR_CYCLE_DEPTH}. A URL is added
222
218
  * before descending into its subtree and removed once that subtree finishes, so
223
219
  * it tracks the active path rather than every URL ever visited.
220
+ * @param {CycleState} [params.cycleState] The wrapper root and detected cycle edges.
224
221
  * @returns {Generator<Array, ProcessResult>}
225
222
  * A generator that yields I/O operations and ultimately returns the shimmed
226
223
  * bindings for all the exports from the module and any transitive export all
227
224
  * modules. `origins` (the defining module per `*`-sourced name) is `undefined`
228
225
  * for a module with no `export *`.
229
226
  */
230
- function * processModule ({ srcUrl, context, excludeDefault = false, depth = 0, seen }) {
231
- const { exportNames, starReexports } = yield * getModuleExports(srcUrl, context)
227
+ function * processModule ({ srcUrl, context, resolveImports, excludeDefault = false, depth = 0, seen, cycleState }) {
228
+ let isCycleRoot = false
229
+ const moduleExports = yield * getModuleExports(srcUrl, context, cycleState !== undefined)
230
+ const { exportNames, starReexports, format } = moduleExports
231
+
232
+ if (cycleState !== undefined && moduleExports.hasModuleImports) {
233
+ cycleState.imports ??= new Set()
234
+ cycleState.imports.add(srcUrl)
235
+ }
232
236
 
233
237
  // Most modules have no export star. Keep that path array-backed so it pays
234
238
  // neither merge bookkeeping nor a Map lookup for each direct export.
235
239
  if (starReexports === undefined) {
236
240
  if (!excludeDefault) {
237
- return { bindings: exportNames, origins: undefined }
241
+ return { bindings: exportNames, origins: undefined, format }
238
242
  }
239
243
 
240
244
  const bindings = []
@@ -242,7 +246,12 @@ function * processModule ({ srcUrl, context, excludeDefault = false, depth = 0,
242
246
  if (shouldExcludeExport(name, srcUrl)) continue
243
247
  bindings.push(name)
244
248
  }
245
- return { bindings, origins: undefined }
249
+ return { bindings, origins: undefined, format }
250
+ }
251
+
252
+ if (cycleState === undefined) {
253
+ cycleState = { rootUrl: srcUrl, imports: undefined }
254
+ isCycleRoot = true
246
255
  }
247
256
 
248
257
  const bindings = new Map()
@@ -306,9 +315,11 @@ function * processModule ({ srcUrl, context, excludeDefault = false, depth = 0,
306
315
  const sub = yield * processModule({
307
316
  srcUrl: result.url,
308
317
  context: { ...context, format: result.format },
318
+ resolveImports,
309
319
  excludeDefault: true,
310
320
  depth: depth + 1,
311
- seen
321
+ seen,
322
+ cycleState
312
323
  })
313
324
 
314
325
  for (const binding of sub.bindings.values()) {
@@ -341,12 +352,66 @@ function * processModule ({ srcUrl, context, excludeDefault = false, depth = 0,
341
352
  }
342
353
  }
343
354
 
344
- return { bindings, origins: starOrigins }
355
+ if (isCycleRoot && cycleState.imports !== undefined) {
356
+ const candidates = cycleState.imports
357
+ cycleState.imports = undefined
358
+ const seenImports = new Set()
359
+ for (const candidate of candidates) {
360
+ yield * findCyclicImports(candidate, context, cycleState, seenImports, resolveImports)
361
+ }
362
+ }
363
+
364
+ if (isCycleRoot && cycleState.imports !== undefined) {
365
+ return { bindings, origins: starOrigins, format, cyclicImports: cycleState.imports }
366
+ }
367
+ return { bindings, origins: starOrigins, format }
368
+ }
369
+
370
+ /**
371
+ * @param {string} url The module whose static requests can close the cycle.
372
+ * @param {LoadContext} context The metadata load context.
373
+ * @param {CycleState} cycleState The wrapper root and its closing importers.
374
+ * @param {Set<string>} seen Modules already inspected for this wrapper.
375
+ * @param {ResolveImports} resolveImports The cached static-import resolver.
376
+ * @param {ModuleImportGraph} [graph] The resolved target graph, if already available.
377
+ */
378
+ function * findCyclicImports (url, context, cycleState, seen, resolveImports, graph) {
379
+ graph ??= yield * resolveImports(url, context)
380
+ if (graph.acyclic) return true
381
+ if (seen.has(url)) return false
382
+ seen.add(url)
383
+ let acyclic = true
384
+ for (const imported of graph.targets) {
385
+ const { url: target, format, importAttributes } = imported
386
+ if (target === cycleState.rootUrl) {
387
+ cycleState.imports ??= new Set()
388
+ cycleState.imports.add(url)
389
+ acyclic = false
390
+ } else if (format === 'module' || format === 'module-typescript' || format === undefined) {
391
+ if (imported.graph?.acyclic) continue
392
+ const targetContext = { ...context, format, importAttributes }
393
+ imported.graph ??= yield * resolveImports(target, targetContext)
394
+ if (!(yield * findCyclicImports(target, targetContext, cycleState, seen, resolveImports, imported.graph))) {
395
+ acyclic = false
396
+ }
397
+ }
398
+ }
399
+ if (acyclic) graph.acyclic = true
400
+ return acyclic
345
401
  }
346
402
 
347
- function addIitm (url) {
403
+ /**
404
+ * @param {string} url
405
+ * @param {'true' | 'bindings'} [kind]
406
+ */
407
+ function addIitm (url, kind = 'true') {
408
+ if (url.indexOf('?') === -1) {
409
+ const hashIndex = url.indexOf('#')
410
+ if (hashIndex === -1) return `${url}?iitm=${kind}`
411
+ return `${url.slice(0, hashIndex)}?iitm=${kind}${url.slice(hashIndex)}`
412
+ }
348
413
  const urlObj = new URL(url)
349
- urlObj.searchParams.set('iitm', 'true')
414
+ urlObj.searchParams.set('iitm', kind)
350
415
  return urlObj.href
351
416
  }
352
417
 
@@ -358,9 +423,79 @@ export function createHook (meta) {
358
423
  const specifiers = new Map()
359
424
  let cachedResolve
360
425
  const iitmURL = new URL('lib/register.js', meta.url).toString()
426
+ const createHookURL = meta.url.replace('hook.mjs', 'create-hook.mjs')
361
427
  let includeModules, excludeModules
362
428
  let shouldInclude = defaultShouldInclude
363
429
  let disableCjsSourceStripping = false
430
+ /** @type {Map<string, Set<string>> | undefined} */
431
+ let cyclicImportTargets
432
+ /** @type {Map<string, string> | undefined} */
433
+ let cyclicSources
434
+ /** @type {Map<string, ModuleImportGraph> | undefined} */
435
+ let moduleImportTargets
436
+
437
+ /**
438
+ * @param {string} url The module whose static imports are resolved.
439
+ * @param {LoadContext} context Its metadata load context.
440
+ */
441
+ function * resolveImports (url, context) {
442
+ const cached = moduleImportTargets?.get(url)
443
+ if (cached !== undefined) return cached
444
+ const { moduleImports } = yield * getModuleExports(url, context, true)
445
+ const targets = []
446
+ if (moduleImports !== undefined) {
447
+ for (const imported of moduleImports) {
448
+ const specifier = typeof imported === 'string' ? imported : imported.specifier
449
+ const importAttributes = typeof imported === 'string' ? {} : Object.fromEntries(imported.attributes)
450
+ const { url: target, format } = yield [RESOLVE, specifier, { parentURL: url, importAttributes }]
451
+ targets.push({ url: target, format, importAttributes, graph: undefined })
452
+ }
453
+ }
454
+ moduleImportTargets ??= new Map()
455
+ const graph = { targets, acyclic: false }
456
+ moduleImportTargets.set(url, graph)
457
+ return graph
458
+ }
459
+
460
+ /**
461
+ * @param {string} url The native module URL.
462
+ * @param {LoadResult} result The actual native load result.
463
+ */
464
+ function prepareNativeSource (url, result) {
465
+ const targets = cyclicImportTargets?.get(url)
466
+ if (targets === undefined || targets.size === 0 ||
467
+ (result.format !== 'module' && result.format !== 'module-typescript')) return result
468
+
469
+ let bindingImports = ''
470
+ if (result.source != null) {
471
+ for (const target of targets) {
472
+ bindingImports += `\nimport ${JSON.stringify(addIitm(target, 'bindings'))}\n`
473
+ }
474
+ }
475
+ // A consumed target must not be queued again by a later barrel.
476
+ targets.clear()
477
+ if (bindingImports === '') return result
478
+ // Original dependencies must initialize before the cycle's shared bindings.
479
+ return { ...result, source: sourceToString(result.source) + bindingImports }
480
+ }
481
+
482
+ /**
483
+ * @param {Set<string>} imports The cycle's closing importers.
484
+ * @param {string} targetURL The wrapper root URL.
485
+ */
486
+ function mergeCyclicImports (imports, targetURL) {
487
+ for (const parentURL of imports) {
488
+ cyclicImportTargets ??= new Map()
489
+ let targets = cyclicImportTargets.get(parentURL)
490
+ if (targets === undefined) {
491
+ targets = new Set()
492
+ cyclicImportTargets.set(parentURL, targets)
493
+ } else if (targets.size === 0) {
494
+ continue
495
+ }
496
+ targets.add(targetURL)
497
+ }
498
+ }
364
499
 
365
500
  // Track CJS module URLs that IITM has wrapped. On Node 24+, CJS modules loaded
366
501
  // via loadCJSModule (in an ESM import chain) have their require() calls for
@@ -378,33 +513,36 @@ export function createHook (meta) {
378
513
  // node_modules, and the full file URL for non-bare specifier imports (relative
379
514
  // paths would be error prone). An absolute path entry added via Hook over the
380
515
  // message port matches the resolved file path, so it is resolved here.
516
+ /**
517
+ * @param {string} url The resolved module URL.
518
+ * @param {string} specifier The original import specifier.
519
+ */
381
520
  function defaultShouldInclude (url, specifier) {
521
+ if (includeModules === undefined && excludeModules === undefined) return true
522
+
382
523
  let resultPath
383
- if (url.startsWith('file:')) {
384
- const stackTraceLimit = Error.stackTraceLimit
385
- Error.stackTraceLimit = 0
386
- try {
387
- resultPath = fileURLToPath(url)
388
- } catch {}
389
- Error.stackTraceLimit = stackTraceLimit
390
- }
524
+ /** @param {string | RegExp} each The module filter. */
391
525
  function match (each) {
392
- if (each instanceof RegExp) {
393
- return each.test(url)
526
+ if (each instanceof RegExp) return each.test(url)
527
+ if (each === specifier || each === url) return true
528
+ if (!isAbsolute(each)) return false
529
+
530
+ if (resultPath === undefined) {
531
+ resultPath = ''
532
+ if (url.startsWith('file:')) {
533
+ const stackTraceLimit = Error.stackTraceLimit
534
+ Error.stackTraceLimit = 0
535
+ try {
536
+ resultPath = fileURLToPath(url)
537
+ } catch {}
538
+ Error.stackTraceLimit = stackTraceLimit
539
+ }
394
540
  }
395
-
396
- return each === specifier || each === url || (resultPath && each === resultPath)
397
- }
398
-
399
- if (includeModules && !includeModules.some(match)) {
400
- return false
541
+ return each === resultPath
401
542
  }
402
543
 
403
- if (excludeModules && excludeModules.some(match)) {
404
- return false
405
- }
406
-
407
- return true
544
+ return (includeModules === undefined || includeModules.some(match)) &&
545
+ (excludeModules === undefined || !excludeModules.some(match))
408
546
  }
409
547
 
410
548
  // Applies the include/exclude/message-port configuration. Shared by the
@@ -462,13 +600,21 @@ export function createHook (meta) {
462
600
  // once the parent loader has turned the specifier into a resolved URL. The
463
601
  // only difference between the asynchronous and synchronous hooks is whether
464
602
  // that resolution was awaited, so all the wrapping decisions live here.
465
- function finishResolve (result, specifier, context, parentURL) {
603
+ /**
604
+ * @param {{ url: string, format?: string }} result The resolved module.
605
+ * @param {string} specifier The original module specifier.
606
+ * @param {ResolveContext} context The resolve context.
607
+ * @param {string} parentURL The importing module URL.
608
+ * @param {boolean} binding Whether the request is for a cycle binding module.
609
+ */
610
+ function finishResolve (result, specifier, context, parentURL, binding) {
466
611
  // Do not wrap the entrypoint module. Many CLIs check whether they are the
467
612
  // "main" module (e.g. require.main === module). Wrapping changes how they
468
613
  // are evaluated, and can make them exit without doing anything.
469
614
  if (parentURL === '') {
470
615
  if (!EXTENSION_RE.test(result.url) && !hasIitm(result.url)) {
471
- return { url: result.url, format: 'commonjs' }
616
+ // Extensionless CLIs can be ESM; preserve the format resolved by Node or an upstream loader.
617
+ return { url: result.url, format: result.format ?? 'commonjs' }
472
618
  }
473
619
  return result
474
620
  }
@@ -492,13 +638,17 @@ export function createHook (meta) {
492
638
  return result
493
639
  }
494
640
 
641
+ if (binding) {
642
+ return { ...result, url: addIitm(result.url, 'bindings'), shortCircuit: true, format: 'module' }
643
+ }
644
+
495
645
  // `shouldInclude` is always set (the include/exclude list matcher by default,
496
646
  // a consumer-provided predicate otherwise), so no nullish check is needed.
497
647
  if (!shouldInclude(result.url, specifier)) {
498
648
  return result
499
649
  }
500
650
 
501
- if (isIitm(parentURL, meta) || (parentURL && hasIitm(parentURL))) {
651
+ if (parentURL === meta.url || parentURL === createHookURL || (parentURL && hasIitm(parentURL))) {
502
652
  return result
503
653
  }
504
654
 
@@ -534,10 +684,11 @@ export function createHook (meta) {
534
684
  }
535
685
 
536
686
  // Preserve the format before an outer loader can normalize it.
537
- const specifierData = result.format === 'module-typescript' || result.format === 'commonjs-typescript'
538
- ? { specifier, format: result.format }
539
- : specifier
540
- specifiers.set(result.url, specifierData)
687
+ if (result.format === 'module-typescript' || result.format === 'commonjs-typescript') {
688
+ specifiers.set(result.url, { specifier, format: result.format })
689
+ } else {
690
+ specifiers.set(result.url, specifier)
691
+ }
541
692
 
542
693
  return {
543
694
  url: addIitm(result.url),
@@ -549,9 +700,16 @@ export function createHook (meta) {
549
700
  }
550
701
  }
551
702
 
703
+ /**
704
+ * @param {string} specifier
705
+ * @param {ResolveContext} context
706
+ * @param {(specifier: string, context?: Partial<ResolveContext>) => ResolveResult | Promise<ResolveResult>} parentResolve
707
+ */
552
708
  async function resolve (specifier, context, parentResolve) {
553
709
  cachedResolve = parentResolve
554
710
 
711
+ const { parentURL = '' } = context
712
+
555
713
  // See https://github.com/nodejs/import-in-the-middle/pull/76.
556
714
  if (specifier === iitmURL) {
557
715
  return {
@@ -560,22 +718,29 @@ export function createHook (meta) {
560
718
  }
561
719
  }
562
720
 
563
- const { parentURL = '' } = context
564
- const newSpecifier = deleteIitm(specifier)
721
+ const parsedURL = parseIitm(specifier)
722
+ const binding = parsedURL?.searchParams.get('iitm') === 'bindings'
723
+ const newSpecifier = parsedURL === undefined ? specifier : deleteIitm(parsedURL)
565
724
  if (isWin && parentURL.indexOf('file:node') === 0) {
566
725
  context.parentURL = ''
567
726
  }
568
727
  const result = await parentResolve(newSpecifier, context)
569
728
 
570
- return finishResolve(result, specifier, context, parentURL)
729
+ return finishResolve(result, specifier, context, parentURL, binding)
571
730
  }
572
731
 
573
732
  // Synchronous counterpart to `resolve`, for `module.registerHooks`. The
574
733
  // synchronous `nextResolve` returns its result directly. We stash it so the
575
734
  // synchronous `load` hook can resolve star re-exports later, mirroring how
576
735
  // `resolve` caches `parentResolve`.
736
+ /**
737
+ * @param {string} specifier
738
+ * @param {ResolveContext} context
739
+ * @param {(specifier: string, context?: Partial<ResolveContext>) => ResolveResult} nextResolve
740
+ */
577
741
  function resolveSync (specifier, context, nextResolve) {
578
742
  cachedResolve = nextResolve
743
+ const { parentURL = '' } = context
579
744
 
580
745
  if (specifier === iitmURL) {
581
746
  return {
@@ -584,14 +749,15 @@ export function createHook (meta) {
584
749
  }
585
750
  }
586
751
 
587
- const { parentURL = '' } = context
588
- const newSpecifier = deleteIitm(specifier)
752
+ const parsedURL = parseIitm(specifier)
753
+ const binding = parsedURL?.searchParams.get('iitm') === 'bindings'
754
+ const newSpecifier = parsedURL === undefined ? specifier : deleteIitm(parsedURL)
589
755
  if (isWin && parentURL.indexOf('file:node') === 0) {
590
756
  context.parentURL = ''
591
757
  }
592
758
  const result = nextResolve(newSpecifier, context)
593
759
 
594
- return finishResolve(result, specifier, context, parentURL)
760
+ return finishResolve(result, specifier, context, parentURL, binding)
595
761
  }
596
762
 
597
763
  /**
@@ -600,8 +766,10 @@ export function createHook (meta) {
600
766
  * @param {string} realUrl The URL of the wrapped module.
601
767
  * @param {string[] | Map<string, string | StarBinding>} bindings Its exported bindings.
602
768
  * @param {string} originalSpecifier The specifier used to import the module.
769
+ * @param {string | undefined} format The wrapped module's loader format.
770
+ * @param {boolean} [staged] Defer Hook invocation until the native root finishes.
603
771
  */
604
- function buildWrapperSource (realUrl, bindings, originalSpecifier) {
772
+ function buildWrapperSource (realUrl, bindings, originalSpecifier, format, staged = false) {
605
773
  // The wrapped module imports its namespace as `namespace`, which serves
606
774
  // every export but the ones a same-origin `export *` collision forced onto
607
775
  // their defining module (#171): the aggregate namespace drops those as
@@ -613,6 +781,7 @@ export function createHook (meta) {
613
781
  let bindingNames = ''
614
782
  let bindingSources
615
783
  let exportSpecifiers = ''
784
+ let facadeSpecifiers = ''
616
785
  let writeCases = ''
617
786
  let index = 0
618
787
  for (const binding of bindings.values()) {
@@ -641,53 +810,77 @@ export function createHook (meta) {
641
810
  }
642
811
  writeCases += ` case ${index++}: ${variableName} = value; break\n`
643
812
  if (shouldReexport(name, realUrl)) {
644
- const exportName = name === 'default' ? name : objectKey
645
- exportSpecifiers += exportSpecifiers === ''
646
- ? `${variableName} as ${exportName}`
647
- : `, ${variableName} as ${exportName}`
813
+ const exportSpecifier = staged ? variableName : `${variableName} as ${name === 'default' ? name : objectKey}`
814
+ if (staged) {
815
+ if (facadeSpecifiers !== '') facadeSpecifiers += ', '
816
+ facadeSpecifiers += `${variableName} as ${objectKey}`
817
+ }
818
+ if (exportSpecifiers !== '') exportSpecifiers += ', '
819
+ exportSpecifiers += exportSpecifier
648
820
  }
649
821
  }
650
- const binder = declarationNames === ''
651
- ? 'const __binder = new ModuleBinder(namespace)\n'
652
- : `let ${declarationNames}
822
+ let binder = 'const __binder = new ModuleBinder(namespace)\n'
823
+ if (declarationNames !== '') {
824
+ let sources = ''
825
+ if (bindingSources !== undefined) {
826
+ sources = `, [${bindingSources}]`
827
+ } else if (staged) {
828
+ sources = ', undefined'
829
+ }
830
+ binder = `let ${declarationNames}
653
831
  function __write (index, value) {
654
832
  switch (index) {
655
833
  ${writeCases} }
656
834
  }
657
- const __binder = new ModuleBinder(namespace, [${bindingNames}], __write${bindingSources === undefined
658
- ? ''
659
- : `, [${bindingSources}]`})
835
+ const __binder = new ModuleBinder(namespace, [${bindingNames}], __write${sources}${staged ? ', true' : ''})
660
836
  `
837
+ }
661
838
  const reexports = exportSpecifiers === '' ? '' : `export { ${exportSpecifiers} }\n`
662
839
 
663
- return `
664
- import { register, ModuleBinder } from ${JSON.stringify(iitmURL)}
840
+ let registration = 'export default __binder'
841
+ if (!staged) {
842
+ registration = `__binder.flush()\n\nregister(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifier)}, ${JSON.stringify(format)})`
843
+ }
844
+ const source = `
845
+ import { ${staged ? '' : 'register, '}ModuleBinder } from ${JSON.stringify(iitmURL)}
665
846
  import * as namespace from ${JSON.stringify(realUrl)}
666
847
  ${originImports}
667
848
  ${binder}
668
849
  ${reexports}
669
850
 
670
- __binder.flush()
671
-
672
- register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifier)})
851
+ ${registration}
673
852
  `
853
+ return staged ? { source, facadeSpecifiers } : source
674
854
  }
675
855
 
676
856
  /**
677
857
  * Finalizes a successful wrap and builds its module source.
678
858
  *
679
859
  * @param {string} realUrl The URL of the wrapped module.
680
- * @param {LoadContext} context Its loader context.
860
+ * @param {string | undefined} format The wrapped module's loader format.
681
861
  * @param {string} originalSpecifier The original import specifier.
682
- * @param {string[] | Map<string, string | StarBinding>} bindings Its exported bindings.
862
+ * @param {ProcessResult} result The processed export bindings and cycle candidates.
683
863
  */
684
- function onWrapSuccess (realUrl, context, originalSpecifier, bindings) {
864
+ function onWrapSuccess (realUrl, format, originalSpecifier, { bindings, cyclicImports }) {
685
865
  specifiers.delete(realUrl)
686
- // context.format is set to 'commonjs' by getCjsExports during processModule.
687
- if (context.format === 'commonjs') {
866
+ if (format === 'commonjs') {
688
867
  cjsInIitmChain.add(realUrl)
689
868
  }
690
- return buildWrapperSource(realUrl, bindings, originalSpecifier)
869
+ if (cyclicImports === undefined) return buildWrapperSource(realUrl, bindings, originalSpecifier, format)
870
+
871
+ const bindingURL = addIitm(realUrl, 'bindings')
872
+ const { source, facadeSpecifiers } = buildWrapperSource(realUrl, bindings, originalSpecifier, format, true)
873
+ cyclicSources ??= new Map()
874
+ cyclicSources.set(bindingURL, source)
875
+ mergeCyclicImports(cyclicImports, realUrl)
876
+ return `
877
+ import ${JSON.stringify(realUrl)}
878
+ import __binder from ${JSON.stringify(bindingURL)}
879
+ export { ${facadeSpecifiers} } from ${JSON.stringify(bindingURL)}
880
+ import { register } from ${JSON.stringify(iitmURL)}
881
+ __binder.flushSync()
882
+ register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifier)}, ${JSON.stringify(format)})
883
+ `
691
884
  }
692
885
 
693
886
  // Bookkeeping shared by the async and sync wrap paths when `processModule`
@@ -710,34 +903,33 @@ register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifie
710
903
  * @param {string} url
711
904
  * @param {LoadContext} context
712
905
  * @param {(url: string, context?: Partial<LoadContext>) => LoadResult | Promise<LoadResult>} parentGetSource
906
+ * @param {string} realUrl The original module URL.
713
907
  */
714
- async function getSource (url, context, parentGetSource) {
715
- if (hasIitm(url)) {
716
- const realUrl = deleteIitm(url)
717
- const specifierData = specifiers.get(realUrl)
718
- if (specifierData === undefined) {
719
- specifiers.delete(url)
720
- return parentGetSource(url, context)
721
- }
908
+ async function getSource (url, context, parentGetSource, realUrl) {
909
+ const specifierData = specifiers.get(realUrl)
910
+ if (specifierData === undefined) {
911
+ specifiers.delete(url)
912
+ return parentGetSource(url, context)
913
+ }
722
914
 
723
- let originalSpecifier = specifierData
724
- let processContext = context
725
- if (typeof specifierData !== 'string') {
726
- originalSpecifier = specifierData.specifier
727
- processContext = { ...context, format: specifierData.format }
728
- }
915
+ let originalSpecifier = specifierData
916
+ let processContext = context
917
+ if (typeof specifierData !== 'string') {
918
+ originalSpecifier = specifierData.specifier
919
+ processContext = { ...context, format: specifierData.format }
920
+ }
729
921
 
730
- try {
731
- const { bindings } = await driveAsync(
732
- processModule({ srcUrl: realUrl, context: processContext }),
733
- { resolve: cachedResolve, load: parentGetSource }
734
- )
735
- return { source: onWrapSuccess(realUrl, processContext, originalSpecifier, bindings) }
736
- } catch (cause) {
737
- onWrapFailure(realUrl, cause)
738
- // Revert back to the non-iitm URL
739
- url = realUrl
740
- }
922
+ try {
923
+ const result = await driveAsync(
924
+ processModule({ srcUrl: realUrl, context: processContext, resolveImports }),
925
+ { resolve: cachedResolve, load: parentGetSource }
926
+ )
927
+ const source = onWrapSuccess(realUrl, result.format, originalSpecifier, result)
928
+ return { source }
929
+ } catch (cause) {
930
+ onWrapFailure(realUrl, cause)
931
+ // Revert back to the non-iitm URL
932
+ url = realUrl
741
933
  }
742
934
 
743
935
  return parentGetSource(url, context)
@@ -750,41 +942,52 @@ register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifie
750
942
  * @param {string} url
751
943
  * @param {LoadContext} context
752
944
  * @param {(url: string, context?: Partial<LoadContext>) => LoadResult} nextLoad
945
+ * @param {string} realUrl The original module URL.
753
946
  */
754
- function getSourceSync (url, context, nextLoad) {
755
- if (hasIitm(url)) {
756
- const realUrl = deleteIitm(url)
757
- const specifierData = specifiers.get(realUrl)
758
- if (specifierData === undefined) {
759
- specifiers.delete(url)
760
- return nextLoad(url, context)
761
- }
947
+ function getSourceSync (url, context, nextLoad, realUrl) {
948
+ const specifierData = specifiers.get(realUrl)
949
+ if (specifierData === undefined) {
950
+ specifiers.delete(url)
951
+ return nextLoad(url, context)
952
+ }
762
953
 
763
- let originalSpecifier = specifierData
764
- let processContext = context
765
- if (typeof specifierData !== 'string') {
766
- originalSpecifier = specifierData.specifier
767
- processContext = { ...context, format: specifierData.format }
768
- }
954
+ let originalSpecifier = specifierData
955
+ let processContext = context
956
+ if (typeof specifierData !== 'string') {
957
+ originalSpecifier = specifierData.specifier
958
+ processContext = { ...context, format: specifierData.format }
959
+ }
769
960
 
770
- try {
771
- const { bindings } = driveSync(
772
- processModule({ srcUrl: realUrl, context: processContext }),
773
- { resolve: cachedResolve, load: nextLoad }
774
- )
775
- return { source: onWrapSuccess(realUrl, processContext, originalSpecifier, bindings) }
776
- } catch (cause) {
777
- onWrapFailure(realUrl, cause)
778
- url = realUrl
779
- }
961
+ try {
962
+ const result = driveSync(
963
+ processModule({ srcUrl: realUrl, context: processContext, resolveImports }),
964
+ { resolve: cachedResolve, load: nextLoad }
965
+ )
966
+ const source = onWrapSuccess(realUrl, result.format, originalSpecifier, result)
967
+ return { source }
968
+ } catch (cause) {
969
+ onWrapFailure(realUrl, cause)
970
+ url = realUrl
780
971
  }
781
972
 
782
973
  return nextLoad(url, context)
783
974
  }
784
975
 
976
+ /**
977
+ * @param {string} url
978
+ * @param {LoadContext} context
979
+ * @param {(url: string, context?: Partial<LoadContext>) => LoadResult | Promise<LoadResult>} parentLoad
980
+ */
785
981
  async function load (url, context, parentLoad) {
786
- if (hasIitm(url)) {
787
- const result = await getSource(url, context, parentLoad)
982
+ const parsedURL = parseIitm(url)
983
+ if (parsedURL !== undefined) {
984
+ if (parsedURL.searchParams.get('iitm') === 'bindings') {
985
+ const source = cyclicSources?.get(url)
986
+ if (source === undefined) return parentLoad(url, context)
987
+ return { source, shortCircuit: true, format: 'module' }
988
+ }
989
+ const realUrl = deleteIitm(parsedURL)
990
+ const result = await getSource(url, context, parentLoad, realUrl)
788
991
  // If wrapping failed, `getSource()` may have fallen back to `parentLoad`,
789
992
  // which can legally return `source: null` (e.g. for non-JS formats).
790
993
  if (result && typeof result === 'object' && result.source != null) {
@@ -796,7 +999,7 @@ register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifie
796
999
  }
797
1000
 
798
1001
  // Fall back to the parent loader with the original (non-iitm) URL.
799
- return parentLoad(deleteIitm(url), context)
1002
+ return parentLoad(realUrl, context)
800
1003
  }
801
1004
 
802
1005
  // On Node 22+, when a CJS module is loaded through the ESM translator and
@@ -817,15 +1020,27 @@ register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifie
817
1020
  return result
818
1021
  }
819
1022
 
820
- return parentLoad(url, context)
1023
+ return prepareNativeSource(url, await parentLoad(url, context))
821
1024
  }
822
1025
 
823
1026
  // Synchronous counterpart to `load`, for `module.registerHooks`. Mirrors the
824
1027
  // async `load` exactly — wrapping via `getSourceSync` and applying the same
825
1028
  // CJS-in-iitm-chain source stripping — only without awaiting.
1029
+ /**
1030
+ * @param {string} url
1031
+ * @param {LoadContext} context
1032
+ * @param {(url: string, context?: Partial<LoadContext>) => LoadResult} nextLoad
1033
+ */
826
1034
  function loadSync (url, context, nextLoad) {
827
- if (hasIitm(url)) {
828
- const result = getSourceSync(url, context, nextLoad)
1035
+ const parsedURL = parseIitm(url)
1036
+ if (parsedURL !== undefined) {
1037
+ if (parsedURL.searchParams.get('iitm') === 'bindings') {
1038
+ const source = cyclicSources?.get(url)
1039
+ if (source === undefined) return nextLoad(url, context)
1040
+ return { source, shortCircuit: true, format: 'module' }
1041
+ }
1042
+ const realUrl = deleteIitm(parsedURL)
1043
+ const result = getSourceSync(url, context, nextLoad, realUrl)
829
1044
  // If wrapping failed, `getSourceSync()` may have fallen back to `nextLoad`,
830
1045
  // which can legally return `source: null` (e.g. for non-JS formats).
831
1046
  if (result && typeof result === 'object' && result.source != null) {
@@ -837,7 +1052,7 @@ register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifie
837
1052
  }
838
1053
 
839
1054
  // Fall back to the parent loader with the original (non-iitm) URL.
840
- return nextLoad(deleteIitm(url), context)
1055
+ return nextLoad(realUrl, context)
841
1056
  }
842
1057
 
843
1058
  if (cjsInIitmChain.has(url) && !disableCjsSourceStripping) {
@@ -851,7 +1066,7 @@ register(${JSON.stringify(realUrl)}, __binder, ${JSON.stringify(originalSpecifie
851
1066
  return result
852
1067
  }
853
1068
 
854
- return nextLoad(url, context)
1069
+ return prepareNativeSource(url, nextLoad(url, context))
855
1070
  }
856
1071
 
857
1072
  return { initialize, load, resolve, resolveSync, loadSync, applyOptions }