diff --git a/change/beachball-7087c042-3375-4bcb-9949-32856b4e48b0.json b/change/beachball-7087c042-3375-4bcb-9949-32856b4e48b0.json new file mode 100644 index 00000000..f0c71e0a --- /dev/null +++ b/change/beachball-7087c042-3375-4bcb-9949-32856b4e48b0.json @@ -0,0 +1,7 @@ +{ + "type": "major", + "comment": "[BREAKING] Switch from `minimatch` to `micromatch`. Patterns should work the same, except that paths MUST use forward slashes. (This applies to `scope`, `ignorePatterns`, `groups`, and `changelog.groups`.)", + "packageName": "beachball", + "email": "elcraig@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/docs/concepts/groups.md b/docs/concepts/groups.md index df5017f0..33e4db2c 100644 --- a/docs/concepts/groups.md +++ b/docs/concepts/groups.md @@ -28,12 +28,12 @@ For cases where it's necessary to bump packages together, `beachball` also provi Groups can be added to the [configuration file](../overview/configuration). See the [`VersionGroupOptions` source](https://github.com/microsoft/beachball/blob/master/src/types/ChangelogOptions.ts) for full details. -| Name | Type | Description | -| ----------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `name` | `string` | Name of the version group | -| `include` | `string \| string[] \| true` | minimatch pattern(s) for package paths to include in this group. Patterns are relative to the repo root and must use forward slashes. If `true`, include all packages except those matching `exclude`. | -| `exclude` | `string \| string[]` | minimatch pattern(s) for package paths to include in this group. Patterns are relative to the repo root and must use forward slashes. | -| `disallowedChangeTypes` | `ChangeType[] \| null` | Disallow these change types for the group. | +| Name | Type | Description | +| ----------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `name` | `string` | Name of the version group | +| `include` | `string \| string[] \| true` | micromatch pattern(s) for package paths to include in this group. Patterns are relative to the repo root and must use forward slashes. If `true`, include all packages except those matching `exclude`. | +| `exclude` | `string \| string[]` | micromatch pattern(s) for package paths to include in this group. Patterns are relative to the repo root and must use forward slashes. | +| `disallowedChangeTypes` | `ChangeType[] \| null` | Disallow these change types for the group. | Example: @@ -58,12 +58,12 @@ If you only want to publish or record changes for certain packages, you should u To show changes for multiple packages in one change file, use the `changelog.groups` option. See the [`ChangelogGroupOptions` source](https://github.com/microsoft/beachball/blob/master/src/types/ChangelogOptions.ts) for full details. -| Name | Type | Description | -| ------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `masterPackageName` | `string` | The main package which a group of changes bubbles up to. | -| `include` | `string \| string[] \| true` | minimatch pattern(s) for package paths to include in this group. Patterns are relative to the repo root and must use forward slashes. If `true`, include all packages except those matching `exclude`. | -| `exclude` | `string \| string[]` | minimatch pattern(s) for package paths to exclude from this group. Patterns are relative to the repo root and must use forward slashes. | -| `changelogPath` | `string` | Put the grouped changelog file under this directory. Can be relative to the root, or absolute. | +| Name | Type | Description | +| ------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `masterPackageName` | `string` | The main package which a group of changes bubbles up to. | +| `include` | `string \| string[] \| true` | micromatch pattern(s) for package paths to include in this group. Patterns are relative to the repo root and must use forward slashes. If `true`, include all packages except those matching `exclude`. | +| `exclude` | `string \| string[]` | micromatch pattern(s) for package paths to exclude from this group. Patterns are relative to the repo root and must use forward slashes. | +| `changelogPath` | `string` | Put the grouped changelog file under this directory. Can be relative to the root, or absolute. | In this example, changelogs for all packages under `packages/*` (except `packages/baz`) are written to a `CHANGELOG.md` at the repo root (`.`), with `foo` as the master package. (To replace `foo`'s usual changelog with a grouped one, you'd specify `changelogPath` as the path to `foo` instead, e.g. `packages/foo`.) diff --git a/docs/overview/configuration.md b/docs/overview/configuration.md index 44a1c4ee..087a457a 100644 --- a/docs/overview/configuration.md +++ b/docs/overview/configuration.md @@ -60,34 +60,34 @@ For the latest full list of supported options, see `RepoOptions` [in this file]( "Applies to" indicates where the settings can be specified: repo-level config or package-level config. -| Option | Type | Default | Applies to | Description | -| ----------------------- | ------------------------------ | -------------- | ------------- | ------------------------------------------------------------------------------------------------ | -| `access` | `'public'` or `'restricted'` | `'restricted'` | repo | publish access level for scoped package names (e.g. `@foo/bar`) | -| `branch` | `string` | [see notes][5] | repo | target branch; [see notes][5] | -| `bumpDeps` | `boolean` | `true` | repo | bump dependent packages during publish (if B is bumped, and A depends on B, also bump A) | -| `changeFilePrompt` | [`ChangeFilePromptOptions`][1] | | repo | customize the prompt for change files (can be used to add custom fields) | -| `changehint` | `string` | | repo | hint message for when change files are not detected but required | -| `changeDir` | `string` | `change` | repo | directory where change files are stored (relative to repo root) | -| `changelog` | [`ChangelogOptions`][2] | | repo | changelog rendering and grouping options | -| `defaultNpmTag` | `string` | `'latest'` | repo, package | the default dist-tag used for NPM publish | -| `disallowedChangeTypes` | `string[]` | | repo, package | what change types are disallowed | -| `fetch` | `boolean` | `true` | repo | fetch from remote before doing diff comparisons | -| `generateChangelog` | `boolean \| 'md' \| 'json'` | `true` | repo | whether to generate `CHANGELOG.md/json` (`'md'` or `'json'` to generate only that type) | -| `gitTags` | `boolean` | `true` | repo, package | whether to create git tags for published packages (eg: foo_v1.0.1) | -| `groups` | [`VersionGroupOptions[]`][3] | | repo | bump these packages together ([see details][3]) | -| `groupChanges` | `boolean` | `false` | repo | write multiple changes to a single changefile | -| `hooks` | [`HooksOptions`][4] | | repo | hooks for custom pre/post publish actions | -| `ignorePatterns` | `string[]` | | repo | ignore changes in these files (minimatch patterns with forward slashes; negations not supported) | -| `package` | `string` | | repo | specifies which package the command relates to (overrides change detection based on `git diff`) | -| `prereleasePrefix` | `string` | | repo | prerelease prefix for packages that are specified to receive a prerelease bump | -| `publish` | `boolean` | `true` | repo | whether to publish to npm registry | -| `push` | `boolean` | `true` | repo | whether to push to the remote git branch | -| `registry` | `string` | | repo | target NPM registry to publish | -| `retries` | `number` | `3` | repo | number of retries for a package publish before failing | -| `scope` | `string[]` | | repo | only consider package paths matching these patterns ([see details](#scoping)) | -| `shouldPublish` | `false \| undefined` | | package | manually disable publishing of a package by beachball (does not work to force publishing) | -| `tag` | `string` | `'latest'` | repo, package | dist-tag for npm when published | -| `transform` | [`TransformOptions`][4] | | repo | transformations for change files | +| Option | Type | Default | Applies to | Description | +| ----------------------- | ------------------------------ | -------------- | ------------- | ------------------------------------------------------------------------------------------------- | +| `access` | `'public'` or `'restricted'` | `'restricted'` | repo | publish access level for scoped package names (e.g. `@foo/bar`) | +| `branch` | `string` | [see notes][5] | repo | target branch; [see notes][5] | +| `bumpDeps` | `boolean` | `true` | repo | bump dependent packages during publish (if B is bumped, and A depends on B, also bump A) | +| `changeFilePrompt` | [`ChangeFilePromptOptions`][1] | | repo | customize the prompt for change files (can be used to add custom fields) | +| `changehint` | `string` | | repo | hint message for when change files are not detected but required | +| `changeDir` | `string` | `change` | repo | directory where change files are stored (relative to repo root) | +| `changelog` | [`ChangelogOptions`][2] | | repo | changelog rendering and grouping options | +| `defaultNpmTag` | `string` | `'latest'` | repo, package | the default dist-tag used for NPM publish | +| `disallowedChangeTypes` | `string[]` | | repo, package | what change types are disallowed | +| `fetch` | `boolean` | `true` | repo | fetch from remote before doing diff comparisons | +| `generateChangelog` | `boolean \| 'md' \| 'json'` | `true` | repo | whether to generate `CHANGELOG.md/json` (`'md'` or `'json'` to generate only that type) | +| `gitTags` | `boolean` | `true` | repo, package | whether to create git tags for published packages (eg: foo_v1.0.1) | +| `groups` | [`VersionGroupOptions[]`][3] | | repo | bump these packages together ([see details][3]) | +| `groupChanges` | `boolean` | `false` | repo | write multiple changes to a single changefile | +| `hooks` | [`HooksOptions`][4] | | repo | hooks for custom pre/post publish actions | +| `ignorePatterns` | `string[]` | | repo | ignore changes in these files (micromatch patterns with forward slashes; negations not supported) | +| `package` | `string` | | repo | specifies which package the command relates to (overrides change detection based on `git diff`) | +| `prereleasePrefix` | `string` | | repo | prerelease prefix for packages that are specified to receive a prerelease bump | +| `publish` | `boolean` | `true` | repo | whether to publish to npm registry | +| `push` | `boolean` | `true` | repo | whether to push to the remote git branch | +| `registry` | `string` | | repo | target NPM registry to publish | +| `retries` | `number` | `3` | repo | number of retries for a package publish before failing | +| `scope` | `string[]` | | repo | only consider package paths matching these patterns ([see details](#scoping)) | +| `shouldPublish` | `false \| undefined` | | package | manually disable publishing of a package by beachball (does not work to force publishing) | +| `tag` | `string` | `'latest'` | repo, package | dist-tag for npm when published | +| `transform` | [`TransformOptions`][4] | | repo | transformations for change files | [1]: https://github.com/microsoft/beachball/blob/master/src/types/ChangeFilePrompt.ts [2]: https://github.com/microsoft/beachball/blob/master/src/types/ChangelogOptions.ts diff --git a/package.json b/package.json index 1759fdd5..4cc243ca 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "execa": "^5.0.0", "fs-extra": "^11.1.1", "lodash": "^4.17.15", - "minimatch": "^3.0.4", + "micromatch": "^4.0.0", "p-graph": "^1.1.2", "p-limit": "^3.0.2", "prompts": "^2.4.2", @@ -64,7 +64,7 @@ "@jest/globals": "^29.0.0", "@types/fs-extra": "^11.0.0", "@types/lodash": "^4.14.191", - "@types/minimatch": "^5.0.0", + "@types/micromatch": "^4.0.0", "@types/node": "^20.0.0", "@types/prompts": "^2.4.2", "@types/semver": "^7.3.13", diff --git a/src/changefile/getChangedPackages.ts b/src/changefile/getChangedPackages.ts index 90fe555e..478220d3 100644 --- a/src/changefile/getChangedPackages.ts +++ b/src/changefile/getChangedPackages.ts @@ -1,6 +1,6 @@ import fs from 'fs-extra'; import path from 'path'; -import minimatch from 'minimatch'; +import micromatch from 'micromatch'; import type { ChangeFileInfo, ChangeInfoMultiple } from '../types/ChangeInfo'; import { getChangePath } from '../paths'; import { getChanges, getStagedChanges, git } from 'workspace-tools'; @@ -89,7 +89,7 @@ function getAllChangedPackages(options: BeachballOptions, packageInfos: PackageI // Also ignore the CHANGELOG files and change files because they're generated by beachball. const ignorePatterns = [...(options.ignorePatterns || []), `${changeDir}/*.json`, 'CHANGELOG.{md,json}']; const nonIgnoredChanges = changes.filter(moddedFile => { - const ignorePattern = ignorePatterns.find(pattern => minimatch(moddedFile, pattern, { matchBase: true })); + const ignorePattern = ignorePatterns.find(pattern => micromatch.isMatch(moddedFile, pattern, { matchBase: true })); ignorePattern && logIgnored(moddedFile, `ignored by pattern "${ignorePattern}"`); return !ignorePattern; }); diff --git a/src/monorepo/isPathIncluded.ts b/src/monorepo/isPathIncluded.ts index 49719fdb..1eca5012 100644 --- a/src/monorepo/isPathIncluded.ts +++ b/src/monorepo/isPathIncluded.ts @@ -1,7 +1,7 @@ -import minimatch from 'minimatch'; +import micromatch from 'micromatch'; /** - * Check if a relative path should be included given include and exclude patterns using minimatch. + * Check if a relative path should be included given include and exclude patterns using micromatch. * @param relativePath Relative path to check. * @param include Include pattern(s). If `true`, include all paths except those excluded. * @param exclude Exclude pattern(s). Currently these must be **negated** patterns: @@ -20,12 +20,12 @@ export function isPathIncluded(params: { shouldInclude = true; } else { const includePatterns = typeof include === 'string' ? [include] : include; - shouldInclude = includePatterns.some(pattern => minimatch(relativePath, pattern)); + shouldInclude = micromatch.isMatch(relativePath, includePatterns); } if (exclude?.length && shouldInclude) { const excludePatterns = typeof exclude === 'string' ? [exclude] : exclude; - shouldInclude = !excludePatterns.some(pattern => minimatch(relativePath, pattern)); + shouldInclude = !micromatch.isMatch(relativePath, excludePatterns); } return shouldInclude; diff --git a/src/types/BeachballOptions.ts b/src/types/BeachballOptions.ts index 6c3deafc..880b2eac 100644 --- a/src/types/BeachballOptions.ts +++ b/src/types/BeachballOptions.ts @@ -135,7 +135,7 @@ export interface RepoOptions { /** Custom pre/post publish actions */ hooks?: HooksOptions; /** - * Ignore changes in these files (minimatch patterns; negations not supported). + * Ignore changes in these files (micromatch patterns; negations not supported). * Patterns are relative to the repo root and must use forward slashes. */ ignorePatterns?: string[]; @@ -174,7 +174,7 @@ export interface RepoOptions { */ retries: number; /** - * Only apply commands to package paths matching these minimatch patterns. + * Only apply commands to package paths matching these micromatch patterns. * Patterns are relative to the monorepo root and must use forward slashes. * * Negations are supported: e.g. `['packages/foo/*', '!packages/foo/bar']` @@ -217,14 +217,14 @@ export interface VersionGroupOptions { name: string; /** - * minimatch pattern(s) for package paths to include in this group. + * micromatch pattern(s) for package paths to include in this group. * Patterns are relative to the repo root and must use forward slashes. * If `true`, include all packages except those matching `exclude`. */ include: string | string[] | true; /** - * minimatch pattern(s) for package paths to exclude from this group. + * micromatch pattern(s) for package paths to exclude from this group. * Patterns are relative to the repo root and must use forward slashes. */ exclude?: string | string[]; diff --git a/src/types/ChangelogOptions.ts b/src/types/ChangelogOptions.ts index 335c2206..d5ce9880 100644 --- a/src/types/ChangelogOptions.ts +++ b/src/types/ChangelogOptions.ts @@ -66,14 +66,14 @@ export interface ChangelogGroupOptions { masterPackageName: string; /** - * minimatch pattern(s) for package paths to include in this group. + * micromatch pattern(s) for package paths to include in this group. * Patterns are relative to the repo root and must use forward slashes. * If `true`, include all packages except those matching `exclude`. */ include: string | string[] | true; /** - * minimatch pattern(s) for package paths to exclude from this group. + * micromatch pattern(s) for package paths to exclude from this group. * Patterns are relative to the repo root and must use forward slashes. */ exclude?: string | string[]; diff --git a/yarn.lock b/yarn.lock index 933e7bb8..92c11ae4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1687,6 +1687,13 @@ __metadata: languageName: node linkType: hard +"@types/braces@npm:*": + version: 3.0.4 + resolution: "@types/braces@npm:3.0.4" + checksum: 10c0/05220f330814364318a1c2f403046d717690cabf3adc8417357b0b12713f92768cf9df76e0e25212b5a2727c8c56765ff19a284c7ece39e0985d0d6fadb6c4aa + languageName: node + linkType: hard + "@types/d3-array@npm:*": version: 3.2.1 resolution: "@types/d3-array@npm:3.2.1" @@ -2098,10 +2105,12 @@ __metadata: languageName: node linkType: hard -"@types/minimatch@npm:^5.0.0": - version: 5.1.2 - resolution: "@types/minimatch@npm:5.1.2" - checksum: 10c0/83cf1c11748891b714e129de0585af4c55dd4c2cafb1f1d5233d79246e5e1e19d1b5ad9e8db449667b3ffa2b6c80125c429dbee1054e9efb45758dbc4e118562 +"@types/micromatch@npm:^4.0.0": + version: 4.0.9 + resolution: "@types/micromatch@npm:4.0.9" + dependencies: + "@types/braces": "npm:*" + checksum: 10c0/b13d7594b4320f20729f20156c51e957d79deb15083f98a736689cd0d3e4ba83b5d125959f6edf65270a6b6db90db9cebef8168d88e1c4eedc9a18aecc0234a3 languageName: node linkType: hard @@ -3618,7 +3627,7 @@ __metadata: "@jest/globals": "npm:^29.0.0" "@types/fs-extra": "npm:^11.0.0" "@types/lodash": "npm:^4.14.191" - "@types/minimatch": "npm:^5.0.0" + "@types/micromatch": "npm:^4.0.0" "@types/node": "npm:^20.0.0" "@types/prompts": "npm:^2.4.2" "@types/semver": "npm:^7.3.13" @@ -3642,7 +3651,7 @@ __metadata: lint-staged: "npm:^15.0.0" lodash: "npm:^4.17.15" mermaid: "npm:^11.4.0" - minimatch: "npm:^3.0.4" + micromatch: "npm:^4.0.0" normalized-tmpdir: "npm:^1.0.1" p-graph: "npm:^1.1.2" p-limit: "npm:^3.0.2"