-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Indicate typescript support in process.features
#54294
Comments
You can check it by accessing and checking process.argv - https://nodejs.org/docs/latest/api/process.html#processargv |
Node-specifc options are not present in
Writing such a check currently would be clumsy and break if the experimental prefix is removed or the option is enabled by default: const supportsTypescript = (process.env.NODE_OPTIONS ?? "").split(/\s+/).includes("--experimental-strip-types") || process.execArgv.includes("--experimental-strip-types"); |
As for my use case of loading a config file, I think I don't strictly need this given that async function loadConfig(rootDir: string): Promise<Record<string, any>> {
let config: Record<string, any> = {};
try {
({default: config} = await Promise.any(["mod.config.ts", "mod.config.js"].map(file => {
return import(path.join(rootDir, file));
})));
} catch {}
return config;
} |
I think this can still be easily supported on userland with a single line:
|
This works now, but it's bound to break once the |
What is the problem this feature will solve?
Command line applications that want to load typescript configuration files should be able to detect whether the current node process is able to import typescript files to avoid an error during async
import
.What is the feature you are proposing to solve the problem?
Add boolean value
process.features.typescript
to indicate whether--experimental-strip-types
is enabled.What alternatives have you considered?
It's possible to check for the presence of
--experimental-strip-types
in eitherprocess.execArgv
orprocess.env.NODE_OPTIONS
, but doing so is quite cumbersome.The text was updated successfully, but these errors were encountered: