From d6a36684b92921a552422242fee404af7ea318d1 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 29 Nov 2024 13:26:09 +0800 Subject: [PATCH 1/2] perf: move `fast-glob` to `tinyglobby` --- package.json | 5 +++-- pnpm-lock.yaml | 26 ++++++++++++++------------ pnpm-workspace.yaml | 1 - src/node/scan-dirs.ts | 11 +++++------ tsconfig.json | 1 + 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index ae343136..bf6ce33c 100644 --- a/package.json +++ b/package.json @@ -49,15 +49,15 @@ "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": { @@ -65,6 +65,7 @@ "@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:", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2313d862..67beeb36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,9 +42,6 @@ catalogs: estree-walker: specifier: ^3.0.3 version: 3.0.3 - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 h3: specifier: ^1.13.0 version: 1.13.0 @@ -60,9 +57,6 @@ catalogs: magic-string: specifier: ^0.30.14 version: 0.30.14 - micromatch: - specifier: ^4.0.8 - version: 4.0.8 mlly: specifier: ^1.7.3 version: 1.7.3 @@ -119,24 +113,21 @@ importers: estree-walker: specifier: 'catalog:' version: 3.0.3 - fast-glob: - specifier: 'catalog:' - version: 3.3.2 local-pkg: specifier: 'catalog:' version: 0.5.1 magic-string: specifier: 'catalog:' version: 0.30.14 - micromatch: - specifier: 'catalog:' - version: 4.0.8 mlly: specifier: 'catalog:' version: 1.7.3 pathe: specifier: 'catalog:' version: 1.1.2 + picomatch: + specifier: ^4.0.2 + version: 4.0.2 pkg-types: specifier: 'catalog:' version: 1.2.1 @@ -146,6 +137,9 @@ importers: strip-literal: specifier: 'catalog:' version: 2.1.1 + tinyglobby: + specifier: ^0.2.10 + version: 0.2.10 unplugin: specifier: 'catalog:' version: 1.16.0 @@ -162,6 +156,9 @@ importers: '@types/node': specifier: 'catalog:' version: 22.10.0 + '@types/picomatch': + specifier: ^3.0.1 + version: 3.0.1 '@vitest/coverage-v8': specifier: 'catalog:' version: 2.1.6(vitest@2.1.6(@types/node@22.10.0)(jiti@1.21.6)) @@ -1113,6 +1110,9 @@ packages: '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} + '@types/picomatch@3.0.1': + resolution: {integrity: sha512-1MRgzpzY0hOp9pW/kLRxeQhUWwil6gnrUYd3oEpeYBqp/FexhaCPv3F8LsYr47gtUU45fO2cm1dbwkSrHEo8Uw==} + '@types/resolve@1.20.2': resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} @@ -4009,6 +4009,8 @@ snapshots: '@types/normalize-package-data@2.4.4': {} + '@types/picomatch@3.0.1': {} + '@types/resolve@1.20.2': {} '@types/semver@7.5.8': {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index d0850a45..8f3d1861 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -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 diff --git a/src/node/scan-dirs.ts b/src/node/scan-dirs.ts index 9f67477a..99a947e7 100644 --- a/src/node/scan-dirs.ts +++ b/src/node/scan-dirs.ts @@ -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', @@ -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]) @@ -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) diff --git a/tsconfig.json b/tsconfig.json index 155d7e0e..4742cfe4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "moduleResolution": "Node", "resolveJsonModule": true, "types": [ + "node", "vite/client" ], "strict": true, From edf7fa503faa731fee36eaa42610fc1857278fdd Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 29 Nov 2024 13:27:09 +0800 Subject: [PATCH 2/2] chore: cleanup --- package.json | 1 - pnpm-lock.yaml | 19 ++----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index bf6ce33c..754e4c41 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,6 @@ "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:", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 67beeb36..b41ac3bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -150,9 +150,6 @@ importers: '@types/estree': specifier: 'catalog:' version: 1.0.6 - '@types/micromatch': - specifier: ^4.0.9 - version: 4.0.9 '@types/node': specifier: 'catalog:' version: 22.10.0 @@ -1081,10 +1078,7 @@ packages: resolution: {integrity: sha512-PNRHbydNG5EH8NK4c+izdJlxajIR6GxcUhzsYNRsn6Myep4dsZt0qFCz3rCPnkvgO5FYibDcMqgNHUT+zvjYZw==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} peerDependencies: - eslint: ^9.15.0 - - '@types/braces@3.0.4': - resolution: {integrity: sha512-0WR3b8eaISjEW7RpZnclONaLFDf7buaowRHdqLp4vLj54AsSAYWfh3DRbfiYJY9XDxMgx1B4sE1Afw2PGpuHOA==} + eslint: '>=8.40.0' '@types/debug@4.1.12': resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==} @@ -1098,9 +1092,6 @@ packages: '@types/mdast@4.0.4': resolution: {integrity: sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA==} - '@types/micromatch@4.0.9': - resolution: {integrity: sha512-7V+8ncr22h4UoYRLnLXSpTxjQrNUXtWHGeMPRJt1nULXI57G9bIcpyrHlmrQ7QK24EyyuXvYcSSWAM8GA9nqCg==} - '@types/ms@0.7.34': resolution: {integrity: sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==} @@ -1191,7 +1182,7 @@ packages: resolution: {integrity: sha512-cxh314tzaWwOLqVes2gnnCtvBDcM1UMdn+iFR+UjAn411dPT3tOmqrJjbMd7koZpMAmBM/GqeV4n9ge7JSiJJQ==} engines: {node: ^18.0.0 || >=20.0.0} peerDependencies: - vite: 6.0.0-alpha.19 + vite: ^5.0.0 || ^6.0.0 vue: ^3.2.25 '@vitest/coverage-v8@2.1.6': @@ -3983,8 +3974,6 @@ snapshots: - supports-color - typescript - '@types/braces@3.0.4': {} - '@types/debug@4.1.12': dependencies: '@types/ms': 0.7.34 @@ -3997,10 +3986,6 @@ snapshots: dependencies: '@types/unist': 3.0.3 - '@types/micromatch@4.0.9': - dependencies: - '@types/braces': 3.0.4 - '@types/ms@0.7.34': {} '@types/node@22.10.0':