forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate-package-lock.js
executable file
·43 lines (35 loc) · 1.14 KB
/
validate-package-lock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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 and reverting package-lock.json, then run ${ yellow(
'npm install'
) }.
`
);
process.exit( 1 );
}
if ( dependency.dependencies ) {
dependencies.push( ...Object.entries( dependency.dependencies ) );
}
}