From ca48fe7e0a350530535786020247cf546c702ad2 Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Tue, 21 May 2024 17:57:05 -0700 Subject: [PATCH] feat: upgrade to rules_js 2.0 (#95) --- .aspect/bazelrc/javascript.bazelrc | 1 + MODULE.bazel | 22 ++++----------- docs/rollup.md | 28 +++++++++---------- e2e/smoke/MODULE.bazel | 6 ++-- e2e/smoke/WORKSPACE.bazel | 10 +++---- rollup/dependencies.bzl | 21 +++++++------- rollup/private/rollup.bzl | 44 ++++++++++++++---------------- 7 files changed, 58 insertions(+), 74 deletions(-) diff --git a/.aspect/bazelrc/javascript.bazelrc b/.aspect/bazelrc/javascript.bazelrc index 474ec63..ace9d60 100644 --- a/.aspect/bazelrc/javascript.bazelrc +++ b/.aspect/bazelrc/javascript.bazelrc @@ -8,3 +8,4 @@ # details. # Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options run:debug -- --node_options=--inspect-brk +test:debug --test_env=NODE_OPTIONS=--inspect-brk diff --git a/MODULE.bazel b/MODULE.bazel index 9c3e82e..01839bf 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -7,14 +7,10 @@ module( ) # Lower-bounds (minimum) versions for direct runtime dependencies -bazel_dep(name = "bazel_skylib", version = "1.3.0") - -# Need feat: backport 2.x features for interoperability by @kormide in #657 -bazel_dep(name = "aspect_bazel_lib", version = "1.38.0") - -# Need feat: import toolchains to use for copy actions by @kormide in #1355 -bazel_dep(name = "aspect_rules_js", version = "1.34.0") -bazel_dep(name = "rules_nodejs", version = "5.5.3") +bazel_dep(name = "aspect_bazel_lib", version = "2.7.3") +bazel_dep(name = "aspect_rules_js", version = "2.0.0-rc0") +bazel_dep(name = "bazel_skylib", version = "1.5.0") +bazel_dep(name = "rules_nodejs", version = "6.1.0") bazel_dep(name = "platforms", version = "0.0.5") rollup = use_extension("@aspect_rules_rollup//rollup:extensions.bzl", "rollup") @@ -27,6 +23,7 @@ use_repo(rollup, "rollup") ####### Dev dependencies ######## bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True) +bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc") npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True) npm.npm_translate_lock( @@ -36,12 +33,3 @@ npm.npm_translate_lock( verify_node_modules_ignored = "//:.bazelignore", ) use_repo(npm, "npm") - -# We want the stardoc handling from bazel-lib 2.x for dev use here, -# but not force users to upgrade yet. -archive_override( - module_name = "aspect_bazel_lib", - integrity = "sha256-9ep2aCsgnMC9kND1o7JtL3pqKIXwxfYV5ykT9IBduw0=", - strip_prefix = "bazel-lib-2.5.0", - urls = ["https://github.com/aspect-build/bazel-lib/releases/download/v2.5.0/bazel-lib-v2.5.0.tar.gz"], -) diff --git a/docs/rollup.md b/docs/rollup.md index a490a14..98ba462 100644 --- a/docs/rollup.md +++ b/docs/rollup.md @@ -22,19 +22,19 @@ For further information about rollup, see https://rollupjs.org/ | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | A unique name for this target. | none | -| node_modules | Label pointing to the linked node_modules target where the rollup is linked, e.g. //:node_modules.

rollup must be linked into the node_modules supplied. | none | -| entry_point | The bundle's entry point (e.g. your main.js or app.js or index.js).

This is just a shortcut for the entry_points attribute with a single output chunk named the same as the rule.

For example, these are equivalent:

python rollup(     name = "bundle",     node_modules = "//:node_modules",     entry_point = "index.js", ) 


python rollup(     name = "bundle",     node_modules = "//:node_modules",     entry_points = {         "index.js": "bundle"     } ) 


If rollup is used on a ts_library, the rollup rule handles selecting the correct outputs from ts_library.

In this case, entry_point can be specified as the .ts file and rollup will handle the mapping to the .mjs output file.

For example:

python ts_library(     name = "foo",     srcs = [         "foo.ts",         "index.ts",     ], ) rollup(     name = "bundle",     node_modules = "//:node_modules",     deps = [ "foo" ],     entry_point = "index.ts", ) 
| None | -| entry_points | The bundle's entry points (e.g. your main.js or app.js or index.js).

Passed to the [--input option](https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#input) in Rollup.

Keys in this dictionary are labels pointing to .js entry point files.

Values are the name to be given to the corresponding output chunk.

Either this attribute or entry_point must be specified, but not both. | {} | -| srcs | Non-entry point JavaScript source files from the workspace.

You must not repeat file(s) passed to entry_point/entry_points. | [] | -| deps | Other libraries that are required by the code, or by the rollup.config.js. | [] | -| args | Command line arguments to pass to Rollup. Can be used to override config file settings.

These argument passed on the command line before arguments that are added by the rule.

Run bazel with --subcommands to see what Rollup CLI command line was invoked.

See the <a href="https://rollupjs.org/guide/en/#command-line-flags">Rollup CLI docs</a> for a complete list of supported arguments. | [] | -| config_file | A rollup.config.js file

Passed to the --config option, see [the config doc](https://rollupjs.org/guide/en/#configuration-files)

If not set, a default basic Rollup config is used. | "@aspect_rules_rollup//rollup:rollup.config" | -| format | Specifies the format of the generated bundle. One of the following:

- amd: Asynchronous Module Definition, used with module loaders like RequireJS - cjs: CommonJS, suitable for Node and other bundlers - esm: Keep the bundle as an ES module file, suitable for other bundlers and inclusion as a <script type=module> tag in modern browsers - iife: A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this.) - umd: Universal Module Definition, works as amd, cjs and iife all in one - system: Native format of the SystemJS loader | "esm" | -| output_dir | Whether to produce a directory output.

We will use the [--output.dir option](https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#outputdir) in rollup rather than --output.file.

If the program produces multiple chunks, you must specify this attribute.

Otherwise, the outputs are assumed to be a single file. | False | -| silent | Whether to execute the rollup binary with the --silent flag, defaults to False.

Using --silent can cause rollup to [ignore errors/warnings](https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#onwarn) which are only surfaced via logging. Since bazel expects printing nothing on success, setting silent to True is a more Bazel-idiomatic experience, however could cause rollup to drop important warnings. | False | -| silent_on_success | Even stronger than --silent, defaults to False.

Since the build still emits some texted, even when passed --silent, this uses the same flag as npm_package_bin to supress all output on success. | False | -| sourcemap | Whether to produce sourcemaps.

Passed to the [--sourcemap option](https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#outputsourcemap") in Rollup | "inline" | -| data | Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_deps field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used. Gathered NpmPackageStoreInfo providers are propagated to the direct dependencies of downstream linked npm_package targets.

NB: Linked npm package targets that are "dev" dependencies do not forward their underlying npm_package_store target(s) through npm_package_store_deps and will therefore not be propagated to the direct dependencies of downstream linked npm_package targets. npm packages that come in from npm_translate_lock are considered "dev" dependencies if they are have dev: true set in the pnpm lock file. This should be all packages that are only listed as "devDependencies" in all package.json files within the pnpm workspace. This behavior is intentional to mimic how devDependencies work in published npm packages. | [] | -| kwargs | Other common arguments such as tags and visibility | none | +| node_modules | Label pointing to the linked node_modules target where the `rollup` is linked, e.g. `//:node_modules`.

`rollup` must be linked into the node_modules supplied. | none | +| entry_point | The bundle's entry point (e.g. your main.js or app.js or index.js).

This is just a shortcut for the `entry_points` attribute with a single output chunk named the same as the rule.

For example, these are equivalent:

rollup(
    name = "bundle",
    node_modules = "//:node_modules",
    entry_point = "index.js",
)


rollup(
    name = "bundle",
    node_modules = "//:node_modules",
    entry_points = {
        "index.js": "bundle"
    }
)


If `rollup` is used on a `ts_library`, the `rollup` rule handles selecting the correct outputs from `ts_library`.

In this case, `entry_point` can be specified as the `.ts` file and `rollup` will handle the mapping to the `.mjs` output file.

For example:

ts_library(
    name = "foo",
    srcs = [
        "foo.ts",
        "index.ts",
    ],
)
rollup(
    name = "bundle",
    node_modules = "//:node_modules",
    deps = [ "foo" ],
    entry_point = "index.ts",
)
| `None` | +| entry_points | The bundle's entry points (e.g. your main.js or app.js or index.js).

Passed to the [`--input` option](https://github.com/rollup/rollup/blob/master/docs/999-big-list-of-options.md#input) in Rollup.

Keys in this dictionary are labels pointing to .js entry point files.

Values are the name to be given to the corresponding output chunk.

Either this attribute or `entry_point` must be specified, but not both. | `{}` | +| srcs | Non-entry point JavaScript source files from the workspace.

You must not repeat file(s) passed to entry_point/entry_points. | `[]` | +| deps | Other libraries that are required by the code, or by the rollup.config.js. | `[]` | +| args | Command line arguments to pass to Rollup. Can be used to override config file settings.

These argument passed on the command line before arguments that are added by the rule.

Run `bazel` with `--subcommands` to see what Rollup CLI command line was invoked.

See the Rollup CLI docs for a complete list of supported arguments. | `[]` | +| config_file | A `rollup.config.js` file

Passed to the `--config` option, see [the config doc](https://rollupjs.org/guide/en/#configuration-files)

If not set, a default basic Rollup config is used. | `"@aspect_rules_rollup//rollup:rollup.config"` | +| format | Specifies the format of the generated bundle. One of the following:

- `amd`: Asynchronous Module Definition, used with module loaders like RequireJS - `cjs`: CommonJS, suitable for Node and other bundlers - `esm`: Keep the bundle as an ES module file, suitable for other bundlers and inclusion as a `