This repository has been archived by the owner on Aug 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: fix main resolution and not found updates
This simplifies the top-level load when ES modules are enabled as we can entirely delegate the module resolver, which will hand over to CommonJS where appropriate. All not found errors are made consistent to throw during resolve and have the MODULE_NOT_FOUND code. Includes the test case from nodejs/node#15736. Fixes: nodejs/node#15732 PR-URL: nodejs/node#16147 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
1 parent
984a851
commit e7f1e84
Showing
9 changed files
with
104 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/es-module/test-esm-preserve-symlinks-not-found-plain.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs | ||
/* eslint-disable required-modules */ | ||
import './not-found.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs | ||
/* eslint-disable required-modules */ | ||
import './not-found'; |
22 changes: 22 additions & 0 deletions
22
test/fixtures/es-module-loaders/not-found-assert-loader.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import assert from 'assert'; | ||
|
||
// a loader that asserts that the defaultResolve will throw "not found" | ||
// (skipping the top-level main of course) | ||
let mainLoad = true; | ||
export async function resolve (specifier, base, defaultResolve) { | ||
if (mainLoad) { | ||
mainLoad = false; | ||
return defaultResolve(specifier, base); | ||
} | ||
try { | ||
await defaultResolve(specifier, base); | ||
} | ||
catch (e) { | ||
assert.equal(e.code, 'MODULE_NOT_FOUND'); | ||
return { | ||
format: 'builtin', | ||
url: 'fs' | ||
}; | ||
} | ||
assert.fail(`Module resolution for ${specifier} should be throw MODULE_NOT_FOUND`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const { execFileSync } = require('child_process'); | ||
|
||
const entryPoints = ['iDoNotExist', 'iDoNotExist.js', 'iDoNotExist.mjs']; | ||
const flags = [[], ['--experimental-modules']]; | ||
const node = process.argv[0]; | ||
|
||
for (const args of flags) { | ||
for (const entryPoint of entryPoints) { | ||
try { | ||
execFileSync(node, args.concat(entryPoint), { stdio: 'pipe' }); | ||
} catch (e) { | ||
assert(e.toString().match(/Error: Cannot find module/)); | ||
continue; | ||
} | ||
assert.fail('Executing node with inexistent entry point should ' + | ||
`fail. Entry point: ${entryPoint}, Flags: [${args}]`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
require('../common'); | ||
const assert = require('assert'); | ||
const { execFileSync } = require('child_process'); | ||
|
||
const entryPoints = ['iDoNotExist', 'iDoNotExist.js', 'iDoNotExist.mjs']; | ||
const flags = [[], ['--experimental-modules', '--preserve-symlinks']]; | ||
const node = process.argv[0]; | ||
|
||
for (const args of flags) { | ||
for (const entryPoint of entryPoints) { | ||
try { | ||
execFileSync(node, args.concat(entryPoint)); | ||
} catch (e) { | ||
assert(e.toString().match(/Error: Cannot find module/)); | ||
continue; | ||
} | ||
assert.fail('Executing node with inexistent entry point should ' + | ||
`fail. Entry point: ${entryPoint}, Flags: [${args}]`); | ||
} | ||
} |