jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.24k stars 508 forks source link

tsdx create command fails at install dependencies due to husky error #943

Closed FaberVitale closed 3 years ago

FaberVitale commented 3 years ago

Current Behavior

npx tsdx create --template 'basic' mylib

[...]
Exit code: 1
Command: node husky install
Arguments: 
Directory: [...]/node_modules/husky
Output:
husky > Setting up git hooks
fatal: not a git repository (or any of the parent directories): .git
husky > Failed to install
yarn add v1.22.10
info No lockfile found.
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

Fails at install dependencies phase.

The error is likely caused by the latest version of husky@4.3.4

See also: https://github.com/typicode/husky/issues/822

Expected behavior

tsdx create command should install all dependencies and create a lock file.

Suggested solution(s)

Downgrade husky or pass HUSKY_SKIP_INSTALL=true.

Your environment

  System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 537.20 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.20.0 - ~/.nvm/versions/node/v12.20.0/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.20.0/bin/npm
  Browsers:
    Chrome: 86.0.4240.198
    Chrome Canary: 89.0.4346.0
    Firefox: 83.0
    Safari: 14.0
jaredpalmer commented 3 years ago

Damn. Can you submit a PR to pin Husky to v4 versions that works? Since v5 is not open source yet

FaberVitale commented 3 years ago

https://github.com/typicode/husky/issues/822#issuecomment-739760031

agilgur5 commented 3 years ago

Thanks for bringing this to attention @FaberVitale and providing some details and links to the upstream issue.

Downgrade husky

Can you submit a PR to pin Husky to v4 versions that works?

typicode/husky#822 (comment)

So I was going to say that downgrading and hard pinning does not actually resolve the root cause issue here and is generally not recommended for an upstream issue -- the upstream issue may itself be resolved without requiring churn from downstream and downstream of downstream consumers. Notably, this would require no less than two releases, one to hard pin, and one to remove the hard pin. I would encourage contributing upstream when possible, #511 and upstream https://github.com/lukeed/sade/pull/36 is an example of this.

That is particularly true for the templates; TSDX does not control them when they are out in the wild (and so cannot later, say, upgrade the version) and actually doesn't version the deps in the templates. A hard pin can also be very confusing to users as it is inconsistent with other dependencies.

It so happens that Husky reverted this change very quickly: v4.3.5 should no longer error and so no action is required from TSDX.

fatal: not a git repository (or any of the parent directories): .git

This is the root cause, and the solution to that is actually to implement #755, which I was going to recommend if Husky did not revert. It should probably still be done to avoid such a problem in the future, although inclusion of Husky v5+ is up for debate given that it can't be used by all libraries due to license limitations

https://github.com/typicode/husky/issues/822#issuecomment-739586804 succinctly describes that v4.3.4 simply made a silent error much louder by actually throwing (in order to resolve another issue). One of the challenges of maintaining is that a bugfix like that can sometimes also be breaking and so puts one into a precarious position. In this case, it seemed to cause more (unexpected) issues than it solved, which is likely what led to it being reverted.