blob: 6b833c29b1e0dfb1e2b99e5ca743da92aa5e04a0 [file]
load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test", "nodejs_binary", "npm_package_bin")
load("//packages/rollup:index.bzl", "rollup_bundle")
_BUNDLE_FORMATS = [
"amd",
"cjs",
"esm",
"iife",
"umd",
"system",
]
[
rollup_bundle(
name = "bundle.%s" % format,
srcs = [
"bar.js",
"some.json",
"//%s/foo:user.js" % package_name(),
],
config_file = "rollup.config.js",
entry_point = "foo.js",
format = format,
sourcemap = "true",
supports_workers = True,
deps = [
"//%s/fum:fumlib" % package_name(),
"//%s/foo:foo_lib" % package_name(),
"//%s/foo_a:foo_lib_a" % package_name(),
"//%s/foo_aaa:foo_lib_a_a_a" % package_name(),
"//%s/far/a/b/c" % package_name(),
"//%s/far/a" % package_name(),
"@npm//@rollup/plugin-commonjs",
"@npm//@rollup/plugin-json",
"@npm//@rollup/plugin-node-resolve",
"@npm//hello",
],
)
for format in _BUNDLE_FORMATS
]
# Verify the bundle .js files
[
generated_file_test(
name = "test_%s" % format,
src = "//%s:golden.%s.js_" % (
package_name(),
format,
),
generated = "bundle.%s.js" % format,
)
for format in _BUNDLE_FORMATS
]
nodejs_binary(
name = "sha256",
entry_point = ":sha256.js",
)
# Verify the hash of bundle .map files
[
npm_package_bin(
name = "bundle_%s_map_sha256" % format,
outs = ["bundle.%s.js.map.sha256" % format],
args = [
"$(execpath :bundle.%s.js.map)" % format,
"$(execpath :bundle.%s.js.map.sha256)" % format,
],
data = [
# ":bundle.*.js" included as a dep as Bazel requires it for
# the "$(execpath :bundle.*.js)" location expansion to work
":bundle.%s.js.map" % format,
# Also include ":bundle.*" as a dep so that the module mappings
# from the ":bundle.*" as propogated to ensure the linker
# handles these propogated mappings property
":bundle.%s" % format,
],
tool = ":sha256",
)
for format in _BUNDLE_FORMATS
]
[
generated_file_test(
name = "test_%s_map_sha256" % format,
src = ":golden.%s.js.map.sha256_" % format,
generated = "bundle.%s.js.map.sha256" % format,
# TODO: fix this test on Windows as sha256 differs
tags = ["fix-windows"],
)
for format in _BUNDLE_FORMATS
]
npm_package_bin(
name = "bundle_umd_sha256",
outs = ["bundle.umd.js.sha256"],
args = [
"$(execpath :bundle.umd.js)",
"$(execpath :bundle.umd.js.sha256)",
],
data = [
# ":bundle.umd.js" included as a dep as Bazel requires it for
# the "$(execpath :bundle.umd.js)" location expansion to work
":bundle.umd.js",
# Also include ":bundle.umd" as a dep so that the module mappings
# from the ":bundle.umd" as propogated to ensure the linker
# handles these propogated mappings property
":bundle.umd",
],
tool = ":sha256",
)
generated_file_test(
name = "test_umd_sha256",
src = ":golden.umd.js.sha256_",
generated = "bundle.umd.js.sha256",
# TODO: fix this test on Windows as sha256 differs
tags = ["fix-windows"],
)