diff --git a/.aspect/workflows/config.yaml b/.aspect/workflows/config.yaml index 48019bfe9..e756771af 100644 --- a/.aspect/workflows/config.yaml +++ b/.aspect/workflows/config.yaml @@ -88,6 +88,19 @@ workspaces: without: true - delivery: without: true + e2e/npm_translate_lock_replace_packages: + icon: npm + tasks: + - test: + queue: aspect-medium + - format: + without: true + - buildifier: + without: true + - configure: + without: true + - delivery: + without: true e2e/npm_translate_lock_empty: icon: npm tasks: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3429a7986..0e91b5382 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -138,8 +138,14 @@ jobs: - os: windows # Exclude MacOS by default, will opt-in to includes - os: macos + # Don't run bzlmod smoke test under workspace - bzlmod: 0 folder: e2e/bzlmod + # Don't run replace_packages test with bzlmod+Bazel 6 due to use of Bazel 7 bzlmod features + - bazel-version: + major: 6 + - bzlmod: 1 + folder: e2e/npm_translate_lock_replace_packages # Don't run RBE tests with Bazel 6 to reduce the size of the test matrix - bazel-version: major: 6 diff --git a/MODULE.bazel b/MODULE.bazel index 80965c394..8f197ffa4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -206,9 +206,6 @@ npm.npm_translate_lock( # other direct dependencies in the `examples/npm_deps/package.json`. "ms@2.1.3": ["examples/npm_deps"], }, - replace_packages = { - "chalk@5.0.1": "@chalk_501//:pkg", - }, update_pnpm_lock = True, verify_node_modules_ignored = "//:.bazelignore", verify_patches = "//examples/npm_deps/patches:patches", @@ -216,7 +213,6 @@ npm.npm_translate_lock( use_repo( npm, "npm", - "npm__chalk__5.0.1__links", "npm__fsevents__2.3.2__links", "npm__rollup__2.70.2", "npm__rollup__2.70.2__links", diff --git a/WORKSPACE b/WORKSPACE index 080fee379..7323ab697 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -159,9 +159,6 @@ npm_translate_lock( # other direct dependencies in the `examples/npm_deps/package.json`. "ms@2.1.3": ["examples/npm_deps"], }, - replace_packages = { - "chalk@5.0.1": "@chalk_501//:pkg", - }, update_pnpm_lock = True, verify_node_modules_ignored = "//:.bazelignore", verify_patches = "//examples/npm_deps/patches:patches", diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index 1472fbe55..7f3aa2280 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -9,13 +9,6 @@ fetch_shfmt() # dev dependency load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -http_archive( - name = "chalk_501", - build_file = "//npm/private/test:vendored/chalk-5.0.1.BUILD", - integrity = "sha256-/nD5GSp77HDNFDwIL68S5PbS+8gefWkube2iIr80/x4=", - url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", -) - http_archive( name = "com_grail_bazel_toolchain", sha256 = "a9fc7cf01d0ea0a935bd9e3674dd3103766db77dfc6aafcb447a7ddd6ca24a78", diff --git a/e2e/npm_translate_lock_replace_packages/.bazelignore b/e2e/npm_translate_lock_replace_packages/.bazelignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/.bazelignore @@ -0,0 +1 @@ +node_modules diff --git a/e2e/npm_translate_lock_replace_packages/.bazelrc b/e2e/npm_translate_lock_replace_packages/.bazelrc new file mode 100644 index 000000000..413c99502 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/.bazelrc @@ -0,0 +1,15 @@ +# Import Aspect bazelrc presets +try-import %workspace%/../../.aspect/bazelrc/bazel7.bazelrc +import %workspace%/../../.aspect/bazelrc/convenience.bazelrc +import %workspace%/../../.aspect/bazelrc/correctness.bazelrc +import %workspace%/../../.aspect/bazelrc/debug.bazelrc +import %workspace%/../../.aspect/bazelrc/javascript.bazelrc +import %workspace%/../../.aspect/bazelrc/performance.bazelrc + +### YOUR PROJECT SPECIFIC OPTIONS GO HERE ### + +# Load any settings & overrides specific to the current user from `.aspect/bazelrc/user.bazelrc`. +# This file should appear in `.gitignore` so that settings are not shared with team members. This +# should be last statement in this config so the user configuration is able to overwrite flags from +# this file. See https://bazel.build/configure/best-practices#bazelrc-file. +try-import %workspace%/../../.aspect/bazelrc/user.bazelrc diff --git a/e2e/npm_translate_lock_replace_packages/.bazelversion b/e2e/npm_translate_lock_replace_packages/.bazelversion new file mode 120000 index 000000000..96cf94962 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/.bazelversion @@ -0,0 +1 @@ +../../.bazelversion \ No newline at end of file diff --git a/e2e/npm_translate_lock_replace_packages/.npmrc b/e2e/npm_translate_lock_replace_packages/.npmrc new file mode 100644 index 000000000..5de6efae1 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/.npmrc @@ -0,0 +1,4 @@ +# Disabling pnpm [hoisting](https://pnpm.io/npmrc#hoist) by setting `hoist=false` is recommended on +# projects using rules_js so that pnpm outside of Bazel lays out a node_modules tree similar to what +# rules_js lays out under Bazel (without a hidden node_modules/.pnpm/node_modules) +hoist=false diff --git a/e2e/npm_translate_lock_replace_packages/BUILD.bazel b/e2e/npm_translate_lock_replace_packages/BUILD.bazel new file mode 100644 index 000000000..16e39531a --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/BUILD.bazel @@ -0,0 +1,68 @@ +load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") +load("@aspect_rules_js//js:defs.bzl", "js_test") +load("@aspect_rules_js//npm:defs.bzl", "npm_package") +load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@npm//:defs.bzl", "npm_link_all_packages") + +npm_link_all_packages(name = "node_modules") + +js_test( + name = "test", + data = [ + "package.json", + ":node_modules", + ], + entry_point = "main.js", +) + +npm_package( + name = "npm-pkg", + srcs = [ + "main.js", + "package.json", + ], +) + +build_test( + name = "node_modules_test", + targets = [ + ":node_modules", + ":npm-pkg", + ], +) + +# Strip the system-dependent 'system_tar' attribute from the generated repositories.bzl +genrule( + name = "npm_translate_lock_wksp-repositories", + srcs = ["@npm//:repositories.bzl"], + outs = ["wksp_repos_stripped.bzl"], + cmd = 'sed "s/system_tar = .*,/system_tar = \\"xxx\\",/" "$<" > "$@"', + target_compatible_with = select({ + "@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"], + "//conditions:default": [], + }), +) + +write_source_files( + name = "write_npm_translate_lock_wksp", + files = { + "snapshots/wksp/npm_defs.bzl": "@npm//:defs.bzl", + "snapshots/wksp/repositories.bzl": ":npm_translate_lock_wksp-repositories", + }, + target_compatible_with = select({ + "@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"], + "//conditions:default": [], + }), +) + +write_source_files( + name = "write_npm_translate_lock_bzlmod", + files = { + # NOTE: @npm//:repositories.bzl not generated for bzlmod + "snapshots/bzlmod/npm_defs.bzl": "@npm//:defs.bzl", + }, + target_compatible_with = select({ + "@aspect_bazel_lib//lib:bzlmod": [], + "//conditions:default": ["@platforms//:incompatible"], + }), +) diff --git a/e2e/npm_translate_lock_replace_packages/MODULE.bazel b/e2e/npm_translate_lock_replace_packages/MODULE.bazel new file mode 100644 index 000000000..63186ce21 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/MODULE.bazel @@ -0,0 +1,42 @@ +module( + name = "e2e_npm_translate_lock_replace_packages", + version = "0.0.0", + compatibility_level = 1, +) + +bazel_dep(name = "platforms", version = "0.0.5") +bazel_dep(name = "aspect_rules_js", version = "0.0.0") +bazel_dep(name = "aspect_bazel_lib", version = "2.7.7") +bazel_dep(name = "bazel_skylib", version = "1.5.0") + +local_path_override( + module_name = "aspect_rules_js", + path = "../..", +) + +npm = use_extension( + "@aspect_rules_js//npm:extensions.bzl", + "npm", + dev_dependency = True, +) +npm.npm_translate_lock( + name = "npm", + npmrc = "//:.npmrc", + pnpm_lock = "//:pnpm-lock.yaml", + replace_packages = { + "chalk@5.3.0": "@chalk_501//:pkg", + }, + verify_node_modules_ignored = "//:.bazelignore", +) + +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "chalk_501", + build_file = "//:chalk-5.0.1.BUILD", + dev_dependency = True, + integrity = "sha256-/nD5GSp77HDNFDwIL68S5PbS+8gefWkube2iIr80/x4=", + url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", +) + +use_repo(npm, "npm") diff --git a/e2e/npm_translate_lock_replace_packages/WORKSPACE b/e2e/npm_translate_lock_replace_packages/WORKSPACE new file mode 100644 index 000000000..2010dab6a --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/WORKSPACE @@ -0,0 +1,37 @@ +local_repository( + name = "aspect_rules_js", + path = "../..", +) + +load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +rules_js_dependencies() + +load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains") + +rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION) + +load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock") + +npm_translate_lock( + name = "npm", + data = ["//:package.json"], + npmrc = "//:.npmrc", + pnpm_lock = "//:pnpm-lock.yaml", + replace_packages = { + "chalk@5.3.0": "@chalk_501//:pkg", + }, + verify_node_modules_ignored = "//:.bazelignore", +) + +load("@npm//:repositories.bzl", "npm_repositories") + +npm_repositories() + +http_archive( + name = "chalk_501", + build_file = "//:chalk-5.0.1.BUILD", + integrity = "sha256-/nD5GSp77HDNFDwIL68S5PbS+8gefWkube2iIr80/x4=", + url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", +) diff --git a/e2e/npm_translate_lock_replace_packages/WORKSPACE.bzlmod b/e2e/npm_translate_lock_replace_packages/WORKSPACE.bzlmod new file mode 100644 index 000000000..3a956c2b7 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/WORKSPACE.bzlmod @@ -0,0 +1,2 @@ +# The presence of this file causes WORKSPACE to be ignored when bzlmod is enabled. +# See https://docs.google.com/document/d/1JtXIVnXyFZ4bmbiBCr5gsTH4-opZAFf5DMMb-54kES0/edit#heading=h.y054fjub9max diff --git a/npm/private/test/vendored/chalk-5.0.1.BUILD b/e2e/npm_translate_lock_replace_packages/chalk-5.0.1.BUILD similarity index 100% rename from npm/private/test/vendored/chalk-5.0.1.BUILD rename to e2e/npm_translate_lock_replace_packages/chalk-5.0.1.BUILD diff --git a/e2e/npm_translate_lock_replace_packages/main.js b/e2e/npm_translate_lock_replace_packages/main.js new file mode 100644 index 000000000..aaf81a778 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/main.js @@ -0,0 +1,21 @@ +import chalk from 'chalk' +import { readFileSync } from 'fs' + +const packageJsonDep = JSON.parse(readFileSync('./package.json', 'utf-8')) + .dependencies['chalk'] +if (packageJsonDep !== '5.3.0') { + throw new Error( + `Expected chalk version 5.3.0 declared in package.json, but got ${pkgDep}` + ) +} + +const actualDep = JSON.parse( + readFileSync('./node_modules/chalk/package.json', 'utf-8') +).version +if (actualDep !== '5.0.1') { + throw new Error( + `Expected chalk to be replaced with version 5.0.1, but got ${actualDep}` + ) +} + +console.log(chalk.blue(`Hello world! The meaning of life is... 42`)) diff --git a/e2e/npm_translate_lock_replace_packages/package.json b/e2e/npm_translate_lock_replace_packages/package.json new file mode 100644 index 000000000..1d87a0686 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/package.json @@ -0,0 +1,10 @@ +{ + "private": true, + "type": "module", + "dependencies": { + "chalk": "5.3.0" + }, + "pnpm": { + "onlyBuiltDependencies": [] + } +} diff --git a/e2e/npm_translate_lock_replace_packages/pnpm-lock.yaml b/e2e/npm_translate_lock_replace_packages/pnpm-lock.yaml new file mode 100644 index 000000000..41f2569d3 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/pnpm-lock.yaml @@ -0,0 +1,23 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + chalk: + specifier: 5.3.0 + version: 5.3.0 + +packages: + + chalk@5.3.0: + resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} + engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + +snapshots: + + chalk@5.3.0: {} diff --git a/e2e/npm_translate_lock_replace_packages/pnpm-workspace.yaml b/e2e/npm_translate_lock_replace_packages/pnpm-workspace.yaml new file mode 100644 index 000000000..2cce0eb74 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - '.' diff --git a/e2e/npm_translate_lock_replace_packages/snapshots/bzlmod/chalk_links_defs.bzl b/e2e/npm_translate_lock_replace_packages/snapshots/bzlmod/chalk_links_defs.bzl new file mode 100644 index 000000000..e69de29bb diff --git a/e2e/npm_translate_lock_replace_packages/snapshots/bzlmod/npm_defs.bzl b/e2e/npm_translate_lock_replace_packages/snapshots/bzlmod/npm_defs.bzl new file mode 100644 index 000000000..dd73a64de --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/snapshots/bzlmod/npm_defs.bzl @@ -0,0 +1,62 @@ +"""@generated by npm_translate_lock(name = "npm", pnpm_lock = "@@//:pnpm-lock.yaml")""" + +load("@@aspect_rules_js~~npm~npm__chalk__5.3.0__links//:defs.bzl", link_0 = "npm_link_imported_package_store", store_0 = "npm_imported_package_store") + +# buildifier: disable=bzl-visibility +load("@aspect_rules_js//js:defs.bzl", _js_library = "js_library") + +_LINK_PACKAGES = [""] + +# buildifier: disable=function-docstring +def npm_link_all_packages(name = "node_modules", imported_links = []): + bazel_package = native.package_name() + root_package = "" + is_root = bazel_package == root_package + link = bazel_package in _LINK_PACKAGES + if not is_root and not link: + msg = "The npm_link_all_packages() macro loaded from @aspect_rules_js~~npm~npm//:defs.bzl and called in bazel package '%s' may only be called in bazel packages that correspond to the pnpm root package or pnpm workspace projects. Projects are discovered from the pnpm-lock.yaml and may be missing if the lockfile is out of date. Root package: '', pnpm workspace projects: %s" % (bazel_package, "'" + "', '".join(_LINK_PACKAGES) + "'") + fail(msg) + link_targets = [] + scope_targets = {} + + for link_fn in imported_links: + new_link_targets, new_scope_targets = link_fn(name) + link_targets.extend(new_link_targets) + for _scope, _targets in new_scope_targets.items(): + if _scope not in scope_targets: + scope_targets[_scope] = [] + scope_targets[_scope].extend(_targets) + + if is_root: + store_0(name = "{}/chalk".format(name)) + if link: + if bazel_package == "": + link_0(name = "{}/chalk".format(name)) + link_targets.append("//{}:{}/chalk".format(bazel_package, name)) + + for scope, scoped_targets in scope_targets.items(): + _js_library( + name = "{}/{}".format(name, scope), + srcs = scoped_targets, + tags = ["manual"], + visibility = ["//visibility:public"], + ) + + _js_library( + name = name, + srcs = link_targets, + tags = ["manual"], + visibility = ["//visibility:public"], + ) + +# buildifier: disable=function-docstring +def npm_link_targets(name = "node_modules", package = None): + bazel_package = package if package != None else native.package_name() + link = bazel_package in _LINK_PACKAGES + + link_targets = [] + + if link: + if bazel_package == "": + link_targets.append("//{}:{}/chalk".format(bazel_package, name)) + return link_targets diff --git a/e2e/npm_translate_lock_replace_packages/snapshots/wksp/chalk_links_defs.bzl b/e2e/npm_translate_lock_replace_packages/snapshots/wksp/chalk_links_defs.bzl new file mode 100644 index 000000000..e69de29bb diff --git a/e2e/npm_translate_lock_replace_packages/snapshots/wksp/npm_defs.bzl b/e2e/npm_translate_lock_replace_packages/snapshots/wksp/npm_defs.bzl new file mode 100644 index 000000000..4b3419ee9 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/snapshots/wksp/npm_defs.bzl @@ -0,0 +1,62 @@ +"""@generated by npm_translate_lock(name = "npm", pnpm_lock = "@//:pnpm-lock.yaml")""" + +load("@@npm__chalk__5.3.0__links//:defs.bzl", link_0 = "npm_link_imported_package_store", store_0 = "npm_imported_package_store") + +# buildifier: disable=bzl-visibility +load("@aspect_rules_js//js:defs.bzl", _js_library = "js_library") + +_LINK_PACKAGES = [""] + +# buildifier: disable=function-docstring +def npm_link_all_packages(name = "node_modules", imported_links = []): + bazel_package = native.package_name() + root_package = "" + is_root = bazel_package == root_package + link = bazel_package in _LINK_PACKAGES + if not is_root and not link: + msg = "The npm_link_all_packages() macro loaded from @npm//:defs.bzl and called in bazel package '%s' may only be called in bazel packages that correspond to the pnpm root package or pnpm workspace projects. Projects are discovered from the pnpm-lock.yaml and may be missing if the lockfile is out of date. Root package: '', pnpm workspace projects: %s" % (bazel_package, "'" + "', '".join(_LINK_PACKAGES) + "'") + fail(msg) + link_targets = [] + scope_targets = {} + + for link_fn in imported_links: + new_link_targets, new_scope_targets = link_fn(name) + link_targets.extend(new_link_targets) + for _scope, _targets in new_scope_targets.items(): + if _scope not in scope_targets: + scope_targets[_scope] = [] + scope_targets[_scope].extend(_targets) + + if is_root: + store_0(name = "{}/chalk".format(name)) + if link: + if bazel_package == "": + link_0(name = "{}/chalk".format(name)) + link_targets.append("//{}:{}/chalk".format(bazel_package, name)) + + for scope, scoped_targets in scope_targets.items(): + _js_library( + name = "{}/{}".format(name, scope), + srcs = scoped_targets, + tags = ["manual"], + visibility = ["//visibility:public"], + ) + + _js_library( + name = name, + srcs = link_targets, + tags = ["manual"], + visibility = ["//visibility:public"], + ) + +# buildifier: disable=function-docstring +def npm_link_targets(name = "node_modules", package = None): + bazel_package = package if package != None else native.package_name() + link = bazel_package in _LINK_PACKAGES + + link_targets = [] + + if link: + if bazel_package == "": + link_targets.append("//{}:{}/chalk".format(bazel_package, name)) + return link_targets diff --git a/e2e/npm_translate_lock_replace_packages/snapshots/wksp/repositories.bzl b/e2e/npm_translate_lock_replace_packages/snapshots/wksp/repositories.bzl new file mode 100644 index 000000000..418693433 --- /dev/null +++ b/e2e/npm_translate_lock_replace_packages/snapshots/wksp/repositories.bzl @@ -0,0 +1,25 @@ +"""@generated by npm_translate_lock(name = "npm", pnpm_lock = "@//:pnpm-lock.yaml")""" + +load("@aspect_rules_js//npm:repositories.bzl", "npm_import") + +# Generated npm_import repository rules corresponding to npm packages in @//:pnpm-lock.yaml +# buildifier: disable=function-docstring +def npm_repositories(): + npm_import( + name = "npm__chalk__5.3.0", + root_package = "", + link_workspace = "", + link_packages = { + "": ["chalk"], + }, + package = "chalk", + version = "5.3.0", + url = "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + system_tar = "xxx", + package_visibility = ["//visibility:public"], + integrity = "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + transitive_closure = { + "chalk": ["5.3.0"], + }, + replace_package = "@chalk_501//:pkg", + ) diff --git a/js/private/dev_deps.bzl b/js/private/dev_deps.bzl index b280908bb..93b1bcc3b 100644 --- a/js/private/dev_deps.bzl +++ b/js/private/dev_deps.bzl @@ -53,13 +53,6 @@ def rules_js_dev_dependencies(): url = "https://github.com/aspect-build/rules_lint/releases/download/v0.7.0/rules_lint-v0.7.0.tar.gz", ) - http_archive( - name = "chalk_501", - integrity = "sha256-/nD5GSp77HDNFDwIL68S5PbS+8gefWkube2iIr80/x4=", - url = "https://registry.npmjs.org/chalk/-/chalk-5.0.1.tgz", - build_file = "//npm/private/test:vendored/chalk-5.0.1.BUILD", - ) - http_archive( name = "com_grail_bazel_toolchain", sha256 = "a9fc7cf01d0ea0a935bd9e3674dd3103766db77dfc6aafcb447a7ddd6ca24a78", diff --git a/npm/private/test/BUILD.bazel b/npm/private/test/BUILD.bazel index 52ea4cb48..05ac282e7 100644 --- a/npm/private/test/BUILD.bazel +++ b/npm/private/test/BUILD.bazel @@ -45,7 +45,6 @@ write_source_files( files = { "snapshots/wksp/npm_defs.bzl": "@npm//:defs.bzl", "snapshots/wksp/repositories.bzl": ":npm_translate_lock_wksp-repositories", - "snapshots/wksp/chalk_links_defs.bzl": "@npm__chalk__5.0.1__links//:defs.bzl", "snapshots/wksp/unused_links_defs.bzl": "@npm__unused__0.2.2__links//:defs.bzl", "snapshots/wksp/fsevents_links_defs.bzl": "@npm__fsevents__2.3.2__links//:defs.bzl", "snapshots/wksp/rollup_links_defs.bzl": "@npm__rollup__2.70.2__links//:defs.bzl", @@ -63,7 +62,6 @@ write_source_files( files = { # NOTE: @npm//:repositories.bzl not generated for bzlmod "snapshots/bzlmod/npm_defs.bzl": "@npm//:defs.bzl", - "snapshots/bzlmod/chalk_links_defs.bzl": "@npm__chalk__5.0.1__links//:defs.bzl", "snapshots/bzlmod/unused_links_defs.bzl": "@npm__unused__0.2.2__links//:defs.bzl", "snapshots/bzlmod/fsevents_links_defs.bzl": "@npm__fsevents__2.3.2__links//:defs.bzl", "snapshots/bzlmod/rollup_links_defs.bzl": "@npm__rollup__2.70.2__links//:defs.bzl", diff --git a/npm/private/test/snapshots/bzlmod/chalk_links_defs.bzl b/npm/private/test/snapshots/bzlmod/chalk_links_defs.bzl deleted file mode 100644 index 13f85f3eb..000000000 --- a/npm/private/test/snapshots/bzlmod/chalk_links_defs.bzl +++ /dev/null @@ -1,165 +0,0 @@ -"@generated by @aspect_rules_js//npm/private:npm_import.bzl for npm package chalk@5.0.1" - -# buildifier: disable=bzl-visibility -load("@aspect_rules_js//npm/private:npm_package_store_internal.bzl", _npm_package_store = "npm_package_store_internal") - -# buildifier: disable=bzl-visibility -load("@aspect_rules_js//npm/private:npm_link_package_store.bzl", _npm_link_package_store = "npm_link_package_store") - -# Generated npm_package_store targets for npm package chalk@5.0.1 -# buildifier: disable=function-docstring -def npm_imported_package_store(name): - bazel_package = native.package_name() - root_package = "" - is_root = bazel_package == root_package - if not is_root: - msg = "No store links in bazel package '%s' for npm package npm package chalk@5.0.1. This is neither the root package nor a link package of this package." % bazel_package - fail(msg) - if not name.endswith("/chalk"): - msg = "name must end with one of '/chalk' when linking the store in package 'chalk'; recommended value is 'node_modules/chalk'" - fail(msg) - link_root_name = name[:-len("/chalk")] - - deps = { - ":.aspect_rules_js/{}/chalk@5.0.1/pkg".format(link_root_name): "chalk", - } - ref_deps = {} - - store_target_name = ".aspect_rules_js/{}/chalk@5.0.1".format(link_root_name) - - # reference target used to avoid circular deps - _npm_package_store( - name = "{}/ref".format(store_target_name), - package = "chalk", - version = "5.0.1", - dev = False, - tags = ["manual"], - ) - - # post-lifecycle target with reference deps for use in terminal target with transitive closure - _npm_package_store( - name = "{}/pkg".format(store_target_name), - src = "{}/pkg_lc".format(store_target_name) if False else "@chalk_501//:pkg", - package = "chalk", - version = "5.0.1", - dev = False, - deps = ref_deps, - tags = ["manual"], - ) - - # package store target with transitive closure of all npm package dependencies - _npm_package_store( - name = store_target_name, - src = None if True else "@chalk_501//:pkg", - package = "chalk", - version = "5.0.1", - dev = False, - deps = deps, - visibility = ["//visibility:public"], - tags = ["manual"], - ) - - # filegroup target that provides a single file which is - # package directory for use in $(execpath) and $(rootpath) - native.filegroup( - name = "{}/dir".format(store_target_name), - srcs = [":{}".format(store_target_name)], - output_group = "package_directory", - visibility = ["//visibility:public"], - tags = ["manual"], - ) - -# Generated npm_package_store and npm_link_package_store targets for npm package chalk@5.0.1 -# buildifier: disable=function-docstring -def npm_link_imported_package_store(name): - bazel_package = native.package_name() - link_packages = { - "examples/npm_package/libs/lib_a": ["chalk"], - "npm/private/test/npm_package": ["chalk"], - } - if bazel_package in link_packages: - link_aliases = link_packages[bazel_package] - else: - link_aliases = ["chalk"] - - link_alias = None - for _link_alias in link_aliases: - if name.endswith("/{}".format(_link_alias)): - # longest match wins - if not link_alias or len(_link_alias) > len(link_alias): - link_alias = _link_alias - if not link_alias: - msg = "name must end with one of '/{{ {link_aliases_comma_separated} }}' when called from package 'chalk'; recommended value(s) are 'node_modules/{{ {link_aliases_comma_separated} }}'".format(link_aliases_comma_separated = ", ".join(link_aliases)) - fail(msg) - - link_root_name = name[:-len("/{}".format(link_alias))] - store_target_name = ".aspect_rules_js/{}/chalk@5.0.1".format(link_root_name) - - # terminal package store target to link - _npm_link_package_store( - name = name, - package = link_alias, - src = "//:{}".format(store_target_name), - visibility = ["//visibility:public"], - tags = ["manual"], - ) - - # filegroup target that provides a single file which is - # package directory for use in $(execpath) and $(rootpath) - native.filegroup( - name = "{}/dir".format(name), - srcs = [":{}".format(name)], - output_group = "package_directory", - visibility = ["//visibility:public"], - tags = ["manual"], - ) - - return [":{}".format(name)] if True else [] - -# Generated npm_package_store and npm_link_package_store targets for npm package chalk@5.0.1 -# buildifier: disable=function-docstring -def npm_link_imported_package( - name = "node_modules", - link = None, - fail_if_no_link = True): - bazel_package = native.package_name() - root_package = "" - link_packages = { - "examples/npm_package/libs/lib_a": ["chalk"], - "npm/private/test/npm_package": ["chalk"], - } - - if link_packages and link != None: - fail("link attribute cannot be specified when link_packages are set") - - is_link = (link == True) or (link == None and bazel_package in link_packages) - is_root = bazel_package == root_package - - if fail_if_no_link and not is_root and not link: - msg = "Nothing to link in bazel package '%s' for npm package npm package chalk@5.0.1. This is neither the root package nor a link package of this package." % bazel_package - fail(msg) - - link_targets = [] - scoped_targets = {} - - if is_link: - link_aliases = [] - if bazel_package in link_packages: - link_aliases = link_packages[bazel_package] - if not link_aliases: - link_aliases = ["chalk"] - for link_alias in link_aliases: - link_target_name = "{}/{}".format(name, link_alias) - npm_link_imported_package_store(name = link_target_name) - if True: - link_targets.append(":{}".format(link_target_name)) - link_scope = link_alias[:link_alias.find("/", 1)] if link_alias[0] == "@" else None - if link_scope: - if link_scope not in scoped_targets: - scoped_targets[link_scope] = [] - scoped_targets[link_scope].append(link_target_name) - - if is_root: - npm_imported_package_store("{}/chalk".format(name)) - - return (link_targets, scoped_targets) diff --git a/npm/private/test/snapshots/wksp/chalk_links_defs.bzl b/npm/private/test/snapshots/wksp/chalk_links_defs.bzl deleted file mode 100644 index 13f85f3eb..000000000 --- a/npm/private/test/snapshots/wksp/chalk_links_defs.bzl +++ /dev/null @@ -1,165 +0,0 @@ -"@generated by @aspect_rules_js//npm/private:npm_import.bzl for npm package chalk@5.0.1" - -# buildifier: disable=bzl-visibility -load("@aspect_rules_js//npm/private:npm_package_store_internal.bzl", _npm_package_store = "npm_package_store_internal") - -# buildifier: disable=bzl-visibility -load("@aspect_rules_js//npm/private:npm_link_package_store.bzl", _npm_link_package_store = "npm_link_package_store") - -# Generated npm_package_store targets for npm package chalk@5.0.1 -# buildifier: disable=function-docstring -def npm_imported_package_store(name): - bazel_package = native.package_name() - root_package = "" - is_root = bazel_package == root_package - if not is_root: - msg = "No store links in bazel package '%s' for npm package npm package chalk@5.0.1. This is neither the root package nor a link package of this package." % bazel_package - fail(msg) - if not name.endswith("/chalk"): - msg = "name must end with one of '/chalk' when linking the store in package 'chalk'; recommended value is 'node_modules/chalk'" - fail(msg) - link_root_name = name[:-len("/chalk")] - - deps = { - ":.aspect_rules_js/{}/chalk@5.0.1/pkg".format(link_root_name): "chalk", - } - ref_deps = {} - - store_target_name = ".aspect_rules_js/{}/chalk@5.0.1".format(link_root_name) - - # reference target used to avoid circular deps - _npm_package_store( - name = "{}/ref".format(store_target_name), - package = "chalk", - version = "5.0.1", - dev = False, - tags = ["manual"], - ) - - # post-lifecycle target with reference deps for use in terminal target with transitive closure - _npm_package_store( - name = "{}/pkg".format(store_target_name), - src = "{}/pkg_lc".format(store_target_name) if False else "@chalk_501//:pkg", - package = "chalk", - version = "5.0.1", - dev = False, - deps = ref_deps, - tags = ["manual"], - ) - - # package store target with transitive closure of all npm package dependencies - _npm_package_store( - name = store_target_name, - src = None if True else "@chalk_501//:pkg", - package = "chalk", - version = "5.0.1", - dev = False, - deps = deps, - visibility = ["//visibility:public"], - tags = ["manual"], - ) - - # filegroup target that provides a single file which is - # package directory for use in $(execpath) and $(rootpath) - native.filegroup( - name = "{}/dir".format(store_target_name), - srcs = [":{}".format(store_target_name)], - output_group = "package_directory", - visibility = ["//visibility:public"], - tags = ["manual"], - ) - -# Generated npm_package_store and npm_link_package_store targets for npm package chalk@5.0.1 -# buildifier: disable=function-docstring -def npm_link_imported_package_store(name): - bazel_package = native.package_name() - link_packages = { - "examples/npm_package/libs/lib_a": ["chalk"], - "npm/private/test/npm_package": ["chalk"], - } - if bazel_package in link_packages: - link_aliases = link_packages[bazel_package] - else: - link_aliases = ["chalk"] - - link_alias = None - for _link_alias in link_aliases: - if name.endswith("/{}".format(_link_alias)): - # longest match wins - if not link_alias or len(_link_alias) > len(link_alias): - link_alias = _link_alias - if not link_alias: - msg = "name must end with one of '/{{ {link_aliases_comma_separated} }}' when called from package 'chalk'; recommended value(s) are 'node_modules/{{ {link_aliases_comma_separated} }}'".format(link_aliases_comma_separated = ", ".join(link_aliases)) - fail(msg) - - link_root_name = name[:-len("/{}".format(link_alias))] - store_target_name = ".aspect_rules_js/{}/chalk@5.0.1".format(link_root_name) - - # terminal package store target to link - _npm_link_package_store( - name = name, - package = link_alias, - src = "//:{}".format(store_target_name), - visibility = ["//visibility:public"], - tags = ["manual"], - ) - - # filegroup target that provides a single file which is - # package directory for use in $(execpath) and $(rootpath) - native.filegroup( - name = "{}/dir".format(name), - srcs = [":{}".format(name)], - output_group = "package_directory", - visibility = ["//visibility:public"], - tags = ["manual"], - ) - - return [":{}".format(name)] if True else [] - -# Generated npm_package_store and npm_link_package_store targets for npm package chalk@5.0.1 -# buildifier: disable=function-docstring -def npm_link_imported_package( - name = "node_modules", - link = None, - fail_if_no_link = True): - bazel_package = native.package_name() - root_package = "" - link_packages = { - "examples/npm_package/libs/lib_a": ["chalk"], - "npm/private/test/npm_package": ["chalk"], - } - - if link_packages and link != None: - fail("link attribute cannot be specified when link_packages are set") - - is_link = (link == True) or (link == None and bazel_package in link_packages) - is_root = bazel_package == root_package - - if fail_if_no_link and not is_root and not link: - msg = "Nothing to link in bazel package '%s' for npm package npm package chalk@5.0.1. This is neither the root package nor a link package of this package." % bazel_package - fail(msg) - - link_targets = [] - scoped_targets = {} - - if is_link: - link_aliases = [] - if bazel_package in link_packages: - link_aliases = link_packages[bazel_package] - if not link_aliases: - link_aliases = ["chalk"] - for link_alias in link_aliases: - link_target_name = "{}/{}".format(name, link_alias) - npm_link_imported_package_store(name = link_target_name) - if True: - link_targets.append(":{}".format(link_target_name)) - link_scope = link_alias[:link_alias.find("/", 1)] if link_alias[0] == "@" else None - if link_scope: - if link_scope not in scoped_targets: - scoped_targets[link_scope] = [] - scoped_targets[link_scope].append(link_target_name) - - if is_root: - npm_imported_package_store("{}/chalk".format(name)) - - return (link_targets, scoped_targets) diff --git a/npm/private/test/snapshots/wksp/repositories.bzl b/npm/private/test/snapshots/wksp/repositories.bzl index 04fca02ad..bc0f78cb6 100644 --- a/npm/private/test/snapshots/wksp/repositories.bzl +++ b/npm/private/test/snapshots/wksp/repositories.bzl @@ -7350,7 +7350,6 @@ def npm_repositories(): transitive_closure = { "chalk": ["5.0.1"], }, - replace_package = "@chalk_501//:pkg", ) npm_import(