Skip to content

Commit 436cebe

Browse files
authored
Add support for nested workspaces (#84)
* Add support for nested workspaces * List all workspaces, but filter root * Remove redundant yarn install * Use @metamask/action-utils for resolving workspace locations * Remove unused import * Remove unused type * Set timeout to 10 seconds
1 parent 49d0024 commit 436cebe

File tree

6 files changed

+29
-27
lines changed

6 files changed

+29
-27
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
"test:watch": "jest --watch"
2424
},
2525
"dependencies": {
26-
"@metamask/action-utils": "^0.0.2",
26+
"@metamask/action-utils": "^1.0.0",
2727
"@metamask/utils": "^5.0.2",
2828
"debug": "^4.3.4",
2929
"execa": "^5.1.1",
30-
"glob": "^10.2.2",
3130
"pony-cause": "^2.1.9",
3231
"semver": "^7.5.0",
3332
"which": "^3.0.0",

src/functional.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { withMonorepoProjectEnvironment } from '../tests/functional/helpers/with';
22
import { buildChangelog } from '../tests/functional/helpers/utils';
33

4+
jest.setTimeout(10_000);
5+
46
describe('create-release-branch (functional)', () => {
57
describe('against a monorepo with independent versions', () => {
68
it('bumps the ordinary part of the root package and updates the versions of the specified packages according to the release spec', async () => {
@@ -654,16 +656,16 @@ Error: Your release spec could not be processed due to the following issues:
654656
655657
* The following packages, which have changed since their latest release, are missing.
656658
657-
- @scope/d
658659
- @scope/b
660+
- @scope/d
659661
660662
Consider including them in the release spec so that any packages that rely on them won't break in production.
661663
662664
If you are ABSOLUTELY SURE that this won't occur, however, and want to postpone the release of a package, then list it with a directive of "intentionally-skip". For example:
663665
664666
packages:
665-
"@scope/d": intentionally-skip
666667
"@scope/b": intentionally-skip
668+
"@scope/d": intentionally-skip
667669
668670
The release spec file has been retained for you to edit again and make the necessary fixes. Once you've done this, re-run this tool.
669671

src/misc-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export async function getStdoutFromCommand(
155155
}
156156

157157
/**
158-
* Runs a Git command, splitting up the immediate output into lines.
158+
* Run a command, splitting up the immediate output into lines.
159159
*
160160
* @param command - The command to execute.
161161
* @param args - The positional arguments to the command.

src/project.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33
import { when } from 'jest-when';
44
import { SemVer } from 'semver';
5+
import * as actionUtils from '@metamask/action-utils';
56
import { withSandbox } from '../tests/helpers';
67
import { buildMockPackage, createNoopWriteStream } from '../tests/unit/helpers';
78
import { readProject } from './project';
@@ -10,6 +11,10 @@ import * as repoModule from './repo';
1011

1112
jest.mock('./package');
1213
jest.mock('./repo');
14+
jest.mock('@metamask/action-utils', () => ({
15+
...jest.requireActual('@metamask/action-utils'),
16+
getWorkspaceLocations: jest.fn(),
17+
}));
1318

1419
describe('project', () => {
1520
describe('readProject', () => {
@@ -57,6 +62,9 @@ describe('project', () => {
5762
projectTagNames,
5863
})
5964
.mockResolvedValue(rootPackage);
65+
when(
66+
jest.spyOn(actionUtils, 'getWorkspaceLocations'),
67+
).mockResolvedValue(['packages/a', 'packages/subpackages/b']);
6068
when(jest.spyOn(packageModule, 'readMonorepoWorkspacePackage'))
6169
.calledWith({
6270
packageDirectoryPath: path.join(

src/project.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { glob } from 'glob';
1+
import { resolve } from 'path';
2+
import { getWorkspaceLocations } from '@metamask/action-utils';
23
import { WriteStreamLike } from './fs';
34
import {
45
Package,
56
readMonorepoRootPackage,
67
readMonorepoWorkspacePackage,
78
} from './package';
8-
import { PackageManifestFieldNames } from './package-manifest';
99
import { getRepositoryHttpsUrl, getTagNames } from './repo';
1010
import { SemVer } from './semver';
11+
import { PackageManifestFieldNames } from './package-manifest';
1112

1213
/**
1314
* The release version of the root package of a monorepo extracted from its
@@ -90,24 +91,17 @@ export async function readProject(
9091
rootPackage.validatedManifest.version,
9192
);
9293

93-
const workspaceDirectories = (
94-
await Promise.all(
95-
rootPackage.validatedManifest[PackageManifestFieldNames.Workspaces].map(
96-
async (workspacePattern) => {
97-
return await glob(workspacePattern, {
98-
cwd: projectDirectoryPath,
99-
absolute: true,
100-
});
101-
},
102-
),
103-
)
104-
).flat();
94+
const workspaceDirectories = await getWorkspaceLocations(
95+
rootPackage.validatedManifest[PackageManifestFieldNames.Workspaces],
96+
projectDirectoryPath,
97+
true,
98+
);
10599

106100
const workspacePackages = (
107101
await Promise.all(
108102
workspaceDirectories.map(async (directory) => {
109103
return await readMonorepoWorkspacePackage({
110-
packageDirectoryPath: directory,
104+
packageDirectoryPath: resolve(projectDirectoryPath, directory),
111105
rootPackageName: rootPackage.validatedManifest.name,
112106
rootPackageVersion: rootPackage.validatedManifest.version,
113107
projectDirectoryPath,

yarn.lock

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -946,14 +946,14 @@ __metadata:
946946
languageName: node
947947
linkType: hard
948948

949-
"@metamask/action-utils@npm:^0.0.2":
950-
version: 0.0.2
951-
resolution: "@metamask/action-utils@npm:0.0.2"
949+
"@metamask/action-utils@npm:^1.0.0":
950+
version: 1.0.0
951+
resolution: "@metamask/action-utils@npm:1.0.0"
952952
dependencies:
953953
"@types/semver": ^7.3.6
954954
glob: ^7.1.7
955955
semver: ^7.3.5
956-
checksum: 4d3552d77a329791e2b1da0ca5023e9e04c1920c61f06ef070e8b4f4f072dd1f632124003964d47cdebf314a621a12d7209fbdd6871db37cfa1330a6ed679a11
956+
checksum: 5cfd5c7f8895f4bc602cb6e7b3e133aae0431ded8f50e136d314b2e54936ae22cc6add226fa6dfabb300addf084e32fd864a87b91af9188fa158b6e99d91e784
957957
languageName: node
958958
linkType: hard
959959

@@ -976,7 +976,7 @@ __metadata:
976976
resolution: "@metamask/create-release-branch@workspace:."
977977
dependencies:
978978
"@lavamoat/allow-scripts": ^2.3.1
979-
"@metamask/action-utils": ^0.0.2
979+
"@metamask/action-utils": ^1.0.0
980980
"@metamask/auto-changelog": ^3.0.0
981981
"@metamask/eslint-config": ^10.0.0
982982
"@metamask/eslint-config-jest": ^10.0.0
@@ -1002,7 +1002,6 @@ __metadata:
10021002
eslint-plugin-node: ^11.1.0
10031003
eslint-plugin-prettier: ^4.2.1
10041004
execa: ^5.1.1
1005-
glob: ^10.2.2
10061005
jest: ^29.5.0
10071006
jest-it-up: ^2.0.2
10081007
jest-when: ^3.5.2
@@ -3160,7 +3159,7 @@ __metadata:
31603159
languageName: node
31613160
linkType: hard
31623161

3163-
"glob@npm:^10.0.0, glob@npm:^10.2.2":
3162+
"glob@npm:^10.0.0":
31643163
version: 10.2.2
31653164
resolution: "glob@npm:10.2.2"
31663165
dependencies:

0 commit comments

Comments
 (0)