Skip to content

Commit 4009a2f

Browse files
committed
process: add process.features.typescript
1 parent 4557c13 commit 4009a2f

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/internal/bootstrap/node.js

+12
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,18 @@ ObjectDefineProperty(process, 'features', {
319319
}
320320

321321
const { emitWarning, emitWarningSync } = require('internal/process/warning');
322+
const { getOptionValue } = require('internal/options');
323+
324+
let hasTypeScriptSupport;
325+
ObjectDefineProperty(process.features, 'typescript', {
326+
__proto__: null,
327+
get() {
328+
return hasTypeScriptSupport ??= !!getOptionValue('--experimental-strip-types');
329+
},
330+
configurable: false,
331+
enumerable: true,
332+
});
333+
322334
process.emitWarning = emitWarning;
323335
internalBinding('process_methods').setEmitWarningSync(emitWarningSync);
324336

test/es-module/test-typescript.mjs

+11
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,14 @@ test('execute a TypeScript file with CommonJS syntax requiring .mts with require
313313
match(result.stdout, /Hello, TypeScript!/);
314314
strictEqual(result.code, 0);
315315
});
316+
317+
test('expect process.features.typescript to be a boolean that reflects the value of --experimental-strip-types', async () => {
318+
const result = await spawnPromisified(process.execPath, [
319+
'--experimental-strip-types',
320+
'-p', 'process.features.typescript',
321+
]);
322+
323+
strictEqual(result.stdout, 'true\n');
324+
strictEqual(result.code, 0);
325+
strictEqual(process.features.typescript, false);
326+
});

test/parallel/test-process-features.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ assert.deepStrictEqual(keys, new Set([
1515
'tls_ocsp',
1616
'tls',
1717
'cached_builtins',
18+
'typescript',
1819
]));
1920

2021
for (const key of keys) {

0 commit comments

Comments
 (0)