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

Add support for nested workspaces #84

Merged
merged 7 commits into from
Jul 18, 2023
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/action-utils": "^0.0.2",
"@metamask/action-utils": "^1.0.0",
"@metamask/utils": "^5.0.2",
"debug": "^4.3.4",
"execa": "^5.1.1",
"glob": "^10.2.2",
"pony-cause": "^2.1.9",
"semver": "^7.5.0",
"which": "^3.0.0",
Expand Down
6 changes: 4 additions & 2 deletions src/functional.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { withMonorepoProjectEnvironment } from '../tests/functional/helpers/with';
import { buildChangelog } from '../tests/functional/helpers/utils';

jest.setTimeout(10_000);

describe('create-release-branch (functional)', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if we could write a functional test involving nested workspaces, but we can do that later.

describe('against a monorepo with independent versions', () => {
it('bumps the ordinary part of the root package and updates the versions of the specified packages according to the release spec', async () => {
Expand Down Expand Up @@ -654,16 +656,16 @@ Error: Your release spec could not be processed due to the following issues:

* The following packages, which have changed since their latest release, are missing.

- @scope/d
- @scope/b
- @scope/d

Consider including them in the release spec so that any packages that rely on them won't break in production.

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:

packages:
"@scope/d": intentionally-skip
"@scope/b": intentionally-skip
"@scope/d": intentionally-skip

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.

Expand Down
2 changes: 1 addition & 1 deletion src/misc-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export async function getStdoutFromCommand(
}

/**
* Runs a Git command, splitting up the immediate output into lines.
* Run a command, splitting up the immediate output into lines.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can run any command, not just Git commands.

*
* @param command - The command to execute.
* @param args - The positional arguments to the command.
Expand Down
8 changes: 8 additions & 0 deletions src/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import path from 'path';
import { when } from 'jest-when';
import { SemVer } from 'semver';
import * as actionUtils from '@metamask/action-utils';
import { withSandbox } from '../tests/helpers';
import { buildMockPackage, createNoopWriteStream } from '../tests/unit/helpers';
import { readProject } from './project';
Expand All @@ -10,6 +11,10 @@ import * as repoModule from './repo';

jest.mock('./package');
jest.mock('./repo');
jest.mock('@metamask/action-utils', () => ({
...jest.requireActual('@metamask/action-utils'),
getWorkspaceLocations: jest.fn(),
}));

describe('project', () => {
describe('readProject', () => {
Expand Down Expand Up @@ -57,6 +62,9 @@ describe('project', () => {
projectTagNames,
})
.mockResolvedValue(rootPackage);
when(
jest.spyOn(actionUtils, 'getWorkspaceLocations'),
).mockResolvedValue(['packages/a', 'packages/subpackages/b']);
when(jest.spyOn(packageModule, 'readMonorepoWorkspacePackage'))
.calledWith({
packageDirectoryPath: path.join(
Expand Down
24 changes: 9 additions & 15 deletions src/project.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { glob } from 'glob';
import { resolve } from 'path';
import { getWorkspaceLocations } from '@metamask/action-utils';
import { WriteStreamLike } from './fs';
import {
Package,
readMonorepoRootPackage,
readMonorepoWorkspacePackage,
} from './package';
import { PackageManifestFieldNames } from './package-manifest';
import { getRepositoryHttpsUrl, getTagNames } from './repo';
import { SemVer } from './semver';
import { PackageManifestFieldNames } from './package-manifest';

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

const workspaceDirectories = (
await Promise.all(
rootPackage.validatedManifest[PackageManifestFieldNames.Workspaces].map(
async (workspacePattern) => {
return await glob(workspacePattern, {
cwd: projectDirectoryPath,
absolute: true,
});
},
),
)
).flat();
const workspaceDirectories = await getWorkspaceLocations(
rootPackage.validatedManifest[PackageManifestFieldNames.Workspaces],
projectDirectoryPath,
true,
);

const workspacePackages = (
await Promise.all(
workspaceDirectories.map(async (directory) => {
return await readMonorepoWorkspacePackage({
packageDirectoryPath: directory,
packageDirectoryPath: resolve(projectDirectoryPath, directory),
rootPackageName: rootPackage.validatedManifest.name,
rootPackageVersion: rootPackage.validatedManifest.version,
projectDirectoryPath,
Expand Down
13 changes: 6 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -946,14 +946,14 @@ __metadata:
languageName: node
linkType: hard

"@metamask/action-utils@npm:^0.0.2":
version: 0.0.2
resolution: "@metamask/action-utils@npm:0.0.2"
"@metamask/action-utils@npm:^1.0.0":
version: 1.0.0
resolution: "@metamask/action-utils@npm:1.0.0"
dependencies:
"@types/semver": ^7.3.6
glob: ^7.1.7
semver: ^7.3.5
checksum: 4d3552d77a329791e2b1da0ca5023e9e04c1920c61f06ef070e8b4f4f072dd1f632124003964d47cdebf314a621a12d7209fbdd6871db37cfa1330a6ed679a11
checksum: 5cfd5c7f8895f4bc602cb6e7b3e133aae0431ded8f50e136d314b2e54936ae22cc6add226fa6dfabb300addf084e32fd864a87b91af9188fa158b6e99d91e784
languageName: node
linkType: hard

Expand All @@ -976,7 +976,7 @@ __metadata:
resolution: "@metamask/create-release-branch@workspace:."
dependencies:
"@lavamoat/allow-scripts": ^2.3.1
"@metamask/action-utils": ^0.0.2
"@metamask/action-utils": ^1.0.0
"@metamask/auto-changelog": ^3.0.0
"@metamask/eslint-config": ^10.0.0
"@metamask/eslint-config-jest": ^10.0.0
Expand All @@ -1002,7 +1002,6 @@ __metadata:
eslint-plugin-node: ^11.1.0
eslint-plugin-prettier: ^4.2.1
execa: ^5.1.1
glob: ^10.2.2
jest: ^29.5.0
jest-it-up: ^2.0.2
jest-when: ^3.5.2
Expand Down Expand Up @@ -3160,7 +3159,7 @@ __metadata:
languageName: node
linkType: hard

"glob@npm:^10.0.0, glob@npm:^10.2.2":
"glob@npm:^10.0.0":
version: 10.2.2
resolution: "glob@npm:10.2.2"
dependencies:
Expand Down