Repository navigation
fix(release): strip unused npm and corepack from bundled node #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e098ae
fix(release): strip unused npm and corepack from bundled node
cbartz fd4c0be
ci(build): strip bundled npm in PR builds via a shared script
cbartz 9c33ade
fix(ci): avoid pipefail false negative in bundled npm check
cbartz 6c0c2de
fix(ci): fail when a bundled node binary is missing
cbartz 17ac084
fix(ci): fail when bundled node cannot report its version
cbartz 4245b29
Merge branch 'main' into fix/strip-bundled-npm
cbartz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env bash | ||
| # Fork-only: remove the npm and corepack bundled with Node from a runner layout. | ||
| # The runner only executes externals/node*/bin/node; npm and corepack are unused and pin | ||
| # vulnerable dependencies (tar, minimatch, undici, ...) that would otherwise ship in every | ||
| # package. Lives outside src/ so upstream merges stay clean. | ||
| # | ||
| # Usage: strip-bundled-npm.sh <layout-dir> <runtime> | ||
| set -euo pipefail | ||
| layout="$1" | ||
| runtime="$2" | ||
|
|
||
| shopt -s nullglob | ||
| nodes=("$layout"/externals/node*/) | ||
| if [ ${#nodes[@]} -eq 0 ]; then | ||
| echo "::error::No bundled Node found in $layout/externals" | ||
| exit 1 | ||
| fi | ||
| for d in "${nodes[@]}"; do | ||
| rm -rf "${d}lib/node_modules/npm" "${d}lib/node_modules/corepack" \ | ||
| "${d}bin/npm" "${d}bin/npx" "${d}bin/corepack" | ||
| done | ||
| leftover="$(find "$layout/externals" \( -path '*/node_modules/npm' -o -path '*/node_modules/corepack' \ | ||
| -o -path '*/bin/npm' -o -path '*/bin/npx' -o -path '*/bin/corepack' \) -print -quit)" | ||
| if [ -n "$leftover" ]; then | ||
| echo "::error::npm or corepack is still bundled in $layout/externals: $leftover" | ||
| exit 1 | ||
| fi | ||
| for d in "${nodes[@]}"; do | ||
| if [ ! -x "${d}bin/node" ]; then | ||
| echo "::error::${d}bin/node is missing" | ||
| exit 1 | ||
| fi | ||
| # Alpine builds need musl, and linux-arm (armv7l) cannot run on the arm64 build host; | ||
| # the package tests cover those. | ||
| case "$d" in *_alpine/) continue ;; esac | ||
| if [ "$runtime" != linux-arm ]; then | ||
| version="$("${d}bin/node" --version)" | ||
| echo "${d}bin/node $version" | ||
| fi | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.