Skip to content

Commit

Permalink
process: add process.features.typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev committed Aug 10, 2024
1 parent 4557c13 commit 1b1e197
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ ObjectDefineProperty(process, 'features', {
}

const { emitWarning, emitWarningSync } = require('internal/process/warning');
const { getOptionValue } = require('internal/options');

let hasTypeScriptSupport;
ObjectDefineProperty(process.features, 'typescript', {
__proto__: null,
get() {
return hasTypeScriptSupport ??= getOptionValue('--experimental-strip-types');
},
configurable: false,
enumerable: true,
});

process.emitWarning = emitWarning;
internalBinding('process_methods').setEmitWarningSync(emitWarningSync);

Expand Down
10 changes: 10 additions & 0 deletions test/es-module/test-typescript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,13 @@ test('execute a TypeScript file with CommonJS syntax requiring .mts with require
match(result.stdout, /Hello, TypeScript!/);
strictEqual(result.code, 0);
});

test('expect process.features.typescript to be true', async () => {
const result = await spawnPromisified(process.execPath, [
'--experimental-strip-types',
'-p', 'process.features.typescript',
]);

strictEqual(result.stdout, 'true\n');
strictEqual(result.code, 0);
});

0 comments on commit 1b1e197

Please sign in to comment.