Skip to content

Commit 7316607

Browse files
authored
test: move examples into isolated bazel module (#2784)
This reduces the (dev)dependencies within the main rules_js MODULE, reduces the (dev/testing) code within the MODULE and some of the unit tests. In theory this could allow the removal of `examples/` from the production module. ### Changes are visible to end-users: no ### Test plan - Covered by existing test cases - New test cases added
1 parent 44a9f19 commit 7316607

72 files changed

Lines changed: 8689 additions & 10879 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,11 @@
22
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "@@//:pnpm-lock.yaml").
33
# This file should be checked into version control along with the pnpm-lock.yaml file.
44
.npmrc=1377619181
5-
examples/js_binary/package.json=-41174383
6-
examples/js_lib_pkg/a/package.json=1999786014
7-
examples/js_lib_pkg/b/package.json=697256916
8-
examples/linked_consumer/package.json=-1109186228
9-
examples/linked_empty_node_modules/package.json=-1039372825
10-
examples/linked_lib/package.json=-958830118
11-
examples/linked_pkg/package.json=1193916912
12-
examples/macro/package.json=857146175
13-
examples/nextjs/package.json=-1479189147
14-
examples/npm_deps/package.json=-2013173234
15-
examples/npm_deps/patches/[email protected]=-442666336
16-
examples/npm_package/libs/lib_a/package.json=-1377103079
17-
examples/npm_package/packages/pkg_a/package.json=1006424040
18-
examples/npm_package/packages/pkg_b/package.json=-1129449456
19-
examples/npm_package/packages/pkg_d/package.json=1146506398
20-
examples/npm_package/packages/pkg_e/package.json=2046864123
21-
examples/runfiles/package.json=-1545884645
22-
examples/stack_traces/package.json=2011229626
23-
examples/vite3/package.json=-1401988763
24-
examples/vite6/package.json=932513196
25-
examples/webpack_cli/package.json=1911342006
265
js/private/coverage/bundle/package.json=-1542925233
276
js/private/devserver/src/package.json=-787455596
28-
js/private/test/image/package.json=1430754959
7+
js/private/test/image-fixture-a/package.json=-845392695
8+
js/private/test/image-fixture-d/package.json=-1165671186
9+
js/private/test/image/package.json=-1116578579
2910
js/private/test/js_run_devserver/package.json=-781575922
3011
js/private/test/node-patches/package.json=-2062409266
3112
js/private/worker/src/package.json=1787033725
@@ -38,5 +19,5 @@ npm/private/test/vendored/is-odd/package.json=1041695223
3819
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349
3920
npm/private/test/vendored/semver-max/package.json=578664053
4021
package.json=1856600154
41-
pnpm-lock.yaml=-1083936682
42-
pnpm-workspace.yaml=2041973211
22+
pnpm-lock.yaml=-923227665
23+
pnpm-workspace.yaml=1041196754

.aspect/workflows/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ workspaces:
150150
# e2e/update_pnpm_lock_with_import:
151151
# e2e/webpack_devserver:
152152
# e2e/webpack_devserver_esm:
153+
examples:
154+
icon: js
155+
tasks: *e2e_tasks
153156
examples/protobuf/bufbuild-es:
154157
icon: proto
155158
tasks: *e2e_tasks

.bazelignore

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
# Nested modules
22
e2e/
3-
examples/protobuf
3+
examples/
44

