refactor(bundlers): delegate wrappers to import-in-the-middle - #10262
refactor(bundlers): delegate wrappers to import-in-the-middle#10262BridgeAR wants to merge 17 commits into
Conversation
Overall package sizeSelf size: 8.89 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.0 | 442.82 kB | 828.77 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## BridgeAR/2026-08-28-turbopack-instrumentation #10262 +/- ##
==================================================================================
- Coverage 98.71% 69.52% -29.19%
==================================================================================
Files 1013 986 -27
Lines 160794 152589 -8205
Branches 74 26 -48
==================================================================================
- Hits 158728 106092 -52636
- Misses 2066 46497 +44431
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Turbopack compiles dependency modules before runtime hooks can observe their exports. Build-time plans and live-binding proxies preserve instrumentation without adding discovery or source analysis to the request path.
1. Clean installs hoisted Babel 8's ESM parser into the CommonJS fake Next compiler because its Babel 7 inputs were only transitive dependencies. 2. Bun applied the root files allowlist to nested READMEs while npm included them automatically, so the package archives differed.
Backport CI widens the repository engine range to include Node 18 and 20. The test then loads ESLint 10 on unsupported runtimes, which fail while parsing its /v regular expressions.
Generated ESM proxies captured mutable exports once, so later updates were invisible to bundled consumers. Build plans persisted hook positions and incomplete source snapshots. Runtime hook changes or star-export updates could therefore apply the wrong instrumentation or load stale proxies. Artifacts under installed dependencies also made read-only dependency trees abort Next configuration.
Build planning could execute application code, lose non-hoisted targets, and retain stale resolution data. Isolated native resolution preserves roots and conditions without request-path work. Generated proxies could be unreachable, miss foreign ESM importers, or make optional edges fatal. Resolver-visible artifacts and importer-local checks preserve instrumentation and fail-open behavior. Supported CommonJS wrappers can contain top-level returns that older Next parsers reject. Script-compatible parsing preserves the wrapper grammar. Legal star-export cycles could exhaust the stack. Active-path tracking terminates cycles without dropping same-origin diamond exports.
Regular module loading passed through the bundler source-map API and allocated its result object for every rewrite. Keeping the scalar path avoids that startup work while Turbopack retains source-map composition. Bundler matchers are cached per diagnostic-channel specifier so targets at different directory depths keep the correct runtime import.
Node.js 22 reads conditions through Set#has. Passing an array throws while resolving bare conditional exports, so target planning silently omits the ESM instrumentation.
Build-time discovery resolved ESM imports with CommonJS rules and reused plans after their dependency graph changed. This selected incorrect conditional exports, retained stale proxies, and could change ESM initialization order.
8e27ae6 to
710e3a4
Compare
Generated source was linted from a synthetic repository path, so valid relative dependencies resolved differently on CI.
…zation Runtime instrumentation shared the bundler rewrite entry point, so every traced process parsed bundler-only source-map composition code during initialization.
Separate bundler wrappers duplicated export discovery, live-binding, and CommonJS replacement semantics, allowing their behavior to drift from runtime instrumentation. Delegate those contracts to import-in-the-middle while retaining bundler-specific resolution, target selection, and source maps.
862411d to
0fd9965
Compare
d899dbf to
8cd78ff
Compare
Separate wrappers for Webpack, esbuild, and Turbopack duplicate export discovery, live-binding, and CommonJS replacement behavior. Their behavior can drift from import-in-the-middle and from each other.
This delegates those contracts to import-in-the-middle's experimental bundler API. dd-trace-js still owns bundler resolution, instrumentation metadata, source-map composition, and watch-file integration.
This draft depends on nodejs/import-in-the-middle#270.