Skip to content

[Bug]: Dependency aliases of transitive dependencies are not working #1062

@devversion

Description

@devversion

What happened?

Consider you are using a project that has a direct dependency on A. Where A then has a dependency on B, but the package is aliased to e.g. alias. e.g.

  registry.npmjs.org/@isaacs/cliui/8.0.2:
    name: '@isaacs/cliui'
    version: 8.0.2
    dependencies:
      string-width-cjs: registry.npmjs.org/string-width/4.2.3

rules_js will properly configure the store target for cliui to look for string-width-cjs as a store dependency. But the store target with the aliased name does actually not exist.

This causes errors like:

ERROR: /usr/local/google/home/pgschwendtner/projects/material.angular.io/BUILD.bazel:9:22: in deps attribute
of npm_package_store_internal rule
//:.aspect_rules_js/node_modules/@[email protected]+@isaacs+cliui+8.0.2/pkg: \
target '//:.aspect_rules_js/node_modules/[email protected]+string-width+4.2.3/ref' does
not exist. Since this rule was created by the macro 'npm_link_all_packages', the error might have been caused by the macro implementation

Version

Linux amd64. Rules_JS rules_js-1.20.1. Bazel 5.1.0. A team member also tried with the latest version.

How to reproduce

No response

Any other information?

Looking into it without diving too much into implementation, the issue seems to be that pnpm_lock_file.packages() is used to create the store entries. But this never holds the aliased package names. i.e. rules_js iterates through the packages: entry in the lock file and then creates store entries for those.

There will never be an entry with the alias though because the alias name will only ever appear in the dependencies section of an entry. The transitive closure detection already has access to this information.

Likely we could use that to compile a more precise list of packages that will then be used
to create the links.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneed: fundingWe could prioritize this based on donation to https://opencollective.com/aspect-build

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions