-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
esm: bypass CommonJS loader under --default-type=module
#49986
Merged
nodejs-github-bot
merged 11 commits into
nodejs:main
from
GeoffreyBooth:bypass-cjs-loader
Oct 5, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
97b1966
esm: bypass CommonJS loader under --default-type
GeoffreyBooth 30821db
Streamline
GeoffreyBooth 286c632
Revert "Streamline"
GeoffreyBooth 4620842
Move/improve tests; decorate "not found" error to provide hint about …
GeoffreyBooth bdafa66
Update docs
GeoffreyBooth 83884e5
Fix for Windows
GeoffreyBooth 162b6fa
Move out main re-resolution
GeoffreyBooth 22bddbd
Optimize
GeoffreyBooth 6c97b9a
Revert "Optimize"
GeoffreyBooth 32aaabc
Update lib/internal/modules/run_main.js
GeoffreyBooth 038dfb8
Return early if possible
GeoffreyBooth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { spawnPromisified } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { describe, it } from 'node:test'; | ||
import { match, strictEqual } from 'node:assert'; | ||
|
||
describe('--experimental-default-type=module should not support extension searching', { concurrency: true }, () => { | ||
it('should support extension searching under --experimental-default-type=commonjs', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-default-type=commonjs', | ||
'index', | ||
], { | ||
cwd: fixtures.path('es-modules/package-without-type'), | ||
}); | ||
|
||
strictEqual(stdout, 'package-without-type\n'); | ||
strictEqual(stderr, ''); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
it('should error with implicit extension under --experimental-default-type=module', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-default-type=module', | ||
'index', | ||
], { | ||
cwd: fixtures.path('es-modules/package-without-type'), | ||
}); | ||
|
||
match(stderr, /ENOENT.*Did you mean to import .*index\.js\?/s); | ||
strictEqual(stdout, ''); | ||
strictEqual(code, 1); | ||
strictEqual(signal, null); | ||
}); | ||
}); | ||
|
||
describe('--experimental-default-type=module should not parse paths as URLs', { concurrency: true }, () => { | ||
it('should not parse a `?` in a filename as starting a query string', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-default-type=module', | ||
'file#1.js', | ||
], { | ||
cwd: fixtures.path('es-modules/package-without-type'), | ||
}); | ||
|
||
strictEqual(stderr, ''); | ||
strictEqual(stdout, 'file#1\n'); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
it('should resolve `..`', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-default-type=module', | ||
'../package-without-type/file#1.js', | ||
], { | ||
cwd: fixtures.path('es-modules/package-without-type'), | ||
}); | ||
|
||
strictEqual(stderr, ''); | ||
strictEqual(stdout, 'file#1\n'); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
it('should allow a leading `./`', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-default-type=module', | ||
'./file#1.js', | ||
], { | ||
cwd: fixtures.path('es-modules/package-without-type'), | ||
}); | ||
|
||
strictEqual(stderr, ''); | ||
strictEqual(stdout, 'file#1\n'); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
it('should not require a leading `./`', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-default-type=module', | ||
'file#1.js', | ||
], { | ||
cwd: fixtures.path('es-modules/package-without-type'), | ||
}); | ||
|
||
strictEqual(stderr, ''); | ||
strictEqual(stdout, 'file#1\n'); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
}); |
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 @@ | ||
console.log('file#1'); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.