diff --git a/docs/Rollup.md b/docs/Rollup.md index 963393e974..ef03f252a4 100755 --- a/docs/Rollup.md +++ b/docs/Rollup.md @@ -347,7 +347,7 @@ Defaults to `@npm//@bazel/rollup/bin:rollup-worker` (*Boolean*): 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) +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. diff --git a/npm_deps.bzl b/npm_deps.bzl index 2e7f8a8a97..08b7444650 100644 --- a/npm_deps.bzl +++ b/npm_deps.bzl @@ -24,6 +24,8 @@ def npm_deps(): "//tools/npm_packages/bazel_workspaces_consistent:BUILD.bazel", "//tools/npm_packages/bazel_workspaces_consistent:index.bzl", "//tools/npm_packages/bazel_workspaces_consistent:package.json", + "//:tools/npm_packages/test_esm_pkg/package.json", + "//:tools/npm_packages/test_esm_pkg/index.mjs", "//:tools/npm_packages/hello/package.json", "//:tools/npm_packages/hello/index.js", "//:tools/npm_packages/node_resolve_index/index.js", @@ -91,6 +93,8 @@ js_library( "//tools/npm_packages/bazel_workspaces_consistent:BUILD.bazel", "//tools/npm_packages/bazel_workspaces_consistent:index.bzl", "//tools/npm_packages/bazel_workspaces_consistent:package.json", + "//:tools/npm_packages/test_esm_pkg/package.json", + "//:tools/npm_packages/test_esm_pkg/index.mjs", "//:tools/npm_packages/hello/package.json", "//:tools/npm_packages/hello/index.js", "//:tools/npm_packages/node_resolve_index/index.js", diff --git a/package.json b/package.json index b8fa7f5265..32d1c10b12 100644 --- a/package.json +++ b/package.json @@ -92,6 +92,7 @@ "source-map": "^0.7.3", "source-map-support": "0.5.9", "terser": "4.4.0", + "test_esm_pkg": "file:./tools/npm_packages/test_esm_pkg", "testy": "file:./tools/npm_packages/testy", "tmp": "0.1.0", "ts-lit-plugin": "1.1.9", diff --git a/packages/rollup/rollup_bundle.bzl b/packages/rollup/rollup_bundle.bzl index 0689f83cbe..37694901a1 100644 --- a/packages/rollup/rollup_bundle.bzl +++ b/packages/rollup/rollup_bundle.bzl @@ -135,7 +135,7 @@ Otherwise, the outputs are assumed to be a single file. "silent": attr.bool( doc = """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) +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. """, @@ -312,7 +312,8 @@ def _rollup_bundle(ctx): stamp = ctx.attr.stamp[StampSettingInfo].value - config = ctx.actions.declare_file("_%s.rollup_config.js" % ctx.label.name) + config_extension = ctx.file.config_file.extension + config = ctx.actions.declare_file("_%s.rollup_config.%s" % (ctx.label.name, config_extension)) ctx.actions.expand_template( template = ctx.file.config_file, output = config, diff --git a/packages/rollup/test/esm_config/BUILD.bazel b/packages/rollup/test/esm_config/BUILD.bazel new file mode 100644 index 0000000000..c5e8aeb95d --- /dev/null +++ b/packages/rollup/test/esm_config/BUILD.bazel @@ -0,0 +1,20 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test") +load("//packages/rollup:index.bzl", "rollup_bundle") + +rollup_bundle( + name = "esm_config", + config_file = "rollup.config.mjs", + entry_point = "input.js", + sourcemap = "false", + supports_workers = True, + deps = [ + # Fake test ESM package from `npm_deps.bzl`. + "@npm//test_esm_pkg", + ], +) + +generated_file_test( + name = "test", + src = "golden.js_", + generated = ":esm_config.js", +) diff --git a/packages/rollup/test/esm_config/golden.js_ b/packages/rollup/test/esm_config/golden.js_ new file mode 100644 index 0000000000..5ff191026e --- /dev/null +++ b/packages/rollup/test/esm_config/golden.js_ @@ -0,0 +1 @@ +console.log('Works - test fixture'); diff --git a/packages/rollup/test/esm_config/input.js b/packages/rollup/test/esm_config/input.js new file mode 100644 index 0000000000..5ff191026e --- /dev/null +++ b/packages/rollup/test/esm_config/input.js @@ -0,0 +1 @@ +console.log('Works - test fixture'); diff --git a/packages/rollup/test/esm_config/rollup.config.mjs b/packages/rollup/test/esm_config/rollup.config.mjs new file mode 100644 index 0000000000..d66969a96e --- /dev/null +++ b/packages/rollup/test/esm_config/rollup.config.mjs @@ -0,0 +1,7 @@ +// Note: We want to have some actual import statements here, +// validating that ESM is actually used for this config file. +import 'test_esm_pkg'; + +export default { + plugins: [], +}; diff --git a/tools/npm_packages/test_esm_pkg/index.mjs b/tools/npm_packages/test_esm_pkg/index.mjs new file mode 100644 index 0000000000..ee87b577ff --- /dev/null +++ b/tools/npm_packages/test_esm_pkg/index.mjs @@ -0,0 +1 @@ +export const greetings = 'Hello'; diff --git a/tools/npm_packages/test_esm_pkg/package.json b/tools/npm_packages/test_esm_pkg/package.json new file mode 100644 index 0000000000..f9f08bf315 --- /dev/null +++ b/tools/npm_packages/test_esm_pkg/package.json @@ -0,0 +1,8 @@ +{ + "version": "0.0.1", + "exports": { + ".": { + "import": "./index.mjs" + } + } +} diff --git a/yarn.lock b/yarn.lock index c06c487b42..567396ae46 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10367,6 +10367,9 @@ test-exclude@^6.0.0: glob "^7.1.4" minimatch "^3.0.4" +"test_esm_pkg@file:./tools/npm_packages/test_esm_pkg": + version "0.0.1" + "testy@file:./tools/npm_packages/testy": version "0.0.1"