Skip to content

Commit

Permalink
update yarn to v4 (#2519)
Browse files Browse the repository at this point in the history
* add yarn update docs and script

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

* update docs

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

* add contributing note

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

* update yarn to v4

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

* update lockfile on every workspace

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

* declare existing csstype resolutions

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

* dedupe workspaces

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

* disable lint issues

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>

---------

Signed-off-by: Juan Pablo Garcia Ripa <[email protected]>
  • Loading branch information
Sarabadu authored Feb 12, 2025
1 parent f34316d commit ddd2878
Show file tree
Hide file tree
Showing 164 changed files with 873,203 additions and 872,820 deletions.
28 changes: 0 additions & 28 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

This file was deleted.

783 changes: 0 additions & 783 deletions .yarn/releases/yarn-3.2.3.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
compressionLevel: mixed

enableGlobalCache: true

httpTimeout: 300000

nodeLinker: node-modules
nmMode: hardlinks-local

npmRegistryServer: "https://registry.npmjs.org/"

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
npmRegistryServer: 'https://registry.npmjs.org/'

yarnPath: .yarn/releases/yarn-3.2.3.cjs
yarnPath: .yarn/releases/yarn-4.6.0.cjs
7 changes: 5 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you have questions or feedback regarding Community Plugins, you can visit the
- [Code of Conduct](#code-of-conduct)
- [License](#license)
- [Security Issues](#security-issues)
- [Get Started!](#get-started)
- [Get Started](#get-started)
- [Forking the Repository](#forking-the-repository)
- [Developing Plugins in Workspaces](#developing-plugins-in-workspaces)
- [Coding Guidelines](#coding-guidelines)
Expand Down Expand Up @@ -83,7 +83,10 @@ There could be times when there is a need for a more rich development environmen
## Coding Guidelines

All code is formatted with `prettier` using the configuration in the repo. If possible we recommend configuring your editor to format automatically, but you can also use the `yarn prettier --write <file>` command to format files.
To keep the codebase consistent and maintainable, we have a some cross workspace tolling in place:

- `yarn`: is the package manager used for all workspaces. We will regularly update the yarn version to keep up with the latest features and bug fixes. This version is managed in the root `package.json` and `.yarnrc.yml` files and should not be locked to a different version in any workspace. Updating the yarn version could imply changes on all the `yarn.lock` files.
- `prettier`: All code is formatted with `prettier` using the configuration in the repo. If possible we recommend configuring your editor to format automatically, but you can also use the `yarn prettier --write <file>` command to format files.

## Versioning

Expand Down
36 changes: 36 additions & 0 deletions docs/updating-yarn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Updating Yarn

## Overview

To keep workflows and tooling easy to maintain, we use a unique yarn version across all workspaces. This document outlines the process for updating the yarn version across all workspaces.

## Process

> [!NOTE] this is the process used from version 3.x to 4.x, future version could imply a different process.
### 1. Update Yarn Version

update the yarn version runing this command on the root of the repository:

```bash
yarn set version latest # or a specific version if is needed
```

### 2. Update Workspaces

Bumping from version 3 to 4 implies changes on all the workspaces `yarn.lock` files, to update all the following command can be used:

```bash
chmod +x ./scripts/run-in-all.sh
./scripts/run-in-all.sh "yarn install && yarn dedupe --mode=update-lockfile && rm -rf node_modules"
```

What this command does is to iterate over all the workspaces and run `yarn install` on each one, full install is needed for some versions when yarn changes the checksums (i.e. from v3 to v4).
The `yarn dedupe` command is used to update the `yarn.lock` file, this command will update the `yarn.lock` file with the new checksums and dependencies.
The `rm -rf node_modules` command is used to remove the `node_modules` folder, this is optional but have in mind installing node modules in all golder will consume more than 100gb on disk.

If for some version update the `--mode=update-lockfile` flag can be used to update the `yarn.lock` file only saving time form yarn link and other steps.

### 3. Create a PR

After running the previous command, a PR should be created with the changes on the `yarn.lock` files. This PR will affect all the workspaces but maintainer will only wait for a couple of approvals to merge it.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prettier:fix": "prettier --write ."
},
"type": "module",
"packageManager": "yarn@3.2.3",
"packageManager": "yarn@4.6.0",
"devDependencies": {
"@backstage-community/cli": "portal:./workspaces/repo-tools/packages/cli",
"@backstage/cli": "^0.27.0",
Expand Down
16 changes: 16 additions & 0 deletions scripts/run-in-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# Default command
DEFAULT_COMMAND="pwd"

# Use provided command or default
if [ "$#" -eq 0 ]; then
COMMAND=$DEFAULT_COMMAND
else
COMMAND="$@"
fi
echo "Running command: $COMMAND"

# Export the command so it's available in the subshells
export COMMAND

find ./workspaces -maxdepth 1 -type d | tail -n +2 | xargs -I {} -P 3 sh -c 'cd "{}" && pwd && eval "$COMMAND"'
74 changes: 74 additions & 0 deletions scripts/set-resolutions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env node

import { readFile, writeFile } from 'fs/promises';
import { resolve } from 'path';

const packages = [
'workspaces/adr/package.json',
'workspaces/airbrake/package.json',
'workspaces/allure/package.json',
'workspaces/analytics/package.json',
'workspaces/apache-airflow/package.json',
'workspaces/apollo-explorer/package.json',
'workspaces/azure-sites/package.json',
'workspaces/badges/package.json',
'workspaces/bazaar/package.json',
'workspaces/bitrise/package.json',
'workspaces/cloudbuild/package.json',
'workspaces/code-climate/package.json',
'workspaces/codescene/package.json',
'workspaces/cost-insights/package.json',
'workspaces/dynatrace/package.json',
'workspaces/entity-feedback/package.json',
'workspaces/entity-validation/package.json',
'workspaces/explore/package.json',
'workspaces/firehydrant/package.json',
'workspaces/fossa/package.json',
'workspaces/gcalendar/package.json',
'workspaces/gcp-projects/package.json',
'workspaces/git-release-manager/package.json',
'workspaces/github-deployments/package.json',
'workspaces/github-issues/package.json',
'workspaces/github-pull-requests-board/package.json',
'workspaces/gitops-profiles/package.json',
'workspaces/gocd/package.json',
'workspaces/graphiql/package.json',
'workspaces/ilert/package.json',
'workspaces/kafka/package.json',
'workspaces/lighthouse/package.json',
'workspaces/linguist/package.json',
'workspaces/microsoft-calendar/package.json',
'workspaces/newrelic/package.json',
'workspaces/nomad/package.json',
'workspaces/octopus-deploy/package.json',
'workspaces/opencost/package.json',
'workspaces/periskop/package.json',
'workspaces/playlist/package.json',
'workspaces/puppetdb/package.json',
'workspaces/rollbar/package.json',
'workspaces/shortcuts/package.json',
'workspaces/splunk/package.json',
'workspaces/stack-overflow/package.json',
'workspaces/stackstorm/package.json',
'workspaces/vault/package.json',
'workspaces/xcmetrics/package.json',
];

const dependencyName = 'csstype@npm:^3.1.3'; // Set your dependency name here
const resolutionVersion = '3.0.9'; // Set your desired resolution version here

for (const packagePath of packages) {
const fullPath = resolve(packagePath);
const packageJson = JSON.parse(await readFile(fullPath, 'utf8'));

if (!packageJson.resolutions) {
packageJson.resolutions = {};
}

packageJson.resolutions[dependencyName] = resolutionVersion;

await writeFile(fullPath, JSON.stringify(packageJson, null, 2) + '\n');
console.log(
`Updated resolution for ${dependencyName} in ${packagePath} to ${resolutionVersion}`,
);
}
Loading

0 comments on commit ddd2878

Please sign in to comment.