Skip to content
Merged
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
44 changes: 37 additions & 7 deletions packages/cli/BUNDLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,14 +504,44 @@ const CORE_PACKAGE_NAME = '@voidzero-dev/vite-plus-core';
const TEST_PACKAGE_NAME = '@voidzero-dev/vite-plus-test';
```

### Package.json Auto-Update
### Package.json Exports Management

The build script automatically updates `package.json`:
The `exports` field in `package.json` has two categories: **manual** and **automated**.

1. Removes old `./test/*` exports
2. Adds new exports from test package
3. Ensures `dist/test` is in the `files` array
#### Manual exports

Core package exports (`./client`, `./module-runner`, `./internal`, `./dist/client/*`, `./types/*`) are defined statically in `package.json` and not auto-generated, since they match upstream Vite's exports structure.
All non-`./test*` exports are manually maintained in `package.json`. These fall into two groups:

This keeps the CLI package exports in sync with both upstream Vite and the test package without manual maintenance.
**CLI-native exports** — point to CLI's own compiled TypeScript (built by `buildCli()` via tsc):

| Export | Description |
| ---------------- | -------------------------- |
| `.` | Main entry (CLI utilities) |
| `./bin` | CLI binary entry point |
| `./binding` | NAPI native binding |
| `./lint` | Lint utilities |
| `./pack` | Pack utilities |
| `./package.json` | Package metadata |

**Core shim exports** — point to shim files auto-generated by `syncCorePackageExports()` that re-export from `@voidzero-dev/vite-plus-core`. The shim files are regenerated on each build, but the `package.json` entries themselves are manual:

| Export | Description |
| -------------------- | ----------------------------------------------------------------------- |
| `./client` | Triple-slash reference for ambient type declarations (CSS modules, etc) |
| `./module-runner` | Vite module runner for SSR/environments |
| `./internal` | Internal Vite APIs |
| `./dist/client/*` | Client runtime files |
| `./types/internal/*` | Blocked (`null`) to prevent access to internal types |
| `./types/*` | Type-only re-exports |

**Note**: The core package's own exports (which the shims point to) are generated upstream by `packages/tools/src/sync-remote-deps.ts`. See [Core Package Bundling](../core/BUNDLING.md) for details.

#### Automated exports (`./test/*`)

All `./test*` exports are fully managed by `syncTestPackageExports()`. The build script:

1. Reads `packages/test/package.json` exports
2. Creates shim files in `dist/test/`
3. Removes old `./test*` exports from `package.json`
4. Merges in newly generated test exports
5. Ensures `dist/test` is in the `files` array
2 changes: 1 addition & 1 deletion packages/cli/binding/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl SubcommandResolver {

let config_path = config_dir.join(temp_filename);
let content = format!(
"import {{ defineConfig }} from 'oxlint';\nimport viteConfig from './{config_basename}';\nexport default defineConfig(viteConfig.{field_name} as any);\n"
"import {{ defineConfig }} from 'vite-plus/lint';\nimport viteConfig from './{config_basename}';\nexport default defineConfig(viteConfig.{field_name} as any);\n"
);
write(&config_path, content).await?;

Expand Down
4 changes: 4 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
"import": "./binding/index.cjs",
"require": "./binding/index.cjs"
},
"./lint": {
"types": "./dist/lint.d.ts",
"import": "./dist/lint.js"
},
"./package.json": "./package.json",
"./pack": {
"types": "./dist/pack.d.ts",
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/snap-tests-global/cli-helper-message/snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ VITE+ - The Unified Toolchain for the Web
vp v<semver>

Local vite-plus:
vite-plus Not found
vite-plus v<semver>

Tools:
vite Not found
rolldown Not found
vitest Not found
oxfmt Not found
oxlint Not found
oxlint-tsgolint Not found
tsdown Not found
vite v<semver>
rolldown v<semver>
vitest v<semver>
oxfmt v<semver>
oxlint v<semver>
oxlint-tsgolint v<semver>
tsdown v<semver>

> vp install -h # show install help message
VITE+ - The Unified Toolchain for the Web
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ VITE+ - The Unified Toolchain for the Web
vp v<semver>

Local vite-plus:
vite-plus Not found
vite-plus v<semver>

Tools:
vite Not found
rolldown Not found
vitest Not found
oxfmt Not found
oxlint Not found
oxlint-tsgolint Not found
tsdown Not found
vite v<semver>
rolldown v<semver>
vitest v<semver>
oxfmt v<semver>
oxlint v<semver>
oxlint-tsgolint v<semver>
tsdown v<semver>

> test -f .node-version && echo 'FAIL: .node-version was created' || echo 'OK: no .node-version created'
OK: no .node-version created
13 changes: 13 additions & 0 deletions packages/cli/src/lint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export {
type AllowWarnDeny,
type DummyRule,
type DummyRuleMap,
type ExternalPluginEntry,
type ExternalPluginsConfig,
type OxlintConfig,
type OxlintEnv,
type OxlintGlobals,
type OxlintOverride,
type RuleCategories,
defineConfig,
} from 'oxlint';
20 changes: 17 additions & 3 deletions packages/tools/src/snap-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,24 @@ export async function snapTest() {
}
}

// Make dependencies available in the test cases
// Make dependencies available in the test cases.
// Create a real node_modules directory so we can add the CLI package itself
// alongside the symlinked dependencies (needed for `vite-plus/*` imports in
// generated config files like .vite-plus-lint.tmp.mts).
const tempNodeModules = path.join(tempTmpDir, 'node_modules');
fs.mkdirSync(tempNodeModules);
const cliNodeModules = path.resolve('node_modules');
for (const entry of fs.readdirSync(cliNodeModules)) {
fs.symlinkSync(
path.join(cliNodeModules, entry),
path.join(tempNodeModules, entry),
process.platform === 'win32' ? 'junction' : 'dir',
);
}
// Add the CLI package itself so `vite-plus/*` subpath imports resolve
fs.symlinkSync(
path.resolve('node_modules'),
path.join(tempTmpDir, 'node_modules'),
path.resolve('.'),
path.join(tempNodeModules, 'vite-plus'),
process.platform === 'win32' ? 'junction' : 'dir',
);

Expand Down
Loading