Skip to content

Commit 4722099

Browse files
alexeaglemhevery
authored andcommitted
build: add bazel integration test (angular#18733)
It includes sass compilation, and building the bazel package distribution. PR Close angular#18733
1 parent 9ffa490 commit 4722099

25 files changed

+536
-141
lines changed

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
33
git_repository(
44
name = "build_bazel_rules_typescript",
55
remote = "https://github.com/bazelbuild/rules_typescript.git",
6-
tag = "0.0.5",
6+
tag = "0.0.6",
77
)
88

99
load("@build_bazel_rules_typescript//:defs.bzl", "node_repositories")

build.sh

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,16 @@ mapSources() {
327327
fi
328328
}
329329

330+
updateVersionReferences() {
331+
NPM_DIR="$1"
332+
(
333+
echo "====== VERSION: Updating version references in ${NPM_DIR}"
334+
cd ${NPM_DIR}
335+
echo "====== EXECUTE: perl -p -i -e \"s/0\.0\.0\-PLACEHOLDER/${VERSION}/g\" $""(grep -ril 0\.0\.0\-PLACEHOLDER .)"
336+
perl -p -i -e "s/0\.0\.0\-PLACEHOLDER/${VERSION}/g" $(grep -ril 0\.0\.0\-PLACEHOLDER .) < /dev/null 2> /dev/null
337+
)
338+
}
339+
330340
VERSION="${VERSION_PREFIX}${VERSION_SUFFIX}"
331341
echo "====== BUILDING: Version ${VERSION}"
332342

@@ -419,11 +429,15 @@ if [[ ${BUILD_TOOLS} == true || ${BUILD_ALL} == true ]]; then
419429
$(npm bin)/tsc -p packages/tsc-wrapped/tsconfig-build.json
420430
cp ./packages/tsc-wrapped/package.json ./dist/packages-dist/tsc-wrapped
421431
cp ./packages/tsc-wrapped/README.md ./dist/packages-dist/tsc-wrapped
422-
(
423-
cd dist/packages-dist/tsc-wrapped
424-
echo "====== EXECUTE: perl -p -i -e \"s/0\.0\.0\-PLACEHOLDER/${VERSION}/g\" $""(grep -ril 0\.0\.0\-PLACEHOLDER .)"
425-
perl -p -i -e "s/0\.0\.0\-PLACEHOLDER/${VERSION}/g" $(grep -ril 0\.0\.0\-PLACEHOLDER .) < /dev/null 2> /dev/null
426-
)
432+
updateVersionReferences dist/packages-dist/tsc-wrapped
433+
434+
rsync -a packages/bazel/ ./dist/packages-dist/bazel
435+
# Re-write nodejs import paths
436+
perl -p -i -e "s#__main__/packages/bazel#angular#g" $(grep -ril __main__ dist/packages-dist/bazel) < /dev/null 2> /dev/null
437+
# Remove BEGIN-INTERNAL...END-INTERAL blocks
438+
# https://stackoverflow.com/questions/24175271/how-can-i-match-multi-line-patterns-in-the-command-line-with-perl-style-regex
439+
perl -0777 -n -i -e "s/(?m)^.*BEGIN-INTERNAL[\w\W]*END-INTERNAL.*\n//g; print" $(grep -ril BEGIN-INTERNAL dist/packages-dist/bazel) < /dev/null 2> /dev/null
440+
updateVersionReferences dist/packages-dist/bazel
427441
fi
428442

429443
for PACKAGE in ${PACKAGES[@]}
@@ -489,12 +503,7 @@ do
489503

490504

491505
if [[ -d ${NPM_DIR} ]]; then
492-
(
493-
echo "====== VERSION: Updating version references"
494-
cd ${NPM_DIR}
495-
echo "====== EXECUTE: perl -p -i -e \"s/0\.0\.0\-PLACEHOLDER/${VERSION}/g\" $""(grep -ril 0\.0\.0\-PLACEHOLDER .)"
496-
perl -p -i -e "s/0\.0\.0\-PLACEHOLDER/${VERSION}/g" $(grep -ril 0\.0\.0\-PLACEHOLDER .) < /dev/null 2> /dev/null
497-
)
506+
updateVersionReferences ${NPM_DIR}
498507
fi
499508

500509
travisFoldEnd "build package: ${PACKAGE}"

integration/bazel/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
filegroup(
4+
name = "node_modules",
5+
srcs = glob([
6+
"node_modules/**/*.js",
7+
"node_modules/**/*.d.ts",
8+
"node_modules/**/*.json",
9+
])
10+
)

integration/bazel/WORKSPACE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
2+
3+
git_repository(
4+
name = "build_bazel_rules_typescript",
5+
remote = "https://github.com/bazelbuild/rules_typescript.git",
6+
tag = "0.0.6",
7+
)
8+
load("@build_bazel_rules_typescript//:defs.bzl", "node_repositories")
9+
node_repositories(package_json = "//:package.json")
10+
11+
local_repository(
12+
name = "angular",
13+
path = "node_modules/@angular/bazel"
14+
)
15+
16+
git_repository(
17+
name = "io_bazel_rules_sass",
18+
remote = "https://github.com/bazelbuild/rules_sass.git",
19+
tag = "0.0.2",
20+
)
21+
22+
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")
23+
24+
sass_repositories()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// WORKAROUND https://github.com/angular/angular/issues/18810
2+
// This file is required to run ngc on angular libraries, to write files like
3+
// node_modules/@angular/core/core.ngsummary.json
4+
{
5+
"compilerOptions": {
6+
"lib": [
7+
"dom",
8+
"es2015"
9+
],
10+
"experimentalDecorators": true,
11+
"types": []
12+
},
13+
"include": [
14+
"node_modules/@angular/**/*"
15+
],
16+
"exclude": [
17+
"node_modules/@angular/bazel/**",
18+
"node_modules/@angular/compiler-cli/**",
19+
"node_modules/@angular/tsc-wrapped/**"
20+
]
21+
}

integration/bazel/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "angular-bazel",
3+
"description": "example and integration test for building Angular apps with Bazel",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@angular/animations": "file:../../dist/packages-dist/animations",
8+
"@angular/common": "file:../../dist/packages-dist/common",
9+
"@angular/compiler": "file:../../dist/packages-dist/compiler",
10+
"@angular/core": "file:../../dist/packages-dist/core",
11+
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
12+
"rxjs": "5.3.1",
13+
"zone.js": "0.8.6"
14+
},
15+
"devDependencies": {
16+
"@angular/bazel": "file:../../dist/packages-dist/bazel",
17+
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
18+
"@types/node": "^7.0.18",
19+
"protobufjs": "5.0.0",
20+
"typescript": "~2.3.1"
21+
},
22+
"scripts": {
23+
"postinstall": "ngc -p angular.tsconfig.json",
24+
"test": "bazel build ..."
25+
}
26+
}

