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

allow "patchedDependencies" patch files to come from dependencies #8023

Open
1 task
samualtnorman opened this issue Apr 27, 2024 · 6 comments
Open
1 task

Comments

@samualtnorman
Copy link

samualtnorman commented Apr 27, 2024

Contribution

Describe the user story

I have a template. As with all templates, it has an issue where I update the template, but people's copies of the template do not and cannot be easily updated. The main 2 ways this template gets out of date is the hackmud.d.ts type declaration file and the patches/typescript@5.4.2.patch file. The declaration file is an easy fix, I can move it into the dependency that I control and add "types": [ "hackmud-script-manager/env" ] to the tsconfig.json. I thought I could maybe do the same thing with the patch file and add "pnpm": { "patchedDependencies": { "typescript@5.4.5": "node_modules/hackmud-script-manager/typescript.patch" } } to the package.json.

I straight away hit

ENOENT  ENOENT: no such file or directory, open '/home/samual/Git/samualtnorman/hackmud-environment/node_modules/hackmud-script-manager/typescript.patch'

however which makes sense because before I install the dependencies, the patch file does not exist.

I tried adding "allowNonAppliedPatches": true but it had no affect.

Describe the solution you'd like

Apply patches after dependencies are installed (might want to disallow a patch file from a dependency for itself).

Describe the drawbacks of your solution

I think pnpm install with patch files might be slower since it can't be as concurrent as before (but I've not looked at how pnpm install works so it might have no affect).

Describe alternatives you've considered

Or respect "allowNonAppliedPatches": true for when the patch file can't be found.
Or add a CLI option to specify patches for dependencies so users can do a regular pnpm install followed by a pnpm install --magic-options-to-apply-patches.

@KSXGitHub
Copy link
Contributor

The patch file (typescript.patch) doesn't seem to exist in hackmud-script-manager: https://www.npmjs.com/package/hackmud-script-manager?activeTab=code

file list of hackmud-script-manager

@samualtnorman
Copy link
Author

yeah I removed it because it didn't work. try this one:
https://www.npmjs.com/package/hackmud-script-manager/v/0.19.1-875bbe4?activeTab=code

@zkochan
Copy link
Member

zkochan commented Apr 30, 2024

Theoretically, it can be implemented. However, it would be a complicated change for something that isn't good practice IMO.

I would suggest you just to fork the problematic dependencies and republish them with new names and the fixes applied. If the dependency is somewhere deep and you don't want to fork the whole chain of dependencies, then you can use an override to replace a subdep with your fork. E.g.:

{
  "pnpm": {
    "overrides": {
      "foo@1": "npm:@norman/foo@1"
    }
  }
}

@samualtnorman
Copy link
Author

I don't really want to fork typescript. that sounds like a lot of work

@KSXGitHub
Copy link
Contributor

I don't really want to fork typescript. that sounds like a lot of work

You don't need to fork TS source code, just download the tarball, edit the file you want to change, and publish it under new names. It's just like pnpm patch with extra steps.

@samualtnorman
Copy link
Author

hmm, I'll think about the option, thank you

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

No branches or pull requests

3 participants