Repository: nodejs/node
Pull request: process: fix `process.features.typescript` when Amaro is unavailable

Fixes: https://github.com/nodejs/node/pull/55320#issuecomment-2400184367

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: lib/internal/bootstrap/node.js
patch: @@ -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', {

filename: test/es-module/test-typescript.mjs
patch: @@ -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',
+    fixtures.path('typescript/echo-process-features-typescript.cjs'),
+  ]);
+
+  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',
+    fixtures.path('typescript/echo-process-features-typescript.cjs'),
+  ]);
+
+  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, 'strip\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, 'transform\n');
-  strictEqual(result.code, 0);
-});
-
 test('expect process.features.typescript to be false without type-stripping', async () => {
   strictEqual(process.features.typescript, false);
 });

filename: test/fixtures/typescript/echo-process-features-typescript.cjs
patch: @@ -0,0 +1,2 @@
+'use strict';
+console.log(process.features.typescript);