Skip to content

Commit

Permalink
fix chokidar glob
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoattal committed Nov 26, 2024
1 parent b50cc0e commit b71e599
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 171 deletions.
1 change: 1 addition & 0 deletions packages/histoire/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"markdown-it-attrs": "^4.2.0",
"markdown-it-emoji": "^3.0.0",
"micromatch": "^4.0.8",
"minimatch": "^10.0.1",
"mrmime": "^2.0.0",
"pathe": "^1.1.2",
"picocolors": "^1.1.1",
Expand Down
36 changes: 18 additions & 18 deletions packages/histoire/src/node/build.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { performance } from 'node:perf_hooks'
import { join } from 'pathe'
import type {
BuildEndCallback,
ChangeViteConfigCallback,
PreviewStoryCallback,
} from '@histoire/shared'
import type { RollupOutput } from 'rollup'
import type {
InlineConfig as ViteInlineConfig,
Plugin as VitePlugin,
} from 'vite'
import type { Context } from './context.js'
import { performance } from 'node:perf_hooks'
import fs from 'fs-extra'
import { lookup as lookupMime } from 'mrmime'
import { join } from 'pathe'
import pc from 'picocolors'
import {
createServer as createViteServer,
mergeConfig as mergeViteConfig,
build as viteBuild,
} from 'vite'
import fs from 'fs-extra'
import { lookup as lookupMime } from 'mrmime'
import pc from 'picocolors'
import type {
BuildEndCallback,
ChangeViteConfigCallback,
PreviewStoryCallback,
} from '@histoire/shared'
import type { RollupOutput } from 'rollup'
import { APP_PATH } from './alias.js'
import type { Context } from './context.js'
import { getViteConfigWithPlugins } from './vite.js'
import { findAllStories } from './stories.js'
import { useCollectStories } from './collect/index.js'
import { BuildPluginApi } from './plugin.js'
import { getSerializedStoryData } from './build-serialize.js'
import { useCollectStories } from './collect'
import { useModuleLoader } from './load.js'
import { startPreview } from './preview.js'
import { createMarkdownFilesWatcher } from './markdown.js'
import { getSerializedStoryData } from './build-serialize.js'
import { BuildPluginApi } from './plugin.js'
import { startPreview } from './preview.js'
import { findAllStories } from './stories.js'
import { getViteConfigWithPlugins } from './vite.js'

const PRELOAD_MODULES = [
'vendor',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Plugin, PluginApiBase } from '@histoire/shared'
import { getInjectedImport } from '../util/vendors.js'
import { findUp } from '../util/find-up.js'
import { getInjectedImport } from '../util/vendors.js'

