Repository navigation
fix(renovate): allow npm remote fetches in Renovate lockfile updates (npm/cli#9800) #536
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
Draft
DevSecNinja
wants to merge
2
commits into
main
Choose a base branch
from
devsecninja-npm-allow-remote
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
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
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,44 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Contract test for the npm 12 EALLOWREMOTE workaround (npm/cli#9800) in the | ||
| # shared presets. The `npmrc` override must stay as narrow as possible: | ||
| # | ||
| # - only in the npm manager block, never at the top level or in packageRules, | ||
| # so no other manager is affected. Renovate's npm manager also writes it for | ||
| # pnpm and Yarn lockfile updates; neither has an allow-remote setting, so for | ||
| # them the line is inert; | ||
| # - only `allow-remote=all`: no allow-git, registry, script or auth settings; | ||
| # - with npmrcMerge, so a repository's own .npmrc is kept and can override it. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
|
|
||
| fail() { | ||
| echo "error: $*" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| command -v pyjson5 >/dev/null 2>&1 || fail "'pyjson5' not found on PATH. Run via 'mise run test'." | ||
|
|
||
| found=0 | ||
| for file in "${repo_root}"/.renovate/*.json5; do | ||
| name="$(basename "${file}")" | ||
| config="$(pyjson5 --as-json "${file}" | tr -d '\r')" | ||
| misplaced="$(jq -r '[paths(objects) as $p | select(getpath($p) | has("npmrc")) | $p | map(tostring) | join(".")] | ||
| | map(select(. != "npm")) | join(", ")' <<<"${config}")" | ||
| [ -z "${misplaced}" ] || fail "${name}: npmrc is only allowed in the npm manager block, found at: ${misplaced}" | ||
| if jq -e 'has("npmrc")' <<<"${config}" >/dev/null; then | ||
| fail "${name}: a top-level npmrc would reach every manager and, without npmrcMerge, replace repository .npmrc files" | ||
| fi | ||
| jq -e '.npm.npmrc' <<<"${config}" >/dev/null || continue | ||
| found=$((found + 1)) | ||
| settings="$(jq -r '.npm.npmrc | split("\n") | map(select(test("^\\s*([#;].*)?$") | not)) | join(" ")' <<<"${config}")" | ||
| [ "${settings}" = "allow-remote=all" ] || | ||
| fail "${name}: npm.npmrc may only set allow-remote=all (npm/cli#9800 workaround), found: ${settings}" | ||
| jq -e '.npm.npmrcMerge == true' <<<"${config}" >/dev/null || | ||
| fail "${name}: npm.npmrc needs npmrcMerge: true, otherwise it replaces the repository's own .npmrc" | ||
| done | ||
| [ "${found}" -le 1 ] || fail "npm.npmrc is set in ${found} presets; keep the workaround in one place" | ||
|
|
||
| echo "Renovate npm allow-remote workaround: OK" |
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.