0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

Fix getPackage resolve path (#11347)

This commit is contained in:
Bjorn Lu 2024-06-26 20:57:33 +08:00 committed by GitHub
parent 0df81422a8
commit 33bdc54729
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes installed packages detection when running `astro check`

View file

@ -9,6 +9,8 @@ import prompts from 'prompts';
import whichPm from 'which-pm';
import type { Logger } from '../core/logger/core.js';
const require = createRequire(import.meta.url);
type GetPackageOptions = {
skipAsk?: boolean;
optional?: boolean;
@ -24,7 +26,7 @@ export async function getPackage<T>(
try {
// Try to resolve with `createRequire` first to prevent ESM caching of the package
// if it errors and fails here
createRequire(options.cwd ?? process.cwd()).resolve(packageName);
require.resolve(packageName, { paths: [options.cwd ?? process.cwd()] });
const packageImport = await import(packageName);
return packageImport as T;
} catch (e) {