Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Update to latest rules_nodejs & cleanup #204

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
platforms:
ubuntu1404:
run_targets:
- "@yarn//:yarn"
- "@nodejs//:yarn"
build_targets:
- "..."
test_flags:
Expand All @@ -12,7 +12,7 @@ platforms:
- "..."
ubuntu1604:
run_targets:
- "@yarn//:yarn"
- "@nodejs//:yarn"
build_targets:
- "..."
test_flags:
Expand All @@ -22,7 +22,7 @@ platforms:
- "..."
macos:
run_targets:
- "@yarn//:yarn"
- "@nodejs//:yarn"
build_targets:
- "..."
test_flags:
Expand All @@ -32,7 +32,7 @@ platforms:
- "..."
windows:
run_targets:
- "@yarn//:yarn"
- "@nodejs//:yarn"
# TODO(alexeagle): expand to all targets when rules_go is fixed
build_targets:
- "//examples:all"
Expand Down
4 changes: 2 additions & 2 deletions .ci/rules_typescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{"node": "ubuntu_16.04-x86_64"}
],
"parameters": {
"configure": ["$BAZEL run @yarn//:yarn"],
"configure": ["$BAZEL run @nodejs//:yarn"],
"test_tag_filters": ["-browser:chromium-local"]
}
},
Expand All @@ -14,7 +14,7 @@
{"node": "darwin-x86_64"}
],
"parameters": {
"configure": ["$BAZEL run @yarn//:yarn"],
"configure": ["$BAZEL run @nodejs//:yarn"],
"test_tag_filters": ["-browser:chromium-local"]
}
}
Expand Down
26 changes: 19 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@

## IMPORTANT
# If you change the `docker_image` version, also change the `cache_key` suffix
var_1: &docker_image angular/ngcontainer:0.1.0
var_2: &cache_key rules_typescript-{{ checksum "yarn.lock" }}-0.1.0
var_1: &docker_image angular/ngcontainer:0.3.0
var_2: &cache_key rules_typescript-{{ checksum "yarn.lock" }}-0.3.0
var_3: &setup-bazel-remote-cache
run:
name: Start up bazel remote cache proxy
command: ~/bazel-remote-proxy -backend circleci://
background: true
# Move node binaries out of the way to enforce that Bazel uses
# only the hermetic ones it downloads
var_4: &hide_node_and_yarn_local_binaries
Copy link
Contributor

Choose a reason for hiding this comment

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

there's a nicer pipe syntax; switch this to

var_4: &hide_node_and_yarn_local_binaries
  run:
    name: Move node, npm, and yarn binaries
    command: |
      sudo mv /usr/local/bin/node /usr/local/bin/node_
      sudo mv /usr/local/bin/npm /usr/local/bin/npm_
      sudo mv /usr/local/bin/yarn /usr/local/bin/yarn_

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

run:
name: Move node, npm, and yarn binaries
command: |
sudo mv /usr/local/bin/node /usr/local/bin/node_
sudo mv /usr/local/bin/npm /usr/local/bin/npm_
sudo mv /usr/local/bin/yarn /usr/local/bin/yarn_

# Settings common to each job
anchor_1: &job_defaults
Expand All @@ -40,11 +49,12 @@ jobs:
- run: .circleci/setup_cache.sh
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
- *setup-bazel-remote-cache
- *hide_node_and_yarn_local_binaries

- restore_cache:
key: *cache_key
- run: bazel info release
- run: bazel run @yarn//:yarn
- run: bazel run @nodejs//:yarn
- run: bazel build ...
- run: bazel test ...

Expand All @@ -58,11 +68,12 @@ jobs:
- run: .circleci/setup_cache.sh
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
- *setup-bazel-remote-cache
- *hide_node_and_yarn_local_binaries

- restore_cache:
key: *cache_key
- run: bazel --bazelrc=/dev/null info release
- run: bazel --bazelrc=/dev/null run @yarn//:yarn
- run: bazel --bazelrc=/dev/null run @nodejs//:yarn
- run: bazel --bazelrc=/dev/null build ...
- run: bazel --bazelrc=/dev/null test ...

Expand All @@ -80,12 +91,13 @@ jobs:
- run: .circleci/setup_cache.sh
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
- *setup-bazel-remote-cache
- *hide_node_and_yarn_local_binaries
- restore_cache:
key: *cache_key
- run: bazel run @yarn//:yarn
- run: bazel run @nodejs//:yarn
# Don't occupy the bazel server, as this test wants to run Bazel itself
- run: bazel run @yarn//:yarn test --script_path=yarn_test.sh
- run: xvfb-run -a ./yarn_test.sh
- run: bazel run @nodejs//:yarn e2e --script_path=yarn_e2e.sh
- run: xvfb-run -a ./yarn_e2e.sh

lint:
<<: *job_defaults
Expand Down
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ filegroup(
"node_modules/**/*.js",
"node_modules/**/*.d.ts",
"node_modules/**/*.json"
] + [
"node_modules/http-server/**",
]),
visibility = ["//visibility:public"],
)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ to verify the integrity of your `node_modules` directory.
You can run the version Bazel has already installed:

