Skip to content

Commit 1b6a5cf

Browse files
committed
test(pack): cover the missing lightningcss optional peer error
Add the command-pack-css-missing-lightningcss snap test: a resolve hook makes lightningcss unresolvable (the dev/CI monorepo always has it), so vp pack surfaces the actionable install hint. Locks in that the error tells users how to fix it.
1 parent a4a537f commit 1b6a5cf

8 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Simulate `lightningcss` not being installed: the dev/CI monorepo always has it
2+
// resolvable from core (it is a transitive dependency), so a resolve hook is the
3+
// deterministic way to exercise the missing optional-peer path. See issue #1586.
4+
export async function resolve(specifier, context, nextResolve) {
5+
if (specifier === 'lightningcss') {
6+
const error = new Error("Cannot find package 'lightningcss'");
7+
error.code = 'ERR_MODULE_NOT_FOUND';
8+
throw error;
9+
}
10+
return nextResolve(specifier, context);
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "command-pack-css-missing-lightningcss",
3+
"version": "1.0.0",
4+
"type": "module"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { register } from 'node:module';
2+
3+
// Loaded via `NODE_OPTIONS=--import=./register-block.mjs` so the resolve hook
4+
// applies to the `vp pack` process (and its managed-Node child).
5+
register('./block-lightningcss.mjs', import.meta.url);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[1]> NODE_OPTIONS=--import=./register-block.mjs vp pack src/index.ts --minify # missing optional lightningcss peer prints an actionable install hint (issue #1586)
2+
ℹ entry: src/index.ts
3+
ℹ Build start
4+
error: Build failed with 1 error:
5+
6+
[plugin @tsdown/css] <cwd>/src/style.css
7+
Error: Cannot find package "lightningcss". CSS bundling with `vp pack` requires it. Install it with `vp add -D lightningcss`.
8+
Caused by:
9+
Error: Cannot find package 'lightningcss'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import './style.css';
2+
3+
export const hello = 'world';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: #ff0000;
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ignoredPlatforms": ["win32"],
3+
"commands": [
4+
"NODE_OPTIONS=--import=./register-block.mjs vp pack src/index.ts --minify # missing optional lightningcss peer prints an actionable install hint (issue #1586)"
5+
]
6+
}

rfcs/pack-command.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ Tests `vp pack src/index.ts --minify` on a CSS entry: the bundled `@tsdown/css`
389389
390390
Loads the bundled `dist/tsdown/tsdown-exe.js` and `dist/tsdown/tsdown-css.js` chunks to prove they resolve `tsdown/internal` against the bundled tsdown without a top-level `tsdown` package. This is Node-version independent (it does not run the SEA build), so it catches the import-resolution regression on every CI Node version.
391391
392+
### Local CLI Test: `command-pack-css-missing-lightningcss`
393+
394+
**Location**: `packages/cli/snap-tests/command-pack-css-missing-lightningcss/`
395+
396+
Runs `vp pack --minify` with a resolve hook (`NODE_OPTIONS=--import`) that makes `lightningcss` unresolvable, simulating the uninstalled optional peer (the dev/CI monorepo always has it). Asserts the actionable error tells the user how to fix it:
397+
398+
```
399+
Cannot find package "lightningcss". CSS bundling with `vp pack` requires it. Install it with `vp add -D lightningcss`.
400+
```
401+
392402
### Global CLI Test: `command-pack-exe`
393403
394404
**Location**: `packages/cli/snap-tests-global/command-pack-exe/`

0 commit comments

Comments
 (0)