Skip to content

[Bug]: js_image_layer puts both first-party and third-party code into same layer #1641

@matthewjh

Description

@matthewjh

What happened?

Hi. js_image_layer has a separation of "app" and "node_modules" layers. The problem is that when 1st-party libraries are used as linked node_modules via the npm_link rules or pnpm workspaces - probably very common for rules_js users - these 1st party libraries are included amongst all the 3rd party node_modules in the node_modules layer, meaning you have 1 layer containing most of the code (100-200mb) and that whole layer changing whenever one of the 1st party libraries changes even slightly.

See https://github.com/aspect-build/rules_js/blob/main/js/private/js_image_layer.bzl#L241

I ended up patching this to check for our "scope" prefix, so our first-party packages would go into the app layer instead of node_modules. However, under this issue it probably makes sense to revisit this bifurcation. Given that rules_js can distinguish between packages that originated in the workspace and externally (e.g. from npm), it would be perhaps nice to see a separate layer for everything "external" and "internal", which appears to better capture the intent of the "app" and "node_modules" layers to separate "infrequently changing" from "frequently changing".

Version

Development (host) and target OS/architectures:

Output of bazel --version:
7.1.1
Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:

Language(s) and/or frameworks involved:

http_archive(
    name = "aspect_rules_js",
    sha256 = "d7500d59712accca9622bce723b8ea596b92fb9b4ff4a4dbd77ed353b9d29f34",
    strip_prefix = "rules_js-1.40.1",
    url = "https://github.com/aspect-build/rules_js/releases/download/v1.40.1/rules_js-v1.40.1.tar.gz",
    patches = [
        "//tools/bazel-patches:aspect_rules_js-image-layer.patch",
    ],
    patch_args = ["-p1"],
)

How to reproduce

No response

Any other information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions