Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: introduce bazel #909

Merged
merged 2 commits into from Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 0 additions & 39 deletions .cicleci/config.yml

This file was deleted.

101 changes: 101 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,101 @@
# This file configures the build at https://circleci.com/gh/angular/universal
# Complete documentation is at https://circleci.com/docs/2.0/

# We use a docker image as the basis for our build, so that all the toolchains we use
# are already installed and the build can start running right away. It also guarantees
# the environment is portable and reproducible on your local machine.
var_1: &docker_image angular/ngcontainer:0.1.0

# CircleCI lets us pick the key for storing one or more caches, to speed up subsequent builds.
# We can use this to avoid re-fetching our dependencies from npm on every build.
# To ensure we don't load a stale cache, we invalidate it based on the entries in the key:
# - the checksum of Yarn's lock file
# - the branch we are on, which really shouldn't be needed since the yarn lock file should be hermetic
# - the docker image tag, working around an issue we saw where changing docker images causes permission
# errors when restoring the cache, like when the user we run as changes
var_2: &cache_key angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-0.1.0

# Each job will inherit these defaults
anchor_1: &job_defaults
working_directory: ~/ng
docker:
- image: *docker_image

# After checkout, rebase on top of master, because we want to test the proposed merge of a
# onto the target branch, not just test what's on the user's fork.
# Similar to travis behavior, but not quite the same.
# See https://discuss.circleci.com/t/1662
anchor_2: &post_checkout
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"

# Opt-in to the new goodness
version: 2

# These jobs will run in parallel, and report separate statuses to GitHub PRs
jobs:
lint:
<<: *job_defaults
steps:
- checkout:
<<: *post_checkout
# Enforce that BUILD files are formatted. Note that this uses the version of buildifier
# from the docker image above - take care that you use the same version when you run
# buildifier locally on your change.
- run: 'buildifier -mode=check $(find . -type f \( -name BUILD.bazel -or -name BUILD \)) ||
(echo "BUILD files not formatted. Please run ''yarn buildifier''" ; exit 1)'

build:
<<: *job_defaults
steps:
- checkout:
<<: *post_checkout

- restore_cache:
key: *cache_key

- run: bazel info release

# TODO: Don't do this
- run: yarn install --frozen-lockfile
# Install the dependencies from NPM
#- run: bazel run @yarn//:yarn install

# Build and Test
# Use bazel query so that we explicitly ask for all buildable targets to
# be built even though we run `bazel test`
# See https://github.com/bazelbuild/bazel/issues/4257
#- run: bazel query //... | xargs bazel test --config=ci
- run: bazel test //...

# - store_artifacts:
# path: dist/bin/modules/aspnetcore-engine/@nguniversal/aspnetcore-engine
# destination: @nguniversal/aspnetcore-engine

# - store_artifacts:
# path: dist/bin/modules/common-engine/@nguniversal/common
# destination: @nguniversal/common

# - store_artifacts:
# path: dist/bin/modules/express-engine/@nguniversal/express-engine
# destination: @nguniversal/express-engine

# - store_artifacts:
# path: dist/bin/modules/hapi-engine/@nguniversal/hapi-engine
# destination: @nguniversal/hapi-engine

# - store_artifacts:
# path: dist/bin/modules/module-map-ngfactory-loader/@nguniversal/module-map-ngfactory-loader
# destination: @nguniversal/module-map-ngfactory-loader

# If we get this far, save the node_modules directory for use next time.
- save_cache:
key: *cache_key
paths:
- "node_modules"

workflows:
version: 2
default_workflow:
jobs:
- build
#- lint
8 changes: 8 additions & 0 deletions .gitignore
Expand Up @@ -21,3 +21,11 @@ web_modules

/compiled
*.metadata.json

# Build Artifacts #
release
dist
bazel-out

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that we've seen issues with VSCode on Mac High Sierra eating all available file handles when this directory is present. I think you're okay here but if you get strange errors about XCode then you should disable the symlinks in the project directory.

/node_modules/
lerna-debug.log
/lib/
25 changes: 25 additions & 0 deletions BUILD.bazel
@@ -0,0 +1,25 @@
# Marker file indicating this folder is a Bazel package.
# Needed so that tsconfig.json can be referenced from BUILD rules.
package(default_visibility=["//visibility:public"])

exports_files(["tsconfig.json"])

# Provides the npm-installed dependencies to Bazel actions.
filegroup(
name = "node_modules",
srcs = glob(
["node_modules/**/*"],
# Exclude directories that commonly contain filenames which are
# illegal bazel labels
exclude = [
# e.g. node_modules/adm-zip/test/assets/attributes_test/New folder/hidden.txt
"node_modules/**/test/**",
# e.g. node_modules/xpath/docs/function resolvers.md
"node_modules/**/docs/**",
],
),
# Allow this targets to be referenced by anyone.
# Other repositories running nodejs binaries will need to
# reference our installed node_modules directory.
visibility = ["//visibility:public"],
)
61 changes: 61 additions & 0 deletions WORKSPACE
@@ -0,0 +1,61 @@
workspace(name = "nguniversal")

