Giter Site home page Giter Site logo

Comments (25)

zkochan avatar zkochan commented on May 5, 2024 26

pnpm has a pnpm patch command since v7.4

from patch-package.

fatso83 avatar fatso83 commented on May 5, 2024 24

For anyone else late to the party, @milahu did the work and you can continue with patch-package and PNPM like nothing has changed by doing:

pnpm remove patch-package
pnpm install @milahu/patch-package-with-pnpm-support

The same commands apply (the executable is still node_modules/.bin/patch-package)

from patch-package.

cdaringe avatar cdaringe commented on May 5, 2024 14

...err worked, pre **ERROR** No package-lock.json, npm-shrinkwrap.json, or yarn.lock file. message 😆

from patch-package.

DrSensor avatar DrSensor commented on May 5, 2024 10

same here, pnpx patch-package <pkg> not working

patch-package 6.2.2

**ERROR** No package-lock.json, npm-shrinkwrap.json, or yarn.lock file.

You must use either npm@>=5, yarn, or npm-shrinkwrap to manage this project's
dependencies.

related PR #73 #252

from patch-package.

milahu avatar milahu commented on May 5, 2024 6

@DrSensor fixed in #302

from patch-package.

hcharley avatar hcharley commented on May 5, 2024 3

This worked for me. Thanks @milahu !

npx @milahu/patch-package-with-pnpm-support @my-org/my-package

Edit, I don't think that --reverse is working @milahu:

npx @milahu/patch-package-with-pnpm-support @my-org/my-package --reverse

from patch-package.

zkochan avatar zkochan commented on May 5, 2024 2

@vjpr with a pnpm hook you can install a package from a local tarball instead of the registry. The local tarball can contain the modified package. Or you could publish the fixed package with a different name, or you could install if from your fork.

from patch-package.

boldwade avatar boldwade commented on May 5, 2024 2

This still doesn't seem to work for me after removing and installing the @milahu package:

$ node_modules/.bin/patch-package react-async-hook
patch-package 6.4.9

**ERROR** No package-lock.json, npm-shrinkwrap.json, or yarn.lock file.

You must use either npm@>=5, yarn, or npm-shrinkwrap to manage this project's
dependencies.

from patch-package.

diachedelic avatar diachedelic commented on May 5, 2024 1

It seems to apply existing patches ok using [email protected], [email protected] and [email protected] - not sure about generating them, but that can be done manually if necessary.

from patch-package.

cdaringe avatar cdaringe commented on May 5, 2024 1

I ended up writing a garbage little script to generate patches from my pnpm project's node_modules, but using npm and a temporary workspace to actually generate the patches.

https://gist.github.com/cdaringe/66c7cd5f95f74766f9eb1e699fdd7399

it's rough around the edges, but gets the job done. YMMV

from patch-package.

milahu avatar milahu commented on May 5, 2024 1

The solutions above aren't compatible with pnpm's .pnpm directory.

only works for top-level dependencies, as pnpm has deep node_modules
→ add the dependency to package.json

from patch-package.

ds300 avatar ds300 commented on May 5, 2024

Hi! Looks like patch-package wouldn't work with pnpm, unfortunately.

pnpm uses hard links and symlinks to save one version of a module only ever once on a disk. When using npm or Yarn for example, if you have 100 projects using the same version of lodash, you will have 100 copies of lodash on disk. With pnpm, lodash will be saved in a single place on the disk and a hard link will put it into the node_modules where it should be installed.

Meanwhile, patch-package requires files to be fully copied in to node_modules, not just linked.

from patch-package.

vjpr avatar vjpr commented on May 5, 2024

Hmm, I did not think of that.

@zkochan How could this package be used for pnpm? Can a hook patch a module?

from patch-package.

ds300 avatar ds300 commented on May 5, 2024

Thanks @zkochan

The other issue is that patch-package's core patch generation UX flow wouldn't work. That flow is:

  1. Edit files inside your node_modules folder
  2. run patch-package to generate a patch file based on your edits

With pnpm, editing files inside your node_modules folder will affect all other pnpm projects on your machine, which is probably not what you want.

The patch application process could be automated using the hooks, but I can't think of a way to make patch generation easy. Any ideas?

from patch-package.

vjpr avatar vjpr commented on May 5, 2024

With pnpm, editing files inside your node_modules folder will affect all other pnpm projects on your machine, which is probably not what you want.

