Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aspect-build/rules_js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.3.2
Choose a base ref
...
head repository: aspect-build/rules_js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.3.3
Choose a head ref
  • 3 commits
  • 18 files changed
  • 3 contributors

Commits on Mar 24, 2025

  1. chore: mirror external releases (#2113)

    Co-authored-by: alexeagle <47395+alexeagle@users.noreply.github.com>
    github-actions[bot] and alexeagle authored Mar 24, 2025
    Copy the full SHA
    5f8c853 View commit details
  2. fix: quotes within js_image_layer regexes (#2145)

    jbedard authored Mar 24, 2025
    Copy the full SHA
    ba38f3a View commit details
  3. fix: js_image_layer files matching no layer (#2143)

    jbedard authored Mar 24, 2025
    Copy the full SHA
    df99ca1 View commit details
10 changes: 5 additions & 5 deletions docs/js_image_layer.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 26 additions & 13 deletions js/private/js_image_layer.bzl
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@ load("@aspect_bazel_lib//lib:tar.bzl", "tar_lib")
load("@bazel_skylib//lib:paths.bzl", "paths")

_DEFAULT_LAYER_GROUPS = {
"node": "\\/js\\/private\\/node-patches\\/|\\/bin\\/nodejs\\/",
"package_store_3p": "\\/\\.aspect_rules_js\\/(?!.*@0\\.0\\.0).*\\/node_modules",
"package_store_1p": "\\.aspect_rules_js\\/.*@0\\.0\\.0\\/node_modules",
"node_modules": "\\/node_modules\\/",
"node": "/js/private/node-patches/|/bin/nodejs/",
"package_store_3p": "/\\.aspect_rules_js/(?!.*@0\\.0\\.0).*/node_modules",
"package_store_1p": "\\.aspect_rules_js/.*@0\\.0\\.0/node_modules",
"node_modules": "/node_modules/",
"app": "", # empty means just match anything.
}

@@ -278,10 +278,10 @@ The default layer groups are as follows and always created.
```
{
"node": "\\/js\\/private\\/node-patches\\/|\\/bin\\/nodejs\\/",
"package_store_1p": "\\.aspect_rules_js\\/.*@0\\.0\\.0\\/node_modules",
"package_store_3p": "\\.aspect_rules_js\\/.*\\/node_modules",
"node_modules": "\\/node_modules\\/",
"node": "/js/private/node-patches/|/bin/nodejs/",
"package_store_1p": "\\.aspect_rules_js/.*@0\\.0\\.0/node_modules",
"package_store_3p": "\\.aspect_rules_js/.*/node_modules",
"node_modules": "/node_modules/",
"app": "", # empty means just match anything.
}
```
@@ -335,13 +335,14 @@ def _run_splitter(ctx, runfiles_dir, files, entries_json, layer_groups):
unused_inputs = ctx.actions.declare_file("{}_{}_unused_inputs.txt".format(ctx.label.name, name))
splitter_outputs.extend([mtree, unused_inputs])
VARIABLES += """
const {name}_re = new RegExp({});
const {name}mtree = new Set(["#mtree"]);
const {name}unusedinputs = createWriteStream("{}");
""".format(unused_inputs.path, name = name)
const {name}unusedinputs = createWriteStream({});
""".format(json.encode(match), json.encode(unused_inputs.path), name = name)

STMT = "else if" if PICK_STATEMENTS != "" else "if"

IF_STMT = "%s (/%s/.test(key))" % (STMT, match)
IF_STMT = "%s (%s_re.test(key))" % (STMT, name)

# Empty match means, match anything, same as .* but faster.
if match == "":
@@ -366,6 +367,18 @@ def _run_splitter(ctx, runfiles_dir, files, entries_json, layer_groups):

expected_layer_groups.append((name, mtree, unused_inputs))

# Final else {} to discard a file if it doesn't match any of the layer groups.
PICK_STATEMENTS += """
else {
%s
continue
}""" % (
"\n".join([
" %sunusedinputs.write(destBuf);" % oname
for oname in layer_groups.keys()
])
)

unused_inputs = ctx.actions.declare_file("{}_splitter_unused_inputs.txt".format(ctx.label.name))
splitter_outputs.append(unused_inputs)

@@ -380,7 +393,7 @@ def _run_splitter(ctx, runfiles_dir, files, entries_json, layer_groups):
"{{RUNFILES_DIR}}": runfiles_dir,
"{{REPO_NAME}}": ctx.workspace_name,
"{{ENTRIES}}": entries_json.path,
"{{PRESERVE_SYMLINKS}}": ctx.attr.preserve_symlinks,
"'{{PRESERVE_SYMLINKS}}'": json.encode(ctx.attr.preserve_symlinks),
"{{UNUSED_INPUTS}}": unused_inputs.path,
"/*{{VARIABLES}}*/": VARIABLES,
"/*{{PICK_STATEMENTS}}*/": PICK_STATEMENTS,
@@ -616,7 +629,7 @@ js_image_layer_lib = struct(
doc = """Preserve symlinks for entries matching the pattern.
By default symlinks within the `node_modules` is preserved.
""",
default = ".*\\/node_modules\\/.*",
default = ".*/node_modules/.*",
),
"layer_groups": attr.string_dict(
doc = """Layer groups to create.
4 changes: 3 additions & 1 deletion js/private/js_image_layer.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions js/private/test/image/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -72,3 +72,38 @@ assert_js_image_layer_listings(
name = "custom_owner_test",
js_image_layer = ":custom_owner",
)

# Case 3: Change owner
# bazel run :custom_owner_test_update_all
make_js_image_layer(
name = "regex_edge_cases",
binary = ":bin",
layer_groups = {
# Odd characters to insert into js string/regex/backtick expressions
"odd_characters": "spaces quotes ' \" ` slashes / \\ | symbols \\{",
},
platform = ":linux_amd64",
preserve_symlinks = "node_modules|/foobar/\"'",
root = "/app",
)

assert_js_image_layer_listings(
name = "regex_edge_cases_test",
additional_layers = ["odd_characters"],
js_image_layer = ":regex_edge_cases",
)

# Case 4: overwrite layer so some files have no matches
# bazel run :custom_owner_test_update_all
make_js_image_layer(
name = "custom_layers_nomatch",
binary = ":bin",
layer_groups = {"app": "no app for you"},
platform = ":linux_amd64",
root = "/app",
)

assert_js_image_layer_listings(
name = "custom_layers_nomatch_test",
js_image_layer = ":custom_layers_nomatch",
)
2 changes: 1 addition & 1 deletion js/private/test/image/asserts.bzl
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ def make_js_image_layer(name, layer_groups = {}, **kwargs):
**kwargs
)

for layer in layers + layer_groups.keys():
for layer in layers + [k for k in layer_groups.keys() if k not in layers]:
native.filegroup(
name = name + "_" + layer,
srcs = [name],
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/node-patches/
-r-xr-xr-x 0 0 0 32555 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/node-patches/fs.cjs
-r-xr-xr-x 0 0 0 1702 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/node-patches/register.cjs
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/bin/
-r-xr-xr-x 0 0 0 80316256 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/rules_nodejs~~node~nodejs_linux_amd64/bin/nodejs/bin/node
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/node_modules/
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/node_modules/acorn -> ../../../../../node_modules/.aspect_rules_js/acorn@8.7.1/node_modules/acorn
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/node_modules/uuid -> ../../../../../node_modules/.aspect_rules_js/uuid@8.3.2/node_modules/uuid
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/@mycorp/
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/@mycorp/pkg-d -> ../../../../../../node_modules/.aspect_rules_js/@mycorp+pkg-d@0.0.0/node_modules/@mycorp/pkg-d
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/js/private/test/image/node_modules/acorn -> ../../../../../node_modules/.aspect_rules_js/acorn@8.12.1/node_modules/acorn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-d@0.0.0/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-d@0.0.0/node_modules/
drwxr-xr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-d@0.0.0/node_modules/@mycorp/
lrwxrwxr-x 0 0 0 0 Jan 1 1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-d@0.0.0/node_modules/@mycorp/pkg-d -> ../../../../../examples/npm_package/packages/pkg_d
Loading