From ca97a1189e3d48cdbfc7ac837e19b69a0c4fc16c Mon Sep 17 00:00:00 2001 From: David Pett Date: Fri, 12 Oct 2018 16:52:47 -0500 Subject: [PATCH 1/2] added a --patches-dir option --- README.md | 4 ++++ src/applyPatches.ts | 3 ++- src/index.ts | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa411644..7cd249fc 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,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..c6efc643 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: ["patches-dir"], }) const packageNames = argv._ @@ -41,7 +42,7 @@ if (argv.help || argv.h) { }) } else { console.log("patch-package: Applying patches...") - applyPatchesForApp(appPath, !!argv["reverse"]) + applyPatchesForApp(appPath, !!argv["reverse"], argv["patches-dir"]) } } From 3927d4c0f6fd7df3af7c249b5741adc610949a96 Mon Sep 17 00:00:00 2001 From: David Pett Date: Fri, 12 Oct 2018 16:56:55 -0500 Subject: [PATCH 2/2] specify patches-dir when creating a patch too --- README.md | 4 ++++ src/index.ts | 5 +++-- src/makePatch.ts | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7cd249fc..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. diff --git a/src/index.ts b/src/index.ts index c6efc643..b6e79321 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +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: ["patches-dir"], + string: ["patch-dir"], }) const packageNames = argv._ @@ -38,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"], argv["patches-dir"]) + 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)