For patch creation, I think this workflow still works. When pnpm install is run, it detects that the global store has changed and will reinstall so there is no problem there. I do it all the time.

For patch application, though currently it would never work. It would need to use the pnpm plugin feature as @zkochan mentioned.

from patch-package.

ds300 avatar ds300 commented on May 5, 2024

closing this issue due to inactivity

from patch-package.

jtyers avatar jtyers commented on May 5, 2024

I'm hitting this today. Use pnpm regularly and now have a pressing need to patch a dependency. Unfortunately creating a patch fails under pnpm with:

$ npx patch-package mname                                                  -INSERT- 
patch-package 6.2.0
• Creating temporary folder
• Installing [email protected] with npm
• Diffing your files with clean files
{ Error: ENOENT: no such file or directory, scandir '/tmp/tmp-4739623rx72YYljFtx/node_modules/mname'
    at Object.readdirSync (fs.js:790:3)
<snip>
  errno: -2,
  syscall: 'scandir',
  code: 'ENOENT',
  path: '/tmp/tmp-4739623rx72YYljFtx/node_modules/mname' }
<snip>
Error: ENOENT: no such file or directory, scandir '/tmp/tmp-4739623rx72YYljFtx/node_modules/mname'
    at Object.readdirSync (fs.js:790:3)

Digging into the way patch-package does its diffing, I suspect copying a directory which is itself a symlink is causing the barf.

It'd be great to support pnpm - in my case, I'm happy to have a patch to a dependency affect all the versions of that package installed on the system.

Aside/as well as pnpm hooks, the https://pnpm.js.org/en/workspaces support might be a way of getting what we want, as it looks like packages are stored per-workspace.

from patch-package.

lenovouser avatar lenovouser commented on May 5, 2024

I am experiencing the same problem, can this be fixed on patch-package's side or does this need to be done in pnpm?

from patch-package.

cdaringe avatar cdaringe commented on May 5, 2024

pnpm works, just with caveats.pnpm users need to manage how they land packages node_modules.

  • modules in need of patch need to be top-level to be hoisted into node_modules. you can do this by promoting your transitive deps to 1st-class deps, right in your package.json
  • install method needs to be clone or copy

from patch-package.

milahu avatar milahu commented on May 5, 2024

This still doesn't seem to work for me

thanks for reporting. this could be the same issue as milahu#4

does npx patch-package --debug say more?

what does patch-package say with

--- a/node_modules/@milahu/patch-package-with-pnpm-support/dist/detectPackageManager.js
+++ b/node_modules/@milahu/patch-package-with-pnpm-support/dist/detectPackageManager.js
@@ -54,6 +54,13 @@
     const packageLockExists = fs_extra_1.default.existsSync(path_1.join(appRootPath, "package-lock.json"));
     const shrinkWrapExists = fs_extra_1.default.existsSync(path_1.join(appRootPath, "npm-shrinkwrap.json"));
     const yarnLockExists = fs_extra_1.default.existsSync(path_1.join(appRootPath, "yarn.lock"));
+console.dir({
+ packageLockExists,
+ shrinkWrapExists,
+ yarnLockExists,
+ findYarnWorkspaceRoot: find_yarn_workspace_root_1.default(),
+ isFileInPnpmRoot: isFileInPnpmRoot(appRootPath, "pnpm-lock.yaml"),
+});
     if ((packageLockExists || shrinkWrapExists) && yarnLockExists) {
         if (overridePackageManager) {
             return overridePackageManager;

from patch-package.

milahu avatar milahu commented on May 5, 2024

@boldwade please try milahu@3545f96

do you have a lockfile in a parent folder? (or in the same folder as package.json)

from patch-package.

StarpTech avatar StarpTech commented on May 5, 2024

Hi, I couldn't find any solution to patch pnpm packages. The solutions above aren't compatible with pnpm's .pnpm directory.

from patch-package.

StarpTech avatar StarpTech commented on May 5, 2024

@milahu thanks. What's missing to integrate your changes into the official repo?

from patch-package.

milahu avatar milahu commented on May 5, 2024

integrate your changes into the official repo?

the owner is gone, so nobody has access*. feel free to maintain a fork ; )

* github requires the owner's consent for project transfer, which is good

For account security reasons, we’re unable to alter repository ownership. This policy is in place to protect all account owners from unauthorized takeovers. (source)

from patch-package.

gunar avatar gunar commented on May 5, 2024

from patch-package.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.