forked from oracle/graaljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: bypass CommonJS loader under --default-type
PR-URL: nodejs/node#49986 Backport-PR-URL: nodejs/node#50669 Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
- Loading branch information
Showing
8 changed files
with
179 additions
and
41 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
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
92 changes: 92 additions & 0 deletions
92
graal-nodejs/test/es-module/test-esm-type-flag-cli-entry.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,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
1 change: 1 addition & 0 deletions
1
graal-nodejs/test/fixtures/es-modules/package-without-type/file#1.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 @@ | ||
console.log('file#1'); |