Skip to content

Commit d4a8748

Browse files
author
Daniel Del Core
committed
remove require from experimental loader
1 parent c4eb50e commit d4a8748

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
@@ -20,20 +20,21 @@ import {
2020
import { getConfigPrompt, getMultiConfigPrompt } from './prompt.js';
2121

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

32-
return {
33-
location,
34-
entryPath,
35-
pkgJson,
36-
};
37+
return { location, entryPath, pkgJson };
3738
};
3839

3940
const install = async (packageName: string) => {
@@ -44,7 +45,7 @@ const ExperimentalModuleLoader = () => {
4445
additionalArgs: ['--force'],
4546
});
4647

47-
const { pkgJson } = getInfo(packageName);
48+
const { pkgJson } = await getInfo(packageName);
4849

4950
// Install whitelisted devDependencies
5051
if (pkgJson?.hypermod?.dependencies) {
@@ -65,7 +66,7 @@ const ExperimentalModuleLoader = () => {
6566
return {
6667
install,
6768
getInfo,
68-
require: (packageName: string) => require(packageName),
69+
require: async (packageName: string) => import(packageName),
6970
};
7071
};
7172

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)