diff --git a/types.d.ts b/types.d.ts index 718f7a2f..42213918 100644 --- a/types.d.ts +++ b/types.d.ts @@ -54,3 +54,19 @@ export interface Overrides { export interface ProcessEnv { [key: string]: string | undefined } + +interface DependencyInfo { + from: string + version: string + resolved: string + path: string +} +interface PackageInfo { + name: string + version: string + path: string + private: boolean + dependencies: Record + devDependencies: Record + optionalDependencies: Record +} diff --git a/utils.ts b/utils.ts index 2b126242..17df4d4b 100644 --- a/utils.ts +++ b/utils.ts @@ -3,6 +3,7 @@ import fs from 'fs' import { fileURLToPath, pathToFileURL } from 'url' import { execaCommand } from 'execa' import { + PackageInfo, EnvironmentData, Overrides, ProcessEnv, @@ -271,6 +272,11 @@ export async function runInRepo(options: RunOptions & RepoOptions) { `@vitejs/plugin-legacy` ] ||= `${options.vitePath}/packages/plugin-legacy` + const vitePackageInfo = await getVitePackageInfo(options.vitePath) + if (vitePackageInfo.dependencies.rollup?.version && !overrides.rollup) { + overrides.rollup = vitePackageInfo.dependencies.rollup.version + } + // build and apply local overrides const localOverrides = await buildOverrides(pkg, options, overrides) cd(dir) // buildOverrides changed dir, change it back @@ -592,3 +598,18 @@ async function buildOverrides( } return overrides } + +/** + * use pnpm ls to get information about installed dependency versions of vite + * @param vitePath - workspace vite root + */ +async function getVitePackageInfo(vitePath: string): Promise { + try { + const lsOutput = await $`pnpm --dir ${vitePath}/packages/vite ls --json` + const lsParsed = JSON.parse(lsOutput) + return lsParsed[0] as PackageInfo + } catch (e) { + console.error('failed to retrieve vite package infos', e) + throw e + } +}