webpack-asset-relocator-loader
Used in ncc while emitting and relocating any asset references
by vercelJavaScript
Commit activity
Last 12 weeks · 6 commits
Community health
2 of 6 standards met
Recent fixes
Follow-up to #212 (note 2 in my review there). What Moves the shorthand-property regression test onto the repo's existing fixture harness: → (input and the two assets unchanged) adds / snapshots deletes is gone — #212 was its only user No source changes. Why already drives 84 fixtures out of . #212 added a second convention plus a ~66-line webpack config that mostly duplicates that harness. Folding it in gets three things: 1. The snapshot pins the emitted syntax, which is the thing that actually regressed in #209. The relevant lines of : It also documents the neighbouring behaviour for free: the ternary is inlined at its declaration and the shorthand read is left alone. 2. The prefix opts the fixture into the harness's asset validation (every emitted asset must have non-zero permissions and a resolved path). 3. One less webpack config to keep in sync with . Verification → 89 passed (unchanged: the suite loses one test file and gains one fixture). → 89 passed, thresholds met. Still a real regression test: with reverted to (pre-#212), the fixture fails with exactly the reported error — Tradeoff The deleted test executed the bundle and asserted the runtime property values; the harness only diffs emitted output. That's a small loss, but the failure mode here is invalid syntax, which the harness catches either way — webpack fails to parse, no is emitted, and the test throws with the compilation errors. Happy to keep the runtime assertions as a separate file instead if you'd rather have both. 🤖 Generated with Claude Code
When a variable holding a statically-known asset path (from ) is read as a shorthand object property, the relocation overwrites the identifier — which is simultaneously the property's key and value — with the asset expression, producing a bare expression inside an object literal. The result is syntactically invalid and webpack fails with . Claude's understanding of the problem & a suggested fix Mechanism In (as of fa39a777): 1. The assignment registers as a known absolute-path binding. 2. At the shorthand property read, returns via its case (line ~44: ) — in a shorthand property, acorn makes the key and value the same node, so the check can't distinguish this from a plain value read. 3. then runs (line ~1318), replacing the identifier — key included — with the bare asset expression. Possible fixes Two contained options: In , exclude shorthand properties: I tested this variant against the loader source: the minimal repro above compiles and runs correctly in both branches (the default branch resolves to the relocated asset because the call is still rewritten at the assignment site, and the asset is still emitted), and (v10.0.4) goes from the parse error to compiling and loading successfully, with emitted. I have not run the repo's unit-test fixtures against it. Alternatively, in , when is the value of a shorthand , emit instead of the bare expression (preserves the read-site inlining). Repro files : : : Build with and webpack 5.108.1: Also reproduced through ncc 0.44.1 (which pins this loader at 1.7.3 as its relocate-loader), so the bug spans at least 1.7.3 → 1.10.0 → current . Control: changing the shorthand to builds successfully and emits the expected with relocated next to the bundle and the program running correctly. Impact This was run down by Claude when trying to figure out why https://github.com/pulumi/actions/pull/1460 couldn't merge as is. This is the root cause of the long-standing inability to bundle v9+/ v11+/ v8+ with ncc (vercel/ncc#986, vercel/ncc#1162 — the latter was closed as unfixable in ncc, but the defect is in this loader and looks contained).
Repository: vercel/webpack-asset-relocator-loader. Description: Used in ncc while emitting and relocating any asset references Stars: 109, Forks: 41. Primary language: JavaScript. Languages: JavaScript (100%). License: MIT. Homepage: https://npmjs.com/@vercel/webpack-asset-relocator-loader Latest release: v1.11.0 (2mo ago). Open PRs: 2, open issues: 17. Last activity: 5d ago. Community health: 50%. Top contributors: guybedford, dependabot[bot], styfle, yjoer, Timer, yichi-yang, yurynix, adriencohen, anupamme, fregante and others.