Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

andyjy
Copy link

@andyjy andyjy commented Apr 1, 2023

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

@karlhorky
Copy link

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

@andyjy
Copy link
Author

andyjy commented May 16, 2023

@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
Copy link
Author

andyjy commented May 29, 2023

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.

@zhanghengxin
Copy link

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

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

@andyjy
Copy link
Author

andyjy commented Jun 19, 2023

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
Copy link
Author

andyjy commented Jul 5, 2023

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 @ 0779cba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should we throw warning instead of error while patched packages not exist
3 participants