5 // node scripts/filter-package-lock-json-to-update-graceful-fs-for-gulp.js
6 // rm -rf ./node_modules
10 // See https://stackoverflow.com/a/58394828/796832
12 // We're removing all of the resolved entries in `package-lock.json`
13 // for `graceful-fs` so it can install the latest next time we `npm install`
15 // For example, we had 115 references to `graceful-fs` before and after running
16 // this script we have 60 because all of gulp packages are just relying
17 // on a single `graceful-fs@4.2.6` version now!
19 const path = require('path');
20 const fs = require('fs').promises;
21 const lockfile = require('../package-lock.json');
23 function recurseOverLockfile(lockfile) {
24 if (lockfile.dependencies) {
25 // Remove all of the `graceful-fs` entries defining the resolved package
26 Object.keys(lockfile.dependencies).forEach(depKey => {
27 if (depKey === 'graceful-fs') {
28 delete lockfile.dependencies[depKey];
30 lockfile.dependencies[depKey] = recurseOverLockfile(lockfile.dependencies[depKey]);
35 if (lockfile.requires) {
36 // Update all of the `graceful-fs` entries for the new version
37 Object.keys(lockfile.requires).forEach(depKey => {
38 if (depKey === 'graceful-fs') {
39 lockfile.requires[depKey] = '^4.2.6';
47 async function exec() {
48 const resultantLockfile = recurseOverLockfile(lockfile);
51 path.join(__dirname, '../package-lock.json'),
52 JSON.stringify(resultantLockfile, null, 2)