-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
esm: unflag extensionless javascript and wasm in module scope
PR-URL: #49974 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
- Loading branch information
1 parent
23cb478
commit 9c68320
Showing
14 changed files
with
174 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Flags: --experimental-wasm-modules | ||
import { mustNotCall, spawnPromisified } from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { describe, it } from 'node:test'; | ||
import { match, ok, strictEqual } from 'node:assert'; | ||
|
||
describe('extensionless ES modules within a "type": "module" package scope', { concurrency: true }, () => { | ||
it('should run as the entry point', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
fixtures.path('es-modules/package-type-module/noext-esm'), | ||
]); | ||
|
||
strictEqual(stderr, ''); | ||
strictEqual(stdout, 'executed\n'); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
it('should be importable', async () => { | ||
const { default: defaultExport } = | ||
await import(fixtures.fileURL('es-modules/package-type-module/noext-esm')); | ||
strictEqual(defaultExport, 'module'); | ||
}); | ||
|
||
it('should be importable from a module scope under node_modules', async () => { | ||
const { default: defaultExport } = | ||
await import(fixtures.fileURL( | ||
'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-esm')); | ||
strictEqual(defaultExport, 'module'); | ||
}); | ||
}); | ||
describe('extensionless Wasm modules within a "type": "module" package scope', { concurrency: true }, () => { | ||
it('should run as the entry point', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-wasm-modules', | ||
'--no-warnings', | ||
fixtures.path('es-modules/package-type-module/noext-wasm'), | ||
]); | ||
|
||
strictEqual(stderr, ''); | ||
strictEqual(stdout, 'executed\n'); | ||
strictEqual(code, 0); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
it('should be importable', async () => { | ||
const { add } = await import(fixtures.fileURL('es-modules/package-type-module/noext-wasm')); | ||
strictEqual(add(1, 2), 3); | ||
}); | ||
|
||
it('should be importable from a module scope under node_modules', async () => { | ||
const { add } = await import(fixtures.fileURL( | ||
'es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-wasm')); | ||
strictEqual(add(1, 2), 3); | ||
}); | ||
}); | ||
|
||
describe('extensionless ES modules within no package scope', { concurrency: true }, () => { | ||
// This succeeds with `--experimental-default-type=module` | ||
it('should error as the entry point', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
fixtures.path('es-modules/noext-esm'), | ||
]); | ||
|
||
match(stderr, /SyntaxError/); | ||
strictEqual(stdout, ''); | ||
strictEqual(code, 1); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
// This succeeds with `--experimental-default-type=module` | ||
it('should error on import', async () => { | ||
try { | ||
await import(fixtures.fileURL('es-modules/noext-esm')); | ||
mustNotCall(); | ||
} catch (err) { | ||
ok(err instanceof SyntaxError); | ||
} | ||
}); | ||
}); | ||
|
||
describe('extensionless Wasm within no package scope', { concurrency: true }, () => { | ||
// This succeeds with `--experimental-default-type=module` | ||
it('should error as the entry point', async () => { | ||
const { code, signal, stdout, stderr } = await spawnPromisified(process.execPath, [ | ||
'--experimental-wasm-modules', | ||
'--no-warnings', | ||
fixtures.path('es-modules/noext-wasm'), | ||
]); | ||
|
||
match(stderr, /SyntaxError/); | ||
strictEqual(stdout, ''); | ||
strictEqual(code, 1); | ||
strictEqual(signal, null); | ||
}); | ||
|
||
// This succeeds with `--experimental-default-type=module` | ||
it('should error on import', async () => { | ||
try { | ||
await import(fixtures.fileURL('es-modules/noext-wasm')); | ||
mustNotCall(); | ||
} catch (err) { | ||
ok(err instanceof SyntaxError); | ||
} | ||
}); | ||
}); |
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
2 changes: 2 additions & 0 deletions
2
...s/es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-esm
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+136 Bytes
.../es-modules/package-type-module/node_modules/dep-with-package-json-type-module/noext-wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions
8
...s-modules/package-type-module/node_modules/dep-with-package-json-type-module/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
...s-modules/package-type-module/node_modules/dep-with-package-json-type-module/wasm-dep.mjs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...odules/dep-with-package-json/package.json → ...th-package-json-without-type/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.