style: fix

This commit is contained in:
Zoltan Kochan
2021-03-17 23:27:28 +02:00
parent 0d68aa002e
commit 903314f4d6
27 changed files with 70 additions and 70 deletions

View File

@@ -69,7 +69,7 @@ export default function<T> (pkgs: Array<Package & T>, opts?: {
if (spec.type === 'directory') {
const matchedPkg = R.values(pkgMap).find(pkg => path.relative(pkg.dir, spec.fetchSpec) === '')
if (!matchedPkg) {
if (matchedPkg == null) {
return ''
}
return matchedPkg.dir
@@ -78,7 +78,7 @@ export default function<T> (pkgs: Array<Package & T>, opts?: {
if (spec.type !== 'version' && spec.type !== 'range') return ''
const pkgs = R.values(pkgMap).filter(pkg => pkg.manifest.name === depName)
if (!pkgs.length) return ''
if (pkgs.length === 0) return ''
const versions = pkgs.filter(({ manifest }) => manifest.version)
.map(pkg => pkg.manifest.version) as string[]

View File

@@ -96,7 +96,7 @@ export async function handler (
} & Pick<Config, 'fetchRetries' | 'fetchRetryMaxtimeout' | 'fetchRetryMintimeout' | 'fetchRetryFactor' | 'production' | 'dev' | 'optional'>
) {
const lockfile = await readWantedLockfile(opts.lockfileDir ?? opts.dir, { ignoreIncompatible: true })
if (!lockfile) {
if (lockfile == null) {
throw new PnpmError('AUDIT_NO_LOCKFILE', `No ${WANTED_LOCKFILE} found: Cannot audit a project without a lockfile`)
}
const include = {

View File

@@ -84,7 +84,7 @@ function getAllVersionsByPackageNames (
[packageName: string]: Set<string>
}
) {
if (!npmPackageLock.dependencies) return
if (npmPackageLock.dependencies == null) return
for (const packageName of Object.keys(npmPackageLock.dependencies)) {
if (!versionsByPackageNames[packageName]) {
versionsByPackageNames[packageName] = new Set()

View File

@@ -167,7 +167,7 @@ export async function handler (
if (opts.cliOptions['save'] === false) {
throw new PnpmError('OPTION_NOT_SUPPORTED', 'The "add" command currently does not support the no-save option')
}
if (!params || !params.length) {
if (!params || (params.length === 0)) {
throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm add` requires the package name')
}
if (

View File

@@ -119,7 +119,7 @@ when running add/update with the --workspace option')
)
if (opts.workspaceDir) {
const selectedProjectsGraph = opts.selectedProjectsGraph ?? selectProjectByDir(allProjects, opts.dir)
if (selectedProjectsGraph) {
if (selectedProjectsGraph != null) {
await recursive(allProjects,
params,
{
@@ -172,24 +172,24 @@ when running add/update with the --workspace option')
manifest = {}
}
const updateMatch = opts.update && params.length ? createMatcher(params) : null
if (updateMatch) {
const updateMatch = opts.update && (params.length > 0) ? createMatcher(params) : null
if (updateMatch != null) {
params = matchDependencies(updateMatch, manifest, includeDirect)
if (!params.length) {
if (params.length === 0) {
throw new PnpmError('NO_PACKAGE_IN_DEPENDENCIES',
'None of the specified packages were found in the dependencies.')
}
}
if (opts.update && opts.latest) {
if (!params || !params.length) {
if (!params || (params.length === 0)) {
params = updateToLatestSpecsFromManifest(manifest, includeDirect)
} else {
params = createLatestSpecs(params, manifest)
}
}
if (opts.workspace) {
if (!params || !params.length) {
if (!params || (params.length === 0)) {
params = updateToWorkspacePackagesFromManifest(manifest, includeDirect, workspacePackages)
} else {
params = createWorkspaceSpecs(params, workspacePackages)
@@ -258,6 +258,6 @@ when running add/update with the --workspace option')
function selectProjectByDir (projects: Project[], searchedDir: string) {
const project = projects.find(({ dir }) => path.relative(dir, searchedDir) === '')
if (!project) return undefined
if (project == null) return undefined
return { [searchedDir]: { dependencies: [], package: project } }
}

View File

@@ -104,7 +104,7 @@ export async function handler (
})
// pnpm link
if (!params || !params.length) {
if ((params == null) || (params.length === 0)) {
const { manifest, writeProjectManifest } = await tryReadProjectManifest(opts.dir, opts)
const newManifest = await linkToGlobal(cwd, {
...linkOpts,
@@ -119,7 +119,7 @@ export async function handler (
const [pkgPaths, pkgNames] = R.partition((inp) => isFilespec.test(inp), params)
if (pkgNames.length) {
if (pkgNames.length > 0) {
let globalPkgNames!: string[]
if (opts.workspaceDir) {
workspacePackagesArr = await findWorkspacePackages(opts.workspaceDir, opts)
@@ -128,7 +128,7 @@ export async function handler (
.filter(({ manifest }) => manifest.name && pkgNames.includes(manifest.name))
pkgsFoundInWorkspace.forEach((pkgFromWorkspace) => pkgPaths.push(pkgFromWorkspace.dir))
if (pkgsFoundInWorkspace.length && !linkOpts.targetDependenciesField) {
if ((pkgsFoundInWorkspace.length > 0) && !linkOpts.targetDependenciesField) {
linkOpts.targetDependenciesField = 'dependencies'
}

View File

@@ -116,7 +116,7 @@ export default async function recursive (
linkWorkspacePackagesDepth: opts.linkWorkspacePackages === 'deep' ? Infinity : opts.linkWorkspacePackages ? 0 : -1,
ownLifecycleHooksStdio: 'pipe',
peer: opts.savePeer,
pruneLockfileImporters: (!opts.ignoredPackages || opts.ignoredPackages.size === 0) &&
pruneLockfileImporters: ((opts.ignoredPackages == null) || opts.ignoredPackages.size === 0) &&
pkgs.length === allProjects.length,
storeController: store.ctrl,
storeDir: store.dir,
@@ -137,7 +137,7 @@ export default async function recursive (
async function getImporters () {
const importers = [] as Array<{ buildIndex: number, manifest: ProjectManifest, rootDir: string }>
await Promise.all(chunks.map(async (prefixes: string[], buildIndex) => {
if (opts.ignoredPackages) {
if (opts.ignoredPackages != null) {
prefixes = prefixes.filter((prefix) => !opts.ignoredPackages!.has(prefix))
}
return Promise.all(
@@ -160,7 +160,7 @@ export default async function recursive (
optionalDependencies: true,
}
const updateMatch = cmdFullName === 'update' && params.length ? createMatcher(params) : null
const updateMatch = cmdFullName === 'update' && (params.length > 0) ? createMatcher(params) : null
// For a workspace with shared lockfile
if (opts.lockfileDir && ['add', 'install', 'remove', 'update'].includes(cmdFullName)) {
@@ -178,26 +178,26 @@ export default async function recursive (
const modulesDir = localConfig.modulesDir ?? opts.modulesDir
const { manifest, writeProjectManifest } = manifestsByPath[rootDir]
let currentInput = [...params]
if (updateMatch) {
if (updateMatch != null) {
currentInput = matchDependencies(updateMatch, manifest, includeDirect)
if (!currentInput.length && (typeof opts.depth === 'undefined' || opts.depth <= 0)) {
if ((currentInput.length === 0) && (typeof opts.depth === 'undefined' || opts.depth <= 0)) {
installOpts.pruneLockfileImporters = false
return
}
}
if (updateToLatest) {
if (!params || !params.length) {
if (!params || (params.length === 0)) {
currentInput = updateToLatestSpecsFromManifest(manifest, includeDirect)
} else {
currentInput = createLatestSpecs(currentInput, manifest)
if (!currentInput.length) {
if (currentInput.length === 0) {
installOpts.pruneLockfileImporters = false
return
}
}
}
if (opts.workspace) {
if (!currentInput || !currentInput.length) {
if (!currentInput || (currentInput.length === 0)) {
currentInput = updateToWorkspacePackagesFromManifest(manifest, includeDirect, workspacePackages)
} else {
currentInput = createWorkspaceSpecs(currentInput, workspacePackages)
@@ -241,7 +241,7 @@ export default async function recursive (
} as MutatedProject)
}
}))
if (!mutatedImporters.length && cmdFullName === 'update') {
if ((mutatedImporters.length === 0) && cmdFullName === 'update') {
throw new PnpmError('NO_PACKAGE_IN_DEPENDENCIES',
'None of the specified packages were found in the dependencies of any of the projects.')
}
@@ -274,20 +274,20 @@ export default async function recursive (
const { manifest, writeProjectManifest } = manifestsByPath[rootDir]
let currentInput = [...params]
if (updateMatch) {
if (updateMatch != null) {
currentInput = matchDependencies(updateMatch, manifest, includeDirect)
if (!currentInput.length) return
if (currentInput.length === 0) return
}
if (updateToLatest) {
if (!params || !params.length) {
if (!params || (params.length === 0)) {
currentInput = updateToLatestSpecsFromManifest(manifest, includeDirect)
} else {
currentInput = createLatestSpecs(currentInput, manifest)
if (!currentInput.length) return
if (currentInput.length === 0) return
}
}
if (opts.workspace) {
if (!currentInput || !currentInput.length) {
if (!currentInput || (currentInput.length === 0)) {
currentInput = updateToWorkspacePackagesFromManifest(manifest, includeDirect, workspacePackages)
} else {
currentInput = createWorkspaceSpecs(currentInput, workspacePackages)
@@ -440,7 +440,7 @@ function calculateRepositoryRoot (
for (const rootDir of projectDirs) {
const relativePartRegExp = new RegExp(`^(\\.\\.\\${path.sep})+`)
const relativePartMatch = relativePartRegExp.exec(path.relative(workspaceDir, rootDir))
if (relativePartMatch) {
if (relativePartMatch != null) {
const relativePart = relativePartMatch[0]
if (relativePart.length > relativeRepoRoot.length) {
relativeRepoRoot = relativePart

View File

@@ -146,7 +146,7 @@ export async function handler (
params: string[]
) {
if (params.length === 0) throw new PnpmError('MUST_REMOVE_SOMETHING', 'At least one dependency name should be specified for removal')
if (opts.recursive && opts.allProjects && opts.selectedProjectsGraph && opts.workspaceDir) {
if (opts.recursive && (opts.allProjects != null) && (opts.selectedProjectsGraph != null) && opts.workspaceDir) {
await recursive(opts.allProjects, params, { ...opts, selectedProjectsGraph: opts.selectedProjectsGraph, workspaceDir: opts.workspaceDir }, 'remove')
return
}

View File

@@ -57,7 +57,7 @@ export async function handler (
},
params: string[]
) {
if (opts.recursive && opts.allProjects && opts.selectedProjectsGraph && opts.workspaceDir) {
if (opts.recursive && (opts.allProjects != null) && (opts.selectedProjectsGraph != null) && opts.workspaceDir) {
await recursive(opts.allProjects, params, { ...opts, selectedProjectsGraph: opts.selectedProjectsGraph, workspaceDir: opts.workspaceDir }, 'unlink')
return
}
@@ -68,7 +68,7 @@ export async function handler (
storeDir: store.dir,
})
if (!params || !params.length) {
if (!params || (params.length === 0)) {
return mutateModules([
{
dependencyNames: params,

View File

@@ -173,7 +173,7 @@ async function interactiveUpdate (
devDependencies: opts.dev !== false,
optionalDependencies: opts.optional !== false,
}
const projects = opts.selectedProjectsGraph
const projects = (opts.selectedProjectsGraph != null)
? Object.values(opts.selectedProjectsGraph).map((wsPkg) => wsPkg.package)
: [
{
@@ -245,7 +245,7 @@ async function update (
depth,
includeDirect,
update: true,
updateMatching: dependencies.length && dependencies.every(dep => !dep.substring(1).includes('@')) && depth > 0 && !opts.latest
updateMatching: (dependencies.length > 0) && dependencies.every(dep => !dep.substring(1).includes('@')) && depth > 0 && !opts.latest
? matcher(dependencies)
: undefined,
updatePackageManifest: opts.save !== false,

View File

@@ -11,7 +11,7 @@ export default function updateToLatestSpecsFromManifest (manifest: ProjectManife
updateSpecs.push(`${depName}@${removeVersionFromSpec(depVersion)}@latest`)
} else {
const selector = getVerSelType(depVersion)
if (!selector) continue
if (selector == null) continue
updateSpecs.push(`${depName}@latest`)
}
}
@@ -32,7 +32,7 @@ export function createLatestSpecs (specs: string[], manifest: ProjectManifest) {
if (allDeps[selector].startsWith('npm:')) {
return `${selector}@${removeVersionFromSpec(allDeps[selector])}@latest`
}
if (!getVerSelType(allDeps[selector])) {
if (getVerSelType(allDeps[selector]) == null) {
return selector
}
return `${selector}@latest`

View File

@@ -134,7 +134,7 @@ export async function handler (
optionalDependencies: opts.optional !== false,
}
const depth = opts.cliOptions?.['depth'] ?? 0
if (opts.recursive && opts.selectedProjectsGraph) {
if (opts.recursive && (opts.selectedProjectsGraph != null)) {
const pkgs = Object.values(opts.selectedProjectsGraph).map((wsPkg) => wsPkg.package)
return listRecursive(pkgs, params, { ...opts, depth, include })
}
@@ -168,7 +168,7 @@ export async function render (
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
reportAs: (opts.parseable ? 'parseable' : (opts.json ? 'json' : 'tree')) as ('parseable' | 'json' | 'tree'),
}
return params.length
return (params.length > 0)
? listForPackages(params, prefixes, listOpts)
: list(prefixes, listOpts)
}

View File

@@ -96,7 +96,7 @@ export async function handler (
opts: ListCommandOptions,
params: string[]
) {
if (!params.length) {
if (params.length === 0) {
throw new PnpmError('MISSING_PACKAGE_NAME', '`pnpm why` requires the package name')
}
return list({

View File

@@ -161,7 +161,7 @@ export async function handler (
devDependencies: opts.dev !== false,
optionalDependencies: opts.optional !== false,
}
if (opts.recursive && opts.selectedProjectsGraph) {
if (opts.recursive && (opts.selectedProjectsGraph != null)) {
const pkgs = Object.values(opts.selectedProjectsGraph).map((wsPkg) => wsPkg.package)
return outdatedRecursive(pkgs, params, { ...opts, include })
}
@@ -177,7 +177,7 @@ export async function handler (
include,
})
if (!outdatedPackages.length) return { output: '', exitCode: 0 }
if (outdatedPackages.length === 0) return { output: '', exitCode: 0 }
if (opts.table !== false) {
return { output: renderOutdatedTable(outdatedPackages, opts), exitCode: 1 }
@@ -253,7 +253,7 @@ export function getCellWidth (data: string[][], columnNumber: number, maxWidth:
}
export function toOutdatedWithVersionDiff<T> (outdated: T & OutdatedPackage): T & OutdatedWithVersionDiff {
if (outdated.latestManifest) {
if (outdated.latestManifest != null) {
return {
...outdated,
...semverDiff(outdated.wanted, outdated.latestManifest.version),
@@ -281,8 +281,8 @@ export function renderCurrent ({ current, wanted }: OutdatedPackage) {
export function renderLatest (outdatedPkg: OutdatedWithVersionDiff): string {
const { latestManifest, change, diff } = outdatedPkg
if (!latestManifest) return ''
if (change === null || !diff) {
if (latestManifest == null) return ''
if (change === null || (diff == null)) {
return latestManifest.deprecated
? chalk.redBright.bold('Deprecated')
: latestManifest.version
@@ -292,7 +292,7 @@ export function renderLatest (outdatedPkg: OutdatedWithVersionDiff): string {
}
export function renderDetails ({ latestManifest }: OutdatedPackage) {
if (!latestManifest) return ''
if (latestManifest == null) return ''
const outputs = []
if (latestManifest.deprecated) {
outputs.push(wrapAnsi(chalk.redBright(latestManifest.deprecated), 40))

View File

@@ -129,7 +129,7 @@ Do you want to continue?`,
})
}
}
if (opts.recursive && opts.selectedProjectsGraph) {
if (opts.recursive && (opts.selectedProjectsGraph != null)) {
await recursivePublish({
...opts,
selectedProjectsGraph: opts.selectedProjectsGraph,
@@ -137,11 +137,11 @@ Do you want to continue?`,
})
return
}
if (params.length && params[0].endsWith('.tgz')) {
if ((params.length > 0) && params[0].endsWith('.tgz')) {
runNpm(opts.npmPath, ['publish', ...params])
return
}
const dir = params.length && params[0] || process.cwd()
const dir = (params.length > 0) && params[0] || process.cwd()
const _runScriptsIfPresent = runScriptsIfPresent.bind(null, {
depPath: dir,

View File

@@ -82,13 +82,13 @@ export async function rebuildPkgs (
maybeOpts: RebuildOptions
) {
const reporter = maybeOpts?.reporter
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.on('data', reporter)
}
const opts = await extendOptions(maybeOpts)
const ctx = await getContext(projects, opts)
if (!ctx.currentLockfile || !ctx.currentLockfile.packages) return
if (!ctx.currentLockfile || (ctx.currentLockfile.packages == null)) return
const packages = ctx.currentLockfile.packages
const searched: PackageSelector[] = pkgSpecs.map((arg) => {
@@ -127,7 +127,7 @@ export async function rebuild (
maybeOpts: RebuildOptions
) {
const reporter = maybeOpts?.reporter
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.on('data', reporter)
}
const opts = await extendOptions(maybeOpts)
@@ -137,7 +137,7 @@ export async function rebuild (
if (opts.pending) {
idsToRebuild = ctx.pendingBuilds
} else if (ctx.currentLockfile?.packages) {
} else if ((ctx.currentLockfile?.packages) != null) {
idsToRebuild = Object.keys(ctx.currentLockfile.packages)
}
@@ -165,7 +165,7 @@ export async function rebuild (
scriptsOpts
)
for (const { id, manifest } of ctx.projects) {
if (manifest?.scripts && (!opts.pending || ctx.pendingBuilds.includes(id))) {
if (((manifest?.scripts) != null) && (!opts.pending || ctx.pendingBuilds.includes(id))) {
ctx.pendingBuilds.splice(ctx.pendingBuilds.indexOf(id), 1)
}
}

View File

@@ -86,7 +86,7 @@ export async function handler (
},
params: string[]
) {
if (opts.recursive && opts.allProjects && opts.selectedProjectsGraph && opts.workspaceDir) {
if (opts.recursive && (opts.allProjects != null) && (opts.selectedProjectsGraph != null) && opts.workspaceDir) {
await recursive(opts.allProjects, params, { ...opts, selectedProjectsGraph: opts.selectedProjectsGraph, workspaceDir: opts.workspaceDir })
return
}

View File

@@ -63,7 +63,7 @@ export default async function recursive (
const workspacePackages = arrayOfWorkspacePackagesToMap(allProjects)
const rebuildOpts = Object.assign(opts, {
ownLifecycleHooksStdio: 'pipe',
pruneLockfileImporters: (!opts.ignoredPackages || opts.ignoredPackages.size === 0) &&
pruneLockfileImporters: ((opts.ignoredPackages == null) || opts.ignoredPackages.size === 0) &&
pkgs.length === allProjects.length,
storeController: store.ctrl,
storeDir: store.dir,
@@ -80,7 +80,7 @@ export default async function recursive (
async function getImporters () {
const importers = [] as Array<{ buildIndex: number, manifest: ProjectManifest, rootDir: string }>
await Promise.all(chunks.map(async (prefixes: string[], buildIndex) => {
if (opts.ignoredPackages) {
if (opts.ignoredPackages != null) {
prefixes = prefixes.filter((prefix) => !opts.ignoredPackages!.has(prefix))
}
return Promise.all(

View File

@@ -247,11 +247,11 @@ function printProjectCommands (
if (output !== '') output += '\n\n'
output += `Commands available via "pnpm run":\n${renderCommands(otherScripts)}`
}
if (!rootManifest?.scripts) {
if ((rootManifest?.scripts) == null) {
return output
}
const rootScripts = Object.entries(rootManifest.scripts)
if (!rootScripts.length) {
if (rootScripts.length === 0) {
return output
}
if (output !== '') output += '\n\n'

View File

@@ -98,7 +98,7 @@ async function statusCmd (opts: StoreCommandOptions) {
const modifiedPkgs = await storeStatus(Object.assign(opts, {
storeDir: await storePath(opts.dir, opts.storeDir),
}))
if (!modifiedPkgs || !modifiedPkgs.length) {
if (!modifiedPkgs || (modifiedPkgs.length === 0)) {
logger.info({
message: 'Packages in the store are untouched',
prefix: opts.dir,

View File

@@ -17,7 +17,7 @@ export default async function (
}
) {
const reporter = opts?.reporter
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.on('data', reporter)
}
@@ -45,7 +45,7 @@ export default async function (
}
}))
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.removeListener('data', reporter)
}

View File

@@ -9,13 +9,13 @@ export default async function (
}
) {
const reporter = opts?.reporter
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.on('data', reporter)
}
await opts.storeController.prune()
await opts.storeController.close()
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.removeListener('data', reporter)
}
}

View File

@@ -13,7 +13,7 @@ import extendOptions, {
export default async function (maybeOpts: StoreStatusOptions) {
const reporter = maybeOpts?.reporter
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.on('data', reporter)
}
const opts = await extendOptions(maybeOpts)
@@ -50,7 +50,7 @@ export default async function (maybeOpts: StoreStatusOptions) {
return (await dint.check(path.join(virtualStoreDir, dp.depPathToFilename(depPath, opts.dir), 'node_modules', name), files)) === false
}, { concurrency: 8 })
if (reporter && typeof reporter === 'function') {
if ((reporter != null) && typeof reporter === 'function') {
streamParser.removeListener('data', reporter)
}

View File

@@ -11,7 +11,7 @@ export default async function () {
const notifier = updateNotifier({ pkg: packageManager })
const update = notifier.update
if (!update) {
if (update == null) {
return
}

View File

@@ -109,7 +109,7 @@ for (let i = 0; i < commands.length; i++) {
helpByCommandName[commandName] = help
cliOptionsTypesByCommandName[commandName] = cliOptionsTypes
shorthandsByCommandName[commandName] = shorthands ?? {}
if (completion) {
if (completion != null) {
completionByCommandName[commandName] = completion
}
Object.assign(rcOptionsTypes, rcOptionsTypes())

View File

@@ -165,7 +165,7 @@ export default async function run (inputArgv: string[]) {
patterns: cliOptions['workspace-packages'],
})
if (!allProjects.length) {
if (allProjects.length === 0) {
if (!config['parseable']) {
console.log(`No projects found in "${wsDir}"`)
}

View File

@@ -1,6 +1,6 @@
import path from 'path'
import prepare from '@pnpm/prepare'
import { promises as fs } from 'fs'
import prepare from '@pnpm/prepare'
import isWindows from 'is-windows'
import pathExists from 'path-exists'
import {