refactor(bazel): Remove bazel-workspace schematics (#29148)

`bazel-workspace` schematics is no longer needed now that the Bazel
files are injected into the project by the Bazel builder.

PR Close #29148
This commit is contained in:
Keen Yee Liau 2019-03-06 17:50:57 -08:00 committed by Kara Erickson
parent 36a1550e00
commit f4f20daee3
29 changed files with 127 additions and 663 deletions

View File

@ -32,6 +32,10 @@ function testBazel() {
ng build ng build
ng test ng test
ng e2e ng e2e
if [ -e 'WORKSPACE' ] || [ -e 'BUILD.bazel' ]; then
echo 'WORKSPACE / BUILD.bazel file should not exist in project'
exit 1
fi
} }
function testNonBazel() { function testNonBazel() {

View File

@ -40,6 +40,17 @@
rxjs "6.3.3" rxjs "6.3.3"
source-map "0.7.3" source-map "0.7.3"
"@angular-devkit/core@7.3.5":
version "7.3.5"
resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-7.3.5.tgz#2a59a913eab358e2385f52ba28132b81435e63b3"
integrity sha512-J/Tztq2BZ3tpwUsbiz8N61rf9lwqn85UvJsDui2SPIdzDR9KmPr5ESI2Irc/PEb9i+CBXtVuhr8AIqo7rR6ZTg==
dependencies:
ajv "6.9.1"
chokidar "2.0.4"
fast-json-stable-stringify "2.0.0"
rxjs "6.3.3"
source-map "0.7.3"
"@angular-devkit/schematics@7.3.2", "@angular-devkit/schematics@^7.3.0-rc.0": "@angular-devkit/schematics@7.3.2", "@angular-devkit/schematics@^7.3.0-rc.0":
version "7.3.2" version "7.3.2"
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.2.tgz#e9d3c1f2128a56f66ea846ce3f80c69d4c3a9ae9" resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.2.tgz#e9d3c1f2128a56f66ea846ce3f80c69d4c3a9ae9"
@ -48,15 +59,23 @@
"@angular-devkit/core" "7.3.2" "@angular-devkit/core" "7.3.2"
rxjs "6.3.3" rxjs "6.3.3"
"@angular-devkit/schematics@7.3.5":
version "7.3.5"
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.5.tgz#7b007f8a86dea76e93eef007d4fb6e7d8324b7bb"
integrity sha512-BFCCkwRMBC4aFlngaloi1avCTgGrl1MFc/0Av2sCpBh/fdm1FqSVzmOiTfu93dehRVVL/bTrA2qj+xpNsXCxzA==
dependencies:
"@angular-devkit/core" "7.3.5"
rxjs "6.3.3"
"@angular/bazel@file:../../dist/packages-dist/bazel": "@angular/bazel@file:../../dist/packages-dist/bazel":
version "8.0.0-beta.6" version "8.0.0-beta.7"
dependencies: dependencies:
"@angular-devkit/architect" "^0.13.4" "@angular-devkit/architect" "^0.13.4"
"@angular-devkit/core" "^7.0.4" "@angular-devkit/core" "^7.0.4"
"@angular-devkit/schematics" "^7.3.0-rc.0" "@angular-devkit/schematics" "^7.3.0-rc.0"
"@bazel/typescript" "^0.26.0" "@bazel/typescript" "^0.26.0"
"@microsoft/api-extractor" "^7.0.21" "@microsoft/api-extractor" "^7.0.21"
"@schematics/angular" "^7.0.4" "@schematics/angular" "^7.3.5"
"@types/node" "6.0.84" "@types/node" "6.0.84"
semver "^5.6.0" semver "^5.6.0"
shelljs "0.8.2" shelljs "0.8.2"
@ -158,7 +177,7 @@
resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.7.tgz#8fb4a9f4fdf01f1469c9fc54b0ad2d36ec57c25d" resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.7.tgz#8fb4a9f4fdf01f1469c9fc54b0ad2d36ec57c25d"
integrity sha512-0bqNlQT8aR4Iq9xx/OsY579Zeqon9uTZDIuvl+XXu16TPPN2sASeKojwm366jA2MjgXd9iyTWpJM5/P1QJ4Dxg== integrity sha512-0bqNlQT8aR4Iq9xx/OsY579Zeqon9uTZDIuvl+XXu16TPPN2sASeKojwm366jA2MjgXd9iyTWpJM5/P1QJ4Dxg==
"@schematics/angular@7.3.2", "@schematics/angular@^7.0.4": "@schematics/angular@7.3.2":
version "7.3.2" version "7.3.2"
resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.2.tgz#470f972a9d80ab8af9900e33972bce44aa567718" resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.2.tgz#470f972a9d80ab8af9900e33972bce44aa567718"
integrity sha512-ClqG1qA919QqsikIXIP/jKl2Boj70lihCbpXhZgjsahLY8UJgq9oh8K1QuvYJtz4AI4GADfG1fGzPdYfy94+kg== integrity sha512-ClqG1qA919QqsikIXIP/jKl2Boj70lihCbpXhZgjsahLY8UJgq9oh8K1QuvYJtz4AI4GADfG1fGzPdYfy94+kg==
@ -167,6 +186,15 @@
"@angular-devkit/schematics" "7.3.2" "@angular-devkit/schematics" "7.3.2"
typescript "3.2.4" typescript "3.2.4"
"@schematics/angular@^7.3.5":
version "7.3.5"
resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.5.tgz#7af1cd446b051b2be3fbe59cb4ba140ec06e2d87"
integrity sha512-fKNZccf1l2OcDwtDupYj54N/YuiMLCWeaXNxcJNUYvGnBtzxQJ4P2LtSCjB4HDvYCtseQM7iyc7D1Xrr5gI8nw==
dependencies:
"@angular-devkit/core" "7.3.5"
"@angular-devkit/schematics" "7.3.5"
typescript "3.2.4"
"@schematics/update@0.13.2": "@schematics/update@0.13.2":
version "0.13.2" version "0.13.2"
resolved "https://registry.yarnpkg.com/@schematics/update/-/update-0.13.2.tgz#14ba82076b435814896ac141ba4dfad0dd3dadcd" resolved "https://registry.yarnpkg.com/@schematics/update/-/update-0.13.2.tgz#14ba82076b435814896ac141ba4dfad0dd3dadcd"

View File

@ -40,7 +40,7 @@
"@bazel/karma": "0.26.0", "@bazel/karma": "0.26.0",
"@bazel/typescript": "0.26.0", "@bazel/typescript": "0.26.0",
"@microsoft/api-extractor": "^7.0.21", "@microsoft/api-extractor": "^7.0.21",
"@schematics/angular": "^7.3.2", "@schematics/angular": "^7.3.5",
"@types/angular": "^1.6.47", "@types/angular": "^1.6.47",
"@types/base64-js": "1.2.5", "@types/base64-js": "1.2.5",
"@types/chokidar": "^1.7.5", "@types/chokidar": "^1.7.5",

View File

@ -33,7 +33,6 @@ npm_package(
"//packages/bazel/src/ng_package:lib", "//packages/bazel/src/ng_package:lib",
"//packages/bazel/src/ngc-wrapped:ngc_lib", "//packages/bazel/src/ngc-wrapped:ngc_lib",
"//packages/bazel/src/protractor/utils", "//packages/bazel/src/protractor/utils",
"//packages/bazel/src/schematics/bazel-workspace",
"//packages/bazel/src/schematics/ng-add", "//packages/bazel/src/schematics/ng-add",
"//packages/bazel/src/schematics/ng-new", "//packages/bazel/src/schematics/ng-new",
], ],

View File

@ -23,7 +23,7 @@
"@angular-devkit/schematics": "^7.3.0-rc.0", "@angular-devkit/schematics": "^7.3.0-rc.0",
"@bazel/typescript": "^0.26.0", "@bazel/typescript": "^0.26.0",
"@microsoft/api-extractor": "^7.0.21", "@microsoft/api-extractor": "^7.0.21",
"@schematics/angular": "^7.0.4", "@schematics/angular": "^7.3.5",
"@types/node": "6.0.84", "@types/node": "6.0.84",
"semver": "^5.6.0", "semver": "^5.6.0",
"shelljs": "0.8.2", "shelljs": "0.8.2",

View File

@ -14,7 +14,6 @@ jasmine_node_test(
name = "test", name = "test",
bootstrap = ["angular/tools/testing/init_node_spec.js"], bootstrap = ["angular/tools/testing/init_node_spec.js"],
deps = [ deps = [
"//packages/bazel/src/schematics/bazel-workspace:test",
"//packages/bazel/src/schematics/ng-add:test", "//packages/bazel/src/schematics/ng-add:test",
"//packages/bazel/src/schematics/ng-new:test", "//packages/bazel/src/schematics/ng-new:test",
"//packages/bazel/src/schematics/utility:test", "//packages/bazel/src/schematics/utility:test",

View File

@ -1,34 +0,0 @@
load("//tools:defaults.bzl", "ts_library")
package(default_visibility = ["//visibility:public"])
ts_library(
name = "bazel-workspace",
srcs = [
"index.ts",
"schema.d.ts",
],
data = glob(["files/**/*"]) + [
"schema.json",
],
deps = [
"@npm//@angular-devkit/core",
"@npm//@angular-devkit/schematics",
"@npm//@schematics/angular",
],
)
ts_library(
name = "test",
testonly = True,
srcs = [
"index_spec.ts",
],
data = [
"//packages/bazel/src/schematics:package_assets",
],
deps = [
":bazel-workspace",
"@npm//@angular-devkit/schematics",
],
)

View File

@ -1,7 +0,0 @@
package(default_visibility = ["//visibility:public"])
# This export allows targets in other packages to reference files that live
# in this package.
exports_files([
"tsconfig.json",
])

View File

@ -1,63 +0,0 @@
# WARNING: This file is generated and it's not meant to be edited.
# Before making any changes, please read Bazel documentation.
# https://docs.bazel.build/versions/master/be/workspace.html
# The WORKSPACE file tells Bazel that this directory is a "workspace", which is like a project root.
# The content of this file specifies all the external dependencies Bazel needs to perform a build.
####################################
# ESModule imports (and TypeScript imports) can be absolute starting with the workspace name.
# The name of the workspace should match the npm package where we publish, so that these
# imports also make sense when referencing the published package.
workspace(name = "<%= utils.underscore(name) %>")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
RULES_NODEJS_VERSION = "<%= RULES_NODEJS_VERSION %>"
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "<%= RULES_NODEJS_SHA256 %>",
url = "https://github.com/bazelbuild/rules_nodejs/releases/download/%s/rules_nodejs-%s.tar.gz" % (RULES_NODEJS_VERSION, RULES_NODEJS_VERSION),
)
<% if (sass) { %>
# Rules for compiling sass
RULES_SASS_VERSION = "<%= RULES_SASS_VERSION %>"
http_archive(
name = "io_bazel_rules_sass",
sha256 = "<%= RULES_SASS_SHA256 %>",
url = "https://github.com/bazelbuild/rules_sass/archive/%s.zip" % RULES_SASS_VERSION,
strip_prefix = "rules_sass-%s" % RULES_SASS_VERSION,
)
<% } %>
####################################
# Load and install our dependencies downloaded above.
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")
# 0.18.0 is needed for .bazelignore
check_bazel_version("0.18.0")
node_repositories()
yarn_install(
name = "npm",
data = ["//:angular-metadata.tsconfig.json"],
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()
load("@npm_bazel_karma//:package.bzl", "rules_karma_dependencies")
rules_karma_dependencies()
load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories")
web_test_repositories()
load("@npm_bazel_karma//:browser_repositories.bzl", "browser_repositories")
browser_repositories()
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")
ts_setup_workspace()
<% if (sass) { %>
load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")
sass_repositories()
<% } %>

View File

@ -1,29 +0,0 @@
# Make TypeScript and Angular compilation fast, by keeping a few copies of the
# compiler running as daemons, and cache SourceFile AST's to reduce parse time.
build --strategy=TypeScriptCompile=worker
build --strategy=AngularTemplateCompile=worker
# Don't create bazel-* symlinks in the WORKSPACE directory, except `bazel-out`,
# which is mandatory.
# These require .gitignore and may scare users.
# Also, it's a workaround for https://github.com/bazelbuild/rules_typescript/issues/12
# which affects the common case of having `tsconfig.json` in the WORKSPACE directory.
#
# Instead, the output will appear in `dist/bin`. You'll need to ignore the
# `bazel-out` directory that is created in the workspace root.
build --symlink_prefix=dist/
# Turn on --incompatible_strict_action_env which was on by default
# in Bazel 0.21.0 but turned off again in 0.22.0. Follow
# https://github.com/bazelbuild/bazel/issues/7026 for more details.
# This flag is needed to so that the bazel cache is not invalidated
# when running bazel via `yarn bazel`.
# See https://github.com/angular/angular/issues/27514.
build --incompatible_strict_action_env
run --incompatible_strict_action_env
test --incompatible_strict_action_env
test --test_output=errors
# Use the Angular 6 compiler
build --define=compile=legacy

View File

@ -1,50 +0,0 @@
load("@npm_bazel_typescript//:index.bzl", "ts_library")
load("@npm_angular_bazel//:index.bzl", "protractor_web_test_suite")
ts_library(
name = "e2e_lib",
testonly = 1,
srcs = glob(["src/**/*.ts"]),
tsconfig = ":tsconfig.e2e.json",
deps = [
"@npm//@types/jasmine",
"@npm//@types/jasminewd2",
"@npm//@types/node",
"@npm//jasmine",
"@npm//protractor",
"@npm//tslib",
],
data = [
"//:tsconfig.json",
],
)
protractor_web_test_suite(
name = "prodserver_test",
data = [
"@npm//@angular/bazel",
"@npm//protractor",
],
on_prepare = ":protractor.on-prepare.js",
server = "//src:prodserver",
deps = [":e2e_lib"],
)
protractor_web_test_suite(
name = "devserver_test",
data = [
"@npm//@angular/bazel",
"@npm//protractor",
],
on_prepare = ":protractor.on-prepare.js",
server = "//src:devserver",
deps = [":e2e_lib"],
)
# Default target in this package is to run the e2e tests on the devserver.
# This is a faster round-trip but doesn't exercise production optimizations like
# code-splitting and lazy loading.
alias(
name = "e2e",
actual = "devserver_test",
)

View File

@ -1,153 +0,0 @@
package(default_visibility = ["//visibility:public"])
load("@npm_angular_bazel//:index.bzl", "ng_module")
load("@npm_bazel_karma//:index.bzl", "ts_web_test_suite")
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "history_server")
load("@build_bazel_rules_nodejs//internal/web_package:web_package.bzl", "web_package")
load("@npm_bazel_typescript//:index.bzl", "ts_devserver", "ts_library")
<% if (sass) { %>load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary")
multi_sass_binary(
name = "styles",
srcs = glob(["**/*.scss"]),
)
<% } %>
ng_module(
name = "src",
srcs = glob(
include = ["**/*.ts"],
exclude = [
"**/*.spec.ts",
"main.ts",
"test.ts",
"initialize_testbed.ts",
],
),
assets = glob([
"**/*.css",
"**/*.html",
])<% if (sass) { %> + [":styles"]<% } %>,
deps = [
"@npm//@angular/core",
"@npm//@angular/platform-browser",<% if (routing) { %>
"@npm//@angular/router",<% } %>
"@npm//@types",
"@npm//rxjs",
],
)
rollup_bundle(
name = "bundle",
entry_point = "src/main.prod",
deps = [
"//src",
"@npm//rxjs",
],
)
web_package(
name = "prodapp",
assets = [
# do not sort
"@npm//node_modules/zone.js:dist/zone.min.js",
":bundle.min.js",
],
data = [
"favicon.ico",
],
index_html = "index.html",
)
history_server(
name = "prodserver",
data = [":prodapp"],
templated_args = ["src/prodapp"],
)
filegroup(
name = "rxjs_umd_modules",
srcs = [
# do not sort
"@npm//node_modules/rxjs:bundles/rxjs.umd.js",
":rxjs_shims.js",
],
)
ts_devserver(
name = "devserver",
port = 4200,
entry_module = "<%= utils.underscore(name) %>/src/main.dev",
serving_path = "/bundle.min.js",
scripts = [
"@npm//node_modules/@angular/common:bundles/common.umd.js",
"@npm//node_modules/@angular/common:bundles/common-http.umd.js",
"@npm//node_modules/@angular/core:bundles/core.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser.umd.js",
"@npm//node_modules/tslib:tslib.js",
":rxjs_umd_modules",
],
static_files = [
"@npm//node_modules/zone.js:dist/zone.min.js",
],
data = [
"favicon.ico",
],
index_html = "index.html",
deps = [":src"],
)
ts_library(
name = "test_lib",
testonly = 1,
srcs = glob(["**/*.spec.ts"]),
deps = [
":src",
"@npm//@angular/core",
"@npm//@types",
],
)
ts_library(
name = "initialize_testbed",
testonly = 1,
srcs = [
"initialize_testbed.ts",
],
deps = [
"@npm//@angular/core",
"@npm//@angular/platform-browser-dynamic",
"@npm//@types",
],
)
ts_web_test_suite(
name = "test",
srcs = [
"@npm//node_modules/@angular/common:bundles/common.umd.js",
"@npm//node_modules/@angular/compiler:bundles/compiler.umd.js",
"@npm//node_modules/@angular/compiler:bundles/compiler-testing.umd.js",
"@npm//node_modules/@angular/core:bundles/core.umd.js",
"@npm//node_modules/@angular/core:bundles/core-testing.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser.umd.js",
"@npm//node_modules/@angular/platform-browser:bundles/platform-browser-testing.umd.js",
"@npm//node_modules/@angular/platform-browser-dynamic:bundles/platform-browser-dynamic.umd.js",
"@npm//node_modules/@angular/platform-browser-dynamic:bundles/platform-browser-dynamic-testing.umd.js",
"@npm//node_modules/tslib:tslib.js",
],
runtime_deps = [
":initialize_testbed",
],
# do not sort
bootstrap = [
"@npm//node_modules/zone.js:dist/zone-testing-bundle.js",
"@npm//node_modules/reflect-metadata:Reflect.js",
],
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
],
deps = [
":rxjs_umd_modules",
":test_lib",
"@npm//karma-jasmine",
],
)

View File

@ -1,76 +0,0 @@
/**
* @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 Schematics for bazel-workspace
*/
import {strings} from '@angular-devkit/core';
import {Rule, SchematicContext, Tree, apply, applyTemplates, mergeWith, url} from '@angular-devkit/schematics';
import {getWorkspace} from '@schematics/angular/utility/config';
import {validateProjectName} from '@schematics/angular/utility/validation';
import {Schema as BazelWorkspaceOptions} from './schema';
/**
* Clean the version string and return version in the form "1.2.3". Return
* null if version string is invalid. This is similar to semver.clean() but
* takes characters like '^' and '~' into account.
*/
export function clean(version: string): string|null {
const matches = version.match(/(\d+\.\d+\.\d+)/);
return matches && matches.pop() || null;
}
/**
* Returns true if project contains routing module, false otherwise.
*/
function hasRoutingModule(host: Tree) {
let hasRouting = false;
host.visit((file: string) => { hasRouting = hasRouting || file.endsWith('-routing.module.ts'); });
return hasRouting;
}
/**
* Returns true if project uses SASS stylesheets, false otherwise.
*/
function hasSassStylesheet(host: Tree) {
let hasSass = false;
// The proper extension for SASS is .scss
host.visit((file: string) => { hasSass = hasSass || file.endsWith('.scss'); });
return hasSass;
}
export default function(options: BazelWorkspaceOptions): Rule {
return (host: Tree, context: SchematicContext) => {
const name = options.name || getWorkspace(host).defaultProject;
if (!name) {
throw new Error('Please provide a name for Bazel workspace');
}
validateProjectName(name);
if (!host.exists('yarn.lock')) {
host.create('yarn.lock', '');
}
const workspaceVersions = {
'RULES_NODEJS_VERSION': '0.26.0',
'RULES_NODEJS_SHA256': '5c86b055c57e15bf32d9009a15bcd6d8e190c41b1ff2fb18037b75e0012e4e7c',
'RULES_SASS_VERSION': '1.17.2',
'RULES_SASS_SHA256': 'e5316ee8a09d1cbb732d3938b400836bf94dba91a27476e9e27706c4c0edae1f',
};
return mergeWith(apply(url('./files'), [
applyTemplates({
utils: strings,
name,
'dot': '.', ...workspaceVersions,
routing: hasRoutingModule(host),
sass: hasSassStylesheet(host),
}),
]));
};
}

View File

@ -1,120 +0,0 @@
/**
* @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
*/
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing';
import {clean} from './index';
describe('Bazel-workspace Schematic', () => {
const schematicRunner =
new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json'));
const defaultOptions = {
name: 'demo',
};
it('should generate Bazel workspace files', () => {
const options = {...defaultOptions};
const host = schematicRunner.runSchematic('bazel-workspace', options);
const files = host.files;
expect(files).toContain('/.bazelignore');
expect(files).toContain('/.bazelrc');
expect(files).toContain('/BUILD.bazel');
expect(files).toContain('/src/BUILD.bazel');
expect(files).toContain('/WORKSPACE');
expect(files).toContain('/yarn.lock');
});
it('should generate empty yarn.lock file', () => {
const host = schematicRunner.runSchematic('bazel-workspace', defaultOptions);
expect(host.files).toContain('/yarn.lock');
expect(host.readContent('/yarn.lock')).toBe('');
});
it('should not replace yarn.lock if it exists', () => {
let host = new UnitTestTree(new HostTree());
host.create('yarn.lock', 'some content');
expect(host.files).toContain('/yarn.lock');
host = schematicRunner.runSchematic('bazel-workspace', defaultOptions, host);
expect(host.files).toContain('/yarn.lock');
expect(host.readContent('/yarn.lock')).toBe('some content');
});
it('should have the correct entry_module for devserver', () => {
const options = {...defaultOptions, name: 'demo-app'};
const host = schematicRunner.runSchematic('bazel-workspace', options);
const {files} = host;
expect(files).toContain('/src/BUILD.bazel');
const content = host.readContent('/src/BUILD.bazel');
expect(content).toContain('entry_module = "demo_app/src/main.dev"');
});
it('should add router if project contains routing module', () => {
let host = new UnitTestTree(new HostTree);
host.create('/src/app/app-routing.module.ts', '');
expect(host.files).toContain('/src/app/app-routing.module.ts');
const options = {...defaultOptions};
host = schematicRunner.runSchematic('bazel-workspace', options, host);
expect(host.files).toContain('/src/BUILD.bazel');
const content = host.readContent('/src/BUILD.bazel');
expect(content).toContain('@npm//@angular/router');
});
describe('WORKSPACE', () => {
it('should contain project name', () => {
const options = {...defaultOptions};
const host = schematicRunner.runSchematic('bazel-workspace', options);
expect(host.files).toContain('/WORKSPACE');
const content = host.readContent('/WORKSPACE');
expect(content).toContain('workspace(name = "demo")');
});
it('should convert dashes in name to underscore', () => {
const options = {...defaultOptions, name: 'demo-project'};
const host = schematicRunner.runSchematic('bazel-workspace', options);
expect(host.files).toContain('/WORKSPACE');
const content = host.readContent('/WORKSPACE');
expect(content).toContain('workspace(name = "demo_project"');
});
});
describe('SASS', () => {
let host = new UnitTestTree(new HostTree);
beforeAll(() => {
host.create('/src/app/app.component.scss', '');
expect(host.files).toContain('/src/app/app.component.scss');
const options = {...defaultOptions};
host = schematicRunner.runSchematic('bazel-workspace', options, host);
expect(host.files).toContain('/WORKSPACE');
expect(host.files).toContain('/src/BUILD.bazel');
});
it('should download and load rules_sass in WORKSPACE', () => {
const content = host.readContent('/WORKSPACE');
expect(content).toContain('RULES_SASS_VERSION');
expect(content).toContain(
'load("@io_bazel_rules_sass//sass:sass_repositories.bzl", "sass_repositories")');
});
it('should add multi_sass_binary rule in src/BUILD', () => {
const content = host.readContent('/src/BUILD.bazel');
expect(content).toContain('load("@io_bazel_rules_sass//:defs.bzl", "multi_sass_binary")');
expect(content).toContain('glob(["**/*.scss"])');
});
});
});
describe('clean', () => {
[['1.2.3', '1.2.3'], [' 1.2.3', '1.2.3'], ['1.2.3 ', '1.2.3'], ['~1.2.3', '1.2.3'],
['^1.2.3', '1.2.3'], ['v1.2.3', '1.2.3'], ['1.2', null], ['a.b.c', null],
].forEach(([version, want]: [string, string]) => {
it(`should match ${version} with ${want}`, () => {
const got = clean(version);
expect(got).toBe(want);
});
});
});

View File

@ -1,13 +0,0 @@
// THIS FILE IS AUTOMATICALLY GENERATED. TO UPDATE THIS FILE YOU NEED TO CHANGE
// THE CORRESPONDING JSON SCHEMA FILE. See README.md.
// tslint:disable:no-global-tslint-disable
// tslint:disable
export interface Schema {
/**
* The name of the project.
*/
name?: string;
}

View File

@ -1,19 +0,0 @@
{
"$schema": "http://json-schema.org/schema",
"id": "SchematicsAngularBazelWorkspace",
"title": "Angular Bazel Workspace Schema",
"type": "object",
"properties": {
"name": {
"description": "The name of the project.",
"type": "string",
"format": "html-selector",
"$default": {
"$source": "argv",
"index": 0
}
}
},
"required": [
]
}

View File

@ -11,12 +11,6 @@
"factory": "./ng-new", "factory": "./ng-new",
"schema": "./ng-new/schema.json", "schema": "./ng-new/schema.json",
"description": "Create an Angular project that builds with Bazel." "description": "Create an Angular project that builds with Bazel."
},
"bazel-workspace": {
"factory": "./bazel-workspace",
"schema": "./bazel-workspace/schema.json",
"description": "Setup Bazel workspace",
"hidden": true
} }
} }
} }

