pnpm / supi

Fast, disk space efficient installation engine. Used by pnpm
MIT License
24 stars 5 forks source link

Hook to allow manipulation of lifecycle scripts #55

Open davej opened 6 years ago

davej commented 6 years ago

(As discussed on gitter) Currently the readPackage hook is only useful for modification of dependencies because it occurs during the resolution phase.

It may be useful to have a hook that taps into other stages of install. My particular use case is to be able to modify lifecycle scripts but there may be other use cases too.

I'm happy to the grunt work on this and PR it if you'd like. Just show me where the code should go and let me know if there are potential side-effects or implications that I should be aware of.

davej commented 6 years ago

Perhaps it's worth considering the naming of hooks? Maybe they should be named based on the stage that they occur? resolution would alias the existing readPackage hook and perhaps install or preInstall would allow modifying the pkg during install time.

zkochan commented 6 years ago

@davej what was the use case for it? I don't remember

If we implement this then I think readPackage() can be reused to override lifecycle scripts. However, overriding lifecycle scripts is conflicting with another optimization that I was planning to do: symlinking packages with their deps directly from the store

davej commented 6 years ago

what was the use case for it?

It was an electron app that allows you to install and run node applications without needing node/npm to be installed. Basically, some package.json scripts reference other scripts, e.g..

{
  "scripts": {
    "bundle": "webpack .",
    "postinstall": "npm run bundle"
  }
}

(Stupid example but you get the point)

I wanted to be able to expand out all matches for npm run x to it's value so that npm wasn't required during the install process.