dsh-nextsteps 1.4.3 → 1.4.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 (2) hide show
  1. package/client.js +32 -5
  2. package/package.json +1 -1
package/client.js CHANGED
@@ -563,17 +563,44 @@ window.__ModuleLoader__.load({
563
563
  const install = async () => {
564
564
  const { info } = update;
565
565
  let pluginManager;
566
- try { pluginManager = ctx.get('remote')?.pluginManager; } catch { pluginManager = undefined; }
567
- if (info === undefined || pluginManager === undefined || typeof pluginManager.installBundle !== 'function') return;
566
+ try {
567
+ pluginManager = ctx.remote?.pluginManager ?? ctx.get?.('remote')?.pluginManager;
568
+ } catch { pluginManager = undefined; }
569
+ if (info === undefined) return;
570
+ if (pluginManager === undefined || typeof pluginManager.installBundle !== 'function') {
571
+ setUpdate({ status: 'error', info, error: 'the plugin manager is not available in this install' });
572
+ return;
573
+ }
568
574
  setUpdate({ status: 'installing', info });
569
575
  try {
576
+ const requestId = NS + '-update-' + info.latest + '-' + Date.now();
577
+ const recoverInstall = async (manager, id) => {
578
+ if (typeof manager.waitForInstall !== 'function') return undefined;
579
+ try {
580
+ const reply = await manager.waitForInstall(id);
581
+ if (reply === null || typeof reply !== 'object' || reply.ok !== true) return undefined;
582
+ return reply.value ?? undefined;
583
+ } catch { return undefined; }
584
+ };
570
585
  const attempt = async (spec) => {
571
- const reply = await pluginManager.installBundle(spec, { requestId: NS + '-update-' + info.latest + '-' + Date.now() });
586
+ const reply = await pluginManager.installBundle(spec, { enabled: true, requestId });
572
587
  if (reply === null || typeof reply !== 'object' || reply.ok !== true) throw new Error(reply?.error?.message ?? 'plugin manager did not answer');
573
588
  return reply.value;
574
589
  };
575
- let result = await attempt(NPM_NAME + '@' + info.latest);
576
- if (result !== null && typeof result === 'object' && result.error?.code === 'already-installed') result = await attempt('https://registry.npmjs.org/' + NPM_NAME + '/-/' + NPM_NAME + '-' + info.latest + '.tgz');
590
+ let result;
591
+ if (typeof pluginManager.updateBundle === 'function') {
592
+ const reply = await pluginManager.updateBundle(NPM_NAME, info.latest, { requestId });
593
+ if (reply === null || typeof reply !== 'object' || reply.ok !== true) {
594
+ const recovered = await recoverInstall(pluginManager, requestId);
595
+ if (recovered === undefined) throw new Error(reply?.error?.message ?? 'plugin manager did not answer');
596
+ result = recovered;
597
+ } else {
598
+ result = reply.value;
599
+ }
600
+ } else {
601
+ result = await attempt(NPM_NAME + '@' + info.latest);
602
+ if (result !== null && typeof result === 'object' && result.error?.code === 'already-installed') result = await attempt('https://registry.npmjs.org/' + NPM_NAME + '/-/' + NPM_NAME + '-' + info.latest + '.tgz');
603
+ }
577
604
  const applied = result !== null && typeof result === 'object' && (result.application === 'applied' || result.application === 'restart-required' || result.version === info.latest);
578
605
  if (!applied) {
579
606
  const diagnostic = typeof result?.error?.diagnostic === 'string' ? result.error.diagnostic.split('\n').find((entry) => entry.trim() !== '') : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-nextsteps",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",