-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build Tools: Validate package-lock.json for "resolved" errors (#22237)
* Build Tools: Validate package-lock.json for "resolved" errors * Build Tooling: Document script purpose * Build Tools: Ignore package-lock TypeScript error
- Loading branch information
Showing
3 changed files
with
47 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 |
---|---|---|
|
@@ -17,5 +17,6 @@ | |
"./api-docs/update-api-docs.js", | ||
"./check-latest-npm.js", | ||
"./changelog.js", | ||
"./validate-package-lock.js", | ||
] | ||
} |
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,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 ) ); | ||
} | ||
} |
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