lukeed / pwa

(WIP) Universal PWA Builder

Home Page:https://pwa.cafe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Detect if Yarn is in use

Daniel15 opened this issue · comments

"pwa init" outputs the following:

      These commands have been added to your package.json already.
      We suggest you begin by typing:

        $ cd pwareacttest
        $ npm install
        $ npm run watch

However, If I'm using Yarn, it should suggest Yarn rather than npm. A system that has Yarn might not even have npm installed. create-react-app is an example of an app that detects if Yarn is being used.

Hey!

I think "in use" is a a bit ambiguous, as simply having something installed on a system doesn't mean it's actually being used or preferred. I stopped the generator before installation so that users can use whatever they want for the actual expensive task.

I think the best I can do here is adding a --yarn flag that prints and includes yarn commands. Even then I'm hesitant because anyone who's actually using yarn/pnpm is smart enough to know how to run the npm * commands in their flavor.

Hmm, that makes sense. I wonder what create-react-app does.

TBH I could have sworn that they printed npm run commands in the message. Maybe it's changed since?

I ran yarn create react-app testcra and it output this at the end:

Success! Created testcra at C:\src\testcra
Inside that directory, you can run several commands:

  yarn start
    Starts the development server.

  yarn build
    Bundles the app into static files for production.

  yarn test
    Starts the test runner.

  yarn eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd testcra
  yarn start

@lukeed Looks like create-react-app decides to use Yarn based on whether there's a yarn.lock file in the directory: https://github.com/facebook/create-react-app/blob/26f701fd60cece427d0e6c5a0ae98a5c79993640/packages/react-scripts/scripts/init.js#L88

Okay, but that still doesn't make sense for this use case. The init creates new directories, and in the event you select the cwd you have to go thru two confirmation steps to make sure it's intended. I'd assume/hope that 99% of inits are not into existing directories 😅