Skip to content

Commit

Permalink
fix: ignore multi-segment package.json bin entries (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Apr 26, 2023
1 parent e12b784 commit f7f3316
Show file tree
Hide file tree
Showing 9 changed files with 1,436 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Input hashes for repository rule npm_translate_lock(name = "npm", pnpm_lock = "//:pnpm-lock.yaml").
# This file should be checked into version control along with the pnpm-lock.yaml file.
.npmrc=-2065072158
pnpm-lock.yaml=1633149504
pnpm-lock.yaml=-1687805643
examples/npm_deps/patches/[email protected]=-442666336
package.json=-1057425123
pnpm-workspace.yaml=1536402859
Expand All @@ -16,7 +16,7 @@ js/private/coverage/bundle/package.json=-1543718929
js/private/image/package.json=-967071841
js/private/test/image/package.json=1295393035
js/private/worker/src/package.json=-755964446
npm/private/test/package.json=667716755
npm/private/test/package.json=672603585
npm/private/test/vendored/lodash-4.17.21.tgz=-1206623349
npm/private/test/npm_package/package.json=-1377103079
npm/private/test/vendored/is-odd/package.json=1041695223
Expand Down
6 changes: 6 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ npm.npm_translate_lock(
"no-remote-exec",
"requires-network",
],
"puppeteer": [
"no-sandbox",
# Workaround Engflow not honoring requires-network on build actions
"no-remote-exec",
"requires-network",
],
},
npmrc = "//:.npmrc",
patch_args = {
Expand Down
6 changes: 6 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ npm_translate_lock(
"no-remote-exec",
"requires-network",
],
"puppeteer": [
"no-sandbox",
# Workaround Engflow not honoring requires-network on build actions
"no-remote-exec",
"requires-network",
],
},
npmrc = "//:.npmrc",
patch_args = {
Expand Down
11 changes: 10 additions & 1 deletion npm/private/lifecycle/lifecycle-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,22 @@ async function makeBins(nodeModulesPath, scope, segmentsUp) {
bin = { [_package]: bin }
}
for (const binName of Object.keys(bin)) {
if (binName.includes('/') || binName.includes('\\')) {
// multi-segment bin names are not supported; pnpm itself
// also does not make .bin entries in this case as of pnpm v8.3.1
continue
}
const binPath = normalizeBinPath(bin[binName])
const binBash = `#!/usr/bin/env bash\nexec node "${path.join(
...segmentsUp,
packageName,
binPath
)}" "$@"`
const binEntryPath = path.join(nodeModulesPath, '.bin', binName)
const binEntryPath = path.join(
nodeModulesPath,
'.bin',
binName
)
await fs.promises.writeFile(binEntryPath, binBash)
await fs.promises.chmod(binEntryPath, '755') // executable
}
Expand Down
2 changes: 1 addition & 1 deletion npm/private/lifecycle/min/index.min.js

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions npm/private/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,25 @@ build_test(
targets = [
":node_modules/@blockprotocol/type-system-web",
":node_modules/@figma/nodegit",
# @kubernetes/client-node has a "prepare" lifecycle hook that runs tsc
":node_modules/@kubernetes/client-node",
":node_modules/@kubernetes/client-node", # @kubernetes/client-node has a "prepare" lifecycle hook that runs tsc
":node_modules/@plotly/regl",
":node_modules/bufferutil",
":node_modules/debug",
":node_modules/esbuild",
":node_modules/handlebars-helpers/helper-date",
":node_modules/inline-fixtures",
":node_modules/json-stable-stringify",
# a vendored .tgz file
":node_modules/lodash",
":node_modules/lodash", # lodash is brought in as a vendored .tgz file: vendored/lodash-4.17.21.tgz
":node_modules/node-gyp",
":node_modules/plotly.js",
":node_modules/protoc-gen-grpc",
":node_modules/regl",
# segfault-handler has a node-gyp install step
":node_modules/segfault-handler",
":node_modules/puppeteer", # has a bin entry in the transitive closure with two segments: @puppeteer/browsers in https://unpkg.com/@puppeteer/[email protected]/package.json
":node_modules/segfault-handler", # segfault-handler has a node-gyp install step
":node_modules/semver-first-satisfied",
":node_modules/typescript",
# intentionally don't include node_modules/unused
":node_modules/webpack-bundle-analyzer",
# intentionally don't include :node_modules/unused
],
)

Expand Down
1 change: 1 addition & 0 deletions npm/private/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"node-gyp": "9.3.0",
"plotly.js": "2.12.1",
"protoc-gen-grpc": "git+ssh://[email protected]:gregmagolan-codaio/protoc-gen-grpc-ts#be5580b06348d3eb9b4610a4a94065154a0df41f",
"puppeteer": "19.11.0",
"regl": "npm:@plotly/[email protected]",
"segfault-handler": "1.3.0",
"semver-first-satisfied": "1.1.0",
Expand Down
Loading

0 comments on commit f7f3316

Please sign in to comment.