-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage-update.js
More file actions
22 lines (18 loc) · 940 Bytes
/
package-update.js
File metadata and controls
22 lines (18 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import fs from 'node:fs';
import pkg from './package.json' with { type: 'json' };
import pkgLock from './package-lock.json' with { type: 'json' };
for (const [p, ver] of Object.entries(pkg.dependencies)) {
let val = ver.slice(0, 1);
if (ver.slice(1) != pkgLock.packages[`node_modules/${p}`].version) {
pkg.dependencies[p] = val + pkgLock.packages[`node_modules/${p}`].version;
console.log(` - Updated ${p} from ${ver} to ${pkgLock.packages[`node_modules/${p}`].version}`);
}
}
for (const [p, ver] of Object.entries(pkg.devDependencies)) {
let val = ver.slice(0, 1);
if (ver.slice(1) != pkgLock.packages[`node_modules/${p}`].version) {
pkg.devDependencies[p] = val + pkgLock.packages[`node_modules/${p}`].version;
console.log(` - Updated ${p} from ${ver} to ${pkgLock.packages[`node_modules/${p}`].version}`);
}
}
fs.writeFileSync('package.json', JSON.stringify(pkg, void 0, 4))