Skip to content

Commit

Permalink
feat: support 'npm:' style package.json aliased npm deps
Browse files Browse the repository at this point in the history
BREAKING CHANGES

See #171
  • Loading branch information
gregmagolan committed Jun 10, 2022
1 parent 3e86624 commit 0fc7846
Show file tree
Hide file tree
Showing 22 changed files with 1,388 additions and 1,062 deletions.
52 changes: 29 additions & 23 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
load("@acorn__8.4.0__links//:defs.bzl", npm_link_acorn = "npm_link_imported_package")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@acorn__8.4.0__links//:defs.bzl", npm_link_acorn = "npm_link_package")
load("//npm:defs.bzl", "npm_link_package", "npm_link_package_dep")
load("@pnpm__links//:defs.bzl", npm_link_pnpm = "npm_link_imported_package")
load("//npm:defs.bzl", "npm_link_package")

load("@pnpm__links//:defs.bzl", npm_link_pnpm = "npm_link_package")
npm_link_pnpm(name = "node_modules/pnpm")

# Link all packages from the /WORKSPACE npm_translate_lock in /package.json to
# bazel-bin/node_modules as well as the virtual store bazel-bin/node_modules/.aspect_rules_js
# since /package.json is the root of the pnpm workspace
npm_link_all_packages(name = "node_modules")

# Link the acorn package, which was fetched separately with npm_import from /WORKSPACE, to the
# virtual store in bazel-bin/node_modules/.aspect_rules_js and as a direct link to
# bazel-bin/node_modules/acorn
npm_link_acorn(name = "node_modules/acorn")
# Link all packages from the /WORKSPACE npm_translate_lock(name = "npm") and also packages from
# manual /WORKSPACE npm_import rules to bazel-bin/node_modules as well as the virtual store
# bazel-bin/node_modules/.aspect_rules_js since /pnpm-lock.yaml is the root of the pnpm workspace
npm_link_all_packages(
name = "node_modules",
imported_links = [
npm_link_acorn,
npm_link_pnpm,
],
)

# Linking a first-party dependency to the virtual store in bazel-bin/node_modules/.aspect_rules_js and
# as a direct link to bazel-bin/node_modules/@mycorp/mylib
npm_link_package(
name = "node_modules/@mycorp/mylib",
src = "//examples/lib",
deps = [
# For a 3rd party deps fetched with an npm_import or via a npm_translate_lock repository rule,
# you must specify both the name and version to qualify the dependency. These should match the
# `package` and `version` attributes of the corresponding `npm_import`.
npm_link_package_dep(
"acorn",
version = "8.4.0",
),
],
# We dep on the virtual store link targets which are layed out in the root package, typically
# the package where the pnpm-lock.yaml file is located.
deps = {
# Package store link targets names for 3rd party packages that come from
# npm_translate_package lock start with the name passed to npm_link_all_packages macro
# (typically 'node_modules') followed by `/<package>/store/<version>` where `package` is the
# package name (including @scope segment if any) and `version` is the specific version of
# the package that comes from the pnpm-lock.yaml file.
"//:node_modules/uuid/store/8.3.2": "",
# Package store link targets names for 3rd party package that come directly from an
# npm_import start with the name passed to the `npm_import`'s `npm_link_imported_package`
# macro (typically 'node_modules') followed by `/<package>/store/<version>` where `package`
# matches the `package` attribute in the npm_import of the package and `version` matches the
# `version` attribute.
"//:node_modules/acorn/store/8.4.0": "",
},
)

gazelle_binary(
Expand Down
25 changes: 22 additions & 3 deletions docs/npm_import.md

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

Loading

0 comments on commit 0fc7846

Please sign in to comment.