forked from nodejs/node
-
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: empty ext from pkg type/main doesnt affect format
This ensures files with unknown extensions like foo.bar are not loaded as CJS/ESM when imported as a main entry point and makes sure that those files would maintain the same format even if loaded after the main entrypoint. PR-URL: nodejs#31021 Reviewed-By: Guy Bedford <guybedford@gmail.com>
- Loading branch information
1 parent
3abe3f2
commit baa3621
Showing
6 changed files
with
95 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fixtures = require('../common/fixtures'); | ||
const { spawn } = require('child_process'); | ||
const assert = require('assert'); | ||
|
||
{ | ||
const entry = fixtures.path( | ||
'/es-modules/package-type-module/extension.unknown' | ||
); | ||
const child = spawn(process.execPath, [entry]); | ||
let stdout = ''; | ||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (data) => { | ||
stdout += data; | ||
}); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 1); | ||
assert.strictEqual(signal, null); | ||
assert.strictEqual(stdout, ''); | ||
assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1); | ||
})); | ||
} | ||
{ | ||
const entry = fixtures.path( | ||
'/es-modules/package-type-module/imports-unknownext.mjs' | ||
); | ||
const child = spawn(process.execPath, [entry]); | ||
let stdout = ''; | ||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (data) => { | ||
stdout += data; | ||
}); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 1); | ||
assert.strictEqual(signal, null); | ||
assert.strictEqual(stdout, ''); | ||
assert.ok(stderr.indexOf('ERR_UNKNOWN_FILE_EXTENSION') !== -1); | ||
})); | ||
} | ||
{ | ||
const entry = fixtures.path('/es-modules/package-type-module/noext-esm'); | ||
const child = spawn(process.execPath, [entry]); | ||
let stdout = ''; | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (data) => { | ||
stdout += data; | ||
}); | ||
child.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
assert.strictEqual(stdout, 'executed\n'); | ||
})); | ||
} | ||
{ | ||
const entry = fixtures.path( | ||
'/es-modules/package-type-module/imports-noext.mjs' | ||
); | ||
const child = spawn(process.execPath, [entry]); | ||
let stdout = ''; | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', (data) => { | ||
stdout += data; | ||
}); | ||
child.on('close', common.mustCall((code, signal) => { | ||
assert.strictEqual(code, 0); | ||
assert.strictEqual(signal, null); | ||
assert.strictEqual(stdout, 'executed\n'); | ||
})); | ||
} |
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 @@ | ||
throw new Error('NO, NEVER'); |
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 @@ | ||
import './noext-esm'; |
1 change: 1 addition & 0 deletions
1
test/fixtures/es-modules/package-type-module/imports-unknownext.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 @@ | ||
import './extension.unknown'; |