Skip to content

Commit e2fd5aa

Browse files
committed
feat: add pnpm support
1 parent d3dcf29 commit e2fd5aa

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ createPatch(
4646
## 🔄 TODO
4747

4848
- `npm` patch support
49-
- `pnpm` patch support
5049

5150
## 🛠️ Contributing
5251

‎src/applyPatch.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,27 @@ import { readFileSync, writeFileSync } from 'node:fs'
33
import { join } from 'node:path'
44
import { applyPatch } from 'diff'
55

6+
const PACKAGE_MANAGER_MAP = {
7+
yarn: {
8+
patch: 'yarn patch',
9+
patchCommit: 'yarn patch-commit -s'
10+
},
11+
pnpm: {
12+
patch: 'pnpm patch',
13+
patchCommit: 'pnpm patch-commit'
14+
}
15+
}
16+
617
function run(command: string): string {
718
console.log(`> ${command}`)
819
return execSync(command, { encoding: 'utf8', stdio: 'pipe' })
920
}
1021

1122
export default async function applyPatch_(packageName: string, patchMap: Record<string, string>) {
23+
const packageManager = process.env.args!.at(0)! as keyof typeof PACKAGE_MANAGER_MAP
24+
1225
console.log(`🔄 Start patching "${packageName}"`)
13-
const patchOutput = run(`yarn patch ${packageName}`)
26+
const patchOutput = run(`${PACKAGE_MANAGER_MAP[packageManager].patch} ${packageName}`)
1427

1528
const tempDir = patchOutput.split('\n')[1].slice(49)
1629

@@ -28,7 +41,7 @@ export default async function applyPatch_(packageName: string, patchMap: Record<
2841
console.log(`💾 Patched ${fileToPatch} with ${patchPath}`)
2942
}
3043

31-
run(`yarn patch-commit -s ${tempDir}`)
44+
run(`${PACKAGE_MANAGER_MAP[packageManager].patchCommit} "${tempDir}"`)
3245

3346
console.log(`📦 "${packageName}" patched`)
3447
}

0 commit comments

Comments
 (0)