prettier / pretty-quick

⚡ Get Pretty Quick
https://npm.im/pretty-quick
MIT License
2.22k stars 83 forks source link

"Unable to detect a source control manager." #190

Closed broofa closed 5 months ago

broofa commented 6 months ago

Getting the above error, possibly as a result of using corepack. This is with node@20 and npm@10 (full environment details below.)

Related: #93

Recipe for reproduction

  1. Create a new, empty directory and cd into it
  2. Create package.json:
    {
    "name": "foo",
    "dependencies": {
    "prettier": "3.2.5",
    "pretty-quick": "4.0.0"
    },
    "packageManager": "npm@10.5.0+sha256.17ca6e08e7633b624e8f870db81a78f46afe119de62bcaf0a7407574139198fc"
    }
  3. corepack enable
  4. npm install
  5. Run pretty-quick...
$ pretty-quick
/private/tmp/foo/node_modules/pretty-quick/lib/index.js:12
        throw new Error('Unable to detect a source control manager.');
              ^

Error: Unable to detect a source control manager.
    at module.exports (/private/tmp/foo/node_modules/pretty-quick/lib/index.js:12:15)
    at main (file:///private/tmp/foo/node_modules/pretty-quick/lib/cli.mjs:12:37)
    at file:///private/tmp/foo/node_modules/pretty-quick/lib/cli.mjs:52:1
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.11.1

Environment

$ npx envinfo --system --browsers --npmPackages --binaries

  System:
    OS: macOS 14.2
    CPU: (10) arm64 Apple M1 Max
    Memory: 381.98 MB / 64.00 GB
    Shell: 5.2.15 - /opt/homebrew/bin/bash
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
    bun: 1.0.14 - ~/.bun/bin/bun
    Watchman: 2023.10.09.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 122.0.6261.128
    Safari: 17.2
JounQin commented 6 months ago

It seems you're using temporary installed pretty-quick instead of project level?

broofa commented 6 months ago

@JounQin 'Not sure what you mean by "temporary" vs. "project level".

The repro recipe declares a direct dependency on pretty-quick, so it's installed locally as part of the project's own node_modules.

JounQin commented 6 months ago

@broofa

/private/tmp/foo/node_modules/pretty-quick/lib/index.js:12

I mean the above doesn't seem to be executed at project level?

Can you please provide an online reproduction?

broofa commented 6 months ago

Stackblitz example here (error shows in terminal pane): https://stackblitz.com/edit/stackblitz-starters-3df8vj?file=package.json

What it looks like on my laptop:

CleanShot 2024-03-28 at 07 30 59

JounQin commented 5 months ago

Sorry I don't quite understand, what is type pretty-quick and how does it making pretty-quick executable without npx prefix?

And isn't the stackblitz demo working as expected? There is no .git folder just like your screenshot.

broofa commented 5 months ago

Ugh, sorry... I forgot that pretty-quick needs a source control directory to work from. While I did get this error while working in a repository, I don't remember which one or what the conditions were that led to the problem. And in my haste to provide a reproduction, I failed to include a directory so... I'm just going to close this out. I'll reopen if/when I see the issue again.

FWIW, type is a built-in bash command that gives you the path to the given command. - I.e. All I'm doing here is showing that when I type "pretty-quick", it's being run out of the local "node_modules" folder.