Yarn: No way to opt out of post-install only

Created on 4 Aug 2017  路  5Comments  路  Source: yarnpkg/yarn

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.

Most helpful comment

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

All 5 comments

still no way to do that?

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?

Deleted!

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

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

Was this page helpful?
0 / 5 - 0 ratings