Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deps): update dependency minimatch to v5 (#1032)
* fix(deps): update dependency minimatch to v5 * chore(deps): update glob to v8 * refactor: wrap glob and minimatch to support windows paths * refactor: ensure exclude patterns are unix paths Also rename `exclude` to `excludePatterns` to clarify these are not os paths Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Daniel Tschinder <231804+danez@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0dd8174
commit 5aaf915
Showing
11 changed files
with
480 additions
and
96 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,61 @@ | ||
import { normalize, resolve } from 'path' | ||
import { promisify } from 'util' | ||
|
||
import glob from 'glob' | ||
import minimatch from 'minimatch' | ||
|
||
const pGlob = promisify(glob) | ||
import { minimatch, glob } from '../../../utils/matching' | ||
|
||
// Returns the subset of `paths` that don't match any of the glob expressions | ||
// from `exclude`. | ||
export const filterExcludedPaths = (paths: string[], exclude: string[] = []) => { | ||
if (exclude.length === 0) { | ||
export const filterExcludedPaths = (paths: string[], excludePattern: string[] = []) => { | ||
if (excludePattern.length === 0) { | ||
return paths | ||
} | ||
|
||
const excludedPaths = paths.filter((path) => !exclude.some((pattern) => minimatch(path, pattern))) | ||
const excludedPaths = paths.filter((path) => !excludePattern.some((pattern) => minimatch(path, pattern))) | ||
|
||
return excludedPaths | ||
} | ||
|
||
export const getPathsOfIncludedFiles = async ( | ||
includedFiles: string[], | ||
basePath?: string, | ||
): Promise<{ exclude: string[]; paths: string[] }> => { | ||
): Promise<{ excludePatterns: string[]; paths: string[] }> => { | ||
if (basePath === undefined) { | ||
return { exclude: [], paths: [] } | ||
return { excludePatterns: [], paths: [] } | ||
} | ||
|
||
// Some of the globs in `includedFiles` might be exclusion patterns, which | ||
// means paths that should NOT be included in the bundle. We need to treat | ||
// these differently, so we iterate on the array and put those paths in a | ||
// `exclude` array and the rest of the paths in an `include` array. | ||
const { include, exclude } = includedFiles.reduce<{ include: string[]; exclude: string[] }>( | ||
const { include, excludePatterns } = includedFiles.reduce<{ include: string[]; excludePatterns: string[] }>( | ||
(acc, path) => { | ||
if (path.startsWith('!')) { | ||
const excludePath = resolve(basePath, path.slice(1)) | ||
// convert to unix paths, as minimatch does not support windows paths in patterns | ||
const excludePattern = resolve(basePath, path.slice(1)) | ||
|
||
return { | ||
include: acc.include, | ||
exclude: [...acc.exclude, excludePath], | ||
excludePatterns: [...acc.excludePatterns, excludePattern], | ||
} | ||
} | ||
|
||
return { | ||
include: [...acc.include, path], | ||
exclude: acc.exclude, | ||
excludePatterns: acc.excludePatterns, | ||
} | ||
}, | ||
{ include: [], exclude: [] }, | ||
{ include: [], excludePatterns: [] }, | ||
) | ||
|
||
const pathGroups = await Promise.all( | ||
include.map((expression) => pGlob(expression, { absolute: true, cwd: basePath, ignore: exclude, nodir: true })), | ||
include.map((expression) => | ||
glob(expression, { absolute: true, cwd: basePath, ignore: excludePatterns, nodir: true }), | ||
), | ||
) | ||
|
||
// `pathGroups` is an array containing the paths for each expression in the | ||
// `include` array. We flatten it into a single dimension. | ||
const paths = pathGroups.flat() | ||
const normalizedPaths = paths.map(normalize) | ||
|
||
return { exclude, paths: [...new Set(normalizedPaths)] } | ||
return { excludePatterns, paths: [...new Set(normalizedPaths)] } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { promisify } from 'util' | ||
|
||
import globFunction from 'glob' | ||
import minimatchFunction from 'minimatch' | ||
import normalizePath from 'normalize-path' | ||
|
||
const pGlob = promisify(globFunction) | ||
|
||
/** | ||
* Both glob and minimatch only support unix style slashes in patterns | ||
* For this reason we wrap them and ensure all patters are always unixified | ||
* We use `normalize-path` here instead of `unixify` because we do not want to remove drive letters | ||
*/ | ||
|
||
export const glob = function (pattern: string, options: globFunction.IOptions): Promise<string[]> { | ||
let normalizedIgnore | ||
if (options.ignore) { | ||
normalizedIgnore = | ||
typeof options.ignore === 'string' | ||
? normalizePath(options.ignore) | ||
: options.ignore.map((expression) => normalizePath(expression)) | ||
} | ||
|
||
return pGlob(normalizePath(pattern), { ...options, ignore: normalizedIgnore }) | ||
} | ||
|
||
export const minimatch = function (target: string, pattern: string, options?: minimatchFunction.IOptions): boolean { | ||
return minimatchFunction(target, normalizePath(pattern), options) | ||
} |
5aaf915
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⏱ Benchmark results
largeDepsEsbuild: 7.2s
largeDepsNft: 34.8s