'How to tell if a project uses Yarn

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.



Solution 1:[1]

Both use package.json with the same JSON format, but NPM 5 generates a package-lock.json file, whereas Yarn generates a yarn.lock file.

Both will resolve to populating the node_modules folder with their own resolution algorithms.

Solution 2:[2]

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'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rob Bell
Solution 2