Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
modules: enforce extensions and dissalow directories#21572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -11,7 +11,8 @@ const preserveSymlinksMain = !!process.binding('config').preserveSymlinksMain; | ||
| const { | ||
| ERR_MISSING_MODULE, | ||
| ERR_MODULE_RESOLUTION_LEGACY, | ||
| ERR_UNKNOWN_FILE_EXTENSION | ||
| ERR_UNKNOWN_FILE_EXTENSION, | ||
| ERR_NON_EXPLICIT_SPECIFIER | ||
| } = require('internal/errors').codes; | ||
| const { resolve: moduleWrapResolve } = internalBinding('module_wrap'); | ||
| const StringStartsWith = Function.call.bind(String.prototype.startsWith); | ||
| @@ -24,6 +25,10 @@ function search(target, base) { | ||
| // We cannot search without a base. | ||
| throw new ERR_MISSING_MODULE(target); | ||
| } | ||
| if ((target[0] === '.' || target[0] === '/') && | ||
| ||
| (extname(target) <= 1)) { | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be a little clearer to have an explicit | ||
| throw new ERR_NON_EXPLICIT_SPECIFIER(target); | ||
| } | ||
| try { | ||
| return moduleWrapResolve(target, base); | ||
| } catch (e) { | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // Flags: --experimental-modules | ||
| import '../common'; | ||
| import('./test-esm-cyclic-dynamic-import'); | ||
| /* eslint-disable node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| import('./test-esm-cyclic-dynamic-import.mjs'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // Flags: --experimental-modules | ||
| import '../common'; | ||
| /* eslint-disable node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| // Assert we can import files with `%` in their pathname. | ||
| import '../fixtures/es-modules/test-esm-double-encoding-native%2520.js'; | ||
| import '../fixtures/es-modules/test-esm-double-encoding-native%2520.mjs'; |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| // Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs | ||
| /* eslint-disable node-core/required-modules */ | ||
| import './not-found'; | ||
| import './not-found.mjs'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| #! }]) // isn't js | ||
| // Flags: --experimental-modules | ||
| import '../common'; | ||
| /* eslint-disable node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| const isJs = true; | ||
| export default isJs; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| // Flags: --experimental-modules | ||
| import '../common'; | ||
| import '../fixtures/es-modules/esm-snapshot-mutator'; | ||
| import one from '../fixtures/es-modules/esm-snapshot'; | ||
| /* eslint-disable node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| import '../fixtures/es-modules/esm-snapshot-mutator.js'; | ||
| import one from '../fixtures/es-modules/esm-snapshot.js'; | ||
| import assert from 'assert'; | ||
| assert.strictEqual(one, 1); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| import { foo, notfound } from './module-named-exports'; | ||
| import { foo, notfound } from './module-named-exports.mjs'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { message } from './message'; | ||
| import { message } from './message.mjs'; | ||
| var t = 1; | ||
| var k = 1; | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| 'use strict'; | ||
| // Trivial test to assert we can load files with `%` in their pathname. | ||
| // Imported by `test-esm-double-encoding.mjs`. | ||
| export default 42; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| // Flags: --experimental-modules | ||
| /* eslint-disable no-unused-vars */ | ||
| import '../common'; | ||
| /* eslint-disable no-unused-vars, node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| import { | ||
| foo, | ||
| notfound | ||
| } from '../fixtures/es-module-loaders/module-named-exports'; | ||
| } from '../fixtures/es-module-loaders/module-named-exports.mjs'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // Flags: --experimental-modules | ||
| import '../common'; | ||
| import '../fixtures/es-module-loaders/syntax-error-import'; | ||
| /* eslint-disable node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| import '../fixtures/es-module-loaders/syntax-error-import.mjs'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| (node:*) ExperimentalWarning: The ESM module loader is experimental. | ||
| file:///*/test/fixtures/es-module-loaders/syntax-error-import.mjs:1 | ||
| import { foo, notfound } from './module-named-exports'; | ||
| import { foo, notfound } from './module-named-exports.mjs'; | ||
| ^^^^^^^^ | ||
| SyntaxError: The requested module './module-named-exports' does not provide an export named 'notfound' | ||
| SyntaxError: The requested module './module-named-exports.mjs' does not provide an export named 'notfound' | ||
| at ModuleJob._instantiate (internal/modules/esm/module_job.js:*:*) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| // Flags: --experimental-modules | ||
| import '../common'; | ||
| import '../fixtures/es-module-loaders/syntax-error'; | ||
| /* eslint-disable node-core/required-modules */ | ||
| import '../common/index.mjs'; | ||
| import '../fixtures/es-module-loaders/syntax-error.mjs'; |
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sorry,
Nis before_. But then it should go beforeERR_NO_CRYPTO, right?