-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): re-introduce @nrwl/bazel
- Loading branch information
1 parent
fb4fccb
commit 2e2167d
Showing
21 changed files
with
537 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[ | ||
"angular", | ||
"bazel", | ||
"cypress", | ||
"express", | ||
"insights", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[ | ||
"angular", | ||
"bazel", | ||
"cypress", | ||
"express", | ||
"insights", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[ | ||
"angular", | ||
"bazel", | ||
"cypress", | ||
"express", | ||
"insights", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
checkFilesExist, | ||
ensureProject, | ||
forEachCli, | ||
readFile, | ||
runCLI, | ||
uniq, | ||
updateFile | ||
} from './utils'; | ||
|
||
forEachCli(currentCLIName => { | ||
describe('Bazel', () => { | ||
const ngapp = uniq('ngapp'); | ||
const reactapp = uniq('reactapp'); | ||
const nglib = uniq('nglib'); | ||
const reactlib = uniq('reactlib'); | ||
|
||
it('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`); | ||
}); | ||
|
||
it('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`); | ||
}); | ||
|
||
it('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}` | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "Nx Bazel", | ||
"version": "0.1", | ||
"extends": [], | ||
"schematics": { | ||
"sync": { | ||
"factory": "./src/schematics/sync/sync", | ||
"schema": "./src/schematics/sync/schema.json", | ||
"description": "Sync Build Files", | ||
"hidden": true | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"schematics": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"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": "8.3.14", | ||
"@angular-devkit/schematics": "8.3.14", | ||
"@nrwl/cli": "*" | ||
}, | ||
"peerDependencies": { | ||
"@nrwl/workspace": "*" | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/bazel/src/schematics/sync/files/build-file/BUILD.bazel__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# ==== Generated by Nx | ||
# ==== Do not touch | ||
|
||
load("@npm//@nrwl/cli:index.bzl", "nx", "nx_test") | ||
|
||
filegroup( | ||
name = "<%= project.name %>", | ||
srcs = glob(["**"]), | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
nx( | ||
name = "build", | ||
args = [ | ||
"build", | ||
"<%= project.name%>", | ||
"--outputPath=$@", | ||
], | ||
data = [ | ||
":<%= project.name %>", | ||
# Dependencies | ||
<% for (dep of dependencies) { %>"//<%= dep %>", | ||
<% } %> | ||
# Root Files | ||
"//:angular.json", | ||
"//:package.json", | ||
"//:tsconfig.json", | ||
# NOTE: Use @npm//node_modules causes bundling to fail due to Babel errors. | ||
"@npm//@angular-devkit/build-angular", | ||
"@npm//@angular/cli", | ||
"@npm//@angular/core", | ||
"@npm//@angular/platform-browser-dynamic", | ||
"@npm//@angular/router", | ||
"@npm//@babel/preset-env", | ||
"@npm//@nrwl/workspace", | ||
"@npm//inquirer", | ||
], | ||
output_dir = True, | ||
) |
7 changes: 7 additions & 0 deletions
7
packages/bazel/src/schematics/sync/files/root-build-file/BUILD.bazel__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
exports_files( | ||
[ | ||
<% for (rootFile of rootFiles) { %>"<%= rootFile %>", | ||
<% } %> | ||
], | ||
visibility = ["//:__subpackages__"], | ||
) |
37 changes: 37 additions & 0 deletions
37
packages/bazel/src/schematics/sync/files/workspace-file/WORKSPACE__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 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 = "c612d6b76eaa17540e8b8c806e02701ed38891460f9ba3303f4424615437887a", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.1/rules_nodejs-0.42.1.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", | ||
data = ["//patches"], | ||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"id": "SchematicsNxApp", | ||
"title": "Nx Application Options Schema", | ||
"type": "object", | ||
"properties": {}, | ||
"required": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
import { createEmptyWorkspace } from '@nrwl/workspace/testing'; | ||
import { runSchematic } from '../utils/testing'; | ||
import { stripIndents } from '@angular-devkit/core/src/utils/literals'; | ||
|
||
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 = "c612d6b76eaa17540e8b8c806e02701ed38891460f9ba3303f4424615437887a", | ||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.1/rules_nodejs-0.42.1.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", | ||
data = ["//patches"], | ||
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`exports_files( | ||
[ | ||
"workspace.json", | ||
"package.json", | ||
"nx.json", | ||
"tsconfig.json", | ||
"tslint.json", | ||
], | ||
visibility = ["//:__subpackages__"], | ||
) | ||
`); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.