Skip to content

Commit

Permalink
chore: remove chokidar options and add TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 20, 2024
1 parent 7d2b36e commit f285485
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 8 additions & 5 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import type {
OutputOptions,
RenderedChunk,
RolldownPlugin,
RolldownWatcher,
RollupBuild,
RollupError,
RollupLog,
RollupOptions,
RollupOutput,
watch as rolldownWatch,
// WatcherOptions,
} from 'rolldown'
import {
Expand Down Expand Up @@ -68,6 +68,8 @@ import { buildLoadFallbackPlugin } from './plugins/loadFallback'
import { findNearestPackageData } from './packages'
import type { PackageCache } from './packages'
import {
type RolldownWatcherOptions as WatcherOptions,
convertToNotifyOptions,
getResolvedOutDirs,
resolveChokidarOptions,
resolveEmptyOutDir,
Expand All @@ -83,8 +85,7 @@ import {
import type { MinimalPluginContext, Plugin, PluginContext } from './plugin'
import type { RollupPluginHooks } from './typeUtils'

export type RollupWatcher = Awaited<ReturnType<typeof rolldownWatch>>
type WatcherOptions = { _: never }
type RollupWatcher = RolldownWatcher

export interface BuildEnvironmentOptions {
/**
Expand Down Expand Up @@ -823,7 +824,7 @@ async function buildEnvironment(
logger.info(colors.cyan(`\nwatching for file changes...`))

const resolvedChokidarOptions = resolveChokidarOptions(
{}, // options.watch.chokidar,
options.watch.chokidar,
resolvedOutDirs,
emptyOutDir,
environment.config.cacheDir,
Expand All @@ -835,7 +836,9 @@ async function buildEnvironment(
output: normalizedOutputs[0], // normalizedOutputs,
watch: {
...options.watch,
chokidar: resolvedChokidarOptions,
// TODO: convert chokidar options more precisely
// TODO: support more chokidar options
notify: convertToNotifyOptions(resolvedChokidarOptions),
},
})

Expand Down
16 changes: 15 additions & 1 deletion packages/vite/src/node/watch.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { EventEmitter } from 'node:events'
import path from 'node:path'
import type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
import type { OutputOptions } from 'rolldown'
import type { InputOptions, OutputOptions } from 'rolldown'
import colors from 'picocolors'
import { escapePath } from 'tinyglobby'
import { withTrailingSlash } from '../shared/utils'
import { arraify, normalizePath } from './utils'
import type { Logger } from './logger'

export type RolldownWatcherOptions = Exclude<
InputOptions['watch'],
false | undefined
>

export function getResolvedOutDirs(
root: string,
outDir: string,
Expand Down Expand Up @@ -78,6 +83,15 @@ export function resolveChokidarOptions(
return resolvedWatchOptions
}

export function convertToNotifyOptions(
options: WatchOptions | undefined,
): RolldownWatcherOptions['notify'] {
if (!options) return
return {
pollInterval: options.interval,
}
}

class NoopWatcher extends EventEmitter implements FSWatcher {
constructor(public options: WatchOptions) {
super()
Expand Down

0 comments on commit f285485

Please sign in to comment.