react-native-update-cli 2.11.0 → 2.13.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/README.md +4 -0
- package/README.zh-CN.md +4 -0
- package/cli.json +6 -0
- package/lib/api.js +10 -12
- package/lib/app.d.ts +1 -1
- package/lib/app.js +1 -1
- package/lib/bin.js +5 -2
- package/lib/bundle-runner.js +22 -12
- package/lib/install.js +3 -4
- package/lib/locales/en.d.ts +1 -0
- package/lib/locales/en.js +1 -0
- package/lib/locales/zh.d.ts +1 -0
- package/lib/locales/zh.js +1 -0
- package/lib/package.d.ts +3 -0
- package/lib/package.js +6 -2
- package/lib/provider.d.ts +2 -2
- package/lib/provider.js +23 -22
- package/lib/types.d.ts +17 -4
- package/lib/utils/app-info-parser/zip.d.ts +3 -3
- package/lib/utils/app-info-parser/zip.js +33 -19
- package/lib/utils/git.d.ts +2 -1
- package/lib/utils/git.js +82 -40
- package/lib/utils/http-helper.js +8 -8
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +9 -1
- package/lib/utils/runtime.d.ts +28 -0
- package/lib/utils/runtime.js +183 -0
- package/lib/utils/zip-entries.js +1 -2
- package/lib/versions.d.ts +6 -3
- package/lib/versions.js +80 -23
- package/package.json +1 -7
- package/src/api.ts +23 -15
- package/src/app.ts +1 -1
- package/src/bin.ts +9 -2
- package/src/bundle-runner.ts +91 -50
- package/src/install.ts +3 -1
- package/src/locales/en.ts +1 -0
- package/src/locales/zh.ts +1 -0
- package/src/package.ts +11 -2
- package/src/provider.ts +47 -40
- package/src/types.ts +18 -4
- package/src/utils/app-info-parser/zip.ts +41 -24
- package/src/utils/git.ts +52 -31
- package/src/utils/http-helper.ts +8 -3
- package/src/utils/index.ts +8 -1
- package/src/utils/runtime.ts +187 -0
- package/src/utils/zip-entries.ts +2 -4
- package/src/versions.ts +105 -32
- package/lib/utils/latest-version/cli.d.ts +0 -1
- package/lib/utils/latest-version/cli.js +0 -308
- package/src/utils/latest-version/cli.ts +0 -445
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
blue,
|
|
3
|
-
bold,
|
|
4
|
-
cyan,
|
|
5
|
-
gray,
|
|
6
|
-
green,
|
|
7
|
-
italic,
|
|
8
|
-
magenta,
|
|
9
|
-
red,
|
|
10
|
-
reset,
|
|
11
|
-
strip,
|
|
12
|
-
underline,
|
|
13
|
-
yellow,
|
|
14
|
-
} from '@colors/colors/safe';
|
|
15
|
-
import { existsSync, readFileSync } from 'fs';
|
|
16
|
-
import { dirname } from 'path';
|
|
17
|
-
import semverDiff from 'semver/functions/diff';
|
|
18
|
-
import semverMajor from 'semver/functions/major';
|
|
19
|
-
import latestVersion, {
|
|
20
|
-
type LatestVersionOptions,
|
|
21
|
-
type LatestVersionPackage,
|
|
22
|
-
type Package,
|
|
23
|
-
type PackageJson,
|
|
24
|
-
} from '.';
|
|
25
|
-
|
|
26
|
-
interface TableColumn {
|
|
27
|
-
label: string;
|
|
28
|
-
attrName: keyof TableRow;
|
|
29
|
-
align: 'left' | 'center' | 'right';
|
|
30
|
-
maxLength: number;
|
|
31
|
-
items: string[];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type TableRowGroup =
|
|
35
|
-
| 'patch'
|
|
36
|
-
| 'minor'
|
|
37
|
-
| 'major'
|
|
38
|
-
| 'majorVersionZero'
|
|
39
|
-
| 'unknown';
|
|
40
|
-
|
|
41
|
-
interface TableRow {
|
|
42
|
-
name: string;
|
|
43
|
-
location: string;
|
|
44
|
-
installed: string;
|
|
45
|
-
tagOrRange: string;
|
|
46
|
-
separator: string;
|
|
47
|
-
wanted: string;
|
|
48
|
-
latest: string;
|
|
49
|
-
group: TableRowGroup;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const colorizeDiff = (from: string, to: string): string => {
|
|
53
|
-
const toParts = to.split('.');
|
|
54
|
-
|
|
55
|
-
const diffIndex = from.split('.').findIndex((part, i) => part !== toParts[i]);
|
|
56
|
-
if (diffIndex !== -1) {
|
|
57
|
-
let color = magenta;
|
|
58
|
-
if (toParts[0] !== '0') {
|
|
59
|
-
color = diffIndex === 0 ? red : diffIndex === 1 ? cyan : green;
|
|
60
|
-
}
|
|
61
|
-
const start = toParts.slice(0, diffIndex).join('.');
|
|
62
|
-
const mid = diffIndex === 0 ? '' : '.';
|
|
63
|
-
const end = color(toParts.slice(diffIndex).join('.'));
|
|
64
|
-
return `${start}${mid}${end}`;
|
|
65
|
-
}
|
|
66
|
-
return to;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const columnCellRenderer = (column: TableColumn, row: TableRow): string => {
|
|
70
|
-
let text = row[column.attrName];
|
|
71
|
-
const gap =
|
|
72
|
-
text.length < column.maxLength
|
|
73
|
-
? ' '.repeat(column.maxLength - text.length)
|
|
74
|
-
: '';
|
|
75
|
-
|
|
76
|
-
switch (column.attrName) {
|
|
77
|
-
case 'name':
|
|
78
|
-
text = yellow(text);
|
|
79
|
-
break;
|
|
80
|
-
case 'installed':
|
|
81
|
-
case 'separator':
|
|
82
|
-
text = blue(text);
|
|
83
|
-
break;
|
|
84
|
-
case 'location':
|
|
85
|
-
case 'tagOrRange':
|
|
86
|
-
text = gray(text);
|
|
87
|
-
break;
|
|
88
|
-
case 'wanted':
|
|
89
|
-
text = colorizeDiff(row.installed, text);
|
|
90
|
-
break;
|
|
91
|
-
case 'latest':
|
|
92
|
-
if (text !== row.wanted) {
|
|
93
|
-
text = colorizeDiff(row.installed, text);
|
|
94
|
-
}
|
|
95
|
-
break;
|
|
96
|
-
default:
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return column.align === 'right' ? `${gap}${text}` : `${text}${gap}`;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const columnHeaderRenderer = (column: TableColumn): string => {
|
|
104
|
-
const text = column.label;
|
|
105
|
-
const gap =
|
|
106
|
-
text.length < column.maxLength
|
|
107
|
-
? ' '.repeat(column.maxLength - text.length)
|
|
108
|
-
: '';
|
|
109
|
-
return column.align === 'right'
|
|
110
|
-
? `${gap}${underline(text)}`
|
|
111
|
-
: `${underline(text)}${gap}`;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const drawBox = (
|
|
115
|
-
lines: string[],
|
|
116
|
-
color = yellow,
|
|
117
|
-
horizontalPadding = 3,
|
|
118
|
-
): void => {
|
|
119
|
-
const maxLineWidth = lines.reduce(
|
|
120
|
-
(max, row) => Math.max(max, strip(row).length),
|
|
121
|
-
0,
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
console.log(color(`┌${'─'.repeat(maxLineWidth + horizontalPadding * 2)}┐`));
|
|
125
|
-
for (const row of lines) {
|
|
126
|
-
const padding = ' '.repeat(horizontalPadding);
|
|
127
|
-
const fullRow = `${row}${' '.repeat(maxLineWidth - strip(row).length)}`;
|
|
128
|
-
console.log(
|
|
129
|
-
`${color('│')}${padding}${reset(fullRow)}${padding}${color('│')}`,
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
console.log(color(`└${'─'.repeat(maxLineWidth + horizontalPadding * 2)}┘`));
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const getTableColumns = (rows: TableRow[]): TableColumn[] => {
|
|
136
|
-
const columns: TableColumn[] = [
|
|
137
|
-
{
|
|
138
|
-
label: 'Package',
|
|
139
|
-
attrName: 'name',
|
|
140
|
-
align: 'left',
|
|
141
|
-
maxLength: 0,
|
|
142
|
-
items: [],
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
label: 'Location',
|
|
146
|
-
attrName: 'location',
|
|
147
|
-
align: 'left',
|
|
148
|
-
maxLength: 0,
|
|
149
|
-
items: [],
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
label: 'Installed',
|
|
153
|
-
attrName: 'installed',
|
|
154
|
-
align: 'right',
|
|
155
|
-
maxLength: 0,
|
|
156
|
-
items: [],
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
label: '',
|
|
160
|
-
attrName: 'separator',
|
|
161
|
-
align: 'center',
|
|
162
|
-
maxLength: 0,
|
|
163
|
-
items: [],
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
label: 'Range',
|
|
167
|
-
attrName: 'tagOrRange',
|
|
168
|
-
align: 'right',
|
|
169
|
-
maxLength: 0,
|
|
170
|
-
items: [],
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
label: '',
|
|
174
|
-
attrName: 'separator',
|
|
175
|
-
align: 'center',
|
|
176
|
-
maxLength: 0,
|
|
177
|
-
items: [],
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
label: 'Wanted',
|
|
181
|
-
attrName: 'wanted',
|
|
182
|
-
align: 'right',
|
|
183
|
-
maxLength: 0,
|
|
184
|
-
items: [],
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
label: 'Latest',
|
|
188
|
-
attrName: 'latest',
|
|
189
|
-
align: 'right',
|
|
190
|
-
maxLength: 0,
|
|
191
|
-
items: [],
|
|
192
|
-
},
|
|
193
|
-
];
|
|
194
|
-
for (const row of rows) {
|
|
195
|
-
for (const column of columns) {
|
|
196
|
-
column.maxLength = Math.max(
|
|
197
|
-
column.label.length,
|
|
198
|
-
column.maxLength,
|
|
199
|
-
row[column.attrName].length || 0,
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return columns;
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
const getTableRows = (updates: LatestVersionPackage[]): TableRow[] => {
|
|
207
|
-
return updates.reduce<TableRow[]>((all, pkg) => {
|
|
208
|
-
const {
|
|
209
|
-
name,
|
|
210
|
-
latest,
|
|
211
|
-
local,
|
|
212
|
-
globalNpm,
|
|
213
|
-
globalYarn,
|
|
214
|
-
wantedTagOrRange,
|
|
215
|
-
updatesAvailable,
|
|
216
|
-
} = pkg;
|
|
217
|
-
const getGroup = (a?: string, b?: string): TableRowGroup => {
|
|
218
|
-
if (b && semverMajor(b) === 0) {
|
|
219
|
-
return 'majorVersionZero';
|
|
220
|
-
}
|
|
221
|
-
if (a && b) {
|
|
222
|
-
const releaseType = semverDiff(a, b) ?? '';
|
|
223
|
-
if (['major', 'premajor', 'prerelease'].includes(releaseType)) {
|
|
224
|
-
return 'major';
|
|
225
|
-
}
|
|
226
|
-
if (['minor', 'preminor'].includes(releaseType)) {
|
|
227
|
-
return 'minor';
|
|
228
|
-
}
|
|
229
|
-
if (['patch', 'prepatch'].includes(releaseType)) {
|
|
230
|
-
return 'patch';
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return 'unknown';
|
|
234
|
-
};
|
|
235
|
-
const add = (
|
|
236
|
-
group: TableRowGroup,
|
|
237
|
-
location: string,
|
|
238
|
-
installed?: string,
|
|
239
|
-
wanted?: string,
|
|
240
|
-
) =>
|
|
241
|
-
all.push({
|
|
242
|
-
name: ` ${name}`,
|
|
243
|
-
location,
|
|
244
|
-
installed: installed ?? 'unknown',
|
|
245
|
-
latest: latest ?? 'unknown',
|
|
246
|
-
tagOrRange: wantedTagOrRange ?? 'unknown',
|
|
247
|
-
separator: '→',
|
|
248
|
-
wanted: wanted ?? 'unknown',
|
|
249
|
-
group,
|
|
250
|
-
});
|
|
251
|
-
if (updatesAvailable) {
|
|
252
|
-
if (updatesAvailable.local) {
|
|
253
|
-
add(
|
|
254
|
-
getGroup(local, updatesAvailable.local),
|
|
255
|
-
'local',
|
|
256
|
-
local,
|
|
257
|
-
updatesAvailable.local,
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
if (updatesAvailable.globalNpm) {
|
|
261
|
-
add(
|
|
262
|
-
getGroup(globalNpm, updatesAvailable.globalNpm),
|
|
263
|
-
'NPM global',
|
|
264
|
-
globalNpm,
|
|
265
|
-
updatesAvailable.globalNpm,
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
if (updatesAvailable.globalYarn) {
|
|
269
|
-
add(
|
|
270
|
-
getGroup(globalYarn, updatesAvailable.globalYarn),
|
|
271
|
-
'YARN global',
|
|
272
|
-
globalYarn,
|
|
273
|
-
updatesAvailable.globalYarn,
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
} else {
|
|
277
|
-
if (local && local !== latest) {
|
|
278
|
-
add(getGroup(local, latest), 'local', local, pkg.wanted);
|
|
279
|
-
}
|
|
280
|
-
if (globalNpm && globalNpm !== latest) {
|
|
281
|
-
add(getGroup(globalNpm, latest), 'NPM global', globalNpm, pkg.wanted);
|
|
282
|
-
}
|
|
283
|
-
if (globalYarn && globalYarn !== latest) {
|
|
284
|
-
add(
|
|
285
|
-
getGroup(globalYarn, latest),
|
|
286
|
-
'YARN global',
|
|
287
|
-
globalYarn,
|
|
288
|
-
pkg.wanted,
|
|
289
|
-
);
|
|
290
|
-
}
|
|
291
|
-
if (!local && !globalNpm && !globalYarn) {
|
|
292
|
-
add('unknown', 'unknown', 'unknown', pkg.wanted);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
return all;
|
|
296
|
-
}, []);
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
const displayTable = (latestVersionPackages: LatestVersionPackage[]): void => {
|
|
300
|
-
const updates = latestVersionPackages.filter((pkg) => pkg.updatesAvailable);
|
|
301
|
-
if (updates.length) {
|
|
302
|
-
const rows = getTableRows(updates);
|
|
303
|
-
const hasUpdates = rows.some((row) => row.installed !== 'unknown');
|
|
304
|
-
const columns = getTableColumns(rows);
|
|
305
|
-
const columnGap = 2;
|
|
306
|
-
|
|
307
|
-
const getGroupLines = (
|
|
308
|
-
groupType: TableRowGroup,
|
|
309
|
-
color: (str: string) => string,
|
|
310
|
-
title: string,
|
|
311
|
-
description?: string,
|
|
312
|
-
): string[] => {
|
|
313
|
-
const items = rows
|
|
314
|
-
.filter((row) => row.group === groupType)
|
|
315
|
-
.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
316
|
-
return !items.length
|
|
317
|
-
? []
|
|
318
|
-
: [
|
|
319
|
-
'',
|
|
320
|
-
color(`${bold(title)} ${italic(`(${description})`)}`),
|
|
321
|
-
...items.map((row) =>
|
|
322
|
-
columns
|
|
323
|
-
.map((column) => columnCellRenderer(column, row))
|
|
324
|
-
.join(' '.repeat(columnGap)),
|
|
325
|
-
),
|
|
326
|
-
];
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
330
|
-
drawBox(
|
|
331
|
-
[
|
|
332
|
-
'',
|
|
333
|
-
hasUpdates ? yellow('Important updates are available.') : undefined,
|
|
334
|
-
hasUpdates ? '' : undefined,
|
|
335
|
-
columns.map(columnHeaderRenderer).join(' '.repeat(columnGap)),
|
|
336
|
-
...getGroupLines(
|
|
337
|
-
'patch',
|
|
338
|
-
green,
|
|
339
|
-
'Patch',
|
|
340
|
-
'backwards-compatible bug fixes',
|
|
341
|
-
),
|
|
342
|
-
...getGroupLines(
|
|
343
|
-
'minor',
|
|
344
|
-
cyan,
|
|
345
|
-
'Minor',
|
|
346
|
-
'backwards-compatible features',
|
|
347
|
-
),
|
|
348
|
-
...getGroupLines(
|
|
349
|
-
'major',
|
|
350
|
-
red,
|
|
351
|
-
'Major',
|
|
352
|
-
'potentially breaking API changes',
|
|
353
|
-
),
|
|
354
|
-
...getGroupLines(
|
|
355
|
-
'majorVersionZero',
|
|
356
|
-
magenta,
|
|
357
|
-
'Major version zero',
|
|
358
|
-
'not stable, anything may change',
|
|
359
|
-
),
|
|
360
|
-
...getGroupLines('unknown', blue, 'Missing', 'not installed'),
|
|
361
|
-
'',
|
|
362
|
-
].filter((line) => line !== undefined) as string[],
|
|
363
|
-
);
|
|
364
|
-
} else {
|
|
365
|
-
console.log(green('🎉 Packages are up-to-date'));
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const checkVersions = async (
|
|
370
|
-
packages: Package | Package[] | PackageJson,
|
|
371
|
-
skipMissing: boolean,
|
|
372
|
-
options: LatestVersionOptions = { useCache: true },
|
|
373
|
-
): Promise<void> => {
|
|
374
|
-
console.log(cyan('Checking versions...'));
|
|
375
|
-
let latestVersionPackages: LatestVersionPackage[];
|
|
376
|
-
if (typeof packages === 'string') {
|
|
377
|
-
latestVersionPackages = [await latestVersion(packages, options)];
|
|
378
|
-
} else if (Array.isArray(packages)) {
|
|
379
|
-
latestVersionPackages = await latestVersion(packages, options);
|
|
380
|
-
} else {
|
|
381
|
-
latestVersionPackages = await latestVersion(packages, options);
|
|
382
|
-
}
|
|
383
|
-
if (skipMissing) {
|
|
384
|
-
latestVersionPackages = latestVersionPackages.filter(
|
|
385
|
-
(pkg) => pkg.local ?? pkg.globalNpm ?? pkg.globalYarn,
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
displayTable(latestVersionPackages);
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
void (async () => {
|
|
392
|
-
let args = process.argv.slice(2);
|
|
393
|
-
|
|
394
|
-
const skipMissing = args.includes('--skip-missing');
|
|
395
|
-
|
|
396
|
-
// Remove any options from the arguments
|
|
397
|
-
args = args.filter((arg) => !arg.startsWith('-'));
|
|
398
|
-
|
|
399
|
-
// If argument is a package.json file
|
|
400
|
-
if (args.length === 1 && args[0].endsWith('package.json')) {
|
|
401
|
-
if (existsSync(args[0])) {
|
|
402
|
-
process.chdir(dirname(args[0]));
|
|
403
|
-
await checkVersions(
|
|
404
|
-
JSON.parse(readFileSync(args[0]).toString()) as PackageJson,
|
|
405
|
-
skipMissing,
|
|
406
|
-
);
|
|
407
|
-
} else {
|
|
408
|
-
console.log(cyan('No package.json file were found'));
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
// else..
|
|
412
|
-
else {
|
|
413
|
-
// Check if a local package.json file exists
|
|
414
|
-
let localPkgJson: PackageJson | undefined;
|
|
415
|
-
if (existsSync('package.json')) {
|
|
416
|
-
localPkgJson = JSON.parse(readFileSync('package.json').toString());
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
// Check given arguments
|
|
420
|
-
if (args.length) {
|
|
421
|
-
// Map arguments with any range that could be found in local package.json
|
|
422
|
-
args = args.map((arg) => {
|
|
423
|
-
if (localPkgJson?.dependencies?.[arg]) {
|
|
424
|
-
return `${arg}@${localPkgJson.dependencies?.[arg]}`;
|
|
425
|
-
}
|
|
426
|
-
if (localPkgJson?.devDependencies?.[arg]) {
|
|
427
|
-
return `${arg}@${localPkgJson.devDependencies?.[arg]}`;
|
|
428
|
-
}
|
|
429
|
-
if (localPkgJson?.peerDependencies?.[arg]) {
|
|
430
|
-
return `${arg}@${localPkgJson.peerDependencies?.[arg]}`;
|
|
431
|
-
}
|
|
432
|
-
return arg;
|
|
433
|
-
});
|
|
434
|
-
await checkVersions(args, skipMissing);
|
|
435
|
-
}
|
|
436
|
-
// ...else check the local package.json if any
|
|
437
|
-
else if (localPkgJson) {
|
|
438
|
-
await checkVersions(localPkgJson, skipMissing);
|
|
439
|
-
}
|
|
440
|
-
// ...else do nothing
|
|
441
|
-
else {
|
|
442
|
-
console.log(cyan('No packages were found'));
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
})();
|