test: assertions for sandboxing of third-party packages (#2614)

Trying to understand + reproduce #362 better.

- Covered by existing test cases
- New test cases added
diff --git a/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU= b/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=
index 99d3c08..85b0874 100755
--- a/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=
+++ b/.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=
@@ -17,7 +17,7 @@
 examples/npm_package/packages/pkg_a/package.json=1006424040
 examples/npm_package/packages/pkg_b/package.json=-1129449456
 examples/npm_package/packages/pkg_d/package.json=1146506398
-examples/npm_package/packages/pkg_e/package.json=2063663382
+examples/npm_package/packages/pkg_e/package.json=2046864123
 examples/runfiles/package.json=-1545884645
 examples/stack_traces/package.json=2011229626
 examples/vite3/package.json=-1401988763
@@ -36,5 +36,5 @@
 npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349
 npm/private/test/vendored/semver-max/package.json=578664053
 package.json=422674712
-pnpm-lock.yaml=-488021962
+pnpm-lock.yaml=627807655
 pnpm-workspace.yaml=-1336981113
diff --git a/examples/macro/BUILD.bazel b/examples/macro/BUILD.bazel
index d7b5fe4..f7b1a53 100644
--- a/examples/macro/BUILD.bazel
+++ b/examples/macro/BUILD.bazel
@@ -7,10 +7,25 @@
 npm_link_all_packages()
 
 mocha_test(
-    name = "test",
+    name = "test_js",
     srcs = ["test.js"],
 )
 
+mocha_test(
+    name = "test_cjs",
+    srcs = ["test.cjs"],
+)
+
+mocha_test(
+    name = "test_esm",
+    srcs = ["test.mjs"],
+)
+
+mocha_test(
+    name = "test_all",
+    srcs = glob(["test.*js"]),
+)
+
 bzl_library(
     name = "mocha",
     srcs = ["mocha.bzl"],
diff --git a/examples/macro/mocha.bzl b/examples/macro/mocha.bzl
index 2750975..a6c51a9 100644
--- a/examples/macro/mocha.bzl
+++ b/examples/macro/mocha.bzl
@@ -10,7 +10,7 @@
             "mocha-multi-reporters",
             "--reporter-options",
             "configFile=$(rootpath //examples/macro:mocha_reporters.json)",
-            native.package_name() + "/*test.js",
+            native.package_name() + "/*test.*js",
         ] + args,
         data = data + srcs + [
             "//examples/macro:mocha_reporters.json",
diff --git a/examples/macro/test.cjs b/examples/macro/test.cjs
new file mode 100644
index 0000000..02a6403
--- /dev/null
+++ b/examples/macro/test.cjs
@@ -0,0 +1,28 @@
+const assert = require('assert')
+const { dirname } = require('node:path')
+
+describe('mocha .cjs', () => {
+    it('integrates with Bazel', () => {
+        assert(true)
+    })
+
+    it('is in bazel-out', () => {
+        assert.match(__dirname, /bazel-out/)
+    })
+
+    it('is sandboxed', () => {
+        assert.match(
+            process.cwd(),
+            /examples\/macro\/test(_\w+)_\/test(_\w+)\.runfiles/
+        )
+        assert.match(
+            __dirname,
+            /examples\/macro\/test(_\w+)_\/test(_\w+)\.runfiles/
+        )
+        assert.match(
+            __filename,
+            /-sandbox\/\d+\/execroot\/_main\/bazel-out\/[^/]+\/bin\/examples\/macro\/test(_\w+)_\/test(_\w+).runfiles\/_main\/examples\/macro\/test\.cjs/
+        )
+        assert.equal(__dirname, dirname(__filename))
+    })
+})
diff --git a/examples/macro/test.js b/examples/macro/test.js
index 13f2ec5..af7aa93 100644
--- a/examples/macro/test.js
+++ b/examples/macro/test.js
@@ -1,7 +1,7 @@
 const assert = require('assert')
 const { dirname } = require('node:path')
 
-describe('mocha', () => {
+describe('mocha .js', () => {
     it('integrates with Bazel', () => {
         assert(true)
     })
@@ -11,11 +11,17 @@
     })
 
     it('is sandboxed', () => {
-        assert.match(process.cwd(), /examples\/macro\/test_\/test\.runfiles/)
-        assert.match(__dirname, /examples\/macro\/test_\/test\.runfiles/)
+        assert.match(
+            process.cwd(),
+            /examples\/macro\/test(_\w+)?_\/test(_\w+)?\.runfiles/
+        )
+        assert.match(
+            __dirname,
+            /examples\/macro\/test(_\w+)?_\/test(_\w+)?\.runfiles/
+        )
         assert.match(
             __filename,
-            /-sandbox\/\d+\/execroot\/_main\/bazel-out\/[^/]+\/bin\/examples\/macro\/test_\/test.runfiles\/_main\/examples\/macro\/test\.js/
+            /-sandbox\/\d+\/execroot\/_main\/bazel-out\/[^/]+\/bin\/examples\/macro\/test(_\w+)?_\/test(_\w+)?\.runfiles\/_main\/examples\/macro\/test\.js/
         )
         assert.equal(__dirname, dirname(__filename))
     })
diff --git a/examples/macro/test.mjs b/examples/macro/test.mjs
new file mode 100644
index 0000000..3d60bd2
--- /dev/null
+++ b/examples/macro/test.mjs
@@ -0,0 +1,31 @@
+import assert from 'node:assert'
+import { dirname } from 'node:path'
+import { fileURLToPath } from 'node:url'
+
+const __filename = import.meta.filename || fileURLToPath(import.meta.url)
+const __dirname = import.meta.dirname || dirname(__filename)
+
+describe('mocha .mjs', () => {
+    it('integrates with Bazel', () => {
+        assert(true)
+    })
+
+    it('is in bazel-out', () => {
+        assert.match(__dirname, /bazel-out/)
+    })
+
+    it('is sandboxed', () => {
+        assert.match(
+            process.cwd(),
+            /examples\/macro\/test(_\w+)_\/test(_\w+)\.runfiles/
+        )
+        assert.match(
+            __dirname,
+            /examples\/macro\/test(_\w+)_\/test(_\w+)\.runfiles/
+        )
+        assert.match(
+            __filename,
+            /-sandbox\/\d+\/execroot\/_main\/bazel-out\/[^/]+\/bin\/examples\/macro\/test(_\w+)_\/test(_\w+).runfiles\/_main\/examples\/macro\/test\.mjs/
+        )
+    })
+})
diff --git a/examples/npm_deps/BUILD.bazel b/examples/npm_deps/BUILD.bazel
index 34adb63..f5062a9 100644
--- a/examples/npm_deps/BUILD.bazel
+++ b/examples/npm_deps/BUILD.bazel
@@ -380,3 +380,66 @@
     ],
     entry_point = "case10.mjs",
 )
+
+#######################################
+# Case 11: use first-party packages directly and indirectly multiple times
+
+write_file(
+    name = "write11_cjs",
+    out = "case11.cjs",
+    content = [
+        "const { sandboxAssert: sandboxAssertB } = require('@mycorp/pkg-b')",
+        "const { sandboxAssert: sandboxAssertC1 } = require('@mycorp/pkg-c1')",
+        "const { sandboxAssert: sandboxAssertD, getAcornVersion: getAcornVersionD } = require('@mycorp/pkg-d')",
+        "const { sandboxAssert: sandboxAssertE, getAcornVersion: getAcornVersionE } = require('@mycorp/pkg-e')",
+        "const { deepEqual } = require('node:assert')",
+        "sandboxAssertB()",
+        "sandboxAssertC1()",
+        "sandboxAssertD()",
+        "sandboxAssertE()",
+        "deepEqual(getAcornVersionD(), getAcornVersionE())",
+    ],
+)
+
+write_file(
+    name = "write11_mjs",
+    out = "case11.mjs",
+    content = [
+        "import { sandboxAssert as sandboxAssertB } from '@mycorp/pkg-b'",
+        "import { sandboxAssert as sandboxAssertC1 } from '@mycorp/pkg-c1'",
+        "import { sandboxAssert as sandboxAssertD, getAcornVersion as getAcornVersionD } from '@mycorp/pkg-d'",
+        "import { sandboxAssert as sandboxAssertE, getAcornVersion as getAcornVersionE } from '@mycorp/pkg-e'",
+        "import { deepEqual } from 'node:assert'",
+        "sandboxAssertB()",
+        "sandboxAssertC1()",
+        "sandboxAssertD()",
+        "sandboxAssertE();",
+        "(await import('@mycorp/pkg-b')).sandboxAssert();",
+        "(await import('@mycorp/pkg-c1')).sandboxAssert();",
+        "(await import('@mycorp/pkg-d')).sandboxAssert();",
+        "(await import('@mycorp/pkg-e')).sandboxAssert();",
+        "deepEqual(getAcornVersionD(), getAcornVersionE())",
+    ],
+)
+
+js_test(
+    name = "test11_cjs",
+    data = [
+        ":node_modules/@mycorp/pkg-d",
+        ":node_modules/@mycorp/pkg-e",
+        "//:node_modules/@mycorp/pkg-b",
+        "//:node_modules/@mycorp/pkg-c1",
+    ],
+    entry_point = "case11.cjs",
+)
+
+js_test(
+    name = "test11_mjs",
+    data = [
+        ":node_modules/@mycorp/pkg-d",
+        ":node_modules/@mycorp/pkg-e",
+        "//:node_modules/@mycorp/pkg-b",
+        "//:node_modules/@mycorp/pkg-c1",
+    ],
+    entry_point = "case11.mjs",
+)
diff --git a/examples/npm_package/packages/pkg_a/index.js b/examples/npm_package/packages/pkg_a/index.js
index dcce73d..6a2639f 100644
--- a/examples/npm_package/packages/pkg_a/index.js
+++ b/examples/npm_package/packages/pkg_a/index.js
@@ -22,8 +22,36 @@
     if (!__filename.includes('/node_modules/.aspect_rules_js/')) {
         throw new Error(`Not in package store: ${__filename}`)
     }
+
+    // When running under test, files should be in runfiles.
+    // This package may also be used as a run_binary(tool) and not in a test.
+    if (process.env.TEST_WORKSPACE) {
+        if (!__filename.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(`Not in runfiles: ${__filename}`)
+        }
+    }
+
+    // Resolve of third-party package 'uuid'
+    const uuid_path = require.resolve('uuid')
+    if (!/-sandbox\/\d+\/execroot\//.test(uuid_path)) {
+        throw new Error(`uuid not in sandbox: ${uuid_path}`)
+    }
+    if (!uuid_path.includes('/node_modules/.aspect_rules_js/uuid@')) {
+        throw new Error(`uuid not in package store: ${uuid_path}`)
+    }
+    if (process.env.TEST_WORKSPACE) {
+        if (!uuid_path.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(
+                `uuid not in runfiles while __filename is: ${uuid_path}`
+            )
+        }
+    }
 }
 
+global['pkg_a__js'] ??= 0
+if (++global['pkg_a__js'] > 1) {
+    throw new Error('pkg_a index.js loaded multiple times')
+}
 sandboxAssert()
 
 module.exports = {
diff --git a/examples/npm_package/packages/pkg_b/index.cjs b/examples/npm_package/packages/pkg_b/index.cjs
index 40ef713..235b04c 100644
--- a/examples/npm_package/packages/pkg_b/index.cjs
+++ b/examples/npm_package/packages/pkg_b/index.cjs
@@ -21,8 +21,36 @@
     if (!__filename.includes('/node_modules/.aspect_rules_js/')) {
         throw new Error(`Not in package store: ${__filename}`)
     }
+
+    // When running under test, files should be in runfiles.
+    // This package may also be used as a run_binary(tool) and not in a test.
+    if (process.env.TEST_WORKSPACE) {
+        if (!__filename.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(`Not in runfiles: ${__filename}`)
+        }
+    }
+
+    // Resolve of third-party package 'uuid'
+    const uuid_path = require.resolve('uuid')
+    if (!/-sandbox\/\d+\/execroot\//.test(uuid_path)) {
+        throw new Error(`uuid not in sandbox: ${uuid_path}`)
+    }
+    if (!uuid_path.includes('/node_modules/.aspect_rules_js/uuid@')) {
+        throw new Error(`uuid not in package store: ${uuid_path}`)
+    }
+    if (process.env.TEST_WORKSPACE) {
+        if (!uuid_path.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(
+                `uuid not in runfiles while __filename is: ${uuid_path}`
+            )
+        }
+    }
 }
 
+global['pkg_b__cjs'] ??= 0
+if (++global['pkg_b__cjs'] > 1) {
+    throw new Error('pkg_b index.cjs loaded multiple times')
+}
 sandboxAssert()
 
 module.exports = {
diff --git a/examples/npm_package/packages/pkg_b/index.mjs b/examples/npm_package/packages/pkg_b/index.mjs
index 3502e18..f589e35 100644
--- a/examples/npm_package/packages/pkg_b/index.mjs
+++ b/examples/npm_package/packages/pkg_b/index.mjs
@@ -26,6 +26,34 @@
     if (!__filename.includes('/node_modules/.aspect_rules_js/')) {
         throw new Error(`Not in package store: ${__filename}`)
     }
+
+    // When running under test, files should be in runfiles.
+    // This package may also be used as a run_binary(tool) and not in a test.
+    if (process.env.TEST_WORKSPACE) {
+        if (!__filename.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(`Not in runfiles: ${__filename}`)
+        }
+    }
+
+    // Resolve of third-party package 'uuid'
+    const uuid_path = fileURLToPath(import.meta.resolve('uuid'))
+    if (!/-sandbox\/\d+\/execroot\//.test(uuid_path)) {
+        throw new Error(`uuid not in sandbox: ${uuid_path}`)
+    }
+    if (!uuid_path.includes('/node_modules/.aspect_rules_js/uuid@')) {
+        throw new Error(`uuid not in package store: ${uuid_path}`)
+    }
+    if (process.env.TEST_WORKSPACE) {
+        if (!uuid_path.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(
+                `uuid not in runfiles while __filename is: ${uuid_path}`
+            )
+        }
+    }
 }
 
+global['pkg_b__mjs'] ??= 0
+if (++global['pkg_b__mjs'] > 1) {
+    throw new Error('pkg_b index.mjs loaded multiple times')
+}
 sandboxAssert()
diff --git a/examples/npm_package/packages/pkg_c/src/index.cjs b/examples/npm_package/packages/pkg_c/src/index.cjs
index 6ed403b..87f03aa 100644
--- a/examples/npm_package/packages/pkg_c/src/index.cjs
+++ b/examples/npm_package/packages/pkg_c/src/index.cjs
@@ -9,8 +9,20 @@
     if (!__filename.includes('/node_modules/.aspect_rules_js/')) {
         throw new Error(`Not in package store: ${__filename}`)
     }
+
+    // When running under test, files should be in runfiles.
+    // This package may also be used as a run_binary(tool) and not in a test.
+    if (process.env.TEST_WORKSPACE) {
+        if (!__filename.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(`Not in runfiles: ${__filename}`)
+        }
+    }
 }
 
