-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscript.update-package.js
More file actions
23 lines (20 loc) · 984 Bytes
/
script.update-package.js
File metadata and controls
23 lines (20 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const fs = require('node:fs');
const path = require('node:path');
const childProcess = require('node:child_process');
const createHash = require('webpack/lib/util/createHash');
const weblog = require('webpack-log');
const logger = weblog({ name: 'update-package' });
const hashFilepath = path.resolve('./package-lock.hash');
const lockFilepath = path.resolve('./package-lock.json');
const currentFilehash = fs.existsSync(hashFilepath) ? fs.readFileSync(hashFilepath).toString() : null;
const makeFilehash = () => createHash('xxhash64').update(fs.readFileSync(lockFilepath).toString()).digest('hex');
const hashOnly = process.argv.slice(2).includes('--hash-only');
if (!currentFilehash || currentFilehash !== makeFilehash()) {
if (!hashOnly) {
logger.info('npm install...');
childProcess.execSync('npm install', { stdio: 'inherit' });
}
fs.writeFileSync(hashFilepath, makeFilehash());
logger.info('updated package-lock.hash');
console.log('');
}