From 608ebdf4a6b53474e2e1e7d240628b5b6dc5a82b Mon Sep 17 00:00:00 2001 From: MK Date: Tue, 20 Oct 2026 20:11:47 +0800 Subject: [PATCH 1/3] feat(cli): support upstream Vite overrides in ecosystem CI --- .../core_command_root_dispatch.global.md | 8 +- .../core_command_root_dispatch.local.md | 8 +- .../core_module_identity/check-api.mjs | 2 +- .../core_module_identity/check-bundled.mjs | 2 +- .../check-tagged-alias.mjs | 23 +-- .../core_module_identity/snapshots.toml | 4 +- ...dule_identity_npm_tagged_alias_rejected.md | 2 +- ...core_module_identity_repackaged_version.md | 8 +- .../core_module_identity/stamp-version.mjs | 20 +++ .../fixtures/core_resolution_errors/index.ts | 1 + .../core_resolution_errors/snapshots.toml | 4 +- .../snapshots/core_resolution_stale_core.md | 10 +- .../core_resolution_upstream_vite.md | 10 +- .../upstream_vite_override/check-api.mjs | 23 +++ .../check-core-guard.mjs | 29 ++++ .../fixtures/upstream_vite_override/entry.ts | 1 + .../upstream_vite_override/index.html | 2 + .../upstream_vite_override/override.test.ts | 17 ++ .../upstream_vite_override/package.json | 13 ++ .../pnpm-workspace.yaml | 3 + .../upstream_vite_override/snapshots.toml | 55 +++++++ .../upstream_vite_override.global.md | 147 ++++++++++++++++++ .../snapshots/upstream_vite_override.local.md | 135 ++++++++++++++++ .../upstream_vite_override/tsconfig.json | 5 + .../upstream_vite_override/use-local-vite.mjs | 40 +++++ .../upstream_vite_override/vite.config.ts | 51 ++++++ docs/guide/ci.md | 44 ++++++ packages/cli/BUNDLING.md | 31 ++-- packages/cli/build.ts | 2 +- packages/cli/package.json | 1 + .../cli/src/__tests__/exports-map.spec.ts | 1 + .../cli/src/__tests__/resolve-core.spec.ts | 127 ++++++++++++--- .../cli/src/__tests__/resolve-vite.spec.ts | 29 +++- packages/cli/src/migration/migrator/tsup.ts | 2 +- packages/cli/src/pack-bin.ts | 4 +- packages/cli/src/pack.ts | 4 +- packages/cli/src/resolve-core.ts | 58 +++++-- packages/cli/src/resolve-pack.ts | 11 +- packages/cli/src/resolve-vite-config.ts | 2 +- packages/cli/src/resolve-vite.ts | 37 +++-- pnpm-lock.yaml | 3 + 41 files changed, 863 insertions(+), 116 deletions(-) create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/stamp-version.mjs create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/index.ts create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-api.mjs create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-core-guard.mjs create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/entry.ts create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/index.html create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/override.test.ts create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/package.json create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/pnpm-workspace.yaml create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots.toml create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots/upstream_vite_override.global.md create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots/upstream_vite_override.local.md create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/tsconfig.json create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/use-local-vite.mjs create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/vite.config.ts diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.global.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.global.md index 3661ad7796..a5f4ff6a4b 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.global.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.global.md @@ -137,10 +137,12 @@ error: Failed to resolve vite command: GenericFailure, Expected @voidzero-dev/vi ## `vp -C . pack packages/app/src/index.ts` -**Exit code:** 1 - ``` VITE+ - The Unified Toolchain for the Web -error: Failed to resolve pack command: GenericFailure, Expected @voidzero-dev/vite-plus-core@, but found vite@8.2.2 at /node_modules/.pnpm/vite@8.2.2/node_modules/vite/package.json. Run `vp migrate` to align the Vite alias, then run `vp install`. +ℹ entry: packages/app/src/index.ts +ℹ Build start +ℹ dist/index.mjs kB │ gzip: kB +ℹ 1 files, total: kB +✔ Build complete in ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.local.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.local.md index 7ec2ac9b22..8d8ca9766e 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.local.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_command_root/snapshots/core_command_root_dispatch.local.md @@ -119,8 +119,10 @@ error: Failed to resolve vite command: GenericFailure, Expected @voidzero-dev/vi ## `vp -C . pack packages/app/src/index.ts` -**Exit code:** 1 - ``` -error: Failed to resolve pack command: GenericFailure, Expected @voidzero-dev/vite-plus-core@, but found vite@8.2.2 at /node_modules/.pnpm/vite@8.2.2/node_modules/vite/package.json. Run `vp migrate` to align the Vite alias, then run `vp install`. +ℹ entry: packages/app/src/index.ts +ℹ Build start +ℹ dist/index.mjs kB │ gzip: kB +ℹ 1 files, total: kB +✔ Build complete in ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-api.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-api.mjs index 573b1212d6..d4fb8b2eb8 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-api.mjs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-api.mjs @@ -25,5 +25,5 @@ assert.equal(ModuleRunner, VpModuleRunner); const config = {}; assert.equal(vite.defineConfig(config), config); assert.equal(pkg.dependencies.vite, `npm:@voidzero-dev/vite-plus-core@${pkg.version}`); -assert.equal(pkg.dependencies['@voidzero-dev/vite-plus-core'], undefined); +assert.equal(pkg.dependencies['@voidzero-dev/vite-plus-core'], pkg.version); console.log('Packed alias, ESM, CommonJS, and module-runner identity passed'); diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-bundled.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-bundled.mjs index 119a23c051..c15bfcf451 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-bundled.mjs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-bundled.mjs @@ -7,6 +7,6 @@ import { build } from 'vite-plus/pack'; const require = createRequire(import.meta.url); const cliRequire = createRequire(require.resolve('vite-plus/package.json')); assert.equal(createServer, cliRequire('vite').createServer); -assert.equal(build, cliRequire('vite/pack').build); +assert.equal(build, cliRequire('@voidzero-dev/vite-plus-core/pack').build); assert.equal(require('./package.json').devDependencies.vite, undefined); console.log('Bundled APIs resolve without a project Vite dependency'); diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-tagged-alias.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-tagged-alias.mjs index 40e971754c..9ee36f9532 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-tagged-alias.mjs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/check-tagged-alias.mjs @@ -12,13 +12,16 @@ assert.equal(require('vite/package.json').name, 'vite'); assert.equal(cliRequire('vite/package.json').name, '@voidzero-dev/vite-plus-core'); assert.notEqual(require.resolve('vite/package.json'), cliRequire.resolve('vite/package.json')); -for (const args of [['dev'], ['pack', 'entry.js']]) { - const result = spawnSync('vp', args, { encoding: 'utf8', timeout: 30_000 }); - assert.ifError(result.error); - const output = result.stdout + result.stderr; - assert.equal(result.status, 1, output); - assert.match(output, /Expected @voidzero-dev\/vite-plus-core@/); - assert.match(output, /but found vite@/); - assert.match(output, /Run `vp migrate` to align the Vite alias, then run `vp install`\./); - console.log(`vp ${args[0]} rejects the replaced npm alias and reports the repair command`); -} +const dev = spawnSync('vp', ['dev'], { encoding: 'utf8', timeout: 30_000 }); +assert.ifError(dev.error); +const output = dev.stdout + dev.stderr; +assert.equal(dev.status, 1, output); +assert.match(output, /Expected @voidzero-dev\/vite-plus-core@/); +assert.match(output, /but found vite@/); +assert.match(output, /Run `vp migrate` to align the Vite alias, then run `vp install`\./); +console.log('vp dev rejects the replaced npm alias and reports the repair command'); + +const pack = spawnSync('vp', ['pack', 'entry.js'], { encoding: 'utf8', timeout: 30_000 }); +assert.ifError(pack.error); +assert.equal(pack.status, 0, pack.stdout + pack.stderr); +console.log('vp pack uses its internal core despite the replaced npm alias'); diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots.toml index d0be4f3f72..5422adfbb5 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots.toml @@ -15,9 +15,7 @@ local-registry = true comment = "CI can stamp the package version after building the CLI. The resolver must compare installed manifests rather than an inlined build-time version." steps = [ { argv = ["vp", "install", "--ignore-scripts"], snapshot = false }, - { argv = ["vpt", "json-edit", "node_modules/vite-plus/package.json", "version", "0.0.0"], snapshot = false }, - { argv = ["vpt", "json-edit", "node_modules/vite-plus/package.json", "dependencies.vite", "npm:@voidzero-dev/vite-plus-core@0.0.0"], snapshot = false }, - { argv = ["vpt", "json-edit", "node_modules/vite/package.json", "version", "0.0.0"], snapshot = false }, + { argv = ["node", "stamp-version.mjs"], snapshot = false }, ["node", "check-api.mjs"], ["vp", "dev"], ["vp", "build"], diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_npm_tagged_alias_rejected.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_npm_tagged_alias_rejected.md index 8f3b5c664c..2230001883 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_npm_tagged_alias_rejected.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_npm_tagged_alias_rejected.md @@ -11,5 +11,5 @@ ``` vp dev rejects the replaced npm alias and reports the repair command -vp pack rejects the replaced npm alias and reports the repair command +vp pack uses its internal core despite the replaced npm alias ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_repackaged_version.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_repackaged_version.md index 214d0ec8a8..d3863906d7 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_repackaged_version.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/snapshots/core_module_identity_repackaged_version.md @@ -5,13 +5,7 @@ CI can stamp the package version after building the CLI. The resolver must compa ## `vp install --ignore-scripts` -## `vpt json-edit node_modules/vite-plus/package.json version 0.0.0` - - -## `vpt json-edit node_modules/vite-plus/package.json dependencies.vite npm:@voidzero-dev/vite-plus-core@0.0.0` - - -## `vpt json-edit node_modules/vite/package.json version 0.0.0` +## `node stamp-version.mjs` ## `node check-api.mjs` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/stamp-version.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/stamp-version.mjs new file mode 100644 index 0000000000..c4680319ea --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_module_identity/stamp-version.mjs @@ -0,0 +1,20 @@ +import { readFileSync, writeFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; + +const require = createRequire(import.meta.url); +const cliManifest = require.resolve('vite-plus/package.json'); +const cliRequire = createRequire(cliManifest); +for (const manifest of new Set([ + cliManifest, + require.resolve('vite/package.json'), + cliRequire.resolve('vite/package.json'), + cliRequire.resolve('@voidzero-dev/vite-plus-core/package.json'), +])) { + const pkg = JSON.parse(readFileSync(manifest, 'utf8')); + pkg.version = '0.0.0'; + if (pkg.name === 'vite-plus') { + pkg.dependencies.vite = 'npm:@voidzero-dev/vite-plus-core@0.0.0'; + pkg.dependencies['@voidzero-dev/vite-plus-core'] = '0.0.0'; + } + writeFileSync(manifest, JSON.stringify(pkg)); +} diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/index.ts b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/index.ts new file mode 100644 index 0000000000..46d3ca8c61 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/index.ts @@ -0,0 +1 @@ +export const value = 42; diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots.toml index 09f24b2b7e..f59accfcaa 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots.toml @@ -4,7 +4,7 @@ vp = "local" steps = [ { argv = ["vpt", "write-file", "node_modules/vite/package.json", "{\"name\":\"vite\",\"version\":\"8.2.2\"}\n"], snapshot = false }, { argv = ["vp", "dev"], continue-on-failure = true }, - ["vp", "pack", "index.ts"], + ["vp", "pack", "--no-config", "index.ts"], ] [[case]] @@ -13,5 +13,5 @@ vp = "local" steps = [ { argv = ["vpt", "write-file", "node_modules/vite/package.json", "{\"name\":\"@voidzero-dev/vite-plus-core\",\"version\":\"0.0.0-stale\"}\n"], snapshot = false }, { argv = ["vp", "dev"], continue-on-failure = true }, - ["vp", "pack", "index.ts"], + ["vp", "pack", "--no-config", "index.ts"], ] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_stale_core.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_stale_core.md index 80cf509b19..dc85995c0b 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_stale_core.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_stale_core.md @@ -12,10 +12,12 @@ error: Failed to resolve vite command: GenericFailure, Expected @voidzero-dev/vite-plus-core@, but found @voidzero-dev/vite-plus-core@ at /node_modules/vite/package.json. Run `vp migrate` to align the Vite alias, then run `vp install`. ``` -## `vp pack index.ts` - -**Exit code:** 1 +## `vp pack --no-config index.ts` ``` -error: Failed to resolve pack command: GenericFailure, Expected @voidzero-dev/vite-plus-core@, but found @voidzero-dev/vite-plus-core@ at /node_modules/vite/package.json. Run `vp migrate` to align the Vite alias, then run `vp install`. +ℹ entry: index.ts +ℹ Build start +ℹ dist/index.mjs kB │ gzip: kB +ℹ 1 files, total: kB +✔ Build complete in ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_upstream_vite.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_upstream_vite.md index 57f4377cc1..250f464a7d 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_upstream_vite.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/core_resolution_errors/snapshots/core_resolution_upstream_vite.md @@ -12,10 +12,12 @@ error: Failed to resolve vite command: GenericFailure, Expected @voidzero-dev/vite-plus-core@, but found vite@8.2.2 at /node_modules/vite/package.json. Run `vp migrate` to align the Vite alias, then run `vp install`. ``` -## `vp pack index.ts` - -**Exit code:** 1 +## `vp pack --no-config index.ts` ``` -error: Failed to resolve pack command: GenericFailure, Expected @voidzero-dev/vite-plus-core@, but found vite@8.2.2 at /node_modules/vite/package.json. Run `vp migrate` to align the Vite alias, then run `vp install`. +ℹ entry: index.ts +ℹ Build start +ℹ dist/index.mjs kB │ gzip: kB +ℹ 1 files, total: kB +✔ Build complete in ``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-api.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-api.mjs new file mode 100644 index 0000000000..a7eb099de3 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-api.mjs @@ -0,0 +1,23 @@ +import assert from 'node:assert/strict'; +import { createRequire } from 'node:module'; +import * as vite from 'vite'; +import * as vp from 'vite-plus'; +import { build as pack } from 'vite-plus/pack'; + +const require = createRequire(import.meta.url); +const cliRequire = createRequire(require.resolve('vite-plus/package.json')); +const vitestRequire = createRequire(cliRequire.resolve('vitest/package.json')); +const core = cliRequire('@voidzero-dev/vite-plus-core/package.json'); +assert.equal(core.version, cliRequire('vite-plus/package.json').version); +assert.equal(pack, cliRequire('@voidzero-dev/vite-plus-core/pack').build); +assert.equal(vite.version, '8.3.4'); +for (const name of ['createServer', 'build', 'resolveConfig', 'DevEnvironment']) { + assert.equal(vite[name], vp[name], name); + assert.equal(require('vite-plus')[name], vite[name], name); +} +assert.equal(cliRequire.resolve('vite'), require.resolve('vite')); +assert.equal(vitestRequire.resolve('vite'), require.resolve('vite')); +if (process.env.LOCAL_VITE === '1') { + assert.equal(vp.ecosystemCiMarker, 'local-vite'); +} +console.log('API exports and bundled Vitest use upstream Vite; pack uses the matching internal core'); diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-core-guard.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-core-guard.mjs new file mode 100644 index 0000000000..7d23a9a198 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/check-core-guard.mjs @@ -0,0 +1,29 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import { readFileSync, writeFileSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { dirname, join } from 'node:path'; + +const require = createRequire(import.meta.url); +const cliRequire = createRequire(require.resolve('vite-plus/package.json')); +const manifest = cliRequire.resolve('@voidzero-dev/vite-plus-core/package.json'); +const original = readFileSync(manifest, 'utf8'); +try { + writeFileSync(manifest, JSON.stringify({ ...JSON.parse(original), version: '0.0.0-stale' })); + for (const command of ['pack', 'build']) { + const local = process.argv[2] === 'local'; + const args = local + ? [join(dirname(require.resolve('vite-plus/package.json')), 'bin/vp'), command] + : [command]; + const result = spawnSync(local ? process.execPath : 'vp', args, { + encoding: 'utf8', + timeout: 30_000, + }); + assert.ifError(result.error); + assert.equal(result.status, 1, result.stdout + result.stderr); + assert.match(result.stdout + result.stderr, /found @voidzero-dev\/vite-plus-core@0.0.0-stale/); + } + console.log('Pack and Vite commands still reject a mismatched internal core'); +} finally { + writeFileSync(manifest, original); +} diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/entry.ts b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/entry.ts new file mode 100644 index 0000000000..74bffb3ffa --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/entry.ts @@ -0,0 +1 @@ +export const message: string = 'Packed with the internal core'; diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/index.html b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/index.html new file mode 100644 index 0000000000..ca3177ab0d --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/index.html @@ -0,0 +1,2 @@ +

