-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #115 And removes `getInstalledData()`, which now lives in `list-installed` instead
- Loading branch information
Showing
22 changed files
with
222 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ | |
*.d.ts | ||
*.d.ts.map | ||
!/lib/**/*-types.d.ts | ||
!/index.d.ts | ||
|
||
# Library specific ones |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
|
||
{ | ||
"extends": "./tsconfig", | ||
"files": [], | ||
"exclude": [ | ||
"test/**/*" | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type * from './lib/lookup-types.d.ts'; | ||
|
||
export type { VersionRangeItem, VersionRangeOptions, VersionRangeResult, VersionRangesOptions } from './lib/check-version-range.js'; | ||
export type { LookupOptions } from './lib/installed-check.js'; | ||
export type { InstalledChecks, InstalledCheckOptions, InstalledCheckResult } from './lib/perform-installed-check.js'; | ||
|
||
export { checkVersionRange, checkVersionRangeCollection } from './lib/check-version-range.js'; | ||
export { installedCheck } from './lib/installed-check.js'; | ||
export { performInstalledCheck } from './lib/perform-installed-check.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,3 @@ | ||
/** @typedef {import('./lib/check-version-range.js').VersionRangeItem} VersionRangeItem */ | ||
/** @typedef {import('./lib/check-version-range.js').VersionRangeOptions} VersionRangeOptions */ | ||
/** @typedef {import('./lib/check-version-range.js').VersionRangeResult} VersionRangeResult */ | ||
/** @typedef {import('./lib/check-version-range.js').VersionRangeOptions} VersionRangesOptions */ | ||
|
||
/** @typedef {import('./lib/get-installed-data.js').PackageJsonLike} PackageJsonLike */ | ||
/** @typedef {import('./lib/get-installed-data.js').InstalledDependencies} InstalledDependencies */ | ||
|
||
/** @typedef {import('./lib/perform-installed-check.js').InstalledChecks} InstalledChecks */ | ||
/** @typedef {import('./lib/perform-installed-check.js').InstalledCheckOptions} InstalledCheckOptions */ | ||
/** @typedef {import('./lib/perform-installed-check.js').InstalledCheckResult} InstalledCheckResult */ | ||
|
||
export { checkVersionRange, checkVersionRangeCollection } from './lib/check-version-range.js'; | ||
export { getInstalledData } from './lib/get-installed-data.js'; | ||
export { installedCheck } from './lib/installed-check.js'; | ||
export { performInstalledCheck } from './lib/perform-installed-check.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,50 @@ | ||
import { getInstalledData } from './get-installed-data.js'; | ||
import { workspaceLookup } from 'list-installed'; | ||
|
||
import { performInstalledCheck } from './perform-installed-check.js'; | ||
|
||
/** @typedef {Omit<import('list-installed').WorkspaceLookupOptions, 'path'> & { cwd?: string }} LookupOptions */ | ||
|
||
const ROOT = Symbol('workspace root'); | ||
|
||
/** | ||
* @param {import('./perform-installed-check.js').InstalledChecks[]} checks | ||
* @param {import('./perform-installed-check.js').InstalledCheckOptions & { cwd?: string }} [options] | ||
* @param {LookupOptions} [lookupOptions] | ||
* @param {import('./perform-installed-check.js').InstalledCheckOptions} [options] | ||
* @returns {Promise<import('./perform-installed-check.js').InstalledCheckResult>} | ||
*/ | ||
export async function installedCheck (checks, options) { | ||
const { cwd = '.', ...checkOptions } = options || {}; | ||
export async function installedCheck (checks, lookupOptions, options) { | ||
const { cwd = '.', ...lookupOptionsRest } = lookupOptions || {}; | ||
|
||
/** @type {Map<string|ROOT, string[]>} */ | ||
const errors = new Map(); | ||
/** @type {Map<string|ROOT, string[]>} */ | ||
const warnings = new Map(); | ||
|
||
for await (const item of workspaceLookup({ ...lookupOptionsRest, path: cwd })) { | ||
const result = await performInstalledCheck(checks, item.pkg, item.installed, options); | ||
|
||
const { installed, pkg } = await getInstalledData(cwd); | ||
const key = 'workspace' in item ? item.workspace : ROOT; | ||
|
||
return performInstalledCheck(checks, pkg, installed, checkOptions); | ||
errors.set(key, result.errors); | ||
warnings.set(key, result.warnings); | ||
} | ||
|
||
return { | ||
errors: prefixNotes(errors, lookupOptions), | ||
warnings: prefixNotes(warnings, lookupOptions), | ||
}; | ||
} | ||
|
||
/** | ||
* @param {Map<string|ROOT, string[]>} notes | ||
* @param {LookupOptions} [lookupOptions] | ||
* @returns {string[]} | ||
*/ | ||
function prefixNotes (notes, lookupOptions) { | ||
if (lookupOptions?.includeWorkspaceRoot !== false && notes.size === 1) { | ||
return [...notes.values()].flat(); | ||
} | ||
return [...notes].flatMap(([key, items]) => | ||
items.map(item => `${key === ROOT ? 'root' : key}: ${item}`) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type PackageJsonLike = { | ||
name?: string | undefined; | ||
version?: string | undefined; | ||
engines?: Record<string, string | undefined>; | ||
dependencies?: Record<string, string | undefined>; | ||
devDependencies?: Record<string, string | undefined>; | ||
optionalDependencies?: Record<string, string | undefined>; | ||
peerDependencies?: Record<string, string | undefined>; | ||
}; | ||
|
||
export type InstalledDependencies = Map<string, PackageJsonLike> | Record<string, PackageJsonLike>; |
Oops, something went wrong.