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

Upgrade Framework to Yarn v3 #3154

Merged
merged 62 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
843d37d
setup and install yarn berry
thedavidprice Jun 16, 2021
4bfd735
futz'n to get it work'n
thedavidprice Jun 16, 2021
cc5671e
upgrade @babel/parser
thedavidprice Jun 16, 2021
94fef57
trying to run eslint to from tasks/framework-tools
thedavidprice Jun 16, 2021
08e02c5
Merge branch 'main' into dsp-yarn2-for-the-lulz
thedavidprice Jul 30, 2021
6439d1e
upgrade to yarn v3.0.0
thedavidprice Jul 30, 2021
d39e0ee
upgrade all task projects
thedavidprice Jul 30, 2021
f16f751
e2e install fix
thedavidprice Jul 30, 2021
0bc141e
fix lint and tooling scripts
thedavidprice Jul 31, 2021
dcf4b6f
lint fix
thedavidprice Jul 31, 2021
039d451
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Aug 12, 2021
919f37c
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Aug 12, 2021
2ada2d1
changes per review comments
thedavidprice Aug 12, 2021
3266701
fix test
thedavidprice Aug 12, 2021
0c16aa9
use yarn cache GH workflow
thedavidprice Aug 12, 2021
131ed68
upgrade cypress
thedavidprice Aug 12, 2021
bb04fa7
fix local cypress run-e2e
thedavidprice Aug 13, 2021
fe20ee1
stashed: experimenting with execa process
thedavidprice Aug 25, 2021
62f00ba
enable preferInteractive
redwoodjsbot Sep 10, 2021
feef9f9
Update yarn v3.0.2
redwoodjsbot Sep 10, 2021
41b4cf4
Revert "stashed: experimenting with execa process"
thedavidprice Sep 10, 2021
9ac8f3b
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Sep 10, 2021
2737519
update yarn.lock files
thedavidprice Sep 10, 2021
83970e8
build:test-project working 🚀
thedavidprice Sep 10, 2021
8699a41
use demandCommand instead
redwoodjsbot Sep 11, 2021
5445100
draft code for subDir check
thedavidprice Sep 11, 2021
b4d4731
Merge branch 'dsp-yarn3-for-the-lulz' of https://github.com/redwoodjs…
thedavidprice Sep 11, 2021
147f6de
Add SubDir check
thedavidprice Sep 11, 2021
19f7dd9
add Yarn TypeScript plugin
thedavidprice Sep 13, 2021
dfdf88b
remove cross-env from yarn scripts
thedavidprice Sep 13, 2021
db3c7d4
GH Actions: fix command, add (update) yarn caching
thedavidprice Sep 17, 2021
8add30b
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Sep 17, 2021
1f2ae80
update yarn.lock
thedavidprice Sep 17, 2021
091a52d
fix yarn cache on CI
thedavidprice Sep 17, 2021
c5fd36f
added yarn constraints plugin
thedavidprice Sep 17, 2021
6904dc9
CI fix
thedavidprice Sep 17, 2021
f4b4cea
Update global declaration for useAuth
dac09 Sep 17, 2021
74bec5e
Move auth global type augmentation to ambient.d.ts
dac09 Sep 17, 2021
5489d4a
Also update web tsconfig to use ambient
dac09 Sep 17, 2021
5e4a7b2
Also do ambient type thingies for router
dac09 Sep 17, 2021
740b823
misc TS fixes and lint cleanup
thedavidprice Sep 17, 2021
3fd938d
CI: add yarn constraints and dedupe checks
thedavidprice Sep 17, 2021
0de9cf8
allow package scripts build and test
thedavidprice Sep 17, 2021
50417ce
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Sep 18, 2021
1fcb94b
fix dependency constraintes dedupe
thedavidprice Sep 18, 2021
3d1e8f1
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Sep 20, 2021
f9817be
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Oct 4, 2021
b6ff7ae
update yarn.lock
thedavidprice Oct 4, 2021
06c3d9f
fix build TS and codemod package errors
thedavidprice Oct 4, 2021
360884a
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Oct 4, 2021
db03b6a
update yarn.lock
thedavidprice Oct 4, 2021
38b2c8f
use jscodeshift in root
redwoodjsbot Oct 5, 2021
f724b71
remove jscodeshift from root package.json
redwoodjsbot Oct 5, 2021
5b907cf
align loose option for babel plugins
redwoodjsbot Oct 5, 2021
137eff4
add yarn seciton to contributing
redwoodjsbot Oct 5, 2021
cfe396f
add babel plugin
redwoodjsbot Oct 5, 2021
c0eccaf
update contributing toc
redwoodjsbot Oct 5, 2021
ca96cd7
update Yarn section in CONTRIBUTING
thedavidprice Oct 5, 2021
5be6af4
add yarn cache to GH Workflow publish canary
thedavidprice Oct 5, 2021
50c217b
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Oct 5, 2021
885c725
Merge branch 'main' into dsp-yarn3-for-the-lulz
thedavidprice Oct 5, 2021
a8cc0c3
move dep to devDep per comment review
thedavidprice Oct 5, 2021
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
26 changes: 20 additions & 6 deletions .github/workflows/build-eslint-jest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,28 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

# - name: Cache "node_modules"
# uses: actions/cache@v2
# with:
# path: '**/node_modules'
# key: node_modules_${{ runner.os }}_${{ hashFiles('**/yarn.lock') }}
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- name: Cache yarn
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --immutable

- name: 'Check Yarn constraints (fix w/ "yarn constraints --fix")'
run: yarn constraints

- name: 'Check for duplicate dependencies (fix w/ "yarn dedupe")'
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn dedupe --check

- name: Build
run: yarn build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/create-pr-artifact.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
node-version: 14

- name: Install dependencies
run: yarn install --frozen-lockfile
run: yarn install --immutable

- name: Build
run: yarn build
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: Cache "node_modules"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- name: Cache yarn
uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: node_modules_${{ runner.os }}_${{ hashFiles('**/yarn.lock') }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-

- name: Install framework modules
run: yarn install --frozen-lockfile
- name: Install dependencies
run: yarn install --immutable

- name: Create a temporary directory
id: createpath
Expand Down
24 changes: 23 additions & 1 deletion .github/workflows/publish-npm-canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,34 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: '14'

- name: Print node and yarn versions
run: |
node --version
yarn --version

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"

- name: Cache yarn
uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
yarn-

- name: Install dependencies
run: yarn install --frozen-lockfile --check-files
run: yarn install --immutable

- name: 'Check Yarn constraints (fix w/ "yarn constraints --fix")'
run: yarn constraints

- name: 'Check for duplicate dependencies (fix w/ "yarn dedupe")'
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn dedupe --check

- name: Build
run: yarn build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-npm-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
node-version: '14'

- name: Install dependencies
run: yarn install --frozen-lockfile --check-files
run: yarn install --immutable --check-files

- name: Build
run: yarn build
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ tasks/e2e/cypress/fixtures/example.json
tmp/
.vscode/*
blog-test-project/*
.yarn/*
**/.yarn/install-state.gz
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
52 changes: 52 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-constraints.cjs

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-typescript.cjs

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

631 changes: 631 additions & 0 deletions .yarn/releases/yarn-3.0.2.cjs

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
compressionLevel: 0

enableGlobalCache: true

nmMode: hardlinks-local

nodeLinker: node-modules
thedavidprice marked this conversation as resolved.
Show resolved Hide resolved

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-constraints.cjs
spec: "@yarnpkg/plugin-constraints"

preferInteractive: true

yarnPath: .yarn/releases/yarn-3.0.2.cjs
103 changes: 100 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Before interacting with the Redwood community, please read and understand our [C

**Table of Contents**

- [Contributing](#contributing)
- [Code Organization](#code-organization)
- [Local Setup](#local-setup)
- [Redwood Framework](#redwood-framework)
Expand All @@ -15,7 +16,14 @@ Before interacting with the Redwood community, please read and understand our [C
- [Browser-based Setup](#browser-based-setup)
- [Integration Tests](#integration-tests)
- [Releases](#releases)
- [Troubleshooting](#troubleshooting)
- [Yarn v3: Tips and Troubleshooting](#yarn-v3-tips-and-troubleshooting)
- [Migrating from yarn v1 to yarn v3](#migrating-from-yarn-v1-to-yarn-v3)
- [New Yarn Commands and Utilities](#new-yarn-commands-and-utilities)
- [Added to CI: dedupe and constraints](#added-to-ci-dedupe-and-constraints)
- [About Yarn v3](#about-yarn-v3)
- [Benefits](#benefits)
- [New Files](#new-files)
- [Advanced Cases](#advanced-cases)

## Code Organization

Expand Down Expand Up @@ -196,6 +204,95 @@ This...
3) Commits, Tags, and Pushes to GH
4) and finally publishes all packages to NPM.

### Troubleshooting

If something went wrong you can use `yarn lerna publish from-package` to publish the packages that aren't already in the registry.

## Yarn v3: Tips and Troubleshooting

### Migrating from yarn v1 to yarn v3
As of `v0.37`, the Redwood Framework has moved from yarn `v1` to yarn `v3`.

If you already have a local copy of the Redwood Framework, or if you're switching between branches that are using different versions, **you'll have to run**:
```
git clean -fxd -e .env
yarn install
```
...and then you'll be good to go.

> Note: Yarn v3 is installed in the directory, while Yarn v1 is installed globally. This allows us to switch as needed per branch and/or project.
### New Yarn Commands and Utilities
**`yarn add --interactive`**
Reuse the specified package from other workspaces in the project. Example:
```
yarn workspace create-redwood-app add -i rimraf
```

> Note: Interactivity is enabled by default

For example, if we're using `yarn add` to add a dependency to a workspace (say `packages/codemods`), and we already have that dependency in another worksapce (say `packages/api-server`), yarn will ask us if we want to use the same version:

```
redwood/packages/codemods$ yarn add yargs
? Which range do you want to use? …
❯ Reuse [email protected] (originally used by @redwoodjs/[email protected] and 2 others)
Use yargs@^17.2.1 (resolved from latest)
```

**`yarn workspaces foreach ...`**
This is a command from the workspaces plugin. Runs the command across all workspaces. Example:
```
yarn workspaces foreach -i -v some-package
```
-v: outputs the package name the command is currently running against

### Added to CI: dedupe and constraints
**`yarn dedupe --check`**
> Duplicates are defined as descriptors with overlapping ranges being resolved and
locked to different locators. They are a natural consequence of Yarn's
deterministic installs, but they can sometimes pile up and unnecessarily
increase the size of your project.
> This command dedupes dependencies in the current project using different
strategies (only one is implemented at the moment):

**`yarn constraints`**
See new file `constraints.pro` for repo config
- https://yarnpkg.com/features/constraints
- Reference from Babel project: https://github.com/babel/babel/blob/main/constraints.pro

### About Yarn v3
Aside from a few plugins, we aren't using most of it's advanced features (like [PnP](https://yarnpkg.com/features/pnp)) yet.

So besides the output in your terminal looking different, not much else is.

> We may explore things like PnP in the future.
> We just have to take things one step at a time since we're trying to release `v1`.
#### Benefits

Some of the benefit yarn `v3` brings us as we prepare for `v1` are:

- faster CI (up to 50% faster)
- most importantly, no more Windows timeouts!
- faster yarn installs
- better dependency guarantees

One of the most significant changes in yarn `v3` is it's stance on [hoisting](https://yarnpkg.com/advanced/lexicon/#hoisting).

#### New Files

Yarn `v3` keeps more of itself in the repo than before.
For exmaple, yarn `v3` isn't installed globally, but on a per-project basis.

Here's a quick overview of some of the new yarn-related files in this repo:

| File | Description |
|:-----------------|:---------------------------------------------------------------------|
| `.yarnrc.yml` | Yarn's configuration file |
| `.yarn/plugins` | Where installed [plugins](https://yarnpkg.com/features/plugins) live |
| `.yarn/releases` | The `yarn v3` binaries themselves |

#### Advanced Cases
If needed, there's more information in [this PR #3154 comment](https://github.com/redwoodjs/redwood/pull/3154#issue-957115489) about special cases:
- "Binary hoisting" is no longer allowed
- Specifying Yarn v1 binary (when necessary)
- `yarn dlx`
- Set `YARN_IGNORE_PATH=1` to ignore local yarn version settings.
- how "postinstall" script works
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ module.exports = {
* https://github.com/tc39/proposal-decorators
**/
['@babel/plugin-proposal-decorators', { legacy: true }],
// The "loose" option must be the same for all three of these plugins.
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-private-methods', { loose: true }],
['@babel/plugin-proposal-private-property-in-object', { loose: true }],
jtoar marked this conversation as resolved.
Show resolved Hide resolved
],
overrides: [
// ** WEB PACKAGES **
Expand Down
14 changes: 14 additions & 0 deletions constraints.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
% Yarn Constraints https://yarnpkg.com/features/constraints
thedavidprice marked this conversation as resolved.
Show resolved Hide resolved
% check with "yarn constraints" (fix w/ "yarn constraints --fix")
% reference for other constraints: https://github.com/babel/babel/blob/main/constraints.pro

% Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'devDependencies') :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'devDependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies').

% Prevent two workspaces from depending on conflicting versions of a same dependency
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType) :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
workspace_has_dependency(OtherWorkspaceCwd, DependencyIdent, DependencyRange2, DependencyType2),
DependencyRange \= DependencyRange2.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
"packages/*"
],
"devDependencies": {
"@babel/cli": "7.15.4",
"@babel/node": "7.15.4",
"eslint": "7.32.0",
"jest": "27.2.0",
"npm-packlist": "3.0.0",
"rimraf": "3.0.2",
"typescript": "4.4.3",
"typescript-transform-paths": "3.3.1"
},
"resolutions": {
Expand All @@ -22,7 +28,7 @@
"vscode-languageserver-textdocument": "1.0.1"
},
"scripts": {
"framework": "yarn --cwd ./tasks/framework-tools",
"framework": "yarn ./tasks/framework-tools",
"build": "yarn framework build",
"build:js": "yarn framework build:js",
"build:types": "yarn framework build:types",
Expand All @@ -35,5 +41,6 @@
"postinstall": "yarn framework install",
"build:link": "node ./tasks/build-and-copy",
"build:test-project": "node ./tasks/test-project/test-project"
}
},
"packageManager": "[email protected]"
}
8 changes: 6 additions & 2 deletions packages/api-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"main": "dist/handler",
"license": "MIT",
"dependencies": {
"@babel/plugin-transform-runtime": "7.15.0",
"ansi-colors": "4.1.1",
"body-parser": "1.19.0",
"chokidar": "3.5.2",
Expand All @@ -28,16 +29,19 @@
"youch-terminal": "1.1.1"
},
"devDependencies": {
"@babel/cli": "7.15.4",
"@types/aws-lambda": "8.10.83",
"@types/express": "4.17.13",
"@types/lodash.escape": "4.0.6",
"@types/morgan": "1.9.3",
"@types/qs": "6.9.7",
"@types/stack-trace": "0.0.29"
"@types/stack-trace": "0.0.29",
"jest": "27.2.0",
"typescript": "4.4.3"
},
"scripts": {
"build": "yarn build:js",
"prepublishOnly": "yarn cross-env NODE_ENV=production yarn build",
"prepublishOnly": "NODE_ENV=production yarn build",
thedavidprice marked this conversation as resolved.
Show resolved Hide resolved
"build:js": "babel src -d dist --extensions \".js,.ts,.tsx\"",
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build && yarn fix:permissions\"",
"fix:permissions": "chmod +x dist/index.js; chmod +x dist/watch.js"
Expand Down
7 changes: 5 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
"uuid": "8.3.2"
},
"devDependencies": {
"@babel/cli": "7.15.4",
"@redwoodjs/auth": "0.37.2",
"@types/crypto-js": "4.0.2",
"@types/jsonwebtoken": "8.5.5",
"@types/lodash.merge": "4.6.6",
"@types/lodash.omitby": "4.6.6",
"@types/md5": "2.3.1",
"split2": "3.2.2"
"jest": "27.2.0",
"split2": "3.2.2",
"typescript": "4.4.3"
},
"jest": {
"testPathIgnorePatterns": [
Expand All @@ -37,7 +40,7 @@
},
"scripts": {
"build": "yarn build:js && yarn build:types",
"prepublishOnly": "yarn cross-env NODE_ENV=production yarn build",
"prepublishOnly": "NODE_ENV=production yarn build",
"build:js": "babel src -d dist --extensions \".js,.ts,.tsx\"",
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,ts,tsx\" --ignore dist --exec \"yarn build\"",
Expand Down
Loading