Skip to content

0.38.0

Compare
Choose a tag to compare
@alexeagle alexeagle released this 26 Sep 23:18

With Bazel itself now at 1.0.0rc3, we are getting closer to a 1.0 release of rules_nodejs.

You can follow our progress at https://github.com/bazelbuild/rules_nodejs/milestone/1

This means it's time for us to land all the breaking changes for things we don't want to support long-term, so starting with this release you can expect more of them.
As always we are doing our best to keep these changes minimal and help you upgrade past them.

Upgrade:

http_archive(
    name = "build_bazel_rules_nodejs",
    sha256 = "1249a60f88e4c0a46d78de06be04d3d41e7421dcfa0c956de65309a7b7ecf6f4",
    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.38.0/rules_nodejs-0.38.0.tar.gz"],
)

You may need to bazel clean --expunge after the update. See #1220

New Features:

npm_package_bin general rule

We now offer a "general rule" for running arbitrary programs distributed over npm, npm_package_bin. You can think of this as "run ./node_modules/.bin/tool" under Bazel.

If you're familiar with Bazel's genrule you can also think of this as an npm-specific variant of that rule.

In this model, you supply the exact same arguments as the CLI documentation for the tool indicates. There is no Bazel-specific layer, which means you can start using
any npm tool immediately
, so long as it follows the documented restrictions. We've tested this feature with a wide variety of packages such as http-server, history-server, google-closure-compiler, sass, babel, less, and stylus.
Note that this feature doesn't let you treat an arbitrary npm test running package as a *_test bazel rule, so this isn't a magic way to get Jest working.

See the documentation:
https://github.com/bazelbuild/rules_nodejs/blob/master/docs/Built-ins.md#npm_package_bin

In addition, we automatically generate an npm_package_bin rule for every npm bin entry we find in the packages you install.

That means if you

$ npm i @babel/cli @babel/core

you can immediately use it in a BUILD file:

load("@npm//@babel/cli:index.bzl", "babel")
babel(
    name = "es5",
    data = [
        "es5.babelrc",
        "@npm//@babel/preset-env",
    ],
    output_dir = True,
    args = [
        "$(location chunks)",
        "--config-file",
        "$(location es5.babelrc)",
        "--out-dir",
        "$@",
    ],
)

to start using the binary. Use bazel query @npm//... to find out more about what we generate in the @npm workspace.

new rollup_bundle rule

This closely mirrors the Rollup CLI. In particular, you can now pass your own rollup.config.js file, which means you can do anything with Rollup under Bazel that you could do without it.

See https://github.com/bazelbuild/rules_nodejs/wiki for steps on migrating away from the old rollup_bundle rule. We will deprecate that rule in the next release.

Check out the new doc: https://github.com/bazelbuild/rules_nodejs/blob/master/docs/Rollup.md

new terser_minified rule

This closely mirrors the Terser CLI, with the additional support for minifying a directory of files. The directory case uses parallel subprocesses to make the build faster.

Check out the new doc: https://github.com/bazelbuild/rules_nodejs/blob/master/docs/Terser.md

Debugging flags

We now look for two environment variables to control our rules:

--define=VERBOSE_LOGS=1 causes our code to print verbose logging info. This probably doesn't mean much to you, but if included in issue reports, it will make it a lot faster for us to understand and troubleshoot the problem.

--define=DEBUG=1 changes the output of rules to make it easier for you to debug your own code. For example, the new terser_minified rule will produce formatted code.

Note that you can add these to your .bazelrc, often with a --config flag, see https://docs.bazel.build/versions/master/guide.html#config

For example,

# .bazelrc

# Build with --config=debug to enable these flags
build:debug --define=DEBUG=1 --my_other_flag

