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

feat: migrate minimatch to picomatch #240

Merged
merged 6 commits into from
Mar 16, 2025
Merged

feat: migrate minimatch to picomatch #240

merged 6 commits into from
Mar 16, 2025

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Mar 14, 2025

Copy link

changeset-bot bot commented Mar 14, 2025

🦋 Changeset detected

Latest commit: f6aae8b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-import-x Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

socket-security bot commented Mar 14, 2025

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@types/picomatch@3.0.2 None 0 18.1 kB types
npm/eslint-plugin-mdx@3.2.0 eval 0 84.6 kB wooorm
npm/eslint-plugin-n@17.16.2 None +1 637 kB eslint-community-bot, weiran.zsd
npm/eslint-plugin-prettier@5.2.3 Transitive: environment +1 94.4 kB bpscott, jounqin, lydell, ...3 more
npm/eslint-plugin-unicorn@56.0.1 None 0 711 kB sindresorhus
npm/eslint-plugin-yml@1.17.0 None 0 288 kB ota-meshi

🚮 Removed packages: npm/@types/is-glob@4.0.4, npm/escope@4.0.0

View full report↗︎

Copy link

codesandbox-ci bot commented Mar 14, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@JounQin JounQin force-pushed the feat/micromatch branch 2 times, most recently from 88acf82 to eb6cc43 Compare March 14, 2025 16:11
Copy link
Collaborator

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

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

If we only use makeRe and isMatch, IMHO we can use picomatch (the library the powers micromatch under the hood) directly!

@JounQin
Copy link
Member Author

JounQin commented Mar 15, 2025

If we only use makeRe and isMatch, IMHO we can use picomatch (the library the powers micromatch under the hood) directly!

Yeah, I started with picomatch, but some cases failed, so I tried micormatch and then found the blocked issue. When it's fixed, I'll try picomatch again.

@Kenneth-Sills
Copy link

Kenneth-Sills commented Mar 16, 2025

I commented on your upstream issue WRT the behavior of leading ./, but coming here to continue.

Since you had the forethought to refactor out the glob calls, we should be able to pretty easily add normalization by modifying the functions provided in glob-match.ts to include a format option that normalizes the paths:

console.log(isMatch('baz', '[a-z]*'))
// true
console.log(isMatch('./baz', './[a-z]*'))
// false

console.log(isMatch('./baz', './[a-z]*', { format: (path) => path.replace(/^\.\//, '') }))
// true

Verified

This commit was signed with the committer’s verified signature.
@JounQin
Copy link
Member Author

JounQin commented Mar 16, 2025

Thanks @Kenneth-Sills I'll give it a try!


Sorry, but it makes ./baz sames as baz, so, unusable in this case.

console.log(isMatch('baz', './[a-z]*', { format: (path) => path.replace(/^\.\//, '') }))
// true
console.log(isMatch('./baz', './[a-z]*', { format: (path) => path.replace(/^\.\//, '') }))
// true

My hacking workaround:

import { isMatch as isMatch_ } from 'micromatch'

const normalizeBackslashes = (str: string) => str.replaceAll('\\', '/')

const defaultFormat = (path: string) => path.replace(/^\.\//, '')

const isMatchBase = (path: string, pattern: string, options?: Options) => {
  path = normalizeBackslashes(path)
  pattern = normalizeBackslashes(pattern)
  if (path.startsWith('./') && !/^(\.\/|\*{1,2})/.test(pattern)) {
    return false
  }
  return isMatch_(path, pattern, { format: defaultFormat, ...options })
}

export const isMatch = (
  pathname: string,
  patterns: string | string[],
  options?: Options,
) => {
  patterns = Array.isArray(patterns) ? patterns : [patterns]
  return patterns.some(p => isMatchBase(pathname, p, options))
}

Copy link

codecov bot commented Mar 16, 2025

Codecov Report

Attention: Patch coverage is 98.43750% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.08%. Comparing base (0449729) to head (63b83aa).

Files with missing lines Patch % Lines
src/utils/glob-match.ts 96.96% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #240      +/-   ##
==========================================
- Coverage   96.09%   96.08%   -0.01%     
==========================================
  Files         106      107       +1     
  Lines        4783     4799      +16     
  Branches     1619     1624       +5     
==========================================
+ Hits         4596     4611      +15     
- Misses        187      188       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Verified

This commit was signed with the committer’s verified signature.
@JounQin JounQin changed the title feat: migrate minimatch to micromatch feat: migrate minimatch to picomatch Mar 16, 2025
@JounQin JounQin requested a review from SukkaW March 16, 2025 08:45
@JounQin JounQin marked this pull request as ready for review March 16, 2025 08:52
@JounQin JounQin enabled auto-merge (squash) March 16, 2025 08:53
@JounQin JounQin disabled auto-merge March 16, 2025 09:26
@JounQin JounQin merged commit 60eb443 into master Mar 16, 2025
58 of 59 checks passed
@JounQin JounQin deleted the feat/micromatch branch March 16, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants