deplift 0.1.0 ā 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/cjs/index.cjs +124 -0
- package/dist/esm/index.mjs +122 -0
- package/package.json +43 -7
- package/types/index.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Zheng Song
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
var promises = require('node:fs/promises');
|
|
6
|
+
var node_child_process = require('node:child_process');
|
|
7
|
+
var fg = require('fast-glob');
|
|
8
|
+
|
|
9
|
+
const defaultIgnore = ["**/node_modules/**", "**/dist/**", "**/coverage/**", "**/build/**", "**/.next/**", "**/.docusaurus/**"];
|
|
10
|
+
const depSections = ["dependencies", "devDependencies"];
|
|
11
|
+
const args = process.argv.slice(2);
|
|
12
|
+
const dryRun = args.includes("--dry-run");
|
|
13
|
+
if (dryRun) console.log("š” Dry run enabled ā no files will be changed or installed.");
|
|
14
|
+
const stripPrefix = version => version.replace(/^[^0-9]*/, "");
|
|
15
|
+
const loadConfig = async () => {
|
|
16
|
+
const configPath = path.resolve("deplift.config.json");
|
|
17
|
+
try {
|
|
18
|
+
const raw = await promises.readFile(configPath, "utf-8");
|
|
19
|
+
const parsed = JSON.parse(raw);
|
|
20
|
+
if (parsed && typeof parsed === "object") {
|
|
21
|
+
return parsed;
|
|
22
|
+
}
|
|
23
|
+
console.warn(`ā ļø Config file exists but is not a valid object: ${configPath}`);
|
|
24
|
+
} catch (_unused) {
|
|
25
|
+
// no config file or cannot read, ignore silently
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
};
|
|
29
|
+
const fetchLatestVersion = async dep => {
|
|
30
|
+
const {
|
|
31
|
+
pkg
|
|
32
|
+
} = dep;
|
|
33
|
+
try {
|
|
34
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`);
|
|
35
|
+
if (!res.ok) {
|
|
36
|
+
throw new Error(`status: ${res.status}`);
|
|
37
|
+
}
|
|
38
|
+
const json = await res.json();
|
|
39
|
+
return {
|
|
40
|
+
...dep,
|
|
41
|
+
latest: json.version
|
|
42
|
+
};
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.warn(` ā ļø Failed to fetch version for ${pkg}: ${err.message}`);
|
|
45
|
+
}
|
|
46
|
+
return dep;
|
|
47
|
+
};
|
|
48
|
+
async function main() {
|
|
49
|
+
const config = await loadConfig();
|
|
50
|
+
const ignorePatterns = Array.isArray(config.ignore) ? Array.from(new Set([...defaultIgnore, ...config.ignore])) : defaultIgnore;
|
|
51
|
+
const packageFiles = await fg.glob("**/package.json", {
|
|
52
|
+
ignore: ignorePatterns
|
|
53
|
+
});
|
|
54
|
+
if (packageFiles.length === 0) {
|
|
55
|
+
console.log("ā No package.json files found.");
|
|
56
|
+
process.exit(0);
|
|
57
|
+
}
|
|
58
|
+
for (const packageJson of packageFiles) {
|
|
59
|
+
const packageJsonPath = path.resolve(packageJson);
|
|
60
|
+
const pkgRaw = await promises.readFile(packageJsonPath, "utf-8");
|
|
61
|
+
let pkgData;
|
|
62
|
+
try {
|
|
63
|
+
pkgData = JSON.parse(pkgRaw);
|
|
64
|
+
} catch (_unused2) {
|
|
65
|
+
console.warn(`ā ļø Failed to parse JSON in ${packageJson}, skipping.`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
console.log(`\nš¦ Processing: ${packageJson}`);
|
|
69
|
+
const dependencies = depSections.reduce((accu, section) => {
|
|
70
|
+
const sectionData = pkgData[section];
|
|
71
|
+
if (!sectionData) return accu;
|
|
72
|
+
const entries = Object.entries(sectionData).filter(([_, version]) => !version.startsWith("file:")).map(([pkg, current]) => ({
|
|
73
|
+
section,
|
|
74
|
+
pkg,
|
|
75
|
+
current
|
|
76
|
+
}));
|
|
77
|
+
return [...accu, ...entries];
|
|
78
|
+
}, []);
|
|
79
|
+
const latestDeps = await Promise.all(dependencies.map(fetchLatestVersion));
|
|
80
|
+
let updated = false;
|
|
81
|
+
for (const {
|
|
82
|
+
section,
|
|
83
|
+
pkg,
|
|
84
|
+
current,
|
|
85
|
+
latest
|
|
86
|
+
} of latestDeps) {
|
|
87
|
+
// Failed to fetch the pkg
|
|
88
|
+
if (!latest) continue;
|
|
89
|
+
if (stripPrefix(current) === latest) {
|
|
90
|
+
console.log(` ${pkg} is already at latest version (${latest})`);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
console.log(` ā ${section} -> ${pkg}: ${current} ā ^${latest}`);
|
|
94
|
+
updated = true;
|
|
95
|
+
if (!dryRun) {
|
|
96
|
+
pkgData[section][pkg] = `^${latest}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (!updated) {
|
|
100
|
+
console.log(` ā
No changes needed for ${packageJson}.`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (dryRun) {
|
|
104
|
+
console.log(` š„ [Dry run] "npm install" for ${packageJson}.`);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
await promises.writeFile(packageJsonPath, JSON.stringify(pkgData, null, 2) + "\n");
|
|
108
|
+
console.log(` š¾ ${packageJson} updated.`);
|
|
109
|
+
try {
|
|
110
|
+
const targetDir = path.dirname(packageJsonPath);
|
|
111
|
+
console.log(" š„ Installing...");
|
|
112
|
+
node_child_process.execSync("npm install", {
|
|
113
|
+
stdio: "inherit",
|
|
114
|
+
cwd: targetDir
|
|
115
|
+
});
|
|
116
|
+
} catch (err) {
|
|
117
|
+
console.error(` ā Failed to install in ${packageJson}: ${err.message}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
main().then(() => console.log("\n[deplift] ā
All dependency updates completed!")).catch(err => {
|
|
122
|
+
console.error("\n[deplift] ā Unexpected error:", err);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
});
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { execSync } from 'node:child_process';
|
|
5
|
+
import fg from 'fast-glob';
|
|
6
|
+
|
|
7
|
+
const defaultIgnore = ["**/node_modules/**", "**/dist/**", "**/coverage/**", "**/build/**", "**/.next/**", "**/.docusaurus/**"];
|
|
8
|
+
const depSections = ["dependencies", "devDependencies"];
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const dryRun = args.includes("--dry-run");
|
|
11
|
+
if (dryRun) console.log("š” Dry run enabled ā no files will be changed or installed.");
|
|
12
|
+
const stripPrefix = version => version.replace(/^[^0-9]*/, "");
|
|
13
|
+
const loadConfig = async () => {
|
|
14
|
+
const configPath = path.resolve("deplift.config.json");
|
|
15
|
+
try {
|
|
16
|
+
const raw = await readFile(configPath, "utf-8");
|
|
17
|
+
const parsed = JSON.parse(raw);
|
|
18
|
+
if (parsed && typeof parsed === "object") {
|
|
19
|
+
return parsed;
|
|
20
|
+
}
|
|
21
|
+
console.warn(`ā ļø Config file exists but is not a valid object: ${configPath}`);
|
|
22
|
+
} catch (_unused) {
|
|
23
|
+
// no config file or cannot read, ignore silently
|
|
24
|
+
}
|
|
25
|
+
return {};
|
|
26
|
+
};
|
|
27
|
+
const fetchLatestVersion = async dep => {
|
|
28
|
+
const {
|
|
29
|
+
pkg
|
|
30
|
+
} = dep;
|
|
31
|
+
try {
|
|
32
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`);
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw new Error(`status: ${res.status}`);
|
|
35
|
+
}
|
|
36
|
+
const json = await res.json();
|
|
37
|
+
return {
|
|
38
|
+
...dep,
|
|
39
|
+
latest: json.version
|
|
40
|
+
};
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.warn(` ā ļø Failed to fetch version for ${pkg}: ${err.message}`);
|
|
43
|
+
}
|
|
44
|
+
return dep;
|
|
45
|
+
};
|
|
46
|
+
async function main() {
|
|
47
|
+
const config = await loadConfig();
|
|
48
|
+
const ignorePatterns = Array.isArray(config.ignore) ? Array.from(new Set([...defaultIgnore, ...config.ignore])) : defaultIgnore;
|
|
49
|
+
const packageFiles = await fg.glob("**/package.json", {
|
|
50
|
+
ignore: ignorePatterns
|
|
51
|
+
});
|
|
52
|
+
if (packageFiles.length === 0) {
|
|
53
|
+
console.log("ā No package.json files found.");
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
for (const packageJson of packageFiles) {
|
|
57
|
+
const packageJsonPath = path.resolve(packageJson);
|
|
58
|
+
const pkgRaw = await readFile(packageJsonPath, "utf-8");
|
|
59
|
+
let pkgData;
|
|
60
|
+
try {
|
|
61
|
+
pkgData = JSON.parse(pkgRaw);
|
|
62
|
+
} catch (_unused2) {
|
|
63
|
+
console.warn(`ā ļø Failed to parse JSON in ${packageJson}, skipping.`);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
console.log(`\nš¦ Processing: ${packageJson}`);
|
|
67
|
+
const dependencies = depSections.reduce((accu, section) => {
|
|
68
|
+
const sectionData = pkgData[section];
|
|
69
|
+
if (!sectionData) return accu;
|
|
70
|
+
const entries = Object.entries(sectionData).filter(([_, version]) => !version.startsWith("file:")).map(([pkg, current]) => ({
|
|
71
|
+
section,
|
|
72
|
+
pkg,
|
|
73
|
+
current
|
|
74
|
+
}));
|
|
75
|
+
return [...accu, ...entries];
|
|
76
|
+
}, []);
|
|
77
|
+
const latestDeps = await Promise.all(dependencies.map(fetchLatestVersion));
|
|
78
|
+
let updated = false;
|
|
79
|
+
for (const {
|
|
80
|
+
section,
|
|
81
|
+
pkg,
|
|
82
|
+
current,
|
|
83
|
+
latest
|
|
84
|
+
} of latestDeps) {
|
|
85
|
+
// Failed to fetch the pkg
|
|
86
|
+
if (!latest) continue;
|
|
87
|
+
if (stripPrefix(current) === latest) {
|
|
88
|
+
console.log(` ${pkg} is already at latest version (${latest})`);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
console.log(` ā ${section} -> ${pkg}: ${current} ā ^${latest}`);
|
|
92
|
+
updated = true;
|
|
93
|
+
if (!dryRun) {
|
|
94
|
+
pkgData[section][pkg] = `^${latest}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!updated) {
|
|
98
|
+
console.log(` ā
No changes needed for ${packageJson}.`);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (dryRun) {
|
|
102
|
+
console.log(` š„ [Dry run] "npm install" for ${packageJson}.`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
await writeFile(packageJsonPath, JSON.stringify(pkgData, null, 2) + "\n");
|
|
106
|
+
console.log(` š¾ ${packageJson} updated.`);
|
|
107
|
+
try {
|
|
108
|
+
const targetDir = path.dirname(packageJsonPath);
|
|
109
|
+
console.log(" š„ Installing...");
|
|
110
|
+
execSync("npm install", {
|
|
111
|
+
stdio: "inherit",
|
|
112
|
+
cwd: targetDir
|
|
113
|
+
});
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(` ā Failed to install in ${packageJson}: ${err.message}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
main().then(() => console.log("\n[deplift] ā
All dependency updates completed!")).catch(err => {
|
|
120
|
+
console.error("\n[deplift] ā Unexpected error:", err);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deplift",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI to update deps in monorepos",
|
|
5
|
+
"author": "Zheng Song",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/szhsin/deplift.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/szhsin/deplift#readme",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/cjs/index.cjs",
|
|
14
|
+
"module": "./dist/esm/index.mjs",
|
|
15
|
+
"types": "./types/index.d.ts",
|
|
16
|
+
"bin": "./dist/cjs/index.cjs",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/",
|
|
20
|
+
"types/"
|
|
21
|
+
],
|
|
5
22
|
"scripts": {
|
|
6
|
-
"
|
|
23
|
+
"start": "run-p watch \"types -- --watch\"",
|
|
24
|
+
"bundle": "rollup -c",
|
|
25
|
+
"watch": "rollup -c -w",
|
|
26
|
+
"clean": "rm -Rf dist types",
|
|
27
|
+
"types": "tsc",
|
|
28
|
+
"prepare": "rm -Rf types/__tests__",
|
|
29
|
+
"build": "run-s clean types bundle",
|
|
30
|
+
"deplift": "node ./dist/cjs/index.cjs",
|
|
31
|
+
"deplift:dry-run": "node ./dist/cjs/index.cjs --dry-run"
|
|
7
32
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@babel/core": "^7.27.1",
|
|
35
|
+
"@babel/preset-env": "^7.27.2",
|
|
36
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
37
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
38
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
39
|
+
"@types/node": "^22.15.21",
|
|
40
|
+
"npm-run-all": "^4.1.5",
|
|
41
|
+
"rollup": "^4.41.0",
|
|
42
|
+
"typescript": "^5.8.3"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"fast-glob": "^3.3.3"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/types/index.d.ts
ADDED