55
# TODO(bazel 8): move to REPO.bazel
6-
examples/js_binary/node_modules/
7-
examples/js_lib_pkg/a/node_modules
8-
examples/js_lib_pkg/b/node_modules
9-
examples/linked_consumer/node_modules
10-
examples/linked_empty_node_modules/node_modules
11-
examples/linked_lib/node_modules
12-
examples/linked_pkg/node_modules
13-
examples/macro/node_modules/
14-
examples/nextjs/node_modules/
15-
examples/npm_deps/node_modules/
16-
examples/npm_package/libs/lib_a/node_modules/
17-
examples/npm_package/packages/pkg_a/node_modules/
18-
examples/npm_package/packages/pkg_b/node_modules/
19-
examples/npm_package/packages/pkg_c/node_modules/
20-
examples/npm_package/packages/pkg_d/node_modules/
21-
examples/npm_package/packages/pkg_e/node_modules/
22-
examples/runfiles/node_modules
23-
examples/stack_traces/node_modules
24-
examples/vite3/node_modules
25-
examples/vite6/node_modules
26-
examples/webpack_cli/node_modules/
276
js/private/coverage/bundle/node_modules
287
js/private/devserver/src/node_modules/
8+
js/private/test/image-fixture-a/node_modules
9+
js/private/test/image-fixture-d/node_modules
2910
js/private/test/image/node_modules
3011
js/private/test/js_run_devserver/node_modules
3112
js/private/test/node-patches/node_modules

BUILD.bazel

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
load("@acorn__8.4.0__links//:defs.bzl", npm_link_acorn = "npm_link_imported_package")
21
load("@bazel_lib//lib:diff_test.bzl", "diff_test")
32
load("@bazel_skylib//rules:build_test.bzl", "build_test")
43
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
54
load("@npm//:defs.bzl", "npm_link_all_packages", "npm_link_targets")
65
load("@pnpm__links//:defs.bzl", npm_link_pnpm = "npm_link_imported_package")
76
load("//js:defs.bzl", "js_library")
8-
load("//npm:defs.bzl", "npm_link_package")
97

