mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-07 21:53:07 -05:00
refactor: remove getSaveType from @pnpm/utils
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import PnpmError from '@pnpm/error'
|
||||
import { getSaveType } from '@pnpm/utils'
|
||||
import {
|
||||
install,
|
||||
mutateModules,
|
||||
@@ -8,6 +7,7 @@ import {
|
||||
import createStoreController from '../createStoreController'
|
||||
import findWorkspacePackages, { arrayOfLocalPackagesToMap } from '../findWorkspacePackages'
|
||||
import getPinnedVersion from '../getPinnedVersion'
|
||||
import getSaveType from '../getSaveType'
|
||||
import { readImporterManifestOnly, tryReadImporterManifest } from '../readImporterManifest'
|
||||
import requireHooks from '../requireHooks'
|
||||
import { PnpmOptions } from '../types'
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import { cached as createStoreController } from '../createStoreController'
|
||||
import findWorkspacePackages, { arrayOfLocalPackagesToMap } from '../findWorkspacePackages'
|
||||
import getConfig from '../getConfig'
|
||||
import getSaveType from '../getSaveType'
|
||||
import readImporterManifest, {
|
||||
readImporterManifestOnly,
|
||||
tryReadImporterManifest,
|
||||
@@ -42,6 +43,7 @@ export default async (
|
||||
localPackages,
|
||||
store: store.path,
|
||||
storeController: store.ctrl,
|
||||
targetDependenciesField: getSaveType(opts),
|
||||
})
|
||||
|
||||
// pnpm link
|
||||
@@ -68,8 +70,8 @@ export default async (
|
||||
const pkgsFoundInWorkspace = workspacePackages.filter((pkg) => pkgNames.includes(pkg.manifest.name))
|
||||
pkgsFoundInWorkspace.forEach((pkgFromWorkspace) => pkgPaths.push(pkgFromWorkspace.path))
|
||||
|
||||
if (pkgsFoundInWorkspace.length && !linkOpts.saveDev && !linkOpts.saveProd && !linkOpts.saveOptional) {
|
||||
linkOpts.saveProd = true
|
||||
if (pkgsFoundInWorkspace.length && !linkOpts.targetDependenciesField) {
|
||||
linkOpts.targetDependenciesField = 'dependencies'
|
||||
}
|
||||
|
||||
globalPkgNames = pkgNames.filter((pkgName) => !pkgsFoundInWorkspace.some((pkgFromWorkspace) => pkgFromWorkspace.manifest.name === pkgName))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import PnpmError from '@pnpm/error'
|
||||
import logger from '@pnpm/logger'
|
||||
import { DependencyManifest, ImporterManifest, PackageManifest } from '@pnpm/types'
|
||||
import { getSaveType } from '@pnpm/utils'
|
||||
import camelcaseKeys = require('camelcase-keys')
|
||||
import graphSequencer = require('graph-sequencer')
|
||||
import isSubdir = require('is-subdir')
|
||||
@@ -11,7 +10,6 @@ import pFilter = require('p-filter')
|
||||
import pLimit from 'p-limit'
|
||||
import path = require('path')
|
||||
import createPkgGraph, { PackageNode } from 'pkgs-graph'
|
||||
import R = require('ramda')
|
||||
import readIniFile = require('read-ini-file')
|
||||
import {
|
||||
addDependenciesToPackage,
|
||||
@@ -26,6 +24,7 @@ import createStoreController from '../../createStoreController'
|
||||
import findWorkspacePackages, { arrayOfLocalPackagesToMap } from '../../findWorkspacePackages'
|
||||
import getCommandFullName from '../../getCommandFullName'
|
||||
import getPinnedVersion from '../../getPinnedVersion'
|
||||
import getSaveType from '../../getSaveType'
|
||||
import { scopeLogger } from '../../loggers'
|
||||
import parsePackageSelector, { PackageSelector } from '../../parsePackageSelectors'
|
||||
import requireHooks from '../../requireHooks'
|
||||
@@ -197,7 +196,6 @@ export async function recursive (
|
||||
&& pkgs.length === allPkgs.length,
|
||||
store: store.path,
|
||||
storeController,
|
||||
targetDependenciesField: getSaveType(opts),
|
||||
|
||||
forceHoistPattern: typeof opts.rawLocalConfig['hoist-pattern'] !== 'undefined' || typeof opts.rawLocalConfig['hoist'] !== 'undefined',
|
||||
forceIndependentLeaves: typeof opts.rawLocalConfig['independent-leaves'] !== 'undefined',
|
||||
@@ -273,7 +271,7 @@ export async function recursive (
|
||||
manifest,
|
||||
mutation,
|
||||
prefix,
|
||||
targetDependenciesField: getSaveType(installOpts),
|
||||
targetDependenciesField: getSaveType(opts),
|
||||
} as MutatedImporter)
|
||||
return
|
||||
case 'installSome':
|
||||
@@ -288,7 +286,7 @@ export async function recursive (
|
||||
savePrefix: typeof localConfig.savePrefix === 'string' ? localConfig.savePrefix : opts.savePrefix,
|
||||
}),
|
||||
prefix,
|
||||
targetDependenciesField: getSaveType(installOpts),
|
||||
targetDependenciesField: getSaveType(opts),
|
||||
} as MutatedImporter)
|
||||
return
|
||||
case 'install':
|
||||
|
||||
9
packages/pnpm/src/getSaveType.ts
Normal file
9
packages/pnpm/src/getSaveType.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Config } from '@pnpm/config'
|
||||
import { DependenciesField } from '@pnpm/types'
|
||||
|
||||
export default function getSaveType (opts: Pick<Config, 'saveDev' | 'saveOptional' | 'saveProd'>): DependenciesField | undefined {
|
||||
if (opts.saveDev) return 'devDependencies'
|
||||
if (opts.saveOptional) return 'optionalDependencies'
|
||||
if (opts.saveProd) return 'dependencies'
|
||||
return undefined
|
||||
}
|
||||
@@ -19,9 +19,6 @@ import {
|
||||
DependencyManifest,
|
||||
ImporterManifest,
|
||||
} from '@pnpm/types'
|
||||
import {
|
||||
getSaveType,
|
||||
} from '@pnpm/utils'
|
||||
import normalize = require('normalize-path')
|
||||
import path = require('path')
|
||||
import pathAbsolute = require('path-absolute')
|
||||
@@ -47,7 +44,6 @@ export default async function link (
|
||||
if (reporter) {
|
||||
streamParser.on('data', reporter)
|
||||
}
|
||||
maybeOpts.saveProd = maybeOpts.saveProd === true
|
||||
const opts = await extendOptions(maybeOpts)
|
||||
const ctx = await getContextForSingleImporter(opts.manifest, {
|
||||
...opts,
|
||||
@@ -58,7 +54,6 @@ export default async function link (
|
||||
const currentLockfile = R.clone(ctx.currentLockfile)
|
||||
const linkedPkgs: Array<{path: string, manifest: DependencyManifest, alias: string}> = []
|
||||
const specsToUpsert = [] as Array<{name: string, pref: string, saveType: DependenciesField}>
|
||||
const saveType = getSaveType(opts)
|
||||
|
||||
for (const linkFrom of linkFromPkgs) {
|
||||
let linkFromPath: string
|
||||
@@ -75,7 +70,7 @@ export default async function link (
|
||||
pref: getPref(manifest.name, manifest.name, manifest.version, {
|
||||
pinnedVersion: opts.pinnedVersion,
|
||||
}),
|
||||
saveType: (saveType || ctx.manifest && guessDependencyType(manifest.name, ctx.manifest)) as DependenciesField,
|
||||
saveType: (opts.targetDependenciesField || ctx.manifest && guessDependencyType(manifest.name, ctx.manifest)) as DependenciesField,
|
||||
})
|
||||
|
||||
const packagePath = normalize(path.relative(opts.prefix, linkFromPath))
|
||||
@@ -128,7 +123,7 @@ export default async function link (
|
||||
// TODO: cover with test that linking reports with correct dependency types
|
||||
const stu = specsToUpsert.find((s) => s.name === manifest.name)
|
||||
await symlinkDirectRootDependency(path, destModules, alias, {
|
||||
fromDependenciesField: stu && stu.saveType || saveType,
|
||||
fromDependenciesField: stu && stu.saveType || opts.targetDependenciesField,
|
||||
linkedPackage: manifest,
|
||||
prefix: opts.prefix,
|
||||
})
|
||||
@@ -140,7 +135,7 @@ export default async function link (
|
||||
})
|
||||
|
||||
let newPkg!: ImporterManifest
|
||||
if (opts.saveDev || opts.saveProd || opts.saveOptional) {
|
||||
if (opts.targetDependenciesField) {
|
||||
newPkg = await save(opts.prefix, opts.manifest, specsToUpsert)
|
||||
for (const { name } of specsToUpsert) {
|
||||
updatedWantedLockfile.importers[importerId].specifiers[name] = getSpecFromPackageManifest(newPkg, name)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { StoreController } from '@pnpm/store-controller-types'
|
||||
import { ImporterManifest, Registries } from '@pnpm/types'
|
||||
import {
|
||||
DependenciesField,
|
||||
ImporterManifest,
|
||||
Registries,
|
||||
} from '@pnpm/types'
|
||||
import { DEFAULT_REGISTRIES, normalizeRegistries } from '@pnpm/utils'
|
||||
import path = require('path')
|
||||
import { ReporterFunction } from '../types'
|
||||
@@ -11,15 +15,13 @@ interface StrictLinkOptions {
|
||||
useLockfile: boolean,
|
||||
lockfileDirectory: string,
|
||||
pinnedVersion: 'major' | 'minor' | 'patch',
|
||||
saveProd: boolean,
|
||||
saveDev: boolean,
|
||||
saveOptional: boolean,
|
||||
storeController: StoreController,
|
||||
manifest: ImporterManifest,
|
||||
prefix: string,
|
||||
registries: Registries,
|
||||
store: string,
|
||||
reporter: ReporterFunction,
|
||||
targetDependenciesField?: DependenciesField,
|
||||
|
||||
hoistPattern: string[] | undefined,
|
||||
forceHoistPattern: boolean,
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { DependenciesField, PnpmOptions } from '@pnpm/types'
|
||||
|
||||
export default function getSaveType (opts: PnpmOptions): DependenciesField | undefined {
|
||||
if (opts.saveDev) return 'devDependencies'
|
||||
if (opts.saveOptional) return 'optionalDependencies'
|
||||
if (opts.saveProd) return 'dependencies'
|
||||
return undefined
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import getAllDependenciesFromPackage from './getAllDependenciesFromPackage'
|
||||
import getSaveType from './getSaveType'
|
||||
import normalizeRegistries, { DEFAULT_REGISTRIES } from './normalizeRegistries'
|
||||
import pickRegistryForPackage from './pickRegistryForPackage'
|
||||
import realNodeModulesDir from './realNodeModulesDir'
|
||||
@@ -10,7 +9,6 @@ export const readPackage = safeReadPackage
|
||||
export {
|
||||
DEFAULT_REGISTRIES,
|
||||
getAllDependenciesFromPackage,
|
||||
getSaveType,
|
||||
normalizeRegistries,
|
||||
pickRegistryForPackage,
|
||||
realNodeModulesDir,
|
||||
|
||||
Reference in New Issue
Block a user