cleanup(repo): remove bazel package

This commit is contained in:
Victor Savkin 2020-11-02 08:30:40 -05:00 committed by Victor Savkin
parent 760811308e
commit 5e9a7d76ac
41 changed files with 5 additions and 1135 deletions

View File

@ -16,7 +16,6 @@ module.exports = {
scopes: [ scopes: [
{ name: 'angular', description: 'anything Angular specific' }, { name: 'angular', description: 'anything Angular specific' },
{ name: 'bazel', description: 'anything Bazel specific' },
{ name: 'core', description: 'anything Nx core specific' }, { name: 'core', description: 'anything Nx core specific' },
{ name: 'docs', description: 'anything related to docs infrastructure' }, { name: 'docs', description: 'anything related to docs infrastructure' },
{ name: 'nextjs', description: 'anything Next specific' }, { name: 'nextjs', description: 'anything Next specific' },

View File

@ -162,7 +162,6 @@ The type must be one of the following:
The scope must be one of the following: The scope must be one of the following:
- angular - anything Angular specific - angular - anything Angular specific
- bazel - anything Bazel specific
- core - anything Nx core specific - core - anything Nx core specific
- docs - anything related to docs infrastructure - docs - anything related to docs infrastructure
- nextjs - anything Next specific - nextjs - anything Next specific

View File

@ -1,6 +1,5 @@
[ [
"angular", "angular",
"bazel",
"cypress", "cypress",
"express", "express",
"jest", "jest",

View File

@ -21,7 +21,6 @@ Nx is an open platform with plugins for many modern tools and frameworks. **To s
> NX Also available: > NX Also available:
@nrwl/bazel (schematics)
@nrwl/express (builders,schematics) @nrwl/express (builders,schematics)
@nrwl/linter (builders) @nrwl/linter (builders)
@nrwl/nest (builders,schematics) @nrwl/nest (builders,schematics)

View File

@ -1,6 +1,5 @@
[ [
"angular", "angular",
"bazel",
"cypress", "cypress",
"express", "express",
"jest", "jest",

View File

@ -1,6 +1,5 @@
[ [
"angular", "angular",
"bazel",
"cypress", "cypress",
"express", "express",
"jest", "jest",

View File

@ -24,7 +24,6 @@ Nx is an open platform with plugins for many modern tools and frameworks. **To s
> NX Also available: > NX Also available:
@nrwl/angular (schematics) @nrwl/angular (schematics)
@nrwl/bazel (schematics)
@nrwl/express (builders,schematics) @nrwl/express (builders,schematics)
@nrwl/nest (builders,schematics) @nrwl/nest (builders,schematics)
@nrwl/next (builders,schematics) @nrwl/next (builders,schematics)

View File

@ -1,10 +0,0 @@
module.exports = {
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
maxWorkers: 1,
globals: { 'ts-jest': { tsConfig: '<rootDir>/tsconfig.spec.json' } },
displayName: 'e2e-bazel',
};

View File

@ -1,83 +0,0 @@
import {
checkFilesExist,
ensureProject,
forEachCli,
readFile,
runCLI,
runCommand,
uniq,
updateFile,
} from '@nrwl/e2e/utils';
forEachCli((currentCLIName) => {
describe('Bazel', () => {
const ngapp = uniq('ngapp');
const reactapp = uniq('reactapp');
const nglib = uniq('nglib');
const reactlib = uniq('reactlib');
it('noop', () => {});
xit('should generate build files for apps', () => {
ensureProject();
runCLI(`generate @nrwl/angular:app ${ngapp}`);
runCLI('generate @nrwl/bazel:sync');
checkFilesExist(`apps/${ngapp}/BUILD.bazel`);
runCLI(`generate @nrwl/react:app ${reactapp}`);
runCLI('generate @nrwl/bazel:sync');
checkFilesExist(`apps/${reactapp}/BUILD.bazel`);
});
xit('should generate build files for libs', () => {
runCLI(`generate @nrwl/angular:lib ${nglib}`);
runCLI('generate @nrwl/bazel:sync');
checkFilesExist(`libs/${nglib}/BUILD.bazel`);
runCLI(`generate @nrwl/angular:lib ${reactlib}`);
runCLI('generate @nrwl/bazel:sync');
checkFilesExist(`libs/${reactlib}/BUILD.bazel`);
});
xit('should add dependencies to build files', () => {
updateFile(`apps/${ngapp}/src/main.ts`, `import '@proj/${nglib}';`);
runCLI('generate @nrwl/bazel:sync');
expect(readFile(`apps/${ngapp}/BUILD.bazel`)).toContain(
`//libs/${nglib}:${nglib}`
);
updateFile(`apps/${reactapp}/src/main.ts`, `import '@proj/${reactlib}';`);
runCLI('generate @nrwl/bazel:sync');
expect(readFile(`apps/${reactapp}/BUILD.bazel`)).toContain(
`//libs/${reactlib}:${reactlib}`
);
});
xit('should be able to lint projects with bazel', () => {
const lintResult = runCommand(
`./node_modules/.bin/bazel test //apps/${ngapp}:lint`
);
expect(lintResult).toContain('PASSED');
});
xit('should be able to build projects with bazel', () => {
const buildResult = runCommand(
`./node_modules/.bin/bazel build //apps/${ngapp}:build`
);
});
xit('should be able to test projects with bazel', () => {
const testResult = runCommand(
`./node_modules/.bin/bazel test //apps/${ngapp}:test`
);
expect(testResult).toContain('PASSED');
});
xit('should be able to e2e test projects with bazel', () => {
const e2eResult = runCommand(
`./node_modules/.bin/bazel test //apps/${ngapp}-e2e:e2e`
);
expect(e2eResult).toContain('PASSED');
});
});
});

View File

@ -1,13 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
]
}

View File

@ -1,16 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.test.ts",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.d.ts"
]
}

View File

@ -17,7 +17,6 @@ module.exports = {
'<rootDir>/packages/create-nx-workspace', '<rootDir>/packages/create-nx-workspace',
'<rootDir>/packages/create-nx-plugin', '<rootDir>/packages/create-nx-plugin',
'<rootDir>/packages/cli', '<rootDir>/packages/cli',
'<rootDir>/packages/bazel',
'<rootDir>/packages/angular', '<rootDir>/packages/angular',
], ],
}; };

View File

@ -99,10 +99,6 @@
"cli": { "cli": {
"tags": [] "tags": []
}, },
"bazel": {
"tags": [],
"implicitDependencies": ["workspace"]
},
"angular": { "angular": {
"tags": [], "tags": [],
"implicitDependencies": ["workspace", "cypress", "jest"] "implicitDependencies": ["workspace", "cypress", "jest"]
@ -118,10 +114,6 @@
"tags": [], "tags": [],
"implicitDependencies": ["angular"] "implicitDependencies": ["angular"]
}, },
"e2e-bazel": {
"tags": [],
"implicitDependencies": ["bazel"]
},
"e2e-cypress": { "e2e-cypress": {
"tags": [], "tags": [],
"implicitDependencies": ["cypress"] "implicitDependencies": ["cypress"]

View File

@ -49,8 +49,6 @@
"@babel/preset-env": "7.9.6", "@babel/preset-env": "7.9.6",
"@babel/preset-react": "7.9.4", "@babel/preset-react": "7.9.4",
"@babel/preset-typescript": "7.10.4", "@babel/preset-typescript": "7.10.4",
"@bazel/bazel": "^1.2.0",
"@bazel/ibazel": "^0.10.3",
"@cypress/webpack-preprocessor": "~4.1.2", "@cypress/webpack-preprocessor": "~4.1.2",
"@nestjs/common": "^7.0.0", "@nestjs/common": "^7.0.0",
"@nestjs/core": "^7.0.0", "@nestjs/core": "^7.0.0",

View File

@ -1,5 +0,0 @@
{
"extends": "../../.eslintrc",
"rules": {},
"ignorePatterns": ["!**/*"]
}

View File

@ -1,15 +0,0 @@
<p align="center"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600"></p>
{{links}}
<hr>
# Bazel Plugin for Nx
{{what-is-nx}}
## How to Use
This package is used by the `@nrwl/workspace`. See [https://github.com/nrwl/nx](https://github.com/nrwl/nx) for more information.
{{resources}}

View File

@ -1,20 +0,0 @@
{
"name": "Nx Bazel",
"version": "0.1",
"extends": [],
"schematics": {
"init": {
"factory": "./src/schematics/init/init",
"schema": "./src/schematics/init/schema.json",
"aliases": ["ng-add"],
"description": "Add Bazel Files",
"hidden": true
},
"sync": {
"factory": "./src/schematics/sync/sync",
"schema": "./src/schematics/sync/schema.json",
"description": "Sync Build Files",
"hidden": true
}
}
}

View File

@ -1,9 +0,0 @@
module.exports = {
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'],
globals: { 'ts-jest': { tsConfig: '<rootDir>/tsconfig.spec.json' } },
displayName: 'bazel',
};

View File

@ -1,3 +0,0 @@
{
"schematics": {}
}

View File

@ -1,54 +0,0 @@
{
"name": "@nrwl/bazel",
"version": "0.0.1",
"description": "Bazel Plugin for Nx",
"repository": {
"type": "git",
"url": "git+https://github.com/nrwl/nx.git"
},
"keywords": [
"Monorepo",
"Bazel",
"Angular",
"React",
"Web",
"Node",
"Nest",
"Jest",
"Cypress",
"CLI"
],
"main": "index.js",
"types": "index.d.ts",
"author": "Victor Savkin",
"license": "MIT",
"bugs": {
"url": "https://github.com/nrwl/nx/issues"
},
"homepage": "https://nx.dev",
"schematics": "./collection.json",
"builders": "./builders.json",
"ng-update": {
"requirements": {},
"migrations": "./migrations.json",
"packageGroup": [
"@nrwl/workspace",
"@nrwl/angular",
"@nrwl/cypress",
"@nrwl/express",
"@nrwl/jest",
"@nrwl/nest",
"@nrwl/node",
"@nrwl/react",
"@nrwl/web"
]
},
"dependencies": {
"@angular-devkit/core": "~10.1.3",
"@angular-devkit/schematics": "~10.1.3",
"@nrwl/cli": "*"
},
"peerDependencies": {
"@nrwl/workspace": "*"
}
}

View File

@ -1,83 +0,0 @@
# Common Bazel settings for JavaScript/NodeJS workspaces
# This rc file is automatically discovered when Bazel is run in this workspace,
# see https://docs.bazel.build/versions/master/guide.html#bazelrc
#
# The full list of Bazel options: https://docs.bazel.build/versions/master/command-line-reference.html
# Bazel will create symlinks from the workspace directory to output artifacts.
# Build results will be placed in a directory called "dist/bin"
# Other directories will be created like "dist/testlogs"
# Be aware that this will still create a bazel-out symlink in
# your project directory, which you must exclude from version control and your
# editor's search path.
build --symlink_prefix=dist/
# To disable the symlinks altogether (including bazel-out) you can use
# build --symlink_prefix=/
# however this makes it harder to find outputs.
# Specifies desired output mode for running tests.
# Valid values are
# 'summary' to output only test status summary
# 'errors' to also print test logs for failed tests
# 'all' to print logs for all tests
# 'streamed' to output logs for all tests in real time
# (this will force tests to be executed locally one at a time regardless of --test_strategy value).
test --test_output=errors
# Support for debugging NodeJS tests
# Add the Bazel option `--config=debug` to enable this
# --test_output=streamed
# Stream stdout/stderr output from each test in real-time.
# See https://docs.bazel.build/versions/master/user-manual.html#flag--test_output for more details.
# --test_strategy=exclusive
# Run one test at a time.
# --test_timeout=9999
# Prevent long running tests from timing out
# See https://docs.bazel.build/versions/master/user-manual.html#flag--test_timeout for more details.
# --nocache_test_results
# Always run tests
# --node_options=--inspect-brk
# Pass the --inspect-brk option to all tests which enables the node inspector agent.
# See https://nodejs.org/de/docs/guides/debugging-getting-started/#command-line-options for more details.
# --define=VERBOSE_LOGS=1
# Rules will output verbose logs if the VERBOSE_LOGS environment variable is set. `VERBOSE_LOGS` will be passed to
# `nodejs_binary` and `nodejs_test` via the default value of the `default_env_vars` attribute of those rules.
# --define=DEBUG=1
# Rules may change their build outputs if the DEBUG environment variable is set. For example,
# mininfiers such as terser may make their output more human readable when this is set. `DEBUG` will be passed to
# `nodejs_binary` and `nodejs_test` via the default value of the `default_env_vars` attribute of those rules.
test:debug --test_output=streamed --test_strategy=exclusive --test_timeout=9999 --nocache_test_results --define=VERBOSE_LOGS=1
# Use bazel run with `--config=debug` to turn on the NodeJS inspector agent.
# The node process will break before user code starts and wait for the debugger to connect.
run:debug --define=VERBOSE_LOGS=1 -- --node_options=--inspect-brk
# The following option will change the build output of certain rules such as terser and may not be desirable in all cases
build:debug --define=DEBUG=1
# Turn off legacy external runfiles
# This prevents accidentally depending on this feature, which Bazel will remove.
build --nolegacy_external_runfiles
# Turn on the "Managed Directories" feature.
# This allows Bazel to share the same node_modules directory with other tools
# NB: this option was introduced in Bazel 0.26
# See https://docs.bazel.build/versions/master/command-line-reference.html#flag--experimental_allow_incremental_repository_updates
common --experimental_allow_incremental_repository_updates
# 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
# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
# config, as the user configuration should be able to overwrite flags from this file.
# See https://docs.bazel.build/versions/master/best-practices.html#bazelrc
# (Note that we use .bazelrc.user so the file appears next to .bazelrc in directory listing,
# rather than user.bazelrc as suggested in the Bazel docs)
try-import %workspace%/.bazelrc.user

View File

@ -1,41 +0,0 @@
import { Tree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
import { runSchematic } from '../utils/testing';
import { readJsonInTree } from '@nrwl/workspace/src/utils/ast-utils';
describe('@nrwl/bazel:sync', () => {
let tree: Tree;
beforeEach(() => {
tree = Tree.empty();
tree = createEmptyWorkspace(tree);
tree.create('.gitignore', '');
});
describe('.bazelrc', () => {
it('should be created', async () => {
const result = await runSchematic('init', {}, tree);
expect(result.exists('.bazelrc')).toEqual(true);
});
});
describe('@bazel dependencies', () => {
it('should be added', async () => {
const result = await runSchematic('init', {}, tree);
const packageJson = readJsonInTree(result, 'package.json');
expect(packageJson.devDependencies['@bazel/bazel']).toBeDefined();
expect(packageJson.devDependencies['@bazel/ibazel']).toBeDefined();
});
});
describe('.gitignore', () => {
it('should have "bazel-*" added', async () => {
const result = await runSchematic('init', {}, tree);
const gitignore = result.readContent('.gitignore');
expect(gitignore).toContain('bazel-*');
});
});
});

View File

@ -1,66 +0,0 @@
import {
apply,
chain,
mergeWith,
Rule,
template,
url,
} from '@angular-devkit/schematics';
import { addDepsToPackageJson, readJsonInTree } from '@nrwl/workspace';
import ignore from 'ignore';
import { bazelVersion, iBazelVersion } from '../utils/versions';
import { noop } from 'rxjs';
function updateGitIgnore(): Rule {
return (host) => {
if (!host.exists('.gitignore')) {
return;
}
const ig = ignore();
ig.add(host.read('.gitignore').toString());
if (!ig.ignores('bazel-out')) {
const content = `${host
.read('.gitignore')!
.toString('utf-8')
.trimRight()}\nbazel-*\n`;
host.overwrite('.gitignore', content);
}
};
}
const updateDependencies = addDepsToPackageJson(
{},
{
'@bazel/bazel': bazelVersion,
'@bazel/ibazel': iBazelVersion,
},
true
);
function addFiles() {
return (host) => {
if (host.exists('/.bazelrc')) {
return noop;
}
return mergeWith(
apply(url('./files/root'), [
template({
tmpl: '',
}),
])
);
};
}
export default (): Rule => {
return (host) => {
const packageJson = readJsonInTree(host, 'package.json');
return chain([
updateGitIgnore(),
!packageJson.devDependencies['@bazel/bazel'] ? updateDependencies : noop,
addFiles(),
]);
};
};

View File

@ -1,8 +0,0 @@
{
"$schema": "http://json-schema.org/schema",
"id": "NxBazelInit",
"title": "Bazel Init Schema",
"type": "object",
"properties": {},
"required": []
}

View File

@ -1,33 +0,0 @@
# ==== Generated by Nx
# ==== Do not touch
load("@npm//@nrwl/cli:index.bzl", "nx", "nx_test")
filegroup(
name = "<%= project.name %>",
srcs = glob(["**"]) + [
# Dependencies
<% for (dep of dependencies) { %>"<%= dep %>",
<% } %>
],
visibility = ["//visibility:public"],
)
<% for (label of labels) { %>
<%= label.bazelRuleName %>(
name = "<%= label.bazelLabel %>",
args = [
"run",
"<%= label.cliTarget %>",<% if (label.isBuildTarget) { %>
"--<%= label.outputArgument %>=$(@D)",<% } %>
],
data = [
":<%= project.name %>",
# Root Files
"//:root-files",
# Node Modules
"@npm//:node_modules"
],<% if (label.isBuildTarget) { %>
output_dir = True,<% } %>
)
<% } %>

View File

@ -1,9 +0,0 @@
filegroup(
name = "root-files",
srcs = [
# Root Files
<% for (rootFile of rootFiles) { %>"<%= rootFile %>",
<% } %>
],
visibility = ["//:__subpackages__"],
)

View File

@ -1,36 +0,0 @@
# Bazel workspace created by @bazel/create 0.38.1
# Declares that this directory is the root of a Bazel workspace.
# See https://docs.bazel.build/versions/master/build-ref.html#workspace
workspace(
# How this workspace would be referenced with absolute labels from another workspace
name = "<%= name %>",
# Map the @npm bazel workspace to the node_modules directory.
# This lets Bazel use the same node_modules as other local tooling.
managed_directories = {"@npm": ["node_modules"]},
)
# Install the nodejs "bootstrap" package
# This provides the basic tools for running and packaging nodejs programs in Bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "<%= rulesNodeJSSha %>",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/<%= rulesNodeJSVersion %>/rules_nodejs-<%= rulesNodeJSVersion %>.tar.gz"],
)
# The yarn_install rule runs yarn anytime the package.json or yarn.lock file changes.
# It also extracts and installs any Bazel rules distributed in an npm package.
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
yarn_install(
# Name this npm so that Bazel Label references look like @npm//package
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
# Install any Bazel rules which were extracted earlier by the yarn_install rule.
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()

View File

@ -1,8 +0,0 @@
{
"$schema": "http://json-schema.org/schema",
"id": "SchematicsNxApp",
"title": "Nx Application Options Schema",
"type": "object",
"properties": {},
"required": []
}

View File

@ -1,283 +0,0 @@
import { chain, Tree } from '@angular-devkit/schematics';
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
import { callRule, runSchematic } from '../utils/testing';
import { stripIndents } from '@angular-devkit/core/src/utils/literals';
import { updateJsonInTree } from '@nrwl/workspace/src/utils/ast-utils';
import { updateWorkspace } from '@nrwl/workspace/src/utils/workspace';
import { rulesNodeJSSha, rulesNodeJSVersion } from '../utils/versions';
import { NxJson } from '@nrwl/workspace/src/core/shared-interfaces';
describe('@nrwl/bazel:sync', () => {
let tree: Tree;
beforeEach(() => {
tree = Tree.empty();
tree = createEmptyWorkspace(tree);
tree.create('tools/schematics/custom/index.ts', '');
});
describe('WORKSPACE', () => {
it('should be created', async () => {
const result = await runSchematic('sync', {}, tree);
expect(result.exists('WORKSPACE')).toEqual(true);
});
it('should name the workspace validly', async () => {
const result = await runSchematic('sync', {}, tree);
const contents = stripIndents`${result.readContent('WORKSPACE')}`;
expect(contents).toContain('name = "test_name"');
});
it('should import nodejs bazel rules', async () => {
const result = await runSchematic('sync', {}, tree);
const contents = stripIndents`${result.readContent('WORKSPACE')}`;
expect(contents).toContain(stripIndents`
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "${rulesNodeJSSha}",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/${rulesNodeJSVersion}/rules_nodejs-${rulesNodeJSVersion}.tar.gz"],
)
`);
});
it('should import yarn bazel rules and install', async () => {
const result = await runSchematic('sync', {}, tree);
const contents = stripIndents`${result.readContent('WORKSPACE')}`;
expect(contents).toContain(stripIndents`
load("@build_bazel_rules_nodejs//:index.bzl", "yarn_install")
yarn_install(
# Name this npm so that Bazel Label references look like @npm//package
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)
# Install any Bazel rules which were extracted earlier by the yarn_install rule.
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()
`);
});
});
describe('root BUILD.bazel', () => {
it('should be created', async () => {
const result = await runSchematic('sync', {}, tree);
expect(result.exists('BUILD.bazel')).toEqual(true);
});
it('should export root files', async () => {
const result = await runSchematic('sync', {}, tree);
const contents = stripIndents`${result.readContent('BUILD.bazel')}`;
expect(contents).toContain(stripIndents`filegroup(
name = "root-files",
srcs = [
# Root Files
"workspace.json",
"package.json",
"nx.json",
"tsconfig.base.json",
"tslint.json",
],
visibility = ["//:__subpackages__"],
)
`);
});
});
describe('Project BUILD files', () => {
beforeEach(async () => {
tree = await callRule(
chain([
updateWorkspace((workspace) => {
workspace.projects.add({
name: 'proj',
root: 'proj',
targets: {
build: {
builder: '@nrwl/web:build',
options: {},
configurations: {
production: {},
},
},
serve: {
builder: '@nrwl/web:dev-server',
options: {},
configurations: {
production: {},
},
},
test: {
builder: '@nrwl/jest:jest',
options: {},
},
},
});
workspace.projects.add({
name: 'proj2',
root: 'proj2',
targets: {
build: {
builder: '@angular-devkit/build-angular:browser',
options: {},
configurations: {
production: {},
},
},
serve: {
builder: '@angular-devkit/build-angular:dev-server',
options: {},
configurations: {
production: {},
},
},
test: {
builder: '@angular-devkit/build-angular:karma',
options: {},
},
},
});
}),
updateJsonInTree<NxJson>('nx.json', (json) => {
json.projects['proj'] = {};
json.projects['proj2'] = {};
return json;
}),
]),
tree
);
});
it('should be generated', async () => {
const result = await runSchematic('sync', {}, tree);
expect(result.exists('proj/BUILD.bazel')).toEqual(true);
expect(result.exists('proj2/BUILD.bazel')).toEqual(true);
});
it('should generate build bazel targets', async () => {
const result = await runSchematic('sync', {}, tree);
const proj1BuildContents = stripIndents`${result.readContent(
'proj/BUILD.bazel'
)}`;
expect(proj1BuildContents).toContain(stripIndents`
nx(
name = "build",
args = [
"run",
"proj:build",
"--outputPath=$(@D)",
],
data = [
":proj",
# Root Files
"//:root-files",
# Node Modules
"@npm//:node_modules"
],
output_dir = True,
)
`);
expect(proj1BuildContents).toContain(stripIndents`
nx(
name = "build__production",
args = [
"run",
"proj:build:production",
"--outputPath=$(@D)",
],
data = [
":proj",
# Root Files
"//:root-files",
# Node Modules
"@npm//:node_modules"
],
output_dir = True,
)
`);
});
it('should generate non-build, non-test bazel targets', async () => {
const result = await runSchematic('sync', {}, tree);
const proj1BuildContents = stripIndents`${result.readContent(
'proj/BUILD.bazel'
)}`;
expect(proj1BuildContents).toContain(stripIndents`
nx(
name = "serve",
args = [
"run",
"proj:serve",
],
data = [
":proj",
# Root Files
"//:root-files",
# Node Modules
"@npm//:node_modules"
],
)
`);
expect(proj1BuildContents).toContain(stripIndents`
nx(
name = "serve__production",
args = [
"run",
"proj:serve:production",
],
data = [
":proj",
# Root Files
"//:root-files",
# Node Modules
"@npm//:node_modules"
],
)
`);
});
it('should generate test bazel targets', async () => {
const result = await runSchematic('sync', {}, tree);
const proj1BuildContents = stripIndents`${result.readContent(
'proj/BUILD.bazel'
)}`;
expect(proj1BuildContents).toContain(stripIndents`
nx_test(
name = "test",
args = [
"run",
"proj:test",
],
data = [
":proj",
# Root Files
"//:root-files",
# Node Modules
"@npm//:node_modules"
],
)
`);
});
});
});

View File

@ -1,199 +0,0 @@
import {
apply,
chain,
MergeStrategy,
mergeWith,
move,
Rule,
schematic,
Source,
template,
Tree,
url,
} from '@angular-devkit/schematics';
import {
getProjectGraphFromHost,
getWorkspace,
readJsonInTree,
readWorkspace,
} from '@nrwl/workspace';
import { join, normalize } from '@angular-devkit/core';
import {
ProjectGraph,
ProjectGraphNode,
} from '@nrwl/workspace/src/core/project-graph';
import { rulesNodeJSSha, rulesNodeJSVersion } from '../utils/versions';
import { TargetDefinition } from '@angular-devkit/core/src/workspace';
const buildBuilders = {
'@angular-devkit/build-angular:browser': 'outputPath',
'@angular-devkit/build-angular:server': 'outputPath',
'@angular-devkit/build-angular:ng-packagr': 'outputPath',
'@angular-devkit/build-webpack:webpack': 'outputPath',
'@nrwl/web:build': 'outputPath',
};
const testBuilders = new Set([
'@angular-devkit/build-angular:karma',
'@angular-devkit/build-angular:protractor',
'@angular-devkit/build-angular:tslint',
'@nrwl/jest:jest',
'@nrwl/cypress:cypress',
'@nrwl/linter:eslint',
]);
function createBuildFile(
project: ProjectGraphNode,
projectGraph: ProjectGraph,
labelsMetadata: Array<{
name: string;
configurations: string[];
target: TargetDefinition;
}>
): Source {
const labels: {
cliTarget: string;
bazelLabel: string;
isBuildTarget: boolean;
outputArgument: string;
}[] = [];
labelsMetadata
.map((metadata) =>
metadata.configurations.map((config) => {
const isTestTarget = testBuilders.has(metadata.target.builder);
const isBuildTarget = !!buildBuilders[metadata.target.builder];
const outputArgument = buildBuilders[metadata.target.builder];
return {
bazelRuleName: isTestTarget ? 'nx_test' : 'nx',
cliTarget: `${project.name}:${metadata.name}${
config === '__nx_default__' ? '' : `:${config}`
}`,
bazelLabel: `${metadata.name}${
config === '__nx_default__' ? '' : `__${config}`
}`,
isBuildTarget,
outputArgument,
};
})
)
.forEach((arr) => {
arr.forEach((label) => labels.push(label));
});
return apply(url('./files/build-file'), [
template({
tmpl: '',
project,
projectGraph,
dependencies: projectGraph.dependencies[project.name]
? projectGraph.dependencies[project.name].map(
(dep) =>
`//${normalize(projectGraph.nodes[dep.target].data.root)}:${
dep.target
}`
)
: [],
labels,
}),
]);
}
function updateBuildFile(
project: ProjectGraphNode,
projectGraph: ProjectGraph
): Rule {
return async (host, context) => {
const workspace = await getWorkspace(host);
const labelsMetadata = Array.from(
workspace.projects.get(project.name).targets.entries()
).map(([name, target]) => ({
name,
target,
configurations: [
'__nx_default__',
...Object.keys(target.configurations || {}),
],
}));
const buildFile = createBuildFile(project, projectGraph, labelsMetadata);
const buildFilePath = join(normalize(project.data.root), 'BUILD.bazel');
return mergeWith(
apply(buildFile, [
(sourceHost) => {
if (host.exists(buildFilePath)) {
const contents = sourceHost.read('BUILD.bazel').toString();
const customPart = host
.read(buildFilePath)
.toString()
.split('# ==== Generated by Nx')[0];
host.delete(buildFilePath);
sourceHost.overwrite('BUILD.bazel', customPart + contents);
}
},
move(project.data.root),
]),
MergeStrategy.Overwrite
);
};
}
function createWorkspaceFile() {
return (host) => {
return mergeWith(
apply(url('./files/workspace-file'), [
template({
tmpl: '',
name: readJsonInTree(host, '/package.json').name.replace('-', '_'),
rulesNodeJSVersion,
rulesNodeJSSha,
}),
() => {
if (host.exists('WORKSPACE')) {
host.delete('WORKSPACE');
}
},
]),
MergeStrategy.Overwrite
);
};
}
const ignoredFromRootBuildFile = ['WORKSPACE', '.bazelrc', 'BUILD.bazel'];
function createRootBuildFile() {
return (host) => {
return mergeWith(
apply(url('./files/root-build-file'), [
template({
tmpl: '',
rootFiles: host
.getDir('/')
.subfiles.filter((f) => !ignoredFromRootBuildFile.includes(f)),
}),
() => {
if (host.exists('BUILD.bazel')) {
host.delete('BUILD.bazel');
}
},
]),
MergeStrategy.Overwrite
);
};
}
const runInit = schematic<{}>('init', {});
export default (): Rule => {
return (host: Tree) => {
const projectGraph = getProjectGraphFromHost(host);
return chain([
runInit,
createWorkspaceFile(),
createRootBuildFile(),
...Object.values(projectGraph.nodes).map((project) =>
updateBuildFile(project, projectGraph)
),
]);
};
};

View File

@ -1,20 +0,0 @@
import { join } from 'path';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import { Tree, Rule } from '@angular-devkit/schematics';
const testRunner = new SchematicTestRunner(
'@nrwl/bazel',
join(__dirname, '../../../collection.json')
);
export function runSchematic<SchemaOptions = any>(
schematicName: string,
options: SchemaOptions,
tree: Tree
) {
return testRunner.runSchematicAsync(schematicName, options, tree).toPromise();
}
export function callRule(rule: Rule, tree: Tree) {
return testRunner.callRule(rule, tree).toPromise();
}

View File

@ -1,5 +0,0 @@
export const bazelVersion = '^1.2.0';
export const iBazelVersion = '0.10.3';
export const rulesNodeJSVersion = '0.42.3';
export const rulesNodeJSSha =
'a54b2511d6dae42c1f7cdaeb08144ee2808193a088004fc3b464a04583d5aa2e';

View File

@ -1,16 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node", "jest"]
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

View File

@ -1,11 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["**/*.spec.ts", "**/*_spec.ts"],
"include": ["**/*.ts"]
}

View File

@ -1,16 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.spec.ts",
"**/*_spec.ts",
"**/*.spec.tsx",
"**/*.spec.js",
"**/*.spec.jsx",
"**/*.d.ts"
]
}

View File

@ -33,7 +33,6 @@
"packageGroup": [ "packageGroup": [
"@nrwl/workspace", "@nrwl/workspace",
"@nrwl/angular", "@nrwl/angular",
"@nrwl/bazel",
"@nrwl/cli", "@nrwl/cli",
"@nrwl/cypress", "@nrwl/cypress",
"@nrwl/eslint-plugin-nx", "@nrwl/eslint-plugin-nx",

View File

@ -8,10 +8,6 @@ export function fetchCorePlugins() {
name: '@nrwl/angular', name: '@nrwl/angular',
capabilities: 'schematics', capabilities: 'schematics',
}, },
{
name: '@nrwl/bazel',
capabilities: 'schematics',
},
{ {
name: '@nrwl/cypress', name: '@nrwl/cypress',
capabilities: 'builders,schematics', capabilities: 'builders,schematics',

View File

@ -9,7 +9,7 @@ elif [ "$1" == "2" ]; then
elif [ "$1" == "3" ]; then elif [ "$1" == "3" ]; then
export SELECTED_CLI=angular export SELECTED_CLI=angular
ts-node --project scripts/tsconfig.e2e.json ./scripts/e2e.ts e2e-angular,e2e-bazel affected ts-node --project scripts/tsconfig.e2e.json ./scripts/e2e.ts e2e-angular affected
elif [ "$1" == "4" ]; then elif [ "$1" == "4" ]; then
export SELECTED_CLI=nx export SELECTED_CLI=nx

View File

@ -18,7 +18,7 @@ cd build/packages
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js sed -i "" "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js
sed -i "" "s|\*|$NX_VERSION|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json sed -i "" "s|\*|$NX_VERSION|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "" "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "" "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
@ -29,7 +29,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js sed -i "" "s|PRETTIER_VERSION|$PRETTIER_VERSION|g" create-nx-plugin/bin/create-nx-plugin.js
else else
sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js sed -i "s|exports.nxVersion = '\*';|exports.nxVersion = '$NX_VERSION';|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace}/src/utils/versions.js
sed -i "s|\*|$NX_VERSION|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,bazel,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json sed -i "s|\*|$NX_VERSION|g" {react,next,web,jest,node,express,nest,cypress,storybook,angular,workspace,cli,linter,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|NX_VERSION|$NX_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|ANGULAR_CLI_VERSION|$ANGULAR_CLI_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
sed -i "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js sed -i "s|TYPESCRIPT_VERSION|$TYPESCRIPT_VERSION|g" create-nx-workspace/bin/create-nx-workspace.js
@ -42,9 +42,9 @@ fi
if [[ $NX_VERSION == "*" ]]; then if [[ $NX_VERSION == "*" ]]; then
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json sed -E -i "" "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
else else
echo $PWD echo $PWD
sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,bazel,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json sed -E -i "s|\"@nrwl\/([^\"]+)\": \"\\*\"|\"@nrwl\/\1\": \"file:$PWD\/\1\"|" {jest,web,react,next,node,express,nest,cypress,storybook,angular,workspace,linter,cli,tao,eslint-plugin-nx,create-nx-workspace,create-nx-plugin,nx-plugin}/package.json
fi fi
fi fi

View File

@ -1434,35 +1434,6 @@
} }
} }
}, },
"bazel": {
"root": "packages/bazel",
"sourceRoot": "packages/bazel",
"projectType": "library",
"schematics": {},
"architect": {
"test": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "packages/bazel/jest.config.js",
"passWithNoTests": true
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"packages/bazel/**/*.ts",
"packages/bazel/**/*.spec.ts",
"packages/bazel/**/*_spec.ts",
"packages/bazel/**/*.spec.tsx",
"packages/bazel/**/*.spec.js",
"packages/bazel/**/*.spec.jsx",
"packages/bazel/**/*.d.ts"
]
}
}
}
},
"angular": { "angular": {
"root": "packages/angular", "root": "packages/angular",
"sourceRoot": "packages/angular", "sourceRoot": "packages/angular",
@ -1587,22 +1558,6 @@
} }
} }
}, },
"e2e-bazel": {
"root": "e2e/bazel",
"sourceRoot": "e2e/bazel",
"projectType": "application",
"schematics": {},
"architect": {
"e2e": {
"builder": "@nrwl/jest:jest",
"options": {
"jestConfig": "e2e/bazel/jest.config.js",
"passWithNoTests": true,
"runInBand": true
}
}
}
},
"e2e-cypress": { "e2e-cypress": {
"root": "e2e/cypress", "root": "e2e/cypress",
"sourceRoot": "e2e/cypress", "sourceRoot": "e2e/cypress",