Skip to content

Commit

Permalink
use picomatch
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Feb 26, 2025
1 parent 0bf9da9 commit 3731ed6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
11 changes: 11 additions & 0 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 @@ -25,10 +25,32 @@ import { promisify } from 'util'
import { isTemporaryBuildFile } from './transpileAndExecuteFile.js'
import { getEnvVarObject } from '../../../../shared/getEnvVarObject.js'
import pc from '@brillout/picocolors'
import picomatch from 'picomatch'
const execA = promisify(exec)

const debug = createDebugger('vike:crawl')

const ignorePatterns = [
'**/node_modules/**',
'**/ejected/**',
// Allow:
// ```
// +Page.js
// +Page.telefunc.js
// ```
'**/*.telefunc.*',
// https://github.com/vikejs/vike/discussions/2222
'**/*.generated.*'
]
const ignoreMatchers = ignorePatterns.map((p) =>
picomatch(p, {
// We must pass the same settings than tinyglobby
// https://github.com/SuperchupuDev/tinyglobby/blob/fcfb08a36c3b4d48d5488c21000c95a956d9797c/src/index.ts#L191-L194
dot: false,
nocase: false
})
)

assertIsNotProductionRuntime()
assertIsSingleModuleInstance('getVikeConfig/crawlPlusFiles.ts')
let gitIsNotUsable = false
Expand Down Expand Up @@ -84,9 +106,6 @@ async function gitLsFiles(userRootDir: string) {
// https://stackoverflow.com/questions/15884180/how-do-i-override-git-configuration-options-by-command-line-parameters/15884261#15884261
const preserveUTF8 = '-c core.quotepath=off'

const ignoreAsPatterns = getIgnoreAsPatterns()
const ignoreAsFilterFn = getIgnoreAsFilterFn()

const cmd = [
'git',
preserveUTF8,
Expand All @@ -98,7 +117,7 @@ async function gitLsFiles(userRootDir: string) {
// Performance gain is non-negligible.
// - https://github.com/vikejs/vike/pull/1688#issuecomment-2166206648
// - When node_modules/ is untracked the performance gain could be significant?
...ignoreAsPatterns.map((pattern) => `--exclude="${pattern}"`),
...ignorePatterns.map((pattern) => `--exclude="${pattern}"`),

// --others --exclude-standard => list untracked files (--others) while using .gitignore (--exclude-standard)
// --cached => list tracked files
Expand Down Expand Up @@ -134,7 +153,7 @@ async function gitLsFiles(userRootDir: string) {
if (!path.posix.basename(filePath).startsWith('+')) continue

// We have to repeat the same exclusion logic here because the option --exclude of `$ git ls-files` only applies to untracked files. (We use --exclude only to speed up the `$ git ls-files` command.)
if (!ignoreAsFilterFn(filePath)) continue
if (ignoreMatchers.some((m) => m(filePath))) continue

// JavaScript file?
if (!isScriptFile(filePath)) continue
Expand All @@ -151,7 +170,7 @@ async function gitLsFiles(userRootDir: string) {
async function tinyglobby(userRootDir: string): Promise<string[]> {
const pattern = `**/+*.${scriptFileExtensions}`
const options = {
ignore: getIgnoreAsPatterns(),
ignore: ignorePatterns,
cwd: userRootDir,
dot: false
}
Expand All @@ -167,31 +186,6 @@ async function tinyglobby(userRootDir: string): Promise<string[]> {
return files
}

// Same as getIgnoreAsFilterFn() but as glob pattern
function getIgnoreAsPatterns(): string[] {
const ignoreAsPatterns = [
'**/node_modules/**',
'**/ejected/**',
// Allow:
// ```
// +Page.js
// +Page.telefunc.js
// ```
'**/*.telefunc.*',
// https://github.com/vikejs/vike/discussions/2222
'**/*.generated.*'
]
return ignoreAsPatterns
}
// Same as getIgnoreAsPatterns() but for Array.filter()
function getIgnoreAsFilterFn(): (file: string) => boolean {
return (file: string) =>
!file.includes('node_modules/') &&
!file.includes('ejected/') &&
!file.includes('.telefunc.') &&
!file.includes('.generated.')
}

// Whether Git is installed and whether we can use it
async function isGitNotUsable(userRootDir: string) {
// Check Git version
Expand Down
2 changes: 2 additions & 0 deletions vike/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"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",
"json5": "^2.0.0",
"picomatch": "^4.0.2",
"semver": "^7.0.0",
"source-map-support": "^0.5.0",
"tinyglobby": "^0.2.10",
Expand Down Expand Up @@ -246,6 +247,7 @@
"@types/estree": "^1.0.5",
"@types/jest": "^29.5.11",
"@types/node": "^20.10.5",
"@types/picomatch": "^3.0.2",
"@types/resolve": "^1.20.6",
"@types/semver": "^7.5.8",
"@types/source-map-support": "^0.5.10",
Expand Down

0 comments on commit 3731ed6

Please sign in to comment.