mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-19 07:37:37 -05:00
25 lines
766 B
TypeScript
25 lines
766 B
TypeScript
import path from 'path'
|
|
import { type ParseWantedDependencyResult } from '@pnpm/parse-wanted-dependency'
|
|
|
|
export interface GetEditDirOptions {
|
|
modulesDir: string
|
|
}
|
|
|
|
export function getEditDirPath (param: string, patchedDep: ParseWantedDependencyResult, opts: GetEditDirOptions): string {
|
|
const editDirName = getEditDirNameFromParsedDep(patchedDep) ?? param
|
|
return path.join(opts.modulesDir, '.pnpm_patches', editDirName)
|
|
}
|
|
|
|
function getEditDirNameFromParsedDep (patchedDep: ParseWantedDependencyResult): string | undefined {
|
|
if (patchedDep.alias && patchedDep.pref) {
|
|
const pref = patchedDep.pref.replace(/[\\/:*?"<>|]+/g, '+')
|
|
return `${patchedDep.alias}@${pref}`
|
|
}
|
|
|
|
if (patchedDep.alias) {
|
|
return patchedDep.alias
|
|
}
|
|
|
|
return undefined
|
|
}
|