Skip to content

[bug] repect code added when modify on the first or last line #430

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

Open
xxxxst opened this issue Oct 26, 2022 · 1 comment
Open

[bug] repect code added when modify on the first or last line #430

xxxxst opened this issue Oct 26, 2022 · 1 comment

Comments

@xxxxst
Copy link

xxxxst commented Oct 26, 2022

version

6.5.0

Environment

windows 7

node v12.16.3
npm v6.14.4
yarn v1.12.1

Current Behavior

add code on the first or last line, when reinstall, the code is repeated

Steps to Reproduce

init environment

>yarn init
>yarn add -D patch-package postinstall-postinstall
>yarn add [email protected]

add "scripts": { "postinstall": "patch-package" }, to package.json

edit file "node_modules/axios/index.js", add var aaa = 3; to the first line

var aaa = 3;
module.exports = require('./lib/axios');

save file and run command:

>yarn patch-package axios

patch-package will then generate the file: axios+0.21.4.patch

diff --git a/node_modules/axios/index.js b/node_modules/axios/index.js
index 79dfd09..c995a6f 100644
--- a/node_modules/axios/index.js
+++ b/node_modules/axios/index.js
@@ -1 +1,2 @@
+var aaa = 3;
 module.exports = require('./lib/axios');
\ No newline at end of file

then remove directory "node_modules", reinstall package

>yarn install

the new file is (node_modules/axios/index.js)

var aaa = 3;
var aaa = 3;
module.exports = require('./lib/axios');

You can see that the modified code appears twice, The same problem occurs when code is added at the end

every time you run yarn patch-package

a new code var aaa = 3; will be add to the file

@FibreFoX
Copy link

I liiked a bit into it, here is what I've found:

  • this does not happen when npm install is used
  • when yarn is used and is not set up correctly (not having postinstall-postinstall installed) the line only gets added once, as it should

Seems like postinstall-postinstall makes problems.

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