@@ -10,7 +10,7 @@ import type {
1010} from "@changesets/types" ;
1111import type { Packages , Tool } from "@manypkg/get-packages" ;
1212import jsYaml from "js-yaml" ;
13- import micromatch from "micromatch " ;
13+ import picomatch from "picomatch " ;
1414import type { ProbotOctokit } from "probot" ;
1515import { isChangeset } from "./is-changeset.ts" ;
1616
@@ -60,7 +60,31 @@ function matchGlobs(
6060) : Array < string > {
6161 return paths . filter ( ( path ) => {
6262 const relativePath = nodePath . relative ( cwd , path ) || "." ;
63- return micromatch . isMatch ( relativePath , globs ) ;
63+ return globMatchSome ( [ relativePath ] , globs ) ;
64+ } ) ;
65+ }
66+
67+ // Mirrors https://github.com/changesets/changesets/blob/5eeb0125f2766b9458aa1725900430b27b24116e/packages/git/src/index.ts#L346-L374
68+ function globMatchSome ( paths : ReadonlyArray < string > , patterns ?: ReadonlyArray < string > ) : boolean {
69+ if ( ! patterns ) return paths . length > 0 ;
70+
71+ const matchers = patterns . map ( ( pattern ) => picomatch ( pattern , undefined , true ) ) ;
72+ return paths . some ( ( path ) => {
73+ if ( path . includes ( "\\" ) ) {
74+ path = path . replaceAll ( "\\" , "/" ) ;
75+ }
76+
77+ let passed = false ;
78+ for ( const matcher of matchers ) {
79+ if ( ! passed ) {
80+ if ( ! matcher . state . negated && matcher ( path ) ) {
81+ passed = true ;
82+ }
83+ } else if ( matcher . state . negated && ! matcher ( path ) ) {
84+ passed = false ;
85+ }
86+ }
87+ return passed ;
6488 } ) ;
6589}
6690
@@ -241,7 +265,7 @@ export const getChangedPackages = async ({
241265
242266 const config = parseConfig ( await rawConfigPromise , packages ) ;
243267
244- // https://github.com/changesets/changesets/blob/6c250f58a128350c6905ed16691a25bf0c8bae0c /packages/git/src/index.ts#L264-L286
268+ // Mirrors https://github.com/changesets/changesets/blob/5eeb0125f2766b9458aa1725900430b27b24116e /packages/git/src/index.ts#L273-L304
245269 const changedPackages = packages . packages
246270 . toSorted ( ( pkgA , pkgB ) => pkgB . dir . length - pkgA . dir . length )
247271 . filter ( ( pkg ) => {
@@ -259,7 +283,7 @@ export const getChangedPackages = async ({
259283
260284 return (
261285 changedPackageFiles . length > 0 &&
262- micromatch ( changedPackageFiles , config . changedFilePatterns ) . length > 0
286+ globMatchSome ( changedPackageFiles , config . changedFilePatterns )
263287 ) ;
264288 } )
265289 . map ( ( pkg ) => pkg . packageJson . name ) ;
0 commit comments