Skip to content

Commit 4e58a50

Browse files
devversiondylhunn
authored andcommitted
build: update postinstall script to account for local target references in dev-infra (angular#44490)
We are in an inconvenient situation where the ng-dev package might rely on packages from the Angular framework repository. Given that we install this package in the framework repository, we need to update some references through a postinstall. This commit updates the patches to account for the latest changes in the dev-infra package/repository. PR Close angular#44490
1 parent d73c716 commit 4e58a50

File tree

1 file changed

+58
-12
lines changed

1 file changed

+58
-12
lines changed

tools/postinstall-patches.js

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,65 @@ ls('node_modules/@types').filter(f => f.startsWith('babel__')).forEach(pkg => {
6161
}
6262
});
6363

64-
log('\n# patch: use local version of @angular/* and zone.js in component_benchmark from @angular/dev-infra.-private');
65-
[['@npm//@angular/platform-browser', '@angular//packages/platform-browser'],
66-
['@npm//@angular/core', '@angular//packages/core'],
67-
[
68-
'load\\("@npm//@angular/bazel:index.bzl", "ng_module"\\)',
69-
'load\("@angular//tools:defaults.bzl", "ng_module"\)'
70-
],
71-
['@npm//zone.js', '//packages/zone.js/bundles:zone.umd.js'],
64+
log('\n# patch: use local version of @angular/* and zone.js in Starlark files from @angular/dev-infra-private');
7265

73-
].forEach(([matcher, replacement]) => {
74-
sed('-i', matcher, replacement,
75-
'node_modules/@angular/dev-infra-private/bazel/benchmark/component_benchmark/component_benchmark.bzl');
76-
});
66+
const ngDevPatches = new Map();
67+
const captureNgDevPatches = (files, patches) =>
68+
patches.forEach(p => _captureNgDevPatch(p[0], p[1], files));
69+
const _captureNgDevPatch = (search, replace, files) => {
70+
for (const fileName of files) {
71+
const currentPatches = ngDevPatches.get(fileName) ?? [];
72+
ngDevPatches.set(fileName, [...currentPatches, [search, replace]]);
73+
}
74+
};
75+
76+
// Patches for the component benchmark rule.
77+
captureNgDevPatches(
78+
[
79+
'node_modules/@angular/dev-infra-private/bazel/benchmark/component_benchmark/component_benchmark.bzl',
80+
],
81+
[
82+
['@npm//@angular/platform-browser', '@angular//packages/platform-browser'],
83+
['@npm//@angular/core', '@angular//packages/core'],
84+
['@npm//:node_modules/zone.js/bundles/zone.umd.js', '//packages/zone.js/bundles:zone.umd.js'],
85+
[
86+
'load\\("@npm//@angular/bazel:index.bzl", "ng_module"\\)',
87+
'load\("@angular//tools:defaults.bzl", "ng_module"\)'
88+
],
89+
]);
90+
91+
// Patches for the app bundling
92+
captureNgDevPatches(
93+
[
94+
'node_modules/@angular/dev-infra-private/bazel/benchmark/app_bundling/index.bzl',
95+
'node_modules/@angular/dev-infra-private/bazel/benchmark/app_bundling/esbuild.config-tmpl.mjs',
96+
],
97+
[
98+
// The app bundle config accesses the linker entry-point as well, so we need
99+
// to request it as well.
100+
[
101+
'"@npm//@angular/compiler-cli"',
102+
'"@angular//packages/compiler-cli", "@angular//packages/compiler-cli/linker/babel"'
103+
],
104+
// When these entry-points are consumed from sources within Bazel, the package exports
105+
// are not available and explicit imports (as per ECMAScript module) are needed.
106+
// This can be removed when devmode&prodmode is combined/ESM is used everywhere.
107+
[
108+
`from '@angular/compiler-cli/linker/babel'`,
109+
`from '@angular/compiler-cli/linker/babel/index.js'`
110+
],
111+
[
112+
`from '@angular/compiler-cli/private/tooling'`,
113+
`from '@angular/compiler-cli/private/tooling.js'`
114+
],
115+
]);
116+
117+
// Apply the captured patches for the `@angular/dev-infra-private` package.
118+
for (const [fileName, patches] of ngDevPatches.entries()) {
119+
for (const patch of patches) {
120+
sed('-i', patch[0], patch[1], fileName);
121+
}
122+
}
77123

78124
log('\n# patch: delete d.ts files referring to rxjs-compat');
79125
// more info in https://github.com/angular/angular/pull/33786

0 commit comments

Comments
 (0)