```sh
$ bazel run @yarn//:yarn
$ bazel run @nodejs//:yarn
```

## Usage
Expand Down
15 changes: 8 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ workspace(name = "build_bazel_rules_typescript")

http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.8.0.zip",
strip_prefix = "rules_nodejs-0.8.0",
sha256 = "4e40dd49ae7668d245c3107645f2a138660fcfd975b9310b91eda13f0c973953",
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.9.1.zip",
strip_prefix = "rules_nodejs-0.9.1",
sha256 = "6139762b62b37c1fd171d7f22aa39566cb7dc2916f0f801d505a9aaf118c117f",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
Expand All @@ -32,11 +32,12 @@ yarn_install(

# Install a hermetic version of node.
# After this is run, these labels will be available:
# - The nodejs install:
# @build_bazel_rules_typescript_node//:bin/node
# @build_bazel_rules_typescript_node//:bin/npm
# - NodeJS:
# @nodejs//:node
# - NPM:
# @nodejs//:npm
# - The yarn package manager:
# @yarn//:yarn
# @nodejs//:yarn
node_repositories(
package_json = ["//:package.json"],
preserve_symlinks = True)
Expand Down
22 changes: 21 additions & 1 deletion examples/app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,29 @@ ts_devserver(
# We'll collect all the devmode JS sources from these TypeScript libraries
deps = [":app"],
# This is the path we'll request from the browser, see index.html
serving_path = "/bundle.js",
serving_path = "/bundle.min.js",
# The devserver can serve our static files too
static_files = ["index.html"],
port = 8080,
)

# Test for production mode
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "nodejs_binary")

rollup_bundle(
name = "bundle",
deps = [":app"],
entry_point = "examples/app/app",
)

nodejs_binary(
name = "prodserver",
args = ["./examples/app"],
data = [
"index.html",
":bundle",
],
entry_point = "http-server/bin/http-server",
)

