Skip to content

Commit

Permalink
perf: switch from fast-glob to tinyglobby (#2193)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Feb 17, 2025
1 parent 83a81eb commit 69f80f4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 36 deletions.
4 changes: 2 additions & 2 deletions docs/pages/filesystem-routing/+Page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ Vike crawls:
- Skips soft-symlinked (`$ ln -s`) directories (if you use Git).
> If you want to also crawl these then set `VIKE_CRAWL="{git:false}"`.
By default Vike uses Git (if your repository uses Git) to crawl your files. If you set `VIKE_CRAWL="{git:false}"` then Vike uses [`fast-glob`](https://github.com/mrmlnc/fast-glob) instead.
By default Vike uses Git (if your repository uses Git) to crawl your files. If you set `VIKE_CRAWL="{git:false}"` then Vike uses [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) instead.

```bash
# Use fast-glob instead of Git to crawl files
# Use tinyglobby instead of Git to crawl files
$ VIKE_CRAWL="{git:false}" npm run dev
```

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/nextjs/+Page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ With Vike, you have full control over your server and over your deployment strat

## Minimal and self-contained (no deps)

[All dependencies](https://github.com/vikejs/vike/blob/3d042da/vike/package.json#L15-L26) are either shared with Vite (e.g. [`fast-glob`](https://github.com/mrmlnc/fast-glob)) or fully owned (e.g. we own [`@brillout/json-serializer`](https://github.com/brillout/json-serializer)). Adding Vike to your Vite app doesn't add any frivolous dependency.
[All dependencies](https://github.com/vikejs/vike/blob/3d042da/vike/package.json#L15-L26) are either shared with Vite (e.g. [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby)) or fully owned (e.g. we own [`@brillout/json-serializer`](https://github.com/brillout/json-serializer)). Adding Vike to your Vite app doesn't add any frivolous dependency.

We believe Vike hits the sweet spot of being a full-fledged frontend tool while avoiding unnecessary bells and whistles.

Expand Down
61 changes: 41 additions & 20 deletions pnpm-lock.yaml

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
assertUsage
} from '../../../../utils.js'
import path from 'path'
import glob from 'fast-glob'
import { glob } from 'tinyglobby'
import { exec } from 'child_process'
import { promisify } from 'util'
import { isTemporaryBuildFile } from './transpileAndExecuteFile.js'
Expand Down Expand Up @@ -59,10 +59,10 @@ async function crawlPlusFiles(
const filesGit = !isGitCrawlDisabled() && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir))
const filesGitNothingFound = !filesGit || filesGit.length === 0
const filesGlob =
(filesGitNothingFound || debug.isActivated) && (await fastGlob(userRootDir, outDirRelativeFromUserRootDir))
(filesGitNothingFound || debug.isActivated) && (await tinyglobby(userRootDir, outDirRelativeFromUserRootDir))
let files = !filesGitNothingFound
? filesGit
: // Fallback to fast-glob for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
: // Fallback to tinyglobby for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
filesGlob
assert(files)
if (debug.isActivated) assert(deepEqual(filesGlob, filesGit), "Git and glob results aren't matching.")
Expand All @@ -72,7 +72,7 @@ async function crawlPlusFiles(

// Normalize
const plusFiles = files.map((filePath) => {
// Both `$ git-ls files` and fast-glob return posix paths
// Both `$ git-ls files` and tinyglobby return posix paths
assertPosixPath(filePath)
assert(!filePath.startsWith(userRootDir))
const filePathAbsoluteUserRootDir = path.posix.join('/', filePath)
Expand All @@ -83,7 +83,7 @@ async function crawlPlusFiles(
return plusFiles
}

// Same as fastGlob() but using `$ git ls-files`
// Same as tinyglobby() but using `$ git ls-files`
async function gitLsFiles(userRootDir: string, outDirRelativeFromUserRootDir: string | null) {
if (gitIsNotUsable) return null

Expand Down Expand Up @@ -156,13 +156,14 @@ async function gitLsFiles(userRootDir: string, outDirRelativeFromUserRootDir: st

return files
}
// Same as gitLsFiles() but using fast-glob
async function fastGlob(userRootDir: string, outDirRelativeFromUserRootDir: string | null): Promise<string[]> {
// Same as gitLsFiles() but using tinyglobby
async function tinyglobby(userRootDir: string, outDirRelativeFromUserRootDir: string | null): Promise<string[]> {
const pattern = `**/+*.${scriptFileExtensions}`
const options = {
ignore: getIgnoreAsPatterns(outDirRelativeFromUserRootDir),
cwd: userRootDir,
dot: false
dot: false,
expandDirectories: false
}
const files = await glob(pattern, options)
// Make build deterministic, in order to get a stable generated hash for dist/client/assets/entries/entry-client-routing.${hash}.js
Expand Down
6 changes: 3 additions & 3 deletions vike/node/plugin/shared/findPageFiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { findPageFiles }

import glob from 'fast-glob'
import { glob } from 'tinyglobby'
import type { ResolvedConfig } from 'vite'
import { assertWarning, toPosixPath, scriptFileExtensions } from '../utils.js'
import type { FileType } from '../../../shared/getPageFiles/fileTypes.js'
Expand All @@ -13,12 +13,12 @@ async function findPageFiles(config: ResolvedConfig, fileTypes: FileType[], isDe
const timeBase = new Date().getTime()
let pageFiles = await glob(
fileTypes.map((fileType) => `**/*${fileType}.${scriptFileExtensions}`),
{ ignore: ['**/node_modules/**', `${outDirRoot}/**`], cwd, dot: false }
{ ignore: ['**/node_modules/**', `${outDirRoot}/**`], cwd, dot: false, expandDirectories: false }
)
pageFiles = pageFiles.map((p) => '/' + toPosixPath(p))
const time = new Date().getTime() - timeBase
if (isDev) {
// We only warn in dev, because while building it's expected to take a long time as fast-glob is competing for resources with other tasks
// We only warn in dev, because while building it's expected to take a long time as tinyglobby is competing for resources with other tasks
assertWarning(
time < 1.5 * 1000,
`Finding your page files ${pc.cyan(
Expand Down
2 changes: 1 addition & 1 deletion vike/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@
"cac": "^6.0.0",
"es-module-lexer": "^1.0.0",
"esbuild": "^0.19.0 || ^0.20.0 || ^0.21.0 || ^0.22.0 || ^0.23.0 || ^0.24.0",
"fast-glob": "^3.0.0",
"json5": "^2.0.0",
"semver": "^7.0.0",
"source-map-support": "^0.5.0",
"tinyglobby": "^0.2.10",
"vite": ">=5.1.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion vike/utils/findFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { assertPosixPath } from './path.js'

type Filename = 'package.json' | 'vike.config.js' | 'vike.config.ts'

// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the fast-glob fallback).
// We need to be able to crawl the filesystem, regardless of Vike's `$ git ls-files` command call, because we need to fallback if the user didn't setup Git (e.g. we cannot remove the tinyglobby fallback).
function findFile(arg: Filename | Filename[], cwd: string): null | string {
assertPosixPath(cwd)
const filenames = isArray(arg) ? arg : [arg]
Expand Down

0 comments on commit 69f80f4

Please sign in to comment.