Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"./api-docs/update-api-docs.js",
"./check-latest-npm.js",
"./changelog.js",
"./validate-package-lock.js",
]
}
43 changes: 43 additions & 0 deletions bin/validate-package-lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env node
'use strict';

// This script validates `package-lock.json` to avoid the introduction of an
// erroneous `"resolved": false` value. It appears to be related to an upstream
// unresolved issue with NPM. If the upstream issue is resolved, this script
// should no longer be necessary.
//
// See: https://github.com/npm/cli/issues/1138

/**
* External dependencies
*/
const { red, yellow } = require( 'chalk' );

/**
* Internal dependencies
*/
// Ignore reason: `package-lock.json` exists outside `bin` `rootDir`.
// @ts-ignore
const packageLock = require( '../package-lock' );

const dependencies = Object.entries( packageLock.dependencies );
for ( const [ name, dependency ] of dependencies ) {
if ( dependency.resolved === false ) {
console.log(
`Invalid resolved dependency in package-lock.json.

${ red( JSON.stringify( { [ name ]: dependency }, null, '\t' ) ) }

To fix, try removing the node_modules directory, then run ${ yellow(
'npm install'
) }.
`
);

process.exit( 1 );
}

if ( dependency.dependencies ) {
dependencies.push( ...Object.entries( dependency.dependencies ) );
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,13 @@
"fixtures:generate": "npm run fixtures:server-registered && cross-env GENERATE_MISSING_FIXTURES=y npm run test-unit",
"fixtures:regenerate": "npm run fixtures:clean && npm run fixtures:generate",
"format-js": "wp-scripts format-js",
"lint": "concurrently \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"",
"lint": "concurrently \"npm run lint-lockfile\" \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"",
"lint-js": "wp-scripts lint-js",
"lint-js:fix": "npm run lint-js -- --fix",
"prelint-php": "npm run wp-env run composer install -- --no-interaction",
"lint-php": "npm run wp-env run composer run-script lint",
"lint-pkg-json": "wp-scripts lint-pkg-json . 'packages/*/package.json'",
"lint-lockfile": "node ./bin/validate-package-lock.js",
"lint-css": "wp-scripts lint-style '**/*.scss'",
"lint-css:fix": "npm run lint-css -- --fix",
"lint:md-js": "wp-scripts lint-md-js",
Expand Down Expand Up @@ -255,6 +256,7 @@
},
"lint-staged": {
"package-lock.json": [
"npm run lint-lockfile",
"node ./bin/check-latest-npm.js"
],
"packages/*/package.json": [
Expand Down