ts_library(
Expand Down
4 changes: 2 additions & 2 deletions examples/app/app_e2e_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ browser.waitForAngularEnabled(false);
// compiling the application as well as starting the server.
const timeoutMs = 90 * 1000;

describe('Devserver', () => {
describe('app', () => {
beforeAll(() => {
browser.get('');
// Don't run any specs until we see a <div> on the page.
Expand All @@ -17,7 +17,7 @@ describe('Devserver', () => {
timeoutMs);
}, timeoutMs);

it('should display: Hello world!', (done) => {
it('should display: Hello, TypeScript', (done) => {
const div = element(by.css('div.ts1'));
div.getText().then(t => expect(t).toEqual(`Hello, TypeScript`));
done();
Expand Down
2 changes: 1 addition & 1 deletion examples/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
For production, you should be able to use the same index.html file, but
this JS resource would be served from a static file.
-->
<script src="/bundle.js"></script>
<script src="/bundle.min.js"></script>
</body>
</html>
39 changes: 38 additions & 1 deletion examples/protocol_buffers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,50 @@ ts_devserver(
deps = [":app"],
entry_module = "build_bazel_rules_typescript/examples/protocol_buffers/app",
bootstrap = ["@build_bazel_rules_typescript//:protobufjs_bootstrap_scripts"],
port = 8080,
)

# Test for production mode
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle")
load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "nodejs_binary")

rollup_bundle(
name = "bundle",
deps = [":app"],
entry_point = "examples/protocol_buffers/app",
globals = {
Copy link
Contributor

Choose a reason for hiding this comment

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

this map is already defined in the js_library - any idea how we could re-use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed. we should be able to make this easier for users. but I think it needs some thought first about the best way to go about it. this works for now IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay let's not wait too long :)

"long": "Long",
"protobufjs/minimal": "protobuf",
},
)

# Needed because the prodserver only loads static files that appear under this
# package.
genrule(
name = "protobufjs",
srcs = [
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/protobufjs/dist/minimal/protobuf.min.js",
"@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/long/dist/long.js",
],
outs = [
"protobuf.min.js",
"long.js"
],
cmd = "outs=($(OUTS)); d=$$(dirname $${outs[0]}); for s in $(SRCS); do cp $$s $$d; done",
)

nodejs_binary(
name = "prodserver",
args = ["./examples/protocol_buffers"],
data = [
"index.html",
":protobufjs",
":bundle",
],
entry_point = "http-server/bin/http-server",
)

ts_library(
name = "e2e",
testonly = 1,
srcs = ["app_e2e_test.ts"],
)
1 change: 1 addition & 0 deletions examples/protocol_buffers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const serverResponse = `{"make": "Porsche"}`;
const car = Car.create(JSON.parse(serverResponse));
const el: HTMLDivElement = document.createElement('div');
el.innerText = `Car from server: ${car.make}`;
el.className = 'ts1';
document.body.appendChild(el);
25 changes: 25 additions & 0 deletions examples/protocol_buffers/app_e2e_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {browser, by, element, ExpectedConditions} from 'protractor';

// This test uses Protractor without Angular, so disable Angular features
browser.waitForAngularEnabled(false);

// Since we don't have a protractor bazel rule yet, the test is brought up in
// parallel with building the service under test. So the timeout must include
// compiling the application as well as starting the server.
const timeoutMs = 90 * 1000;

describe('protocol_buffers', () => {
beforeAll(() => {
browser.get('');
// Don't run any specs until we see a <div> on the page.
browser.wait(
ExpectedConditions.presenceOf(element(by.css('div.ts1'))),
timeoutMs);
}, timeoutMs);

it('should display: Car from server: Porsche', (done) => {
const div = element(by.css('div.ts1'));
div.getText().then(t => expect(t).toEqual(`Car from server: Porsche`));
done();
});
});
10 changes: 10 additions & 0 deletions examples/protocol_buffers/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<title>protocol_buffers example</title>
</head>
<body>
<script src="/protobuf.min.js"></script>
<script src="/long.js"></script>
<script src="/bundle.min.js"></script>
</body>
</html>
9 changes: 7 additions & 2 deletions internal/devserver/ts_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ def _ts_devserver(ctx):
content = """#!/bin/sh
RUNFILES="$PWD/.."
{main} {serving_arg} \
-base "$RUNFILES" \
-base="$RUNFILES" \
-packages={packages} \
-manifest={workspace}/{manifest} \
-scripts_manifest={workspace}/{scripts_manifest} \
-entry_module={entry_module} \
-port={port} \
"$@"
""".format(
main = ctx.executable._devserver.short_path,
Expand All @@ -97,7 +98,8 @@ RUNFILES="$PWD/.."
packages = ",".join(packages.to_list()),
manifest = ctx.outputs.manifest.short_path,
scripts_manifest = ctx.outputs.scripts_manifest.short_path,
entry_module = ctx.attr.entry_module))
entry_module = ctx.attr.entry_module,
port = str(ctx.attr.port)))
return [DefaultInfo(
runfiles = ctx.runfiles(
files = devserver_runfiles,
Expand Down Expand Up @@ -140,6 +142,9 @@ ts_devserver = rule(
doc = """Additional root paths to serve static_files from.
Paths should include the workspace name such as [\"__main__/resources\"]
"""),
"port": attr.int(
doc = """The port that the devserver will listen on.""",
default = 5432),
"_requirejs_script": attr.label(allow_files = True, single_file = True, default = Label("@build_bazel_rules_typescript_devserver_deps//:node_modules/requirejs/require.js")),
"_devserver": attr.label(
default = Label("//internal/devserver/main"),
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@
"@types/tmp": "^0.0.33",
"clang-format": "1.0.49",
"concurrently": "^3.5.1",
"http-server": "^0.11.1",
"protobufjs": "5.0.0",
"protractor": "^5.2.0",
"tsickle": "0.25.x",
"tsutils": "2.20.0",
"typescript": "2.7.x"
},
"scripts": {
"pretest": "webdriver-manager update && bazel build examples/app:all",
"test": "concurrently \"bazel run examples/app:devserver\" protractor --kill-others --success first",
"pree2e": "webdriver-manager update $CHROMEDRIVER_VERSION_ARG && bazel build examples/app:e2e && bazel build examples/protocol_buffers:e2e",
"e2e": "yarn e2e-examples-app-devserver && yarn e2e-examples-app-prodserver && yarn e2e-examples-protobuf-devserver && yarn e2e-examples-protobuf-prodserver",
"e2e-examples-app-devserver": "concurrently \"bazel run examples/app:devserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite app\" --kill-others --success first",
"e2e-examples-app-prodserver": "concurrently \"bazel run examples/app:prodserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite app\" --kill-others --success first",
"e2e-examples-protobuf-devserver": "concurrently \"bazel run examples/protocol_buffers:devserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite protocol_buffers\" --kill-others --success first",
"e2e-examples-protobuf-prodserver": "concurrently \"bazel run examples/protocol_buffers:prodserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite protocol_buffers\" --kill-others --success first",
"preskylint": "bazel build --noshow_progress @io_bazel//src/tools/skylark/java/com/google/devtools/skylark/skylint:Skylint",
"skylint": "find . -type f -name \"*.bzl\" ! -path \"*/node_modules/*\" | xargs $(bazel info bazel-bin)/external/io_bazel/src/tools/skylark/java/com/google/devtools/skylark/skylint/Skylint",
"skydoc": "bazel build //:docs && unzip -o -d docs/api bazel-bin/docs-skydoc.zip"
Expand Down
13 changes: 9 additions & 4 deletions protractor.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
exports.config = {
specs: ['bazel-bin/examples/app/*_e2e_test.js'],
capabilities:
{browserName: 'chrome', chromeOptions: {args: ['--no-sandbox']}},
suites: {
app: 'bazel-bin/examples/app/*_e2e_test.js',
protocol_buffers: 'bazel-bin/examples/protocol_buffers/*_e2e_test.js',
},
capabilities: {
browserName: 'chrome',
chromeOptions: {args: ['--no-sandbox']}
},
directConnect: true,
baseUrl: 'http://localhost:5432/',
baseUrl: 'http://localhost:8080/',
framework: 'jasmine',
};
Loading