pull/4808/head
Divyansh Singh 3 months ago
parent b25b358805
commit 067d89083b

@ -2,7 +2,6 @@ import _debug from 'debug'
import fs from 'fs-extra'
import path from 'node:path'
import c from 'picocolors'
import { glob } from 'tinyglobby'
import {
createLogger,
loadConfigFromFile,
@ -24,6 +23,7 @@ import {
type SiteData
} from './shared'
import type { RawConfigExports, SiteConfig, UserConfig } from './siteConfig'
import { glob } from './utils/glob'
export { resolvePages } from './plugins/dynamicRoutesPlugin'
export { resolveSiteDataByRoute } from './shared'
@ -190,11 +190,9 @@ async function gatherAdditionalConfig(
) {
//
const candidates = await glob(additionalConfigGlob, {
const candidates = await glob([additionalConfigGlob], {
cwd: path.resolve(root, srcDir),
dot: false, // conveniently ignores .vitepress/*
ignore: ['**/node_modules/**', ...srcExclude],
expandDirectories: false
ignore: srcExclude
})
const deps: string[][] = []

@ -6,11 +6,7 @@ import type { SiteConfig } from './config'
import { createMarkdownRenderer } from './markdown/markdown'
import type { LoaderModule } from './plugins/staticDataPlugin'
import type { Awaitable } from './shared'
import {
getWatchedFiles,
normalizeWatchPatterns,
type GlobOptions
} from './utils/glob'
import { glob, normalizeWatchPatterns, type GlobOptions } from './utils/glob'
export interface ContentOptions<T = ContentData[]> {
/**
@ -99,7 +95,7 @@ export function createContentLoader<T = ContentData[]>(
async load(files?: string[]) {
// the loader is being called directly, do a fresh glob
if (!files) files = await getWatchedFiles(watch, options.globOptions)
if (!files) files = await glob(watch, options.globOptions)
const md = await createMarkdownRenderer(
config.srcDir,

@ -11,11 +11,7 @@ import {
} from 'vite'
import type { Awaitable } from '../shared'
import { type SiteConfig, type UserConfig } from '../siteConfig'
import {
getWatchedFiles,
normalizeWatchPatterns,
type GlobOptions
} from '../utils/glob'
import { glob, normalizeWatchPatterns, type GlobOptions } from '../utils/glob'
import { ModuleGraph } from '../utils/moduleGraph'
import { resolveRewrites } from './rewritesPlugin'
@ -84,7 +80,7 @@ export async function resolvePages(
routeModuleCache.clear()
}
const allMarkdownFiles = await getWatchedFiles(['**/*.md'], {
const allMarkdownFiles = await glob(['**/*.md'], {
cwd: srcDir,
ignore: userConfig.srcExclude
})
@ -315,7 +311,7 @@ async function resolveDynamicRoutes(
let pathsData: UserRouteConfig[]
if (typeof loader === 'function') {
const watchedFiles = await getWatchedFiles(watch, options.globOptions)
const watchedFiles = await glob(watch, options.globOptions)
pathsData = await loader(watchedFiles)
} else {
pathsData = loader

@ -8,11 +8,7 @@ import {
type ViteDevServer
} from 'vite'
import type { Awaitable } from '../shared'
import {
getWatchedFiles,
normalizeWatchPatterns,
type GlobOptions
} from '../utils/glob'
import { glob, normalizeWatchPatterns, type GlobOptions } from '../utils/glob'
const loaderMatch = /\.data\.m?(j|t)s($|\?)/
@ -101,7 +97,7 @@ export const staticDataPlugin: Plugin = {
}
// load the data
const watchedFiles = await getWatchedFiles(watch, options.globOptions)
const watchedFiles = await glob(watch, options.globOptions)
const data = await load(watchedFiles)
// record loader module for HMR

@ -1,5 +1,5 @@
import path from 'node:path'
import { glob } from 'tinyglobby'
import { glob as _glob } from 'tinyglobby'
import { normalizePath } from 'vite'
export interface GlobOptions {
@ -20,13 +20,13 @@ export function normalizeWatchPatterns(
)
}
export async function getWatchedFiles(
export async function glob(
patterns: string[] | undefined,
options?: GlobOptions
): Promise<string[]> {
if (!patterns?.length) return []
return (
await glob(patterns, {
await _glob(patterns, {
ignore: ['**/node_modules/**', '**/dist/**', ...(options?.ignore || [])],
expandDirectories: false,
...options

Loading…
Cancel
Save