Repository navigation
Commit e78a670
authored
transpile: report a file: URL as a stripped script's sourceURL (#800)
* transpile: report a file: URL as a stripped script's sourceURL
Node's type stripping emits pathToFileURL(filename).href as the
`//# sourceURL` of a stripped script, and the inspector surfaces that
value as Debugger.scriptParsed's `url` — the key editors and DevTools
match breakpoints against. nub emitted the bare filesystem path, so
every transpiled .ts/.cts/.mts reached them under a different script
identity than the same file under node.
The percent-encoding matches pathToFileURL byte for byte. Its set is
wider than the WHATWG path percent-encode set — `[`, `]`, `^`, `|` and
`~` are escaped too — so it is derived from a sweep against v26.7.0
rather than from the URL spec.
CACHE_SCHEMA goes to "7": the sourceURL is baked into the cached body,
so a "6"-era entry would keep serving the old identity.
Upstream's test/parallel/test-inspector-strip-types.js now passes under
nub on 4 of its 5 scenarios, matching plain node on the same checkout
(the fifth fails identically under both). test-debugger-probe-typescript
reports the right `url` and still differs on line/column, which is
transpiled-position fidelity rather than script identity.
* transpile: spell the sourceURL for the host Node's escape band
The sourceURL is percent-encoded to match `pathToFileURL`, but that
escape set is not fixed across nub's supported range. nodejs/node#54545
widened it to cover `[`, `]`, `^`, `|` and `~`, and it reached the
release lines out of order, so it takes bands rather than one floor —
measured on real binaries at each boundary tag:
18.x (incl. 18.20.8) narrow 20.18.3+ wide
20.0.0 - 20.18.2 narrow 22.12.0+ wide
21.x (incl. 21.7.3) narrow 23.1.0+ wide
22.0.0 - 22.11.x narrow 24.0.0+ wide
23.0.x narrow
Emitting one fixed set gave one file two identities inside a single
process on the narrow band: Node computes a module's own URL with its
own `pathToFileURL`, so on v22.11 the loader carried
`w[x]y^z~q/probe.ts` while `Debugger.scriptParsed` reported
`w%5Bx%5Dy%5Ez%7Eq/probe.ts`, and a breakpoint set against the module
URL matched no script. `transformCached` now takes `process.version`
and derives the band from it.
The URL FORM stays unconditional. Node's own type stripping only began
reporting a `file:` URL in v26.4.0, backported to v24.19.0, and v25.x
never got it; following the host there would flip nub's script identity
on a patch bump.
`url_band` joins the cache-key preimage, because the band changes the
bytes that get stored: without it an `nvm use` across a boundary serves
a body carrying the other band's spelling. The schema stays at "7" —
both halves land together, and neither shipped.
The URL helpers move to `nub-cache-key`, which exists so the cache's
pure logic can be unit-tested off the `test = false` cdylib. Both
`windows` branches are now covered against captured
`pathToFileURL(p, { windows: true })` output. The integration test
asserts the cold pass actually populated the cache directory, so a
disabled cache fails instead of quietly running cold twice.
* transpile: cover the host-band plumbing end-to-end, record Cause 7 fixed
The integration fixture directories held only characters escaped the
same way in both bands, so nothing exercised `process.version` →
`transformCached`'s 9th argument → `host_widens_url_path` → the emitted
bytes. A wrong value there fell through to widened and still passed on
any modern host.
The all-platform fixture directory is now `w[x]y^z~q`. Those four
characters are band-sensitive and legal in a Windows filename, so the
Windows leg exercises the same path; `|` is band-sensitive but illegal
there, so it joins the unix-only fixture as `a b%c#d?e|f`. The fixture
already derives its expectation from the host's own `pathToFileURL`, so
this is a differential: forcing the 9th argument to a narrow-band
version fails both tests on a v26.7.0 host.
wiki/research/nub-v0.5-augmentation-regressions.md records Cause 7 as
fixed, drops the stale emitter line reference for the current symbols,
and keeps the original analysis. Two additions: the inspector
script-identity symptom that shares the same string, and the two facts
the original recommendation did not anticipate — the host-dependent
escape set, and why the URL form is deliberately not host-gated.
Both symptoms re-verified against the built binary. Coverage: with the
bare path `nub --test --experimental-test-coverage` drops every
TypeScript row and reports a fake 100%; with the fix `lib.ts | 100.00 |
100.00 | 50.00` matches plain node.
* wiki: state which Cause 7 symptom carries a committed test1 parent 874f842 commit e78a670
5 files changed
Lines changed: 550 additions & 28 deletions
File tree
- crates
- nub-cache-key/src
- nub-cli/tests
- nub-native/src
- runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
18 | 27 | | |
19 | 28 | | |
20 | 29 | | |
21 | 30 | | |
22 | 31 | | |
23 | 32 | | |
24 | 33 | | |
25 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
26 | 37 | | |
27 | 38 | | |
28 | 39 | | |
| |||
33 | 44 | | |
34 | 45 | | |
35 | 46 | | |
| 47 | + | |
36 | 48 | | |
37 | 49 | | |
38 | 50 | | |
| |||
50 | 62 | | |
51 | 63 | | |
52 | 64 | | |
| 65 | + | |
| 66 | + | |
53 | 67 | | |
54 | 68 | | |
55 | 69 | | |
| |||
63 | 77 | | |
64 | 78 | | |
65 | 79 | | |
| 80 | + | |
66 | 81 | | |
67 | 82 | | |
68 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
69 | 86 | | |
70 | 87 | | |
71 | 88 | | |
| |||
115 | 132 | | |
116 | 133 | | |
117 | 134 | | |
| 135 | + | |
118 | 136 | | |
119 | 137 | | |
120 | 138 | | |
| |||
125 | 143 | | |
126 | 144 | | |
127 | 145 | | |
| 146 | + | |
128 | 147 | | |
129 | 148 | | |
130 | 149 | | |
131 | 150 | | |
132 | 151 | | |
133 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
134 | 178 | | |
0 commit comments