From f0259c7ed05d323c28a78a5928c65d76f8aef89f Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:55:14 +0200 Subject: [PATCH] chore: replace `minimatch` with built-in `path.matchesGlob` --- package.json | 1 - scripts/affected.ts | 23 +++++++++++++---------- yarn.lock | 3 +-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 93f44e0a3..14534ce51 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "globals": "^16.5.0", "js-yaml": "^5.2.2", "knip": "^6.23.0", - "minimatch": "^10.0.0", "nx": "^22.0.0", "oxfmt": "^0.59.0", "oxlint": "^1.51.0", diff --git a/scripts/affected.ts b/scripts/affected.ts index 2450a4566..2b774d925 100644 --- a/scripts/affected.ts +++ b/scripts/affected.ts @@ -1,7 +1,7 @@ import { getBaseCommit, getChangedFiles, git } from "@rnx-kit/tools-git"; import * as yaml from "js-yaml"; -import { Minimatch } from "minimatch"; import * as fs from "node:fs"; +import * as path from "node:path"; type MatchChangedFiles = { "any-glob-to-any-file": string[] }; type Match = { "changed-files": MatchChangedFiles[] }; @@ -24,9 +24,8 @@ function loadLabels(): Record { /** * Makes platform specific file path matchers. */ -function makeMatchers(): Record { - const matchers: Record = {}; - const options = { dot: true }; +function makeMatchers(): Record { + const matchers: Record = {}; const labels = loadLabels(); for (const [label, match] of Object.entries(labels)) { @@ -36,7 +35,11 @@ function makeMatchers(): Record { const patterns = match[0]["changed-files"][0]["any-glob-to-any-file"]; const platform = label.split(": ")[1]; - matchers[platform] = patterns.map((m) => new Minimatch(m, options)); + matchers[platform] = patterns.map((pattern) => + // Modify pattern to match filenames starting with a period (but ignore + // patterns that start with `*`) + pattern.replaceAll("/*", "/{.,}*") + ); } return matchers; @@ -54,15 +57,15 @@ function getAffectedPlatforms(targetBranch: string | undefined): string[] { return clean(Object.keys(platformMatchers)); } - const changedFiles = getChangedFiles(baseCommit); - if (changedFiles.length === 0) { + const files = getChangedFiles(baseCommit); + if (files.length === 0) { // If there are no files, we are building default branch return clean(Object.keys(platformMatchers)); } // All platforms are affected if `react-native` related packages are changed const lockfile = "yarn.lock"; - if (changedFiles.includes(lockfile)) { + if (files.includes(lockfile)) { const diff = git("diff", baseCommit, lockfile); if (diff.includes("react-native")) { return clean(Object.keys(platformMatchers)); @@ -70,8 +73,8 @@ function getAffectedPlatforms(targetBranch: string | undefined): string[] { } const affectedPlatforms = new Set(); - for (const [platform, matchers] of Object.entries(platformMatchers)) { - if (matchers.some((m) => changedFiles.some((f) => m.match(f)))) { + for (const [platform, patterns] of Object.entries(platformMatchers)) { + if (patterns.some((m) => files.some((f) => path.matchesGlob(f, m)))) { affectedPlatforms.add(platform); } } diff --git a/yarn.lock b/yarn.lock index 5e621be6a..346ab845d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2508,7 +2508,6 @@ __metadata: globals: "npm:^16.5.0" js-yaml: "npm:^5.2.2" knip: "npm:^6.23.0" - minimatch: "npm:^10.0.0" nx: "npm:^22.0.0" oxfmt: "npm:^0.59.0" oxlint: "npm:^1.51.0" @@ -11676,7 +11675,7 @@ __metadata: languageName: node linkType: hard -"minimatch@npm:^10.0.0, minimatch@npm:^10.0.3, minimatch@npm:^10.1.1, minimatch@npm:^10.2.2, minimatch@npm:^10.2.5": +"minimatch@npm:^10.0.3, minimatch@npm:^10.1.1, minimatch@npm:^10.2.2, minimatch@npm:^10.2.5": version: 10.2.5 resolution: "minimatch@npm:10.2.5" dependencies: