Skip to content

Commit 3bc49c6

Browse files
author
Daniel Del Core
committed
remove require from experimental loader
1 parent ee13161 commit 3bc49c6

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

packages/cli/src/main.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ import { fetchConfigsForWorkspaces, getPackageJson } from './utils/file-system';
1717
import { getConfigPrompt, getMultiConfigPrompt } from './prompt';
1818

1919
const ExperimentalModuleLoader = () => {
20-
const getInfo = (packageName: string) => {
21-
const entryPath = require.resolve(packageName);
22-
const location = entryPath.split(packageName)[0] + packageName;
20+
const getInfo = async (packageName: string) => {
21+
// @ts-expect-error Experimental loader
22+
const entryPath = import.meta.resolve(packageName);
23+
// @ts-expect-error Experimental loader
24+
const location = (entryPath.split(packageName)[0] + packageName).replace(
25+
'file://',
26+
'',
27+
);
2328
const pkgJsonRaw = fs.readFileSync(
24-
path.join(location, 'package.json'),
29+
path.join(location.replace('file://', ''), 'package.json'),
2530
'utf8',
2631
);
2732
const pkgJson = JSON.parse(pkgJsonRaw);
2833

29-
return {
30-
location,
31-
entryPath,
32-
pkgJson,
33-
};
34+
return { location, entryPath, pkgJson };
3435
};
3536

3637
const install = async (packageName: string) => {
@@ -40,7 +41,7 @@ const ExperimentalModuleLoader = () => {
4041
additionalArgs: ['--force'],
4142
});
4243

43-
const { pkgJson } = getInfo(packageName);
44+
const { pkgJson } = await getInfo(packageName);
4445

4546
// Install whitelisted devDependencies
4647
if (pkgJson?.hypermod?.dependencies) {
@@ -61,7 +62,7 @@ const ExperimentalModuleLoader = () => {
6162
return {
6263
install,
6364
getInfo,
64-
require: (packageName: string) => require(packageName),
65+
require: async (packageName: string) => import(packageName),
6566
};
6667
};
6768

packages/fetcher/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export async function fetchPackage(
8585
packageManager: PluginManager,
8686
): Promise<ConfigMeta> {
8787
await packageManager.install(packageName);
88-
const pkg = packageManager.require(packageName);
89-
const info = packageManager.getInfo(packageName);
88+
const pkg = await packageManager.require(packageName);
89+
const info = await packageManager.getInfo(packageName);
9090

9191
if (!info) {
9292
throw new Error(`Unable to find package info for: ${packageName}`);
@@ -117,7 +117,7 @@ export async function fetchRemotePackage(
117117

118118
// Search main entrypoint for transform/presets from the default import
119119
try {
120-
const pkg = packageManager.require(packageName);
120+
const pkg = await packageManager.require(packageName);
121121
const configExport = resolveConfigExport(pkg);
122122

123123
if (configExport.transforms || configExport.presets) {

0 commit comments

Comments
 (0)