+global['pkg_c__cjs'] ??= 0
+if (++global['pkg_c__cjs'] > 1) {
+    throw new Error('pkg_c index.cjs loaded multiple times')
+}
 sandboxAssert()
 
 module.exports.name = pkgC.name
diff --git a/examples/npm_package/packages/pkg_c/src/index.mjs b/examples/npm_package/packages/pkg_c/src/index.mjs
index 92d35e7..42d0b29 100644
--- a/examples/npm_package/packages/pkg_c/src/index.mjs
+++ b/examples/npm_package/packages/pkg_c/src/index.mjs
@@ -14,6 +14,18 @@
     if (!__filename.includes('/node_modules/.aspect_rules_js/')) {
         throw new Error(`Not in package store: ${__filename}`)
     }
+
+    // When running under test, files should be in runfiles.
+    // This package may also be used as a run_binary(tool) and not in a test.
+    if (process.env.TEST_WORKSPACE) {
+        if (!__filename.startsWith(process.env.RUNFILES_DIR)) {
+            throw new Error(`Not in runfiles: ${__filename}`)
+        }
+    }
 }
 
+global['pkg_c__mjs'] ??= 0
+if (++global['pkg_c__mjs'] > 1) {
+    throw new Error('pkg_c index.mjs loaded multiple times')
+}
 sandboxAssert()
