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

Run postinstall after package upgrades #2878

Closed
evan-scott-zocdoc opened this issue Mar 9, 2017 · 22 comments
Closed

Run postinstall after package upgrades #2878

evan-scott-zocdoc opened this issue Mar 9, 2017 · 22 comments

Comments

@evan-scott-zocdoc
Copy link

evan-scott-zocdoc commented Mar 9, 2017

Do you want to request a feature or report a bug?
kind of neither, behavioral change

What is the current behavior?
After running a command like yarn upgrade {pkg} or yarn upgrade-interactive, the npm postinstall script is not being run.

What is the expected behavior?
I would expect the postinstall script to be run, since yarn is effectively installing an updated version of one or more packages.

Please mention your node.js, yarn and operating system version.
yarn 0.21.3, mac os latest

@BYK
Copy link
Member

BYK commented Oct 30, 2017

@evan-scott-zocdoc is this still a problem?

@evan-scott-zocdoc
Copy link
Author

@BYK not sure, sorry. We moved off yarn internally.

@jakubzitny
Copy link

@BYK I'd say yes. It's not really a problem, it's just a nice feature that would be cool to have if there are no downsides to it. postinstall is run after both yarn and yarn add, it'd be cool to run it after upgrade too.

@BYK
Copy link
Member

BYK commented Nov 27, 2017

@jakubzitny thanks. It feels almost like a bug to me but since there are no repro steps, I can't verify this issue. Do you have a specific case at hand that you can share with us?

@evan-scott-zocdoc
Copy link
Author

since there are no repro steps

Just upgrade a package that has "postinstall" defined in the package.json. Like this one: https://github.com/jwhitmarsh/postinstall-test

You could try starting it at this commit: 9e0ca63f40fdb578c01dd6bf6424273aa7e3bb3b
And then upgrading to this commit: a15f70fc414ab0c68920bed77b40c8a56cd0ad23

@rally25rs
Copy link
Contributor

Since upgrade internally calls add which extends install it is actually surprising that these scripts don't get run.

It should happen during the "Rebuilding all packages" phase.

@rally25rs
Copy link
Contributor

Actually, if I yarn add the linked repo above by @evan-scott-zocdoc then yarn upgrade --verbose I can see the script being run (yarn v1.3.2)

[4/4] 📃  Rebuilding all packages...
⠁
⠁
⠁
[1/3] ⡀ fsevents
[-/3] ⡀ waiting...
[-/3] ⡀ waiting...
[-/3] ⡀ waiting...
verbose 11.344 node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.6.39
[3/3] ⠂ postinstall-test: src/index.js -> lib/index.js
[-/3] ⠂ waiting...
[-/3] ⠂ waiting...
[-/3] ⠂ waiting...
verbose 13.717 > postinstall-test@1.0.0 postinstall /Users/jvalore/Projects/yarn-test/node_modules/postinstall-test
> postinstall-build na "npm run build"

npm WARN postinstall-test@1.0.0 No description
npm WARN The package babel-cli is included as both a dev and production dependency.

up to date in 0.961s

> postinstall-test@1.0.0 build /Users/jvalore/Projects/yarn-test/node_modules/postinstall-test
> babel src --out-dir lib

src/index.js -> lib/index.js
success Saved lockfile.

(postinstall-build na "npm run build" is the postinstall script)

@rally25rs
Copy link
Contributor

Closing as this was opened against a now old version of Yarn, and I was unable to reproduce with Yarn 1.3.2; the postinstall script was run when I tried to reproduce it. If someone is still having this issue with Yarn v1.3.2, please open a new issue.

@soullivaneuh
Copy link

@rally25rs Please re-open, it's not solved at all.

With the following configuration:

"scripts": {
  "postinstall": "./yarn-scripts",
  "build": "encore dev",
  "watch": "encore dev --watch",
  "prod": "encore production"
}

If I run yarn upgrade, the yarn-scripts file is never called. It is called on yarn install.

Using last v1.3.2 version.

@adrian-gierakowski
Copy link

adrian-gierakowski commented Mar 5, 2018

I can confirm that yarn v1.5.1 DOES NOT run pre\postinstall scripts for upgrade and remove commands. It does run the scripts for install and add

steps to reproduce:

mkdir yarn_install_scripts_test
cd yarn_install_scripts_test
echo '{
  "name": "yarn_test",
  "version": "1.0.0",
  "scripts": {
    "preinstall": "touch preinstall",
    "postinstall": "touch postinstall"
  }
}' > package.json
yarn add ramda@0.21
ls
rm *install
yarn upgrade ramda@0.25
ls
yarn remove ramda
ls

the output of first ls will be:

node_modules package.json postinstall preinstall yarn.lock

and for the other two:

node_modules package.json yarn.lock

@adrian-gierakowski
Copy link

adrian-gierakowski commented Mar 5, 2018

Ok, it looks like I have misunderstood the purpose of the pre\postinstall scripts: they are supposed to be ran when package is installed as a dep of another package, but I was trying to use them to run some commands every time there is a modification to deps of my package ( like when adding of removing deps ).

To take a step back, what I was trying to achieve is to prevent yarn from messing up the content of a folder which I have symlinked into node_modules ( similarly to what's described here ), so I would remove the symlink in pre and add it back in postinstall ( see example below ). It worked for me for yarn install or add ran inside the package, but running upgrade or remove to modify some deps would cause the symlinked folder to be wiped clean.

here's an example of what I would have in my package.json:

{
  "name": "yarn_test",
  "version": "1.0.0",
  "scripts": {
    "preinstall": "if [ -L ./node_modules/my_module ]; then unlink ./node_modules/my_module; fi",
    "postinstall": "if ! [ -L ./node_modules/my_module ]; then ln -s ../my_module/ ./node_modules/my_module; fi"
  },
}

But it looks like what I really need is to add the folder as link dep with link:my_module like in this test fixture :)

@Tehnix
Copy link

Tehnix commented Jul 24, 2018

I would like this to be reopened, since the issue was never resolved. It is not working on yarn version 1.7.1.

Our usecase is to patch a library via the postinstall. This then gets overwritten everytime we run yarn upgrade on an unrelated package, and will cause the application to crash without the patch. The patch then needs to be reapplied with yarn again.

Ideally yarn upgrade would respect postinstall, or a new lifecycle hook would be added, e.g. postupgrade.

@sprilukin
Copy link

sprilukin commented Mar 8, 2019

yarn 1.13.0. issue still is not resolved.

@carcade
Copy link

carcade commented Apr 3, 2019

Yarn 1.15.2, issue still is not resolved.

@clubajax
Copy link

clubajax commented May 3, 2019

It would help if there was a trigger for upgrade. There is not.

@Wintereise
Copy link

Please allow us to target upgrade specifically with postupgrade if making postinstall be called for upgrades is not planned.

@salztorte
Copy link

i think a postupgrade hook is a good solution.

@sesteva
Copy link

sesteva commented Aug 5, 2019

1.16.0 still presents the same defect

@supervanya
Copy link

supervanya commented Feb 4, 2020

I still would really like the postupgrade hook!

@elwayman02
Copy link

Confirming that this issue still exists in 1.21.1. Please re-open and fix.

@sryze
Copy link

sryze commented Nov 30, 2022

Same in 1.22.19

@khames50k
Copy link

khames50k commented Nov 30, 2022 via email

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