@@ -3,7 +3,7 @@ import { buildChecksum, transform } from '../compiler/mod.ts'
3
3
import { colors , createHash , ensureDir , minify , path , walk } from '../deps.ts'
4
4
import { EventEmitter } from '../framework/core/events.ts'
5
5
import type { RouteModule } from '../framework/core/routing.ts'
6
- import { createBlankRouterURL , isModuleURL , Routing , toPagePath } from '../framework/core/routing.ts'
6
+ import { createBlankRouterURL , Routing , toPagePath } from '../framework/core/routing.ts'
7
7
import { defaultReactVersion , minDenoVersion , moduleExts , hashShortLength } from '../shared/constants.ts'
8
8
import { ensureTextFile , existsDirSync , existsFileSync } from '../shared/fs.ts'
9
9
import log from '../shared/log.ts'
@@ -12,7 +12,7 @@ import type { Config, LoaderPlugin, LoaderTransformResult, ModuleOptions, Router
12
12
import { VERSION } from '../version.ts'
13
13
import { Bundler } from './bundler.ts'
14
14
import { defaultConfig , loadConfig } from './config.ts'
15
- import { clearCompilation , computeHash , createHtml , formatBytesWithColor , getAlephPkgUri , getRelativePath , reFullVersion , reHashJs , reHashResolve , toLocalUrl , trimModuleExt } from './helper.ts'
15
+ import { clearCompilation , computeHash , createHtml , formatBytesWithColor , getAlephPkgUri , getRelativePath , isModuleURL , reFullVersion , reHashJs , reHashResolve , toLocalUrl , trimModuleExt } from './helper.ts'
16
16
17
17
/** A module includes the compilation details. */
18
18
export type Module = {
@@ -211,36 +211,7 @@ export class Application implements ServerApplication {
211
211
for await ( const event of w ) {
212
212
for ( const p of event . paths ) {
213
213
const url = util . cleanPath ( util . trimPrefix ( p , this . srcDir ) )
214
- const validated = ( ) => {
215
- // ignore `.aleph` and output directories
216
- if ( url . startsWith ( '/.aleph/' ) || url . startsWith ( this . config . outputDir ) ) {
217
- return false
218
- }
219
-
220
- // is module
221
- if ( isModuleURL ( url ) ) {
222
- if ( url . startsWith ( '/pages/' ) || url . startsWith ( '/api/' ) ) {
223
- return true
224
- }
225
- switch ( trimModuleExt ( url ) ) {
226
- case '/404' :
227
- case '/app' :
228
- return true
229
- }
230
- }
231
-
232
- // is dep
233
- for ( const { deps } of this . #modules. values ( ) ) {
234
- if ( deps . some ( dep => dep . url === url ) ) {
235
- return true
236
- }
237
- }
238
-
239
- // is loaded by plugin
240
- return this . config . plugins . some ( p => p . type === 'loader' && p . test . test ( url ) )
241
- }
242
-
243
- if ( validated ( ) ) {
214
+ if ( this . isScopedModule ( url ) ) {
244
215
util . debounceX ( url , ( ) => {
245
216
if ( existsFileSync ( p ) ) {
246
217
let type = 'modify'
@@ -298,6 +269,34 @@ export class Application implements ServerApplication {
298
269
}
299
270
}
300
271
272
+ private isScopedModule ( url : string ) {
273
+ // is module
274
+ if ( isModuleURL ( url ) ) {
275
+ if ( url . startsWith ( '/pages/' ) || url . startsWith ( '/api/' ) ) {
276
+ return true
277
+ }
278
+ switch ( trimModuleExt ( url ) ) {
279
+ case '/404' :
280
+ case '/app' :
281
+ return true
282
+ }
283
+ }
284
+
285
+ // is page module by plugin
286
+ if ( this . config . plugins . some ( p => p . type === 'loader' && p . test . test ( url ) && p . allowPage ) ) {
287
+ return true
288
+ }
289
+
290
+ // is dep
291
+ for ( const { deps } of this . #modules. values ( ) ) {
292
+ if ( deps . some ( dep => dep . url === url ) ) {
293
+ return true
294
+ }
295
+ }
296
+
297
+ return false
298
+ }
299
+
301
300
get isDev ( ) {
302
301
return this . mode === 'development'
303
302
}
@@ -472,12 +471,7 @@ export class Application implements ServerApplication {
472
471
[ '/app' , '/404' ] . includes ( trimModuleExt ( url ) )
473
472
}
474
473
}
475
- for ( const plugin of this . config . plugins ) {
476
- if ( plugin . type === 'loader' && plugin . test . test ( url ) ) {
477
- return plugin . allowPage || plugin . acceptHMR
478
- }
479
- }
480
- return false
474
+ return this . config . plugins . some ( p => p . type === 'loader' && p . test . test ( url ) && ( p . allowPage || p . acceptHMR ) )
481
475
}
482
476
483
477
/** inject HMR code */
0 commit comments