build: remove rollup packaging from dev-infra (#35647)
The dev-infra package currently uses rollup for packaging. This has been done initially as a way to workaround manifest paths being used in the AMD JavaScript output. The actual solution to this problem is setting module names that match the `package.json` name. This ensures that the package can be consumed correctly in Bazel, and through NPM. This allows us to get rid of the rollup bundling, and we don't need to hard-code which dependencies should be external or included. Additionally, tools that are part of `dev-infra` can now specify their external dependencies simply in the `package.json`. To reduce version duplication, and out-of-sync versions, a new genrule has been created that syncs the versions with the top-level project `package.json`. PR Close #35647
This commit is contained in:
parent
7aab399c84
commit
b7138c1ec5
|
@ -8,6 +8,7 @@ exports_files([
|
||||||
"scripts/ci/track-payload-size.sh",
|
"scripts/ci/track-payload-size.sh",
|
||||||
"scripts/ci/payload-size.sh",
|
"scripts/ci/payload-size.sh",
|
||||||
"scripts/ci/payload-size.js",
|
"scripts/ci/payload-size.js",
|
||||||
|
"package.json",
|
||||||
])
|
])
|
||||||
|
|
||||||
alias(
|
alias(
|
||||||
|
|
|
@ -1,38 +1,38 @@
|
||||||
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
|
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
|
||||||
load("@npm_bazel_typescript//:index.bzl", "ts_library")
|
load("@npm_bazel_typescript//:index.bzl", "ts_library")
|
||||||
load("@npm_bazel_rollup//:index.bzl", "rollup_bundle")
|
|
||||||
|
|
||||||
ts_library(
|
ts_library(
|
||||||
name = "cli",
|
name = "cli",
|
||||||
srcs = [
|
srcs = [
|
||||||
"cli.ts",
|
"cli.ts",
|
||||||
],
|
],
|
||||||
|
module_name = "@angular/dev-infra-private",
|
||||||
deps = [
|
deps = [
|
||||||
"//dev-infra/pullapprove",
|
"//dev-infra/pullapprove",
|
||||||
"@npm//@types/node",
|
"@npm//@types/node",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
rollup_bundle(
|
genrule(
|
||||||
name = "bundle",
|
name = "package-json",
|
||||||
config_file = "rollup.config.js",
|
srcs = [
|
||||||
entry_point = ":cli.ts",
|
"tmpl-package.json",
|
||||||
format = "umd",
|
"//:package.json",
|
||||||
sourcemap = "hidden",
|
|
||||||
deps = [
|
|
||||||
":cli",
|
|
||||||
"@npm//rollup-plugin-commonjs",
|
|
||||||
"@npm//rollup-plugin-node-resolve",
|
|
||||||
],
|
],
|
||||||
|
outs = ["package.json"],
|
||||||
|
cmd = """
|
||||||
|
$(location //tools:inline-package-json-deps) $(location tmpl-package.json) \
|
||||||
|
$(location //:package.json) $@
|
||||||
|
""",
|
||||||
|
tools = ["//tools:inline-package-json-deps"],
|
||||||
)
|
)
|
||||||
|
|
||||||
pkg_npm(
|
pkg_npm(
|
||||||
name = "npm_package",
|
name = "npm_package",
|
||||||
srcs = [
|
|
||||||
"package.json",
|
|
||||||
],
|
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
":bundle",
|
":cli",
|
||||||
|
":package-json",
|
||||||
|
"//dev-infra/ts-circular-dependencies",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
/**
|
/**
|
||||||
* @license
|
* @license
|
||||||
* Copyright Google Inc. All Rights Reserved.
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"name": "@angular/dev-infra-private",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"description": "INTERNAL USE ONLY - Angular internal DevInfra tooling/scripts - INTERNAL USE ONLY",
|
|
||||||
"license": "MIT",
|
|
||||||
"private": true,
|
|
||||||
"bin": {
|
|
||||||
"ng-dev": "./bundle.js"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@ ts_library(
|
||||||
srcs = [
|
srcs = [
|
||||||
"verify.ts",
|
"verify.ts",
|
||||||
],
|
],
|
||||||
|
module_name = "@angular/dev-infra-private/pullapprove",
|
||||||
visibility = ["//dev-infra:__subpackages__"],
|
visibility = ["//dev-infra:__subpackages__"],
|
||||||
deps = [
|
deps = [
|
||||||
"@npm//@types/minimatch",
|
"@npm//@types/minimatch",
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
const node = require('rollup-plugin-node-resolve');
|
|
||||||
const commonjs = require('rollup-plugin-commonjs');
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
external: ['shelljs', 'minimatch', 'yaml'],
|
|
||||||
preferBuiltins: true,
|
|
||||||
output: {
|
|
||||||
banner: "#!/usr/bin/env node",
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
node({
|
|
||||||
mainFields: ['browser', 'es2015', 'module', 'jsnext:main', 'main'],
|
|
||||||
}),
|
|
||||||
commonjs(),
|
|
||||||
],
|
|
||||||
};
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"name": "@angular/dev-infra-private",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "INTERNAL USE ONLY - Angular internal DevInfra tooling/scripts - INTERNAL USE ONLY",
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"bin": {
|
||||||
|
"ng-dev": "./cli.js",
|
||||||
|
"ts-circular-deps": "./ts-circular-dependencies/index.js"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"chalk": "<from-root>",
|
||||||
|
"glob": "<from-root>",
|
||||||
|
"minimatch": "<from-root>",
|
||||||
|
"shelljs": "<from-root>",
|
||||||
|
"typescript": "<from-root>",
|
||||||
|
"yaml": "<from-root>",
|
||||||
|
"yargs": "<from-root>",
|
||||||
|
"tslib": "<from-root>"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
load("@npm_bazel_typescript//:index.bzl", "ts_config")
|
load("@npm_bazel_typescript//:index.bzl", "ts_config")
|
||||||
|
load("//tools:defaults.bzl", "nodejs_binary")
|
||||||
|
|
||||||
exports_files([
|
exports_files([
|
||||||
"tsconfig.json",
|
"tsconfig.json",
|
||||||
|
@ -13,6 +14,11 @@ ts_config(
|
||||||
deps = ["tsconfig.json"],
|
deps = ["tsconfig.json"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
nodejs_binary(
|
||||||
|
name = "inline-package-json-deps",
|
||||||
|
entry_point = "inline-package-json-deps.js",
|
||||||
|
)
|
||||||
|
|
||||||
platform(
|
platform(
|
||||||
name = "rbe_ubuntu1604-angular",
|
name = "rbe_ubuntu1604-angular",
|
||||||
parents = ["@rbe_ubuntu1604_angular//config:platform"],
|
parents = ["@rbe_ubuntu1604_angular//config:platform"],
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. 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.io/license
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Script that updates a dependencies in a specified `package.json` file to be
|
||||||
|
* based on the dependencies of the specified base `package.json`. This allows
|
||||||
|
* developers to sync dependencies between two `package.json` files without having
|
||||||
|
* to manually copy versions all the time.
|
||||||
|
*
|
||||||
|
* e.g. `/package.json` defines the project dependencies. The `dev-infra/package.json`
|
||||||
|
* uses a subset of these dependencies and declares these as dependencies for the shared
|
||||||
|
* package. The dependencies should be the same as the one from `/package.json` as those
|
||||||
|
* versions are used for testing and development. We don't want mismatching versions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const [inputPackageJsonPath, basePackageJsonPath, outputPath] = args;
|
||||||
|
const BASE_DEPENDENCY_MARKER = '<from-root>';
|
||||||
|
|
||||||
|
if (!inputPackageJsonPath || !basePackageJsonPath || !outputPath) {
|
||||||
|
console.error('Usage: ./inline-package-json-deps.js <input-pkg-json> <base-pkg-json> <out-path>');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputPackageJson = JSON.parse(fs.readFileSync(inputPackageJsonPath, 'utf8'));
|
||||||
|
const basePackageJson = JSON.parse(fs.readFileSync(basePackageJsonPath, 'utf8'));
|
||||||
|
const result = {...inputPackageJson};
|
||||||
|
|
||||||
|
if (inputPackageJson.dependencies) {
|
||||||
|
inlineDependenciesFromBase(inputPackageJson.dependencies);
|
||||||
|
}
|
||||||
|
if (inputPackageJson.peerDependencies) {
|
||||||
|
inlineDependenciesFromBase(inputPackageJson.peerDependencies);
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates dependencies which have their version set to the base marker,
|
||||||
|
* to match the version from the base `package.json` file.
|
||||||
|
*/
|
||||||
|
function inlineDependenciesFromBase(deps) {
|
||||||
|
Object.keys(deps).forEach(name => {
|
||||||
|
const value = deps[name];
|
||||||
|
if (value !== BASE_DEPENDENCY_MARKER) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const linkedVersion = getDependency(basePackageJson, name);
|
||||||
|
if (linkedVersion === null) {
|
||||||
|
console.error(`Could not find base version for: ${name}`);
|
||||||
|
console.error(
|
||||||
|
`Either set a version for ${name} in "${basePackageJsonPath}", or use ` +
|
||||||
|
`an explicit version in "${inputPackageJson}"`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
deps[name] = linkedVersion;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Gets the version of the specified package from the given package object. */
|
||||||
|
function getDependency(packageJson, name) {
|
||||||
|
if (packageJson.dependencies && packageJson.dependencies[name]) {
|
||||||
|
return packageJson.dependencies[name];
|
||||||
|
}
|
||||||
|
if (packageJson.devDependencies && packageJson.devDependencies[name]) {
|
||||||
|
return packageJson.devDependencies[name];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
Loading…
Reference in New Issue