fix(dev-infra): ensure ts-node is registered with commonjs as module (#37217)
We recently added support for automatic registration of `ts-node` when the dev-infra configuration is loaded. In addition to registering ts-node, we should also ensure that the `commonjs` module is set up. By default, `ts-node` would use ES module imports that are not supported by default in NodeJS. PR Close #37217
This commit is contained in:
parent
cfb37b8994
commit
3e5fa56956
|
@ -7,8 +7,9 @@
|
|||
*/
|
||||
|
||||
import {existsSync} from 'fs';
|
||||
import {join} from 'path';
|
||||
import {dirname, join} from 'path';
|
||||
import {exec} from 'shelljs';
|
||||
|
||||
import {isTsNodeAvailable} from './ts-node';
|
||||
|
||||
/**
|
||||
|
@ -83,7 +84,12 @@ function readConfigFile(configPath: string): object {
|
|||
// version of the given configuration seems to exist, set up `ts-node` if available.
|
||||
if (require.extensions['.ts'] === undefined && existsSync(`${configPath}.ts`) &&
|
||||
isTsNodeAvailable()) {
|
||||
require('ts-node').register({skipProject: true, transpileOnly: true});
|
||||
// Ensure the module target is set to `commonjs`. This is necessary because the
|
||||
// dev-infra tool runs in NodeJS which does not support ES modules by default.
|
||||
// Additionally, set the `dir` option to the directory that contains the configuration
|
||||
// file. This allows for custom compiler options (such as `--strict`).
|
||||
require('ts-node').register(
|
||||
{dir: dirname(configPath), transpileOnly: true, compilerOptions: {module: 'commonjs'}});
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue