Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(yarn): upgrade to v2 #1276

Merged
merged 4 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
Expand Down Expand Up @@ -62,15 +60,17 @@ public
.DS_Store

# Yarn
yarn-error.log
.pnp/
.pnp.js
# Yarn Integrity file
.yarn-integrity
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Vscode settings
.vscode/settings.json
.vscode/tasks.json
.vercel
# Local Netlify folder
.netlify
.netlify
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 16.18.1
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

807 changes: 807 additions & 0 deletions .yarn/releases/yarn-3.3.0.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.3.0.cjs
66 changes: 51 additions & 15 deletions docs/dependency-management.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,77 @@
# Website dependency management

We use [`yarn`](https://classic.yarnpkg.com/lang/en/) to manage our dependencies. This means the nexus of our dependency management lies in the `yarn.lock` file. We _*never*_ want to update `yarn.lock` file manually, we can fix everything from the command line using the `yarn` cli.
We use [`yarn`](https://yarnpkg.com/) to manage our dependencies. This means the
nexus of our dependency management lies in the `yarn.lock` file. We **never**
want to update `yarn.lock` file manually, we can fix everything from the command
line using the `yarn` cli.

## TLDR

1. New *theme* dependency: `yarn workspace gatsby-theme-carbon add my-package`
1. New *dev* dependency: `yarn add -D -W my-package`
1. New _theme_ dependency: `yarn workspace gatsby-theme-carbon add my-package`
1. New _dev_ dependency: `yarn add -D -W my-package`
1. Update dependencies: `yarn upgrade-interactive`
1. Update dependencies (include breaking/non-semver): `yarn upgrade-interactive --latest`
1. Remove dependency: `yarn workspace gatsby-theme-carbon remove my-package` or `yarn -W remove my-package` for dev dependencies.
1. Update dependencies (include breaking/non-semver):
`yarn upgrade-interactive --latest`
1. Remove dependency: `yarn workspace gatsby-theme-carbon remove my-package` or
`yarn -W remove my-package` for dev dependencies.
1. Resolve merge conflict in `yarn.lock`: `yarn`
1. Update package in both `yarn.lock` and `package.json`: `yarn workspace gatsby-theme-carbon add existing-package` or `yarn add -W -D existing-package` for dev dependencies
1. Update package in both `yarn.lock` and `package.json`:
`yarn workspace gatsby-theme-carbon add existing-package` or
`yarn add -W -D existing-package` for dev dependencies

## Workspaces

This project uses [yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) to keep our two "packages" in sync (the example app and the Gatsby theme itself. If you're in the project's root and want to run a command in a specific workspace you can run `yarn workspace X run my-command`. For example, `yarn workspace gatsby-theme-carbon remove my-speciall-dependency`.
This project uses [yarn workspaces](https://yarnpkg.com/features/workspaces) to
keep our two "packages" in sync (the example app and the Gatsby theme itself. If
you're in the project's root and want to run a command in a specific workspace
you can run `yarn workspace X run my-command`. For example,
`yarn workspace gatsby-theme-carbon remove my-speciall-dependency`.

Dev dependencies (linting, formatting etc.) aren't managed in either of the packages, their managed at the root of the project. However, if you try to run `yarn add my-dependency` in the root, yarn will ask you to pass the `-W` flag so confirm you didn't mean to put it in a specific package.
Dev dependencies (linting, formatting etc.) aren't managed in either of the
packages, their managed at the root of the project. However, if you try to run
`yarn add my-dependency` in the root, yarn will ask you to pass the `-W` flag so
confirm you didn't mean to put it in a specific package.

## Adding and removing dependencies

There's two kinds of dependencies: regular dependencies, and dev dependencies. The difference isn't super important for Gatsby sites. However when `NODE_ENV` is `production`, yarn won't install the development dependencies. By installing them in the right category, we can decrease the installation time.
There's two kinds of dependencies: regular dependencies, and dev dependencies.
The difference isn't super important for Gatsby sites. However when `NODE_ENV`
is `production`, yarn won't install the development dependencies. By installing
them in the right category, we can decrease the installation time.

As a rule of thumb, dependencies required to build the site are regular dependencies. Dependencies required to edit the code (linters, formatters, commit checkers, etc.) are dev dependencies. When a dependency is no longer needed, it should be removed so we can reduce our CI install time.
As a rule of thumb, dependencies required to build the site are regular
dependencies. Dependencies required to edit the code (linters, formatters,
commit checkers, etc.) are dev dependencies. When a dependency is no longer
needed, it should be removed so we can reduce our CI install time.

## Updating dependencies

One major difference between `npm` and `yarn`, is that `yarn` doesn't really care too much about the `package.json` file. The actual versions used to build your project are derived from the `yarn.lock` file at the root of the directory. This makes sense, considering the `package.json` file has semanticly versioned _ranges_ for dependencies.
One major difference between `npm` and `yarn`, is that `yarn` doesn't really
care too much about the `package.json` file. The actual versions used to build
your project are derived from the `yarn.lock` file at the root of the directory.
This makes sense, considering the `package.json` file has semanticly versioned
_ranges_ for dependencies.

To update our dependency, we can type `yarn upgrade-interactive`. This let's us chose which packages we want to update individually. If you want to include packages with updates beyond your version range (breaking/non-semver) pass the `latest` flag: `yarn upgrade-interactive --latest`
To update our dependency, we can type `yarn upgrade-interactive`. This let's us
chose which packages we want to update individually. If you want to include
packages with updates beyond your version range (breaking/non-semver) pass the
`latest` flag: `yarn upgrade-interactive --latest`

![Demo of yarn upgrade-interactive command](./deps.png)

After selecting the package, and hitting enter, you'll notice nothing changed in the `package.json`. This is because after updating to `@carbon/icons-react@10.14`, our `package.json` is _still correct_ because `10.14.0` satisfies the requirement in our package.json (`^10.13.0`). Simply commit the changes to `yarn.lock` and you're good to go.
After selecting the package, and hitting enter, you'll notice nothing changed in
the `package.json`. This is because after updating to
`@carbon/icons-react@10.14`, our `package.json` is _still correct_ because
`10.14.0` satisfies the requirement in our package.json (`^10.13.0`). Simply
commit the changes to `yarn.lock` and you're good to go.

If for some reason you really need to update a version in the `package.json` you can re-add the package with: `yarn add @carbon/icons-react` this will update the `package.json` to show the latest version.
If for some reason you really need to update a version in the `package.json` you
can re-add the package with: `yarn add @carbon/icons-react` this will update the
`package.json` to show the latest version.

## Merge conflicts

If you ever get a merge conflict in your `yarn.lock` file, run the command `yarn`. The file will be updated to resolve the issue. After doing this add and commit the file. Since it's a merge commit, you don't need a commit message: `git add . && git commit`.
If you ever get a merge conflict in your `yarn.lock` file, run the command
`yarn`. The file will be updated to resolve the issue. After doing this add and
commit the file. Since it's a merge commit, you don't need a commit message:
`git add . && git commit`.
Binary file added docs/deps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"release-it-yarn-workspaces": "^2.0.1",
"stylelint": "^13.2.1",
"stylelint-config-recommended-scss": "^4.2.0",
"stylelint-scss": "^3.16.0",
"yarn": "^1.22.4"
"stylelint-scss": "^3.16.0"
},
"version": "3.0.0"
"version": "3.0.0",
"packageManager": "yarn@3.3.0"
}
8 changes: 4 additions & 4 deletions packages/example/src/pages/contributions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ git remote -v

## Development

We use [yarn](https://yarnpkg.com/lang/en/docs/install/) and yarn workspaces to
develop the Carbon Gatsby theme. This allows us to have a development
We use [yarn](https://yarnpkg.com/getting-started/install) and yarn workspaces
to develop the Carbon Gatsby theme. This allows us to have a development
environment that’s closely linked to the theme with minimal setup. Run
`yarn install` to install all of the projects dependencies.

This project has two packages: the actual theme package (`gatsby-theme-carbon`)
and the `example` package. The example package emulates a project which uses the
theme. Its only dependencies are Gatsby, React, and the adjacent theme package.
The `example` package also serves as the theme’s documentation and
[website](https://gatsby.carbondesignsystem.com); it’s deployed on every merge to
main.
[website](https://gatsby.carbondesignsystem.com); it’s deployed on every merge
to main.

New theme development will happen in the theme package while documentation and
testing of that change will occur through changes in the example directory.
Expand Down
Loading