Skip to content

Commit fcc15ce

Browse files
committed
Revert "build: remove unneeded babel types postinstall patching (angular#53374)" (angular#53432)
This reverts commit 4cdd515. PR Close angular#53432
1 parent 2565121 commit fcc15ce

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

goldens/public-api/localize/tools/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
```ts
66

77
/// <reference types="@angular/compiler-cli/private/babel" />
8+
/// <reference types="@types/babel__core" />
89

910
import { AbsoluteFsPath } from '@angular/compiler-cli/private/localize';
1011
import { Element as Element_2 } from '@angular/compiler';

packages/compiler-cli/private/babel.d.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,5 @@
2020
// that is not governed by Bazel, and therefore not expected by the `strict_deps` rule.
2121
// Declaring the modules here allows `strict_deps` to always find a declaration of the modules
2222
// in an input file to the compilation, therefore accepting the module import.
23-
declare module '@babel/core' {
24-
export * from '@types/babel__core';
25-
}
26-
declare module '@babel/generator' {
27-
export { default } from '@types/babel__generator';
28-
}
23+
declare module '@babel/core' {}
24+
declare module '@babel/generator' {}

tools/postinstall-patches.js

+16
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ sed('-i', '(\'response\' in xhr)', '(\'response\' in (xhr as any))',
4545
'node_modules/rxjs/src/observable/dom/AjaxObservable.ts');
4646
*/
4747

48+
// Workaround https://github.com/bazelbuild/rules_nodejs/issues/1033
49+
// TypeScript doesn't understand typings without "declare module" unless
50+
// they are actually resolved by the @types default mechanism
51+
log('\n# patch: @types/babel__* adding declare module wrappers');
52+
ls('node_modules/@types').filter(f => f.startsWith('babel__')).forEach(pkg => {
53+
const modName = '@' + pkg.replace('__', '/');
54+
const typingsFile = `node_modules/@types/${pkg}/index.d.ts`;
55+
// Only add the patch if it is not already there.
56+
if (readFileSync(typingsFile, 'utf8').indexOf('/*added by tools/postinstall_patches.js*/') ===
57+
-1) {
58+
const insertPrefix = `/*added by tools/postinstall_patches.js*/ declare module "${modName}" { `;
59+
sed('-i', `(// Type definitions for ${modName})`, insertPrefix + '$1', typingsFile);
60+
echo('}').toEnd(typingsFile);
61+
}
62+
});
63+
4864
log('\n# patch: delete d.ts files referring to rxjs-compat');
4965
// more info in https://github.com/angular/angular/pull/33786
5066
rm('-rf', [

0 commit comments

Comments
 (0)