@xi-ix/dsh-multi-sync 0.1.3 → 0.1.5
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/client.js +14 -1
- package/index.js +54 -0
- package/package.json +3 -1
package/client.js
CHANGED
|
@@ -57,6 +57,9 @@ window.__ModuleLoader__.load({
|
|
|
57
57
|
linked: '本地挂载',
|
|
58
58
|
added: '新增',
|
|
59
59
|
local: '本地',
|
|
60
|
+
'local-unpublished': '本地(该版本未发布)',
|
|
61
|
+
'local-unknown': '本地(registry 未响应)',
|
|
62
|
+
localOrigin: '本地挂载 · 已发布',
|
|
60
63
|
remote: '非 registry',
|
|
61
64
|
unknown: '未知',
|
|
62
65
|
alreadyTitle: '这些已经装过,不会重复处理',
|
|
@@ -112,6 +115,9 @@ window.__ModuleLoader__.load({
|
|
|
112
115
|
linked: 'local link',
|
|
113
116
|
added: 'new',
|
|
114
117
|
local: 'local',
|
|
118
|
+
'local-unpublished': 'local (version not published)',
|
|
119
|
+
'local-unknown': 'local (registry unreachable)',
|
|
120
|
+
localOrigin: 'local mount · published',
|
|
115
121
|
remote: 'non-registry',
|
|
116
122
|
unknown: 'unknown',
|
|
117
123
|
alreadyTitle: 'Already installed — left untouched',
|
|
@@ -471,7 +477,14 @@ window.__ModuleLoader__.load({
|
|
|
471
477
|
{ key: row.name },
|
|
472
478
|
h('td', null, row.name),
|
|
473
479
|
h('td', null, row.version || '—'),
|
|
474
|
-
h(
|
|
480
|
+
h(
|
|
481
|
+
'td',
|
|
482
|
+
null,
|
|
483
|
+
(row.bundle ? 'bundle' : 'dep') +
|
|
484
|
+
(row.origin === 'local'
|
|
485
|
+
? ' · ' + (row.localVersion ? `${L.localOrigin} (${row.localVersion} → ${row.version})` : L.localOrigin)
|
|
486
|
+
: ''),
|
|
487
|
+
),
|
|
475
488
|
),
|
|
476
489
|
),
|
|
477
490
|
list.skipped.map((row) =>
|
package/index.js
CHANGED
|
@@ -225,6 +225,29 @@ function compareVersions(a, b) {
|
|
|
225
225
|
|
|
226
226
|
// ---------------------------------------------------------------- operations
|
|
227
227
|
|
|
228
|
+
/**
|
|
229
|
+
* What the registry knows about a package: whether this exact version is served,
|
|
230
|
+
* and which version `latest` points at.
|
|
231
|
+
*
|
|
232
|
+
* A locally linked plugin whose own version is unpublished can still travel as the
|
|
233
|
+
* latest published release, which is what the user actually wants on the other
|
|
234
|
+
* machine. An unreachable registry reports nothing rather than guessing.
|
|
235
|
+
*/
|
|
236
|
+
async function registryFacts(packageName, version) {
|
|
237
|
+
const base = process.env.npm_config_registry || 'https://registry.npmjs.org/'
|
|
238
|
+
const url = `${base.replace(/\/+$/, '')}/${encodeURIComponent(packageName)}`
|
|
239
|
+
try {
|
|
240
|
+
const response = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(8000) })
|
|
241
|
+
if (!response.ok) return { reachable: true, has: false, latest: null }
|
|
242
|
+
const document = await response.json()
|
|
243
|
+
const versions = document?.versions ?? {}
|
|
244
|
+
const latest = typeof document?.['dist-tags']?.latest === 'string' ? document['dist-tags'].latest : null
|
|
245
|
+
return { reachable: true, has: typeof versions[version] === 'object', latest }
|
|
246
|
+
} catch {
|
|
247
|
+
return { reachable: false, has: false, latest: null }
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
228
251
|
async function scan() {
|
|
229
252
|
const profile = resolveProfile()
|
|
230
253
|
const manifest = await readJson(join(profile.dir, 'package.json'))
|
|
@@ -236,6 +259,37 @@ async function scan() {
|
|
|
236
259
|
for (const [packageName, spec] of Object.entries(dependencies)) {
|
|
237
260
|
const kind = specKind(String(spec))
|
|
238
261
|
if (kind !== 'registry') {
|
|
262
|
+
// Local mount: it still travels if the registry serves the same version, and
|
|
263
|
+
// falls back to the latest published release when the local one is ahead.
|
|
264
|
+
const facts = await installedFacts(profile.dir, packageName)
|
|
265
|
+
if (facts?.version && PACKAGE_NAME.test(packageName)) {
|
|
266
|
+
const meta = await registryFacts(packageName, facts.version)
|
|
267
|
+
if (meta.has) {
|
|
268
|
+
plugins.push({
|
|
269
|
+
name: packageName,
|
|
270
|
+
version: facts.version,
|
|
271
|
+
spec: String(spec),
|
|
272
|
+
bundle: facts.bundle ?? bundles.has(packageName),
|
|
273
|
+
present: true,
|
|
274
|
+
origin: 'local',
|
|
275
|
+
})
|
|
276
|
+
continue
|
|
277
|
+
}
|
|
278
|
+
if (meta.latest !== null) {
|
|
279
|
+
plugins.push({
|
|
280
|
+
name: packageName,
|
|
281
|
+
version: meta.latest,
|
|
282
|
+
spec: String(spec),
|
|
283
|
+
bundle: facts.bundle ?? bundles.has(packageName),
|
|
284
|
+
present: true,
|
|
285
|
+
origin: 'local',
|
|
286
|
+
localVersion: facts.version,
|
|
287
|
+
})
|
|
288
|
+
continue
|
|
289
|
+
}
|
|
290
|
+
skipped.push({ name: packageName, spec: String(spec), reason: meta.reachable ? 'local-unpublished' : 'local-unknown' })
|
|
291
|
+
continue
|
|
292
|
+
}
|
|
239
293
|
skipped.push({ name: packageName, spec: String(spec), reason: kind })
|
|
240
294
|
continue
|
|
241
295
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xi-ix/dsh-multi-sync",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Copy one machine's installed DSH plugin list to another: scan the profile, export a pinned list, then install the selected entries on the other machine.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -51,3 +51,5 @@
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
|
|
55
|
+
|