@@ -6,7 +6,7 @@ import { createRouter } from './router.ts'
6
6
import { colors , ensureDir , path , Sha1 , walk } from './std.ts'
7
7
import { compile } from './tsc/compile.ts'
8
8
import type { APIHandle , Config , Location , RouterURL } from './types.ts'
9
- import util , { existsDirSync , existsFileSync , hashShort , reHashJs , reHttp , reModuleExt , reStyleModuleExt } from './util.ts'
9
+ import util , { existsDirSync , existsFileSync , hashShort , reHashJs , reHttp , reMDExt , reModuleExt , reStyleModuleExt } from './util.ts'
10
10
import { cleanCSS , Document , less } from './vendor/mod.ts'
11
11
import { version } from './version.ts'
12
12
@@ -31,10 +31,13 @@ interface RenderResult {
31
31
}
32
32
33
33
export interface AlephEnv {
34
- appRoot : string
35
- buildID : string
36
- config : Config
37
- mode : 'development' | 'production'
34
+ version : string
35
+ build : {
36
+ mode : 'development' | 'production'
37
+ buildID : string
38
+ appRoot : string
39
+ config : Config
40
+ }
38
41
}
39
42
40
43
export default class Project {
@@ -395,10 +398,13 @@ export default class Project {
395
398
396
399
Object . assign ( globalThis , {
397
400
ALEPH_ENV : {
398
- appRoot : this . appRoot ,
399
- buildID : this . buildID ,
400
- config : this . config ,
401
- mode : this . mode ,
401
+ version,
402
+ build : {
403
+ appRoot : this . appRoot ,
404
+ buildID : this . buildID ,
405
+ config : this . config ,
406
+ mode : this . mode ,
407
+ }
402
408
} as AlephEnv ,
403
409
document : new Document ( ) ,
404
410
innerWidth : 1920 ,
@@ -468,39 +474,40 @@ export default class Project {
468
474
log . info ( 'Start watching code changes...' )
469
475
for await ( const event of w ) {
470
476
for ( const p of event . paths ) {
471
- const path = util . trimPrefix ( util . trimPrefix ( p , this . appRoot ) , '/' )
477
+ const path = '/' + util . trimPrefix ( util . trimPrefix ( p , this . appRoot ) , '/' )
472
478
const validated = ( ( ) => {
473
- if ( ! reModuleExt . test ( path ) && ! reStyleModuleExt . test ( path ) ) {
479
+ if ( ! reModuleExt . test ( path ) && ! reStyleModuleExt . test ( path ) && ! reMDExt . test ( path ) ) {
474
480
return false
475
481
}
476
482
// ignore '.aleph' and output directories
477
- if ( path . startsWith ( '.aleph/' ) || path . startsWith ( this . config . outputDir . slice ( 1 ) ) ) {
483
+ if ( path . startsWith ( '/ .aleph/' ) || path . startsWith ( this . config . outputDir ) ) {
478
484
return false
479
485
}
480
- const moduleID = '/' + path . replace ( reModuleExt , '.js' )
481
- switch ( moduleID ) {
482
- case '/404.js' :
483
- case '/app.js' :
484
- case '/data.js' : {
485
- return true
486
- }
487
- default : {
488
- if ( ( moduleID . startsWith ( '/pages/' ) || moduleID . startsWith ( '/api/' ) ) && moduleID . endsWith ( '.js' ) ) {
486
+ if ( reModuleExt . test ( path ) ) {
487
+ switch ( path . replace ( reModuleExt , '' ) ) {
488
+ case '/404' :
489
+ case '/app' :
490
+ case '/data' : {
489
491
return true
490
492
}
491
- let isDep = false
492
- for ( const { deps } of this . #modules. values ( ) ) {
493
- if ( deps . findIndex ( dep => dep . url === '/' + path ) > - 1 ) {
494
- isDep = true
495
- break
493
+ default : {
494
+ if ( path . startsWith ( '/pages/' ) || path . startsWith ( '/api/' ) ) {
495
+ return true
496
496
}
497
497
}
498
- return isDep
499
498
}
500
499
}
500
+ let isDep = false
501
+ for ( const { deps } of this . #modules. values ( ) ) {
502
+ if ( deps . findIndex ( dep => dep . url === path ) > - 1 ) {
503
+ isDep = true
504
+ break
505
+ }
506
+ }
507
+ return isDep
501
508
} ) ( )
502
509
if ( validated ) {
503
- const moduleID = '/' + path . replace ( reModuleExt , '.js' )
510
+ const moduleID = path . replace ( reModuleExt , '.js' )
504
511
util . debounceX ( moduleID , ( ) => {
505
512
const removed = ! existsFileSync ( p )
506
513
const cleanup = ( ) => {
@@ -525,8 +532,8 @@ export default class Project {
525
532
if ( ! this . #modules. has ( moduleID ) ) {
526
533
type = 'add'
527
534
}
528
- log . info ( type , '/' + path )
529
- this . _compile ( '/' + path , { forceCompile : true } ) . then ( ( { hash } ) => {
535
+ log . info ( type , path )
536
+ this . _compile ( path , { forceCompile : true } ) . then ( ( { hash } ) => {
530
537
const hmrable = this . isHMRable ( moduleID )
531
538
if ( hmrable ) {
532
539
if ( type === 'add' ) {
@@ -536,7 +543,7 @@ export default class Project {
536
543
}
537
544
}
538
545
cleanup ( )
539
- this . _updateDependency ( '/' + path , hash , mod => {
546
+ this . _updateDependency ( path , hash , mod => {
540
547
if ( ! hmrable && this . isHMRable ( mod . id ) ) {
541
548
this . #fsWatchListeners. forEach ( e => e . emit ( mod . id , 'modify' , mod . hash ) )
542
549
}
@@ -545,15 +552,15 @@ export default class Project {
545
552
}
546
553
} )
547
554
} ) . catch ( err => {
548
- log . error ( `compile(/ ${ path } ):` , err . message )
555
+ log . error ( `compile(${ path } ):` , err . message )
549
556
} )
550
557
} else if ( this . #modules. has ( moduleID ) ) {
551
558
this . #modules. delete ( moduleID )
552
559
cleanup ( )
553
560
if ( this . isHMRable ( moduleID ) ) {
554
561
this . #fsWatchListeners. forEach ( e => e . emit ( 'remove' , moduleID ) )
555
562
}
556
- log . info ( 'remove' , '/' + path )
563
+ log . info ( 'remove' , path )
557
564
}
558
565
} , 150 )
559
566
}
0 commit comments