@xi-ix/dsh-multi-sync 0.1.4 → 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.
Files changed (3) hide show
  1. package/client.js +10 -1
  2. package/index.js +43 -21
  3. package/package.json +2 -1
package/client.js CHANGED
@@ -58,6 +58,7 @@ window.__ModuleLoader__.load({
58
58
  added: '新增',
59
59
  local: '本地',
60
60
  'local-unpublished': '本地(该版本未发布)',
61
+ 'local-unknown': '本地(registry 未响应)',
61
62
  localOrigin: '本地挂载 · 已发布',
62
63
  remote: '非 registry',
63
64
  unknown: '未知',
@@ -115,6 +116,7 @@ window.__ModuleLoader__.load({
115
116
  added: 'new',
116
117
  local: 'local',
117
118
  'local-unpublished': 'local (version not published)',
119
+ 'local-unknown': 'local (registry unreachable)',
118
120
  localOrigin: 'local mount · published',
119
121
  remote: 'non-registry',
120
122
  unknown: 'unknown',
@@ -475,7 +477,14 @@ window.__ModuleLoader__.load({
475
477
  { key: row.name },
476
478
  h('td', null, row.name),
477
479
  h('td', null, row.version || '—'),
478
- h('td', null, (row.bundle ? 'bundle' : 'dep') + (row.origin === 'local' ? ' · ' + L.localOrigin : '')),
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
+ ),
479
488
  ),
480
489
  ),
481
490
  list.skipped.map((row) =>
package/index.js CHANGED
@@ -226,21 +226,25 @@ function compareVersions(a, b) {
226
226
  // ---------------------------------------------------------------- operations
227
227
 
228
228
  /**
229
- * Whether the registry already serves this exact version.
229
+ * What the registry knows about a package: whether this exact version is served,
230
+ * and which version `latest` points at.
230
231
  *
231
- * A locally linked plugin that has been published is a normal downloadable entry
232
- * for the other machine, so the scan asks instead of assuming that every `link:`
233
- * or `file:` spec is unshareable. An unreachable registry answers "no", which
234
- * degrades to the previous behaviour rather than failing the scan.
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
235
  */
236
- async function publishedAt(packageName, version) {
236
+ async function registryFacts(packageName, version) {
237
237
  const base = process.env.npm_config_registry || 'https://registry.npmjs.org/'
238
- const url = `${base.replace(/\/+$/, '')}/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}`
238
+ const url = `${base.replace(/\/+$/, '')}/${encodeURIComponent(packageName)}`
239
239
  try {
240
- const response = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(6000) })
241
- return response.ok
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 }
242
246
  } catch {
243
- return false
247
+ return { reachable: false, has: false, latest: null }
244
248
  }
245
249
  }
246
250
 
@@ -255,20 +259,38 @@ async function scan() {
255
259
  for (const [packageName, spec] of Object.entries(dependencies)) {
256
260
  const kind = specKind(String(spec))
257
261
  if (kind !== 'registry') {
258
- // Local mount: it still travels if the same version is on the 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.
259
264
  const facts = await installedFacts(profile.dir, packageName)
260
- if (facts?.version && PACKAGE_NAME.test(packageName) && (await publishedAt(packageName, facts.version))) {
261
- plugins.push({
262
- name: packageName,
263
- version: facts.version,
264
- spec: String(spec),
265
- bundle: facts.bundle ?? bundles.has(packageName),
266
- present: true,
267
- origin: 'local',
268
- })
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' })
269
291
  continue
270
292
  }
271
- skipped.push({ name: packageName, spec: String(spec), reason: facts?.version ? 'local-unpublished' : kind })
293
+ skipped.push({ name: packageName, spec: String(spec), reason: kind })
272
294
  continue
273
295
  }
274
296
  if (!PACKAGE_NAME.test(packageName)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xi-ix/dsh-multi-sync",
3
- "version": "0.1.4",
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",
@@ -52,3 +52,4 @@
52
52
 
53
53
 
54
54
 
55
+