[bug] repect code added when modify on the first or last line
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
I liiked a bit into it, here is what I've found:
- this does not happen when
npm installis used - when yarn is used and is not set up correctly (not having
postinstall-postinstallinstalled) the line only gets added once, as it should
Seems like postinstall-postinstall makes problems.