diff --git a/examples/npm_package/packages/pkg_d/index.cjs b/examples/npm_package/packages/pkg_d/index.cjs
index 2c4fdb3..d3ad385 100644
--- a/examples/npm_package/packages/pkg_d/index.cjs
+++ b/examples/npm_package/packages/pkg_d/index.cjs
@@ -22,6 +22,18 @@
     if (!__filename.startsWith(process.env.RUNFILES_DIR)) {
         throw new Error(`Not runfiles: ${__filename}`)
     }
+
+    // Resolve of third-party package 'uuid'
+    const uuid_path = require.resolve('uuid')
+    if (!/-sandbox\/\d+\/execroot\//.test(uuid_path)) {
+        throw new Error(`uuid not in sandbox: ${uuid_path}`)
+    }
+    if (!uuid_path.includes('/node_modules/.aspect_rules_js/uuid@')) {
+        throw new Error(`uuid not in package store: ${uuid_path}`)
+    }
+    if (!uuid_path.startsWith(process.env.RUNFILES_DIR)) {
+        throw new Error(`uuid not in runfiles: ${uuid_path}`)
+    }
 }
 
 module.exports = {
@@ -31,4 +43,8 @@
     sandboxAssert,
 }
 
+global['pkg_d__cjs'] ??= 0
+if (++global['pkg_d__cjs'] > 1) {
+    throw new Error('pkg_d index.cjs loaded multiple times')
+}
 sandboxAssert()
