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 fs from 'fs-extra'
import path from 'node:path' import path from 'node:path'
import c from 'picocolors' import c from 'picocolors'
import { glob } from 'tinyglobby'
import { import {
createLogger, createLogger,
loadConfigFromFile, loadConfigFromFile,
@ -24,6 +23,7 @@ import {
type SiteData type SiteData
} from './shared' } from './shared'
import type { RawConfigExports, SiteConfig, UserConfig } from './siteConfig' import type { RawConfigExports, SiteConfig, UserConfig } from './siteConfig'
import { glob } from './utils/glob'
export { resolvePages } from './plugins/dynamicRoutesPlugin' export { resolvePages } from './plugins/dynamicRoutesPlugin'
export { resolveSiteDataByRoute } from './shared' 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), cwd: path.resolve(root, srcDir),
dot: false, // conveniently ignores .vitepress/* ignore: srcExclude
ignore: ['**/node_modules/**', ...srcExclude],
expandDirectories: false
}) })
const deps: string[][] = [] const deps: string[][] = []

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

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

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

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

Loading…
Cancel
Save