Skip to content

Commit a4a537f

Browse files
committed
fix(pack): bundle @tsdown/exe and @tsdown/css into core
@tsdown/exe and @tsdown/css hard-peer-depend on tsdown and import tsdown/internal, but Vite+ bundles tsdown internally with no resolvable top-level tsdown package, so installing them failed with "Failed to import module @tsdown/exe". Bundle both into core (tsdown-exe.js, tsdown-css.js) so they resolve tsdown/internal at build time and work without any extra install. lightningcss (native) stays external as an optional peer, loaded lazily with an actionable error when it is missing. Closes #1586
1 parent c1cadc3 commit a4a537f

15 files changed

Lines changed: 311 additions & 36 deletions

File tree

docs/guide/pack.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,20 @@ export default defineConfig({
5858
});
5959
```
6060

61+
Executable support is bundled into Vite+, so you do not need to install `@tsdown/exe` separately.
62+
63+
Building executables uses Node's [Single Executable Applications](https://nodejs.org/api/single-executable-applications.html) support and requires Node.js 25.7.0 or later. Switch the active runtime with `vp env use 25` if `vp pack --exe` reports an unsupported version.
64+
6165
See the official [tsdown executable docs](https://tsdown.dev/options/exe#executable) for details about configuring custom file names, embedded assets, and cross-platform targets.
66+
67+
## CSS Bundling
68+
69+
`vp pack` can transform and bundle CSS (including CSS Modules and Lightning CSS optimizations) for your entry points. This support is bundled into Vite+, so you do not need to install `@tsdown/css`.
70+
71+
CSS transforms are powered by [Lightning CSS](https://lightningcss.dev/), which ships as a native module and is an optional peer dependency. Install it when you bundle CSS:
72+
73+
```bash
74+
vp add -D lightningcss
75+
```
76+
77+
If it is missing, `vp pack` prints an actionable error telling you to install it.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "command-pack-css",
3+
"version": "1.0.0",
4+
"type": "module"
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
> vp pack src/index.ts --minify # bundles CSS via the bundled @tsdown/css + lightningcss (issue #1586)
2+
ℹ entry: src/index.ts
3+
ℹ Build start
4+
ℹ dist/index.mjs <variable> kB │ gzip: <variable> kB
5+
ℹ dist/style.css <variable> kB │ gzip: <variable> kB
6+
ℹ 2 files, total: <variable> kB
7+
✔ Build complete in <variable>ms
8+
9+
> cat dist/style.css # lightningcss-optimized output proves @tsdown/css ran
10+
.foo {
11+
color: red;
12+
}
13+
14+
.bar {
15+
margin: 0;
16+
}
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.foo {
2+
color: #ff0000;
3+
}
4+
5+
.bar {
6+
margin: 0px 0px 0px 0px;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ignoredPlatforms": ["win32"],
3+
"commands": [
4+
"vp pack src/index.ts --minify # bundles CSS via the bundled @tsdown/css + lightningcss (issue #1586)",
5+
"cat dist/style.css # lightningcss-optimized output proves @tsdown/css ran"
6+
]
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "command-pack-tsdown-extensions",
3+
"version": "1.0.0",
4+
"type": "module"
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> node verify-extensions.mjs # bundled @tsdown/exe and @tsdown/css load without a top-level tsdown (issue #1586)
2+
tsdown-exe.js: getCacheDir, getCachedBinaryPath, getTargetSuffix, resolveNodeBinary
3+
tsdown-css.js: CssPlugin, resolveCssOptions
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 verify-extensions.mjs # bundled @tsdown/exe and @tsdown/css load without a top-level tsdown (issue #1586)"
5+
]
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Issue #1586: `@tsdown/exe` and `@tsdown/css` have a hard peer dependency on
2+
// `tsdown` and import `tsdown/internal`, but Vite+ bundles tsdown internally and
3+
// does not expose a resolvable top-level `tsdown` package. Before the fix, the
4+
// bundled tsdown loaded them as external top-level packages, so `vp pack --exe`
5+
// (and CSS bundling) failed with `Failed to import module "@tsdown/exe"`.
6+
//
7+
// They are now bundled into core, so this loads the bundled extension chunks
8+
// directly to prove they resolve `tsdown/internal` against the bundled tsdown.
9+
// `vp pack --exe` itself needs Node >= 25.7 (SEA), so it cannot run end-to-end
10+
// in CI; this check is Node-version independent.
11+
import { createRequire } from 'node:module';
12+
import path from 'node:path';
13+
import { pathToFileURL } from 'node:url';
14+
15+
const require = createRequire(import.meta.url);
16+
const packEntry = require.resolve('@voidzero-dev/vite-plus-core/pack');
17+
const tsdownDir = path.dirname(packEntry);
18+
19+
for (const chunk of ['tsdown-exe.js', 'tsdown-css.js']) {
20+
const mod = await import(pathToFileURL(path.join(tsdownDir, chunk)).href);
21+
console.log(`${chunk}: ${Object.keys(mod).sort().join(', ')}`);
22+
}

0 commit comments

Comments
 (0)