@@ -18,6 +18,7 @@ const ignore = ignoreExport.default
1818
1919/**
2020 * @import { TopBunOpts, Results } from './lib/builder.js'
21+ * @import { FSWatcher, Stats } from 'node:fs'
2122*/
2223
2324/**
@@ -53,7 +54,7 @@ export class TopBun {
5354 /** @type {string } */ #src = ''
5455 /** @type {string } */ #dest = ''
5556 /** @type {TopBunOpts } */ opts = { }
56- /** @type {chokidar. FSWatcher? } */ #watcher = null
57+ /** @type {FSWatcher? } */ #watcher = null
5758 /** @type {any? } */ #cpxWatcher = null
5859 /** @type {browserSync.BrowserSyncInstance? } */ #browserSyncServer = null
5960
@@ -63,7 +64,7 @@ export class TopBun {
6364 * @param {string } dest - The dest path of the page build
6465 * @param {TopBunOpts } [opts] - The options for the site build
6566 */
66- constructor ( src , dest , opts = { } ) {
67+ constructor ( src , dest , opts = { } ) {
6768 assert ( src , 'src is a required argument' )
6869 assert ( dest , 'dest is a required argument' )
6970
@@ -77,11 +78,11 @@ export class TopBun {
7778 this . opts = opts
7879 }
7980
80- get watching ( ) {
81+ get watching ( ) {
8182 return Boolean ( this . #watcher)
8283 }
8384
84- build ( ) {
85+ build ( ) {
8586 return builder ( this . #src, this . #dest, { static : true , ...this . opts } )
8687 }
8788
@@ -91,11 +92,11 @@ export class TopBun {
9192 * @param {boolean } params.serve
9293 * @return {Promise<Results> }
9394 */
94- async watch ( {
95+ async watch ( {
9596 serve,
9697 } = {
97- serve : true ,
98- } ) {
98+ serve : true ,
99+ } ) {
99100 if ( this . watching ) throw new Error ( 'Already watching.' )
100101
101102 /** @type Results */
@@ -140,8 +141,21 @@ export class TopBun {
140141
141142 const anymatch = ( /** @type {string } */ name ) => ig . ignores ( relname ( this . #src, name ) )
142143
143- const watcher = chokidar . watch ( `${ this . #src} /**/*.+(js|css|html|md)` , {
144- ignored : anymatch ,
144+ const watcher = chokidar . watch ( this . #src, {
145+ /**
146+ * Determines whether a given path should be ignored by the watcher.
147+ *
148+ * @param {string } filePath - The path to the file or directory.
149+ * @param {Stats } [stats] - The stats object for the path (may be undefined).
150+ * @returns {boolean } - Returns true if the path should be ignored.
151+ */
152+ ignored : ( filePath , stats ) => {
153+ // Combine your existing 'anymatch' function with the new extension check
154+ return (
155+ anymatch ( filePath ) ||
156+ Boolean ( ( stats ?. isFile ( ) && ! / \. ( j s | c s s | h t m l | m d ) $ / . test ( filePath ) ) )
157+ )
158+ } ,
145159 persistent : true ,
146160 } )
147161
@@ -174,7 +188,7 @@ export class TopBun {
174188 return report
175189 }
176190
177- async stopWatching ( ) {
191+ async stopWatching ( ) {
178192 if ( ( ! this . watching || ! this . #cpxWatcher) ) throw new Error ( 'Not watching' )
179193 if ( this . #watcher) await this . #watcher. close ( )
180194 this . #cpxWatcher. close ( )
@@ -191,15 +205,15 @@ export class TopBun {
191205 * @param {string } name The name string
192206 * @return {string } the relname
193207 */
194- function relname ( root , name ) {
208+ function relname ( root , name ) {
195209 return root === name ? basename ( name ) : relative ( root , name )
196210}
197211
198212/**
199213 * An error logger
200214 * @param {Error | AggregateError | any } err The error to log
201215 */
202- function errorLogger ( err ) {
216+ function errorLogger ( err ) {
203217 if ( ! ( err instanceof Error || err instanceof AggregateError ) ) throw new Error ( 'Non-error thrown' , { cause : err } )
204218 if ( 'results' in err ) delete err . results
205219 console . error ( inspect ( err , { depth : 999 , colors : true } ) )
@@ -212,7 +226,7 @@ function errorLogger (err) {
212226 * An build logger
213227 * @param {Results } results
214228 */
215- function buildLogger ( results ) {
229+ function buildLogger ( results ) {
216230 if ( results ?. warnings ?. length > 0 ) {
217231 console . log (
218232 '\nThere were build warnings:\n'
0 commit comments