Hacker News new | ask | show | jobs
by notpublic 1693 days ago
You can find out which packages require postinstall scripts and then run them manually:

  $ grep postinstall node_modules/*/package.json
  node_modules/esbuild/package.json:    "postinstall": "node install.js"
  $ cd node_modules/esbuild
  $ npm run postinstall
1 comments

And to clarify, you should run this once by hand to collect the list, don't add the grepping to the actuall installation script or you are back to square one :D

Here's what I use with yarn, install.sh:

    #!/usr/bin/env bash

    yarn

    function run_install() {
      local dependency="node_modules/$1"
      if [[ -d "$dependency" ]]; then
        yarn --cwd "$dependency" run postinstall
      fi
    }

    run_install 'esbuild'
    run_install 'other_package'
    ...
Good point and nice script. I am going to use it in my projects.

I wish package.json had an option where I could explicitly mark which packages can run postinstall scripts.

> explicitly mark which packages can run postinstall scripts

Here's an RFC on exactly that: https://github.com/npm/rfcs/discussions/80