Skip to content

Commit 3896f86

Browse files
alan-agius4AndrewKushnir
authored andcommitted
refactor(migrations): switch from esbuild to Rollup for schematics bundling (angular#57602)
Replaces esbuild with Rollup for bundling schematics to support code splitting, as esbuild does not handle code splitting when targeting CommonJS modules. **Before:** ``` du -sh dist/bin/packages/core/npm_package/schematics 7.7M dist/bin/packages/core/npm_package/schematics ``` **After:** ``` du -sh dist/bin/packages/core/npm_package/schematics 3.1M dist/bin/packages/core/npm_package/schematics ``` PR Close angular#57602
1 parent 36d8d19 commit 3896f86

File tree

15 files changed

+105
-106
lines changed

15 files changed

+105
-106
lines changed

packages/core/schematics/BUILD.bazel

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("//tools:defaults.bzl", "pkg_npm")
2+
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
23

34
exports_files([
45
"tsconfig.json",
@@ -20,9 +21,33 @@ pkg_npm(
2021
validate = False,
2122
visibility = ["//packages/core:__pkg__"],
2223
deps = [
23-
"//packages/core/schematics/ng-generate/control-flow-migration:bundle",
24-
"//packages/core/schematics/ng-generate/inject-migration:bundle",
25-
"//packages/core/schematics/ng-generate/route-lazy-loading:bundle",
26-
"//packages/core/schematics/ng-generate/standalone-migration:bundle",
24+
":bundles",
25+
],
26+
)
27+
28+
rollup_bundle(
29+
name = "bundles",
30+
config_file = ":rollup.config.js",
31+
entry_points = {
32+
"//packages/core/schematics/ng-generate/control-flow-migration:index.ts": "control-flow-migration",
33+
"//packages/core/schematics/ng-generate/inject-migration:index.ts": "inject-migration",
34+
"//packages/core/schematics/ng-generate/route-lazy-loading:index.ts": "route-lazy-loading",
35+
"//packages/core/schematics/ng-generate/standalone-migration:index.ts": "standalone-migration",
36+
},
37+
format = "cjs",
38+
link_workspace_root = True,
39+
output_dir = True,
40+
sourcemap = "false",
41+
visibility = [
42+
"//packages/core/schematics/test:__pkg__",
43+
],
44+
deps = [
45+
"//packages/core/schematics/ng-generate/control-flow-migration",
46+
"//packages/core/schematics/ng-generate/inject-migration",
47+
"//packages/core/schematics/ng-generate/route-lazy-loading",
48+
"//packages/core/schematics/ng-generate/standalone-migration",
49+
"@npm//@rollup/plugin-commonjs",
50+
"@npm//@rollup/plugin-node-resolve",
51+
"@npm//magic-string",
2752
],
2853
)

packages/core/schematics/collection.json

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,27 @@
22
"schematics": {
33
"standalone-migration": {
44
"description": "Converts the entire application or a part of it to standalone",
5-
"factory": "./ng-generate/standalone-migration/bundle",
5+
"factory": "./bundles/standalone-migration#migrate",
66
"schema": "./ng-generate/standalone-migration/schema.json",
7-
"aliases": [
8-
"standalone"
9-
]
7+
"aliases": ["standalone"]
108
},
119
"control-flow-migration": {
1210
"description": "Converts the entire application to block control flow syntax",
13-
"factory": "./ng-generate/control-flow-migration/bundle",
11+
"factory": "./bundles/control-flow-migration#migrate",
1412
"schema": "./ng-generate/control-flow-migration/schema.json",
15-
"aliases": [
16-
"control-flow"
17-
]
13+
"aliases": ["control-flow"]
1814
},
1915
"inject-migration": {
2016
"description": "Converts usages of constructor-based injection to the inject() function",
21-
"factory": "./ng-generate/inject-migration/bundle",
17+
"factory": "./bundles/inject-migration#migrate",
2218
"schema": "./ng-generate/inject-migration/schema.json",
23-
"aliases": [
24-
"inject"
25-
]
19+
"aliases": ["inject"]
2620
},
2721
"route-lazy-loading-migration": {
2822
"description": "Updates route definitions to use lazy-loading of components instead of eagerly referencing them",
29-
"factory": "./ng-generate/route-lazy-loading/bundle",
23+
"factory": "./bundles/route-lazy-loading#migrate",
3024
"schema": "./ng-generate/route-lazy-loading/schema.json",
3125
"aliases": ["route-lazy-loading"]
3226
}
3327
}
3428
}
35-

packages/core/schematics/ng-generate/control-flow-migration/BUILD.bazel

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "esbuild_no_sourcemaps", "ts_library")
1+
load("//tools:defaults.bzl", "ts_library")
22

33
package(
44
default_visibility = [
@@ -25,15 +25,3 @@ ts_library(
2525
"@npm//typescript",
2626
],
2727
)
28-
29-
esbuild_no_sourcemaps(
30-
name = "bundle",
31-
entry_point = ":index.ts",
32-
external = [
33-
"@angular-devkit/*",
34-
"typescript",
35-
],
36-
format = "cjs",
37-
platform = "node",
38-
deps = [":control-flow-migration"],
39-
)

packages/core/schematics/ng-generate/control-flow-migration/ifs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
getPlaceholder,
2424
hasLineBreaks,
2525
parseTemplate,
26-
PlaceholderKind,
2726
reduceNestingOffset,
2827
} from './util';
2928

packages/core/schematics/ng-generate/control-flow-migration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface Options {
2121
format: boolean;
2222
}
2323

24-
export default function (options: Options): Rule {
24+
export function migrate(options: Options): Rule {
2525
return async (tree: Tree, context: SchematicContext) => {
2626
const basePath = process.cwd();
2727
const pathToMigrate = normalizePath(join(basePath, options.path));

packages/core/schematics/ng-generate/control-flow-migration/migration.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ import {
2323
import {
2424
canRemoveCommonModule,
2525
formatTemplate,
26-
parseTemplate,
2726
processNgTemplates,
2827
removeImports,
29-
validateI18nStructure,
3028
validateMigratedTemplate,
3129
} from './util';
3230

packages/core/schematics/ng-generate/inject-migration/BUILD.bazel

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "esbuild_no_sourcemaps", "ts_library")
1+
load("//tools:defaults.bzl", "ts_library")
22

33
package(
44
default_visibility = [
@@ -24,15 +24,3 @@ ts_library(
2424
"@npm//typescript",
2525
],
2626
)
27-
28-
esbuild_no_sourcemaps(
29-
name = "bundle",
30-
entry_point = ":index.ts",
31-
external = [
32-
"@angular-devkit/*",
33-
"typescript",
34-
],
35-
format = "cjs",
36-
platform = "node",
37-
deps = [":inject-migration"],
38-
)

packages/core/schematics/ng-generate/inject-migration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface Options extends MigrationOptions {
1818
path: string;
1919
}
2020

21-
export default function (options: Options): Rule {
21+
export function migrate(options: Options): Rule {
2222
return async (tree: Tree) => {
2323
const basePath = process.cwd();
2424
const pathToMigrate = normalizePath(join(basePath, options.path));

packages/core/schematics/ng-generate/route-lazy-loading/BUILD.bazel

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//tools:defaults.bzl", "esbuild_no_sourcemaps", "ts_library")
1+
load("//tools:defaults.bzl", "ts_library")
22

33
package(
44
default_visibility = [
@@ -26,15 +26,3 @@ ts_library(
2626
"@npm//typescript",
2727
],
2828
)
29-
30-
esbuild_no_sourcemaps(
31-
name = "bundle",
32-
entry_point = ":index.ts",
33-
external = [
34-
"@angular-devkit/*",
35-
"typescript",
36-
],
37-
format = "cjs",
38-
platform = "node",
39-
deps = [":route-lazy-loading"],
40-
)

packages/core/schematics/ng-generate/route-lazy-loading/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface Options {
2020
path: string;
2121
}
2222

23-
export default function (options: Options): Rule {
23+
export function migrate(options: Options): Rule {
2424
return async (tree, context) => {
2525
const {buildPaths} = await getProjectTsConfigPaths(tree);
2626
const basePath = process.cwd();

0 commit comments

Comments
 (0)