@@ -302,17 +302,33 @@ export class PnpInstaller implements Installer {
302
302
}
303
303
304
304
if ( pnpPath . main . endsWith ( `.cjs` ) ) {
305
- await xfs . writeFilePromise ( pnpPath . esmLoader , `import { syncBuiltinESMExports, createRequire } from 'module';
305
+ await xfs . writeFilePromise ( pnpPath . esmLoader , `import { syncBuiltinESMExports, createRequire, builtinModules } from 'module';
306
+ import { fileURLToPath, pathToFileURL, URL } from 'url';
306
307
syncBuiltinESMExports();
307
308
308
309
const pnpapi = createRequire(import.meta.url)('pnpapi');
309
310
310
- export async function resolve(specifier, context) {
311
+ function isValidURL(str) {
312
+ try {
313
+ new URL(str);
314
+ return true;
315
+ } catch {
316
+ return false;
317
+ }
318
+ }
319
+
320
+ const builtins = new Set([...builtinModules]);
321
+
322
+ export async function resolve(specifier, context, defaultResolver) {
323
+ if (builtins.has(specifier) || isValidURL(specifier)) {
324
+ return defaultResolver(specifier, context, defaultResolver);
325
+ }
326
+
311
327
const { parentURL = null } = context;
312
328
313
329
const resolvedPath = pnpapi.resolveRequest(
314
- specifier.replace('file:///', '') ,
315
- parentURL && parentURL.replace('file:///', '')
330
+ specifier,
331
+ parentURL ? fileURLToPath(parentURL) : undefined
316
332
);
317
333
318
334
if (!resolvedPath) {
@@ -322,7 +338,7 @@ export async function resolve(specifier, context) {
322
338
}
323
339
324
340
return {
325
- url: new URL(\`file:///\${ resolvedPath}\` ).href,
341
+ url: pathToFileURL( resolvedPath).href,
326
342
};
327
343
}
328
344
` ) ;
0 commit comments