diff --git a/build.config.ts b/build.config.ts index 6b97886..755a389 100644 --- a/build.config.ts +++ b/build.config.ts @@ -6,12 +6,12 @@ import { build, type BuildOptions, transform } from "esbuild"; export default defineBuildConfig({ hooks: { async "build:before"(ctx) { - ctx.options.alias["minimatch"] = await buildMinimatch(); + ctx.options.alias["zeptomatch"] = await buildZeptomatch(); }, }, }); -async function buildMinimatch() { +async function buildZeptomatch() { let bundle = await build({ format: "iife", globalName: "__lib__", @@ -19,29 +19,25 @@ async function buildMinimatch() { write: false, stdin: { resolveDir: process.cwd(), - contents: /* js */ `export { minimatch } from "minimatch";`, + contents: /* js */ `export { default as zeptomatch } from "zeptomatch";`, }, }).then((r) => r.outputFiles![0].text); - bundle = bundle - .replace("options.debug", "false") - .replace(/ this\.debug\(/gm, " // this.debug("); - bundle = (await transform(bundle, { minify: true })).code!; bundle = /* js */ ` -let _lazyMinimatch = () => { ${bundle}; return __lib__; }; -let _minimatch; -export const minimatch = (path, pattern, opts) => { - if (!_minimatch) { - _minimatch = _lazyMinimatch(); - _lazyMinimatch = null; +let _lazyMatch = () => { ${bundle}; return __lib__.default || __lib__; }; +let _match; +export default (path, pattern) => { + if (!_match) { + _match = _lazyMatch(); + _lazyMatch = null; } - return _minimatch.minimatch(path, pattern, opts); + return _match(path, pattern); }; `; - const outFile = resolve("tmp/node_modules/minimatch/minimatch.min.mjs"); + const outFile = resolve("tmp/node_modules/zeptomatch/zeptomatch.min.mjs"); await mkdir(dirname(outFile), { recursive: true }); await writeFile(outFile, bundle); return outFile; diff --git a/package.json b/package.json index 4a1c11d..47ac038 100644 --- a/package.json +++ b/package.json @@ -53,11 +53,11 @@ "eslint": "^9.17.0", "eslint-config-unjs": "^0.4.2", "jiti": "^2.4.2", - "minimatch": "^10.0.1", "prettier": "^3.4.2", "typescript": "^5.7.2", "unbuild": "^3.2.0", - "vitest": "^2.1.8" + "vitest": "^2.1.8", + "zeptomatch": "^2.0.0" }, "packageManager": "pnpm@9.15.2" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aabc837..8ff77d2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,9 +29,6 @@ importers: jiti: specifier: ^2.4.2 version: 2.4.2 - minimatch: - specifier: ^10.0.1 - version: 10.0.1 prettier: specifier: ^3.4.2 version: 3.4.2 @@ -44,6 +41,9 @@ importers: vitest: specifier: ^2.1.8 version: 2.1.8(@types/node@22.10.2) + zeptomatch: + specifier: ^2.0.0 + version: 2.0.0 packages: @@ -1276,6 +1276,9 @@ packages: resolution: {integrity: sha512-OkToC372DtlQeje9/zHIo5CT8lRP/FUgEOKBEhU4e0abL7J7CD24fD9ohiLN5hagG/kWCYj4K5oaxxtj2Z0Dig==} engines: {node: '>=18'} + grammex@3.1.3: + resolution: {integrity: sha512-rUZoJJQguOCaAMTuoyxs40OxqSLgVhzCCwDn1mbp2vETWutv/TmgAz7KxMR8Tz4z4cty/zIh88HrOWKqWgeGjg==} + graphemer@1.4.0: resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==} @@ -1533,10 +1536,6 @@ packages: resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==} engines: {node: '>=4'} - minimatch@10.0.1: - resolution: {integrity: sha512-ethXTt3SGGR+95gudmqJ1eNhRO7eGEGIgYA9vnPatK4/etz2MEVDno5GMCibdMTuBMyElzIlgxMna3K94XDIDQ==} - engines: {node: 20 || >=22} - minimatch@3.1.2: resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} @@ -2286,6 +2285,9 @@ packages: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} + zeptomatch@2.0.0: + resolution: {integrity: sha512-xjsIq0tpg7dNtJcbl0tNf4d4It4UK1ujSYJZXvGygse3GNgX44v/b2FRbM8sCGZS2qh4o983u8+1CBNNF+106g==} + snapshots: '@ampproject/remapping@2.3.0': @@ -3518,6 +3520,8 @@ snapshots: globals@15.14.0: {} + grammex@3.1.3: {} + graphemer@1.4.0: {} has-flag@4.0.0: {} @@ -3738,10 +3742,6 @@ snapshots: min-indent@1.0.1: {} - minimatch@10.0.1: - dependencies: - brace-expansion: 2.0.1 - minimatch@3.1.2: dependencies: brace-expansion: 1.1.11 @@ -4500,3 +4500,7 @@ snapshots: yaml@2.6.1: {} yocto-queue@0.1.0: {} + + zeptomatch@2.0.0: + dependencies: + grammex: 3.1.3 diff --git a/src/path.ts b/src/path.ts index 3f5f65c..b902001 100644 --- a/src/path.ts +++ b/src/path.ts @@ -8,7 +8,7 @@ Check LICENSE file import type path from "node:path"; -import { minimatch } from "minimatch"; +import zeptomatch from "zeptomatch"; import { normalizeWindowsPath } from "./_internal"; @@ -293,14 +293,14 @@ export const parse: typeof path.parse = function (p) { }; }; -export const matchesGlob: typeof path.matchesGlob = (path, pattern) => { - // https://github.com/nodejs/node/blob/main/lib/internal/fs/glob.js#L660 - // https://github.com/isaacs/minimatch#windows - return minimatch(normalize(path), pattern, { - windowsPathsNoEscape: true, - nonegate: true, - nocomment: true, - optimizationLevel: 2, - nocaseMagicOnly: true, - }); +/** + * The `path.matchesGlob()` method determines if `path` matches the `pattern`. + * @param path The path to glob-match against. + * @param pattern The glob to check the path against. + */ +export const matchesGlob = ( + path: string, + pattern: string | string[], +): boolean => { + return zeptomatch(pattern, normalize(path)); }; diff --git a/test/index.spec.ts b/test/index.spec.ts index 1bc873f..6d9c614 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -403,6 +403,7 @@ describe("constants", () => { runTest("matchesGlob", matchesGlob, [ ["/foo/bar", "/foo/**", true], [String.raw`\foo\bar`, "/foo/**", true], + ["/foo/bar", "/{bar,foo}/**", true], ]); function _s(item) {