Skip to content

Commit

Permalink
feat: override rollup (#254)
Browse files Browse the repository at this point in the history
* chore: remove special handling for vite-3

* feat: override rollup of test projects to use the exact same version as local workspace vite
  • Loading branch information
dominikg authored Oct 15, 2023
1 parent ba1f0f4 commit 30752dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, DependencyInfo>
devDependencies: Record<string, DependencyInfo>
optionalDependencies: Record<string, DependencyInfo>
}
21 changes: 21 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs'
import { fileURLToPath, pathToFileURL } from 'url'
import { execaCommand } from 'execa'
import {
PackageInfo,
EnvironmentData,
Overrides,
ProcessEnv,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<PackageInfo> {
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
}
}

0 comments on commit 30752dd

Please sign in to comment.