@deot/dev-updater 2.7.0 → 2.9.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/dist/index.cjs +25 -20
- package/dist/index.js +25 -20
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -29,15 +29,14 @@ function _interopNamespaceDefault(e) {
|
|
|
29
29
|
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
30
30
|
|
|
31
31
|
const fitVersion = (versions, version, commandOptions) => {
|
|
32
|
-
|
|
33
|
-
if (!vRegex.test(version))
|
|
34
|
-
return version;
|
|
32
|
+
const vRegex = /([\d]+\.[\d]+\..*)/;
|
|
33
|
+
if (!vRegex.test(version)) return version;
|
|
35
34
|
const { major = false, minor = false, patch = false } = commandOptions || {};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
const originalPrefix = (version.match(/([^\d]*).*/) || ["", ""])[1];
|
|
36
|
+
const prefix = major ? ">=" : minor ? "^" : patch ? "~" : originalPrefix;
|
|
37
|
+
const oldVersion = version.match(vRegex)[1];
|
|
38
|
+
const vailds = versions.slice(versions.indexOf(oldVersion) + 1);
|
|
39
|
+
const newVersion = semver.maxSatisfying(vailds, prefix + oldVersion) || oldVersion;
|
|
41
40
|
return `${originalPrefix}${newVersion}`;
|
|
42
41
|
};
|
|
43
42
|
|
|
@@ -64,7 +63,7 @@ class Update {
|
|
|
64
63
|
const { dependencies = {}, devDependencies = {} } = packageOptionsMap[key];
|
|
65
64
|
const deps = { ...dependencies, ...devDependencies };
|
|
66
65
|
Object.keys(deps).forEach((packageName) => {
|
|
67
|
-
|
|
66
|
+
const version = deps[packageName];
|
|
68
67
|
packageNames[packageName] = packageNames[packageName] || {};
|
|
69
68
|
if (typeof packageNames[packageName][version] !== "string") {
|
|
70
69
|
packageNames[packageName][version] = "";
|
|
@@ -81,7 +80,7 @@ class Update {
|
|
|
81
80
|
const lastIndex = versions.indexOf(lastVersion);
|
|
82
81
|
const versions$ = versions.slice(0, lastIndex == -1 ? versions.length : lastIndex + 1);
|
|
83
82
|
Object.keys(packageNames[packageName]).forEach((version) => {
|
|
84
|
-
|
|
83
|
+
const newVersion = fitVersion(versions$, version, commandOptions);
|
|
85
84
|
if (newVersion === version) {
|
|
86
85
|
delete packageNames[packageName][version];
|
|
87
86
|
} else {
|
|
@@ -102,14 +101,14 @@ class Update {
|
|
|
102
101
|
}
|
|
103
102
|
async updatePackageOptions(changed) {
|
|
104
103
|
const { packageOptionsMap, commandOptions } = this;
|
|
105
|
-
|
|
104
|
+
const packageFolderNames = [];
|
|
106
105
|
Object.keys(packageOptionsMap).forEach((packageDir) => {
|
|
107
106
|
const packageOptions = packageOptionsMap[packageDir];
|
|
108
107
|
const { devDependencies = {}, dependencies = {} } = packageOptions;
|
|
109
108
|
let isChanged = false;
|
|
110
109
|
[devDependencies, dependencies].forEach((target) => {
|
|
111
110
|
Object.keys(target).forEach((packageName) => {
|
|
112
|
-
|
|
111
|
+
const version = target[packageName];
|
|
113
112
|
if (changed[packageName]?.[version]) {
|
|
114
113
|
isChanged = true;
|
|
115
114
|
target[packageName] = changed[packageName][version];
|
|
@@ -140,7 +139,7 @@ class Update {
|
|
|
140
139
|
const locals = devShared.Locals.impl();
|
|
141
140
|
const { cwd } = locals;
|
|
142
141
|
await fs.remove(`${cwd}/node_modules`);
|
|
143
|
-
await devShared.Shell.spawn("npx", ["pnpm", "install", "--lockfile
|
|
142
|
+
await devShared.Shell.spawn("npx", ["pnpm", "install", "--no-frozen-lockfile"]);
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
async commit(message) {
|
|
@@ -187,12 +186,12 @@ ${message}`);
|
|
|
187
186
|
async process() {
|
|
188
187
|
const spinner = ora(`Analyze ...`);
|
|
189
188
|
spinner.start();
|
|
190
|
-
|
|
189
|
+
const changed = await this.getPackageChanged();
|
|
191
190
|
spinner.stop();
|
|
192
191
|
let message = `deps updated
|
|
193
192
|
|
|
194
193
|
`;
|
|
195
|
-
|
|
194
|
+
const keys = Object.keys(changed);
|
|
196
195
|
if (!keys.length) {
|
|
197
196
|
devShared.Logger.log(chalk.red(`No Package Update Found.`));
|
|
198
197
|
return;
|
|
@@ -205,11 +204,17 @@ ${message}`);
|
|
|
205
204
|
devShared.Logger.log(`${chalk.cyan(key)}: ${chalk.yellow(version)} -> ${chalk.green(changed[key][version])}`);
|
|
206
205
|
});
|
|
207
206
|
});
|
|
208
|
-
const { all } = this.commandOptions;
|
|
207
|
+
const { all, changeLog } = this.commandOptions;
|
|
209
208
|
let packageFolderNames = await this.updatePackageOptions(changed);
|
|
210
|
-
|
|
209
|
+
const hasChanged = packageFolderNames.length;
|
|
211
210
|
packageFolderNames = hasChanged && all ? ["*"] : packageFolderNames;
|
|
212
|
-
|
|
211
|
+
if (changeLog) {
|
|
212
|
+
message = `chore${hasChanged ? "(" : ""}${packageFolderNames.join(",")}${hasChanged ? ")" : ""}: ${message}`;
|
|
213
|
+
} else {
|
|
214
|
+
const locals = devShared.Locals.impl();
|
|
215
|
+
const { workspace } = locals;
|
|
216
|
+
message = `${workspace ? "chore" : "void"}: ${message}`;
|
|
217
|
+
}
|
|
213
218
|
await this.updateLock();
|
|
214
219
|
await this.test();
|
|
215
220
|
await this.commit(message);
|
|
@@ -234,14 +239,14 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
|
|
|
234
239
|
commit: true,
|
|
235
240
|
push: true,
|
|
236
241
|
test: true,
|
|
242
|
+
changeLog: true,
|
|
237
243
|
major: false,
|
|
238
244
|
minor: false,
|
|
239
245
|
patch: false,
|
|
240
246
|
all: false,
|
|
241
247
|
...options
|
|
242
248
|
};
|
|
243
|
-
if (process.env.NODE_ENV === "UNIT")
|
|
244
|
-
return devShared.Shell.spawn(`echo update`);
|
|
249
|
+
if (process.env.NODE_ENV === "UNIT") return devShared.Shell.spawn(`echo update`);
|
|
245
250
|
await update(options).process();
|
|
246
251
|
}, {
|
|
247
252
|
onError: (e) => {
|
package/dist/index.js
CHANGED
|
@@ -6,15 +6,14 @@ import ora from 'ora';
|
|
|
6
6
|
import semver from 'semver';
|
|
7
7
|
|
|
8
8
|
const fitVersion = (versions, version, commandOptions) => {
|
|
9
|
-
|
|
10
|
-
if (!vRegex.test(version))
|
|
11
|
-
return version;
|
|
9
|
+
const vRegex = /([\d]+\.[\d]+\..*)/;
|
|
10
|
+
if (!vRegex.test(version)) return version;
|
|
12
11
|
const { major = false, minor = false, patch = false } = commandOptions || {};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const originalPrefix = (version.match(/([^\d]*).*/) || ["", ""])[1];
|
|
13
|
+
const prefix = major ? ">=" : minor ? "^" : patch ? "~" : originalPrefix;
|
|
14
|
+
const oldVersion = version.match(vRegex)[1];
|
|
15
|
+
const vailds = versions.slice(versions.indexOf(oldVersion) + 1);
|
|
16
|
+
const newVersion = semver.maxSatisfying(vailds, prefix + oldVersion) || oldVersion;
|
|
18
17
|
return `${originalPrefix}${newVersion}`;
|
|
19
18
|
};
|
|
20
19
|
|
|
@@ -41,7 +40,7 @@ class Update {
|
|
|
41
40
|
const { dependencies = {}, devDependencies = {} } = packageOptionsMap[key];
|
|
42
41
|
const deps = { ...dependencies, ...devDependencies };
|
|
43
42
|
Object.keys(deps).forEach((packageName) => {
|
|
44
|
-
|
|
43
|
+
const version = deps[packageName];
|
|
45
44
|
packageNames[packageName] = packageNames[packageName] || {};
|
|
46
45
|
if (typeof packageNames[packageName][version] !== "string") {
|
|
47
46
|
packageNames[packageName][version] = "";
|
|
@@ -58,7 +57,7 @@ class Update {
|
|
|
58
57
|
const lastIndex = versions.indexOf(lastVersion);
|
|
59
58
|
const versions$ = versions.slice(0, lastIndex == -1 ? versions.length : lastIndex + 1);
|
|
60
59
|
Object.keys(packageNames[packageName]).forEach((version) => {
|
|
61
|
-
|
|
60
|
+
const newVersion = fitVersion(versions$, version, commandOptions);
|
|
62
61
|
if (newVersion === version) {
|
|
63
62
|
delete packageNames[packageName][version];
|
|
64
63
|
} else {
|
|
@@ -79,14 +78,14 @@ class Update {
|
|
|
79
78
|
}
|
|
80
79
|
async updatePackageOptions(changed) {
|
|
81
80
|
const { packageOptionsMap, commandOptions } = this;
|
|
82
|
-
|
|
81
|
+
const packageFolderNames = [];
|
|
83
82
|
Object.keys(packageOptionsMap).forEach((packageDir) => {
|
|
84
83
|
const packageOptions = packageOptionsMap[packageDir];
|
|
85
84
|
const { devDependencies = {}, dependencies = {} } = packageOptions;
|
|
86
85
|
let isChanged = false;
|
|
87
86
|
[devDependencies, dependencies].forEach((target) => {
|
|
88
87
|
Object.keys(target).forEach((packageName) => {
|
|
89
|
-
|
|
88
|
+
const version = target[packageName];
|
|
90
89
|
if (changed[packageName]?.[version]) {
|
|
91
90
|
isChanged = true;
|
|
92
91
|
target[packageName] = changed[packageName][version];
|
|
@@ -117,7 +116,7 @@ class Update {
|
|
|
117
116
|
const locals = Locals.impl();
|
|
118
117
|
const { cwd } = locals;
|
|
119
118
|
await fs.remove(`${cwd}/node_modules`);
|
|
120
|
-
await Shell.spawn("npx", ["pnpm", "install", "--lockfile
|
|
119
|
+
await Shell.spawn("npx", ["pnpm", "install", "--no-frozen-lockfile"]);
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
122
|
async commit(message) {
|
|
@@ -164,12 +163,12 @@ ${message}`);
|
|
|
164
163
|
async process() {
|
|
165
164
|
const spinner = ora(`Analyze ...`);
|
|
166
165
|
spinner.start();
|
|
167
|
-
|
|
166
|
+
const changed = await this.getPackageChanged();
|
|
168
167
|
spinner.stop();
|
|
169
168
|
let message = `deps updated
|
|
170
169
|
|
|
171
170
|
`;
|
|
172
|
-
|
|
171
|
+
const keys = Object.keys(changed);
|
|
173
172
|
if (!keys.length) {
|
|
174
173
|
Logger.log(chalk.red(`No Package Update Found.`));
|
|
175
174
|
return;
|
|
@@ -182,11 +181,17 @@ ${message}`);
|
|
|
182
181
|
Logger.log(`${chalk.cyan(key)}: ${chalk.yellow(version)} -> ${chalk.green(changed[key][version])}`);
|
|
183
182
|
});
|
|
184
183
|
});
|
|
185
|
-
const { all } = this.commandOptions;
|
|
184
|
+
const { all, changeLog } = this.commandOptions;
|
|
186
185
|
let packageFolderNames = await this.updatePackageOptions(changed);
|
|
187
|
-
|
|
186
|
+
const hasChanged = packageFolderNames.length;
|
|
188
187
|
packageFolderNames = hasChanged && all ? ["*"] : packageFolderNames;
|
|
189
|
-
|
|
188
|
+
if (changeLog) {
|
|
189
|
+
message = `chore${hasChanged ? "(" : ""}${packageFolderNames.join(",")}${hasChanged ? ")" : ""}: ${message}`;
|
|
190
|
+
} else {
|
|
191
|
+
const locals = Locals.impl();
|
|
192
|
+
const { workspace } = locals;
|
|
193
|
+
message = `${workspace ? "chore" : "void"}: ${message}`;
|
|
194
|
+
}
|
|
190
195
|
await this.updateLock();
|
|
191
196
|
await this.test();
|
|
192
197
|
await this.commit(message);
|
|
@@ -211,14 +216,14 @@ const run = (options) => Utils.autoCatch(async () => {
|
|
|
211
216
|
commit: true,
|
|
212
217
|
push: true,
|
|
213
218
|
test: true,
|
|
219
|
+
changeLog: true,
|
|
214
220
|
major: false,
|
|
215
221
|
minor: false,
|
|
216
222
|
patch: false,
|
|
217
223
|
all: false,
|
|
218
224
|
...options
|
|
219
225
|
};
|
|
220
|
-
if (process.env.NODE_ENV === "UNIT")
|
|
221
|
-
return Shell.spawn(`echo update`);
|
|
226
|
+
if (process.env.NODE_ENV === "UNIT") return Shell.spawn(`echo update`);
|
|
222
227
|
await update(options).process();
|
|
223
228
|
}, {
|
|
224
229
|
onError: (e) => {
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-updater",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
9
10
|
"import": "./dist/index.js",
|
|
10
|
-
"require": "./dist/index.cjs"
|
|
11
|
-
"types": "./dist/index.d.ts"
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"access": "public"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@deot/dev-shared": "^2.
|
|
23
|
-
"chalk": "^5.
|
|
24
|
-
"fs-extra": "^11.
|
|
25
|
-
"ora": "^
|
|
26
|
-
"semver": "^7.
|
|
22
|
+
"@deot/dev-shared": "^2.9.0",
|
|
23
|
+
"chalk": "^5.4.1",
|
|
24
|
+
"fs-extra": "^11.3.0",
|
|
25
|
+
"ora": "^8.2.0",
|
|
26
|
+
"semver": "^7.7.1"
|
|
27
27
|
}
|
|
28
28
|
}
|