Files
pnpm/patching/plugin-commands-patching/src/updatePatchedDependencies.ts
btea 17b7e9fbb3 fix(patch): saved path file should be relative path (#9403)
* fix(patch): saved path file should be relative path

* fix: update relative dir

* fix: update

* fix: paths in patchedDependencies should be normalized

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
2025-04-14 11:42:14 +02:00

23 lines
809 B
TypeScript

import path from 'path'
import normalizePath from 'normalize-path'
import { writeSettings, type WriteSettingsOptions } from '@pnpm/config.config-writer'
export async function updatePatchedDependencies (
patchedDependencies: Record<string, string>,
opts: Omit<WriteSettingsOptions, 'updatedSettings'>
): Promise<void> {
const workspaceDir = opts.workspaceDir ?? opts.rootProjectManifestDir
for (const [patchName, patchPath] of Object.entries(patchedDependencies)) {
if (path.isAbsolute(patchPath)) {
patchedDependencies[patchName] = normalizePath(path.relative(workspaceDir, patchPath))
}
}
await writeSettings({
...opts,
workspaceDir,
updatedSettings: {
patchedDependencies: Object.keys(patchedDependencies).length ? patchedDependencies : undefined,
},
})
}