-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates
prerender_component()
to accept JS source files.
Refs #38, #39, #4. This allows JS source files to be included in `prerender_component()` and related rules, both for prerendering HTML and as client side scripts. This mostly involved replacing the relevant `ts_library()` targets with `js_library()` targets to compile user code and avoid depending on it from a `ts_library()` which would require `*.d.ts` definitions that the user may not write. I included support for `*.mjs` and `*.cjs` files, although I have had trouble getting ESM to work with rules_nodejs and `*.mjs` doesn't work for a lot of complicated reasons not related to `prerender_component()`. Since we need to compile user code with either `ts_library()` or `js_library()`, it means that a given `prerender_component()` target can only compile *all* TypeScript or *all* JavaScript. This is an unfortunate requirement, but not also a reasonable ask of users, so I don't feel too bad for not supporting it.
- Loading branch information
Showing
7 changed files
with
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Utilities based around file paths.""" | ||
|
||
def is_js_file(src): | ||
"""Returns whether or not the given src path is a JavaScript file.""" | ||
return src.endswith(".js") or src.endswith(".mjs") or src.endswith(".cjs") |
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,22 @@ | ||
"""Tests for `paths.bzl`.""" | ||
|
||
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") | ||
load(":paths.bzl", "is_js_file") | ||
|
||
def _is_js_file_impl(ctx): | ||
env = unittest.begin(ctx) | ||
|
||
asserts.equals(env, True, is_js_file("foo/bar/baz.js")) | ||
asserts.equals(env, True, is_js_file("foo/bar/baz.mjs")) | ||
asserts.equals(env, True, is_js_file("foo/bar/baz.cjs")) | ||
|
||
asserts.equals(env, False, is_js_file("foo/bar/baz.ts")) | ||
asserts.equals(env, False, is_js_file("foo/bar/baz.d.ts")) | ||
asserts.equals(env, False, is_js_file("foo/bar/baz.test")) | ||
|
||
return unittest.end(env) | ||
|
||
_is_js_file_test = unittest.make(_is_js_file_impl) | ||
|
||
def paths_test_suite(name): | ||
unittest.suite(name, _is_js_file_test) |
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
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