Skip to content

Commit

Permalink
don't run for dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ds300 committed Mar 3, 2021
1 parent 9d1e46d commit 4042ed3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@ git commit -m "fix brokenFile.js in some-package"
```

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

No more waiting around for pull requests to be merged and published. No more
forking repos just to fix that one tiny thing preventing your app from working.
No more waiting around for pull requests to be merged and published! No more
forking repos just to change one line!

ⓘ <em>Is your project a published npm package? If so you should only patch dev
dependencies. Because of the way node_modules folders are managed, patch files
can't be reliably applied for your dependents. `patch-package` won't even
try.</em>

## Set-up

Expand Down
15 changes: 13 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { getAppRootPath } from "./getAppRootPath"
import { makePatch } from "./makePatch"
import { makeRegExp } from "./makeRegExp"
import { detectPackageManager } from "./detectPackageManager"
import { join } from "./path"
import { normalize, sep } from "path"
import { join, resolve } from "./path"
import { basename, normalize, sep } from "path"
import slash = require("slash")
import isCi from "is-ci"
import { existsSync } from "fs"

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

if (
basename(resolve(process.cwd(), "../")) === "node_modules" &&
existsSync(resolve(process.cwd(), "../../package.json"))
) {
console.log(
`patch-package seems to be running as part of a dependency's postinstall script and will not attempt to apply patches.`,
)
process.exit(0)
}

if (argv.version || argv.v) {
// noop
} else if (argv.help || argv.h) {
Expand Down

0 comments on commit 4042ed3

Please sign in to comment.