cleanup(js): switch to picomatch (#30079)

This commit is contained in:
James Garbutt 2025-02-25 12:26:33 +00:00 committed by GitHub
parent c02719d2df
commit c35862d4b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 29 additions and 12 deletions

View File

@ -141,6 +141,7 @@
"@types/marked": "^2.0.0", "@types/marked": "^2.0.0",
"@types/node": "20.16.10", "@types/node": "20.16.10",
"@types/npm-package-arg": "6.1.1", "@types/npm-package-arg": "6.1.1",
"@types/picomatch": "3.0.2",
"@types/react": "18.3.1", "@types/react": "18.3.1",
"@types/react-dom": "18.3.0", "@types/react-dom": "18.3.0",
"@types/semver": "^7.5.8", "@types/semver": "^7.5.8",
@ -364,6 +365,7 @@
"next-seo": "^5.13.0", "next-seo": "^5.13.0",
"node-machine-id": "1.1.12", "node-machine-id": "1.1.12",
"npm-run-path": "^4.0.1", "npm-run-path": "^4.0.1",
"picomatch": "4.0.2",
"preact": "10.25.4", "preact": "10.25.4",
"react": "18.3.1", "react": "18.3.1",
"react-copy-to-clipboard": "^5.1.0", "react-copy-to-clipboard": "^5.1.0",

View File

@ -11,6 +11,10 @@
"name": "fast-glob", "name": "fast-glob",
"message": "Please use `tinyglobby` instead." "message": "Please use `tinyglobby` instead."
}, },
{
"name": "minimatch",
"message": "Please use `picomatch` instead."
},
{ {
"name": "fs-extra", "name": "fs-extra",
"message": "Please use equivalent utilities from `node:fs` instead." "message": "Please use equivalent utilities from `node:fs` instead."

View File

@ -52,10 +52,10 @@
"ignore": "^5.0.4", "ignore": "^5.0.4",
"js-tokens": "^4.0.0", "js-tokens": "^4.0.0",
"jsonc-parser": "3.2.0", "jsonc-parser": "3.2.0",
"minimatch": "9.0.3",
"npm-package-arg": "11.0.1", "npm-package-arg": "11.0.1",
"npm-run-path": "^4.0.1", "npm-run-path": "^4.0.1",
"ora": "5.3.0", "ora": "5.3.0",
"picomatch": "4.0.2",
"semver": "^7.5.3", "semver": "^7.5.3",
"source-map-support": "0.5.19", "source-map-support": "0.5.19",
"tinyglobby": "^0.2.10", "tinyglobby": "^0.2.10",

View File

@ -1,6 +1,6 @@
import { detectPackageManager, type CreateNodesContext } from '@nx/devkit'; import { detectPackageManager, type CreateNodesContext } from '@nx/devkit';
import { TempFs } from '@nx/devkit/internal-testing-utils'; import { TempFs } from '@nx/devkit/internal-testing-utils';
import { minimatch } from 'minimatch'; import picomatch = require('picomatch');
import { mkdirSync, rmdirSync } from 'node:fs'; import { mkdirSync, rmdirSync } from 'node:fs';
// eslint-disable-next-line @typescript-eslint/no-restricted-imports // eslint-disable-next-line @typescript-eslint/no-restricted-imports
import { getLockFileName } from 'nx/src/plugins/js/lock-file/lock-file'; import { getLockFileName } from 'nx/src/plugins/js/lock-file/lock-file';
@ -3784,7 +3784,7 @@ async function applyFilesToTempFsAndContext(
await tempFs.createFiles(fileSys); await tempFs.createFiles(fileSys);
// @ts-expect-error update otherwise readonly property for testing // @ts-expect-error update otherwise readonly property for testing
context.configFiles = Object.keys(fileSys).filter((file) => context.configFiles = Object.keys(fileSys).filter((file) =>
minimatch(file, createNodesV2[0], { dot: true }) picomatch(createNodesV2[0], { dot: true })(file)
); );
setupWorkspaceContext(tempFs.tempDir); setupWorkspaceContext(tempFs.tempDir);
} }

View File

@ -17,7 +17,7 @@ import {
type TargetConfiguration, type TargetConfiguration,
} from '@nx/devkit'; } from '@nx/devkit';
import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs'; import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';
import { minimatch } from 'minimatch'; import picomatch = require('picomatch');
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'; import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
import { import {
basename, basename,
@ -555,8 +555,8 @@ function getInputs(
if ( if (
!otherFilesInclude.some( !otherFilesInclude.some(
(includePath) => (includePath) =>
minimatch(normalize(includePath), normalize(excludePath)) || picomatch(normalize(excludePath))(normalize(includePath)) ||
minimatch(normalize(excludePath), normalize(includePath)) picomatch(normalize(includePath))(normalize(excludePath))
) )
) { ) {
excludePaths.add(excludePath); excludePaths.add(excludePath);

View File

@ -1,4 +1,4 @@
import { minimatch } from 'minimatch'; import picomatch = require('picomatch');
import { import {
copyFileSync, copyFileSync,
existsSync, existsSync,
@ -169,8 +169,8 @@ export class CopyAssetsHandler {
const pathFromRoot = path.relative(this.rootDir, event.path); const pathFromRoot = path.relative(this.rootDir, event.path);
for (const ag of this.assetGlobs) { for (const ag of this.assetGlobs) {
if ( if (
minimatch(pathFromRoot, ag.pattern) && picomatch(ag.pattern)(pathFromRoot) &&
!ag.ignore?.some((ig) => minimatch(pathFromRoot, ig)) && !ag.ignore?.some((ig) => picomatch(ig)(pathFromRoot)) &&
!this.ignore.ignores(pathFromRoot) !this.ignore.ignores(pathFromRoot)
) { ) {
const relPath = path.relative(ag.input, pathFromRoot); const relPath = path.relative(ag.input, pathFromRoot);
@ -192,7 +192,7 @@ export class CopyAssetsHandler {
private filesToEvent(files: string[], assetGlob: AssetEntry): FileEvent[] { private filesToEvent(files: string[], assetGlob: AssetEntry): FileEvent[] {
return files.reduce((acc, src) => { return files.reduce((acc, src) => {
if ( if (
!assetGlob.ignore?.some((ig) => minimatch(src, ig)) && !assetGlob.ignore?.some((ig) => picomatch(ig)(src)) &&
!this.ignore.ignores(src) !this.ignore.ignores(src)
) { ) {
const relPath = path.relative(assetGlob.input, src); const relPath = path.relative(assetGlob.input, src);

View File

@ -6,7 +6,7 @@ import {
type GeneratorCallback, type GeneratorCallback,
type Tree, type Tree,
} from '@nx/devkit'; } from '@nx/devkit';
import { minimatch } from 'minimatch'; import picomatch = require('picomatch');
import { join } from 'node:path/posix'; import { join } from 'node:path/posix';
import { getGlobPatternsFromPackageManagerWorkspaces } from 'nx/src/plugins/package-json'; import { getGlobPatternsFromPackageManagerWorkspaces } from 'nx/src/plugins/package-json';
import { PackageJson } from 'nx/src/utils/package-json'; import { PackageJson } from 'nx/src/utils/package-json';
@ -30,7 +30,7 @@ export function getProjectPackageManagerWorkspaceState(
(path) => readJson(tree, path, { expectComments: true }) (path) => readJson(tree, path, { expectComments: true })
); );
const isIncluded = patterns.some((p) => const isIncluded = patterns.some((p) =>
minimatch(join(projectRoot, 'package.json'), p) picomatch(p)(join(projectRoot, 'package.json'))
); );
return isIncluded ? 'included' : 'excluded'; return isIncluded ? 'included' : 'excluded';

11
pnpm-lock.yaml generated
View File

@ -120,6 +120,9 @@ importers:
npm-run-path: npm-run-path:
specifier: ^4.0.1 specifier: ^4.0.1
version: 4.0.1 version: 4.0.1
picomatch:
specifier: 4.0.2
version: 4.0.2
preact: preact:
specifier: 10.25.4 specifier: 10.25.4
version: 10.25.4 version: 10.25.4
@ -505,6 +508,9 @@ importers:
'@types/npm-package-arg': '@types/npm-package-arg':
specifier: 6.1.1 specifier: 6.1.1
version: 6.1.1 version: 6.1.1
'@types/picomatch':
specifier: 3.0.2
version: 3.0.2
'@types/react': '@types/react':
specifier: 18.3.1 specifier: 18.3.1
version: 18.3.1 version: 18.3.1
@ -7282,6 +7288,9 @@ packages:
'@types/phoenix@1.6.5': '@types/phoenix@1.6.5':
resolution: {integrity: sha512-xegpDuR+z0UqG9fwHqNoy3rI7JDlvaPh2TY47Fl80oq6g+hXT+c/LEuE43X48clZ6lOfANl5WrPur9fYO1RJ/w==} resolution: {integrity: sha512-xegpDuR+z0UqG9fwHqNoy3rI7JDlvaPh2TY47Fl80oq6g+hXT+c/LEuE43X48clZ6lOfANl5WrPur9fYO1RJ/w==}
'@types/picomatch@3.0.2':
resolution: {integrity: sha512-n0i8TD3UDB7paoMMxA3Y65vUncFJXjcUf7lQY7YyKGl6031FNjfsLs6pdLFCy2GNFxItPJG8GvvpbZc2skH7WA==}
'@types/prettier@2.7.3': '@types/prettier@2.7.3':
resolution: {integrity: sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==} resolution: {integrity: sha512-+68kP9yzs4LMp7VNh8gdzMSPZFL44MLGqiHWvttYJe+6qnuVr4Ek9wSBQoveqY/r+LwjCcU29kNVkidwim+kYA==}
@ -25667,6 +25676,8 @@ snapshots:
'@types/phoenix@1.6.5': {} '@types/phoenix@1.6.5': {}
'@types/picomatch@3.0.2': {}
'@types/prettier@2.7.3': {} '@types/prettier@2.7.3': {}
'@types/prop-types@15.7.13': {} '@types/prop-types@15.7.13': {}