Skip to content

Commit

Permalink
refactor: update to rules_js 1.0.0-rc.4 (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Aug 2, 2022
1 parent 8c96d84 commit 17a1ee5
Show file tree
Hide file tree
Showing 10 changed files with 1,216 additions and 1,124 deletions.
12 changes: 8 additions & 4 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Users should not load files under "/internal"
## webpack_bundle

<pre>
webpack_bundle(<a href="#webpack_bundle-name">name</a>, <a href="#webpack_bundle-args">args</a>, <a href="#webpack_bundle-deps">deps</a>, <a href="#webpack_bundle-entry_point">entry_point</a>, <a href="#webpack_bundle-entry_points">entry_points</a>, <a href="#webpack_bundle-output_dir">output_dir</a>, <a href="#webpack_bundle-srcs">srcs</a>, <a href="#webpack_bundle-supports_workers">supports_workers</a>,
<a href="#webpack_bundle-webpack">webpack</a>, <a href="#webpack_bundle-webpack_config">webpack_config</a>, <a href="#webpack_bundle-webpack_worker">webpack_worker</a>)
webpack_bundle(<a href="#webpack_bundle-name">name</a>, <a href="#webpack_bundle-args">args</a>, <a href="#webpack_bundle-data">data</a>, <a href="#webpack_bundle-deps">deps</a>, <a href="#webpack_bundle-entry_point">entry_point</a>, <a href="#webpack_bundle-entry_points">entry_points</a>, <a href="#webpack_bundle-output_dir">output_dir</a>, <a href="#webpack_bundle-srcs">srcs</a>,
<a href="#webpack_bundle-supports_workers">supports_workers</a>, <a href="#webpack_bundle-webpack">webpack</a>, <a href="#webpack_bundle-webpack_config">webpack_config</a>, <a href="#webpack_bundle-webpack_worker">webpack_worker</a>)
</pre>

Runs the webpack-cli under bazel.
Expand All @@ -23,6 +23,7 @@ Runs the webpack-cli under bazel.
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="webpack_bundle-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | |
| <a id="webpack_bundle-args"></a>args | Command line arguments to pass to Webpack.<br><br>These argument passed on the command line before arguments that are added by the rule. Run <code>bazel</code> with <code>--subcommands</code> to see what Webpack CLI command line was invoked.<br><br>See the [Webpack CLI docs](https://webpack.js.org/api/cli/) for a complete list of supported arguments. | List of strings | optional | [] |
| <a id="webpack_bundle-data"></a>data | Runtime dependencies to include in binaries/tests that depend on this target.<br><br> The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the <code>data</code> attribute are added to the runfiles of this taregt. Thery should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.<br><br> If this list contains linked npm packages, npm package store targets or other targets that provide <code>JsInfo</code>, <code>NpmPackageStoreInfo</code> providers are gathered from <code>JsInfo</code>. This is done directly from <code>npm_package_stores</code> and <code>transitive_npm_package_stores</code> fields of these and for linked npm package targets, from the underlying npm_package_store target(s) that back the links via <code>npm_linked_packages</code> and <code>transitive_npm_linked_packages</code>.<br><br> Gathered <code>NpmPackageStoreInfo</code> providers are used downstream as direct dependencies when linking a downstream <code>npm_package</code> target with <code>npm_link_package</code>. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="webpack_bundle-deps"></a>deps | Runtime dependencies which may be loaded during compliation. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="webpack_bundle-entry_point"></a>entry_point | The point or points where to start the application bundling process.<br><br>See https://webpack.js.org/concepts/entry-points/ | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |
| <a id="webpack_bundle-entry_points"></a>entry_points | - | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: Label -> String</a> | optional | {} |
Expand All @@ -40,7 +41,8 @@ Runs the webpack-cli under bazel.

<pre>
webpack_dev_server_rule(<a href="#webpack_dev_server_rule-name">name</a>, <a href="#webpack_dev_server_rule-chdir">chdir</a>, <a href="#webpack_dev_server_rule-data">data</a>, <a href="#webpack_dev_server_rule-enable_runfiles">enable_runfiles</a>, <a href="#webpack_dev_server_rule-entry_point">entry_point</a>, <a href="#webpack_dev_server_rule-env">env</a>, <a href="#webpack_dev_server_rule-expected_exit_code">expected_exit_code</a>,
<a href="#webpack_dev_server_rule-log_level">log_level</a>, <a href="#webpack_dev_server_rule-node_options">node_options</a>, <a href="#webpack_dev_server_rule-patch_node_fs">patch_node_fs</a>, <a href="#webpack_dev_server_rule-srcs">srcs</a>, <a href="#webpack_dev_server_rule-webpack_config">webpack_config</a>)
<a href="#webpack_dev_server_rule-include_declarations">include_declarations</a>, <a href="#webpack_dev_server_rule-include_npm_linked_packages">include_npm_linked_packages</a>, <a href="#webpack_dev_server_rule-include_transitive_sources">include_transitive_sources</a>,
<a href="#webpack_dev_server_rule-log_level">log_level</a>, <a href="#webpack_dev_server_rule-node_options">node_options</a>, <a href="#webpack_dev_server_rule-patch_node_fs">patch_node_fs</a>, <a href="#webpack_dev_server_rule-webpack_config">webpack_config</a>)
</pre>


Expand All @@ -57,10 +59,12 @@ webpack_dev_server_rule(<a href="#webpack_dev_server_rule-name">name</a>, <a hre
| <a id="webpack_dev_server_rule-entry_point"></a>entry_point | Internal use only | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | required | |
| <a id="webpack_dev_server_rule-env"></a>env | Environment variables of the action.<br><br> Subject to <code>$(location)</code> and make variable expansion. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="webpack_dev_server_rule-expected_exit_code"></a>expected_exit_code | The expected exit code.<br><br> Can be used to write tests that are expected to fail. | Integer | optional | 0 |
| <a id="webpack_dev_server_rule-include_declarations"></a>include_declarations | When True, <code>declarations</code> and <code>transitive_declarations</code> from <code>JsInfo</code> providers in data targets are included in the runfiles of the target.<br><br> Defaults to false since declarations are generally not needed at runtime and introducing them could slow down developer round trip time due to having to generate typings on source file changes. | Boolean | optional | False |
| <a id="webpack_dev_server_rule-include_npm_linked_packages"></a>include_npm_linked_packages | When True, files in <code>npm_linked_packages</code> and <code>transitive_npm_linked_packages</code> from <code>JsInfo</code> providers in data targets are included in the runfiles of the target.<br><br> <code>transitive_files</code> from <code>NpmPackageStoreInfo</code> providers in data targets are also included in the runfiles of the target. | Boolean | optional | True |
| <a id="webpack_dev_server_rule-include_transitive_sources"></a>include_transitive_sources | When True, <code>transitive_sources</code> from <code>JsInfo</code> providers in data targets are included in the runfiles of the target. | Boolean | optional | True |
| <a id="webpack_dev_server_rule-log_level"></a>log_level | Set the logging level.<br><br> Log from are written to stderr. They will be supressed on success when running as the tool of a js_run_binary when silent_on_success is True. In that case, they will be shown only on a build failure along with the stdout & stderr of the node tool being run. | String | optional | "error" |
| <a id="webpack_dev_server_rule-node_options"></a>node_options | Options to pass to the node.<br><br> https://nodejs.org/api/cli.html | List of strings | optional | [] |
| <a id="webpack_dev_server_rule-patch_node_fs"></a>patch_node_fs | Patch the to Node.js <code>fs</code> API (https://nodejs.org/api/fs.html) for this node program to prevent the program from following symlinks out of the execroot, runfiles and the sandbox.<br><br> When enabled, <code>js_binary</code> patches the Node.js sync and async <code>fs</code> API functions <code>lstat</code>, <code>readlink</code>, <code>realpath</code>, <code>readdir</code> and <code>opendir</code> so that the node program being run cannot resolve symlinks out of the execroot and the runfiles tree. When in the sandbox, these patches prevent the program being run from resolving symlinks out of the sandbox.<br><br> When disabled, node programs can leave the execroot, runfiles and sandbox by following symlinks which can lead to non-hermetic behavior. | Boolean | optional | True |
| <a id="webpack_dev_server_rule-srcs"></a>srcs | JavaScript source files from the workspace. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] |
| <a id="webpack_dev_server_rule-webpack_config"></a>webpack_config | Webpack configuration file.<br><br>See https://webpack.js.org/configuration/ | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None |


Expand Down
19 changes: 16 additions & 3 deletions scripts/mirror_releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,41 @@ npx pnpm install [email protected] webpack-cli webpack-dev-server @bazel/worker --l
touch BUILD
cat >WORKSPACE <<EOF
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "aspect_rules_js",
sha256 = "b82da82edf64ba7e07e568193d645fc09b0a4ec92e0d82bd4e53d1a0e28ff681",
strip_prefix = "rules_js-1.0.0-rc.3",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0-rc.3.tar.gz",
sha256 = "f2b36aac9d3368e402c9083c884ad9b26ca6fa21e83b53c12482d6cb2e949451",
strip_prefix = "rules_js-1.0.0-rc.4",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0-rc.4.tar.gz",
)
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
rules_js_dependencies()
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
nodejs_register_toolchains(
name = "nodejs",
node_version = "16.9.0",
)
load("@aspect_bazel_lib//lib:repositories.bzl", "DEFAULT_YQ_VERSION", "register_yq_toolchains")
register_yq_toolchains(
version = DEFAULT_YQ_VERSION,
)
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
npm_translate_lock(
name = "npm_webpack",
pnpm_lock = "//:pnpm-lock.yaml",
)
load("@npm_webpack//:repositories.bzl", "npm_repositories")
npm_repositories()
EOF
bazel fetch @npm_webpack//:all
cp $(bazel info output_base)/external/npm_webpack/{defs,repositories}.bzl "$out"
Expand Down
6 changes: 3 additions & 3 deletions webpack/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def rules_webpack_dependencies():
maybe(
http_archive,
name = "aspect_rules_js",
sha256 = "b82da82edf64ba7e07e568193d645fc09b0a4ec92e0d82bd4e53d1a0e28ff681",
strip_prefix = "rules_js-1.0.0-rc.3",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0-rc.3.tar.gz",
sha256 = "f2b36aac9d3368e402c9083c884ad9b26ca6fa21e83b53c12482d6cb2e949451",
strip_prefix = "rules_js-1.0.0-rc.4",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.0.0-rc.4.tar.gz",
)

maybe(
Expand Down
14 changes: 10 additions & 4 deletions webpack/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")


bzl_library(
name = "webpack_bundle",
srcs = ["webpack_bundle.bzl"],
visibility = ["//webpack:__subpackages__"],
deps = ["@aspect_bazel_lib//lib:copy_to_bin"],
deps = [
"@aspect_bazel_lib//lib:copy_to_bin",
"@aspect_rules_js//js:libs",
"@aspect_rules_js//js:providers",
],
)

exports_files(["webpack.config.js", "webpack_worker.js"])
exports_files([
"webpack.config.js",
"webpack_worker.js",
])

# gazelle:exclude v*.*.*/*
# gazelle:ignore
bzl_library(
name = "versions",
srcs = ["versions.bzl"],
visibility = ["//webpack:__subpackages__"]
visibility = ["//webpack:__subpackages__"],
)
2 changes: 1 addition & 1 deletion webpack/private/devserver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ bzl_library(
name = "devserver",
srcs = ["devserver.bzl"],
visibility = ["//webpack:__subpackages__"],
deps = ["@aspect_rules_js//js:defs"],
deps = ["@aspect_rules_js//js:libs"],
)
57 changes: 30 additions & 27 deletions webpack/private/devserver/devserver.bzl
Original file line number Diff line number Diff line change
@@ -1,69 +1,72 @@
"webpack_dev_server macro"
load("@aspect_rules_js//js:defs.bzl", "js_binary_lib")
load("@bazel_skylib//lib:dicts.bzl", "dicts")

load("@aspect_rules_js//js:libs.bzl", "js_binary_lib", "js_lib_helpers")
load("@bazel_skylib//lib:dicts.bzl", "dicts")

_attrs = dicts.add(js_binary_lib.attrs, {
"entry_point": attr.label(
doc = "Internal use only",
mandatory = True,
),
"srcs": attr.label_list(
doc = "JavaScript source files from the workspace.",
allow_files = True
),
"webpack_config": attr.label(
"webpack_config": attr.label(
doc = """Webpack configuration file.
See https://webpack.js.org/configuration/""",
allow_single_file = [".js"],
mandatory = False
),
allow_single_file = [".js"],
mandatory = False,
),
"_webpack_devserver_config": attr.label(
doc = "Internal use only",
allow_single_file = [".js"],
default = Label("//webpack/private/devserver:webpack.config.js")
allow_single_file = [".js"],
default = Label("//webpack/private/devserver:webpack.config.js"),
),
})


def _impl(ctx):

fixed_args = [
"serve",
"--output-path",
"./dist",
"-c",
ctx.file._webpack_devserver_config.short_path
"-c",
ctx.file._webpack_devserver_config.short_path,
]

files = ctx.files.srcs + ctx.files.data + [
ctx.file._webpack_devserver_config
]
files = [ctx.file._webpack_devserver_config]
files.extend(ctx.files.data)
files.extend(js_lib_helpers.gather_files_from_js_providers(
targets = ctx.attr.data,
include_transitive_sources = ctx.attr.include_transitive_sources,
include_declarations = ctx.attr.include_declarations,
include_npm_linked_packages = ctx.attr.include_npm_linked_packages,
))

if ctx.attr.webpack_config:
files.append(ctx.file.webpack_config)
fixed_args.extend(["-c", ctx.file.webpack_config.short_path, "--merge"])


launcher = js_binary_lib.create_launcher(
ctx,
log_prefix_rule_set = "aspect_rules_webpack",
log_prefix_rule = "webpack_devserver",
fixed_args = fixed_args,
)

runfiles = launcher.runfiles.merge(ctx.runfiles(
runfiles = ctx.runfiles(
files = files,
))
).merge(launcher.runfiles).merge_all([
target[DefaultInfo].default_runfiles
for target in ctx.attr.data
])

return [DefaultInfo(
executable = launcher.executable,
runfiles = runfiles
)]
return [
DefaultInfo(
executable = launcher.executable,
runfiles = runfiles,
),
]

lib = struct(
attrs = _attrs,
implementation = _impl,
toolchains = js_binary_lib.toolchains,
)
)
Loading

0 comments on commit 17a1ee5

Please sign in to comment.