Skip to content

Commit f41f1d3

Browse files
authored
Relax package-lock lint to only check top-level dependencies (#58125)
1 parent 2815802 commit f41f1d3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

.github/workflows/package-lock-lint.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
run: |
3838
npm --version
3939
40+
# Save the current top-level dependencies from package-lock.json
41+
node -e "console.log(JSON.stringify(require('./package-lock.json').packages['']))" > /tmp/before.json
42+
4043
# From https://docs.npmjs.com/cli/v7/commands/npm-install
4144
#
4245
# The --package-lock-only argument will only update the
@@ -45,9 +48,16 @@ jobs:
4548
#
4649
npm install --package-lock-only --ignore-scripts --include=optional
4750
48-
# If the package.json (dependencies and devDependencies) is
49-
# in correct sync with package-lock.json running the above command
50-
# should *not* make an edit to the package-lock.json. I.e.
51-
# running `git status` should
52-
# say "nothing to commit, working tree clean".
53-
git diff --exit-code
51+
# Extract the top-level dependencies after regeneration
52+
node -e "console.log(JSON.stringify(require('./package-lock.json').packages['']))" > /tmp/after.json
53+
54+
# Compare only the top-level package dependencies
55+
# This ignores platform-specific differences in nested dependency resolution
56+
# (like "peer" flags) that don't affect actual installed versions
57+
if ! diff /tmp/before.json /tmp/after.json; then
58+
echo "ERROR: Top-level dependencies in package-lock.json are out of sync with package.json"
59+
echo "Please run 'npm install' locally and commit the updated package-lock.json"
60+
exit 1
61+
fi
62+
63+
echo "✓ Top-level dependencies are in sync"

0 commit comments

Comments
 (0)