-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tooling: Ignore optional changes to lockfile
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,33 @@ | ||
// npm will introduce changes to a `package-lock.json` file for optional | ||
// dependencies varying on environment. Disregard from a git diff result when | ||
// only changes are addition of "optional" flag in `package-lock.json` file. | ||
// | ||
// See: https://github.com/npm/npm/issues/17722 | ||
|
||
// Example usage: | ||
// | ||
// git diff -U0 | xargs -0 node bin/process-git-diff | ||
|
||
// Example input: | ||
// | ||
// diff --git a/package-lock.json b/package-lock.json | ||
// index e8c8a25dc..251af8689 100644 | ||
// --- a/package-lock.json | ||
// +++ b/package-lock.json | ||
// @@ -14373 +14373,2 @@ | ||
// - "dev": true | ||
// + "dev": true, | ||
// + "optional": true | ||
// @@ -14648 +14649,2 @@ | ||
// - "dev": true | ||
// + "dev": true, | ||
// + "optional": true | ||
|
||
const hasNonOptionalDiff = !! ( process.argv[ 2 ] || '' ) | ||
// Strip individual diffs of optional-only. | ||
.replace( /@@ .+ @@\n(-.+\n\+.+,\n)?\+.+\"optional\": true,?\n/gm, '' ) | ||
// If no more line diffs remain after above, remove diff heading for file. | ||
.replace( /diff --git a\/package-lock.json b\/package-lock.json\nindex \w+..\w+ \d+\n--- a\/package-lock.json\n\+\+\+ b\/package-lock.json\n(?!@@)/, '' ); | ||
|
||
// Exit with error code if, after replace, changes still exist. | ||
process.exit( hasNonOptionalDiff ? 1 : 0 ); |
This file contains 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