Skip to content

Commit 632c28a

Browse files
josephperrottalan-agius4
authored andcommitted
fix(ng-dev): properly load typescript configuration files (#3048)
Properly load typescript configuration files by registering tsx to transpile the files at load time PR Close #3048
1 parent ba37a2d commit 632c28a

File tree

8 files changed

+18765
-6610
lines changed

8 files changed

+18765
-6610
lines changed

.github/local-actions/branch-manager/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ esbuild_checked_in(
3131
":lib",
3232
],
3333
entry_point = "lib/main.ts",
34+
external = [
35+
"pnpapi",
36+
],
3437
format = "esm",
3538
platform = "node",
3639
target = "node22",

.github/local-actions/branch-manager/main.js

Lines changed: 18743 additions & 6602 deletions
Large diffs are not rendered by default.

ng-dev/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ NG_DEV_EXTERNALS = [
3434
# intend to provide interop globals for this as it could hide other significant issues.
3535
"@yarnpkg/lockfile",
3636
"@google-cloud/spanner",
37+
"tsx",
3738
]
3839

3940
ts_project(

ng-dev/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"semver": "7.7.2",
6767
"supports-color": "10.2.2",
6868
"typed-graphqlify": "3.1.6",
69+
"tsx": "4.20.5",
6970
"typescript": "5.9.2",
7071
"utf-8-validate": "6.0.5",
7172
"which": "5.0.0",

ng-dev/utils/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ ts_project(
6060
"//ng-dev:node_modules/@types/yarnpkg__lockfile",
6161
"//ng-dev:node_modules/@yarnpkg/lockfile",
6262
"//ng-dev:node_modules/chalk",
63+
"//ng-dev:node_modules/fast-glob",
6364
"//ng-dev:node_modules/semver",
6465
"//ng-dev:node_modules/supports-color",
66+
"//ng-dev:node_modules/tsx",
6567
"//ng-dev:node_modules/typed-graphqlify",
6668
"//ng-dev:node_modules/which",
6769
"//ng-dev:node_modules/yaml",

ng-dev/utils/config.ts

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

9-
import {pathToFileURL} from 'url';
109
import {join} from 'path';
11-
10+
import glob from 'fast-glob';
11+
import {register} from 'tsx/esm/api';
1212
import {Assertions, MultipleAssertions} from './config-assertions.js';
1313
import {Log} from './logging.js';
1414
import {getCachedConfig, setCachedConfig} from './config-cache.js';
1515
import {determineRepoBaseDirFromCwd} from './repo-directory.js';
16+
import {pathToFileURL} from 'url';
1617

1718
/**
1819
* Type describing a ng-dev configuration.
@@ -81,7 +82,7 @@ export interface CaretakerConfig {
8182
* The filename expected for creating the ng-dev config, without the file
8283
* extension to allow either a typescript or javascript file to be used.
8384
*/
84-
const CONFIG_FILE_PATH = '.ng-dev/config.mjs';
85+
const CONFIG_FILE_PATH_MATCHER = '.ng-dev/config.{mjs,mts}';
8586

8687
/**
8788
* The filename expected for local user config, without the file extension to allow a typescript,
@@ -118,9 +119,12 @@ export async function getConfig(baseDirOrAssertions?: unknown) {
118119
baseDir = determineRepoBaseDirFromCwd();
119120
}
120121

122+
/** The configuration file discovered based on a glob match. */
123+
const [matchedFile] = await glob(CONFIG_FILE_PATH_MATCHER, {cwd: baseDir});
124+
121125
// If the global config is not defined, load it from the file system.
122126
// The full path to the configuration file.
123-
const configPath = join(baseDir, CONFIG_FILE_PATH);
127+
const configPath = join(baseDir, matchedFile);
124128
// Read the configuration and validate it before caching it for the future.
125129
cachedConfig = await readConfigFile(configPath);
126130

@@ -204,6 +208,7 @@ export function assertValidCaretakerConfig<T extends NgDevConfig>(
204208
* if the configuration file cannot be read.
205209
*/
206210
async function readConfigFile(configPath: string, returnEmptyObjectOnError = false): Promise<{}> {
211+
const unregister = register({tsconfig: false});
207212
try {
208213
// ESM imports expect a valid URL. On Windows, the disk name causes errors like:
209214
// `ERR_UNSUPPORTED_ESM_URL_SCHEME: <..> Received protocol 'c:'`
@@ -219,5 +224,7 @@ async function readConfigFile(configPath: string, returnEmptyObjectOnError = fal
219224
Log.error(`Could not read configuration file at ${configPath}.`);
220225
Log.error(e);
221226
process.exit(1);
227+
} finally {
228+
unregister();
222229
}
223230
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/local-dev.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ bazelCommand=${BAZEL:-"pnpm bazel"}
1717
${bazelCommand} build ng-dev:npm_package
1818
)
1919

20-
export TS_NODE_TRANSPILE_ONLY=1
21-
export TS_NODE_PROJECT=${PWD}/.ng-dev/tsconfig.json
22-
2320
# Execute the built ng-dev command in the current working directory
2421
# and pass-through arguments unmodified.
25-
${devInfraProjectDir}/node_modules/.bin/tsx ${ngDevBinFile} ${@}
22+
${ngDevBinFile} ${@}

0 commit comments

Comments
 (0)