supi icon indicating copy to clipboard operation
supi copied to clipboard

Hook to allow manipulation of lifecycle scripts

Open davej opened this issue 7 years ago • 3 comments

(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 avatar Mar 14 '18 14:03 davej

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.

davej avatar Mar 14 '18 14:03 davej

@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

zkochan avatar Mar 31 '18 17:03 zkochan

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.

davej avatar Mar 31 '18 18:03 davej