Skip to content

Commit 009cb50

Browse files
authored
Use CircleCI to enforce "lockfileVersion": 2 in package-lock.json (#9068)
1 parent febbba9 commit 009cb50

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.circleci/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jobs:
66
- image: circleci/node:16.13.0
77
steps:
88
- checkout
9+
- run: npm run ci:precheck
910
- restore_cache:
1011
keys:
1112
# When lock file changes, use increasingly general patterns to
@@ -29,6 +30,7 @@ jobs:
2930
- image: circleci/node:16.13.0
3031
steps:
3132
- checkout
33+
- run: npm run ci:precheck
3234
- restore_cache:
3335
keys:
3436
# When lock file changes, use increasingly general patterns to

config/precheck.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const {
2+
lockfileVersion,
3+
} = require("../package-lock.json");
4+
5+
const expectedVersion = 2;
6+
7+
if (typeof lockfileVersion !== "number" ||
8+
lockfileVersion < expectedVersion) {
9+
throw new Error(
10+
`Old lockfileVersion (${
11+
lockfileVersion
12+
}) found in package-lock.json (expected ${
13+
expectedVersion
14+
} or later)`
15+
);
16+
}
17+
18+
console.log("ok", {
19+
lockfileVersion,
20+
expectedVersion,
21+
});

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"prepdist": "node ./config/prepareDist.js",
4141
"resolve": "ts-node-script config/resolveModuleIds.ts",
4242
"clean": "rimraf -r dist coverage lib temp",
43+
"ci:precheck": "node config/precheck.js",
4344
"test": "jest --config ./config/jest.config.js",
4445
"test:debug": "BABEL_ENV=server node --inspect-brk node_modules/.bin/jest --config ./config/jest.config.js --runInBand --testTimeout 99999",
4546
"test:ci": "npm run test:coverage && npm run test:memory",

0 commit comments

Comments
 (0)