Skip to content

Commit 3602d90

Browse files
authored
feat!: Migrate to use the Pub workspaces feature (#816)
<!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Description This PR migrates so that we rely on the pub workspaces feature instead of creating the pubspec_overrides.yaml file. Docs update and migration instructions are soon coming up. Closes: #747 ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [x] ✨ `feat` -- New feature (non-breaking change which adds functionality) - [ ] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue) - [x] ❌ `!` -- Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 `refactor` -- Code refactor - [ ] ✅ `ci` -- Build configuration change - [ ] 📝 `docs` -- Documentation - [ ] 🗑️ `chore` -- Chore
1 parent b26f310 commit 3602d90

35 files changed

+780
-1581
lines changed

.github/workflows/validate.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- uses: actions/checkout@v3
3232
- uses: dart-lang/setup-dart@v1
3333
with:
34-
sdk: 3.2.0 # Update when min sdk supported version of `melos` package changes.
34+
sdk: 3.6.0 # Update when min sdk supported version of `melos` package changes.
3535
- name: Run Melos
3636
run: ./.github/workflows/scripts/install-tools.sh
3737

docs/commands/bootstrap.mdx

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,43 @@ description: Learn more about the `bootstrap` command in Melos.
77

88
<Info>Supports all [Melos filtering](/filters) flags.</Info>
99

10-
This command initializes the workspace, links local packages together and
11-
installs remaining package dependencies.
10+
This command initializes the workspace and installs remaining package
11+
dependencies.
1212

1313
```bash
1414
melos bootstrap
1515
# or
1616
melos bs
1717
```
1818

19-
Bootstrapping has two primary functions:
19+
Bootstrapping has three primary functions:
2020

2121
1. Installing all package dependencies (internally using `pub get`).
22-
2. Locally linking any packages together via path dependency overrides _without
23-
having to edit your pubspec.yaml_.
22+
2. Syncing shared dependencies between packages.
23+
3. Running any bootstrap lifecycle scripts.
2424

2525
## Why is bootstrapping required?
2626

27-
In normal projects, packages can be linked by providing a `path` within the
28-
`pubspec.yaml`. This works for small projects however presents a problem at
29-
scale. Packages cannot be published with a locally defined path, meaning once
30-
you're ready to publish your packages you'll need to manually update all the
31-
packages `pubspec.yaml` files with the versions. If your packages are also
32-
tightly coupled (dependencies of each other), you'll also have to manually check
33-
which versions should be updated. Even with a few of packages this can become a
34-
long and error-prone task.
35-
36-
Melos solves this problem by overriding local files which the Dart analyzer uses
37-
to read packages from. If a local package exists (defined in the `melos.yaml`
38-
file) and a different local package has it listed as a dependency, it will be
39-
linked regardless of whether a version has been specified.
27+
After the [Pub Workspaces feature](https://dart.dev/tools/pub/workspaces) was
28+
introduced in Dart 3.6.0, it is no longer strictly necessary to run `melos
29+
bootstrap`, since all the packages are already linked together. However, there
30+
are still some benefits to running `melos bootstrap`, because you need to run
31+
`pub get` in each package to initialize the workspace, and `melos bootstrap`
32+
will do that for you.
4033

4134
### Benefits
4235

43-
- All local packages in the repository can be interlinked by Melos to point to
44-
their local directories rather than 'remote' _without pubspec.yaml
45-
modifications_.
36+
Why would I want to use a monorepo?
37+
38+
- All local packages in the repository can be interlinked to point to their
39+
local directories rather than 'remote' _without pubspec.yaml modifications_.
4640
- **Example Scenario**: In a repository, package `A` depends on package `B`.
4741
Both packages `A` & `B` exist in the monorepo. However, if you `pub get`
4842
inside package `A`, `pub` will retrieve package `B` from the pub.dev
49-
registry as it's unaware of `B` existing locally. However, with Melos, it's
50-
aware that package `B` exists locally too, so it will generate the various
51-
pub files to point to a relative path in the local repository.
43+
registry as it's unaware of `B` existing locally. However, with Melos and
44+
pub workspaces, it's aware that package `B` exists locally too, so it will
45+
generate the various pub files to point to a relative path in the local
46+
repository.
5247
- If you wanted to use pub you could of course define a dependency override
5348
in the pubspec of package `A` that sets a path for package `B` but, then
5449
you'd have to do this manually every time and then manually remove it
@@ -86,20 +81,19 @@ melos bootstrap --diff="main"
8681

8782
## Bootstrap flags
8883

89-
- The `--no-example` flag is used to exclude flutter package's example's dependencies
90-
(https://github.com/dart-lang/pub/pull/3856)
84+
- The `--no-example` flag is used to exclude flutter package's example's
85+
dependencies (https://github.com/dart-lang/pub/pull/3856)
9186
- This will run `pub get` with the `--no-example` flag.
9287
- The `--enforce-lockfile` flag is used to enforce versions from `.lock` files.
9388
- Ensure .lock files exist, as failure may occur if they're not checked in.
94-
- The `--no-enforce-lockfile` flag is used to disregard versions from `.lock` files if
95-
`enforce-lockfile` is configured in the `melos.yaml` file.
96-
- The `--skip-linking` flag is used to skip the local linking of workspace packages.
97-
- The `--offline` flag is used to only resolve dependencies from the local cache by running
98-
`pub get` with the `--offline` flag.
89+
- The `--no-enforce-lockfile` flag is used to disregard versions from `.lock`
90+
files if `enforce-lockfile` is configured in the `melos.yaml` file.
91+
- The `--offline` flag is used to only resolve dependencies from the local
92+
cache by running `pub get` with the `--offline` flag.
9993

10094

101-
In addition to the above flags, the `melos bootstrap` command supports a few different flags that
102-
can be defined in your `melos.yaml` file.
95+
In addition to the above flags, the `melos bootstrap` command supports a few
96+
different configurations that can be defined in your `melos.yaml` file.
10397

10498

10599
### Shared dependencies

docs/getting-started.mdx

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ description: Learn how to start using Melos in your project
88
Melos requires a few one-off steps to be completed before you can start using
99
it.
1010

11+
## Pub Workspaces
12+
13+
First start by reading the short Pub Workspaces guide for how to get your
14+
monorepo ready to be used with Melos and Pub Workspaces, the guide can be
15+
found on the [Dart website](https://dart.dev/tools/pub/workspaces).
16+
1117
## Installation
1218

1319
Install Melos as a
@@ -59,11 +65,18 @@ now:
5965

6066
```yaml
6167
name: my_project
62-
68+
publish_to: none
6369
environment:
64-
sdk: '>=3.0.0 <4.0.0'
70+
sdk: ^3.6.0
71+
workspace:
72+
- packages/helper
73+
- packages/client_package
74+
- packages/server_package
6575
```
6676
77+
Where `packages/helper`, `packages/client_package` and `packages/server_package`
78+
are the paths to the packages in your workspace.
79+
6780
The corresponding `pubspec.lock` file should also be committed. Make sure to
6881
exclude it from the `.gitignore` file.
6982

@@ -73,6 +86,18 @@ Add Melos as a development dependency by running the following command:
7386
dart pub add melos --dev
7487
```
7588

89+
### Configure your packages
90+
91+
Next, in all your packages `pubspec.yaml` files, add the
92+
`resolution: workspace` field:
93+
94+
```yaml
95+
name: my_package
96+
resolution: workspace
97+
98+
...
99+
```
100+
76101
### Configure the workspace
77102

78103
Next create a `melos.yaml` file at the repository root. Within the `melos.yaml`
@@ -90,43 +115,23 @@ The `packages` list should contain paths to the individual packages within your
90115
project. Each path can be defined using the
91116
[glob](https://docs.python.org/3/library/glob.html) pattern expansion format.
92117

93-
Melos generates `pubspec_overrides.yaml` files to link local packages for
94-
development. Typically these files should be ignored by git. To ignore these
95-
files, add the following to your `.gitignore` file:
96-
97-
```
98-
pubspec_overrides.yaml
99-
```
100-
101118
## Bootstrapping
102119

103-
Once installed & setup, Melos needs to be bootstrapped. Bootstrapping has 2
104-
primary roles:
120+
Once installed & setup, Melos needs to be bootstrapped. Bootstrapping has
121+
three primary functions:
105122

106123
1. Installing all package dependencies (internally using `pub get`).
107-
2. Locally linking any packages together.
124+
2. Syncing shared dependencies between packages.
125+
3. Running any bootstrap lifecycle scripts.
108126

109-
Bootstrap your project by running the following command:
127+
Bootstrap your project by running the following command:
110128

111129
```bash
112130
melos bootstrap
113131
```
114132

115-
### Why do I need to bootstrap?
116-
117-
In normal projects, packages can be linked by providing a `path` within the
118-
`pubspec.yaml`. This works for small projects however presents a problem at
119-
scale. Packages cannot be published with a locally defined path, meaning once
120-
you're ready to publish your packages you'll need to manually update all the
121-
packages `pubspec.yaml` files with the versions. If your packages are also
122-
tightly coupled (dependencies of each other), you'll also have to manually check
123-
which versions should be updated. Even with a few packages this can become a
124-
long and error-prone task.
125-
126-
Melos solves this problem by overriding local files which the Dart analyzer uses
127-
to read packages from. If a local package exists (defined in the `melos.yaml`
128-
file) and a different local package has it listed as a dependency, it will be
129-
linked regardless of whether a version has been specified.
133+
If you wonder why bootrapping is needed you can read more about it in the
134+
[Bootstrap section](/commands/bootstrap).
130135

131136
## Next steps
132137

@@ -146,15 +151,16 @@ packages:
146151
- packages/**
147152
148153
scripts:
149-
analyze:
150-
exec: dart analyze .
154+
generate:
155+
run: melos exec -c 1 --depends-on build_runner -- dart run build_runner build
151156
```
152157

153-
Then execute the command by running `melos run analyze`.
158+
Then execute the command by running `melos generate`.
154159

155160
If you're looking for some inspiration as to what scripts can help with, check
156161
out the
157-
[FlutterFire repository](https://github.com/firebase/flutterfire/blob/master/melos.yaml).
162+
[FlutterFire repository](https://github.com/firebase/flutterfire/blob/main/melos.yaml)
163+
or the [Flame repository](https://github.com/flame-engine/flame/blob/main/melos.yaml).
158164

159165
If you are using VS Code, there is an [extension](/ide-support#vs-code)
160166
available, to integrate Melos with VS Code.

docs/guides/migrations.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,41 @@ description: How to migrate between major versions of Melos.
55

66
# Migrations
77

8+
## 6.x.x to 7.x.x
9+
10+
Since the [pub workspaces](https://dart.dev/tools/pub/workspaces) feature has
11+
been released, Melos has been updated to rely on that instead of creating
12+
`pubspec_overrides.yaml` files and thus some migration is needed.
13+
14+
The main difference is that you now have to add `resolution: workspace` to all
15+
of your packages' `pubspec.yaml` files and add a list of all your packages to
16+
the root `pubspec.yaml` file, similar to this:
17+
18+
Package `pubspec.yaml` file:
19+
```yaml
20+
name: my_package
21+
environment:
22+
sdk: ^3.6.0
23+
resolution: workspace
24+
```
25+
26+
Workspace root `pubspec.yaml` file:
27+
```yaml
28+
name: my_workspace
29+
publish_to: none
30+
environment:
31+
sdk: ^3.6.0
32+
workspace:
33+
- packages/helper
34+
- packages/client_package
35+
- packages/server_package
36+
dev_dependencies:
37+
melos: ^7.0.0
38+
```
39+
40+
> [!NOTE]
41+
> You have to use Dart SDK 3.6.0 or newer to use pub workspaces.
42+
843
## 3.0.0 to 4.0.0
944

1045
### `--no-git-tag-version` behavior change

docs/index.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ other. Features include:
3030
- Listing of local packages & their dependencies.
3131

3232
Melos also works great on CI/CD environments to help automate complex tasks and
33-
challenges.
33+
challenges. If you're using GitHub you can check out the
34+
[Melos GitHub Action](https://github.com/bluefireteam/melos-action).
3435

3536
## Projects using Melos
3637

melos.yaml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,38 @@ categories:
1111
command:
1212
bootstrap:
1313
environment:
14-
sdk: ">=3.2.0 <4.0.0"
14+
sdk: ^3.6.0
1515
dependencies:
1616
ansi_styles: ^0.3.2+1
17-
args: ^2.4.2
17+
args: ^2.6.0
1818
cli_launcher: ^0.3.1
19-
cli_util: ^0.4.1
20-
collection: ^1.18.0
19+
cli_util: ^0.4.2
20+
collection: any
2121
conventional_commit: ^0.6.0+1
22-
file: ^7.0.0
22+
file: ^7.0.1
2323
glob: ^2.1.2
24-
graphs: ^2.3.1
25-
http: ^1.1.0
26-
meta: ^1.10.0
24+
graphs: ^2.3.2
25+
http: ^1.2.2
26+
meta: any
2727
mustache_template: ^2.0.0
28-
path: ^1.8.3
29-
platform: ^3.1.4
28+
path: any
29+
platform: ^3.1.6
3030
pool: ^1.5.1
3131
prompts: ^2.0.0
32-
pub_semver: ^2.1.4
33-
pub_updater: ^0.4.0
34-
pubspec_parse: ^1.4.0
35-
string_scanner: ^1.2.0
36-
yaml: ^3.1.2
37-
yaml_edit: ^2.1.1
32+
pub_semver: ^2.1.5
33+
pub_updater: ^0.5.0
34+
pubspec_parse:
35+
git:
36+
url: https://github.com/dart-lang/tools.git
37+
path: pkgs/pubspec_parse
38+
string_scanner: ^1.3.0
39+
yaml: ^3.1.3
40+
yaml_edit: ^2.2.2
3841
dev_dependencies:
39-
mockito: ^5.4.2
40-
test: ^1.24.9
41-
path: ^1.9.0
42-
yaml: ^3.1.2
42+
mockito: ^5.4.5
43+
test: any
44+
path: ^1.9.1
45+
yaml: ^3.1.3
4346
version:
4447
# Generate commit links in package changelogs.
4548
linkToCommits: true

packages/conventional_commit/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ description:
44
version: 0.6.0+1
55
repository: https://github.com/invertase/melos/tree/main/packages/conventional_commit
66
issue_tracker: https://github.com/invertase/melos/issues
7+
resolution: workspace
78

89
environment:
9-
sdk: ">=3.2.0 <4.0.0"
10+
sdk: ^3.6.0
1011

1112
dev_dependencies:
12-
test: ^1.24.9
13+
test: any

packages/melos/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,41 @@ bases into multi-package repositories (sometimes called
3434
**Melos is a tool that optimizes the workflow around managing multi-package
3535
repositories with git and Pub.**
3636

37+
## Migrate to Melos 7.x.x
38+
39+
Since the [pub workspaces](https://dart.dev/tools/pub/workspaces) feature has
40+
been released, Melos has been updated to rely on that instead of creating
41+
`pubspec_overrides.yaml` files and thus some migration is needed.
42+
43+
The main difference is that you now have to add `resolution: workspace` to all
44+
of your packages' `pubspec.yaml` files and add a list of all your packages to
45+
the root `pubspec.yaml` file, similar to this:
46+
47+
Package `pubspec.yaml` file:
48+
```yaml
49+
name: my_package
50+
environment:
51+
sdk: ^3.6.0
52+
resolution: workspace
53+
```
54+
55+
Workspace root `pubspec.yaml` file:
56+
```yaml
57+
name: my_workspace
58+
publish_to: none
59+
environment:
60+
sdk: ^3.6.0
61+
workspace:
62+
- packages/helper
63+
- packages/client_package
64+
- packages/server_package
65+
dev_dependencies:
66+
melos: ^7.0.0
67+
```
68+
69+
> [!NOTE]
70+
> You have to use Dart SDK 3.6.0 or newer to use pub workspaces.
71+
3772
## Github Action
3873

3974
If you're planning on using Melos in your GitHub Actions workflows, you can use

0 commit comments

Comments
 (0)