integration/bazel/src/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@angular//:index.bzl", "ng_module")
2+
3+
# Allow targets under sub-packages to reference the tsconfig.json file
4+
exports_files(["tsconfig.json"])
5+
6+
ng_module(
7+
name = "app",
8+
srcs = ["app.module.ts"],
9+
deps = ["//src/hello-world"],
10+
tsconfig = ":tsconfig.json",
11+
)

integration/bazel/src/app.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {HelloWorldModule} from './hello-world/hello-world.module';
2+
3+
import {NgModule} from '@angular/core';
4+
import {BrowserModule} from '@angular/platform-browser';
5+
6+
@NgModule({
7+
imports: [BrowserModule, HelloWorldModule]
8+
})
9+
export class AppModule {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package(default_visibility = ["//visibility:public"])
2+
load("@angular//:index.bzl", "ng_module")
3+
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_binary")
4+
5+
sass_binary(
6+
name = "styles",
7+
src = "hello-world.component.scss",
8+
deps = [
9+
"//src/shared:colors",
10+
"//src/shared:fonts",
11+
],
12+
)
13+
14+
ng_module(
15+
name = "hello-world",
16+
srcs = glob(["*.ts"]),
17+
tsconfig = "//src:tsconfig.json",
18+
assets = [":styles"],
19+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@import "src/shared/fonts";
2+
@import "src/shared/colors";
3+
4+
html {
5+
body {
6+
font-family: $default-font-stack;
7+
h1 {
8+
font-family: $modern-font-stack;
9+
color: $example-red;
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)