Skip to content
Draft
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,3 +20,28 @@ steps = [
["vp", "pack"],
["vpt", "print-file", "dist/index.d.mts"],
]

[[case]]
name = "command_pack_dts_tsrs"
vp = "global"
local-registry = true
comment = "Without typescript, the packed CLI generates inferred declarations with the bundled tsrs. The experimental tsrs notice does not fail --fail-on-warn. pnpm hoist:false keeps undeclared compilers out of reach."
steps = [
{ argv = ["vpt", "json-edit", "package.json", "devDependencies", "{\"vite-plus\":\"latest\"}"], snapshot = false },
{ argv = ["vp", "install", "--ignore-scripts"], snapshot = false },
["vp", "pack", "--fail-on-warn"],
["vpt", "print-file", "dist/index.d.mts"],
]

[[case]]
name = "command_pack_dts_tsrs_hoisted"
vp = "global"
local-registry = true
comment = "With pnpm's default hoisting and no typescript, no transitive typescript reaches the declaration plugin, so the bundled tsrs generates the declarations."
steps = [
{ argv = ["vpt", "json-edit", "package.json", "devDependencies", "{\"vite-plus\":\"latest\"}"], snapshot = false },
{ argv = ["vpt", "write-file", "pnpm-workspace.yaml", "minimumReleaseAge: 0"], snapshot = false },
{ argv = ["vp", "install", "--ignore-scripts"], snapshot = false },
["vp", "pack"],
["vpt", "print-file", "dist/index.d.mts"],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# command_pack_dts_tsrs

Without typescript, the packed CLI generates inferred declarations with the bundled tsrs. The experimental tsrs notice does not fail --fail-on-warn. pnpm hoist:false keeps undeclared compilers out of reach.

## `vpt json-edit package.json devDependencies '{"vite-plus":"latest"}'`


## `vp install --ignore-scripts`


## `vp pack --fail-on-warn`

```
VITE+ - The Unified Toolchain for the Web

ℹ entry: src/index.ts
ℹ tsconfig: tsconfig.json
ℹ Generating declarations with bundled tsrs <version> (experimental) because `typescript` is not installed
ℹ Build start
ℹ Emit types with tsrs
ℹ dist/index.mjs <size> kB │ gzip: <size> kB
ℹ dist/index.d.mts <size> kB │ gzip: <size> kB
ℹ 2 files, total: <size> kB
✔ Build complete in <duration>
```

## `vpt print-file dist/index.d.mts`

```
export declare function greet(name: string): {
message: string;
length: number;
};
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# command_pack_dts_tsrs_hoisted

With pnpm's default hoisting and no typescript, no transitive typescript reaches the declaration plugin, so the bundled tsrs generates the declarations.

## `vpt json-edit package.json devDependencies '{"vite-plus":"latest"}'`


## `vpt write-file pnpm-workspace.yaml 'minimumReleaseAge: 0'`


## `vp install --ignore-scripts`


## `vp pack`

```
VITE+ - The Unified Toolchain for the Web

ℹ entry: src/index.ts
ℹ tsconfig: tsconfig.json
ℹ Generating declarations with bundled tsrs <version> (experimental) because `typescript` is not installed
ℹ Build start
ℹ Emit types with tsrs
ℹ dist/index.mjs <size> kB │ gzip: <size> kB
ℹ dist/index.d.mts <size> kB │ gzip: <size> kB
ℹ 2 files, total: <size> kB
✔ Build complete in <duration>
```

## `vpt print-file dist/index.d.mts`

```
export declare function greet(name: string): {
message: string;
length: number;
};
```
18 changes: 18 additions & 0 deletions docs/guide/pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ export default defineConfig({
});
```

## Declaration Files

With `dts` enabled, tsdown selects the declaration generator. It uses the project's `typescript`, or Oxc when the tsconfig enables `isolatedDeclarations`.

If `typescript` is not installed, `vp pack` generates declarations with the `tsrs` compiler that Vite+ ships for type-aware linting. This support is experimental. tsrs reads compiler options only from the tsconfig file, so `dts.compilerOptions` and `dts.tsconfigRaw` require `typescript`.

To use tsrs also when the project installs `typescript`, set the generator:

```ts [vite.config.ts]
import { defineConfig } from 'vite-plus';

export default defineConfig({
pack: {
dts: { generator: 'tsrs' },
},
});
```

## Standalone Executables

`vp pack` can also build standalone executables through tsdown's experimental [`exe` option](https://tsdown.dev/options/exe#executable).
Expand Down
Loading
Loading