Skip to content

Commit 4042ed3

Browse files
committed
don't run for dependencies
1 parent 9d1e46d commit 4042ed3

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ git commit -m "fix brokenFile.js in some-package"
1818
```
1919

2020
Patches created by `patch-package` are automatically and gracefully applied when
21-
you use `npm`(>=5) or `yarn`.
21+
you use `npm` or `yarn`.
2222

23-
No more waiting around for pull requests to be merged and published. No more
24-
forking repos just to fix that one tiny thing preventing your app from working.
23+
No more waiting around for pull requests to be merged and published! No more
24+
forking repos just to change one line!
25+
26+
ⓘ <em>Is your project a published npm package? If so you should only patch dev
27+
dependencies. Because of the way node_modules folders are managed, patch files
28+
can't be reliably applied for your dependents. `patch-package` won't even
29+
try.</em>
2530

2631
## Set-up
2732

src/index.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { getAppRootPath } from "./getAppRootPath"
77
import { makePatch } from "./makePatch"
88
import { makeRegExp } from "./makeRegExp"
99
import { detectPackageManager } from "./detectPackageManager"
10-
import { join } from "./path"
11-
import { normalize, sep } from "path"
10+
import { join, resolve } from "./path"
11+
import { basename, normalize, sep } from "path"
1212
import slash = require("slash")
1313
import isCi from "is-ci"
14+
import { existsSync } from "fs"
1415

1516
const appPath = getAppRootPath()
1617
const argv = minimist(process.argv.slice(2), {
@@ -33,6 +34,16 @@ console.log(
3334
require(join(__dirname, "../package.json")).version,
3435
)
3536

37+
if (
38+
basename(resolve(process.cwd(), "../")) === "node_modules" &&
39+
existsSync(resolve(process.cwd(), "../../package.json"))
40+
) {
41+
console.log(
42+
`patch-package seems to be running as part of a dependency's postinstall script and will not attempt to apply patches.`,
43+
)
44+
process.exit(0)
45+
}
46+
3647
if (argv.version || argv.v) {
3748
// noop
3849
} else if (argv.help || argv.h) {

0 commit comments

Comments
 (0)