Skip to content

Commit

Permalink
fix(config): deno resolving vite cjs entry
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Sep 11, 2024
1 parent 587ad7b commit 8651f5d
Showing 1 changed file with 50 additions and 9 deletions.
59 changes: 50 additions & 9 deletions packages/vite/src/node/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ export function resolvePackageData(
return null
}

function loadPackageFile(
pkgPath: string,
basedir: string,
originalBasedir: string,
packageCache?: PackageCache,
): PackageData | null {
if (tryStatSync(pkgPath)?.isFile()) {
try {
const pkgData = loadPackageData(pkgPath)

if (packageCache) {
setFnpdCache(packageCache, pkgData, basedir, originalBasedir)
}

return pkgData
} catch {}
}

return null
}

export function findNearestPackageData(
basedir: string,
packageCache?: PackageCache,
Expand All @@ -131,16 +152,36 @@ export function findNearestPackageData(
}

const pkgPath = path.join(basedir, 'package.json')
if (tryStatSync(pkgPath)?.isFile()) {
try {
const pkgData = loadPackageData(pkgPath)

if (packageCache) {
setFnpdCache(packageCache, pkgData, basedir, originalBasedir)
}

let pkgData = loadPackageFile(
pkgPath,
basedir,
originalBasedir,
packageCache,
)
if (pkgData !== null) return pkgData

Check warning on line 161 in packages/vite/src/node/packages.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Expected '!=' and instead saw '!=='

// Check for `deno.json` and `deno.jsonc` if we're
// running inside Deno
if (typeof process.versions.deno === 'string') {
let pkgPath = path.join(basedir, 'deno.json')
pkgData = loadPackageFile(pkgPath, basedir, originalBasedir, packageCache)

// File `deno.json` not found, try `deno.jsonc`
if (pkgData === null) {

Check warning on line 170 in packages/vite/src/node/packages.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Expected '==' and instead saw '==='
pkgPath = path.join(basedir, 'deno.jsonc')
pkgData = loadPackageFile(
pkgPath,
basedir,
originalBasedir,
packageCache,
)
}
if (pkgData !== null) {

Check warning on line 179 in packages/vite/src/node/packages.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Expected '!=' and instead saw '!=='
// PackageData is assumed to be a `package.json` schema.
// In Deno packages are always in ESM.
pkgData.data.type = 'module'
return pkgData
} catch {}
}
}

const nextBasedir = path.dirname(basedir)
Expand Down

0 comments on commit 8651f5d

Please sign in to comment.