From 183eb29b7191827cb193780475e528efa6d830e1 Mon Sep 17 00:00:00 2001 From: Marcin Date: Mon, 21 Aug 2023 07:35:21 -0700 Subject: [PATCH 1/4] Update to use micromatch. --- docs/concepts/groups.md | 2 +- docs/overview/configuration.md | 2 +- package.json | 4 ++-- src/changefile/getChangedPackages.ts | 4 ++-- src/monorepo/isPathIncluded.ts | 8 ++++---- src/types/BeachballOptions.ts | 27 +++++++++++++++++++++------ src/types/ChangelogOptions.ts | 4 ++-- yarn.lock | 16 ++++++++++++++-- 8 files changed, 47 insertions(+), 20 deletions(-) diff --git a/docs/concepts/groups.md b/docs/concepts/groups.md index 1de7ef8b7..ac15e03bb 100644 --- a/docs/concepts/groups.md +++ b/docs/concepts/groups.md @@ -40,6 +40,6 @@ module.exports = { } ``` -`beachball` uses `minimatch` to match which packages belong to which group via this configuration. In the above configuration, packages located inside `packages/groupfoo` would be bumped together. +`beachball` uses `micromatch` to match which packages belong to which group via this configuration. In the above configuration, packages located inside `packages/groupfoo` would be bumped together. > NOTE: Beachball does not guarantee currently that these packages have the same version number, but that it will be bumped at the same rate. This is an area of active development, so please consider submitting feature request issues to change its behavior with justifications diff --git a/docs/overview/configuration.md b/docs/overview/configuration.md index be794ea60..56739bdb0 100644 --- a/docs/overview/configuration.md +++ b/docs/overview/configuration.md @@ -71,7 +71,7 @@ For the latest full list of supported options, see `RepoOptions` [in this file]( | `groups` | `VersionGroupOptions[]` ([details][3]) | | repo | specifies groups of packages that need to be version bumped at the same time | | `groupChanges` | bool | `false` | repo | will write multiple changes to a single changefile | | `hooks` | `HooksOptions` ([details][4]) | | repo | hooks for custom pre/post publish actions | -| `ignorePatterns` | string[] | | repo | ignore changes in these files (minimatch patterns; negations not supported) | +| `ignorePatterns` | string[] | | repo | ignore changes in these files (micromatch patterns; negations not supported) | | `package` | string | | repo | specifies which package the command relates to (overrides change detection based on `git diff`) | | `prereleasePrefix` | string | | repo | prerelease prefix for packages that are specified to receive a prerelease bump | | `publish` | bool | `true` | repo | whether to publish to npm registry | diff --git a/package.json b/package.json index 4304298fd..10ccee7b4 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "execa": "^5.0.0", "fs-extra": "^10.0.0", "lodash": "^4.17.15", - "minimatch": "^3.0.4", + "micromatch": "^4.0.5", "p-limit": "^3.0.2", "prompts": "^2.4.2", "semver": "^7.0.0", @@ -58,7 +58,7 @@ "@jest/globals": "^29.0.0", "@types/fs-extra": "^9.0.13", "@types/lodash": "^4.14.191", - "@types/minimatch": "^5.0.0", + "@types/micromatch": "^4.0.2", "@types/node": "^14.0.0", "@types/prompts": "^2.4.2", "@types/semver": "^7.3.13", diff --git a/src/changefile/getChangedPackages.ts b/src/changefile/getChangedPackages.ts index caeb71a47..50939afbe 100644 --- a/src/changefile/getChangedPackages.ts +++ b/src/changefile/getChangedPackages.ts @@ -1,6 +1,6 @@ import fs from 'fs-extra'; import path from 'path'; -import minimatch from 'minimatch'; +import micromatch from 'micromatch'; import { ChangeFileInfo, ChangeInfoMultiple } from '../types/ChangeInfo'; import { changeFolder, getChangePath } from '../paths'; import { getChanges, getStagedChanges, git } from 'workspace-tools'; @@ -89,7 +89,7 @@ function getAllChangedPackages(options: BeachballOptions, packageInfos: PackageI // Also ignore the CHANGELOG files and change files because they're generated by beachball. const ignorePatterns = [...(options.ignorePatterns || []), `${changeFolder}/*.json`, 'CHANGELOG.{md,json}']; const nonIgnoredChanges = changes.filter(moddedFile => { - const ignorePattern = ignorePatterns.find(pattern => minimatch(moddedFile, pattern, { matchBase: true })); + const ignorePattern = ignorePatterns.find(pattern => micromatch.isMatch(moddedFile, pattern, { matchBase: true })); ignorePattern && logIgnored(moddedFile, `ignored by pattern "${ignorePattern}"`); return !ignorePattern; }); diff --git a/src/monorepo/isPathIncluded.ts b/src/monorepo/isPathIncluded.ts index 7503a4fe4..de875d409 100644 --- a/src/monorepo/isPathIncluded.ts +++ b/src/monorepo/isPathIncluded.ts @@ -1,19 +1,19 @@ -import minimatch from 'minimatch'; +import micromatch from 'micromatch'; /** - * Check if a relative path should be included given include and exclude patterns using minimatch. + * Check if a relative path should be included given include and exclude patterns using micromatch. */ export function isPathIncluded(relativePath: string, include: string | string[], exclude?: string | string[]): boolean { const includePatterns = typeof include === 'string' ? [include] : include; let shouldInclude = includePatterns.reduce( - (included, pattern) => included || minimatch(relativePath, pattern), + (included, pattern) => included || micromatch.isMatch(relativePath, pattern), false ); if (exclude) { const excludePatterns = typeof exclude === 'string' ? [exclude] : exclude; shouldInclude = excludePatterns.reduce( - (excluded: boolean, pattern: string) => excluded && minimatch(relativePath, pattern), + (excluded: boolean, pattern: string) => excluded && micromatch.isMatch(relativePath, pattern), shouldInclude ); } diff --git a/src/types/BeachballOptions.ts b/src/types/BeachballOptions.ts index 902dcbc2a..a5d779bb3 100644 --- a/src/types/BeachballOptions.ts +++ b/src/types/BeachballOptions.ts @@ -116,7 +116,7 @@ export interface RepoOptions { gitTags: boolean; /** Custom pre/post publish actions */ hooks?: HooksOptions; - /** Ignore changes in these files (minimatch patterns; negations not supported) */ + /** Ignore changes in these files (micromatch patterns; negations not supported) */ ignorePatterns?: string[]; /** For the `change` command, change message. For the `publish` command, commit message. */ message: string; @@ -179,10 +179,10 @@ export interface PackageOptions { * Options for bumping package versions together. */ export interface VersionGroupOptions { - /** minimatch pattern (or array of minimatch) to detect which packages should be included in this group */ + /** micromatch pattern (or array of micromatch) to detect which packages should be included in this group */ include: string | string[]; - /** minimatch pattern (or array of minimatch) to detect which packages should be excluded in this group */ + /** micromatch pattern (or array of micromatch) to detect which packages should be excluded in this group */ exclude?: string | string[]; disallowedChangeTypes: ChangeType[] | null; @@ -204,7 +204,12 @@ export interface HooksOptions { * @param version The post-bump version of the package to be published * @param packageInfos Metadata about other packages processed by Beachball. Computed post-bump. Readonly. */ - prepublish?: (packagePath: string, name: string, version: string, packageInfos: Readonly) => void | Promise; + prepublish?: ( + packagePath: string, + name: string, + version: string, + packageInfos: Readonly + ) => void | Promise; /** * Runs for each package after the publish command. @@ -215,7 +220,12 @@ export interface HooksOptions { * @param version The post-bump version of the package to be published * @param packageInfos Metadata about other packages processed by Beachball. Computed post-bump. Readonly. */ - postpublish?: (packagePath: string, name: string, version: string, packageInfos: Readonly) => void | Promise; + postpublish?: ( + packagePath: string, + name: string, + version: string, + packageInfos: Readonly + ) => void | Promise; /** * Runs for each package, before writing changelog and package.json updates @@ -236,7 +246,12 @@ export interface HooksOptions { * @param version The post-bump version of the package to be published * @param packageInfos Metadata about other packages processed by Beachball. Computed post-bump. Readonly. */ - postbump?: (packagePath: string, name: string, version: string, packageInfos: Readonly) => void | Promise; + postbump?: ( + packagePath: string, + name: string, + version: string, + packageInfos: Readonly + ) => void | Promise; /** * Runs once after all bumps to all packages before committing changes diff --git a/src/types/ChangelogOptions.ts b/src/types/ChangelogOptions.ts index 11d8d6b4e..b76b262b2 100644 --- a/src/types/ChangelogOptions.ts +++ b/src/types/ChangelogOptions.ts @@ -36,10 +36,10 @@ export interface ChangelogGroupOptions { */ masterPackageName: string; - /** minimatch pattern (or array of minimatch) to detect which packages should be included in this group */ + /** micromatch pattern (or array of micromatch) to detect which packages should be included in this group */ include: string | string[]; - /** minimatch pattern (or array of minimatch) to detect which packages should be excluded in this group */ + /** micromatch pattern (or array of micromatch) to detect which packages should be excluded in this group */ exclude?: string | string[]; changelogPath: string; diff --git a/yarn.lock b/yarn.lock index 6d5c0ee36..a57939050 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1371,6 +1371,11 @@ "@types/connect" "*" "@types/node" "*" +"@types/braces@*": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@types/braces/-/braces-3.0.2.tgz#70009e5d385bc0d804f40f0a3f92285022536730" + integrity sha512-U5tlMYa0U/2eFTmJgKcPWQOEICP173sJDa6OjHbj5Tv+NVaYcrq2xmdWpNXOwWYGwJu+jER/pfTLdoQ31q8PzA== + "@types/connect-history-api-fallback@*": version "1.5.0" resolved "https://registry.yarnpkg.com/@types/connect-history-api-fallback/-/connect-history-api-fallback-1.5.0.tgz#9fd20b3974bdc2bcd4ac6567e2e0f6885cb2cf41" @@ -1494,12 +1499,19 @@ resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.2.tgz#e2ce9d83a613bacf284c7be7d491945e39e1f8e9" integrity sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA== +"@types/micromatch@^4.0.2": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@types/micromatch/-/micromatch-4.0.2.tgz#ce29c8b166a73bf980a5727b1e4a4d099965151d" + integrity sha512-oqXqVb0ci19GtH0vOA/U2TmHTcRY9kuZl4mqUxe0QmJAlIW13kzhuK5pi1i9+ngav8FjpSb9FVS/GE00GLX1VA== + dependencies: + "@types/braces" "*" + "@types/mime@*", "@types/mime@^1": version "1.3.2" resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw== -"@types/minimatch@*", "@types/minimatch@^5.0.0": +"@types/minimatch@*": version "5.1.2" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== @@ -7996,7 +8008,7 @@ micromatch@^3.1.10, micromatch@^3.1.4: snapdragon "^0.8.1" to-regex "^3.0.2" -micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4: +micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5: version "4.0.5" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== From 9e24b683d21d7ea1251638164fec9a615106cc7e Mon Sep 17 00:00:00 2001 From: Marcin Date: Mon, 21 Aug 2023 08:19:02 -0700 Subject: [PATCH 2/4] migration to Micromatch. --- package.json | 4 ++-- yarn.lock | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 10ccee7b4..da522a5db 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "execa": "^5.0.0", "fs-extra": "^10.0.0", "lodash": "^4.17.15", - "micromatch": "^4.0.5", + "micromatch": "^3.1.10", "p-limit": "^3.0.2", "prompts": "^2.4.2", "semver": "^7.0.0", @@ -58,7 +58,7 @@ "@jest/globals": "^29.0.0", "@types/fs-extra": "^9.0.13", "@types/lodash": "^4.14.191", - "@types/micromatch": "^4.0.2", + "@types/micromatch": "^3.1.0", "@types/node": "^14.0.0", "@types/prompts": "^2.4.2", "@types/semver": "^7.3.13", diff --git a/yarn.lock b/yarn.lock index a57939050..510f85c2f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1499,10 +1499,10 @@ resolved "https://registry.yarnpkg.com/@types/mdurl/-/mdurl-1.0.2.tgz#e2ce9d83a613bacf284c7be7d491945e39e1f8e9" integrity sha512-eC4U9MlIcu2q0KQmXszyn5Akca/0jrQmwDRgpAMJai7qBWq4amIQhZyNau4VYGtCeALvW1/NtjzJJ567aZxfKA== -"@types/micromatch@^4.0.2": - version "4.0.2" - resolved "https://registry.yarnpkg.com/@types/micromatch/-/micromatch-4.0.2.tgz#ce29c8b166a73bf980a5727b1e4a4d099965151d" - integrity sha512-oqXqVb0ci19GtH0vOA/U2TmHTcRY9kuZl4mqUxe0QmJAlIW13kzhuK5pi1i9+ngav8FjpSb9FVS/GE00GLX1VA== +"@types/micromatch@^3.1.0": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@types/micromatch/-/micromatch-3.1.1.tgz#98eac88894da6606c2690624a9893a59c812d9fa" + integrity sha512-Wr5y4uv3r7JP4jEUqv7rZeYiMBGRHcbojDVsl11wq6gw1v/ZZQvJexd9rtvVx3EIVqw8dwtcRjSs8m2DV9qHjQ== dependencies: "@types/braces" "*" @@ -8008,7 +8008,7 @@ micromatch@^3.1.10, micromatch@^3.1.4: snapdragon "^0.8.1" to-regex "^3.0.2" -micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5: +micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4: version "4.0.5" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== From f674215ac01323720b367327039eef59895d009c Mon Sep 17 00:00:00 2001 From: Marcin Date: Mon, 21 Aug 2023 09:35:57 -0700 Subject: [PATCH 3/4] with benchmark. --- benchmark.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 +++ tsconfig.json | 2 +- yarn.lock | 31 +++++++++++++++++++++++++++++-- 4 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 benchmark.ts diff --git a/benchmark.ts b/benchmark.ts new file mode 100644 index 000000000..509b8d79a --- /dev/null +++ b/benchmark.ts @@ -0,0 +1,51 @@ +// Description: Benchmarking the performance of micromatch vs minimatch +import minimatch from 'minimatch'; +import micromatch from 'micromatch'; + +const Benchmark = require('benchmark'); + +(() => { + var suite = new Benchmark.Suite(); + + const ignorePatterns = ['*.test.js', 'tests/**', 'yarn.lock', 'change/*.json', 'CHANGELOG.{md,json}']; + + const filesToCheck = [ + 'src/foo.test.js', + 'tests/stuff.js', + 'yarn.lock', + 'playwright', + 'browser', + 'edge', + 'foo', + 'bar', + 'baz', + 'qux', + 'src/f', + ]; + + suite + .add('micromatch', function () { + for (const file of filesToCheck) { + ignorePatterns.find(pattern => micromatch.isMatch(file, pattern, { matchBase: true })); + } + }) + .add('minimatch', function () { + for (const file of filesToCheck) { + ignorePatterns.find(pattern => minimatch(file, pattern, { matchBase: true })); + } + }) + .on('complete', function (this: any) { + console.log('Fastest is ' + this.filter('fastest').map('name')); + const tableData = this.map(benchmark => ({ + Function: benchmark.name, + 'Average Time (µs)': (benchmark.stats.mean * 1e6).toFixed(2), // Convert to microseconds + 'Operations per Second': benchmark.hz.toFixed(2), + 'Standard Error of the Mean': benchmark.stats.sem.toFixed(2), + 'Relative Margin of Error': benchmark.stats.rme.toFixed(2), + })); + + // Create a console table + console.table(tableData); + }) + .run(); +})(); diff --git a/package.json b/package.json index da522a5db..30173cbbc 100644 --- a/package.json +++ b/package.json @@ -41,11 +41,13 @@ "update-snapshots": "yarn test:unit -u && yarn test:func -u && yarn test:e2e -u" }, "dependencies": { + "benchmark": "^2.1.4", "cosmiconfig": "^7.0.0", "execa": "^5.0.0", "fs-extra": "^10.0.0", "lodash": "^4.17.15", "micromatch": "^3.1.10", + "minimatch": "^3.0.4", "p-limit": "^3.0.2", "prompts": "^2.4.2", "semver": "^7.0.0", @@ -59,6 +61,7 @@ "@types/fs-extra": "^9.0.13", "@types/lodash": "^4.14.191", "@types/micromatch": "^3.1.0", + "@types/minimatch": "^5.0.0", "@types/node": "^14.0.0", "@types/prompts": "^2.4.2", "@types/semver": "^7.3.13", diff --git a/tsconfig.json b/tsconfig.json index 36c04d126..6b8851be9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,5 +18,5 @@ "lib": ["ES2020"], "types": ["node"] }, - "include": ["src/**/*"] + "include": ["src/**/*", "benchmark.ts"] } diff --git a/yarn.lock b/yarn.lock index 510f85c2f..dbdfa5cd5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1511,7 +1511,7 @@ resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a" integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw== -"@types/minimatch@*": +"@types/minimatch@*", "@types/minimatch@^5.0.0": version "5.1.2" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca" integrity sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA== @@ -2711,6 +2711,14 @@ bcryptjs@2.4.3: resolved "https://registry.yarnpkg.com/bcryptjs/-/bcryptjs-2.4.3.tgz#9ab5627b93e60621ff7cdac5da9733027df1d0cb" integrity sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ== +benchmark@^2.1.4: + version "2.1.4" + resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629" + integrity sha512-l9MlfN4M1K/H2fbhfMy3B7vJd6AGKJVQn2h6Sg/Yx+KckoUA7ewS5Vv6TjSq18ooE1kS9hhAlQRH3AkXIh/aOQ== + dependencies: + lodash "^4.17.4" + platform "^1.3.3" + big.js@^3.1.3: version "3.2.0" resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e" @@ -3169,6 +3177,13 @@ char-regex@^1.0.2: resolved "https://registry.yarnpkg.com/char-regex/-/char-regex-1.0.2.tgz#d744358226217f981ed58f479b1d6bcc29545dcf" integrity sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw== +charm@*: + version "1.0.2" + resolved "https://registry.yarnpkg.com/charm/-/charm-1.0.2.tgz#8add367153a6d9a581331052c4090991da995e35" + integrity sha512-wqW3VdPnlSWT4eRiYX+hcs+C6ViBPUWk1qTCd+37qw9kEm/a5n2qcyQDMBWvSYKN/ctqZzeXNQaeBjOetJJUkw== + dependencies: + inherits "^2.0.1" + chokidar@^2.0.3, chokidar@^2.1.8: version "2.1.8" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.1.8.tgz#804b3a7b6a99358c3c5c61e71d8728f041cff917" @@ -3258,6 +3273,13 @@ cli-boxes@^2.2.0: resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f" integrity sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw== +cli-chart@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/cli-chart/-/cli-chart-0.1.0.tgz#eddaeb6558e8bb2020bc93efebbe245048abf5e1" + integrity sha512-8SxT0CbRZaPOPCLz0poBHYDKdVMx++EWTqU8FUvBYhTI/GrSQ6PX9ViGF25CK3VYPUACiFVuNeqc13E4XgXoHw== + dependencies: + charm "*" + cliui@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-5.0.0.tgz#deefcfdb2e800784aa34f46fa08e06851c7bbbc5" @@ -7756,7 +7778,7 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ== -lodash@4.17.21, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.3, lodash@^4.17.5: +lodash@4.17.21, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.3, lodash@^4.17.4, lodash@^4.17.5: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -8857,6 +8879,11 @@ pkginfo@0.4.1: resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.4.1.tgz#b5418ef0439de5425fc4995042dced14fb2a84ff" integrity sha512-8xCNE/aT/EXKenuMDZ+xTVwkT8gsoHN2z/Q29l80u0ppGEXVvsKRzNMbtKhg8LS8k1tJLAHHylf6p4VFmP6XUQ== +platform@^1.3.3: + version "1.3.6" + resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" + integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== + pn@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/pn/-/pn-1.1.0.tgz#e2f4cef0e219f463c179ab37463e4e1ecdccbafb" From 474dc4e9e58e5967ecf00e23cdd2e4369ebb3701 Mon Sep 17 00:00:00 2001 From: Marcin Date: Mon, 21 Aug 2023 09:42:41 -0700 Subject: [PATCH 4/4] more more. --- benchmark.ts | 2 +- benchmarkLarge.ts | 62 +++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 benchmarkLarge.ts diff --git a/benchmark.ts b/benchmark.ts index 509b8d79a..e9eb3de99 100644 --- a/benchmark.ts +++ b/benchmark.ts @@ -38,7 +38,7 @@ const Benchmark = require('benchmark'); console.log('Fastest is ' + this.filter('fastest').map('name')); const tableData = this.map(benchmark => ({ Function: benchmark.name, - 'Average Time (µs)': (benchmark.stats.mean * 1e6).toFixed(2), // Convert to microseconds + 'Mean Time (ms)': (benchmark.stats.mean * 1000).toFixed(2), // Convert to milliseconds 'Operations per Second': benchmark.hz.toFixed(2), 'Standard Error of the Mean': benchmark.stats.sem.toFixed(2), 'Relative Margin of Error': benchmark.stats.rme.toFixed(2), diff --git a/benchmarkLarge.ts b/benchmarkLarge.ts new file mode 100644 index 000000000..bdd351b52 --- /dev/null +++ b/benchmarkLarge.ts @@ -0,0 +1,62 @@ +// Description: Benchmarking the performance of micromatch vs minimatch +import minimatch from 'minimatch'; +import micromatch from 'micromatch'; + +const Benchmark = require('benchmark'); + +(() => { + var suite = new Benchmark.Suite(); + + const ignorePatterns = ['*.test.js', 'tests/**', 'yarn.lock', 'change/*.json', 'CHANGELOG.{md,json}']; + + const filesToCheck = [ + 'src/foo.test.js', + 'tests/stuff.js', + 'yarn.lock', + 'playwright', + 'browser', + 'edge', + 'foo', + 'bar', + 'baz', + 'qux', + 'src/f', + ]; + + const numberOfRandomFiles = 10000; + + // Generate additional random files + for (let i = 0; i < numberOfRandomFiles; i++) { + const randomIndex = Math.floor(Math.random() * filesToCheck.length); + const randomFileName = filesToCheck[randomIndex]; + const randomVariant = Math.floor(Math.random() * 1000); // Generate a random number for variation + + filesToCheck.push(`${randomFileName}_${randomVariant}`); + } + + suite + .add('micromatch', function () { + for (const file of filesToCheck) { + ignorePatterns.find(pattern => micromatch.isMatch(file, pattern, { matchBase: true })); + } + }) + .add('minimatch', function () { + for (const file of filesToCheck) { + ignorePatterns.find(pattern => minimatch(file, pattern, { matchBase: true })); + } + }) + .on('complete', function (this: any) { + console.log('Fastest is ' + this.filter('fastest').map('name')); + const tableData = this.map(benchmark => ({ + Function: benchmark.name, + 'Mean Time (ms)': (benchmark.stats.mean * 1000).toFixed(2), // Convert to milliseconds + 'Operations per Second': benchmark.hz.toFixed(2), + 'Standard Error of the Mean': benchmark.stats.sem.toFixed(2), + 'Relative Margin of Error': benchmark.stats.rme.toFixed(2), + })); + + // Create a console table + console.table(tableData); + }) + .run(); +})(); diff --git a/tsconfig.json b/tsconfig.json index 6b8851be9..5cfa3ef7b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,5 +18,5 @@ "lib": ["ES2020"], "types": ["node"] }, - "include": ["src/**/*", "benchmark.ts"] + "include": ["src/**/*", "benchmark.ts", "benchmarkLarge.ts"] }