Skip to content

Commit

Permalink
feat(ng-dev): remove ts-node runtime registration as it does not wo…
Browse files Browse the repository at this point in the history
…rk with ESM

TS Node cannot register itself at runtime as the ESM module resolution
cannot be intercepted from within the runtime. We solved this already by
setting up the ts-node ESM loader hooks in the Shebang.

The user of `ng-dev` can always specify a tsconfig for the configuration
by setting the `TS_NODE_PROJECT` environment variable and aliasing
`ng-dev`. This is the expected new way. NgDev will also support non-TS
written standard `.mjs` or `type: module` `.js` config files.
  • Loading branch information
devversion committed Jun 16, 2022
1 parent 55fe8f0 commit 70b51cd
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 47 deletions.
2 changes: 0 additions & 2 deletions github-actions/commit-message-based-labels/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ load("//tools:defaults.bzl", "esbuild_checked_in")
esbuild_checked_in(
name = "post",
entry_point = "//github-actions/commit-message-based-labels/lib:post.ts",
external = ["ts-node"],
deps = [
"//github-actions/commit-message-based-labels/lib",
],
Expand All @@ -12,7 +11,6 @@ esbuild_checked_in(
esbuild_checked_in(
name = "main",
entry_point = "//github-actions/commit-message-based-labels/lib:main.ts",
external = ["ts-node"],
deps = [
"//github-actions/commit-message-based-labels/lib",
],
Expand Down
8 changes: 1 addition & 7 deletions github-actions/commit-message-based-labels/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24535,8 +24535,7 @@ function parseInternal(fullText) {
}

//
import tsNode from "ts-node";
import { dirname, join } from "path";
import { join } from "path";

//
var ANSI_BACKGROUND_OFFSET = 10;
Expand Down Expand Up @@ -25287,11 +25286,6 @@ function assertValidGithubConfig(config) {
}
}
async function readConfigFile(configPath, returnEmptyObjectOnError = false) {
tsNode.register({
dir: dirname(configPath),
esm: true,
transpileOnly: true
});
try {
return await import(configPath);
} catch (e) {
Expand Down
2 changes: 0 additions & 2 deletions github-actions/slash-commands/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package(default_visibility = ["//github-actions/slash-commands:__subpackages__"]
esbuild_checked_in(
name = "main",
entry_point = "//github-actions/slash-commands/lib:main.ts",
external = ["ts-node"],
deps = [
"//github-actions/slash-commands/lib",
],
Expand All @@ -14,7 +13,6 @@ esbuild_checked_in(
esbuild_checked_in(
name = "post",
entry_point = "//github-actions/slash-commands/lib:post.ts",
external = ["ts-node"],
deps = [
"//github-actions/slash-commands/lib",
],
Expand Down
8 changes: 1 addition & 7 deletions github-actions/slash-commands/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60973,8 +60973,7 @@ function getCommitsInRange(from, to = "HEAD") {
}

//
import tsNode from "ts-node";
import { dirname, join } from "path";
import { join } from "path";

//
var ANSI_BACKGROUND_OFFSET = 10;
Expand Down Expand Up @@ -61739,11 +61738,6 @@ function assertValidGithubConfig(config) {
}
}
async function readConfigFile(configPath, returnEmptyObjectOnError = false) {
tsNode.register({
dir: dirname(configPath),
esm: true,
transpileOnly: true
});
try {
return await import(configPath);
} catch (e2) {
Expand Down
2 changes: 0 additions & 2 deletions ng-dev/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ load("//tools:defaults.bzl", "esbuild_esm_bundle", "ts_library")
load("//bazel:extract_types.bzl", "extract_types")

NG_DEV_EXTERNALS = [
# `ts-node` is optional for users who write their configurations in TypeScript.
"ts-node",
# `typescript` is external because we want the project to provide a TypeScript version.
# TODO: Figure out how we want to manage dependencies for the dev-infra tool.
"typescript",
Expand Down
1 change: 0 additions & 1 deletion ng-dev/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ts_library(
"@npm//inquirer",
"@npm//semver",
"@npm//supports-color",
"@npm//ts-node",
"@npm//typed-graphqlify",
"@npm//which",
"@npm//yaml",
Expand Down
18 changes: 3 additions & 15 deletions ng-dev/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import tsNode from 'ts-node';

import {dirname, join} from 'path';
import {join} from 'path';
import {Assertions, MultipleAssertions} from './config-assertions.js';

import {Log} from './logging.js';
Expand Down Expand Up @@ -153,20 +151,10 @@ export function assertValidGithubConfig<T extends NgDevConfig>(
}

/**
* Resolves and reads the specified configuration file, optionally returning an empty object if the
* configuration file cannot be read.
* Resolves and reads the specified configuration file, optionally returning an empty object
* if the configuration file cannot be read.
*/
async function readConfigFile(configPath: string, returnEmptyObjectOnError = false): Promise<{}> {
// 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),
esm: true,
transpileOnly: true,
});

try {
return await import(configPath);
} catch (e) {
Expand Down
2 changes: 0 additions & 2 deletions tools/local-actions/changelog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ load("//tools:defaults.bzl", "esbuild_checked_in")
esbuild_checked_in(
name = "post",
entry_point = "//tools/local-actions/changelog/lib:post.ts",
external = ["ts-node"],
deps = [
"//tools/local-actions/changelog/lib",
],
Expand All @@ -12,7 +11,6 @@ esbuild_checked_in(
esbuild_checked_in(
name = "main",
entry_point = "//tools/local-actions/changelog/lib:main.ts",
external = ["ts-node"],
deps = [
"//tools/local-actions/changelog/lib",
],
Expand Down
12 changes: 3 additions & 9 deletions tools/local-actions/changelog/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13045,10 +13045,10 @@ var require_ejs = __commonJS({
exports.localsName = _DEFAULT_LOCALS_NAME;
exports.promiseImpl = new Function("return this;")().Promise;
exports.resolveInclude = function(name, filename, isDir) {
var dirname2 = path.dirname;
var dirname = path.dirname;
var extname = path.extname;
var resolve = path.resolve;
var includePath = resolve(isDir ? filename : dirname2(filename), name);
var includePath = resolve(isDir ? filename : dirname(filename), name);
var ext = extname(name);
if (!ext) {
includePath += ".ejs";
Expand Down Expand Up @@ -59277,8 +59277,7 @@ var DryRunError = class extends Error {
};

//
import tsNode from "ts-node";
import { dirname, join } from "path";
import { join } from "path";

//
var cachedConfig = null;
Expand Down Expand Up @@ -59335,11 +59334,6 @@ function assertValidGithubConfig(config2) {
}
}
async function readConfigFile(configPath, returnEmptyObjectOnError = false) {
tsNode.register({
dir: dirname(configPath),
esm: true,
transpileOnly: true
});
try {
return await import(configPath);
} catch (e) {
Expand Down

0 comments on commit 70b51cd

Please sign in to comment.