-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support bazel+js packages that install into regular @npm//packa…
…ge:index.bzl location
- Loading branch information
Showing
10 changed files
with
155 additions
and
18 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
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
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,10 @@ | ||
load("@npm//bazel_workspaces_consistent:index.bzl", "some_rule") | ||
load("@npm_bazel_jasmine//:index.bzl", "jasmine_node_test") | ||
|
||
some_rule(name = "test_data") | ||
|
||
jasmine_node_test( | ||
name = "test", | ||
srcs = ["spec.js"], | ||
data = ["test_data"], | ||
) |
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,5 @@ | ||
These test the installation of npm packages which contain bazel rules. | ||
We call these "hybrid" packages because they're distributed, versioned, and installed by npm | ||
but they contain bazel rules we can call from BUILD files. | ||
|
||
The packages themselves are in /tools/npm_packages/bazel_workspaces* |
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,11 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
describe('installing hybrid packages', () => { | ||
it('should work', () => { | ||
const content = fs.readFileSync( | ||
path.join(process.env['TEST_SRCDIR'], 'npm', 'bazel_workspaces_consistent', 'a.txt'), | ||
'utf-8'); | ||
expect(content).toEqual('some content'); | ||
}); | ||
}); |
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
17 changes: 17 additions & 0 deletions
17
tools/npm_packages/bazel_workspaces_consistent/BUILD.bazel
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,17 @@ | ||
load("@build_bazel_rules_nodejs//third_party/github.com/bazelbuild/bazel-skylib:rules/write_file.bzl", "write_file") | ||
load(":index.bzl", "some_rule") | ||
|
||
# Just a dumb target to make sure we can use it from code that installs this npm package | ||
write_file( | ||
name = "some_file", | ||
out = "a.txt", | ||
content = ["some content"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
some_rule( | ||
name = "test", | ||
# Normally we would set the default to work in our source repo, | ||
# and transform on publish. | ||
text = "//tools/npm_packages/bazel_workspaces_consistent:a.txt", | ||
) |
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 @@ | ||
"Simplest possible rule for testing it can be loaded and called" | ||
|
||
_ATTRS = { | ||
# Note, we can reference our file without needing "@npm" which means it works | ||
# regardless what name the user chooses for their workspace | ||
"text": attr.label(default = Label("//bazel_workspaces_consistent:a.txt"), allow_single_file = True), | ||
} | ||
|
||
def _impl(ctx): | ||
# No actions, just echo the input file as the default output | ||
return [DefaultInfo(files = depset(ctx.files.text))] | ||
|
||
some_rule = rule(_impl, attrs = _ATTRS) |
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,6 @@ | ||
{ | ||
"name": "bazel_workspaces_consistent", | ||
"version": "0.0.1", | ||
"description": "https://hackmd.io/JkUESy8JTkyvGIlc-vNjeQ" | ||
} | ||
|
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