diff --git a/examples/npm_package/packages/pkg_d/index.mjs b/examples/npm_package/packages/pkg_d/index.mjs
index aec2726..9215ca2 100644
--- a/examples/npm_package/packages/pkg_d/index.mjs
+++ b/examples/npm_package/packages/pkg_d/index.mjs
@@ -17,6 +17,18 @@
     if (!__filename.startsWith(process.env.RUNFILES_DIR)) {
         throw new Error(`Not runfiles: ${__filename}`)
     }
+
+    // Resolve of third-party package 'uuid'
+    const uuid_path = fileURLToPath(import.meta.resolve('uuid'))
+    if (!/-sandbox\/\d+\/execroot\//.test(uuid_path)) {
+        throw new Error(`uuid not in sandbox: ${uuid_path}`)
+    }
+    if (!uuid_path.includes('/node_modules/.aspect_rules_js/uuid@')) {
+        throw new Error(`uuid not in package store: ${uuid_path}`)
+    }
+    if (!uuid_path.startsWith(process.env.RUNFILES_DIR)) {
+        throw new Error(`uuid not in runfiles: ${uuid_path}`)
+    }
 }
 
 export function toAst(program) {
@@ -27,4 +39,8 @@
     return acorn.version
 }
 
+global['pkg_d__mjs'] ??= 0
+if (++global['pkg_d__mjs'] > 1) {
+    throw new Error('pkg_d index.mjs loaded multiple times')
+}
 sandboxAssert()
diff --git a/examples/npm_package/packages/pkg_e/index.cjs b/examples/npm_package/packages/pkg_e/index.cjs
index 68f65fb..5c339dd 100644
--- a/examples/npm_package/packages/pkg_e/index.cjs
+++ b/examples/npm_package/packages/pkg_e/index.cjs
@@ -5,6 +5,8 @@
     sandboxAssert: dSandboxAssert,
 } = require('@mycorp/pkg-d')
 
+const { sandboxAssert: bSandboxAssert } = require('@mycorp/pkg-b')
+
 function sandboxAssert() {
     if (!/-sandbox\/\d+\/execroot\//.test(__filename)) {
         throw new Error(`Not in sandbox: ${__filename}`)
@@ -16,10 +18,25 @@
         throw new Error(`Not runfiles: ${__filename}`)
     }
 
+    bSandboxAssert()
     dSandboxAssert()
+    require('@mycorp/pkg-b').sandboxAssert()
     require('@mycorp/pkg-d').sandboxAssert()
+
+    // Resolve of pkg-d
+    const pkgDPath = require.resolve('@mycorp/pkg-d')
+    if (!/-sandbox\/\d+\/execroot\//.test(pkgDPath)) {
+        throw new Error(`pkg-d not in sandbox: ${pkgDPath}`)
+    }
+    if (!pkgDPath.startsWith(process.env.RUNFILES_DIR)) {
+        throw new Error(`pkg-d not in runfiles: ${pkgDPath}`)
+    }
 }
 
+global['pkg_e__cjs'] ??= 0
+if (++global['pkg_e__cjs'] > 1) {
+    throw new Error('pkg_e index.cjs loaded multiple times')
+}
 sandboxAssert()
 
 module.exports = {
diff --git a/examples/npm_package/packages/pkg_e/index.mjs b/examples/npm_package/packages/pkg_e/index.mjs
index 9ff70d8..7e3c02b 100644
--- a/examples/npm_package/packages/pkg_e/index.mjs
+++ b/examples/npm_package/packages/pkg_e/index.mjs
@@ -5,6 +5,7 @@
 
 import { fileURLToPath } from 'node:url'
 
+import { sandboxAssert as bSandboxAssert } from '@mycorp/pkg-b'
 import { sandboxAssert as dSandboxAssert } from '@mycorp/pkg-d'
 export { getAcornVersion, toAst, uuid } from '@mycorp/pkg-d'
 
@@ -21,11 +22,26 @@
         throw new Error(`Not runfiles: ${__filename}`)
     }
 
-    // Static import of pkg-d
+    // Static import of pkg-b,d
+    bSandboxAssert()
     dSandboxAssert()
 
-    // Dynamic import of pkg-d
+    // Dynamic import of pkg-b,d
+    await import('@mycorp/pkg-b').then(({ sandboxAssert }) => sandboxAssert())
     await import('@mycorp/pkg-d').then(({ sandboxAssert }) => sandboxAssert())
+
+    // Resolve of pkg-d
+    const pkgDPath = fileURLToPath(import.meta.resolve('@mycorp/pkg-d'))
+    if (!/-sandbox\/\d+\/execroot\//.test(pkgDPath)) {
+        throw new Error(`pkg-d not in sandbox: ${pkgDPath}`)
+    }
+    if (!pkgDPath.startsWith(process.env.RUNFILES_DIR)) {
+        throw new Error(`pkg-d not in runfiles: ${pkgDPath}`)
+    }
 }
 
