From 70b51cd7edf7128ba6c6f29911e28f0c7922f8cc Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 10 Jun 2022 17:36:44 +0000 Subject: [PATCH] feat(ng-dev): remove `ts-node` runtime registration as it does not work 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. --- .../commit-message-based-labels/BUILD.bazel | 2 -- .../commit-message-based-labels/main.js | 8 +------- github-actions/slash-commands/BUILD.bazel | 2 -- github-actions/slash-commands/main.js | 8 +------- ng-dev/BUILD.bazel | 2 -- ng-dev/utils/BUILD.bazel | 1 - ng-dev/utils/config.ts | 18 +++--------------- tools/local-actions/changelog/BUILD.bazel | 2 -- tools/local-actions/changelog/main.js | 12 +++--------- 9 files changed, 8 insertions(+), 47 deletions(-) diff --git a/github-actions/commit-message-based-labels/BUILD.bazel b/github-actions/commit-message-based-labels/BUILD.bazel index d8806576a..ce611384e 100644 --- a/github-actions/commit-message-based-labels/BUILD.bazel +++ b/github-actions/commit-message-based-labels/BUILD.bazel @@ -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", ], @@ -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", ], diff --git a/github-actions/commit-message-based-labels/main.js b/github-actions/commit-message-based-labels/main.js index d41131541..c8b83f9b5 100644 --- a/github-actions/commit-message-based-labels/main.js +++ b/github-actions/commit-message-based-labels/main.js @@ -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; @@ -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) { diff --git a/github-actions/slash-commands/BUILD.bazel b/github-actions/slash-commands/BUILD.bazel index c72be1f45..c116d3d47 100644 --- a/github-actions/slash-commands/BUILD.bazel +++ b/github-actions/slash-commands/BUILD.bazel @@ -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", ], @@ -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", ], diff --git a/github-actions/slash-commands/main.js b/github-actions/slash-commands/main.js index 170a08ae9..1c68dbe54 100644 --- a/github-actions/slash-commands/main.js +++ b/github-actions/slash-commands/main.js @@ -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; @@ -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) { diff --git a/ng-dev/BUILD.bazel b/ng-dev/BUILD.bazel index bc0d30242..424dee207 100644 --- a/ng-dev/BUILD.bazel +++ b/ng-dev/BUILD.bazel @@ -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", diff --git a/ng-dev/utils/BUILD.bazel b/ng-dev/utils/BUILD.bazel index a6154d0c9..236e647fe 100644 --- a/ng-dev/utils/BUILD.bazel +++ b/ng-dev/utils/BUILD.bazel @@ -37,7 +37,6 @@ ts_library( "@npm//inquirer", "@npm//semver", "@npm//supports-color", - "@npm//ts-node", "@npm//typed-graphqlify", "@npm//which", "@npm//yaml", diff --git a/ng-dev/utils/config.ts b/ng-dev/utils/config.ts index 4bbb91e41..4a32288d3 100644 --- a/ng-dev/utils/config.ts +++ b/ng-dev/utils/config.ts @@ -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'; @@ -153,20 +151,10 @@ export function assertValidGithubConfig( } /** - * 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) { diff --git a/tools/local-actions/changelog/BUILD.bazel b/tools/local-actions/changelog/BUILD.bazel index 000624015..837ef5581 100644 --- a/tools/local-actions/changelog/BUILD.bazel +++ b/tools/local-actions/changelog/BUILD.bazel @@ -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", ], @@ -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", ], diff --git a/tools/local-actions/changelog/main.js b/tools/local-actions/changelog/main.js index f24744210..02c9a2097 100644 --- a/tools/local-actions/changelog/main.js +++ b/tools/local-actions/changelog/main.js @@ -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"; @@ -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; @@ -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) {