Skip to content

Commit 220d6ec

Browse files
authored
refactor: use resolvePackageData to get rollup version (#18208)
1 parent bea0272 commit 220d6ec

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

packages/vite/src/node/utils.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,11 @@ export const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//
137137
// TODO: use import()
138138
const _require = createRequire(import.meta.url)
139139

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

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

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

1039-
const _dirname = path.dirname(fileURLToPath(import.meta.url))
1040-
10411035
export const requireResolveFromRootWithFallback = (
10421036
root: string,
10431037
id: string,

0 commit comments

Comments
 (0)