豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit feba54c

Browse files
committed
feat(ng-dev): always require ts-node to be available
As part of our ESM change we should avoid the dynamic import and just use `ts-node` as a normal import. We expect our ng-dev users to always have their configs written in TS anyway.
1 parent 07fdaca commit feba54c

File tree

3 files changed

+12
-37
lines changed

3 files changed

+12
-37
lines changed

ng-dev/utils/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ts_library(
3737
"@npm//inquirer",
3838
"@npm//semver",
3939
"@npm//supports-color",
40+
"@npm//ts-node",
4041
"@npm//typed-graphqlify",
4142
"@npm//which",
4243
"@npm//yaml",

ng-dev/utils/config.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import tsNode from 'ts-node';
10+
911
import {dirname, join} from 'path';
1012
import {Assertions, MultipleAssertions} from './assertion-typings';
1113

@@ -36,9 +38,6 @@ export interface GithubConfig {
3638
*/
3739
const CONFIG_FILE_PATH = '.ng-dev/config';
3840

39-
/** The configuration for ng-dev. */
40-
let cachedConfig: {} | null = null;
41-
4241
/**
4342
* The filename expected for local user config, without the file extension to allow a typescript,
4443
* javascript or json file to be used.
@@ -147,23 +146,15 @@ export function assertValidGithubConfig<T>(
147146
* configuration file cannot be read.
148147
*/
149148
function readConfigFile(configPath: string, returnEmptyObjectOnError = false): {} {
150-
// If the `.ts` extension has not been set up already, and a TypeScript based
151-
// version of the given configuration seems to exist, set up `ts-node` if available.
152-
if (
153-
require.extensions['.ts'] === undefined &&
154-
existsSync(`${configPath}.ts`) &&
155-
isTsNodeAvailable()
156-
) {
157-
// Ensure the module target is set to `commonjs`. This is necessary because the
158-
// dev-infra tool runs in NodeJS which does not support ES modules by default.
159-
// Additionally, set the `dir` option to the directory that contains the configuration
160-
// file. This allows for custom compiler options (such as `--strict`).
161-
require('ts-node').register({
162-
dir: dirname(configPath),
163-
transpileOnly: true,
164-
compilerOptions: {module: 'commonjs'},
165-
});
166-
}
149+
// Ensure the module target is set to `commonjs`. This is necessary because the
150+
// dev-infra tool runs in NodeJS which does not support ES modules by default.
151+
// Additionally, set the `dir` option to the directory that contains the configuration
152+
// file. This allows for custom compiler options (such as `--strict`).
153+
tsNode.register({
154+
dir: dirname(configPath),
155+
transpileOnly: true,
156+
compilerOptions: {module: 'commonjs'},
157+
});
167158

168159
try {
169160
return require(configPath);

ng-dev/utils/ts-node.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)