Skip to content

Commit 0327376

Browse files
chore/pin-dependency-versions
chore(deps): pin dependency versions and add version pinning script
2 parents a17c072 + bc0f511 commit 0327376

File tree

4 files changed

+159
-76
lines changed

4 files changed

+159
-76
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pids
1515
*.pid
1616
*.seed
1717
*.pid.lock
18+
.DS_Store
19+
1820

1921
# Directory for instrumented libs generated by jscoverage/JSCover
2022
lib-cov

package-lock.json

Lines changed: 40 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,45 @@
1818
"lint": "next lint"
1919
},
2020
"dependencies": {
21-
"@next/third-parties": "^15.4.0-canary.51",
22-
"@radix-ui/react-checkbox": "^1.3.2",
23-
"@radix-ui/react-dialog": "^1.1.13",
24-
"@radix-ui/react-dropdown-menu": "^2.1.6",
25-
"@radix-ui/react-label": "^2.1.6",
26-
"@radix-ui/react-select": "^2.2.4",
27-
"@radix-ui/react-separator": "^1.1.6",
28-
"@radix-ui/react-slot": "^1.1.2",
29-
"@radix-ui/react-switch": "^1.2.4",
30-
"@radix-ui/react-tabs": "^1.1.3",
31-
"@types/js-cookie": "^3.0.6",
32-
"bcryptjs": "^3.0.2",
33-
"class-variance-authority": "^0.7.1",
34-
"cloudinary": "^2.6.1",
35-
"clsx": "^2.1.1",
36-
"dotenv": "^16.5.0",
37-
"js-cookie": "^3.0.5",
38-
"jsonwebtoken": "^9.0.2",
39-
"lucide-react": "^0.477.0",
40-
"mongoose": "^8.14.2",
41-
"next": "15.1.7",
42-
"next-themes": "^0.4.6",
43-
"pdfkit": "^0.17.2",
44-
"pptxgenjs": "^4.0.1",
45-
"react": "^19.0.0",
46-
"react-dom": "^19.0.0",
47-
"react-force-graph-2d": "^1.27.1",
48-
"tailwind-merge": "^3.0.2",
49-
"tailwindcss-animate": "^1.0.7"
21+
"@next/third-parties": "15.4.0-canary.51",
22+
"@radix-ui/react-checkbox": "1.3.2",
23+
"@radix-ui/react-dialog": "1.1.13",
24+
"@radix-ui/react-dropdown-menu": "2.1.6",
25+
"@radix-ui/react-label": "2.1.6",
26+
"@radix-ui/react-select": "2.2.4",
27+
"@radix-ui/react-separator": "1.1.6",
28+
"@radix-ui/react-slot": "1.1.2",
29+
"@radix-ui/react-switch": "1.2.4",
30+
"@radix-ui/react-tabs": "1.1.3",
31+
"@types/js-cookie": "3.0.6",
32+
"bcryptjs": "3.0.2",
33+
"class-variance-authority": "0.7.1",
34+
"cloudinary": "2.6.1",
35+
"clsx": "2.1.1",
36+
"dotenv": "16.5.0",
37+
"js-cookie": "3.0.5",
38+
"jsonwebtoken": "9.0.2",
39+
"lucide-react": "0.477.0",
40+
"mongoose": "8.14.2",
41+
"next": "15.1.9",
42+
"next-themes": "0.4.6",
43+
"pdfkit": "0.17.2",
44+
"pptxgenjs": "4.0.1",
45+
"react": "19.0.0",
46+
"react-dom": "19.0.0",
47+
"react-force-graph-2d": "1.27.1",
48+
"tailwind-merge": "3.0.2",
49+
"tailwindcss-animate": "1.0.7"
5050
},
5151
"devDependencies": {
52-
"@types/jsonwebtoken": "^9.0.9",
53-
"@types/node": "^20",
54-
"@types/react": "^19",
55-
"@types/react-dom": "^19",
52+
"@types/jsonwebtoken": "9.0.9",
53+
"@types/node": "20.17.22",
54+
"@types/react": "19.0.10",
55+
"@types/react-dom": "19.0.4",
5656
"eslint": "9.26.0",
5757
"eslint-config-next": "15.3.2",
58-
"postcss": "^8",
59-
"tailwindcss": "^3.4.1",
60-
"typescript": "^5"
58+
"postcss": "8.5.3",
59+
"tailwindcss": "3.4.17",
60+
"typescript": "5.8.2"
6161
}
6262
}

scripts/pin-versions.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Sync dependency versions in package.json with the versions installed in node_modules.
5+
* Affects dependencies, devDependencies and peerDependencies.
6+
*/
7+
8+
const fs = require("fs");
9+
const path = require("path");
10+
11+
const ROOT_DIR = process.cwd();
12+
const PACKAGE_JSON_PATH = path.join(ROOT_DIR, "package.json");
13+
const NODE_MODULES_DIR = path.join(ROOT_DIR, "node_modules");
14+
15+
function readJson(filePath) {
16+
try {
17+
const raw = fs.readFileSync(filePath, "utf8");
18+
return JSON.parse(raw);
19+
} catch (err) {
20+
console.error(`Failed to read or parse ${filePath}`);
21+
console.error(err.message);
22+
process.exit(1);
23+
}
24+
}
25+
26+
function ensurePackageJson() {
27+
if (!fs.existsSync(PACKAGE_JSON_PATH)) {
28+
console.error("package.json not found in the current directory");
29+
process.exit(1);
30+
}
31+
}
32+
33+
function pinSectionDependencies(pkgJson, sectionKey) {
34+
const section = pkgJson[sectionKey];
35+
if (!section || typeof section !== "object") return;
36+
37+
for (const depName of Object.keys(section)) {
38+
const depPackageJsonPath = path.join(NODE_MODULES_DIR, depName, "package.json");
39+
40+
if (!fs.existsSync(depPackageJsonPath)) {
41+
console.warn(`[skip] ${sectionKey}.${depName} not found in node_modules`);
42+
continue;
43+
}
44+
45+
const installedMeta = readJson(depPackageJsonPath);
46+
const installedVersion = installedMeta.version;
47+
48+
if (!installedVersion) {
49+
console.warn(`[skip] ${sectionKey}.${depName} has no version field in its package.json`);
50+
continue;
51+
}
52+
53+
const previous = section[depName];
54+
section[depName] = installedVersion;
55+
56+
console.log(
57+
`[pin] ${sectionKey}.${depName}: ${previous} -> ${installedVersion}`
58+
);
59+
}
60+
}
61+
62+
function writePackageJson(pkgJson) {
63+
fs.writeFileSync(PACKAGE_JSON_PATH, JSON.stringify(pkgJson, null, 2) + "\n", "utf8");
64+
}
65+
66+
function main() {
67+
ensurePackageJson();
68+
69+
const pkgJson = readJson(PACKAGE_JSON_PATH);
70+
71+
pinSectionDependencies(pkgJson, "dependencies");
72+
pinSectionDependencies(pkgJson, "devDependencies");
73+
pinSectionDependencies(pkgJson, "peerDependencies");
74+
75+
writePackageJson(pkgJson);
76+
77+
console.log();
78+
console.log("package.json updated with versions from node_modules");
79+
}
80+
81+
main();

0 commit comments

Comments
 (0)