Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ npm_package/packages/pkg_d/package.json=1146506398
npm_package/packages/pkg_e/package.json=2046864123
package.json=-2075121688
package_json_module/package.json=-1167380556
pnpm-lock.yaml=559561144
pnpm-lock.yaml=1115218092
pnpm-workspace.yaml=-1653994035
rspack/package.json=-34571256
runfiles/package.json=-1545884645
stack_traces/package.json=2011229626
vite3/package.json=-1401988763
Expand Down
1 change: 1 addition & 0 deletions examples/.bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ npm_package/packages/pkg_c/node_modules
npm_package/packages/pkg_d/node_modules
npm_package/packages/pkg_e/node_modules
package_json_module/node_modules
rspack/node_modules
runfiles/node_modules
stack_traces/node_modules
vite3/node_modules
Expand Down
1 change: 1 addition & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ npm.npm_translate_lock(
"//npm_package/packages/pkg_d:package.json",
"//npm_package/packages/pkg_e:package.json",
"//package_json_module:package.json",
"//rspack:package.json",
"//runfiles:package.json",
"//stack_traces:package.json",
"//vite3:package.json",
Expand Down
1,998 changes: 1,966 additions & 32 deletions examples/pnpm-lock.yaml

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions examples/rspack/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
load("@aspect_rules_js//js:defs.bzl", "js_binary", "js_image_layer", "js_library")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//rspack:@rspack/cli/package_json.bzl", "bin")

npm_link_all_packages()

# The Rspack config. It is natural to represent this as a js_library, because
# it is a JavaScript source file with dependencies.
js_library(
name = "rspack_config",
srcs = ["rspack.config.cjs"],
deps = [":node_modules/@rspack/cli"],
)

bin.rspack(
name = "rspack_build",
srcs = ["rspack_entry.js"],
outs = ["rspack/main.bundle.js"],
chdir = package_name(),
Comment thread
jbedard marked this conversation as resolved.
# The config should be provided via the data parameter so that it becomes
# part of the runfiles of the Rspack binary.
data = [":rspack_config"],
# Since :rspack_config is a dependency of the binary, we need to reference
# it here in fixed_args. The fixed_args param applies to the js_binary
# whereas args applies to js_run_binary.
fixed_args = [
"build",
"--config",
"$$RUNFILES_DIR/$(rlocationpath :rspack_config)",
],
use_execroot_entry_point = False,
Comment thread
jbedard marked this conversation as resolved.
)

js_binary(
name = "rspack_built_binary",
entry_point = "rspack/main.bundle.js",
)

# Make sure we can handle building for a different platform. Let's build an
# image for Linux and another for Mac OS, and at least one of these will
# involve a target platform different from the execution platform.
platform(
name = "linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

platform(
name = "macos",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

js_image_layer(
name = "rspack_image_linux",
binary = ":rspack_built_binary",
platform = ":linux",
)

js_image_layer(
name = "rspack_image_macos",
binary = ":rspack_built_binary",
platform = ":macos",
)

build_test(
name = "build_test",
targets = [
":rspack_image_linux",
":rspack_image_macos",
],
)
8 changes: 8 additions & 0 deletions examples/rspack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "rspack_example",
"private": true,
"devDependencies": {
"@rspack/cli": "1.7.11",
"@rspack/core": "1.7.11"
}
}
12 changes: 12 additions & 0 deletions examples/rspack/rspack.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { defineConfig } = require('@rspack/cli');
const path = require("path");

module.exports = defineConfig({
entry: {
main: './rspack_entry.js',
Comment thread
acozzette marked this conversation as resolved.
},
output: {
path: path.resolve(process.cwd(), 'rspack/'),
filename: '[name].bundle.js',
},
});
1 change: 1 addition & 0 deletions examples/rspack/rspack_entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('hello rspack');
21 changes: 16 additions & 5 deletions examples/vite3/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
# An example/repro of https://github.com/aspect-build/rules_js/issues/656
# using vite v3 and react

load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//vite3:vite/package_json.bzl", vite_bin = "bin")

npm_link_all_packages(name = "node_modules")

js_library(
name = "vite-config",
srcs = ["vite.config.js"],
deps = [
":node_modules/@vitejs/plugin-react",
":node_modules/vite",
],
)

vite_bin.vite(
name = "build",
srcs = [
"index.html",
"src/index.jsx",
"vite.config.js",
] + [
":node_modules/@vitejs/plugin-react",
":node_modules/react",
":node_modules/react-dom",
":node_modules/vite",
],
args = ["build"],
chdir = package_name(),
data = [":vite-config"],
fixed_args = [
"build",
"--config",
"$$RUNFILES_DIR/$(rlocationpath :vite-config)",
],
out_dirs = ["build"],
)

Expand Down
23 changes: 17 additions & 6 deletions examples/vite6/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
# An example/repro of https://github.com/aspect-build/rules_js/issues/656
# using vite v3 and react
# using vite v6 and react

load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//vite6:vite/package_json.bzl", vite_bin = "bin")

npm_link_all_packages(name = "node_modules")

js_library(
name = "vite-config",
srcs = ["vite.config.mjs"],
deps = [
":node_modules/@vitejs/plugin-react",
":node_modules/vite",
],
)

vite_bin.vite(
name = "build",
srcs = [
"index.html",
"src/index.jsx",
"vite.config.mjs",
] + [
":node_modules/@vitejs/plugin-react",
":node_modules/react",
":node_modules/react-dom",
":node_modules/vite",
],
args = ["build"],
chdir = package_name(),
data = [":vite-config"],
fixed_args = [
"build",
"--config",
"$$RUNFILES_DIR/$(rlocationpath :vite-config)",
],
out_dirs = ["build"],
)

Expand Down
26 changes: 15 additions & 11 deletions examples/webpack_cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,30 @@ js_library(
],
deps = [
":node_modules/@vanilla-extract/css",
":node_modules/mathjs",
],
)

js_library(
name = "webpack-config",
srcs = ["webpack.config.js"],
deps = [
":node_modules/@vanilla-extract/webpack-plugin",
":node_modules/css-loader",
":node_modules/mathjs",
":node_modules/mini-css-extract-plugin",
],
)

bin.webpack_cli(
name = "bundle",
srcs = [
":lib",
":webpack.config.js",
],
outs = [
"dist/main.js",
],
args = [
"--config webpack.config.js",
],
srcs = [":lib"],
outs = ["dist/main.js"],
chdir = package_name(),
data = [":webpack-config"],
fixed_args = [
"--config",
"$$RUNFILES_DIR/$(rlocationpath :webpack-config)",
],
log_level = "debug",
)

Expand Down
4 changes: 2 additions & 2 deletions examples/webpack_cli/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin')

const out_path = path.resolve(__dirname, 'dist')
const out_path = path.resolve(process.cwd(), 'dist')

module.exports = {
entry: path.join(__dirname, 'index.js'),
entry: path.join(process.cwd(), 'index.js'),
stats: 'verbose',
mode: 'development',
stats: 'detailed',
Expand Down
26 changes: 16 additions & 10 deletions js/private/coverage/bundle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//js/private/coverage/bundle:rollup/package_json.bzl", rollup_bin = "bin")
load("//js:defs.bzl", "js_library")

npm_link_all_packages()

js_library(
name = "config",
srcs = ["rollup.config.mjs"],
deps = [
":node_modules/@rollup/plugin-commonjs",
":node_modules/@rollup/plugin-json",
":node_modules/@rollup/plugin-node-resolve",
],
)

rollup_bin.rollup(
name = "bundle",
srcs = [
"c8.js",
"package.json",
"rollup.config.mjs",
":node_modules/@rollup/plugin-commonjs",
":node_modules/@rollup/plugin-json",
":node_modules/@rollup/plugin-node-resolve",
":node_modules/c8",
],
outs = [
"bundle.js",
],
args = [
outs = ["bundle.js"],
chdir = package_name(),
data = [":config"],
fixed_args = [
Comment thread
acozzette marked this conversation as resolved.
"c8.js",
"--config",
"rollup.config.mjs",
"$$RUNFILES_DIR/$(rlocationpath :config)",
"--format",
"cjs",
"--file",
"bundle.js",
],
chdir = package_name(),
visibility = ["//js/private/coverage:__pkg__"],
)
16 changes: 11 additions & 5 deletions js/private/devserver/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//js/private/devserver/src:rollup/package_json.bzl", rollup_bin = "bin")
load("//js:defs.bzl", "js_library")

npm_link_all_packages()

js_library(
name = "config",
srcs = ["rollup.config.mjs"],
deps = [":node_modules/@rollup/plugin-node-resolve"],
)

rollup_bin.rollup(
name = "js_run_devserver_bundle",
srcs = [
"js_run_devserver.mjs",
"rollup.config.mjs",
":node_modules/@rollup/plugin-node-resolve",
"//js/private/watch",
],
outs = ["bundle.mjs"],
args = [
chdir = package_name(),
data = [":config"],
fixed_args = [
"js_run_devserver.mjs",
"--config",
"rollup.config.mjs",
"$$RUNFILES_DIR/$(rlocationpath :config)",
"--format",
"es",
"--file",
"bundle.mjs",
],
chdir = package_name(),
visibility = ["//js/private/devserver:__pkg__"],
)
11 changes: 7 additions & 4 deletions js/private/test/node-patches/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ js_library(

babel_bin.babel(
name = "babel_mjs2js",
srcs = MJS_TESTS + [":babel_config"],
outs = [t.replace(".mjs", ".cjs") for t in MJS_TESTS],
args = [
srcs = MJS_TESTS,
outs = CJS_TESTS,
chdir = package_name(),
data = [":babel_config"],
fixed_args = [
"--config-file",
"$$RUNFILES_DIR/$(rlocationpath :babel_config)",
"--extensions",
".mjs",
"--out-file-extension",
".cjs",
"--out-dir",
".",
] + MJS_TESTS,
chdir = package_name(), # to automatically pickup babel.config.js
)

# Basic tests
Expand Down
Loading
Loading