Skip to content
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

Allow json modules to be resolved in Node >=17.5.0 without flag #1665

Merged
merged 3 commits into from Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion dist-raw/node-esm-default-get-format.js
Expand Up @@ -11,7 +11,11 @@ const {
const { extname } = require('path');
const { getOptionValue } = require('./node-options');

const experimentalJsonModules = getOptionValue('--experimental-json-modules');
const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(s => parseInt(s, 10));
const experimentalJsonModules =
nodeMajor > 17
|| (nodeMajor === 17 && nodeMinor >= 5)
|| getOptionValue('--experimental-json-modules');
const experimentalSpeciferResolution =
getOptionValue('--experimental-specifier-resolution');
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -171,7 +171,7 @@
"singleQuote": true
},
"volta": {
"node": "16.9.1",
"node": "17.5.0",
"npm": "6.14.15"
}
}
43 changes: 32 additions & 11 deletions src/test/esm-loader.spec.ts
Expand Up @@ -261,17 +261,38 @@ test.suite('esm', (test) => {
test.suite('supports import assertions', (test) => {
test.runIf(nodeSupportsImportAssertions);

test('Can import JSON using the appropriate flag and assertion', async (t) => {
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-json-modules ./importJson.ts`,
{
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
}
);
expect(err).toBe(null);
expect(stdout.trim()).toBe(
'A fuchsia car has 2 seats and the doors are open.\nDone!'
);
test.suite('node >=17.5.0', (test) => {
test.runIf(semver.gte(process.version, '17.5.0'));

test('Can import JSON modules with appropriate assertion', async (t) => {
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} ./importJson.ts`,
{
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
}
);
expect(err).toBe(null);
expect(stdout.trim()).toBe(
'A fuchsia car has 2 seats and the doors are open.\nDone!'
);
});
});

test.suite('node <17.5.0', (test) => {
test.runIf(semver.lt(process.version, '17.5.0'));

test('Can import JSON using the appropriate flag and assertion', async (t) => {
const { err, stdout } = await exec(
`${CMD_ESM_LOADER_WITHOUT_PROJECT} --experimental-json-modules ./importJson.ts`,
{
cwd: resolve(TEST_DIR, 'esm-import-assertions'),
}
);
expect(err).toBe(null);
expect(stdout.trim()).toBe(
'A fuchsia car has 2 seats and the doors are open.\nDone!'
);
});
});
});

Expand Down