+global['pkg_e__mjs'] ??= 0
+if (++global['pkg_e__mjs'] > 1) {
+    throw new Error('pkg_e index.mjs loaded multiple times')
+}
 await sandboxAssert()
diff --git a/examples/npm_package/packages/pkg_e/package.json b/examples/npm_package/packages/pkg_e/package.json
index 2cbab84..dfcf27f 100644
--- a/examples/npm_package/packages/pkg_e/package.json
+++ b/examples/npm_package/packages/pkg_e/package.json
@@ -9,6 +9,7 @@
         }
     },
     "dependencies": {
+        "@mycorp/pkg-b": "workspace:*",
         "@mycorp/pkg-d": "workspace:*"
     }
 }
diff --git a/js/private/test/image/checksum_test.expected b/js/private/test/image/checksum_test.expected
index e0b7578..57cbcd5 100644
--- a/js/private/test/image/checksum_test.expected
+++ b/js/private/test/image/checksum_test.expected
@@ -1,4 +1,4 @@
 50af5fea724651ca61d47fed08d476ab369bbdef2c24f92cab9dd9317bb52580  js/private/test/image/cksum_node.tar
 052600f3a82ab6a4cc12cab7384971c960f9c589fdbfcf21bca563c36ff7d16e  js/private/test/image/cksum_package_store_3p.tar
-214533bee38e3daf9cab29d917ab775ec6b55c726ace5ed27e957b59a95091b3  js/private/test/image/cksum_package_store_1p.tar
+bcd3826edb788a083e88ae3dbfb7fbd86bb1de8d8ef1db881b6488d63d715245  js/private/test/image/cksum_package_store_1p.tar
 febf95a6d554c9bda3f0515bfd5ef273ac67d31c231d8162beaef8c4b7bc72f3  js/private/test/image/cksum_node_modules.tar
diff --git a/js/private/test/image/custom_layers_nomatch_test_package_store_1p.listing b/js/private/test/image/custom_layers_nomatch_test_package_store_1p.listing
index b44d0a2..7c72913 100644
--- a/js/private/test/image/custom_layers_nomatch_test_package_store_1p.listing
+++ b/js/private/test/image/custom_layers_nomatch_test_package_store_1p.listing
@@ -19,7 +19,7 @@
 -r-xr-xr-x  0 0      0         224 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/a2/index.js
 -r-xr-xr-x  0 0      0          31 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.d.ts
 -r-xr-xr-x  0 0      0         237 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.js
--r-xr-xr-x  0 0      0         815 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
+-r-xr-xr-x  0 0      0        1848 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
 -r-xr-xr-x  0 0      0         166 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/package.json
 lrwxrwxr-x  0 0      0           0 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/acorn -> ../../acorn@8.7.1/node_modules/acorn
 lrwxrwxr-x  0 0      0           0 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/chalk -> ../../chalk@5.0.1/node_modules/chalk
diff --git a/js/private/test/image/custom_owner_test_app.listing b/js/private/test/image/custom_owner_test_app.listing
index eaa72ff..eaf2501 100644
--- a/js/private/test/image/custom_owner_test_app.listing
+++ b/js/private/test/image/custom_owner_test_app.listing
@@ -9,8 +9,8 @@
 drwxr-xr-x  0 100    0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/
 drwxr-xr-x  0 100    0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/
 drwxr-xr-x  0 100    0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/
--r-xr-xr-x  0 100    0         810 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.cjs
--r-xr-xr-x  0 100    0         841 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.mjs
+-r-xr-xr-x  0 100    0        1420 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.cjs
+-r-xr-xr-x  0 100    0        1470 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.mjs
 -r-xr-xr-x  0 100    0         336 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/package.json
 drwxr-xr-x  0 100    0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/js/
 drwxr-xr-x  0 100    0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/js/private/
diff --git a/js/private/test/image/custom_owner_test_package_store_1p.listing b/js/private/test/image/custom_owner_test_package_store_1p.listing
index 36be2c2..62cc722 100644
--- a/js/private/test/image/custom_owner_test_package_store_1p.listing
+++ b/js/private/test/image/custom_owner_test_package_store_1p.listing
@@ -18,7 +18,7 @@
 -r-xr-xr-x  0 100    0         224 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/a2/index.js
 -r-xr-xr-x  0 100    0          31 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.d.ts
 -r-xr-xr-x  0 100    0         237 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.js
--r-xr-xr-x  0 100    0         815 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
+-r-xr-xr-x  0 100    0        1848 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
 -r-xr-xr-x  0 100    0         166 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/package.json
 lrwxrwxr-x  0 100    0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/acorn -> ../../acorn@8.7.1/node_modules/acorn
 lrwxrwxr-x  0 100    0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/chalk -> ../../chalk@5.0.1/node_modules/chalk
diff --git a/js/private/test/image/default_test_app.listing b/js/private/test/image/default_test_app.listing
index d5a70f3..11a54df 100644
--- a/js/private/test/image/default_test_app.listing
+++ b/js/private/test/image/default_test_app.listing
@@ -9,8 +9,8 @@
 drwxr-xr-x  0 0      0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/
 drwxr-xr-x  0 0      0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/
 drwxr-xr-x  0 0      0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/
--r-xr-xr-x  0 0      0         810 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.cjs
--r-xr-xr-x  0 0      0         841 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.mjs
+-r-xr-xr-x  0 0      0        1420 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.cjs
+-r-xr-xr-x  0 0      0        1470 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.mjs
 -r-xr-xr-x  0 0      0         336 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/package.json
 drwxr-xr-x  0 0      0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/js/
 drwxr-xr-x  0 0      0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/js/private/
