Skip to content

Commit

Permalink
See user/README.md for info.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgp1130 committed Sep 5, 2021
1 parent bfa5f3a commit 6d8df06
Show file tree
Hide file tree
Showing 47 changed files with 1,581 additions and 1 deletion.
19 changes: 19 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("//tools:publish.bzl", "publish_files")
load("//:index.bzl", "prerender_component")
load(
"//packages/rules_prerender:prerender_component_publish_files.bzl",
"prerender_component_publish_files",
)

exports_files(["tsconfig.json"], visibility = ["//visibility:public"])

Expand Down Expand Up @@ -33,9 +39,21 @@ publish_files(
"index.bzl",
"package.bzl",
"package.json",
":publishable_publish_files",
],
)

prerender_component_publish_files(
name = "publishable_publish_files",
dep = ":publishable",
)

prerender_component(
name = "publishable",
srcs = ["publishable.ts"],
deps = ["//packages/rules_prerender/publishable"],
)

SUBSTITUTIONS = {
# Remap packages with a `BUILD.publish` file to use
# `@npm//rules_prerender/...` so they can be resolved at runtime.
Expand Down Expand Up @@ -63,6 +81,7 @@ pkg_npm(
"//packages/renderer:publish_files",
"//packages/rules_prerender",
"//packages/rules_prerender:publish_files",
"//packages/rules_prerender/publishable:publish_files",
"//tools/internal:annotation_extractor",
"//tools/internal:renderer",
"//tools/internal:resource_injector",
Expand Down
33 changes: 33 additions & 0 deletions BUILD.publish
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("@npm//rules_prerender:index.bzl", "prerender_component")

exports_files(glob(["**/*.bzl"]), visibility = ["//visibility:public"])

# Re-export the component at `rules_prerender/publishable` so it can be imported
# without reaching into internal file paths.
prerender_component(
name = "publishable",
srcs = [
"publishable.js",
"publishable.d.ts",
],
deps = ["//packages/rules_prerender/publishable"],
visibility = ["//visibility:public"],
)

# `js_library()` must be in the workspace root so the `path` attribute links
# there and `import 'rules_prerender/packages/rules_prerender/publishable/publishable'`
# resolves as expected.
js_library(
name = "scripts_for_publishable",
srcs = ["@npm//rules_prerender/packages/rules_prerender/publishable:scripts_sources"],
# Link under `external/npm/rules_prerender/...`
package_name = "rules_prerender",
visibility = ["@npm//rules_prerender/packages/rules_prerender/publishable:__pkg__"],
)

js_library(
name = "scripts_for_publishable_dep",
srcs = ["@npm//rules_prerender/packages/rules_prerender/publishable:scripts_dep_sources"],
package_name = "rules_perender",
visibility = ["@npm//rules_prerender/packages/rules_prerender/publishable:__pkg__"],
)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"lint-commit": "git diff \"${COMMIT}~1..${COMMIT}\" --name-only | npm run -s -- filter-lintable | xargs -P 8 -L 1 -I {} bash -c \"git show \\\"${COMMIT}:{}\\\" --diff-filter=d | npm run -s -- eslint --stdin --stdin-filename \\\"{}@${COMMIT}\\\"\" --max-warnings 0",
"filter-lintable": "grep '\\.js$\\|\\.cjs$\\|\\.mjs$\\|\\.ts$'",
"eslint": "eslint",
"prepare": "husky install"
"prepare": "which husky &> /dev/null && husky install || exit 0"
},
"repository": {
"type": "git",
Expand Down
93 changes: 93 additions & 0 deletions packages/rules_prerender/publishable/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
load("@npm//@bazel/typescript:index.bzl", "ts_library")
load("//:index.bzl", "prerender_component", "web_resources")
load(
"//packages/rules_prerender:prerender_component_publish_files.bzl",
"prerender_component_publish_files",
)
load("//tools:publish.bzl", "publish_files")

publish_files(
name = "publish_files",
files = [
":publishable_publish_files",
":publishable_dep_publish_files",
],
visibility = ["//:__pkg__"],
)

# TODO: Test dependencies?
prerender_component_publish_files(
name = "publishable_publish_files",
dep = ":publishable",
)

prerender_component(
name = "publishable",
srcs = ["publishable.ts"],
lib_deps = ["//packages/rules_prerender"],
scripts = [":scripts"],
styles = ["publishable_style.css"],
visibility = ["//:__pkg__"],
deps = [":publishable_dep"],
)

ts_library(
name = "scripts",
srcs = ["publishable_script.ts"],
)

prerender_component_publish_files(
name = "publishable_dep_publish_files",
dep = ":publishable_dep",
)

prerender_component(
name = "publishable_dep",
srcs = ["publishable_dep.ts"],
lib_deps = [
":prerender_dep",
"//packages/rules_prerender",
],
scripts = [":publishable_dep_script"],
styles = [
"publishable_dep_style.css",
":style_dep",
],
resources = [":publishable_dep_resource"],
)

ts_library(
name = "prerender_dep",
srcs = ["prerender_dep.ts"],
)

ts_library(
name = "publishable_dep_script",
srcs = ["publishable_dep_script.ts"],
deps = [":script_dep"],
)

ts_library(
name = "script_dep",
srcs = ["script_dep.ts"],
)

filegroup(
name = "style_dep",
srcs = ["style_dep.css"],
)

web_resources(
name = "publishable_dep_resource",
entries = {
"/red.png": "red.png",
},
deps = [":resource_dep"],
)

web_resources(
name = "resource_dep",
entries = {
"/blue.png": "blue.png",
},
)
53 changes: 53 additions & 0 deletions packages/rules_prerender/publishable/BUILD.publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
load("@npm//rules_prerender:index.bzl", "prerender_component", "web_resources")

prerender_component(
name = "publishable",
srcs = [
"publishable.js",
"publishable.d.ts",
],
scripts = ["@npm//rules_prerender:scripts_for_publishable"],
styles = ["publishable_style.css"],
visibility = ["//visibility:public"],
deps = [":publishable_dep"],
)

# Must copy all client-side sources to `bin/` so that Rollup can find them
copy_to_bin(
name = "scripts_sources",
srcs = ["publishable_script.mjs"],
visibility = ["@npm//rules_prerender:__pkg__"],
)

prerender_component(
name = "publishable_dep",
srcs = [
"publishable_dep.js",
"publishable_dep.d.ts",
],
scripts = ["@npm//rules_prerender:scripts_for_publishable_dep"],
styles = [
"publishable_dep_style.css",
"style_dep.css",
],
resources = [":publishable_dep_resource"],
)

# Must copy all client-side sources to `bin/` so that Rollup can find them
copy_to_bin(
name = "scripts_dep_sources",
srcs = [
"publishable_dep_script.mjs",
"script_dep.mjs",
],
visibility = ["@npm//rules_prerender:__pkg__"],
)

web_resources(
name = "publishable_dep_resource",
entries = {
"/red.png": "publishable_dep_resources/red.png",
"/blue.png": "publishable_dep_resources/blue.png",
},
)
Binary file added packages/rules_prerender/publishable/blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/rules_prerender/publishable/prerender_dep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const greeting = 'Hello' as string;
14 changes: 14 additions & 0 deletions packages/rules_prerender/publishable/publishable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { includeScript, includeStyle } from 'rules_prerender';
import { renderMessage } from 'rules_prerender/packages/rules_prerender/publishable/publishable_dep';

export function renderPublishable(target: string): string {
return `
<div class="publishable">
<span>Publishable</span>
${renderMessage(target)}
${includeScript('rules_prerender/packages/rules_prerender/publishable/publishable_script')}
${includeStyle('rules_prerender/packages/rules_prerender/publishable/publishable_style.css')}
</div>
`.trim();
}
16 changes: 16 additions & 0 deletions packages/rules_prerender/publishable/publishable_dep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { includeScript, includeStyle } from 'rules_prerender';
import { greeting } from 'rules_prerender/packages/rules_prerender/publishable/prerender_dep';

export function renderMessage(target: string): string {
return `
<div class="publishable-dependency">
<span>${greeting}, ${target}!</span>
<img src="/red.png" width="10px" height="10px"></img>
<img src="/blue.png" width="10px" height="10px"></img>
${includeScript('rules_prerender/packages/rules_prerender/publishable/publishable_dep_script')}
${includeStyle('rules_prerender/packages/rules_prerender/publishable/publishable_dep_style.css')}
</div>
`.trim();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { message } from './script_dep';

console.log(message);
console.log('Hello from publishable_dep!');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'rules_prerender/packages/rules_prerender/publishable/style_dep.css';
1 change: 1 addition & 0 deletions packages/rules_prerender/publishable/publishable_script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('Hello from publishable!');
3 changes: 3 additions & 0 deletions packages/rules_prerender/publishable/publishable_style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.publishable > span {
color: red;
}
Binary file added packages/rules_prerender/publishable/red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/rules_prerender/publishable/script_dep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const message = 'Hello from script_dep!' as string;
3 changes: 3 additions & 0 deletions packages/rules_prerender/publishable/style_dep.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.publishable-dependency > span {
color: blue;
}
1 change: 1 addition & 0 deletions publishable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './packages/rules_prerender/publishable/publishable';
4 changes: 4 additions & 0 deletions user/.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
bazel-out

85 changes: 85 additions & 0 deletions user/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 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

# Cache action outputs on disk so they persist across output_base and bazel shutdown (eg. changing branches)
build --disk_cache=~/.cache/bazel-disk-cache

# 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.
# --compilation_mode=dbg
# Rules may change their build outputs if the compilation mode is set to dbg. For example,
# mininfiers such as terser may make their output more human readable when this is set. Rules will pass `COMPILATION_MODE`
# to `nodejs_binary` executables via the actions.run env attribute.
# See https://docs.bazel.build/versions/master/user-manual.html#flag--compilation_mode for more details.
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 --compilation_mode=dbg

# Turn off legacy external runfiles
# This prevents accidentally depending on this feature, which Bazel will remove.
build --nolegacy_external_runfiles

# 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

# When running `bazel coverage` --instrument_test_targets needs to be set in order to
# collect coverage information from test targets
coverage --instrument_test_targets

# 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

1 change: 1 addition & 0 deletions user/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.2.0
4 changes: 4 additions & 0 deletions user/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

dist
bazel-out
node_modules
1 change: 1 addition & 0 deletions user/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(["tsconfig.json"], visibility = ["//visibility:public"])
Loading

0 comments on commit 6d8df06

Please sign in to comment.