From 281dbc1b1365309636bd322df194c42fb875db09 Mon Sep 17 00:00:00 2001 From: James Browning Date: Mon, 28 Feb 2022 23:12:29 +1300 Subject: [PATCH 1/3] Enable JSON modules by default in Node >=17.5.0 --- dist-raw/node-esm-default-get-format.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dist-raw/node-esm-default-get-format.js b/dist-raw/node-esm-default-get-format.js index d8af956f3..65b0bf6dd 100644 --- a/dist-raw/node-esm-default-get-format.js +++ b/dist-raw/node-esm-default-get-format.js @@ -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'); From 2e2d44b2f475855674c0697446a8c160dcec03f6 Mon Sep 17 00:00:00 2001 From: James Browning Date: Tue, 1 Mar 2022 18:38:46 +1300 Subject: [PATCH 2/3] Added tests for experimental json modules no longer requiring flag --- src/test/esm-loader.spec.ts | 43 +++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/test/esm-loader.spec.ts b/src/test/esm-loader.spec.ts index d4a943798..76cb320d5 100644 --- a/src/test/esm-loader.spec.ts +++ b/src/test/esm-loader.spec.ts @@ -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!' + ); + }); }); }); From 4516ad28c1bcc40a277cc530eaf23fbca2b430be Mon Sep 17 00:00:00 2001 From: Andrew Bradley Date: Wed, 2 Mar 2022 18:54:27 -0500 Subject: [PATCH 3/3] bump node version used for development; just more convenient this way --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9e8bbdb61..55247000f 100644 --- a/package.json +++ b/package.json @@ -171,7 +171,7 @@ "singleQuote": true }, "volta": { - "node": "16.9.1", + "node": "17.5.0", "npm": "6.14.15" } }