http_archive(
name = "com_github_bazelbuild_buildtools",
# Note, this commit matches the version of buildifier in angular/ngcontainer
url = "https://github.com/bazelbuild/buildtools/archive/b3b620e8bcff18ed3378cd3f35ebeb7016d71f71.zip",
strip_prefix = "buildtools-b3b620e8bcff18ed3378cd3f35ebeb7016d71f71",
sha256 = "dad19224258ed67cbdbae9b7befb785c3b966e5a33b04b3ce58ddb7824b97d73",
)

http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.5.1.zip",
strip_prefix = "rules_nodejs-0.5.1",
sha256 = "dabd1a596a6f00939875762dcb1de93b5ada0515069244198aa6792bc37bb92a",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
node_repositories(package_json = ["//:package.json"])


# http_archive(
# name = "build_bazel_rules_typescript",
# url = "https://github.com/bazelbuild/rules_typescript/archive/0.11.1.zip",
# strip_prefix = "rules_typescript-0.11.1",
# sha256 = "7406bea7954e1c906f075115dfa176551a881119f6820b126ea1eacb09f34a1a",
#)
local_repository(
name = "build_bazel_rules_typescript",
path = "node_modules/@bazel/typescript",
)

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

# Some of the TypeScript is written in Go.
# Bazel doesn't support transitive WORKSPACE deps, so we must repeat them here.
http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.9.0/rules_go-0.9.0.tar.gz",
sha256 = "4d8d6244320dd751590f9100cf39fd7a4b75cd901e1f3ffdfd6f048328883695",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()


####################################
# Tell Bazel about some workspaces that were installed from npm.

local_repository(
name = "angular",
path = "node_modules/@angular/bazel",
)


local_repository(
name = "rxjs",
path = "node_modules/rxjs/src",
)
21 changes: 21 additions & 0 deletions angular.tsconfig.json
@@ -0,0 +1,21 @@
// WORKAROUND https://github.com/angular/angular/issues/18810
// This file is required to run ngc on angular libraries, to write files like
// node_modules/@angular/core/core.ngsummary.json
{
"compilerOptions": {
"lib": [
"dom",
"es2015"
],
"experimentalDecorators": true,
"types": []
},
"include": [
"node_modules/@angular/**/*"
],
"exclude": [
"node_modules/@angular/bazel/**",
"node_modules/@angular/compiler-cli/**",
"node_modules/@angular/tsc-wrapped/**"
]
}
34 changes: 34 additions & 0 deletions modules/aspnetcore-engine/BUILD.bazel
@@ -0,0 +1,34 @@
load("//tools:defaults.bzl", "ts_library", "ng_module", "ng_package")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")

ng_module(
name = "aspnetcore-engine_module",
srcs = glob([
"*.ts",
"src/**/*.ts",
]),
deps = ["@rxjs"],
)

ng_package(
name = "@nguniversal/aspnetcore-engine",
srcs = [":package.json"],
entry_point = "index.js",
deps = [":aspnetcore-engine_module"],
)

ts_library(
name = "unit_test_lib",
srcs = glob([
"spec/**/*.spec.ts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if we have the spec files in line with the actual files, but we might need to discuss this offline. Core does it this way, the other repos do it in the same directory.

]),
testonly=True,
deps = [
":aspnetcore-engine_module"
],
)

jasmine_node_test(
name = "unit_test",
srcs = [":unit_test_lib"],
)
33 changes: 33 additions & 0 deletions modules/common/BUILD.bazel
@@ -0,0 +1,33 @@
load("//tools:defaults.bzl", "ts_library", "ng_module", "ng_package")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")

ng_module(
name = "common_module",
srcs = glob([
"*.ts",
"src/**/*.ts",
]),
deps = [],
)

ng_package(
name = "@nguniversal/common",
srcs = [":package.json"],
entry_point = "index.js",
deps = [":common_module"],
)
ts_library(
name = "unit_test_lib",
srcs = glob([
"spec/**/*.spec.ts"
]),
testonly=True,
deps = [
":common_module"
],
)

jasmine_node_test(
name = "unit_test",
srcs = [":unit_test_lib"],
)
5 changes: 5 additions & 0 deletions modules/common/spec/index.spec.ts
@@ -0,0 +1,5 @@
describe('test runner', () => {
it('can run a test', () => {
expect(true).toBe(true);
});
});
35 changes: 35 additions & 0 deletions modules/express-engine/BUILD.bazel
@@ -0,0 +1,35 @@
load("//tools:defaults.bzl", "ts_library", "ng_module", "ng_package")
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test")

ng_module(
name = "express-engine_module",
srcs = glob([
"*.ts",
"src/**/*.ts",
]),
deps = ["@rxjs"],
)

ng_package(

name = "@nguniversal/express-engine",
srcs = [":package.json"],
entry_point = "index.js",
deps = [":express-engine_module"],
)

ts_library(
name = "unit_test_lib",
srcs = glob([
"spec/**/*.spec.ts"
]),
testonly=True,
deps = [
":express-engine_module"
],
)

jasmine_node_test(
name = "unit_test",
srcs = [":unit_test_lib"],
)
5 changes: 5 additions & 0 deletions modules/express-engine/spec/index.spec.ts
@@ -0,0 +1,5 @@
describe('test runner', () => {
it('can run a test', () => {
expect(true).toBe(true);
});
});