diff --git a/js/private/test/image/default_test_package_store_1p.listing b/js/private/test/image/default_test_package_store_1p.listing
index ae77a79..28a06b7 100644
--- a/js/private/test/image/default_test_package_store_1p.listing
+++ b/js/private/test/image/default_test_package_store_1p.listing
@@ -18,7 +18,7 @@
 -r-xr-xr-x  0 0      0         224 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/a2/index.js
 -r-xr-xr-x  0 0      0          31 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.d.ts
 -r-xr-xr-x  0 0      0         237 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.js
--r-xr-xr-x  0 0      0         815 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
+-r-xr-xr-x  0 0      0        1848 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
 -r-xr-xr-x  0 0      0         166 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/package.json
 lrwxrwxr-x  0 0      0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/acorn -> ../../acorn@8.7.1/node_modules/acorn
 lrwxrwxr-x  0 0      0           0 Jan  1  1970 ./js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/chalk -> ../../chalk@5.0.1/node_modules/chalk
diff --git a/js/private/test/image/regex_edge_cases_test_app.listing b/js/private/test/image/regex_edge_cases_test_app.listing
index 378789f..a332597 100644
--- a/js/private/test/image/regex_edge_cases_test_app.listing
+++ b/js/private/test/image/regex_edge_cases_test_app.listing
@@ -10,8 +10,8 @@
 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/
--r-xr-xr-x  0 0      0         810 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.cjs
--r-xr-xr-x  0 0      0         841 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.mjs
+-r-xr-xr-x  0 0      0        1420 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.cjs
+-r-xr-xr-x  0 0      0        1470 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/index.mjs
 -r-xr-xr-x  0 0      0         336 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/examples/npm_package/packages/pkg_d/package.json
 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/
diff --git a/js/private/test/image/regex_edge_cases_test_package_store_1p.listing b/js/private/test/image/regex_edge_cases_test_package_store_1p.listing
index b44d0a2..7c72913 100644
--- a/js/private/test/image/regex_edge_cases_test_package_store_1p.listing
+++ b/js/private/test/image/regex_edge_cases_test_package_store_1p.listing
@@ -19,7 +19,7 @@
 -r-xr-xr-x  0 0      0         224 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/a2/index.js
 -r-xr-xr-x  0 0      0          31 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.d.ts
 -r-xr-xr-x  0 0      0         237 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/a/index.js
--r-xr-xr-x  0 0      0         815 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
+-r-xr-xr-x  0 0      0        1848 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/index.js
 -r-xr-xr-x  0 0      0         166 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/@mycorp/pkg-a/package.json
 lrwxrwxr-x  0 0      0           0 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/acorn -> ../../acorn@8.7.1/node_modules/acorn
 lrwxrwxr-x  0 0      0           0 Jan  1  1970 ./app/js/private/test/image/bin.runfiles/_main/node_modules/.aspect_rules_js/@mycorp+pkg-a@0.0.0/node_modules/chalk -> ../../chalk@5.0.1/node_modules/chalk
diff --git a/npm/private/test/snapshots/npm_defs-no_dev.bzl b/npm/private/test/snapshots/npm_defs-no_dev.bzl
index 0a9cbde..f749967 100644
--- a/npm/private/test/snapshots/npm_defs-no_dev.bzl
+++ b/npm/private/test/snapshots/npm_defs-no_dev.bzl
@@ -2433,6 +2433,18 @@
             tags = ["manual"],
         )
         _npm_local_package_store(
+            package_store_name = "@mycorp+pkg-b@0.0.0",
+            src = "//examples/npm_package/packages/pkg_b:pkg",
+            package = "@mycorp/pkg-b",
+            version = "0.0.0",
+            deps = {
+                "//:.aspect_rules_js/node_modules/acorn@8.7.1": "acorn",
+                "//:.aspect_rules_js/node_modules/uuid@8.3.2": "uuid",
+            },
+            visibility = ["//visibility:public"],
+            tags = ["manual"],
+        )
+        _npm_local_package_store(
             package_store_name = "@mycorp+pkg-d@0.0.0",
             src = "//examples/npm_package/packages/pkg_d:pkg",
             package = "@mycorp/pkg-d",
@@ -2539,8 +2551,8 @@
             }
         elif bazel_package == "js/private/test/image":
             link_323()
-            _fp_link_5()
             _fp_link_6()
+            _fp_link_7()
             link_targets = [
                 ":node_modules/acorn",
                 ":node_modules/@mycorp/pkg-d",
@@ -2626,9 +2638,16 @@
             }
         elif bazel_package == "examples/npm_package/packages/pkg_e":
             _fp_link_5()
-            link_targets = [":node_modules/@mycorp/pkg-d"]
+            _fp_link_6()
+            link_targets = [
+                ":node_modules/@mycorp/pkg-b",
+                ":node_modules/@mycorp/pkg-d",
+            ]
             scope_targets = {
-                "@mycorp": [":node_modules/@mycorp/pkg-d"],
+                "@mycorp": [
+                    ":node_modules/@mycorp/pkg-b",
+                    ":node_modules/@mycorp/pkg-d",
+                ],
             }
     for link_fn in imported_links:
         new_link_targets, new_scope_targets = link_fn(name, prod, dev)
@@ -2779,7 +2798,10 @@
             ])
     elif bazel_package == "examples/npm_package/packages/pkg_e":
         if prod:
-            link_targets.extend([":node_modules/@mycorp/pkg-d"])
+            link_targets.extend([
+                ":node_modules/@mycorp/pkg-b",
+                ":node_modules/@mycorp/pkg-d",
+            ])
     return link_targets
 
 # Generated npm_link_package_store for linking of first-party "js_lib_pkg_a" package
