From 7154e588d6f78979dfa86d4f922c1ffb4abf3f41 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 18 Oct 2024 16:05:19 +0800 Subject: [PATCH 1/3] perf(deps): replace fast-glob with tinyglobby --- packages/core/package.json | 4 +-- packages/core/prebundle.config.mjs | 1 - packages/core/rslib.config.ts | 1 - packages/core/src/config.ts | 2 +- packages/core/tsconfig.json | 1 - packages/plugin-dts/package.json | 4 +-- packages/plugin-dts/src/utils.ts | 10 +++---- pnpm-lock.yaml | 45 ++++++++++++++++++++++++------ tests/package.json | 4 +-- tests/scripts/helper.ts | 11 +++----- 10 files changed, 51 insertions(+), 32 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 29d64b6af..24c6c2d0f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -38,14 +38,14 @@ }, "dependencies": { "@rsbuild/core": "~1.0.14", - "rsbuild-plugin-dts": "workspace:*" + "rsbuild-plugin-dts": "workspace:*", + "tinyglobby": "^0.2.9" }, "devDependencies": { "@rslib/tsconfig": "workspace:*", "@rspack/core": "1.0.8", "@types/fs-extra": "^11.0.4", "commander": "^12.1.0", - "fast-glob": "^3.3.2", "fs-extra": "^11.2.0", "memfs": "^4.14.0", "picocolors": "1.1.0", diff --git a/packages/core/prebundle.config.mjs b/packages/core/prebundle.config.mjs index cf004823e..21b450c7e 100644 --- a/packages/core/prebundle.config.mjs +++ b/packages/core/prebundle.config.mjs @@ -13,7 +13,6 @@ export default { }, dependencies: [ 'commander', - 'fast-glob', { name: 'rslog', afterBundle(task) { diff --git a/packages/core/rslib.config.ts b/packages/core/rslib.config.ts index c4daef171..4f725b59e 100644 --- a/packages/core/rslib.config.ts +++ b/packages/core/rslib.config.ts @@ -24,7 +24,6 @@ export default defineConfig({ target: 'node', externals: { picocolors: '../compiled/picocolors/index.js', - 'fast-glob': '../compiled/fast-glob/index.js', commander: '../compiled/commander/index.js', rslog: '../compiled/rslog/index.js', }, diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 4f69016c5..e14e080a6 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -9,7 +9,7 @@ import { mergeRsbuildConfig, rspack, } from '@rsbuild/core'; -import glob from 'fast-glob'; +import { glob } from 'tinyglobby'; import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME, diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index d00b7b5b2..248a3738f 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -13,7 +13,6 @@ "paths": { "commander": ["./compiled/commander"], "picocolors": ["./compiled/picocolors"], - "fast-glob": ["./compiled/fast-glob"], "rslog": ["./compiled/rslog"] } }, diff --git a/packages/plugin-dts/package.json b/packages/plugin-dts/package.json index ad36172be..0e0a24e02 100644 --- a/packages/plugin-dts/package.json +++ b/packages/plugin-dts/package.json @@ -29,9 +29,9 @@ "dev": "rslib build --watch" }, "dependencies": { - "fast-glob": "^3.3.2", "magic-string": "^0.30.12", - "picocolors": "1.1.0" + "picocolors": "1.1.0", + "tinyglobby": "^0.2.9" }, "devDependencies": { "@microsoft/api-extractor": "^7.47.9", diff --git a/packages/plugin-dts/src/utils.ts b/packages/plugin-dts/src/utils.ts index ddb1edaaf..d13398d86 100644 --- a/packages/plugin-dts/src/utils.ts +++ b/packages/plugin-dts/src/utils.ts @@ -3,14 +3,12 @@ import fsP from 'node:fs/promises'; import { platform } from 'node:os'; import path, { join } from 'node:path'; import { type RsbuildConfig, logger } from '@rsbuild/core'; -import fg from 'fast-glob'; import MagicString from 'magic-string'; import color from 'picocolors'; +import { convertPathToPattern, glob } from 'tinyglobby'; import ts from 'typescript'; import type { DtsEntry } from './index'; -const { convertPathToPattern } = fg; - export function loadTsconfig(tsconfigPath: string): ts.ParsedCommandLine { const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile); const configFileContent = ts.parseJsonConfigFileContent( @@ -68,8 +66,8 @@ export const prettyTime = (seconds: number): string => { return `${format(minutes.toFixed(2))} m`; }; -// fast-glob only accepts posix path -// https://github.com/mrmlnc/fast-glob#convertpathtopatternpath +// tinyglobby only accepts posix path +// https://github.com/SuperchupuDev/tinyglobby?tab=readme-ov-file#api const convertPath = (path: string) => { if (platform() === 'win32') { return convertPathToPattern(path); @@ -111,7 +109,7 @@ export async function processDtsFiles( return; } - const dtsFiles = await fg(convertPath(join(dir, '/**/*.d.ts'))); + const dtsFiles = await glob(convertPath(join(dir, '/**/*.d.ts'))); for (const file of dtsFiles) { try { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cd68a5ef4..a24907e3f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -140,6 +140,9 @@ importers: rsbuild-plugin-dts: specifier: workspace:* version: link:../plugin-dts + tinyglobby: + specifier: ^0.2.9 + version: 0.2.9 devDependencies: '@rslib/tsconfig': specifier: workspace:* @@ -153,9 +156,6 @@ importers: commander: specifier: ^12.1.0 version: 12.1.0 - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 fs-extra: specifier: ^11.2.0 version: 11.2.0 @@ -208,15 +208,15 @@ importers: packages/plugin-dts: dependencies: - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 magic-string: specifier: ^0.30.12 version: 0.30.12 picocolors: specifier: 1.1.0 version: 1.1.0 + tinyglobby: + specifier: ^0.2.9 + version: 0.2.9 devDependencies: '@microsoft/api-extractor': specifier: ^7.47.9 @@ -281,9 +281,6 @@ importers: '@types/react-dom': specifier: ^18.3.1 version: 18.3.1 - fast-glob: - specifier: ^3.3.2 - version: 3.3.2 fs-extra: specifier: ^11.2.0 version: 11.2.0 @@ -296,6 +293,9 @@ importers: test-helper: specifier: workspace:* version: link:scripts + tinyglobby: + specifier: ^0.2.9 + version: 0.2.9 tests/e2e/react-component: dependencies: @@ -2601,6 +2601,14 @@ packages: fault@1.0.4: resolution: {integrity: sha512-CJ0HCB5tL5fYTEA7ToAq5+kTwd++Borf1/bifxd9iT70QcXr4MRrO3Llf8Ifs70q+SJcGHFtnIE/Nw6giCtECA==} + fdir@6.4.2: + resolution: {integrity: sha512-KnhMXsKSPZlAhp7+IjUkRZKPb4fUyccpDrdFXbi4QL1qkmFh9kVY09Yox+n4MaOb3lHZ1Tv829C3oaaXoMYPDQ==} + peerDependencies: + picomatch: ^3 || ^4 + peerDependenciesMeta: + picomatch: + optional: true + fetch-blob@3.2.0: resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==} engines: {node: ^12.20 || >= 14.13} @@ -3706,6 +3714,10 @@ packages: resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} engines: {node: '>=8.6'} + picomatch@4.0.2: + resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==} + engines: {node: '>=12'} + pify@2.3.0: resolution: {integrity: sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==} engines: {node: '>=0.10.0'} @@ -4503,6 +4515,10 @@ packages: tinyexec@0.3.0: resolution: {integrity: sha512-tVGE0mVJPGb0chKhqmsoosjsS+qUnJVGJpZgsHYQcGoPlG3B51R3PouqTgEGH2Dc9jjFyOqOpix6ZHNMXp1FZg==} + tinyglobby@0.2.9: + resolution: {integrity: sha512-8or1+BGEdk1Zkkw2ii16qSS7uVrQJPre5A9o/XkWPATkk23FZh/15BKFxPnlTy6vkljZxLqYCzzBMj30ZrSvjw==} + engines: {node: '>=12.0.0'} + tinypool@1.0.0: resolution: {integrity: sha512-KIKExllK7jp3uvrNtvRBYBWBOAXSX8ZvoaD8T+7KB/QHIuoJW3Pmr60zucywjAlMb5TeXUkcs/MWeWLu0qvuAQ==} engines: {node: ^18.0.0 || >=20.0.0} @@ -7036,6 +7052,10 @@ snapshots: dependencies: format: 0.2.2 + fdir@6.4.2(picomatch@4.0.2): + optionalDependencies: + picomatch: 4.0.2 + fetch-blob@3.2.0: dependencies: node-domexception: 1.0.0 @@ -8432,6 +8452,8 @@ snapshots: picomatch@2.3.1: {} + picomatch@4.0.2: {} + pify@2.3.0: {} pify@4.0.1: {} @@ -9293,6 +9315,11 @@ snapshots: tinyexec@0.3.0: {} + tinyglobby@0.2.9: + dependencies: + fdir: 6.4.2(picomatch@4.0.2) + picomatch: 4.0.2 + tinypool@1.0.0: {} tinyrainbow@1.2.0: {} diff --git a/tests/package.json b/tests/package.json index 50be35f11..d9a1daeee 100644 --- a/tests/package.json +++ b/tests/package.json @@ -23,10 +23,10 @@ "@types/node": "~18.19.39", "@types/react": "^18.3.11", "@types/react-dom": "^18.3.1", - "fast-glob": "^3.3.2", "fs-extra": "^11.2.0", "path-serializer": "0.1.3", "strip-ansi": "^7.1.0", - "test-helper": "workspace:*" + "test-helper": "workspace:*", + "tinyglobby": "^0.2.9" } } diff --git a/tests/scripts/helper.ts b/tests/scripts/helper.ts index ae1398265..317409c9d 100644 --- a/tests/scripts/helper.ts +++ b/tests/scripts/helper.ts @@ -1,13 +1,10 @@ import { platform } from 'node:os'; import { join } from 'node:path'; -import fg, { - type Options as GlobOptions, - convertPathToPattern, -} from 'fast-glob'; import fse from 'fs-extra'; +import { type GlobOptions, convertPathToPattern, glob } from 'tinyglobby'; -// fast-glob only accepts posix path -// https://github.com/mrmlnc/fast-glob#convertpathtopatternpath +// tinyglobby only accepts posix path +// https://github.com/SuperchupuDev/tinyglobby?tab=readme-ov-file#api const convertPath = (path: string) => { if (platform() === 'win32') { return convertPathToPattern(path); @@ -19,7 +16,7 @@ export const globContentJSON = async ( path: string, options?: GlobOptions, ): Promise> => { - const files = await fg(convertPath(join(path, '**/*')), options); + const files = await glob(convertPath(join(path, '**/*')), options); const ret: Record = {}; await Promise.all( From ad4d7d835ad551d18aa5b618725d64cfd5aeba64 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 18 Oct 2024 16:08:50 +0800 Subject: [PATCH 2/3] fix: cspell --- scripts/dictionary.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/dictionary.txt b/scripts/dictionary.txt index 61473d57d..6bf19a79c 100644 --- a/scripts/dictionary.txt +++ b/scripts/dictionary.txt @@ -119,6 +119,7 @@ systemjs tailwindcss taze templating +tinyglobby transpiling treeshaking tsbuildinfo From 5dd15138ef1555a619c5082a5bb752c485a4b9de Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 18 Oct 2024 16:24:48 +0800 Subject: [PATCH 3/3] fix: prefer using absolute path --- packages/core/src/config.ts | 1 + packages/plugin-dts/src/utils.ts | 4 +++- tests/scripts/helper.ts | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index e14e080a6..03312bd74 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -748,6 +748,7 @@ const composeEntryConfig = async ( // Turn entries in array into each separate entry. const globEntryFiles = await glob(entryFiles, { cwd: root, + absolute: true, }); // Filter the glob resolved entry files based on the allowed extensions diff --git a/packages/plugin-dts/src/utils.ts b/packages/plugin-dts/src/utils.ts index d13398d86..f8117779b 100644 --- a/packages/plugin-dts/src/utils.ts +++ b/packages/plugin-dts/src/utils.ts @@ -109,7 +109,9 @@ export async function processDtsFiles( return; } - const dtsFiles = await glob(convertPath(join(dir, '/**/*.d.ts'))); + const dtsFiles = await glob(convertPath(join(dir, '/**/*.d.ts')), { + absolute: true, + }); for (const file of dtsFiles) { try { diff --git a/tests/scripts/helper.ts b/tests/scripts/helper.ts index 317409c9d..ef2860f45 100644 --- a/tests/scripts/helper.ts +++ b/tests/scripts/helper.ts @@ -16,7 +16,10 @@ export const globContentJSON = async ( path: string, options?: GlobOptions, ): Promise> => { - const files = await glob(convertPath(join(path, '**/*')), options); + const files = await glob(convertPath(join(path, '**/*')), { + absolute: true, + ...options, + }); const ret: Record = {}; await Promise.all(