19 lines
996 B
JavaScript
19 lines
996 B
JavaScript
// "A package the form needs is missing, install it" (no DOM, tested with a fake runner in wizard-install.test.mjs): the packages
|
|
// are required one after the other (composer require --dev), the first failure stops the rest.
|
|
|
|
/**
|
|
* deps: run({action: 'require', package, dev}, onOutput) -> {code}; onStep(package, index, total) is told before each one.
|
|
* Resolves with {status: 'installed' | 'failed' | 'nothing', done: [package], failed?: package}.
|
|
*/
|
|
export async function installPackages(missing, deps) {
|
|
if (!missing?.length) return { status: 'nothing', done: [] };
|
|
const done = [];
|
|
for (const [i, m] of missing.entries()) {
|
|
deps.onStep?.(m.package, i, missing.length);
|
|
let exit = null;
|
|
try { exit = await deps.run({ action: 'require', package: m.package, dev: true }, deps.onOutput); } catch { exit = null; }
|
|
if (!exit || exit.code !== 0) return { status: 'failed', done, failed: m.package };
|
|
done.push(m.package);
|
|
}
|
|
return { status: 'installed', done };
|
|
}
|