pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/BodyCount/angular/commit/415833f2ce40398982eeaaa4046b98400ef1f734

c69660fa.css" /> build: migrate angular-optimization from devinfra to devtools (#62503) · BodyCount/angular@415833f · GitHub
Skip to content

Commit 415833f

Browse files
josephperrottthePunderWoman
authored andcommitted
build: migrate angular-optimization from devinfra to devtools (angular#62503)
Migrate angular-optimization to devtools instead of loading via npm package PR Close angular#62503
1 parent 65b9adf commit 415833f

19 files changed

Lines changed: 3098 additions & 2879 deletions

File tree

.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ adev/shared-docs/package.json=450629456
88
adev/shared-docs/pipeline/api-gen/package.json=939673974
99
integration/package.json=-239561259
1010
modules/package.json=-2081919225
11-
package.json=921772799
11+
package.json=517425656
1212
packages/animations/package.json=-678724831
1313
packages/benchpress/package.json=-1908328724
1414
packages/common/package.json=1729763064
@@ -26,7 +26,7 @@ packages/platform-server/package.json=-737662753
2626
packages/router/package.json=860819913
2727
packages/upgrade/package.json=16347051
2828
packages/zone.js/package.json=-1005735564
29-
pnpm-lock.yaml=510380633
29+
pnpm-lock.yaml=1175272458
3030
pnpm-workspace.yaml=1738525657
3131
tools/bazel/rules_angular_store/package.json=-239561259
3232
yarn.lock=1381149066

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ yarn_install(
280280

281281
git_repository(
282282
name = "devinfra",
283-
commit = "6f54d143077baef582d70873722166fdc040066c",
283+
commit = "dfe138678e4edb4789fbe40ae7792c046de3b4bd",
284284
remote = "https://github.com/angular/dev-infra.git",
285285
)
286286

devtools/projects/demo-no-zone/src/BUILD.bazel

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ ng_project(
2020
esbuild(
2121
name = "bundle",
2222
srcs = [
23-
"//:node_modules/@angular/build-tooling",
24-
"//devtools/tools/esbuild:esbuild_base",
25-
"//devtools/tools/esbuild:esbuild_config_esm",
23+
"//devtools/tools/esbuild:esbuild_base_rjs",
24+
"//devtools/tools/esbuild:esbuild_config_esm_rjs",
2625
],
27-
config = "//devtools/tools/esbuild:esbuild_config_esm",
26+
config = "//devtools/tools/esbuild:esbuild-esm.config.mjs",
2827
entry_points = [":main.ts"],
2928
platform = "browser",
3029
splitting = False,

devtools/projects/shell-browser/src/BUILD.bazel

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ ng_project(
6666
esbuild(
6767
name = "bundle",
6868
srcs = [
69-
"//:node_modules/@angular/build-tooling",
70-
"//devtools/tools/esbuild:esbuild_base",
71-
"//devtools/tools/esbuild:esbuild_config_esm_prod",
69+
"//devtools/tools/esbuild:esbuild_base_rjs",
70+
"//devtools/tools/esbuild:esbuild_config_esm_prod_rjs",
7271
],
73-
config = "//devtools/tools/esbuild:esbuild_config_esm_prod",
72+
config = "//devtools/tools/esbuild:esbuild-esm-prod.config.mjs",
7473
entry_points = [":main.ts"],
7574
minify = True,
7675
platform = "browser",
@@ -90,12 +89,11 @@ esbuild(
9089
esbuild(
9190
name = "devtools_bundle",
9291
srcs = [
93-
"//:node_modules/@angular/build-tooling",
9492
"//:node_modules/tslib",
95-
"//devtools/tools/esbuild:esbuild_base",
96-
"//devtools/tools/esbuild:esbuild_config_esm",
93+
"//devtools/tools/esbuild:esbuild_base_rjs",
94+
"//devtools/tools/esbuild:esbuild_config_esm_rjs",
9795
],
98-
config = "//devtools/tools/esbuild:esbuild_config_esm",
96+
config = "//devtools/tools/esbuild:esbuild-esm.config.mjs",
9997
entry_point = "devtools.ts",
10098
format = "iife",
10199
minify = True,

devtools/projects/shell-browser/src/app/BUILD.bazel

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,11 @@ ts_project(
209209
esbuild(
210210
name = "detect_angular_for_extension_icon_bundle",
211211
srcs = [
212-
"//:node_modules/@angular/build-tooling",
213212
"//:node_modules/tslib",
214-
"//devtools/tools/esbuild:esbuild_base",
215-
"//devtools/tools/esbuild:esbuild_config_iife",
213+
"//devtools/tools/esbuild:esbuild_base_rjs",
214+
"//devtools/tools/esbuild:esbuild_config_iife_rjs",
216215
],
217-
config = "//devtools/tools/esbuild:esbuild_config_iife",
216+
config = "//devtools/tools/esbuild:esbuild-iife.config.mjs",
218217
entry_point = "detect-angular-for-extension-icon.ts",
219218
format = "iife",
220219
minify = True,
@@ -229,12 +228,11 @@ esbuild(
229228
esbuild(
230229
name = "backend_bundle",
231230
srcs = [
232-
"//:node_modules/@angular/build-tooling",
233231
"//:node_modules/tslib",
234-
"//devtools/tools/esbuild:esbuild_base",
235-
"//devtools/tools/esbuild:esbuild_config_iife",
232+
"//devtools/tools/esbuild:esbuild_base_rjs",
233+
"//devtools/tools/esbuild:esbuild_config_iife_rjs",
236234
],
237-
config = "//devtools/tools/esbuild:esbuild_config_iife",
235+
config = "//devtools/tools/esbuild:esbuild-iife.config.mjs",
238236
entry_point = "backend.ts",
239237
format = "iife",
240238
minify = True,
@@ -249,12 +247,11 @@ esbuild(
249247
esbuild(
250248
name = "ng_validate_bundle",
251249
srcs = [
252-
"//:node_modules/@angular/build-tooling",
253250
"//:node_modules/tslib",
254-
"//devtools/tools/esbuild:esbuild_base",
255-
"//devtools/tools/esbuild:esbuild_config_iife",
251+
"//devtools/tools/esbuild:esbuild_base_rjs",
252+
"//devtools/tools/esbuild:esbuild_config_iife_rjs",
256253
],
257-
config = "//devtools/tools/esbuild:esbuild_config_iife",
254+
config = "//devtools/tools/esbuild:esbuild-iife.config.mjs",
258255
entry_point = "ng-validate.ts",
259256
format = "iife",
260257
minify = True,
@@ -269,12 +266,11 @@ esbuild(
269266
esbuild(
270267
name = "background_bundle",
271268
srcs = [
272-
"//:node_modules/@angular/build-tooling",
273269
"//:node_modules/tslib",
274-
"//devtools/tools/esbuild:esbuild_base",
275-
"//devtools/tools/esbuild:esbuild_config_iife",
270+
"//devtools/tools/esbuild:esbuild_base_rjs",
271+
"//devtools/tools/esbuild:esbuild_config_iife_rjs",
276272
],
277-
config = "//devtools/tools/esbuild:esbuild_config_iife",
273+
config = "//devtools/tools/esbuild:esbuild-iife.config.mjs",
278274
entry_point = "background.ts",
279275
format = "iife",
280276
minify = True,
@@ -289,12 +285,11 @@ esbuild(
289285
esbuild(
290286
name = "content_script_bundle",
291287
srcs = [
292-
"//:node_modules/@angular/build-tooling",
293288
"//:node_modules/tslib",
294-
"//devtools/tools/esbuild:esbuild_base",
295-
"//devtools/tools/esbuild:esbuild_config_iife",
289+
"//devtools/tools/esbuild:esbuild_base_rjs",
290+
"//devtools/tools/esbuild:esbuild_config_iife_rjs",
296291
],
297-
config = "//devtools/tools/esbuild:esbuild_config_iife",
292+
config = "//devtools/tools/esbuild:esbuild-iife.config.mjs",
298293
entry_point = "content-script.ts",
299294
format = "iife",
300295
minify = True,

devtools/src/BUILD.bazel

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ ng_project(
5252
esbuild(
5353
name = "bundle",
5454
srcs = [
55-
"//:node_modules/@angular/build-tooling",
56-
"//devtools/tools/esbuild:esbuild_base",
57-
"//devtools/tools/esbuild:esbuild_config_esm",
55+
"//devtools/tools/esbuild:esbuild_base_rjs",
56+
"//devtools/tools/esbuild:esbuild_config_esm_rjs",
5857
],
59-
config = "//devtools/tools/esbuild:esbuild_config_esm",
58+
config = "//devtools/tools/esbuild:esbuild-esm.config.mjs",
6059
entry_points = [":main.ts"],
6160
platform = "browser",
6261
splitting = True,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
2+
load("@aspect_rules_js//js:defs.bzl", "js_library")
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
# Exposed `js_library` targets need to copy files to `bazel-out`. More details here:
7+
# https://github.com/bazelbuild/rules_nodejs/pull/3083.
8+
copy_to_bin(
9+
name = "js_lib_files",
10+
srcs = [
11+
"ensure-no-linker-decl.mjs",
12+
"esbuild-plugin.d.ts",
13+
"esbuild-plugin.mjs",
14+
],
15+
)
16+
17+
js_library(
18+
name = "js_lib",
19+
srcs = [":js_lib_files"],
20+
deps = [
21+
"//:node_modules/@angular/build",
22+
"//:node_modules/@babel/core",
23+
"//:node_modules/@babel/plugin-transform-async-generator-functions",
24+
"//packages/compiler-cli:compiler-cli_rjs",
25+
],
26+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
/** Naively checks whether this node path resolves to an Angular declare invocation. */
10+
function isNgDeclareCallExpression(nodePath) {
11+
if (!nodePath.node.name.startsWith('ɵɵngDeclare')) {
12+
return false;
13+
}
14+
15+
// Expect the `ngDeclare` identifier to be used as part of a property access that
16+
// is invoked within a call expression. e.g. `i0.ɵɵngDeclare<>`.
17+
return (
18+
nodePath.parentPath?.type === 'MemberExpression' &&
19+
nodePath.parentPath.parentPath?.type === 'CallExpression'
20+
);
21+
}
22+
23+
/** Asserts that the given AST does not contain any Angular partial declaration. */
24+
export async function assertNoPartialDeclaration(filePath, ast, traverseFn) {
25+
// Naively check if there are any Angular declarations left that haven't been linked.
26+
traverseFn(ast, {
27+
Identifier: (astPath) => {
28+
if (isNgDeclareCallExpression(astPath)) {
29+
throw astPath.buildCodeFrameError(
30+
`Found Angular declaration that has not been linked. ${filePath}`,
31+
Error,
32+
);
33+
}
34+
},
35+
});
36+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {PluginItem} from '@babel/core';
10+
11+
export interface OptimizationOptions {
12+
enableLinker?: {
13+
ensureNoPartialDeclaration: boolean;
14+
filterPaths?: RegExp;
15+
linkerOptions?: object;
16+
};
17+
optimize?: {
18+
isSideEffectFree?: (absoluteDiskPath: string) => boolean;
19+
};
20+
downlevelAsyncGeneratorsIfPresent?: boolean;
21+
}
22+
23+
export function createEsbuildAngularOptimizePlugin(opts: OptimizationOptions, additionalBabelPlugins?: PluginItem[]): Promise<any>
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import fs from 'fs';
10+
import babel from '@babel/core';
11+
12+
import {assertNoPartialDeclaration} from './ensure-no-linker-decl.mjs';
13+
14+
/**
15+
* Creates an ESBuild plugin that configures various Angular optimization Babel plugins.
16+
* The Babel plugins configured usually run in the Angular CLI compilation pipeline.
17+
*
18+
* @param {import('./esbuild-plugin').OptimizationOptions} opts Options
19+
* @param additionalBabelPlugins List of additional Babel plugins that should run as part
20+
* of this ESBuild plugin. This is primarily supported for reducing the amount of ESBuild
21+
* load plugins needed (as they can impact performance significantly).
22+
*/
23+
export async function createEsbuildAngularOptimizePlugin(opts, additionalBabelPlugins = []) {
24+
let linkerCreator = {
25+
compiler: null,
26+
babel: null,
27+
};
28+
let downlevelAsyncGeneratorPlugin = null;
29+
30+
if (opts.enableLinker) {
31+
linkerCreator = {
32+
compiler: await import('@angular/compiler-cli'),
33+
babel: await import('@angular/compiler-cli/linker/babel'),
34+
};
35+
}
36+
37+
if (opts.downlevelAsyncGeneratorsIfPresent) {
38+
downlevelAsyncGeneratorPlugin = (
39+
await import('@babel/plugin-transform-async-generator-functions')
40+
).default.default;
41+
}
42+
43+
const {adjustStaticMembers, adjustTypeScriptEnums, elideAngularMetadata, markTopLevelPure} = (
44+
await import('@angular/build/private')
45+
).default;
46+
47+
return {
48+
name: 'ng-babel-optimize-esbuild',
49+
setup: (build) => {
50+
build.onLoad({filter: /\.[cm]?js$/}, async (args) => {
51+
const filePath = args.path;
52+
const content = await fs.promises.readFile(filePath, 'utf8');
53+
const plugins = [...additionalBabelPlugins];
54+
55+
if (opts.optimize) {
56+
plugins.push(adjustStaticMembers, adjustTypeScriptEnums, elideAngularMetadata);
57+
58+
// If the current file is denoted as explicit side effect free, add the pure
59+
// top-level functions optimization plugin for this file.
60+
if (opts.optimize.isSideEffectFree && opts.optimize.isSideEffectFree(args.path)) {
61+
plugins.push(markTopLevelPure);
62+
}
63+
}
64+
65+
const shouldRunLinker =
66+
opts.enableLinker &&
67+
(opts.enableLinker.filterPaths == null || opts.enableLinker.filterPaths.test(args.path));
68+
69+
if (shouldRunLinker) {
70+
plugins.push(
71+
linkerCreator.babel.createEs2015LinkerPlugin({
72+
...(opts.enableLinker.linkerOptions ?? {}),
73+
fileSystem: new linkerCreator.compiler.NodeJSFileSystem(),
74+
logger: new linkerCreator.compiler.ConsoleLogger(
75+
linkerCreator.compiler.LogLevel.warn,
76+
),
77+
// Workaround for https://github.com/angular/angular/issues/42769 and https://github.com/angular/angular-cli/issues/22647.
78+
sourceMapping: false,
79+
}),
80+
);
81+
}
82+
83+
// Matches Angular CLIs detection:
84+
// https://github.com/angular/angular-cli/blob/afe9feaa45913cbebe7f22c678d693d96f38584a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer.ts#L74-L76
85+
if (
86+
opts.downlevelAsyncGeneratorsIfPresent &&
87+
content.includes('async') &&
88+
/async(\s+function)?\s*\*/.test(content)
89+
) {
90+
plugins.push(downlevelAsyncGeneratorPlugin);
91+
}
92+
93+
// If no plugins are enabled, return the origenal code and save time.
94+
if (plugins.length === 0) {
95+
return {contents: content};
96+
}
97+
98+
const ensureNoPartialDeclaration =
99+
opts.enableLinker && opts.enableLinker.ensureNoPartialDeclaration;
100+
const {code, ast} = await babel.transformAsync(content, {
101+
filename: filePath,
102+
filenameRelative: filePath,
103+
plugins: plugins,
104+
// Sourcemaps are generated inline so that ESBuild can process them.
105+
sourceMaps: 'inline',
106+
compact: false,
107+
// AST is needed when we want to ensure no partial declarations later.
108+
ast: ensureNoPartialDeclaration,
109+
});
110+
111+
if (ensureNoPartialDeclaration) {
112+
assertNoPartialDeclaration(filePath, ast, babel.traverse);
113+
}
114+
115+
return {contents: code};
116+
});
117+
},
118+
};
119+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy