Skip to content

Commit

Permalink
fixup! add some properties to require
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed May 25, 2023
1 parent be60bfb commit 8df8dc0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/modules/esm/translators.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,17 @@ function createCJSModuleWrap(url, source) {
job.runSync();
return cjsCache.get(job.url).exports;
};
setOwnProperty(require, 'resolve', function resolve(spec) {
setOwnProperty(requireFn, 'resolve', function resolve(spec) {
// TODO: add support for absolute paths
if (spec[0] === '.') {
spec = pathToFileURL(join(__dirname, spec));
}
// TODO: make this work for CJSism (e.g. dir import, extensionless imports, etc.)
const { url: resolvedURL } = asyncESM.esmLoader.resolve(spec, url);
return StringPrototypeStartsWith(resolvedURL, 'file://') ? fileURLToPath(resolvedURL) : resolvedURL;
});
setOwnProperty(require, 'cache', CJSModule._cache);
setOwnProperty(require, 'main', process.mainModule);
setOwnProperty(requireFn, 'cache', CJSModule._cache);
setOwnProperty(requireFn, 'main', process.mainModule);

cjsCache.set(url, module);
ReflectApply(compiledWrapper, module.exports,
Expand Down

0 comments on commit 8df8dc0

Please sign in to comment.