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

No way to opt out of post-install only #4100

Closed
dziamid opened this issue Aug 4, 2017 · 15 comments
Closed

No way to opt out of post-install only #4100

dziamid opened this issue Aug 4, 2017 · 15 comments
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.

Comments

@dziamid
Copy link

dziamid commented Aug 4, 2017

While yarn install --ignore-scripts ignores post-install scripts, it also prevents the Building fresh packages... stage of the install.

How do I ignore post-install while keeping the building of fresh packages ?
Or how do I invoke building of fresh packages manually? I haven't found a command that does that.

@phra
Copy link

phra commented Mar 1, 2018

still no way to do that?

@twang2218
Copy link

I have the same issue here, my use case is for Dockerfile. Here is the Dockerfile:

FROM node:8 as builder

## Prepare dependencies
WORKDIR /app/
COPY package.json /app/
COPY yarn.lock /app/
RUN yarn --ignore-scripts

## Build
COPY . /app/
RUN yarn build

I want to install the dependencies as a layer, then build the package later as another layer, just followed the Dockerfile best practice. And I don't want to execute postinstall script in current package for the dependencies installation layer, but I definitely do not want to stop the dependencies building.

I tried --ignore-scripts as above, then all the dependencies building process are stopped as well.

For my case, I have pngquant-bin in my dependencies tree (not even in package.json of my package), and it has a postinstall script:

  "scripts": {
    "postinstall": "node lib/install.js",
    "test": "xo && mocha"
  },

So, what can I do if I just want to stop postinstall script defined in my package.json?

@anhkind
Copy link

anhkind commented Apr 19, 2018

Deleted!

@ipmb
Copy link

ipmb commented May 14, 2018

Here's a workaround:

  "postinstall": "test -n \"$NOYARNPOSTINSTALL\" || yarn run build"

You can now optionally prevent the postinstall script from running with:

$ NOYARNPOSTINSTALL=1 yarn install

@johannesjo
Copy link

No update on this? It has been over two years now...

@akoidan
Copy link

akoidan commented Dec 30, 2020

@ipmb so we drop cross-platform support? I guess windows-base OSes don't have test

@rajivshah3
Copy link

I needed a cross-platform way to do this as well, so I made skip-postinstall

{
    "scripts": {
        "postinstall": "skip-postinstall || node-gyp rebuild"
    }
}
SKIP_POSTINSTALL=1 yarn install

@merceyz
Copy link
Member

merceyz commented Jan 4, 2021

If you want to run the postinstalls of dependencies but not your own you should just move that script out of your postinstall and invoke it manually whenever you need it to run

How do I ignore post-install while keeping the building of fresh packages ?

"Building fresh packages" is the postinstalls


Or how do I invoke building of fresh packages manually? I haven't found a command that does that.

Closing as fixed in v2 where you can run yarn install --mode skip-build then later do yarn rebuild to trigger them

https://yarnpkg.com/getting-started/migration
https://yarnpkg.com/cli/install#options-mode%20%230
https://yarnpkg.com/cli/rebuild

@merceyz merceyz closed this as completed Jan 4, 2021
@merceyz merceyz added the fixed-in-modern This issue has been fixed / implemented in Yarn 2+. label Jan 4, 2021
@leikoilja
Copy link

@merceyz, there is no even an option of skip-builds in the latest docs :/

@merceyz
Copy link
Member

merceyz commented Jan 13, 2022

It was renamed to --mode skip-build, I've updated my comment

@oliverlockwood
Copy link

@rajivshah3 I've been making use of your lightweight skip-postinstall package for a few months now (very helpful, thanks!), but now I get warnings and https://www.npmjs.com/package/skip-postinstall says it's deprecated.
I raised issue rajivshah3/skip-postinstall#1 on your project. Are you planning to resolve this or are you considering the mini-project to be abandoned?

@cwtuan
Copy link

cwtuan commented May 16, 2023

I want to disable a specific dependency's postinstall. Is that possible?

@devthejo
Copy link

Here is my workaround:
https://github.com/devthejo/yarn-plugin-fetch/tree/master#production

@andrew-aladjev
Copy link

andrew-aladjev commented Sep 29, 2023

From my point of view postinstall script will be launched 2 times: during yarn install in current project context and during yarn install in different context (dependency installation). So you have to somehow separate this 2 cases. Also you need to allow user to stop this script. So I've provided the following solution:

"postinstall-script": "sh -c 'if [ -f ./dist/postinstall.js ]; then node ./dist/postinstall.js; fi'",
"postinstall": "sh -c 'if [ ! \"$<PROJECT_NAME>_NO_POST_INSTALL\" ]; then yarn postinstall-script; fi'"

It depends on bash (or other shell), but today bash installation is not a big deal for Windows and OSX.

@leaftail1880
Copy link

Easiest cross-platform way:

"postinstall": "node -e \"process.env.NO_POSTINSTALL===1&&process.exit(1)\" || your-script"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.
Projects
None yet
Development

No branches or pull requests