Upstream Vite

+ diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/override.test.ts b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/override.test.ts new file mode 100644 index 0000000000..9231c4e6f9 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/override.test.ts @@ -0,0 +1,17 @@ +import { expect, test } from 'vite-plus/test'; +import * as vite from 'vite'; +import * as vp from 'vite-plus'; + +test('uses the replacement Vite through public API exports', async () => { + expect(vp.version).toBe('8.3.4'); + expect(vp.createServer).toBe(vite.createServer); + if (process.env.LOCAL_VITE === '1') { + expect(vp.ecosystemCiMarker).toBe('local-vite'); + } + const server = await vp.createServer({ configFile: false, server: { middlewareMode: true } }); + try { + expect(vite.isRunnableDevEnvironment(server.environments.ssr)).toBe(true); + } finally { + await server.close(); + } +}); diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/package.json b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/package.json new file mode 100644 index 0000000000..433633326a --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/package.json @@ -0,0 +1,13 @@ +{ + "name": "upstream-vite-override", + "private": true, + "type": "module", + "packageManager": "pnpm@11.24.0", + "devDependencies": { + "vite": "8.3.4", + "vite-plus": "latest" + }, + "scripts": { + "postinstall": "vp pack" + } +} diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/pnpm-workspace.yaml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/pnpm-workspace.yaml new file mode 100644 index 0000000000..109d7f196e --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/pnpm-workspace.yaml @@ -0,0 +1,3 @@ +minimumReleaseAge: 0 +overrides: + vite: 8.3.4 diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots.toml new file mode 100644 index 0000000000..3efdc4b09f --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots.toml @@ -0,0 +1,55 @@ +[[case]] +name = "upstream_vite_override" +vp = ["global"] +# Use pinned upstream Vite through the runner's registry to exercise its real +# CLI, API exports, and Vitest peer layout instead of a mock Vite package. +local-registry = true +comment = "A global Vite override replaces CLI/API/Vitest Vite, while postinstall pack keeps its matching internal core. Repeat with a local file dependency and a different public CLI entry." +env = { VP_USE_PROJECT_VITE = "1" } +steps = [ + { argv = ["vp", "install"], snapshot = false }, + ["node", "check-api.mjs"], + ["vpt", "stat-file", "packed/entry.mjs", "--assert", "file"], + ["vpt", "stat-file", "packed/entry.d.mts", "--assert", "file"], + ["vp", "build"], + ["vp", "dev"], + ["vp", "preview"], + ["vp", "test", "run"], + { argv = ["node", "use-local-vite.mjs"], snapshot = false }, + { argv = ["vp", "install"], envs = [["EXPECT_INTERNAL_CONFIG", "1"]], snapshot = false }, + { argv = ["node", "check-api.mjs"], envs = [["LOCAL_VITE", "1"]] }, + ["vp", "build"], + ["vp", "dev"], + ["vp", "preview"], + { argv = ["vp", "test", "run"], envs = [["LOCAL_VITE", "1"]] }, + ["node", "check-core-guard.mjs"], +] + +# The registry installation owns the runtime dependencies. Invoke its public +# local bin instead of the runner's bootstrap CLI, which has separate Vitest peers. +[[case]] +name = "upstream_vite_override" +vp = ["local"] +# Use pinned upstream Vite through the runner's registry to exercise its real +# CLI, API exports, and Vitest peer layout instead of a mock Vite package. +local-registry = true +comment = "A global Vite override replaces CLI/API/Vitest Vite, while postinstall pack keeps its matching internal core. Repeat with a local file dependency and a different public CLI entry." +env = { VP_USE_PROJECT_VITE = "1" } +steps = [ + { argv = ["vp", "install"], snapshot = false }, + ["node", "check-api.mjs"], + ["vpt", "stat-file", "packed/entry.mjs", "--assert", "file"], + ["vpt", "stat-file", "packed/entry.d.mts", "--assert", "file"], + ["node", "node_modules/vite-plus/bin/vp", "build"], + ["node", "node_modules/vite-plus/bin/vp", "dev"], + ["node", "node_modules/vite-plus/bin/vp", "preview"], + ["node", "node_modules/vite-plus/bin/vp", "test", "run"], + { argv = ["node", "use-local-vite.mjs"], snapshot = false }, + { argv = ["node", "node_modules/vite-plus/bin/vp", "install"], envs = [["EXPECT_INTERNAL_CONFIG", "1"]], snapshot = false }, + { argv = ["node", "check-api.mjs"], envs = [["LOCAL_VITE", "1"]] }, + ["node", "node_modules/vite-plus/bin/vp", "build"], + ["node", "node_modules/vite-plus/bin/vp", "dev"], + ["node", "node_modules/vite-plus/bin/vp", "preview"], + { argv = ["node", "node_modules/vite-plus/bin/vp", "test", "run"], envs = [["LOCAL_VITE", "1"]] }, + ["node", "check-core-guard.mjs", "local"], +] diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots/upstream_vite_override.global.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots/upstream_vite_override.global.md new file mode 100644 index 0000000000..c691b11741 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/upstream_vite_override/snapshots/upstream_vite_override.global.md @@ -0,0 +1,147 @@ +# upstream_vite_override + +A global Vite override replaces CLI/API/Vitest Vite, while postinstall pack keeps its matching internal core. Repeat with a local file dependency and a different public CLI entry. + +## `vp install` + + +## `node check-api.mjs` + +``` +API exports and bundled Vitest use upstream Vite; pack uses the matching internal core +``` + +## `vpt stat-file packed/entry.mjs --assert file` + +``` +packed/entry.mjs: file +``` + +## `vpt stat-file packed/entry.d.mts --assert file` + +``` +packed/entry.d.mts: file +``` + +## `vp build` + +``` +VITE+ - The Unified Toolchain for the Web + +✓ 4 modules transformed. +computing gzip size... +dist/index.html kB │ gzip: kB +dist/assets/index-.js kB │ gzip: kB + +✓ built in +``` + +## `vp dev` + +``` + + VITE ready in + + ➜ Local: http://127.0.0.1:/ + ➜ press h + enter to show help +Upstream Vite dev served HTTP 200 +``` + +## `vp preview` + +``` +VITE+ - The Unified Toolchain for the Web + + ➜ Local: http://127.0.0.1:/ + ➜ press h + enter to show help +Upstream Vite preview served HTTP 200 +``` + +## `vp test run` + +``` +VITE+ - The Unified Toolchain for the Web + + RUN + + ✓ override.test.ts (1 test) + ✓ uses the replacement Vite through public API exports + + Test Files 1 passed (1) + Tests 1 passed (1) + Start at