From 119a94ef4bc2d945277e49a03694ce99f0a481a2 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:50:38 -0500 Subject: [PATCH] build: remove unneeded babel types postinstall patching (#53441) These patches are no longer necessary with the current state of the type packages and the code within the repository. The types are now included in the already required babel.d.ts file for the relevant babel packages (currently: `@babel/core` and `@babel/generator`). PR Close #53441 --- goldens/public-api/localize/tools/index.md | 1 - packages/compiler-cli/private/babel.d.ts | 8 ++++++-- .../test/compliance/linked/BUILD.bazel | 1 + tools/postinstall-patches.js | 16 ---------------- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/goldens/public-api/localize/tools/index.md b/goldens/public-api/localize/tools/index.md index 9bd2233f402..45bd11e73e3 100644 --- a/goldens/public-api/localize/tools/index.md +++ b/goldens/public-api/localize/tools/index.md @@ -5,7 +5,6 @@ ```ts /// -/// import { AbsoluteFsPath } from '@angular/compiler-cli/private/localize'; import { Element as Element_2 } from '@angular/compiler'; diff --git a/packages/compiler-cli/private/babel.d.ts b/packages/compiler-cli/private/babel.d.ts index 0b5acaacc0e..e0edb00d243 100644 --- a/packages/compiler-cli/private/babel.d.ts +++ b/packages/compiler-cli/private/babel.d.ts @@ -20,5 +20,9 @@ // that is not governed by Bazel, and therefore not expected by the `strict_deps` rule. // Declaring the modules here allows `strict_deps` to always find a declaration of the modules // in an input file to the compilation, therefore accepting the module import. -declare module '@babel/core' {} -declare module '@babel/generator' {} +declare module '@babel/core' { + export * from '@types/babel__core'; +} +declare module '@babel/generator' { + export { default } from '@types/babel__generator'; +} diff --git a/packages/compiler-cli/test/compliance/linked/BUILD.bazel b/packages/compiler-cli/test/compliance/linked/BUILD.bazel index cbb4f209ad7..da796356b98 100644 --- a/packages/compiler-cli/test/compliance/linked/BUILD.bazel +++ b/packages/compiler-cli/test/compliance/linked/BUILD.bazel @@ -7,6 +7,7 @@ ts_library( deps = [ "//packages/compiler-cli/linker", "//packages/compiler-cli/linker/babel", + "//packages/compiler-cli/private", "//packages/compiler-cli/src/ngtsc/file_system", "//packages/compiler-cli/src/ngtsc/logging", "//packages/compiler-cli/src/ngtsc/sourcemaps", diff --git a/tools/postinstall-patches.js b/tools/postinstall-patches.js index 1cbef7d6283..5eb0416bdfa 100644 --- a/tools/postinstall-patches.js +++ b/tools/postinstall-patches.js @@ -45,22 +45,6 @@ sed('-i', '(\'response\' in xhr)', '(\'response\' in (xhr as any))', 'node_modules/rxjs/src/observable/dom/AjaxObservable.ts'); */ -// Workaround https://github.com/bazelbuild/rules_nodejs/issues/1033 -// TypeScript doesn't understand typings without "declare module" unless -// they are actually resolved by the @types default mechanism -log('\n# patch: @types/babel__* adding declare module wrappers'); -ls('node_modules/@types').filter(f => f.startsWith('babel__')).forEach(pkg => { - const modName = '@' + pkg.replace('__', '/'); - const typingsFile = `node_modules/@types/${pkg}/index.d.ts`; - // Only add the patch if it is not already there. - if (readFileSync(typingsFile, 'utf8').indexOf('/*added by tools/postinstall_patches.js*/') === - -1) { - const insertPrefix = `/*added by tools/postinstall_patches.js*/ declare module "${modName}" { `; - sed('-i', `(// Type definitions for ${modName})`, insertPrefix + '$1', typingsFile); - echo('}').toEnd(typingsFile); - } -}); - log('\n# patch: delete d.ts files referring to rxjs-compat'); // more info in https://github.com/angular/angular/pull/33786 rm('-rf', [