BREAKING CHANGES:

  • we no longer publish rules for http-server, history-server, less, and stylus npm packages. Use the generated bin mentioned above (you may also need to install the package if you didn't before):

    - load("@build_bazel_rules_nodejs//:defs.bzl", "history_server")
    + load("@npm//history-server:index.bzl", "history_server")
    
    - load("@build_bazel_rules_nodejs//:defs.bzl", "http_server")    
    + load("@npm//http-server:index.bzl", "http_server")
    
    - load("@npm_bazel_less//:index.bzl", "less_binary")             
    + load("@npm//less:index.bzl", "lessc")
    
    - load("@npm_bazel_stylus//:index.bzl", "stylus_binary")         
    + load("@npm//stylus:index.bzl", "stylus")
    
  • in addition, the new way to run lessc and stylus has you interact directly with their CLI rather than use some syntax sugar on it. You may want to define your own macro called less_binary or stylus_binary which re-introduces the syntax sugar if you want to keep your BUILD files the same. A new usage looks like this (copied from examples/app/styles/BUILD.bazel):

    lessc(
        name = "base",
        outs = [
            "base.css",
            "base.css.map",
        ],
        args = [
            "$(location base.less)",
            "$(location base.css)",
            "--silent",
            "--source-map",
        ],
        data = [
            "base.less",
            "variables.less",
        ],
    )
    
    stylus(
        name = "styles",
        outs = [
            "test.css",
            "test.css.map",
        ],
        args = [
            "$(location test.styl)",
            "--out",
            "$(location test.css)",
            "--compress",
            "--sourcemap",
        ],
        data = ["test.styl"],
    )
  • ts_library now outputs industry-standard ".mjs" files rather than the peculiar ".closure.js" files. If you had any paths hard-coded you'll need to update them.
    Note that the @angular/bazel package violates this, so to use this release with Angular, check out the patches folder in examples/angular.
    We'll make sure Angular picks up this change in their next release so the patch should be very short-lived.

  • The ts_proto_library rule is not well maintained, so we've moved it to the @bazel/labs package so that it won't be subject to the stability guarantees that will come with 1.0. Don't expect any features, fixes, or support for using protocol buffers for now.

  • rules_karma_dependencies was renamed to npm_bazel_karma_dependencies for consistency

  • We removed deprecated @npm_bazel_typescript//:defs.bzl and @npm_bazel_karma//:defs.bzl. Replace defs.bzl with index.bzl in your load() statements.

  • The @yarn workspace is no longer created. Use @nodejs//:yarn instead.

Upcoming Breaking Changes:

  • There is a new load location @build_bazel_rules_nodejs//:index.bzl. Please update from @build_bazel_rules_nodejs//:defs.bzl. This is so all our APIs use the same index.bzl convention.
  • We'll deprecate and remove the old rollup_bundle rule before 1.0

Bug Fixes

  • builtin: linker test should run program as an action (#1113) (7f0102e)
  • add golden file (9a02ee0)
  • add missing async test fixes (12f711a)
  • builtin: support for scoped modules in linker (#1199) (94abf68)
  • protractor: update rules_webtesting patch to include additional windows fixes (#1140) (f76e97b)
  • rollup: npm requires an index.js file (2ababdf)

chore

Code Refactoring

  • remove http_server and history_server rules (#1158) (01fdeec)

Features

  • builtin: detect APF node module format if ANGULAR_PACKAGE file found (#1112) (162e436)
  • builtin: expose the new linker to node programs (65d8a36)
  • builtin: introduce npm_package_bin (#1139) (2fd80cf)
  • builtin: linker should resolve workspace-absolute paths (307a796)
  • builtin: npm_package_bin can produce directory output (#1164) (6d8c625)
  • examples: demonstrate that a macro assembles a workflow (7231aaa)
  • examples: replace examples/webapp with new rollup_bundle (c6cd91c)
  • examples: the Angular example now lives in rules_nodejs (9072ddb)
  • rollup: ensure that sourcemaps work end-to-end (f340589)
  • rollup: new implementation of rollup_bundle in @bazel/rollup package (3873715), closes #532 #724
  • rollup: support multiple entry points (f660d39)
  • rollup: tests and docs for new rollup_bundle (cfef773)
  • terser: support directory inputs (21b5142)
  • add angular example (#1124) (c376355)
  • terser: support source map files (#1195) (d5bac48)
  • typescript: add JSEcmaScriptModuleInfo provider to ts_library outputs (1433eb9)