Skip to content

Instantly share code, notes, and snippets.

@sahilrajput03
Last active January 5, 2026 14:41
Show Gist options
  • Select an option

  • Save sahilrajput03/91691c60b52b1b3fe9992a45fa802b8d to your computer and use it in GitHub Desktop.

Select an option

Save sahilrajput03/91691c60b52b1b3fe9992a45fa802b8d to your computer and use it in GitHub Desktop.
Using only yarn, #yarn #learningYarn #onlyYarn

Yarn workspaces

More

LEARN: Use ctrl+p and ctrl+n for switching to previous and next commands in bash.

LEARN: MOVING TO YARN PERMANENTLY # renamed /c/nodejs/'s npm and npm.cmd # _npm and _npm.cmd files.

LEARN: YARN does use package-lock.json file for installing exact dependencies it used in last installation of package.

yarn release article - @ engineering.fb.com

yarn start # For npm start

yarn init # Initialize new project.

yarn or yarn install # Install all dependencies.

yarn add [pkg] # Installs latest avalable version.
yarn add [pkg] --dev # Installs as dev dependency. # Or: yarn add -D [pkg]
yarn remove [pkg] # Removes a dependecy.
yarn global add [pkg] # Installs globally.

yarn add [pkg@someVersion] # Installs specific version.

yarn add [pkg] --peer
yarn add [pkg] --optional

yarn upgrade [package]
yarn upgrade [package]@[version]
yarn upgrade [package]@[tag]

Publishing

yarn version --major  # Instead of    npm version major
yarn version --minor  # Instead of    npm version minor
yarn version --patch  # Instead of    npm version patch

yarn login #This is only executable on cmd(so use win+n 11 for cmd in conemu) and it'll need your npm username and npm email address to be able to publish( via `yarn publish`).

yarn publish # Publishes to npm registry, but good thing is it instanly shows up on yarn registry(YIKES) and for npm it is as usual, like it takes around 1-2 minute to actually see it on their site.

yarn unpublish

Unortunately yarn unpublish doens't exists so use:

_npm unpublish <pkg-name> -f # Will remove complete project fom npm registry.
_npm unpublish <pkg-name>@ver # Will remove particular version from npm registry.

Source : Migrating from npm @ yarnpkg.com

Source : Pubish @ yarnpkg.com

yarn run

{
  "name": "my-package",
  "scripts": {
    "build": "babel src -d lib",
    "test": "jest"
  }
}
yarn [script-name] # Or yarn run [script-name]

yarn start
yarn script2 # Works perfectly.

yarn run test -o --watch
# would run below command -
jest -o --watch.

Source : yarn run @ yarnpkg.com

Seeing version of yarn

# Checking installed version of yarn
yarn -v
yarn --version

Updating yarn

npmBackup i -g yarn
#verify installed version by - yarn -v or yarn --version

Peer dependency

Peer dependencies are a special type of dependency that would only ever come up if you were publishing your own package.

Having a peer dependency means that your package needs a dependency that is the same exact dependency as the person installing your package. This is useful for packages like react that need to have a single copy of react-dom that is also used by the person installing it.

Source - Amazing Guide @ yarnpkg.com

yarn upgrade (npm update)

yarn upgrade [pkg]

Source: Docs @ yarnpkg.com

There are times when we don't want to npm run someShit or npm start for a current directory but for a custom directory, say if you lazy enought to cd and do npm run or npm start, in those cases you

  • You can use npm start -C <directoryHere> or `npm start --prefix , src@stackoverflow and look for --prefix there.., and also there's stackoverflow for the same src@officialDocs.
  • If using yarn, you can use --cwd for e.g., yarn --cwd <directoryHere> start or yarn --cwd someRunScript. Docs for same here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment