Skip to content

Commit

Permalink
module: 12.x self resolve flag as experimental modules
Browse files Browse the repository at this point in the history
PR-URL: #31757
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
  • Loading branch information
guybedford authored and MylesBorins committed Feb 13, 2020
1 parent 7a5954e commit f0b2d87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ function resolveBasePath(basePath, exts, isMain, trailingSlash, request) {
}

function trySelf(parentPath, isMain, request) {
if (!experimentalModules) return false;
const { data: pkg, path: basePath } = readPackageScope(parentPath) || {};
if (!pkg || pkg.exports === undefined) return false;
if (typeof pkg.name !== 'string') return false;
Expand Down
16 changes: 16 additions & 0 deletions test/es-module/test-esm-flagged-self.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

require('../common');
const assert = require('assert');
const path = require('path');
const { createRequireFromPath } = require('module');

const fixturesRequire =
createRequireFromPath(path.resolve(__dirname, '../fixtures/_'));

try {
fixturesRequire('pkgexports/resolve-self');
assert(false);
} catch (e) {
assert.strictEqual(e.code, 'MODULE_NOT_FOUND');
}

0 comments on commit f0b2d87

Please sign in to comment.