fix(package‑is‑installable): use WantedEngine and WantedPlatform

PR #2099
This commit is contained in:
ExE Boss
2019-10-19 13:37:47 +02:00
committed by Zoltan Kochan
parent 2251259b8c
commit c4426b0da9
4 changed files with 19 additions and 22 deletions

View File

@@ -38,7 +38,4 @@ export type Engine = {
pnpm: string,
}
export type WantedEngine = {
node?: string,
pnpm?: string,
}
export type WantedEngine = Partial<Engine>

View File

@@ -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<Platform>
function checkList (value: string, list: string | string[]) {
let tmp
let match = false

View File

@@ -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[],
},

View File

@@ -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[],
},