From 22c85e5796fdc4f8bbfc0d330f9cae0194de5413 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 28 Sep 2018 10:21:47 -0400 Subject: [PATCH 1/3] Testing: Fail CI build if local changes exist --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a31c837258466..63ba05d3fa5a25 100644 --- a/package.json +++ b/package.json @@ -151,7 +151,9 @@ "build": "npm run build:packages && cross-env NODE_ENV=production webpack", "check-engines": "check-node-version --package", "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"", - "ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\"", + "precheck-local-changes": "npm run docs:build", + "check-local-changes": "git diff --exit-code > /dev/null || ( echo \"There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!\" && exit 1 );", + "ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\" \"npm run check-local-changes\"", "predev": "npm run check-engines", "dev": "npm run build:packages && concurrently \"cross-env webpack --watch\" \"npm run dev:packages\"", "dev:packages": "node ./bin/packages/watch.js", From fa44d86b25bd2022b7676530b077014f08689be6 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 12 Oct 2018 11:15:08 -0400 Subject: [PATCH 2/3] Tooling: Ignore optional changes to lockfile --- bin/process-git-diff.js | 33 +++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 bin/process-git-diff.js diff --git a/bin/process-git-diff.js b/bin/process-git-diff.js new file mode 100644 index 00000000000000..c7c983fc9e4a6a --- /dev/null +++ b/bin/process-git-diff.js @@ -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 ); diff --git a/package.json b/package.json index 63ba05d3fa5a25..1b8e0ce2e6c2cd 100644 --- a/package.json +++ b/package.json @@ -152,7 +152,7 @@ "check-engines": "check-node-version --package", "check-licenses": "concurrently \"wp-scripts check-licenses --prod --gpl2\" \"wp-scripts check-licenses --dev\"", "precheck-local-changes": "npm run docs:build", - "check-local-changes": "git diff --exit-code > /dev/null || ( echo \"There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!\" && exit 1 );", + "check-local-changes": "( git diff -U0 | xargs -0 node bin/process-git-diff ) || ( echo \"There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!\" && exit 1 );", "ci": "concurrently \"npm run lint\" \"npm run test-unit:coverage-ci\" \"npm run check-local-changes\"", "predev": "npm run check-engines", "dev": "npm run build:packages && concurrently \"cross-env webpack --watch\" \"npm run dev:packages\"", From da292376571b6c97278086cd8f38b3837c771149 Mon Sep 17 00:00:00 2001 From: Matthew Riley MacPherson Date: Fri, 12 Oct 2018 23:45:24 +0100 Subject: [PATCH 3/3] chore: Tweak diff script comment --- bin/process-git-diff.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/process-git-diff.js b/bin/process-git-diff.js index c7c983fc9e4a6a..b80b117daa59e4 100644 --- a/bin/process-git-diff.js +++ b/bin/process-git-diff.js @@ -1,6 +1,7 @@ // 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. +// dependencies varying on environment. If the only changes are the +// addition of an "optional" flag in `package-lock.json` file from +// `git diff`: we ignore the results. // // See: https://github.com/npm/npm/issues/17722