Skip to content

Commit

Permalink
Fix getPackage resolve path (#11347)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jun 26, 2024
1 parent 0df8142 commit 33bdc54
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/famous-maps-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes installed packages detection when running `astro check`
4 changes: 3 additions & 1 deletion packages/astro/src/cli/install-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 33bdc54

Please sign in to comment.