108
# Link all packages from the /MODULE npm_translate_lock(name = "npm") and also packages from
119
# manual /MODULE npm_import rules to bazel-bin/node_modules as well as the package store
1210
# bazel-bin/node_modules/.aspect_rules_js since /pnpm-lock.yaml is the root of the pnpm workspace
1311
npm_link_all_packages(
1412
imported_links = [
15-
npm_link_acorn,
1613
npm_link_pnpm,
1714
],
1815
)
@@ -28,7 +25,6 @@ build_test(
2825
NODE_MODULES = npm_link_targets(
2926
package = package_name(),
3027
) + [
31-
"//:node_modules/acorn",
3228
"//:node_modules/pnpm",
3329
]
3430

@@ -61,25 +57,6 @@ diff_test(
6157
file2 = "query_npm_link_targets_node_modules",
6258
)
6359

64-
# Example of manually linking a first-party dependency. Its transitive npm dependencies
65-
# are picked up automatically via 'npm_package_store_infos' in the js_library targets that
66-
# the `npm_package` target depends on.
67-
npm_link_package(
68-
name = "node_modules/@mycorp/pkg-b",
69-
src = "//examples/npm_package/packages/pkg_b:pkg",
70-
)
71-
72-
# Manually linked pkg-c with additional use cases.
73-
npm_link_package(
74-
name = "node_modules/@mycorp/pkg-c1",
75-
src = "//examples/npm_package/packages/pkg_c:pkg_c1",
76-
)
77-
78-
npm_link_package(
79-
name = "node_modules/@mycorp/pkg-c2",
80-
src = "//examples/npm_package/packages/pkg_c:pkg_c2",
81-
)
82-
8360
buildifier(
8461
name = "buildifier",
8562
exclude_patterns = [

MODULE.bazel

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ node_dev.toolchain(
157157
node_version = "24.9.0",
158158
)
159159

160-
############################################
161-
# npm dependencies used by examples
162-
163160
npm = use_extension(
164161
"@aspect_rules_js//npm:extensions.bzl",
165162
"npm",
@@ -175,37 +172,16 @@ npm.npm_translate_lock(
175172
],
176173
},
177174
custom_postinstalls = {
178-
"@aspect-test/c": "echo moo > cow.txt",
179-
"@aspect-test/[email protected]": "echo mooo >> cow.txt",
180175
"pngjs": "chmod -R a+X *", # fixes malformed tarball content file permissions in this package after extraction (see https://github.com/aspect-build/rules_js/issues/1637 for more details)
181176
},
182177
data = [
183178
"//:package.json",
184179
"//:pnpm-workspace.yaml",
185-
"//examples/js_binary:package.json",
186-
"//examples/js_lib_pkg/a:package.json",
187-
"//examples/js_lib_pkg/b:package.json",
188-
"//examples/linked_consumer:package.json",
189-
"//examples/linked_empty_node_modules:package.json",
190-
"//examples/linked_lib:package.json",
191-
"//examples/linked_pkg:package.json",
192-
"//examples/macro:package.json",
193-
"//examples/nextjs:package.json",
194-
"//examples/npm_deps:package.json",
195-
"//examples/npm_deps/patches:[email protected]",
196-
"//examples/npm_package/libs/lib_a:package.json",
197-
"//examples/npm_package/packages/pkg_a:package.json",
198-
"//examples/npm_package/packages/pkg_b:package.json",
199-
"//examples/npm_package/packages/pkg_d:package.json",
200-
"//examples/npm_package/packages/pkg_e:package.json",
201-
"//examples/runfiles:package.json",
202-
"//examples/stack_traces:package.json",
203-
"//examples/vite3:package.json",
204-
"//examples/vite6:package.json",
205-
"//examples/webpack_cli:package.json",
206180
"//js/private/coverage/bundle:package.json",
207181
"//js/private/devserver/src:package.json",
208182
"//js/private/test/image:package.json",
183+
"//js/private/test/image-fixture-a:package.json",
184+
"//js/private/test/image-fixture-d:package.json",
209185
"//js/private/test/js_run_devserver:package.json",
210186
"//js/private/test/node-patches:package.json",
211187
"//js/private/worker/src:package.json",
@@ -263,28 +239,11 @@ npm.npm_translate_lock(
263239
npmrc = "//:.npmrc",
264240
package_visibility = {
265241
"unused": ["//npm/private/test:__subpackages__"],
266-
"@mycorp/pkg-a": [
267-
"//examples:__subpackages__",
268-
"//js/private/test/image:__subpackages__",
269-
],
270-
"@mycorp/pkg-d": [
271-
"//examples:__subpackages__",
272-
"//js/private/test/image:__subpackages__",
273-
],
274-
"@mycorp/pkg-e": ["//examples:__subpackages__"],
275242
},
276243
pnpm_lock = "//:pnpm-lock.yaml",
277-
public_hoist_packages = {
278-
# Instructs the linker to hoist the [email protected] npm package to `node_modules/ms` in the `examples/npm_deps` package.
279-
# Similar to adding `public-hoist-pattern[]=ms` in .npmrc but with control over which version to hoist and where
280-
# to hoist it. This hoisted package can be referenced by the label `//examples/npm_deps:node_modules/ms` same as
281-
# other direct dependencies in the `examples/npm_deps/package.json`.
282-
"[email protected]": ["examples/npm_deps"],
283-
},
284244
update_pnpm_lock = True,
285245
use_pnpm = "@pnpm10//:package/bin/pnpm.cjs",
286246
verify_node_modules_ignored = "//:.bazelignore",
287-
verify_patches = "//examples/npm_deps/patches:patches",
288247
)
289248
npm.npm_translate_lock(
290249
name = "npm-no_optional",
@@ -306,26 +265,8 @@ use_repo(
306265
"npm__es5-ext__0.10.64__links",
307266
"npm__fsevents__2.3.3__links",
308267
"npm__google-closure-compiler__20251111.0.0__links",
309-
"npm__next__15.2.6_1642820312__links",
310268
"npm__rollup__4.55.2",
311269
"npm__rollup__4.55.2__links",
312270
"npm__unused__0.2.2__links",
313271
"npm__webpack-bundle-analyzer__4.5.0_bufferutil_4.0.8",
314272
)
315-
316-
# As an example, manually import a package using explicit coordinates.
317-
# Just a demonstration of the syntax de-sugaring.
318-
npm.npm_import(
319-
name = "acorn__8.4.0",
320-
bins = {"acorn": "./bin/acorn"},
321-
integrity = "sha512-ULr0LDaEqQrMFGyQ3bhJkLsbtrQ8QibAseGZeaSUiT/6zb9IvIkomWHJIvgvwad+hinRAgsI51JcWk2yvwyL+w==",
322-
package = "acorn",
323-
# Root package where to link the package store
324-
root_package = "",
325-
version = "8.4.0",
326-
)
327-
use_repo(
328-
npm,
329-
"acorn__8.4.0",
330-
"acorn__8.4.0__links",
331-
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# @generated
2+
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "@@//:pnpm-lock.yaml").
3+
# This file should be checked into version control along with the pnpm-lock.yaml file.
4+
.npmrc=1377619181
5+
js_binary/package.json=-41174383
6+
js_lib_pkg/a/package.json=1999786014
7+
js_lib_pkg/b/package.json=697256916
8+
linked_consumer/package.json=-1109186228
9+
linked_empty_node_modules/package.json=-1039372825
10+
linked_lib/package.json=-958830118
11+
linked_pkg/package.json=1193916912
12+
macro/package.json=857146175
13+
nextjs/package.json=-1479189147
14+
npm_deps/package.json=-2013173234
15+
npm_deps/patches/[email protected]=-442666336
16+
npm_package/libs/lib_a/package.json=-1377103079
17+
npm_package/packages/pkg_a/package.json=1006424040
18+
npm_package/packages/pkg_b/package.json=-1129449456
19+
npm_package/packages/pkg_d/package.json=1146506398
20+
npm_package/packages/pkg_e/package.json=2046864123
21+
package.json=-2075121688
22+
pnpm-lock.yaml=-136872610
23+
pnpm-workspace.yaml=498711803
24+
runfiles/package.json=-1545884645
25+
stack_traces/package.json=2011229626
26+
vite3/package.json=-1401988763
27+
vite6/package.json=932513196
28+
webpack_cli/package.json=1911342006

examples/.bazelignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
protobuf
2+
3+
node_modules
4+
js_binary/node_modules
5+
js_lib_pkg/a/node_modules
6+
js_lib_pkg/b/node_modules
7+
linked_consumer/node_modules
8+
linked_empty_node_modules/node_modules
9+
linked_lib/node_modules
10+
linked_pkg/node_modules
11+
macro/node_modules
12+
nextjs/node_modules
13+
npm_deps/node_modules
14+
npm_package/libs/lib_a/node_modules
15+
npm_package/packages/pkg_a/node_modules
16+
npm_package/packages/pkg_b/node_modules
17+
npm_package/packages/pkg_c/node_modules
18+
npm_package/packages/pkg_d/node_modules
19+
npm_package/packages/pkg_e/node_modules
20+
runfiles/node_modules
21+
stack_traces/node_modules
22+
vite3/node_modules
23+
vite6/node_modules
24+
webpack_cli/node_modules

examples/.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import %workspace%/../tools/preset.bazelrc
2+
import %workspace%/../e2e/e2e.bazelrc

examples/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../.bazelversion

examples/.npmrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on
2+
# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what
3+
# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules)
4+
hoist=false
5+
6+
# Set a custom registry for a scope that is picked up by pnpm when resolving packages;
7+
# This affects the lockfile format and is here to cover this case.
8+
@types:registry=https://registry.yarnpkg.com
9+
10+
# The rules_js linker won't see this public-hoist-pattern[] since hoisting is _not_ encoded
11+
# in the pnpm lockfile. In pnpm it is a linking time consideration when laying out the node_modules
12+
# tree. In rules_js we currently have a `public_hoist_packages` attribute on `npm_translate_lock`
13+
# the emulates this behavior (see example in MODULE). In the future we'll add support to
14+
# parse the .npmrc file so these directives are used to direct hoisting in the rules_js linker as well.
15+
public-hoist-pattern[]=ms

0 commit comments

Comments
 (0)