fix(cli): inline lint-staged version into staged debug bundle#1925
fix(cli): inline lint-staged version into staged debug bundle#1925rokuosan wants to merge 5 commits into
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
There was a problem hiding this comment.
Thanks, that matches the direction I had in mind.
One small alternative: how about replacing lint-staged/lib/version.js directly?
It could make the change a bit shorter, since the debug path calls getVersion() here:
https://github.com/lint-staged/lint-staged/blob/5f3b8f28e895972bd5a2cdba733327b49859b91f/lib/index.js#L106-L115
and getVersion() is isolated in lib/version.js:
https://github.com/lint-staged/lint-staged/blob/5f3b8f28e895972bd5a2cdba733327b49859b91f/lib/version.js#L3-L6
Not blocking though — the current approach also looks clear to me.
|
Also, could you please look into the CI failure? |
|
Thanks, that makes sense. I'll also investigate the CI failure. |
… hook Drop the resolveId + virtual-module indirection and replace lint-staged's lib/version.js directly in a single load hook. The ./version.js import is relative, so the bundler resolves it to the real file and the load hook short-circuits the read — no virtual id or importer matching needed.
Problem
vp staged --debugcrashes by readingvite-plus/dist/package.jsoninstead of lint-staged's package.json #1922vp staged --debugcrashes in the published package.When debug logging is enabled, bundled
lint-stagedcallsgetVersion()(lib/version.js), which reads its own manifest viareadFile(new URL('../package.json', import.meta.url)). The CLI bundleslint-staged intodist/staged/bin.js, so that relative../package.jsondoes not exist at runtime and the command throws instead of printing the debug log.This is exactly what the pinned
lint-staged@16.4.0does inlib/version.js:Source: https://github.com/lint-staged/lint-staged/blob/445f9dd042b88528c798b2e25c21c9adbc69a732/lib/version.js#L1-L6
Fix
Add a tsdown plugin (
inline-lint-staged-version) that rewrites the./version.jsimport coming fromlint-staged/lib/index.jsto a virtual moduleexposing the dependency version resolved at build time:
Keeps the
getVersionnamed-export shape identical, so no lint-staged internals change.Tests
command-staged-with-configglobal snap test with avp staged --debugstep that must succeed. A regression flips the recorded exit code (>→[1]>), failing the snapshot.Verified against a real build:
dist/staged/bin.jsnow contains the inlinedconst version = "16.4.0"and no longer referencesreadFile(new URL('../package.json', ...)).closes: #1922