@xi-ix/dsh-multi-sync 0.1.3 → 0.1.4

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 +5 -1
  2. package/index.js +33 -1
  3. package/package.json +2 -1
package/client.js CHANGED
@@ -57,6 +57,8 @@ window.__ModuleLoader__.load({
57
57
  linked: '本地挂载',
58
58
  added: '新增',
59
59
  local: '本地',
60
+ 'local-unpublished': '本地(该版本未发布)',
61
+ localOrigin: '本地挂载 · 已发布',
60
62
  remote: '非 registry',
61
63
  unknown: '未知',
62
64
  alreadyTitle: '这些已经装过,不会重复处理',
@@ -112,6 +114,8 @@ window.__ModuleLoader__.load({
112
114
  linked: 'local link',
113
115
  added: 'new',
114
116
  local: 'local',
117
+ 'local-unpublished': 'local (version not published)',
118
+ localOrigin: 'local mount · published',
115
119
  remote: 'non-registry',
116
120
  unknown: 'unknown',
117
121
  alreadyTitle: 'Already installed — left untouched',
@@ -471,7 +475,7 @@ window.__ModuleLoader__.load({
471
475
  { key: row.name },
472
476
  h('td', null, row.name),
473
477
  h('td', null, row.version || '—'),
474
- h('td', null, row.bundle ? 'bundle' : 'dep'),
478
+ h('td', null, (row.bundle ? 'bundle' : 'dep') + (row.origin === 'local' ? ' · ' + L.localOrigin : '')),
475
479
  ),
476
480
  ),
477
481
  list.skipped.map((row) =>
package/index.js CHANGED
@@ -225,6 +225,25 @@ function compareVersions(a, b) {
225
225
 
226
226
  // ---------------------------------------------------------------- operations
227
227
 
228
+ /**
229
+ * Whether the registry already serves this exact version.
230
+ *
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.
235
+ */
236
+ async function publishedAt(packageName, version) {
237
+ const base = process.env.npm_config_registry || 'https://registry.npmjs.org/'
238
+ const url = `${base.replace(/\/+$/, '')}/${encodeURIComponent(packageName)}/${encodeURIComponent(version)}`
239
+ try {
240
+ const response = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(6000) })
241
+ return response.ok
242
+ } catch {
243
+ return false
244
+ }
245
+ }
246
+
228
247
  async function scan() {
229
248
  const profile = resolveProfile()
230
249
  const manifest = await readJson(join(profile.dir, 'package.json'))
@@ -236,7 +255,20 @@ async function scan() {
236
255
  for (const [packageName, spec] of Object.entries(dependencies)) {
237
256
  const kind = specKind(String(spec))
238
257
  if (kind !== 'registry') {
239
- skipped.push({ name: packageName, spec: String(spec), reason: kind })
258
+ // Local mount: it still travels if the same version is on the registry.
259
+ 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
+ })
269
+ continue
270
+ }
271
+ skipped.push({ name: packageName, spec: String(spec), reason: facts?.version ? 'local-unpublished' : kind })
240
272
  continue
241
273
  }
242
274
  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.3",
3
+ "version": "0.1.4",
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,4 @@
51
51
  }
52
52
 
53
53
 
54
+