From c4426b0da978c3bb85e1dca0fcfd16aa8ed6ec3a Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sat, 19 Oct 2019 13:37:47 +0200 Subject: [PATCH] =?UTF-8?q?fix(package=E2=80=91is=E2=80=91installable):=20?= =?UTF-8?q?use=C2=A0`WantedEngine`=20and=C2=A0`WantedPlatform`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #2099 --- .../package-is-installable/src/checkEngine.ts | 5 +---- .../package-is-installable/src/checkPlatform.ts | 11 ++++++++--- packages/package-is-installable/src/index.ts | 16 +++++++--------- packages/pnpm/src/packageIsInstallable.ts | 9 +++------ 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/package-is-installable/src/checkEngine.ts b/packages/package-is-installable/src/checkEngine.ts index 720333edef..32ddb82870 100644 --- a/packages/package-is-installable/src/checkEngine.ts +++ b/packages/package-is-installable/src/checkEngine.ts @@ -38,7 +38,4 @@ export type Engine = { pnpm: string, } -export type WantedEngine = { - node?: string, - pnpm?: string, -} +export type WantedEngine = Partial diff --git a/packages/package-is-installable/src/checkPlatform.ts b/packages/package-is-installable/src/checkPlatform.ts index 89faf016cd..29e27e99b5 100644 --- a/packages/package-is-installable/src/checkPlatform.ts +++ b/packages/package-is-installable/src/checkPlatform.ts @@ -1,17 +1,20 @@ import PnpmError from '@pnpm/error' export class UnsupportedPlatformError extends PnpmError { - public wanted: Platform + public wanted: WantedPlatform public current: Platform - constructor (packageId: string, wanted: Platform, current: Platform) { + constructor (packageId: string, wanted: WantedPlatform, current: Platform) { super('UNSUPPORTED_PLATFORM', `Unsupported platform for ${packageId}: wanted ${JSON.stringify(wanted)} (current: ${JSON.stringify(current)})`) this.wanted = wanted this.current = current } } -export default function checkPlatform (packageId: string, wantedPlatform: Platform) { +export default function checkPlatform ( + packageId: string, + wantedPlatform: WantedPlatform, +) { const platform = process.platform const arch = process.arch let osOk = true @@ -34,6 +37,8 @@ export type Platform = { os: string | string[], } +export type WantedPlatform = Partial + function checkList (value: string, list: string | string[]) { let tmp let match = false diff --git a/packages/package-is-installable/src/index.ts b/packages/package-is-installable/src/index.ts index 8a69cb8366..892d549fb7 100644 --- a/packages/package-is-installable/src/index.ts +++ b/packages/package-is-installable/src/index.ts @@ -2,12 +2,16 @@ import { installCheckLogger, skippedOptionalDependencyLogger, } from '@pnpm/core-loggers' -import checkEngine, { UnsupportedEngineError } from './checkEngine' +import checkEngine, { UnsupportedEngineError, WantedEngine } from './checkEngine' import checkPlatform, { UnsupportedPlatformError } from './checkPlatform' +export { Engine } from './checkEngine' +export { Platform, WantedPlatform } from './checkPlatform' + export { UnsupportedEngineError, UnsupportedPlatformError, + WantedEngine, } export default function packageIsInstallable ( @@ -15,10 +19,7 @@ export default function packageIsInstallable ( pkg: { name: string, version: string, - engines?: { - node?: string, - npm?: string, - }, + engines?: WantedEngine, cpu?: string[], os?: string[], }, @@ -62,10 +63,7 @@ export default function packageIsInstallable ( export function checkPackage ( pkgId: string, manifest: { - engines?: { - node?: string, - npm?: string, - }, + engines?: WantedEngine, cpu?: string[], os?: string[], }, diff --git a/packages/pnpm/src/packageIsInstallable.ts b/packages/pnpm/src/packageIsInstallable.ts index c268600787..7e7eba6d28 100644 --- a/packages/pnpm/src/packageIsInstallable.ts +++ b/packages/pnpm/src/packageIsInstallable.ts @@ -1,14 +1,11 @@ import logger from '@pnpm/logger' -import { checkPackage, UnsupportedEngineError } from '@pnpm/package-is-installable' +import { checkPackage, UnsupportedEngineError, WantedEngine } from '@pnpm/package-is-installable' import packageManager from './pnpmPkgJson' -export default function ( +export default function packageIsInstallable ( pkgPath: string, pkg: { - engines?: { - node?: string, - npm?: string, - }, + engines?: WantedEngine, cpu?: string[], os?: string[], },