From 94b422a1ddbb61ce4968aa03df7287300e151b7b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 8 Oct 2024 18:48:27 +0200 Subject: [PATCH 1/3] process: fix `process.features.typescript` when Amaro is unavailable --- lib/internal/bootstrap/node.js | 2 +- test/es-module/test-typescript.mjs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index e06854deaba5a0..b8c47ee0f54bbd 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -315,7 +315,7 @@ ObjectDefineProperty(process, 'features', { const { emitWarning, emitWarningSync } = require('internal/process/warning'); const { getOptionValue } = require('internal/options'); -let kTypeStrippingMode = null; +let kTypeStrippingMode = process.config.variables.node_use_amaro ? null : false; // This must be a getter, as getOptionValue does not work // before bootstrapping. ObjectDefineProperty(process.features, 'typescript', { diff --git a/test/es-module/test-typescript.mjs b/test/es-module/test-typescript.mjs index d1314450436b7b..3171def2a877ee 100644 --- a/test/es-module/test-typescript.mjs +++ b/test/es-module/test-typescript.mjs @@ -361,7 +361,7 @@ test('expect process.features.typescript to be \'strip\' when --experimental-str ]); strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'strip\n'); + strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'strip\n' : 'false\n'); strictEqual(result.code, 0); }); @@ -373,7 +373,7 @@ test('expect process.features.typescript to be \'transform\' when --experimental ]); strictEqual(result.stderr, ''); - strictEqual(result.stdout, 'transform\n'); + strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'transform\n' : 'false\n'); strictEqual(result.code, 0); }); From dbf4cbe3dd9d9d422c63a52d3493259430527e19 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 9 Oct 2024 09:01:22 +0200 Subject: [PATCH 2/3] fixup! process: fix `process.features.typescript` when Amaro is unavailable --- test/es-module/test-typescript.mjs | 49 +++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/test/es-module/test-typescript.mjs b/test/es-module/test-typescript.mjs index 3171def2a877ee..cb8c5099b3b308 100644 --- a/test/es-module/test-typescript.mjs +++ b/test/es-module/test-typescript.mjs @@ -3,6 +3,31 @@ import * as fixtures from '../common/fixtures.mjs'; import { match, strictEqual } from 'node:assert'; import { test } from 'node:test'; +test('expect process.features.typescript to be \'strip\' when --experimental-strip-types', async () => { + const result = await spawnPromisified(process.execPath, [ + '--no-warnings', + '--experimental-strip-types', + '-p', 'process.features.typescript', + ]); + + strictEqual(result.stderr, ''); + strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'strip\n' : 'false\n'); + strictEqual(result.code, 0); +}); + +test('expect process.features.typescript to be \'transform\' when --experimental-transform-types', async () => { + const result = await spawnPromisified(process.execPath, [ + '--no-warnings', + '--experimental-transform-types', + '-p', 'process.features.typescript', + ]); + + strictEqual(result.stderr, ''); + strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'transform\n' : 'false\n'); + strictEqual(result.code, 0); +}); + + if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); test('execute a TypeScript file', async () => { @@ -353,30 +378,6 @@ test('execute a TypeScript test mocking module', { skip: isWindows && process.ar strictEqual(result.code, 0); }); -test('expect process.features.typescript to be \'strip\' when --experimental-strip-types', async () => { - const result = await spawnPromisified(process.execPath, [ - '--no-warnings', - '--experimental-strip-types', - '-p', 'process.features.typescript', - ]); - - strictEqual(result.stderr, ''); - strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'strip\n' : 'false\n'); - strictEqual(result.code, 0); -}); - -test('expect process.features.typescript to be \'transform\' when --experimental-transform-types', async () => { - const result = await spawnPromisified(process.execPath, [ - '--no-warnings', - '--experimental-transform-types', - '-p', 'process.features.typescript', - ]); - - strictEqual(result.stderr, ''); - strictEqual(result.stdout, process.config.variables.node_use_amaro ? 'transform\n' : 'false\n'); - strictEqual(result.code, 0); -}); - test('expect process.features.typescript to be false without type-stripping', async () => { strictEqual(process.features.typescript, false); }); From 60dce1fee136de9b31c707aad67a1861c4f04663 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 9 Oct 2024 14:48:24 +0200 Subject: [PATCH 3/3] fixup! process: fix `process.features.typescript` when Amaro is unavailable --- test/es-module/test-typescript.mjs | 4 ++-- test/fixtures/typescript/echo-process-features-typescript.cjs | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/typescript/echo-process-features-typescript.cjs diff --git a/test/es-module/test-typescript.mjs b/test/es-module/test-typescript.mjs index cb8c5099b3b308..a7ca6d70dd5e10 100644 --- a/test/es-module/test-typescript.mjs +++ b/test/es-module/test-typescript.mjs @@ -7,7 +7,7 @@ test('expect process.features.typescript to be \'strip\' when --experimental-str const result = await spawnPromisified(process.execPath, [ '--no-warnings', '--experimental-strip-types', - '-p', 'process.features.typescript', + fixtures.path('typescript/echo-process-features-typescript.cjs'), ]); strictEqual(result.stderr, ''); @@ -19,7 +19,7 @@ test('expect process.features.typescript to be \'transform\' when --experimental const result = await spawnPromisified(process.execPath, [ '--no-warnings', '--experimental-transform-types', - '-p', 'process.features.typescript', + fixtures.path('typescript/echo-process-features-typescript.cjs'), ]); strictEqual(result.stderr, ''); diff --git a/test/fixtures/typescript/echo-process-features-typescript.cjs b/test/fixtures/typescript/echo-process-features-typescript.cjs new file mode 100644 index 00000000000000..7f8b14e9e0440f --- /dev/null +++ b/test/fixtures/typescript/echo-process-features-typescript.cjs @@ -0,0 +1,2 @@ +'use strict'; +console.log(process.features.typescript);