Skip to content

Commit

Permalink
build: remove unneeded babel types postinstall patching (angular#53374)
Browse files Browse the repository at this point in the history
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`).
  • Loading branch information
clydin committed Dec 8, 2023
1 parent e866b8d commit 9fd1725
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
1 change: 0 additions & 1 deletion goldens/public-api/localize/tools/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
```ts

/// <reference types="@angular/compiler-cli/private/babel" />
/// <reference types="@types/babel__core" />

import { AbsoluteFsPath } from '@angular/compiler-cli/private/localize';
import { Element as Element_2 } from '@angular/compiler';
Expand Down
8 changes: 6 additions & 2 deletions packages/compiler-cli/private/babel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
16 changes: 0 additions & 16 deletions tools/postinstall-patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down

0 comments on commit 9fd1725

Please sign in to comment.