build: use rollup directory instead of rollup through @bazel/rollup (#62556)

Use rollup directly instead of using the previous toolchain implementation

PR Close #62556
This commit is contained in:
Joey Perrott
2025-07-09 18:21:38 +00:00
committed by Andrew Kushnir
parent 9c45c322d1
commit efc2a41d1d
6 changed files with 184 additions and 51 deletions
+91 -39
View File
@@ -1,5 +1,5 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm2//:rollup/package_json.bzl", rollup = "bin")
load("//tools:defaults.bzl", "pkg_npm")
load("//tools:defaults2.bzl", "ts_config")
@@ -61,46 +61,98 @@ pkg_npm(
],
)
rollup_bundle(
bundle_entrypoints = [
[
"inject-migration",
"packages/core/schematics/ng-generate/inject-migration/index.js",
],
[
"route-lazy-loading",
"packages/core/schematics/ng-generate/route-lazy-loading/index.js",
],
[
"standalone-migration",
"packages/core/schematics/ng-generate/standalone-migration/index.js",
],
[
"cleanup-unused-imports",
"packages/core/schematics/ng-generate/cleanup-unused-imports/index.js",
],
[
"signals",
"packages/core/schematics/ng-generate/signals/index.js",
],
[
"signal-input-migration",
"packages/core/schematics/ng-generate/signal-input-migration/index.js",
],
[
"signal-queries-migration",
"packages/core/schematics/ng-generate/signal-queries-migration/index.js",
],
[
"output-migration",
"packages/core/schematics/ng-generate/output-migration/index.js",
],
[
"self-closing-tags-migration",
"packages/core/schematics/ng-generate/self-closing-tags-migration/index.js",
],
[
"inject-flags",
"packages/core/schematics/migrations/inject-flags/index.js",
],
[
"test-bed-get",
"packages/core/schematics/migrations/test-bed-get/index.js",
],
[
"document-core",
"packages/core/schematics/migrations/document-core/index.js",
],
[
"control-flow-migration",
"packages/core/schematics/migrations/control-flow-migration/index.js",
],
]
rollup.rollup(
name = "bundles",
config_file = ":rollup.config.js",
entry_points = {
"//packages/core/schematics/ng-generate/inject-migration:index.ts": "inject-migration",
"//packages/core/schematics/ng-generate/route-lazy-loading:index.ts": "route-lazy-loading",
"//packages/core/schematics/ng-generate/standalone-migration:index.ts": "standalone-migration",
"//packages/core/schematics/ng-generate/cleanup-unused-imports:index.ts": "cleanup-unused-imports",
"//packages/core/schematics/ng-generate/signals:index.ts": "signals",
"//packages/core/schematics/ng-generate/signal-input-migration:index.ts": "signal-input-migration",
"//packages/core/schematics/ng-generate/signal-queries-migration:index.ts": "signal-queries-migration",
"//packages/core/schematics/ng-generate/output-migration:index.ts": "output-migration",
"//packages/core/schematics/ng-generate/self-closing-tags-migration:index.ts": "self-closing-tags-migration",
"//packages/core/schematics/migrations/inject-flags:index.ts": "inject-flags",
"//packages/core/schematics/migrations/test-bed-get:index.ts": "test-bed-get",
"//packages/core/schematics/migrations/document-core:index.ts": "document-core",
"//packages/core/schematics/migrations/control-flow-migration:index.ts": "control-flow-migration",
},
format = "cjs",
link_workspace_root = True,
output_dir = True,
sourcemap = "false",
srcs = [
"rollup.config.js",
"//:node_modules/@rollup/plugin-commonjs",
"//:node_modules/@rollup/plugin-node-resolve",
"//:node_modules/magic-string",
"//:node_modules/semver",
"//packages/core/schematics:tsconfig_build",
"//packages/core/schematics/migrations/control-flow-migration:control-flow-migration_rjs",
"//packages/core/schematics/migrations/document-core:document-core_rjs",
"//packages/core/schematics/migrations/inject-flags:inject-flags_rjs",
"//packages/core/schematics/migrations/test-bed-get:test-bed-get_rjs",
"//packages/core/schematics/ng-generate/cleanup-unused-imports:cleanup-unused-imports_rjs",
"//packages/core/schematics/ng-generate/inject-migration:inject-migration_rjs",
"//packages/core/schematics/ng-generate/output-migration:output-migration_rjs",
"//packages/core/schematics/ng-generate/route-lazy-loading:route-lazy-loading_rjs",
"//packages/core/schematics/ng-generate/self-closing-tags-migration:self-closing-tags-migration_rjs",
"//packages/core/schematics/ng-generate/signal-input-migration:signal-input-migration_rjs",
"//packages/core/schematics/ng-generate/signal-queries-migration:signal-queries-migration_rjs",
"//packages/core/schematics/ng-generate/signals:signals_rjs",
"//packages/core/schematics/ng-generate/standalone-migration:standalone-migration_rjs",
"//tools/bazel/rollup:path-plugin",
],
args = [
"--format=cjs",
"--config=$(rootpath rollup.config.js)",
"--dir=packages/core/schematics/bundles",
"--no-sourcemap",
] + ["--input=%s=%s" % (name, path) for [
name,
path,
] in bundle_entrypoints],
out_dirs = [
"bundles",
],
visibility = [
"//packages/core/schematics/test:__pkg__",
],
deps = [
"//packages/core/schematics/migrations/control-flow-migration",
"//packages/core/schematics/migrations/document-core",
"//packages/core/schematics/migrations/inject-flags",
"//packages/core/schematics/migrations/test-bed-get",
"//packages/core/schematics/ng-generate/cleanup-unused-imports",
"//packages/core/schematics/ng-generate/inject-migration",
"//packages/core/schematics/ng-generate/output-migration",
"//packages/core/schematics/ng-generate/route-lazy-loading",
"//packages/core/schematics/ng-generate/self-closing-tags-migration",
"//packages/core/schematics/ng-generate/signal-input-migration",
"//packages/core/schematics/ng-generate/signal-queries-migration",
"//packages/core/schematics/ng-generate/signals",
"//packages/core/schematics/ng-generate/standalone-migration",
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-node-resolve",
],
)
@@ -7,6 +7,7 @@
*/
const {nodeResolve} = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const {pathPlugin} = require('../../../tools/bazel/rollup/path-plugin.cjs');
/** Removed license banners from input files. */
const stripBannerPlugin = {
@@ -43,6 +44,7 @@ const banner = `'use strict';
*/`;
const plugins = [
pathPlugin({tsconfigPath: 'packages/core/schematics/tsconfig.json'}),
nodeResolve({
jail: process.cwd(),
}),
+22 -11
View File
@@ -1,15 +1,26 @@
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm2//:rollup/package_json.bzl", rollup = "bin")
rollup_bundle(
rollup.rollup(
name = "language-service",
config_file = "rollup.config.js",
entry_point = "//packages/language-service/src:ts_plugin.ts",
format = "amd",
silent = True,
visibility = ["//packages/language-service:__pkg__"],
deps = [
"//packages/language-service/src",
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-node-resolve",
srcs = [
"rollup.config.js",
"//:node_modules/@angular/compiler-cli",
"//:node_modules/@rollup/plugin-commonjs",
"//:node_modules/@rollup/plugin-node-resolve",
"//packages/language-service:tsconfig_build",
"//packages/language-service/src:src_rjs",
"//packages/language-service/src:ts_plugin.js",
"//tools/bazel/rollup:path-plugin",
],
outs = [
"language-service.js",
],
args = [
"--format=amd",
"--config=$(rootpath rollup.config.js)",
"--input=packages/language-service/src/ts_plugin.js",
"--file=packages/language-service/bundles/language-service.js",
"--sourcemap=inline",
],
visibility = ["//packages/language-service:__pkg__"],
)
@@ -8,6 +8,7 @@
const {nodeResolve} = require('@rollup/plugin-node-resolve');
const commonJs = require('@rollup/plugin-commonjs');
const {pathPlugin} = require('../../../tools/bazel/rollup/path-plugin.cjs');
// This is a custom AMD file header that patches the AMD `define` call generated
// by rollup so that the bundle exposes a CJS-exported function which takes an
@@ -47,7 +48,13 @@ const external = ['os', 'fs', 'path', 'typescript'];
const config = {
external,
plugins: [nodeResolve({preferBuiltins: true}), commonJs()],
plugins: [
pathPlugin({
tsconfigPath: 'packages/language-service/tsconfig.json',
}),
nodeResolve({preferBuiltins: true}),
commonJs(),
],
output: {
banner: amdFileHeader,
},
+12
View File
@@ -0,0 +1,12 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
js_library(
name = "path-plugin",
srcs = [
"path-plugin.cjs",
],
visibility = ["//visibility:public"],
deps = [
"//:node_modules/get-tsconfig",
],
)
+49
View File
@@ -0,0 +1,49 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
const {existsSync, statSync} = require('node:fs');
const {join} = require('node:path');
const {parseTsconfig, createPathsMatcher} = require('get-tsconfig');
function pathPlugin({tsconfigPath}) {
if (tsconfigPath === undefined) {
throw Error('A path tsconfig file must be provided.');
}
const fullTsconfigPath = join(process.cwd(), tsconfigPath);
const tsconfig = parseTsconfig(fullTsconfigPath);
const pathMappingMatcher = createPathsMatcher({config: tsconfig, path: fullTsconfigPath});
return {
name: 'paths',
resolveId: (source) => {
/**
* A list containing all of the potential paths which match the provided source based
* on the paths field from the tsconfig.
*/
const matchedSources = pathMappingMatcher(source);
if (matchedSources.length == 0) {
return null;
}
// We need to check each matched source to see if it loads at the path directly, or is
// a directory with an index.js file to import.
for (let matchedSource of matchedSources) {
const indexPath = join(matchedSource, 'index.js');
if (existsSync(indexPath) && statSync(indexPath).isFile) {
return {id: indexPath};
}
const filePath = matchedSource + '.js';
if (existsSync(filePath) && statSync(filePath).isFile) {
return {id: filePath};
}
}
throw Error(`Cannot find ${source}\nLocations checked:\n-${matchedSources.join('\n')}`);
},
};
}
module.exports = {pathPlugin};