View File

@ -12,7 +12,6 @@ ts_library(
"schema.json", "schema.json",
], ],
deps = [ deps = [
"//packages/bazel/src/schematics/bazel-workspace",
"//packages/bazel/src/schematics/utility", "//packages/bazel/src/schematics/utility",
"@npm//@angular-devkit/core", "@npm//@angular-devkit/core",
"@npm//@angular-devkit/schematics", "@npm//@angular-devkit/schematics",

View File

@ -61,20 +61,13 @@ function addDevDependenciesToPackageJson(options: Schema) {
} }
/** /**
* Append main.dev.ts and main.prod.ts to src directory. These files are needed * Append additional Javascript / Typescript files needed to compile an Angular
* by Bazel for devserver and prodserver, respectively. They are different from * project under Bazel.
* main.ts generated by CLI because they use platformBrowser (AOT) instead of
* platformBrowserDynamic (JIT).
*/ */
function addDevAndProdMainForAot(options: Schema) { function addFilesRequiredByBazel(options: Schema) {
return (host: Tree) => { return (host: Tree) => {
return mergeWith(apply(url('./files'), [ return mergeWith(apply(url('./files'), [
applyTemplates({ applyTemplates({}),
utils: strings,
...options,
'dot': '.',
}),
move('/src'),
])); ]));
}; };
} }
@ -331,8 +324,7 @@ export default function(options: Schema): Rule {
validateProjectName(options.name); validateProjectName(options.name);
return chain([ return chain([
schematic('bazel-workspace', options), addFilesRequiredByBazel(options),
addDevAndProdMainForAot(options),
addDevDependenciesToPackageJson(options), addDevDependenciesToPackageJson(options),
addPostinstallToGenerateNgSummaries(), addPostinstallToGenerateNgSummaries(),
backupAngularJson(), backupAngularJson(),

View File

@ -17,54 +17,45 @@ describe('ng-add schematic', () => {
beforeEach(() => { beforeEach(() => {
host = new UnitTestTree(new HostTree()); host = new UnitTestTree(new HostTree());
host.create( host.create('package.json', JSON.stringify({
'package.json', JSON.stringify( name: 'demo',
{ dependencies: {
name: 'demo', '@angular/core': '1.2.3',
dependencies: { 'rxjs': '~6.3.3',
'@angular/core': '1.2.3', },
'rxjs': '~6.3.3', devDependencies: {
}, 'typescript': '3.2.2',
devDependencies: { },
'typescript': '3.2.2', }));
}, host.create('tsconfig.json', JSON.stringify({
}, compileOnSave: false,
null, 2)); compilerOptions: {
host.create( baseUrl: './',
'tsconfig.json', JSON.stringify( outDir: './dist/out-tsc',
{ }
compileOnSave: false, }));
compilerOptions: { host.create('angular.json', JSON.stringify({
baseUrl: './', projects: {
outDir: './dist/out-tsc', 'demo': {
} architect: {
}, build: {},
null, 2)); serve: {},
host.create( test: {},
'angular.json', JSON.stringify( 'extract-i18n': {
{ builder: '@angular-devkit/build-angular:extract-i18n',
projects: { },
'demo': { },
architect: { },
build: {}, 'demo-e2e': {
serve: {}, architect: {
test: {}, e2e: {},
'extract-i18n': { lint: {
builder: '@angular-devkit/build-angular:extract-i18n', builder: '@angular-devkit/build-angular:tslint',
}, },
}, },
}, },
'demo-e2e': { },
architect: { }));
e2e: {},
lint: {
builder: '@angular-devkit/build-angular:tslint',
},
},
},
},
},
null, 2));
schematicRunner = schematicRunner =
new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json')); new SchematicTestRunner('@angular/bazel', require.resolve('../collection.json'));
}); });
@ -109,11 +100,11 @@ describe('ng-add schematic', () => {
expect(devDeps).toContain('@bazel/karma'); expect(devDeps).toContain('@bazel/karma');
}); });
it('should create Bazel workspace file', () => { it('should not create Bazel workspace file', () => {
host = schematicRunner.runSchematic('ng-add', defaultOptions, host); host = schematicRunner.runSchematic('ng-add', defaultOptions, host);
const {files} = host; const {files} = host;
expect(files).toContain('/WORKSPACE'); expect(files).not.toContain('/WORKSPACE');
expect(files).toContain('/BUILD.bazel'); expect(files).not.toContain('/BUILD.bazel');
}); });
it('should produce main.dev.ts and main.prod.ts for AOT', () => { it('should produce main.dev.ts and main.prod.ts for AOT', () => {
@ -225,19 +216,16 @@ describe('ng-add schematic', () => {
]; ];
for (const [version, upgrade] of cases) { for (const [version, upgrade] of cases) {
it(`should ${upgrade ? '' : 'not '}upgrade v${version}')`, () => { it(`should ${upgrade ? '' : 'not '}upgrade v${version}')`, () => {
host.overwrite( host.overwrite('package.json', JSON.stringify({
'package.json', JSON.stringify( name: 'demo',
{ dependencies: {
name: 'demo', '@angular/core': '1.2.3',
dependencies: { 'rxjs': version,
'@angular/core': '1.2.3', },
'rxjs': version, devDependencies: {
}, 'typescript': '3.2.2',
devDependencies: { },
'typescript': '3.2.2', }));
},
},
null, 2));
host = schematicRunner.runSchematic('ng-add', defaultOptions, host); host = schematicRunner.runSchematic('ng-add', defaultOptions, host);
expect(host.files).toContain('/package.json'); expect(host.files).toContain('/package.json');
const content = host.readContent('/package.json'); const content = host.readContent('/package.json');

View File

@ -25,12 +25,11 @@ describe('ng-new schematic', () => {
expect(files).toContain('/demo/package.json'); expect(files).toContain('/demo/package.json');
}); });
it('should call ng-add to generate Bazel files', () => { it('should call ng-add to generate additional files needed by Bazel', () => {
const options = {...defaultOptions}; const options = {...defaultOptions};
const host = schematicRunner.runSchematic('ng-new', options); const host = schematicRunner.runSchematic('ng-new', options);
const {files} = host; const {files} = host;
expect(files).toContain('/demo/WORKSPACE'); expect(files).toContain('/demo/src/main.dev.ts');
expect(files).toContain('/demo/BUILD.bazel'); expect(files).toContain('/demo/src/main.prod.ts');
expect(files).toContain('/demo/src/BUILD.bazel');
}); });
}); });

View File

@ -31,6 +31,17 @@
rxjs "6.3.3" rxjs "6.3.3"
source-map "0.7.3" source-map "0.7.3"
"@angular-devkit/core@7.3.5":
version "7.3.5"
resolved "https://registry.yarnpkg.com/@angular-devkit/core/-/core-7.3.5.tgz#2a59a913eab358e2385f52ba28132b81435e63b3"
integrity sha512-J/Tztq2BZ3tpwUsbiz8N61rf9lwqn85UvJsDui2SPIdzDR9KmPr5ESI2Irc/PEb9i+CBXtVuhr8AIqo7rR6ZTg==
dependencies:
ajv "6.9.1"
chokidar "2.0.4"
fast-json-stable-stringify "2.0.0"
rxjs "6.3.3"
source-map "0.7.3"
"@angular-devkit/schematics@7.3.2", "@angular-devkit/schematics@^7.3.2": "@angular-devkit/schematics@7.3.2", "@angular-devkit/schematics@^7.3.2":
version "7.3.2" version "7.3.2"
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.2.tgz#e9d3c1f2128a56f66ea846ce3f80c69d4c3a9ae9" resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.2.tgz#e9d3c1f2128a56f66ea846ce3f80c69d4c3a9ae9"
@ -39,6 +50,14 @@
"@angular-devkit/core" "7.3.2" "@angular-devkit/core" "7.3.2"
rxjs "6.3.3" rxjs "6.3.3"
"@angular-devkit/schematics@7.3.5":
version "7.3.5"
resolved "https://registry.yarnpkg.com/@angular-devkit/schematics/-/schematics-7.3.5.tgz#7b007f8a86dea76e93eef007d4fb6e7d8324b7bb"
integrity sha512-BFCCkwRMBC4aFlngaloi1avCTgGrl1MFc/0Av2sCpBh/fdm1FqSVzmOiTfu93dehRVVL/bTrA2qj+xpNsXCxzA==
dependencies:
"@angular-devkit/core" "7.3.5"
rxjs "6.3.3"
"@angular/bazel@file:./tools/npm/@angular_bazel": "@angular/bazel@file:./tools/npm/@angular_bazel":
version "0.0.0" version "0.0.0"
@ -265,7 +284,7 @@
resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.5.tgz#c448a38902ccb5601c1b2ef3b1a105012ef7712c" resolved "https://registry.yarnpkg.com/@microsoft/tsdoc/-/tsdoc-0.12.5.tgz#c448a38902ccb5601c1b2ef3b1a105012ef7712c"
integrity sha512-xEAyvLXo4Cter/b0EMCWUZTgXOfLOPJ/Xr52WdjVclPx9eDmNTGFtZl8Pn/nqSnZsQBNcHL0eHk/YyRyyXXpiQ== integrity sha512-xEAyvLXo4Cter/b0EMCWUZTgXOfLOPJ/Xr52WdjVclPx9eDmNTGFtZl8Pn/nqSnZsQBNcHL0eHk/YyRyyXXpiQ==
"@schematics/angular@7.3.2", "@schematics/angular@^7.3.2": "@schematics/angular@7.3.2":
version "7.3.2" version "7.3.2"
resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.2.tgz#470f972a9d80ab8af9900e33972bce44aa567718" resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.2.tgz#470f972a9d80ab8af9900e33972bce44aa567718"
integrity sha512-ClqG1qA919QqsikIXIP/jKl2Boj70lihCbpXhZgjsahLY8UJgq9oh8K1QuvYJtz4AI4GADfG1fGzPdYfy94+kg== integrity sha512-ClqG1qA919QqsikIXIP/jKl2Boj70lihCbpXhZgjsahLY8UJgq9oh8K1QuvYJtz4AI4GADfG1fGzPdYfy94+kg==
@ -274,6 +293,15 @@
"@angular-devkit/schematics" "7.3.2" "@angular-devkit/schematics" "7.3.2"
typescript "3.2.4" typescript "3.2.4"
"@schematics/angular@^7.3.5":
version "7.3.5"
resolved "https://registry.yarnpkg.com/@schematics/angular/-/angular-7.3.5.tgz#7af1cd446b051b2be3fbe59cb4ba140ec06e2d87"
integrity sha512-fKNZccf1l2OcDwtDupYj54N/YuiMLCWeaXNxcJNUYvGnBtzxQJ4P2LtSCjB4HDvYCtseQM7iyc7D1Xrr5gI8nw==
dependencies:
"@angular-devkit/core" "7.3.5"
"@angular-devkit/schematics" "7.3.5"
typescript "3.2.4"
"@schematics/update@0.13.2": "@schematics/update@0.13.2":
version "0.13.2" version "0.13.2"
resolved "https://registry.yarnpkg.com/@schematics/update/-/update-0.13.2.tgz#14ba82076b435814896ac141ba4dfad0dd3dadcd" resolved "https://registry.yarnpkg.com/@schematics/update/-/update-0.13.2.tgz#14ba82076b435814896ac141ba4dfad0dd3dadcd"