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

Creating .patch-file not working with NPM overrides having (shared) nested dependency #455

Open
FibreFoX opened this issue Feb 21, 2023 · 0 comments

Comments

@FibreFoX
Copy link

Not sure if bug or (not yet implemented) feature.

NPM supports changing and even replacing (transitive) dependencies via the "overrides" node in the package.json, this is a NPM feature since v8 (not sure since when exactly):

I now have this interesting example where I want to replace a (transitive) dependency with a different dependency (not only a different version) in order to get rid of bugs/in order to increase build-speed/because the lib got reworked under different package coordinates:

{
  "name": "some-patch-package-thing",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "postinstall": "patch-package"
  },
  "dependencies": {
    "react-use": "^17.4.0"
  },
  "devDependencies": {
    "patch-package": "^6.5.1",
    "postinstall-postinstall": "^2.1.0",
    "react-scripts": "5.0.1"
  },
  "engines": {
    "node": ">= 18.14.0"
  },
  "overrides": {
    "magic-string": {
      "sourcemap-codec": "@jridgewell/sourcemap-codec@^1.4.14"
    },
    "nano-css": {
      "sourcemap-codec": "@jridgewell/sourcemap-codec@^1.4.14"
    },
    "svgo": {
      "nth-check": "2.1.1"
    }
  }
}

After npm install all dependencies are getting downloaded, but as magic-string and nano-css are now sharing the same version, the node_modules-folder contain a symlink to the real package. Having two dependencies sharing the same version of a transitive dependency is KEY to this bug. Having only magic-string does not recreate the problem.

Here a tree-output of the magic-string in node_modules:

|   index.d.ts
|   LICENSE
|   package.json
|   README.md
|
+---dist
|       magic-string.cjs.js
|       magic-string.cjs.js.map
|       magic-string.es.js
|       magic-string.es.js.map
|       magic-string.umd.js
|       magic-string.umd.js.map
|
\---node_modules
    \---sourcemap-codec

After download is finished I need to adjust the magic-string-package to reflect the new @jridgewell/sourcemap-codec coordinates, so I edit the files node_modules/magic-string/dist/magic-string.cjs.js and node_modules/magic-string/dist/magic-string.es.js.

Now here comes the problem: when I run npx patch-package magic-string after my edits, to create a patch-file (as normal), I will get greeted with a weird warning:
grafik

(Text version of the screenshot, to improve searchability)

patch-package 6.5.1
• Creating temporary folder
• Installing magic-string@0.25.9 with npm
• Diffing your files with clean files
Error: ENOENT: no such file or directory, stat 'C:\develop\tmp\some-patch-package-thing\node_modules\magic-string\node_modules\sourcemap-codec'
    at Object.statSync (node:fs:1596:3)
    at Object.statSync (C:\develop\tmp\some-patch-package-thing\node_modules\graceful-fs\polyfills.js:318:34)
    at statSync (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\util\stat.js:10:52)
    at getStatsSync (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\util\stat.js:24:19)
    at Object.checkPathsSync (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\util\stat.js:49:33)
    at copyDirItem (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:121:29)
    at C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:115:39
    at Array.forEach (<anonymous>)
    at copyDir (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:115:23)
    at mkDirAndCopy (C:\develop\tmp\some-patch-package-thing\node_modules\fs-extra\lib\copy-sync\copy-sync.js:110:3) {
  errno: -4058,
  syscall: 'stat',
  code: 'ENOENT',
  path: 'C:\\develop\\tmp\\some-patch-package-thing\\node_modules\\magic-string\\node_modules\\sourcemap-codec'
}
C:\develop\tmp\some-patch-package-thing\node_modules\patch-package\dist\makePatch.js:218
        throw e;
        ^

This probably is due to the node_modules folder not existing in the one which gets downloaded on the • Installing magic-string@0.25.9 with npm step. I have not tested this on MacOS or Linux systems.

OS: Windows 10 Pro
Node: v18.14.0
NPM: 9.4.2

fabOnReact added a commit to fabOnReact/App that referenced this issue Sep 13, 2023
JKobrynski pushed a commit to JKobrynski/Expensify that referenced this issue Sep 21, 2023
JKobrynski pushed a commit to JKobrynski/Expensify that referenced this issue Sep 21, 2023
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

No branches or pull requests

1 participant