@@ -2809,10 +2831,19 @@
         src = "//:.aspect_rules_js/node_modules/@lib+test2@0.0.0",
     )
 
-# Generated npm_link_package_store for linking of first-party "@mycorp/pkg-d" package
+# Generated npm_link_package_store for linking of first-party "@mycorp/pkg-b" package
 # buildifier: disable=function-docstring
 def _fp_link_5(alias = None):
     _npm_local_link_package_store(
+        name = "node_modules/@mycorp/pkg-b" if alias == None else "node_modules/{}".format(alias),
+        package = alias,
+        src = "//:.aspect_rules_js/node_modules/@mycorp+pkg-b@0.0.0",
+    )
+
+# Generated npm_link_package_store for linking of first-party "@mycorp/pkg-d" package
+# buildifier: disable=function-docstring
+def _fp_link_6(alias = None):
+    _npm_local_link_package_store(
         name = "node_modules/@mycorp/pkg-d" if alias == None else "node_modules/{}".format(alias),
         package = alias,
         src = "//:.aspect_rules_js/node_modules/@mycorp+pkg-d@0.0.0",
@@ -2820,7 +2851,7 @@
 
 # Generated npm_link_package_store for linking of first-party "@mycorp/pkg-a" package
 # buildifier: disable=function-docstring
-def _fp_link_6(alias = None):
+def _fp_link_7(alias = None):
     _npm_local_link_package_store(
         name = "node_modules/@mycorp/pkg-a" if alias == None else "node_modules/{}".format(alias),
         package = alias,
diff --git a/npm/private/test/snapshots/npm_defs-no_optional.bzl b/npm/private/test/snapshots/npm_defs-no_optional.bzl
index 655ebed..4c3af6e 100644
--- a/npm/private/test/snapshots/npm_defs-no_optional.bzl
+++ b/npm/private/test/snapshots/npm_defs-no_optional.bzl
@@ -2016,12 +2016,25 @@
             package = "@mycorp/pkg-e",
             version = "0.0.0",
             deps = {
+                "//:.aspect_rules_js/node_modules/@mycorp+pkg-b@0.0.0": "@mycorp/pkg-b",
                 "//:.aspect_rules_js/node_modules/@mycorp+pkg-d@0.0.0": "@mycorp/pkg-d",
             },
             visibility = ["//visibility:public"],
             tags = ["manual"],
         )
         _npm_local_package_store(
+            package_store_name = "@mycorp+pkg-b@0.0.0",
+            src = "//examples/npm_package/packages/pkg_b:pkg",
+            package = "@mycorp/pkg-b",
+            version = "0.0.0",
+            deps = {
+                "//:.aspect_rules_js/node_modules/acorn@8.7.1": "acorn",
+                "//:.aspect_rules_js/node_modules/uuid@8.3.2": "uuid",
+            },
+            visibility = ["//visibility:public"],
+            tags = ["manual"],
+        )
+        _npm_local_package_store(
             package_store_name = "test-npm_package@0.0.0",
             src = "//npm/private/test/npm_package:pkg",
             package = "test-npm_package",
@@ -2177,7 +2190,7 @@
             link_886(dev=True)
             link_898(dev=True)
             link_917(dev=True)
-            _fp_link_8()
+            _fp_link_9()
             link_targets = [
                 ":node_modules/@fastify/send",
                 ":node_modules/@figma/nodegit",
@@ -2475,9 +2488,16 @@
             }
         elif bazel_package == "examples/npm_package/packages/pkg_e":
             _fp_link_6()
-            link_targets = [":node_modules/@mycorp/pkg-d"]
+            _fp_link_8()
+            link_targets = [
+                ":node_modules/@mycorp/pkg-d",
+                ":node_modules/@mycorp/pkg-b",
+            ]
             scope_targets = {
-                "@mycorp": [":node_modules/@mycorp/pkg-d"],
+                "@mycorp": [
+                    ":node_modules/@mycorp/pkg-d",
+                    ":node_modules/@mycorp/pkg-b",
+                ],
             }
     for link_fn in imported_links:
         new_link_targets, new_scope_targets = link_fn(name, prod, dev)
@@ -2763,7 +2783,10 @@
             ])
     elif bazel_package == "examples/npm_package/packages/pkg_e":
         if prod:
-            link_targets.extend([":node_modules/@mycorp/pkg-d"])
+            link_targets.extend([
+                ":node_modules/@mycorp/pkg-d",
+                ":node_modules/@mycorp/pkg-b",
+            ])
     return link_targets
 
 # Generated npm_link_package_store for linking of first-party "@mycorp/pkg-a" package
@@ -2820,10 +2843,19 @@
         src = "//:.aspect_rules_js/node_modules/@mycorp+pkg-e@0.0.0",
     )
 
