diff --git a/lib/installed-check.js b/lib/installed-check.js index 503eee5..e681693 100644 --- a/lib/installed-check.js +++ b/lib/installed-check.js @@ -4,13 +4,15 @@ import { performInstalledCheck } from './perform-installed-check.js'; /** @typedef {Omit & { cwd?: string|undefined }} LookupOptions */ -const ROOT = Symbol('workspace root'); +export const ROOT = Symbol('workspace root'); + +/** @typedef {{ [workspace: string]: boolean; [ROOT]?: boolean; }} WorkspaceSuccess */ /** * @param {import('./perform-installed-check.js').InstalledChecks[]} checks * @param {LookupOptions} [lookupOptions] * @param {import('./perform-installed-check.js').InstalledCheckOptions} [options] - * @returns {Promise} + * @returns {Promise} */ export async function installedCheck (checks, lookupOptions, options) { const { cwd = '.', ...lookupOptionsRest } = lookupOptions || {}; @@ -21,7 +23,10 @@ export async function installedCheck (checks, lookupOptions, options) { const warnings = new Map(); /** @type {Map} */ const suggestions = new Map(); + /** @type {WorkspaceSuccess} */ + const workspaceSuccess = {}; + // TODO: Optionally use a readWorkspaces() + npm API lookup instead for await (const item of workspaceLookup({ ...lookupOptionsRest, path: cwd })) { const result = await performInstalledCheck(checks, item.pkg, item.installed, options); @@ -30,12 +35,15 @@ export async function installedCheck (checks, lookupOptions, options) { errors.set(key, result.errors); warnings.set(key, result.warnings); suggestions.set(key, result.suggestions); + + workspaceSuccess[key] = result.errors.length === 0; } return { errors: prefixNotes(errors, lookupOptions), warnings: prefixNotes(warnings, lookupOptions), suggestions: prefixNotes(suggestions, lookupOptions), + workspaceSuccess, }; } diff --git a/test/installed-check.spec.js b/test/installed-check.spec.js index eb441d8..3138070 100644 --- a/test/installed-check.spec.js +++ b/test/installed-check.spec.js @@ -2,7 +2,7 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import { join } from 'desm'; -import { installedCheck } from '../lib/installed-check.js'; +import { ROOT, installedCheck } from '../lib/installed-check.js'; chai.use(chaiAsPromised); chai.should(); @@ -35,6 +35,7 @@ describe('installedCheck()', () => { errors: ["foo: Dependency is not installed. Can't check its version"], suggestions: [], warnings: ["foo: Dependency is not installed. Can't check its requirements"], + workspaceSuccess: { [ROOT]: false }, }); }); }); @@ -48,6 +49,7 @@ describe('installedCheck()', () => { errors: [], suggestions: [], warnings: [], + workspaceSuccess: { [ROOT]: true }, }); }); @@ -59,6 +61,7 @@ describe('installedCheck()', () => { errors: [], suggestions: [], warnings: [], + workspaceSuccess: { [ROOT]: true }, }); }); @@ -93,6 +96,7 @@ describe('installedCheck()', () => { 'invalid-module-version: Missing "engines.bar"', 'invalid-module-version: Missing "engines.abc"', ], + workspaceSuccess: { [ROOT]: false }, }); }); @@ -110,6 +114,7 @@ describe('installedCheck()', () => { warnings: [ 'Missing "engines.node" in main package', ], + workspaceSuccess: { [ROOT]: false }, }); }); @@ -125,6 +130,7 @@ describe('installedCheck()', () => { 'Incompatible combined "engines.node" requirements.', ], warnings: [], + workspaceSuccess: { [ROOT]: false }, }); }); @@ -136,6 +142,7 @@ describe('installedCheck()', () => { 'errors': [], suggestions: [], warnings: [], + workspaceSuccess: { [ROOT]: true }, }); }); @@ -161,6 +168,7 @@ describe('installedCheck()', () => { 'invalid-module-version: Missing "engines.bar"', 'invalid-module-version: Missing "engines.abc"', ], + workspaceSuccess: { [ROOT]: false }, }); }); @@ -177,6 +185,7 @@ describe('installedCheck()', () => { ], warnings: [ ], + workspaceSuccess: { [ROOT]: false }, }); }); @@ -198,6 +207,10 @@ describe('installedCheck()', () => { ], warnings: [ ], + workspaceSuccess: { + [ROOT]: false, + '@voxpelli/workspace-a': false, + }, }); }); @@ -217,6 +230,9 @@ describe('installedCheck()', () => { ], warnings: [ ], + workspaceSuccess: { + '@voxpelli/workspace-a': false, + }, }); }); });