Skip to content

Commit

Permalink
feat(ng-dev): always require ts-node to be available
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devversion committed Jun 16, 2022
1 parent 07fdaca commit feba54c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
1 change: 1 addition & 0 deletions ng-dev/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ts_library(
"@npm//inquirer",
"@npm//semver",
"@npm//supports-color",
"@npm//ts-node",
"@npm//typed-graphqlify",
"@npm//which",
"@npm//yaml",
Expand Down
31 changes: 11 additions & 20 deletions ng-dev/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import tsNode from 'ts-node';

import {dirname, join} from 'path';
import {Assertions, MultipleAssertions} from './assertion-typings';

Expand Down Expand Up @@ -36,9 +38,6 @@ export interface GithubConfig {
*/
const CONFIG_FILE_PATH = '.ng-dev/config';

/** The configuration for ng-dev. */
let cachedConfig: {} | null = null;

/**
* The filename expected for local user config, without the file extension to allow a typescript,
* javascript or json file to be used.
Expand Down Expand Up @@ -147,23 +146,15 @@ export function assertValidGithubConfig<T>(
* configuration file cannot be read.
*/
function readConfigFile(configPath: string, returnEmptyObjectOnError = false): {} {
// If the `.ts` extension has not been set up already, and a TypeScript based
// version of the given configuration seems to exist, set up `ts-node` if available.
if (
require.extensions['.ts'] === undefined &&
existsSync(`${configPath}.ts`) &&
isTsNodeAvailable()
) {
// 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'},
});
}
// 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`).
tsNode.register({
dir: dirname(configPath),
transpileOnly: true,
compilerOptions: {module: 'commonjs'},
});

try {
return require(configPath);
Expand Down
17 changes: 0 additions & 17 deletions ng-dev/utils/ts-node.ts

This file was deleted.

0 comments on commit feba54c

Please sign in to comment.