Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
[COMPLETED] Cleaning up temporary files...

> git add -A && git commit -m 'second'
> echo 'export const bar = 2;' >> src/index.ts && git add src/index.ts
> vp staged --debug # should succeed with debug enabled
> git add -A && git commit -m 'third'
> printf 'eval("code");\n' > src/fail.js && git add src/fail.js
[1]> vp staged > /dev/null 2>&1 # should fail when staged .js file has lint errors
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
},
"vp staged # should succeed with staged .ts files",
{ "command": "git add -A && git commit -m 'second'", "ignoreOutput": true },
{
"command": "echo 'export const bar = 2;' >> src/index.ts && git add src/index.ts",
"ignoreOutput": true
},
{
"command": "vp staged --debug # should succeed with debug enabled",
"ignoreOutput": true
},
{ "command": "git add -A && git commit -m 'third'", "ignoreOutput": true },
{
"command": "printf 'eval(\"code\");\\n' > src/fail.js && git add src/fail.js",
"ignoreOutput": true
Expand Down
23 changes: 22 additions & 1 deletion packages/cli/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { createRequire } from 'node:module';

import { defineConfig } from 'tsdown';

const require = createRequire(import.meta.url);
const lintStagedPackageJson = require('lint-staged/package.json') as { version: string };

/**
* Rewrite `../versions.js` → `./versions.js` at resolve time.
*
Expand All @@ -18,6 +23,22 @@ const fixVersionsPathPlugin = {
},
};

/**
* Replace lint-staged's lib/version.js with a build-time version value.
*
* The original module reads ../package.json at runtime when debug logging is enabled,
* but that file does not exist in the bundled dist/staged/bin.js.
*/
const inlineLintStagedVersionPlugin = {
name: 'inline-lint-staged-version',
load(id: string) {
if (id.replaceAll('\\', '/').endsWith('/lint-staged/lib/version.js')) {
return `export const getVersion = async () => ${JSON.stringify(lintStagedPackageJson.version)};\n`;
}
return undefined;
},
};

export default defineConfig([
// ESM — all entry points bundled to dist/
{
Expand Down Expand Up @@ -56,7 +77,7 @@ export default defineConfig([
mainFields: ['module', 'main'],
},
},
plugins: [fixVersionsPathPlugin],
plugins: [fixVersionsPathPlugin, inlineLintStagedVersionPlugin],
},

// CJS — dual-format entries
Expand Down