Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a project uses Yarn

Tags:

yarnpkg

How does one know if a project uses Yarn or NPM? Both contain a package.json file, although Yarn dependencies contain a file in the folder called yarn.lock.

like image 398
user3126529 Avatar asked Jul 09 '20 03:07

user3126529


People also ask

How do I know if my project uses yarn?

Projects using npm will have a package-lock. json file while projects using yarn will have a yarn.

Can a project have both npm and yarn?

Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node. js module resolution algorithm.


1 Answers

I created this shell alias to detect if a project uses npm or yarn.

alias npm_or_yarn='ls yarn.lock &> /dev/null && echo yarn || echo npm'

You can also create an alias to automatically run start using npm or yarn.

alias npm_or_yarn_start='$(npm_or_yarn) start'
like image 169
Andrew Avatar answered Sep 30 '22 01:09

Andrew