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:
parent
0df81422a8
commit
33bdc54729
2 changed files with 8 additions and 1 deletions
5
.changeset/famous-maps-notice.md
Normal file
5
.changeset/famous-maps-notice.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes installed packages detection when running `astro check`
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue