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

perf: move fast-glob to tinyglobby #396

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@
"acorn": "catalog:",
"escape-string-regexp": "catalog:",
"estree-walker": "catalog:",
"fast-glob": "catalog:",
"local-pkg": "catalog:",
"magic-string": "catalog:",
"micromatch": "catalog:",
"mlly": "catalog:",
"pathe": "catalog:",
"picomatch": "^4.0.2",
"pkg-types": "catalog:",
"scule": "catalog:",
"strip-literal": "catalog:",
"tinyglobby": "^0.2.10",
"unplugin": "catalog:"
},
"devDependencies": {
"@antfu/eslint-config": "catalog:",
"@types/estree": "catalog:",
"@types/micromatch": "^4.0.9",
"@types/node": "catalog:",
"@types/picomatch": "^3.0.1",
"@vitest/coverage-v8": "catalog:",
"bumpp": "catalog:",
"conventional-changelog-cli": "catalog:",
Expand Down
45 changes: 16 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ catalog:
escape-string-regexp: ^5.0.0
eslint: ^9.15.0
estree-walker: ^3.0.3
fast-glob: ^3.3.2
h3: ^1.13.0
jquery: ^3.7.1
lit: ^3.2.1
Expand Down
11 changes: 5 additions & 6 deletions src/node/scan-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { existsSync } from 'node:fs'
import { readFile } from 'node:fs/promises'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import fg from 'fast-glob'
import mm from 'micromatch'
import { findExports, findTypeExports, resolve as mllyResolve } from 'mlly'
import { dirname, join, normalize, parse as parsePath, resolve } from 'pathe'
import pm from 'picomatch'
import { camelCase } from 'scule'
import { glob } from 'tinyglobby'

const FileExtensionLookup = [
'mts',
Expand Down Expand Up @@ -44,21 +44,20 @@ export function normalizeScanDirs(dirs: (string | ScanDir)[], options?: ScanDirE

export async function scanFilesFromDir(dir: ScanDir | ScanDir[], options?: ScanDirExportsOptions) {
const dirGlobs = (Array.isArray(dir) ? dir : [dir]).map(i => i.glob)
const files = (await fg(
const files = (await glob(
dirGlobs,
{
absolute: true,
cwd: options?.cwd || process.cwd(),
onlyFiles: true,
followSymbolicLinks: true,
unique: true,
},
))
.map(i => normalize(i))

const fileFilter = options?.fileFilter || (() => true)

const indexOfDirs = (file: string) => dirGlobs.findIndex(glob => mm.isMatch(file, glob))
const indexOfDirs = (file: string) => dirGlobs.findIndex(glob => pm.isMatch(file, glob))
const fileSortByDirs = files.reduce((acc, file) => {
const index = indexOfDirs(file)
if (acc[index])
Expand All @@ -76,7 +75,7 @@ export async function scanDirExports(dirs: (string | ScanDir)[], options?: ScanD
const files = await scanFilesFromDir(normalizedDirs, options)

const includeTypesDirs = normalizedDirs.filter(dir => !dir.glob.startsWith('!') && dir.types)
const isIncludeTypes = (file: string) => includeTypesDirs.some(dir => mm.isMatch(file, dir.glob))
const isIncludeTypes = (file: string) => includeTypesDirs.some(dir => pm.isMatch(file, dir.glob))

const imports = (await Promise.all(files.map(file => scanExports(file, isIncludeTypes(file))))).flat()
const deduped = dedupeDtsExports(imports)
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"moduleResolution": "Node",
"resolveJsonModule": true,
"types": [
"node",
"vite/client"
],
"strict": true,
Expand Down