Lifecycle scripts for hosted git and local dependencies not run on install

Do you want to request a feature or report a bug?

What is the current behavior?
When a hosted git dependency is installed, lifecycle scripts are not run (e.g. prepare)

If the current behavior is a bug, please provide the steps to reproduce.
Run yarn add user/repo or yarn add github:user/repo. No lifecycle scripts will be run.

What is the expected behavior?
prepare should be run on install (like with npm@5)

Please mention your node.js, yarn and operating system version.
Node.js 9.4.0
Yarn 1.3.2
MacOS 10.13

I’ve done some investigation as to why this broken. This is what I’ve found:

#3553 added the correct behavior, but only for git fetching, meaning the dependency was actually fetched via git.

Because Yarn recognizes certain git hosts, Yarn will install these dependencies via HTTP/tarball method instead of git (presumably for performance). So if this logic is triggered (which will happen with dependencies formatted like repo/user or github:repo/user, then the appropriate lifecycle scripts won’t be run.

Related issues:

I’d be interested in making a PR to resolve this, but figured I’d make an issue first. I’m thinking that the logic for running lifecycle scripts in src/fetchers/git-fetcher.js should probably be moved into the more generic src/fetchers/base-fetcher, since per #3911 lifecycle scripts should be run for non-git dependencies as well.

Author: Fantashit

2 thoughts on “Lifecycle scripts for hosted git and local dependencies not run on install

  1. Totally understand if that’s the holdup and don’t get me wrong, I’m very thankful for the hard work! I would be happy to contribute when I find the time… Always the excuse I know…. My question was meant to be a, “Why isn’t this a higher priority?” and not a “Why isn’t this fixed dammit!?”

    Here’s why I think this is a big issue:

    Github has a billion forks people definitely want to use as they would use a normal package. I avoid forking things quite a lot because npm and yarn both didn’t use to manage this. It’s actually what got me to try Yarn in the first place. Though it didn’t have it either, I stayed for those sweet, sweet yarn.lock files.

    I’m not sure if npm has addressed this either, I’m just surprised it’s not a higher priority. Not being able to readily use both Github and local forks as expected massively increases iteration time and I feel like it must be a single line somewhere.

    Can you possibly point me towards the part(s) of the codebase that manage invoking post-install scripts?

  2. In my case the prepare script was executed but the build artefacts were deleted by Yarn because they matched the .gitignore. I solved this by adding an empty .npmignore, which Yarn picks over the .gitignore.

Comments are closed.