Skip to content

Commit 01f1254

Browse files
committed
fix(cli/create): pin packageManager and yarn linker before migrate install
The remote-template migrate flow was breaking on npm/yarn/bun because `vp install` couldn't honor `--package-manager`: - `vite_install`'s `prompt_package_manager_selection` hardcodes pnpm in CI / non-TTY environments when no `packageManager` field, no workspace file, and no lockfile are present. create-vite scaffolds without a `packageManager` field, so every non-pnpm path silently switched to pnpm at install #1 — leaving the wrong lockfile for install #2 and tripping ERR_PNPM_NO_MATCHING_VERSION on CI's local tarballs. - Yarn Berry's default Plug'n'Play stores deps inside .yarn/cache/*.zip. `@oxlint/migrate` calls fileURLToPath over zip entries and throws MODULE_NOT_FOUND on `@eslint/js`. Before install #1 in the migrate-gated branches (standalone + monorepo): - Call `setPackageManager(fullPath, downloadPackageManager)` so `vp install` picks up the `--package-manager` choice from the field. - For yarn, write a minimal `.yarnrc.yml` with `nodeLinker: node-modules` so the install produces a classic `node_modules/` that `@oxlint/migrate` can resolve. Export `setPackageManager` from migrator.ts for reuse from create/bin.ts. Verified end-to-end locally: all four package managers (pnpm / npm / yarn / bun) now migrate `vite@9.0.5 --template react-ts` cleanly — eslint.config.js removed, `.oxlintrc.json` merged into vite.config.ts, packageManager pinned to the chosen PM. Drop the CI matrix `exclude` that previously scoped this entry to pnpm.
1 parent f745218 commit 01f1254

3 files changed

Lines changed: 31 additions & 18 deletions

File tree

.github/workflows/test-vp-create.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,6 @@ jobs:
151151
- npm
152152
- yarn
153153
- bun
154-
# Remote create-vite scaffolds bake `"packageManager": "pnpm@..."`
155-
# into the generated package.json, which `vp install` follows over
156-
# the --package-manager CLI flag. Combined with local-tarball
157-
# overrides in CI, that makes non-pnpm paths resolve
158-
# @voidzero-dev/vite-plus-core@0.0.0 from the npm registry and
159-
# fail. Scope this matrix entry to pnpm until the remote-template
160-
# install-flag propagation is sorted out separately.
161-
exclude:
162-
- template:
163-
name: remote-vite-react-ts
164-
package-manager: npm
165-
- template:
166-
name: remote-vite-react-ts
167-
package-manager: yarn
168-
- template:
169-
name: remote-vite-react-ts
170-
package-manager: bun
171154
env:
172155
VP_OVERRIDE_PACKAGES: '{"vite":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-core-0.0.0.tgz","vitest":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-test-0.0.0.tgz","@voidzero-dev/vite-plus-core":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-core-0.0.0.tgz","@voidzero-dev/vite-plus-test":"file:${{ github.workspace }}/tmp/tgz/voidzero-dev-vite-plus-test-0.0.0.tgz"}'
173156
VP_VERSION: 'file:${{ github.workspace }}/tmp/tgz/vite-plus-0.0.0.tgz'

packages/cli/src/create/bin.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs';
12
import path from 'node:path';
23
import { styleText } from 'node:util';
34

@@ -17,6 +18,7 @@ import {
1718
rewriteMonorepo,
1819
rewriteMonorepoProject,
1920
rewriteStandaloneProject,
21+
setPackageManager,
2022
} from '../migration/migrator.ts';
2123
import { DependencyType, PackageManager, type WorkspaceInfo } from '../types/index.ts';
2224
import {
@@ -989,6 +991,20 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
989991

990992
updateWorkspaceConfig(projectDir, workspaceInfo);
991993
if (shouldMigrateLintFmtTools) {
994+
// Pin the packageManager field before install so `vp install` honors
995+
// the user's `--package-manager` choice instead of falling back to
996+
// pnpm (the hardcoded non-interactive/CI default in vite_install).
997+
setPackageManager(fullPath, workspaceInfo.downloadPackageManager);
998+
// Yarn Berry's default Plug'n'Play stores deps inside .yarn/cache/*.zip,
999+
// which @oxlint/migrate can't resolve (ESM's fileURLToPath over a zip
1000+
// entry throws MODULE_NOT_FOUND). Force classic node_modules layout so
1001+
// the migration step can import the template's ESLint plugins.
1002+
if (workspaceInfo.packageManager === PackageManager.yarn) {
1003+
const yarnrcPath = path.join(fullPath, '.yarnrc.yml');
1004+
if (!fs.existsSync(yarnrcPath)) {
1005+
fs.writeFileSync(yarnrcPath, 'nodeLinker: node-modules\n');
1006+
}
1007+
}
9921008
updateCreateProgress('Installing dependencies');
9931009
installSummary = await runViteInstall(
9941010
workspaceInfo.rootDir,
@@ -1015,6 +1031,20 @@ Use \`vp create --list\` to list all available templates, or run \`vp create --h
10151031
});
10161032
} else {
10171033
if (shouldMigrateLintFmtTools) {
1034+
// Pin the packageManager field before install so `vp install` honors
1035+
// the user's `--package-manager` choice instead of falling back to
1036+
// pnpm (the hardcoded non-interactive/CI default in vite_install).
1037+
setPackageManager(fullPath, workspaceInfo.downloadPackageManager);
1038+
// Yarn Berry's default Plug'n'Play stores deps inside .yarn/cache/*.zip,
1039+
// which @oxlint/migrate can't resolve (ESM's fileURLToPath over a zip
1040+
// entry throws MODULE_NOT_FOUND). Force classic node_modules layout so
1041+
// the migration step can import the template's ESLint plugins.
1042+
if (workspaceInfo.packageManager === PackageManager.yarn) {
1043+
const yarnrcPath = path.join(fullPath, '.yarnrc.yml');
1044+
if (!fs.existsSync(yarnrcPath)) {
1045+
fs.writeFileSync(yarnrcPath, 'nodeLinker: node-modules\n');
1046+
}
1047+
}
10181048
updateCreateProgress('Installing dependencies');
10191049
installSummary = await runViteInstall(fullPath, options.interactive, installArgs, {
10201050
silent: compactOutput,

packages/cli/src/migration/migrator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ export function rewritePrepareScript(rootDir: string): string | undefined {
23672367
return oldDir;
23682368
}
23692369

2370-
function setPackageManager(
2370+
export function setPackageManager(
23712371
projectDir: string,
23722372
downloadPackageManager: DownloadPackageManagerResult,
23732373
) {

0 commit comments

Comments
 (0)