-# Generated npm_link_package_store for linking of first-party "test-npm_package" package
+# Generated npm_link_package_store for linking of first-party "@mycorp/pkg-b" package
 # buildifier: disable=function-docstring
 def _fp_link_8(alias = None):
     _npm_local_link_package_store(
+        name = "node_modules/@mycorp/pkg-b" if alias == None else "node_modules/{}".format(alias),
+        package = alias,
+        src = "//:.aspect_rules_js/node_modules/@mycorp+pkg-b@0.0.0",
+    )
+
+# Generated npm_link_package_store for linking of first-party "test-npm_package" package
+# buildifier: disable=function-docstring
+def _fp_link_9(alias = None):
+    _npm_local_link_package_store(
         name = "node_modules/test-npm_package" if alias == None else "node_modules/{}".format(alias),
         package = alias,
         src = "//:.aspect_rules_js/node_modules/test-npm_package@0.0.0",
diff --git a/npm/private/test/snapshots/npm_defs.bzl b/npm/private/test/snapshots/npm_defs.bzl
index 388ce63..1bc2d46 100644
--- a/npm/private/test/snapshots/npm_defs.bzl
+++ b/npm/private/test/snapshots/npm_defs.bzl
@@ -1203,7 +1203,7 @@
     "js/private/test/image": ["@mycorp/pkg-a", "@mycorp/pkg-d", "acorn"],
     "examples/js_lib_pkg/b": ["js_lib_pkg_a", "@types/node"],
     "examples/linked_consumer": ["@lib/test", "@lib/test2"],
-    "examples/npm_package/packages/pkg_e": ["@mycorp/pkg-d"],
+    "examples/npm_package/packages/pkg_e": ["@mycorp/pkg-d", "@mycorp/pkg-b"],
     "npm/private/test": ["test-npm_package", "@fastify/send", "@figma/nodegit", "@kubernetes/client-node", "@plotly/regl", "regl", "bufferutil", "debug", "esbuild", "handlebars-helpers/helper-date", "hot-shots", "inline-fixtures", "json-stable-stringify", "lodash", "lodash-4.17.21", "lodash-4.17.21-tar", "node-gyp", "plotly.js", "pngjs", "protoc-gen-grpc", "puppeteer", "segfault-handler", "semver-first-satisfied", "syncpack", "typescript", "unused", "webpack-bundle-analyzer"],
     "examples/linked_lib": ["@aspect-test/e", "alias-e", "@aspect-test/e-dev", "@aspect-test/f", "@types/node"],
     "examples/linked_pkg": ["@aspect-test/e", "alias-e", "@aspect-test/e-dev", "@aspect-test/f", "@types/node"],
@@ -2506,12 +2506,25 @@
             package = "@mycorp/pkg-e",
             version = "0.0.0",
             deps = {
+                "//:.aspect_rules_js/node_modules/@mycorp+pkg-b@0.0.0": "@mycorp/pkg-b",
                 "//:.aspect_rules_js/node_modules/@mycorp+pkg-d@0.0.0": "@mycorp/pkg-d",
             },
             visibility = ["//visibility:public"],
             tags = ["manual"],
         )
         _npm_local_package_store(
+            package_store_name = "@mycorp+pkg-b@0.0.0",
+            src = "//examples/npm_package/packages/pkg_b:pkg",
+            package = "@mycorp/pkg-b",
+            version = "0.0.0",
+            deps = {
+                "//:.aspect_rules_js/node_modules/acorn@8.7.1": "acorn",
+                "//:.aspect_rules_js/node_modules/uuid@8.3.2": "uuid",
+            },
+            visibility = ["//visibility:public"],
+            tags = ["manual"],
+        )
+        _npm_local_package_store(
             package_store_name = "test-npm_package@0.0.0",
             src = "//npm/private/test/npm_package:pkg",
             package = "test-npm_package",
@@ -2669,7 +2682,7 @@
             link_1107(dev=True)
             link_1121(dev=True)
             link_1140(dev=True)
-            _fp_link_8()
+            _fp_link_9()
             link_targets = [
                 ":node_modules/@fastify/send",
                 ":node_modules/@figma/nodegit",
@@ -2966,9 +2979,16 @@
             }
         elif bazel_package == "examples/npm_package/packages/pkg_e":
             _fp_link_6()
-            link_targets = [":node_modules/@mycorp/pkg-d"]
+            _fp_link_8()
+            link_targets = [
+                ":node_modules/@mycorp/pkg-d",
+                ":node_modules/@mycorp/pkg-b",
+            ]
             scope_targets = {
-                "@mycorp": [":node_modules/@mycorp/pkg-d"],
+                "@mycorp": [
+                    ":node_modules/@mycorp/pkg-d",
+                    ":node_modules/@mycorp/pkg-b",
+                ],
             }
     for link_fn in imported_links:
         new_link_targets, new_scope_targets = link_fn(name, prod, dev)
@@ -3254,7 +3274,10 @@
             ])
     elif bazel_package == "examples/npm_package/packages/pkg_e":
         if prod:
-            link_targets.extend([":node_modules/@mycorp/pkg-d"])
+            link_targets.extend([
+                ":node_modules/@mycorp/pkg-d",
+                ":node_modules/@mycorp/pkg-b",
+            ])
     return link_targets
 
 # Generated npm_link_package_store for linking of first-party "@mycorp/pkg-a" package
@@ -3314,10 +3337,19 @@
         link_visibility = ["//examples:__subpackages__"],
     )
 
-# Generated npm_link_package_store for linking of first-party "test-npm_package" package
+# Generated npm_link_package_store for linking of first-party "@mycorp/pkg-b" package
 # buildifier: disable=function-docstring
 def _fp_link_8(alias = None):
     _npm_local_link_package_store(
+        name = "node_modules/@mycorp/pkg-b" if alias == None else "node_modules/{}".format(alias),
+        package = alias,
+        src = "//:.aspect_rules_js/node_modules/@mycorp+pkg-b@0.0.0",
+    )
+
+# Generated npm_link_package_store for linking of first-party "test-npm_package" package
+# buildifier: disable=function-docstring
+def _fp_link_9(alias = None):
+    _npm_local_link_package_store(
         name = "node_modules/test-npm_package" if alias == None else "node_modules/{}".format(alias),
         package = alias,
         src = "//:.aspect_rules_js/node_modules/test-npm_package@0.0.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index f6b2adb..a4bdeaa 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -230,6 +230,9 @@
 
   examples/npm_package/packages/pkg_e:
     dependencies:
+      '@mycorp/pkg-b':
+        specifier: workspace:*
+        version: link:../pkg_b
       '@mycorp/pkg-d':
         specifier: workspace:*
         version: link:../pkg_d