Skip to content

Commit 93f08c7

Browse files
committed
broken: js_library() => npm_package() loads the npm_package() files twice
1 parent 1536b29 commit 93f08c7

8 files changed

Lines changed: 92 additions & 46 deletions

File tree

.aspect/rules/external_repository_action_cache/npm_translate_lock_LTE4Nzc1MDcwNjU=

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "@@//:pnpm-lock.yaml").
33
# This file should be checked into version control along with the pnpm-lock.yaml file.
44
.npmrc=-2065072158
5-
examples/js_binary/package.json=-41174383
5+
examples/js_binary/package.json=1355509971
66
examples/js_lib_pkg/a/package.json=740602849
77
examples/js_lib_pkg/b/package.json=-561926249
88
examples/linked_consumer/package.json=-1109186228
@@ -34,5 +34,5 @@ npm/private/test/vendored/is-odd/package.json=1041695223
3434
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349
3535
npm/private/test/vendored/semver-max/package.json=578664053
3636
package.json=-2040565922
37-
pnpm-lock.yaml=231890567
37+
pnpm-lock.yaml=881679841
3838
pnpm-workspace.yaml=-1336981113

examples/js_binary/BUILD.bazel

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ js_test(
181181
###############################
182182
# Use case 4
183183
# A first-party library which we want to run as a program.
184-
# This relies on @mycorp/pkg-a and @mycorp/pkg-b which are packages within this monorepo.
184+
# This relies on @mycorp/pkg-{a,b,d} which are packages within this monorepo.
185185

186186
write_file(
187187
name = "write4_cjs",
@@ -212,6 +212,7 @@ write_file(
212212
name = "bin4_%s" % t,
213213
data = [
214214
":node_modules/@mycorp/pkg-a",
215+
":node_modules/@mycorp/pkg-e",
215216
"//:node_modules/@mycorp/pkg-b",
216217
],
217218
entry_point = "case4.%s" % t,
@@ -263,6 +264,27 @@ write_file(
263264
file1 = "//examples:expected_one_ast.json",
264265
file2 = ":out4-b_%s" % t,
265266
),
267+
js_run_binary(
268+
name = "run4-e_%s" % t,
269+
outs = ["out4-e_%s" % t],
270+
args = [
271+
"out4-e_%s" % t,
272+
"@mycorp/pkg-e",
273+
],
274+
chdir = package_name(),
275+
# This specifically tests that a `select` and `|` operator can be used when setting `env`.
276+
env = {} | select({
277+
"//conditions:default": {
278+
"NODE_ENV": "production",
279+
},
280+
}),
281+
tool = ":bin4_%s" % t,
282+
),
283+
diff_test(
284+
name = "test4-e_%s" % t,
285+
file1 = "//examples:expected_one_ast.json",
286+
file2 = ":out4-e_%s" % t,
287+
),
266288
]
267289
for t in [
268290
"mjs",

examples/js_binary/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"private": true,
33
"devDependencies": {
4-
"@mycorp/pkg-a": "workspace:*"
4+
"@mycorp/pkg-a": "workspace:*",
5+
"@mycorp/pkg-e": "workspace:*"
56
}
67
}

examples/npm_package/packages/pkg_e/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ js_library(
1717
# linker when linking a js_libary.
1818
deps = [
1919
":node_modules",
20+
21+
# Manually linked and not in :node_modules
22+
"//:node_modules/@mycorp/pkg-b",
2023
],
2124
)

examples/npm_package/packages/pkg_e/index.cjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const { sandboxAssert: dSandboxAssert } = require('@mycorp/pkg-d')
1+
const { sandboxAssert: bSandboxAssert } = require('@mycorp/pkg-b')
2+
const { sandboxAssert: dSandboxAssert, toAst } = require('@mycorp/pkg-d')
23

34
function sandboxAssert() {
45
if (!/-sandbox\/\d+\/execroot\//.test(__filename)) {
@@ -11,10 +12,13 @@ function sandboxAssert() {
1112
throw new Error(`Not runfiles: ${__filename}`)
1213
}
1314

15+
bSandboxAssert()
1416
dSandboxAssert()
17+
require('@mycorp/pkg-b').sandboxAssert()
1518
require('@mycorp/pkg-d').sandboxAssert()
1619
}
1720

1821
sandboxAssert()
1922

23+
module.exports.toAst = toAst
2024
module.exports.sandboxAssert = sandboxAssert

examples/npm_package/packages/pkg_e/index.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { fileURLToPath } from 'node:url'
77

8+
import { sandboxAssert as bSandboxAssert } from '@mycorp/pkg-b'
89
import { sandboxAssert as dSandboxAssert } from '@mycorp/pkg-d'
910
export { getAcornVersion, toAst, uuid } from '@mycorp/pkg-d'
1011

@@ -23,8 +24,10 @@ export async function sandboxAssert() {
2324

2425
// Static import of pkg-d
2526
dSandboxAssert()
27+
bSandboxAssert()
2628

27-
// Dynamic import of pkg-d
29+
// Dynamic import of pkg-{b,d}
30+
await import('@mycorp/pkg-b').then(({ sandboxAssert }) => sandboxAssert())
2831
await import('@mycorp/pkg-d').then(({ sandboxAssert }) => sandboxAssert())
2932
}
3033

npm/private/test/snapshots/npm_defs.bzl

Lines changed: 50 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)