diff --git a/packages/cli/BUNDLING.md b/packages/cli/BUNDLING.md index 1ec7ff718e..746728dbda 100644 --- a/packages/cli/BUNDLING.md +++ b/packages/cli/BUNDLING.md @@ -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 diff --git a/packages/cli/binding/src/cli.rs b/packages/cli/binding/src/cli.rs index 6cecc92644..06dc21f934 100644 --- a/packages/cli/binding/src/cli.rs +++ b/packages/cli/binding/src/cli.rs @@ -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?; diff --git a/packages/cli/package.json b/packages/cli/package.json index d8196408c1..338af24071 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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", diff --git a/packages/cli/snap-tests-global/cli-helper-message/snap.txt b/packages/cli/snap-tests-global/cli-helper-message/snap.txt index 9d29913801..eefe1b4d55 100644 --- a/packages/cli/snap-tests-global/cli-helper-message/snap.txt +++ b/packages/cli/snap-tests-global/cli-helper-message/snap.txt @@ -55,16 +55,16 @@ VITE+ - The Unified Toolchain for the Web vp v Local vite-plus: - vite-plus Not found + vite-plus v 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 + rolldown v + vitest v + oxfmt v + oxlint v + oxlint-tsgolint v + tsdown v > vp install -h # show install help message VITE+ - The Unified Toolchain for the Web diff --git a/packages/cli/snap-tests-global/command-version-no-side-effects/snap.txt b/packages/cli/snap-tests-global/command-version-no-side-effects/snap.txt index c23315020a..20c1f0fd4d 100644 --- a/packages/cli/snap-tests-global/command-version-no-side-effects/snap.txt +++ b/packages/cli/snap-tests-global/command-version-no-side-effects/snap.txt @@ -4,16 +4,16 @@ VITE+ - The Unified Toolchain for the Web vp v Local vite-plus: - vite-plus Not found + vite-plus v 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 + rolldown v + vitest v + oxfmt v + oxlint v + oxlint-tsgolint v + tsdown v > test -f .node-version && echo 'FAIL: .node-version was created' || echo 'OK: no .node-version created' OK: no .node-version created diff --git a/packages/cli/src/lint.ts b/packages/cli/src/lint.ts new file mode 100644 index 0000000000..25f7703d56 --- /dev/null +++ b/packages/cli/src/lint.ts @@ -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'; diff --git a/packages/tools/src/snap-test.ts b/packages/tools/src/snap-test.ts index 656db6610d..c54b4ff699 100755 --- a/packages/tools/src/snap-test.ts +++ b/packages/tools/src/snap-test.ts @@ -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', );