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

process: fix process.features.typescript when Amaro is unavailable #55323

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
49 changes: 25 additions & 24 deletions test/es-module/test-typescript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
richardlau marked this conversation as resolved.
Show resolved Hide resolved


if (!process.config.variables.node_use_amaro) skip('Requires Amaro');

test('execute a TypeScript file', async () => {
Expand Down Expand Up @@ -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);
});
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/typescript/echo-process-features-typescript.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
console.log(process.features.typescript);
Loading