patch-package icon indicating copy to clipboard operation
patch-package copied to clipboard

Add --ignore-missing flag to continue without error on missing packages

Open andyjy opened this issue 1 year ago • 6 comments

Ignores patches for packages that are not present in node_modules.

This is useful when working with monorepos and wanting to install sub-packages separately from the root package, with pruned dependencies.

Closes #339

andyjy avatar Apr 01 '23 15:04 andyjy

@ds300 what do you think about this one? Would be very useful :)

karlhorky avatar May 07 '23 16:05 karlhorky

@ds300 I saw you approved a CI run that failed all jobs during setup - looks to have been unrelated to my changes; I've just updated against latest master branch which seems should fix the CI workflows (?🤞)

Glad to update this PR with changes if you'd like to accept it conditional on feedback. Thanks!

andyjy avatar May 16 '23 10:05 andyjy

Update 2023-07-03: PR now updated to support setting env var PATCH_PACKAGE_IGNORE_MISSING=1 so missing packages can easily be ignored during deployment (due to pruned dependencies) but alerted during development (due to updating dependencies without also updating relevant patches).

Original comment:

I realise this feature as-implemented is "dangerous" - within a monorepo, a future update to the package-lock file may relocate a package out from the root node_modules folder into one or more nested node_modules folders under an individual workspace/subpackage.

Currently patch-package will error when this occurs, drawing attention to fact the current patch is now against a "missing" package. This PR will currently switch that behaviour to subtly reporting as missing when the --ignore-missing flag is specified, which is easy to miss and not the desired behaviour for such circumstances.

I suspect a workable approach is to update the support for --ignore-missing to (instead?) be set via an environment variable - this can then be set at deploy time (when some packages may be missing as expected due to deploying with pruned dependencies) but error locally and during CI when we expect all packages to be present.

andyjy avatar May 29 '23 20:05 andyjy

guys, you can do it according to the following in packages.json.

"installConfig": { "hoistingLimits": "workspaces" }

zhanghengxin avatar Jun 13 '23 05:06 zhanghengxin

guys, you can do it according to the following in packages.json.

"installConfig": { "hoistingLimits": "workspaces" }

thanks, it looks like that's a feature of yarn only - not npm

andyjy avatar Jun 19 '23 12:06 andyjy

I realise this feature as-implemented is "dangerous"

PR now updated to support setting the env var PATCH_PACKAGE_IGNORE_MISSING=1 so this can be set at deploy time (when some packages may be missing as expected due to deploying with pruned dependencies) but error during local development and CI when we expect all packages to be present.

I left the CLI option --ignore-missing for now, but could remove that if preferred.

I've published this fork under patch-package-ignore-missing - version 7.0.1-2 is up to date with patch-package @ https://github.com/ds300/patch-package/commit/0779cbafefc5241ba53f6eb6fb3b94ee398e037a

andyjy avatar Jul 05 '23 14:07 andyjy