export interface TailwindTokensOptions {
configFile?: string
Expand Down
20 changes: 10 additions & 10 deletions packages/histoire/src/node/collect/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { MessageChannel } from 'node:worker_threads'
import { cpus } from 'node:os'
import type { ServerStoryFile } from '@histoire/shared'
import type { ViteDevServer } from 'vite'
import { ViteNodeServer } from 'vite-node/server'
import type { FetchFunction, ResolveIdFunction } from 'vite-node'
import { relative } from 'pathe'
import pc from 'picocolors'
import type { Context } from '../context.js'
import type { Payload, ReturnData } from './worker.js'
import { cpus } from 'node:os'
import { MessageChannel } from 'node:worker_threads'
import Tinypool from '@akryum/tinypool'
import { createBirpc } from 'birpc'
import type { ServerStoryFile } from '@histoire/shared'
import { relative } from 'pathe'
import pc from 'picocolors'
import { ViteNodeServer } from 'vite-node/server'
import { createPath } from '../tree.js'
import type { Context } from '../context.js'
import { slash } from '../util/fs.js'
import type { Payload, ReturnData } from './worker.js'

export interface UseCollectStoriesOptions {
server: ViteDevServer
Expand All @@ -27,8 +27,8 @@ export function useCollectStories(options: UseCollectStoriesOptions, ctx: Contex
inline: [
/histoire\/dist/,
/histoire\/client/,
/@histoire\/[\w\d-]+\/dist/,
/histoire-[\w\d-]+\/dist/,
/@histoire\/[\w-]+\/dist/,
/histoire-[\w-]+\/dist/,
/@vue\/devtools-api/,
/vuetify/,
// @TODO temporary fix for https://github.com/histoire-dev/histoire/issues/409
Expand Down
3 changes: 0 additions & 3 deletions packages/histoire/src/node/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ export async function buildCommand(options: BuildOptions) {
mode: 'build',
})
await build(ctx)

// @TODO remove when https://github.com/vitejs/vite/issues/6815 is fixed
process.exit(0)
}
6 changes: 3 additions & 3 deletions packages/histoire/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ export async function loadConfigFile(configFile: string): Promise<Partial<Histoi
const jiti = createJiti(__filename, {
moduleCache: false,
})
const result = await jiti.import(configFile)
if (!result.default) {
const result = await jiti.import(configFile, { default: true }) as Partial<HistoireConfig>
if (!result) {
throw new Error(`Expected default export in ${configFile}`)
}
return result.default
return result
}
catch (e) {
console.error(pc.red(`Error while loading ${configFile}`))
Expand Down
4 changes: 2 additions & 2 deletions packages/histoire/src/node/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ResolvedConfig } from 'vite'
import { resolveConfig as resolveViteConfig } from 'vite'
import type {
ConfigMode,
FinalSupportPlugin,
Expand All @@ -8,6 +6,8 @@ import type {
ServerMarkdownFile,
ServerStoryFile,
} from '@histoire/shared'
import type { ResolvedConfig } from 'vite'
import { resolveConfig as resolveViteConfig } from 'vite'
import { processConfig, resolveConfig } from './config.js'
import { mergeHistoireViteConfig } from './vite.js'

Expand Down
16 changes: 8 additions & 8 deletions packages/histoire/src/node/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { performance } from 'node:perf_hooks'
import { createServer as createViteServer } from 'vite'
import pc from 'picocolors'
import type { ServerStoryFile } from '@histoire/shared'
import type { Context } from './context.js'
import { getViteConfigWithPlugins } from './vite.js'
import * as VirtualFiles from './virtual/index.js'
import { onStoryChange, onStoryListChange, watchStories } from './stories.js'
import { performance } from 'node:perf_hooks'
import pc from 'picocolors'
import { createServer as createViteServer } from 'vite'
import { useCollectStories } from './collect/index.js'
import { DevEventPluginApi, DevPluginApi } from './plugin.js'
import { useModuleLoader } from './load.js'
import { wrapLogError } from './util/log.js'
import { createMarkdownFilesWatcher, onMarkdownListChange } from './markdown.js'
import { DevEventPluginApi, DevPluginApi } from './plugin.js'
import { onStoryChange, onStoryListChange, watchStories } from './stories.js'
import { wrapLogError } from './util/log.js'
import * as VirtualFiles from './virtual/index.js'
import { getViteConfigWithPlugins } from './vite.js'

export interface CreateServerOptions {
port?: number
Expand Down
15 changes: 13 additions & 2 deletions packages/histoire/src/node/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { kebabCase } from 'change-case'
import chokidar from 'chokidar'
import { globby } from 'globby'
import micromatch from 'micromatch'
import { minimatch } from 'minimatch'
import { basename, resolve } from 'pathe'

type StoryChangeHandler = (file?: ServerStoryFile) => unknown
Expand Down Expand Up @@ -44,9 +45,19 @@ let context: Context

export async function watchStories(newContext: Context) {
context = newContext
const watcher = chokidar.watch(context.config.storyMatch, {

const watcher = chokidar.watch('.', {
ignored: (path, stats) => {
if (context.config.storyIgnored.some(pattern => minimatch(path, pattern))) {
return true
}
if (context.config.storyMatch.some(pattern => minimatch(path, pattern))) {
return false
}

return stats?.isFile()
},
cwd: context.root,
ignored: context.config.storyIgnored,
})

watcher
Expand Down
Loading

0 comments on commit b71e599

Please sign in to comment.