omp-config-crypt 0.9.0 → 0.9.1
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/index.js +60 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -111,6 +111,7 @@ import {
|
|
|
111
111
|
import {
|
|
112
112
|
inventoryResources,
|
|
113
113
|
readResource,
|
|
114
|
+
canonicalResourceValue,
|
|
114
115
|
sanitizeResourceForExport,
|
|
115
116
|
restoreResourceForImport,
|
|
116
117
|
HOME_PLACEHOLDER,
|
|
@@ -356,12 +357,10 @@ export function adaptArchive(blob, pass) {
|
|
|
356
357
|
}
|
|
357
358
|
|
|
358
359
|
/**
|
|
359
|
-
* Installs
|
|
360
|
-
*
|
|
361
|
-
* public plans sanitize action values away, so the snapshot payload is consulted as
|
|
362
|
-
* fallback. Skipped entries keep their blocked state and surface as apply errors.
|
|
360
|
+
* Installs exact plugin package versions through npm (or an injected installer).
|
|
361
|
+
* Returns the fixed "name@version" entries plus names skipped for missing versions.
|
|
363
362
|
*/
|
|
364
|
-
|
|
363
|
+
function installPluginPackages(entries, root, install) {
|
|
365
364
|
const npmCmd = resolveNpmCommand();
|
|
366
365
|
const doInstall = install ?? ((name, version) => {
|
|
367
366
|
execFileSync(
|
|
@@ -370,14 +369,9 @@ export function fixPluginPrerequisites(plan, root, { install, payload = null } =
|
|
|
370
369
|
{ stdio: "pipe", shell: npmCmd.shell },
|
|
371
370
|
);
|
|
372
371
|
});
|
|
373
|
-
const payloadVersions = new Map((payload?.resources || []).map((resource) => [resource.id, resource.value]));
|
|
374
372
|
const fixed = [];
|
|
375
373
|
const skipped = [];
|
|
376
|
-
for (const
|
|
377
|
-
if (action.action !== "blocked" || !String(action.id || "").startsWith("plugin:")) continue;
|
|
378
|
-
if (action.reason !== "plugin-not-installed" && action.reason !== "plugin-version-mismatch") continue;
|
|
379
|
-
const name = action.id.slice("plugin:".length);
|
|
380
|
-
const version = action.value?.version ?? payloadVersions.get(action.id)?.version ?? null;
|
|
374
|
+
for (const { name, version } of entries) {
|
|
381
375
|
if (!version) {
|
|
382
376
|
skipped.push(name);
|
|
383
377
|
continue;
|
|
@@ -392,6 +386,52 @@ export function fixPluginPrerequisites(plan, root, { install, payload = null } =
|
|
|
392
386
|
return { fixed, skipped };
|
|
393
387
|
}
|
|
394
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Installs remote-declared plugins whose local declaration can no longer be
|
|
391
|
+
* canonicalized — a range dependency (e.g. "^0.1.2") whose node_modules vanished
|
|
392
|
+
* makes planSync throw before the blocked-plugin path can trigger. Restoring the
|
|
393
|
+
* exact remote version first keeps the plan buildable.
|
|
394
|
+
*/
|
|
395
|
+
export function repairUnreadablePlugins(payload, root, { install } = {}) {
|
|
396
|
+
const entries = [];
|
|
397
|
+
for (const resource of payload?.resources || []) {
|
|
398
|
+
const id = String(resource?.id || "");
|
|
399
|
+
if (!id.startsWith("plugin:")) continue;
|
|
400
|
+
const version = resource.value?.version;
|
|
401
|
+
if (!version) continue;
|
|
402
|
+
let local = null;
|
|
403
|
+
try {
|
|
404
|
+
local = readResource(root, id);
|
|
405
|
+
} catch { local = null; }
|
|
406
|
+
if (!local) continue;
|
|
407
|
+
try {
|
|
408
|
+
canonicalResourceValue(id, local.value, root);
|
|
409
|
+
} catch {
|
|
410
|
+
entries.push({ name: id.slice("plugin:".length), version });
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return installPluginPackages(entries, root, install).fixed;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Installs the missing or mismatched plugin dependencies a sync plan blocked on.
|
|
418
|
+
* Versions come from the plan action value when present (internal/hand-built plans);
|
|
419
|
+
* public plans sanitize action values away, so the snapshot payload is consulted as
|
|
420
|
+
* fallback. Skipped entries keep their blocked state and surface as apply errors.
|
|
421
|
+
*/
|
|
422
|
+
export function fixPluginPrerequisites(plan, root, { install, payload = null } = {}) {
|
|
423
|
+
const payloadVersions = new Map((payload?.resources || []).map((resource) => [resource.id, resource.value]));
|
|
424
|
+
const entries = [];
|
|
425
|
+
for (const action of plan.actions || []) {
|
|
426
|
+
if (action.action !== "blocked" || !String(action.id || "").startsWith("plugin:")) continue;
|
|
427
|
+
if (action.reason !== "plugin-not-installed" && action.reason !== "plugin-version-mismatch") continue;
|
|
428
|
+
const name = action.id.slice("plugin:".length);
|
|
429
|
+
const version = action.value?.version ?? payloadVersions.get(action.id)?.version ?? null;
|
|
430
|
+
entries.push({ name, version });
|
|
431
|
+
}
|
|
432
|
+
return installPluginPackages(entries, root, install);
|
|
433
|
+
}
|
|
434
|
+
|
|
395
435
|
/**
|
|
396
436
|
* Restores an encrypted archive buffer into the config tree with 3-way merge planning and journaled transaction.
|
|
397
437
|
*/
|
|
@@ -415,10 +455,17 @@ export function restoreArchive(blob, pass, root = configRoot(), options = {}) {
|
|
|
415
455
|
}
|
|
416
456
|
|
|
417
457
|
const dryRun = Boolean(options.dryRun);
|
|
458
|
+
|
|
459
|
+
// Self-healing stage 1: repair local plugin declarations that would break planning
|
|
460
|
+
// (range dependency with a vanished install). Must run before planSync.
|
|
461
|
+
if (!dryRun && options.autoFixPlugins !== false) {
|
|
462
|
+
repairUnreadablePlugins(effectivePayload, root, { install: options.installFn });
|
|
463
|
+
}
|
|
464
|
+
|
|
418
465
|
let plan = planSync(effectivePayload, root, { strategy: options.strategy });
|
|
419
466
|
|
|
420
|
-
// Self-healing: install plugin dependencies the plan blocked on, then replan
|
|
421
|
-
// (the install mutates the plugins tree, so the original plan is stale). Remaining
|
|
467
|
+
// Self-healing stage 2: install plugin dependencies the plan blocked on, then replan
|
|
468
|
+
// once (the install mutates the plugins tree, so the original plan is stale). Remaining
|
|
422
469
|
// blocked actions still fail the apply.
|
|
423
470
|
if (!dryRun && plan.prerequisites.length > 0 && options.autoFixPlugins !== false) {
|
|
424
471
|
const fx = fixPluginPrerequisites(plan, root, { install: options.installFn, payload: effectivePayload });
|