The yarn lab incorporates a few steps:
- Install
yarn - Create a new project with
yarn - Installing/reinstall/syncing project dependencies
- Add/remove/update some dependencies
Questions? If you have any questions, ping #webguild.
Before you get started, familiarize yourself a bit with the yarn Documentation.
Create a new directory and use yarn init just like you would npm init to create a new node.js project:
$ mkdir my_yarn_project
$ cd my_yarn_projectAlso, we're going to want to track the changes to our project throughout the lab. Initialize a git repo and add your first commit (.gitignore)
my_yarn_project$ git init
my_yarn_project$ echo "node_modules" >> .gitignore
my_yarn_project$ git add -A; git commit -am "Initial commit"Congratulations! You're ready to start the lab.
Once you're ready, go ahead and install yarn:
$ npm i -g yarn@^0.22When that completes, verify yarn was installed successfully:
$ yarn --version
0.22.0Use yarn init just like you would npm init to create a new node.js project:
my_yarn_project$ yarn init
# Follow promptsyarn init will create a basic package.json manifest file that will contain all your dependency versions. Verify it was successfully:
my_yarn_project$ ls
package.jsonNote: Use git status to verify package.json was created, and add it to your repo:
New projects are so minimalist. At Pinterest, usually you'll be working with existing projects. Go ahead and add the following to your newly minted package.json's "dependencies" entry:
"dependencies": {
"gestalt": "0.18.0",
"react": "^15.4.1",
"react-bash": "^1.4.3",
"react-dnd": "^2.1.4",
"react-dnd-html5-backend": "^2.1.2",
"react-dom": "^15.4.1",
"react-modal": "^1.2.0",
"react-motion": "^0.4.2",
"react-redux": "^5.0.2",
"react-router": "^2.7.0",
"react-scroll": "^1.0.17",
"react-slick": "^0.12.2",
"react-sparklines": "^1.4.2",
"react-sticky-position": "^2.0.0"
}And install them:
my_yarn_project$ yarnThat's it! Verify your modules installed correctly:
my_yarn_project$ node
> require('react').version
'15.4.2'A couple things of note:
yarnusesyarn.lockto track the dependency tree installed intonode_modules.yarnwill always keepyarn.lockin sync with package.json.yarn.lockwill be overwritten if a relevant entry (e.g., to"dependencies"changes inpackage.json)
Go ahead and confirm this by cating the contents of yarn.lock:
my_yarn_project$ cat yarn.lockNow let's add a dependency or two. I was never really a fan of react-sticky-position, so let's go ahead and remove it:
yarn remove react-sticky-positionWhen you use yarn to add or remove modules, yarn will modify both package.json and yarn.lock as needed. Go ahead and commit your changes:
$ git status
On branch master
Latest commit question
Untracked files:
(use "git add <file>..." to include in what will be committed)
package.json
yarn.lock
$ git commit -am "Removing react-sticky-position"Repeat the above with yarn add [email protected] then again with yarn upgrade to interactively update lodash to the latest version.