Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use resolvePackageData to get rollup version #18208

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,11 @@ export const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//
// TODO: use import()
const _require = createRequire(import.meta.url)

export function resolveDependencyVersion(
dep: string,
pkgRelativePath = '../../package.json',
): string {
const pkgPath = path.resolve(_require.resolve(dep), pkgRelativePath)
return JSON.parse(fs.readFileSync(pkgPath, 'utf-8')).version
}
const _dirname = path.dirname(fileURLToPath(import.meta.url))

export const rollupVersion = resolveDependencyVersion('rollup')
// NOTE: we don't use VERSION variable exported from rollup to avoid importing rollup in dev
export const rollupVersion =
resolvePackageData('rollup', _dirname, true)?.data.version ?? ''

// set in bin/vite.js
const filter = process.env.VITE_DEBUG_FILTER
Expand Down Expand Up @@ -1036,8 +1032,6 @@ export function getHash(text: Buffer | string, length = 8): string {
return h.padEnd(length, '_')
}

const _dirname = path.dirname(fileURLToPath(import.meta.url))

export const requireResolveFromRootWithFallback = (
root: string,
id: string,
Expand Down