1
- import { once } from 'events'
2
1
import os from 'os'
3
2
import fs from 'fs'
4
3
import process from 'process'
@@ -7,10 +6,7 @@ import { format, inspect } from 'util'
7
6
import type { NetlifyAPI } from '@netlify/api'
8
7
import { getGlobalConfigStore } from '@netlify/dev-utils'
9
8
import { Chalk } from 'chalk'
10
- import chokidar from 'chokidar'
11
- import decache from 'decache'
12
9
import WSL from 'is-wsl'
13
- import debounce from 'lodash/debounce.js'
14
10
import terminalLink from 'terminal-link'
15
11
16
12
import { startSpinner } from '../lib/spinner.js'
@@ -235,79 +231,13 @@ export const normalizeConfig = (config: CachedConfig['config']): NormalizedCache
235
231
return publishOrigin === 'default' ? { ...config , build } : config
236
232
}
237
233
238
- const DEBOUNCE_WAIT = 100
239
-
240
- interface WatchDebouncedOptions {
241
- depth ?: number
242
- ignored ?: ( string | RegExp ) [ ]
243
- onAdd ?: ( paths : string [ ] ) => void
244
- onChange ?: ( paths : string [ ] ) => void
245
- onUnlink ?: ( paths : string [ ] ) => void
246
- }
247
-
248
- /**
249
- * Adds a file watcher to a path or set of paths and debounces the events.
250
- */
251
- export const watchDebounced = async (
252
- target : string | string [ ] ,
253
- { depth, ignored = [ ] , onAdd = noOp , onChange = noOp , onUnlink = noOp } : WatchDebouncedOptions ,
254
- ) => {
255
- const baseIgnores = [ / \/ ( n o d e _ m o d u l e s | .g i t ) \/ / ]
256
- const watcher = chokidar . watch ( target , { depth, ignored : [ ...baseIgnores , ...ignored ] , ignoreInitial : true } )
257
-
258
- await once ( watcher , 'ready' )
259
-
260
- let onChangeQueue : string [ ] = [ ]
261
- let onAddQueue : string [ ] = [ ]
262
- let onUnlinkQueue : string [ ] = [ ]
263
-
264
- const debouncedOnChange = debounce ( ( ) => {
265
- onChange ( onChangeQueue )
266
- onChangeQueue = [ ]
267
- } , DEBOUNCE_WAIT )
268
- const debouncedOnAdd = debounce ( ( ) => {
269
- onAdd ( onAddQueue )
270
- onAddQueue = [ ]
271
- } , DEBOUNCE_WAIT )
272
- const debouncedOnUnlink = debounce ( ( ) => {
273
- onUnlink ( onUnlinkQueue )
274
- onUnlinkQueue = [ ]
275
- } , DEBOUNCE_WAIT )
276
-
277
- watcher
278
- . on ( 'change' , ( path ) => {
279
- // @ts -expect-error
280
- decache ( path )
281
- onChangeQueue . push ( path )
282
- debouncedOnChange ( )
283
- } )
284
- . on ( 'unlink' , ( path ) => {
285
- // @ts -expect-error
286
- decache ( path )
287
- onUnlinkQueue . push ( path )
288
- debouncedOnUnlink ( )
289
- } )
290
- . on ( 'add' , ( path ) => {
291
- // @ts -expect-error
292
- decache ( path )
293
- onAddQueue . push ( path )
294
- debouncedOnAdd ( )
295
- } )
296
-
297
- return watcher
298
- }
299
-
300
234
export const getTerminalLink = ( text : string , url : string ) : string =>
301
235
terminalLink ( text , url , { fallback : ( ) => `${ text } (${ url } )` } )
302
236
303
237
export const isNodeError = ( err : unknown ) : err is NodeJS . ErrnoException => err instanceof Error
304
238
305
239
export const nonNullable = < T > ( value : T ) : value is NonNullable < T > => value !== null && value !== undefined
306
240
307
- export const noOp = ( ) => {
308
- // no-op
309
- }
310
-
311
241
export interface APIError extends Error {
312
242
status : number
313
243
message : string
0 commit comments