diff --git a/README.md b/README.md index aa411644..85e39f96 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,10 @@ which is a diff between normal old `package-name` and your fixed version. Commit Make regexps used in --include or --exclude filters case-sensitive. +* `--patches-dir` + + Specifies patches directory. defaults to `patches` + ### Updating patches Use exactly the same process as for making patches in the first place, i.e. make more changes, run patch-package, commit the changes to the patch file. @@ -105,6 +109,10 @@ Run `patch-package` without arguments to apply all patches in your project. This option was added to help people using CircleCI avoid [an issue around caching and patch file updates](https://github.com/ds300/patch-package/issues/37) but might be useful in other contexts too. +* `--patches-dir` + + Specifies patches directory. defaults to `patches` + #### Notes To apply patches individually, you may use `git`: diff --git a/src/applyPatches.ts b/src/applyPatches.ts index ea0e040f..700422b1 100644 --- a/src/applyPatches.ts +++ b/src/applyPatches.ts @@ -55,8 +55,9 @@ function getInstalledPackageVersion( export const applyPatchesForApp = ( appPath: AppPath, reverse: boolean, + patchDir: string = "patches", ): void => { - const patchesDirectory = path.join(appPath, "patches") as PatchesDirectory + const patchesDirectory = path.join(appPath, patchDir) as PatchesDirectory const files = findPatchFiles(patchesDirectory) if (files.length === 0) { diff --git a/src/index.ts b/src/index.ts index 0e7f3b9f..b6e79321 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,6 +11,7 @@ import { detectPackageManager } from "./detectPackageManager" const appPath = getAppRootPath() const argv = minimist(process.argv.slice(2), { boolean: ["use-yarn", "case-sensitive-path-filtering", "reverse"], + string: ["patch-dir"], }) const packageNames = argv._ @@ -37,11 +38,12 @@ if (argv.help || argv.h) { detectPackageManager(appPath, argv["use-yarn"] ? "yarn" : null), include, exclude, + argv["patch-dir"], ) }) } else { console.log("patch-package: Applying patches...") - applyPatchesForApp(appPath, !!argv["reverse"]) + applyPatchesForApp(appPath, !!argv["reverse"], argv["patch-dir"]) } } diff --git a/src/makePatch.ts b/src/makePatch.ts index 306753cd..d82468a4 100644 --- a/src/makePatch.ts +++ b/src/makePatch.ts @@ -36,6 +36,7 @@ export const makePatch = ( packageManager: PackageManager, includePaths: RegExp, excludePaths: RegExp, + patchDir: string = "patches", ) => { const nodeModulesPath = join(appPath, "node_modules") const packagePath = join(nodeModulesPath, packageName) @@ -53,7 +54,7 @@ export const makePatch = ( const tmpRepoPackagePath = join(tmpRepoNodeModulesPath, packageName) try { - const patchesDir = join(appPath, "patches") + const patchesDir = join(appPath, patchDir) if (!fs.existsSync(patchesDir)) { fs.mkdirSync(patchesDir) @@ -183,7 +184,7 @@ export const makePatch = ( fs.mkdirSync(dirname(patchPath)) } fs.writeFileSync(patchPath, patch) - console.log(`${green("✔")} Created file patches/${patchFileName}`) + console.log(`${green("✔")} Created file ${patchDir}/${patchFileName}`) } } catch (e) { console.error(e)