PR Close #26488
This commit is contained in:
@ -1,24 +1,20 @@
|
||||
load("//tools:defaults.bzl", "npm_package")
|
||||
|
||||
genrule(
|
||||
name = "workspace",
|
||||
outs = ["WORKSPACE"],
|
||||
cmd = "echo 'workspace(name=\"angular\")' > $@",
|
||||
)
|
||||
|
||||
npm_package(
|
||||
name = "npm_package",
|
||||
srcs = glob(["*.bzl"]) + [
|
||||
"BUILD.bazel",
|
||||
srcs = [
|
||||
"check_version.js",
|
||||
"package.json",
|
||||
"protractor-utils.js",
|
||||
"//packages/bazel/src:package_assets",
|
||||
],
|
||||
packages = ["//packages/bazel/docs"],
|
||||
# Re-host //packages/bazel/ which is just // in the public distro
|
||||
replacements = {
|
||||
"//packages/bazel/": "//",
|
||||
"angular/packages/bazel/": "angular/",
|
||||
},
|
||||
packages = [
|
||||
"//packages/bazel/docs",
|
||||
],
|
||||
tags = ["release-with-framework"],
|
||||
deps = [":workspace"],
|
||||
deps = [
|
||||
"//packages/bazel/src/ng_package:lib",
|
||||
"//packages/bazel/src/ngc-wrapped:ngc_lib",
|
||||
"//packages/bazel/src/protractor/utils",
|
||||
],
|
||||
)
|
||||
|
74
packages/bazel/check_version.js
Normal file
74
packages/bazel/check_version.js
Normal file
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
/**
|
||||
* @fileoverview This script runs as a postinstall in the published npm packages
|
||||
* and checks that the version of the build_bazel_rules_typescript external
|
||||
* repository matches that of the published npm package.
|
||||
*
|
||||
* Note, this check is only performed with bazel managed deps when the yarn or
|
||||
* npm install is from a yarn_install or npm_install repository rule. For self
|
||||
* managed bazel deps this check is not performed and it is the responsibility
|
||||
* of the user to ensure that the versions match.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Version in package.bzl should match the npm package version
|
||||
// but this should be tolerant of development stamped versions such as
|
||||
// "0.17.0-7-g76dc057"
|
||||
const npmPackageVersion = process.env.npm_package_version.split('-')[0];
|
||||
|
||||
// If this is a bazel managed deps yarn_install or npm_install then the
|
||||
// cwd is $(bazel info
|
||||
// output_base)/external/<wksp>/node_modules/@angular/bazel and there should
|
||||
// be $(bazel info output_base)/external/<wksp>/internal/generate_build_file.js
|
||||
// folder
|
||||
function isBazelManagedDeps() {
|
||||
try {
|
||||
fs.statSync('../../../generate_build_file.js');
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBazelManagedDeps()) {
|
||||
let contents;
|
||||
try {
|
||||
// If this is a yarn_install or npm_install then the cwd is $(bazel info
|
||||
// output_base)/external/<wksp>/node_modules/@angular/bazel so we can look for
|
||||
// the package.json file under $(bazel info
|
||||
// output_base)/external/angular/package.json
|
||||
const packagePath = path.resolve(process.cwd(), '../../../../angular/package.json');
|
||||
contents = require(packagePath);
|
||||
} catch (e) {
|
||||
throw new Error('The angular repository is not installed in your Bazel WORKSPACE file');
|
||||
}
|
||||
if (contents.name !== 'angular-srcs') {
|
||||
throw new Error('Invalid package.json in angular repository');
|
||||
}
|
||||
// Be tolerant of versions such as "0.17.0-7-g76dc057"
|
||||
const angularPackageVersion = contents.version.split('-')[0];
|
||||
if (npmPackageVersion !== angularPackageVersion) {
|
||||
// TODO: we might need to support a range here.
|
||||
// For example, if you end up with @angular/bazel@6.1.8 and
|
||||
// @angular/bazel@6.1.9 both installed one of the postinstalls is
|
||||
// guaranteed to fail since there's only one version of
|
||||
// angular
|
||||
throw new Error(`Expected angular repository to be version ${
|
||||
npmPackageVersion} but found ${angularPackageVersion}`);
|
||||
}
|
||||
} else {
|
||||
// No version check
|
||||
console.warn(`WARNING: With self managed deps you must ensure the @angular/bazel
|
||||
npm package version matches the angular repository version.
|
||||
Use yarn_install or npm_install for this version to be checked automatically.
|
||||
`);
|
||||
}
|
@ -4,10 +4,17 @@
|
||||
"description": "Angular - bazel build rules",
|
||||
"author": "angular",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"ngc-wrapped": "./src/ngc-wrapped/index.js",
|
||||
"packager": "./src/ng_package/packager.js",
|
||||
"xi18n": "./src/ngc-wrapped/extract_i18n.js",
|
||||
"modify_tsconfig": "./src/modify_tsconfig.js"
|
||||
},
|
||||
"typings": "./src/ngc-wrapped/index.d.ts",
|
||||
"dependencies": {
|
||||
"@bazel/typescript": "^0.15.0",
|
||||
"@bazel/typescript": "^0.19.1",
|
||||
"@types/node": "6.0.84",
|
||||
"protobufjs": "5.0.0"
|
||||
"tsickle": "0.28.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@angular/compiler-cli": "0.0.0-PLACEHOLDER",
|
||||
@ -19,5 +26,8 @@
|
||||
},
|
||||
"ng-update": {
|
||||
"packageGroup": "NG_UPDATE_PACKAGE_GROUP"
|
||||
},
|
||||
"scripts": {
|
||||
"postinstall": "node ./check_version.js"
|
||||
}
|
||||
}
|
||||
|
9
packages/bazel/protractor-utils.js
Normal file
9
packages/bazel/protractor-utils.js
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
module.exports = require('./src/protractor/utils');
|
@ -2,14 +2,13 @@ package(default_visibility = ["//visibility:public"])
|
||||
|
||||
filegroup(
|
||||
name = "package_assets",
|
||||
srcs = glob(["*"]) + [
|
||||
"//packages/bazel/src/ng_package:package_assets",
|
||||
"//packages/bazel/src/ngc-wrapped:package_assets",
|
||||
"//packages/bazel/src/protractor:package_assets",
|
||||
],
|
||||
srcs = ["modify_tsconfig.js"],
|
||||
visibility = ["//packages/bazel:__subpackages__"],
|
||||
)
|
||||
|
||||
# For generating skydoc
|
||||
exports_files(glob(["*.bzl"]))
|
||||
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
|
||||
|
||||
nodejs_binary(
|
||||
|
@ -16,6 +16,9 @@ load(
|
||||
)
|
||||
load("@build_bazel_rules_nodejs//internal/common:node_module_info.bzl", "NodeModuleInfo", "collect_node_modules_aspect")
|
||||
|
||||
_DEFAULT_COMPILER = "@angular//:@angular/bazel/ngc-wrapped"
|
||||
_DEFAULT_NG_XI18N = "@npm//@angular/bazel/bin:xi18n"
|
||||
|
||||
def compile_strategy(ctx):
|
||||
"""Detect which strategy should be used to implement ng_module.
|
||||
|
||||
@ -358,7 +361,7 @@ def ngc_compile_action(
|
||||
ctx.actions.run(
|
||||
inputs = list(inputs),
|
||||
outputs = messages_out,
|
||||
executable = ctx.executable._ng_xi18n,
|
||||
executable = ctx.executable.ng_xi18n,
|
||||
arguments = (_EXTRA_NODE_OPTIONS_FLAGS +
|
||||
[tsconfig_file.path] +
|
||||
# The base path is bin_dir because of the way the ngc
|
||||
@ -521,12 +524,21 @@ NG_MODULE_ATTRIBUTES = {
|
||||
"inline_resources": attr.bool(default = True),
|
||||
"no_i18n": attr.bool(default = False),
|
||||
"compiler": attr.label(
|
||||
default = Label("//packages/bazel/src/ngc-wrapped"),
|
||||
doc = """Sets a different ngc compiler binary to use for this library.
|
||||
|
||||
The default ngc compiler depends on the `@npm//@angular/bazel`
|
||||
target which is setup for projects that use bazel managed npm deps that
|
||||
fetch the @angular/bazel npm package. It is recommended that you use
|
||||
the workspace name `@npm` for bazel managed deps so the default
|
||||
compiler works out of the box. Otherwise, you'll have to override
|
||||
the compiler attribute manually.
|
||||
""",
|
||||
default = Label(_DEFAULT_COMPILER),
|
||||
executable = True,
|
||||
cfg = "host",
|
||||
),
|
||||
"_ng_xi18n": attr.label(
|
||||
default = Label("//packages/bazel/src/ngc-wrapped:xi18n"),
|
||||
"ng_xi18n": attr.label(
|
||||
default = Label(_DEFAULT_NG_XI18N),
|
||||
executable = True,
|
||||
cfg = "host",
|
||||
),
|
||||
|
@ -1,20 +1,16 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
filegroup(
|
||||
name = "package_assets",
|
||||
srcs = glob(["*"]),
|
||||
visibility = ["//packages/bazel:__subpackages__"],
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
|
||||
|
||||
exports_files(["rollup.config.js"])
|
||||
exports_files([
|
||||
"rollup.config.js",
|
||||
"ng_package.bzl",
|
||||
])
|
||||
|
||||
ts_library(
|
||||
name = "lib",
|
||||
srcs = glob(["*.ts"]),
|
||||
compiler = "//:@bazel/typescript/tsc_wrapped",
|
||||
node_modules = "@angular_packager_deps//:node_modules",
|
||||
tsconfig = ":tsconfig.json",
|
||||
)
|
||||
|
@ -31,6 +31,8 @@ load("@build_bazel_rules_nodejs//:internal/node.bzl", "sources_aspect")
|
||||
load("@build_bazel_rules_nodejs//internal/common:node_module_info.bzl", "NodeModuleInfo")
|
||||
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5")
|
||||
|
||||
_DEFAULT_NG_PACKAGER = "@npm//@angular/bazel/bin:packager"
|
||||
|
||||
# Convert from some-dash-case to someCamelCase
|
||||
def _convert_dash_case_to_camel_case(s):
|
||||
parts = s.split("-")
|
||||
@ -341,7 +343,7 @@ def _ng_package_impl(ctx):
|
||||
mnemonic = "AngularPackage",
|
||||
inputs = packager_inputs,
|
||||
outputs = [npm_package_directory],
|
||||
executable = ctx.executable._ng_packager,
|
||||
executable = ctx.executable.ng_packager,
|
||||
arguments = [packager_args],
|
||||
)
|
||||
|
||||
@ -379,8 +381,8 @@ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{
|
||||
"entry_point_name": attr.string(
|
||||
doc = "Name to use when generating bundle files for the primary entry-point.",
|
||||
),
|
||||
"_ng_packager": attr.label(
|
||||
default = Label("//packages/bazel/src/ng_package:packager"),
|
||||
"ng_packager": attr.label(
|
||||
default = Label(_DEFAULT_NG_PACKAGER),
|
||||
executable = True,
|
||||
cfg = "host",
|
||||
),
|
||||
|
@ -1,23 +1,19 @@
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
|
||||
|
||||
filegroup(
|
||||
name = "package_assets",
|
||||
srcs = glob(["*"]),
|
||||
visibility = ["//packages/bazel:__subpackages__"],
|
||||
)
|
||||
|
||||
ts_library(
|
||||
name = "ngc_lib",
|
||||
srcs = [
|
||||
"extract_i18n.ts",
|
||||
"index.ts",
|
||||
],
|
||||
compiler = "//:@bazel/typescript/tsc_wrapped",
|
||||
module_name = "@angular/bazel",
|
||||
node_modules = "@ngdeps//typescript:typescript__typings",
|
||||
tsconfig = ":tsconfig.json",
|
||||
visibility = ["//packages/bazel/test/ngc-wrapped:__subpackages__"],
|
||||
visibility = [
|
||||
"//packages/bazel:__pkg__",
|
||||
"//packages/bazel/test/ngc-wrapped:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
# BEGIN-INTERNAL
|
||||
# Only needed when compiling within the Angular repo.
|
||||
@ -47,6 +43,6 @@ nodejs_binary(
|
||||
data = [
|
||||
":ngc_lib",
|
||||
],
|
||||
entry_point = "angular/packages/bazel/src/ngc-wrapped/index.js/extract_i18n.js",
|
||||
entry_point = "angular/packages/bazel/src/ngc-wrapped/extract_i18n.js",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
@ -1,13 +1,6 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
filegroup(
|
||||
name = "package_assets",
|
||||
srcs = glob(["*"]) + [
|
||||
"//packages/bazel/src/protractor/utils:package_assets",
|
||||
],
|
||||
visibility = ["//packages/bazel:__subpackages__"],
|
||||
)
|
||||
|
||||
exports_files([
|
||||
"protractor.conf.js",
|
||||
"protractor_web_test.bzl",
|
||||
])
|
||||
|
@ -1,17 +1,10 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
filegroup(
|
||||
name = "package_assets",
|
||||
srcs = glob(["*"]),
|
||||
visibility = ["//packages/bazel:__subpackages__"],
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")
|
||||
|
||||
ts_library(
|
||||
name = "utils",
|
||||
srcs = ["index.ts"],
|
||||
compiler = "//:@bazel/typescript/tsc_wrapped",
|
||||
module_name = "@angular/bazel/protractor-utils",
|
||||
node_modules = "@ngdeps//typescript:typescript__typings",
|
||||
tsconfig = ":tsconfig.json",
|
||||
|
Reference in New Issue
Block a user