@@ -5,7 +5,7 @@ import log from './log.ts'
5
5
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
- import type { APIHandle , Config , Location , RouterURL } from './types.ts'
8
+ import type { AlephEnv , APIHandle , Config , Location , RouterURL } from './types.ts'
9
9
import util , { existsDirSync , existsFileSync , hashShort , reHashJs , reHttp , reModuleExt , reStyleModuleExt } from './util.ts'
10
10
import { cleanCSS , Document , less } from './vendor/mod.ts'
11
11
import { version } from './version.ts'
@@ -38,7 +38,7 @@ interface RenderResult {
38
38
39
39
export default class Project {
40
40
readonly mode : 'development' | 'production'
41
- readonly appDir : string
41
+ readonly appRoot : string
42
42
readonly config : Config
43
43
readonly ready : Promise < void >
44
44
@@ -49,7 +49,7 @@ export default class Project {
49
49
50
50
constructor ( dir : string , mode : 'development' | 'production' ) {
51
51
this . mode = mode
52
- this . appDir = path . resolve ( dir )
52
+ this . appRoot = dir
53
53
this . config = {
54
54
srcDir : '/' ,
55
55
outputDir : '/dist' ,
@@ -77,15 +77,15 @@ export default class Project {
77
77
}
78
78
79
79
get srcDir ( ) {
80
- return path . join ( this . appDir , this . config . srcDir )
80
+ return path . join ( this . appRoot , this . config . srcDir )
81
81
}
82
82
83
83
get buildID ( ) {
84
84
return this . #buildID
85
85
}
86
86
87
87
get buildDir ( ) {
88
- return path . join ( this . appDir , '.aleph' , 'build-' + this . buildID )
88
+ return path . join ( this . appRoot , '.aleph' , 'build-' + this . buildID )
89
89
}
90
90
91
91
get apiPaths ( ) {
@@ -269,11 +269,10 @@ export default class Project {
269
269
await Promise . all ( [ outputDir , distDir ] . map ( dir => ensureDir ( dir ) ) )
270
270
271
271
// copy public files
272
- const publicDir = path . join ( this . appDir , 'public' )
272
+ const publicDir = path . join ( this . appRoot , 'public' )
273
273
if ( existsDirSync ( publicDir ) ) {
274
274
for await ( const { path : p } of walk ( publicDir , { includeDirs : false } ) ) {
275
- const rp = path . resolve ( util . trimPrefix ( p , publicDir ) )
276
- await Deno . copyFile ( p , path . join ( outputDir , rp ) )
275
+ await Deno . copyFile ( p , path . join ( outputDir , util . trimPrefix ( p , publicDir ) ) )
277
276
}
278
277
}
279
278
@@ -320,7 +319,7 @@ export default class Project {
320
319
Object . assign ( this . config . importMap , { imports : Object . assign ( { } , this . config . importMap . imports , imports ) } )
321
320
}
322
321
323
- const importMapFile = path . join ( this . appDir , 'import_map.json' )
322
+ const importMapFile = path . join ( this . appRoot , 'import_map.json' )
324
323
if ( existsFileSync ( importMapFile ) ) {
325
324
const { imports } = JSON . parse ( await Deno . readTextFile ( importMapFile ) )
326
325
Object . assign ( this . config . importMap , { imports : Object . assign ( { } , this . config . importMap . imports , imports ) } )
@@ -389,7 +388,7 @@ export default class Project {
389
388
}
390
389
391
390
private async _init ( ) {
392
- const walkOptions = { includeDirs : false , exts : [ '.js' , '.ts' , '.mjs' ] , skip : [ / \. d \. t s $ / i] }
391
+ const walkOptions = { includeDirs : false , exts : [ '.js' , '.ts' , '.mjs' ] , skip : [ / ^ \. / , / \. d \. t s $ / i , / \. ( t e s t | s p e c | e 2 e ) \. m ? ( j | t ) s $ / i] }
393
392
const dataDir = path . join ( this . srcDir , 'data' )
394
393
const apiDir = path . join ( this . srcDir , 'api' )
395
394
const pagesDir = path . join ( this . srcDir , 'pages' )
@@ -400,11 +399,11 @@ export default class Project {
400
399
401
400
Object . assign ( globalThis , {
402
401
ALEPH_ENV : {
403
- appDir : this . appDir ,
402
+ appRoot : this . appRoot ,
404
403
buildID : this . buildID ,
405
404
config : this . config ,
406
405
mode : this . mode ,
407
- } ,
406
+ } as AlephEnv ,
408
407
document : new Document ( ) ,
409
408
innerWidth : 1920 ,
410
409
innerHeight : 1080 ,
@@ -419,8 +418,7 @@ export default class Project {
419
418
switch ( name ) {
420
419
case 'api' :
421
420
for await ( const { path : p } of walk ( apiDir , walkOptions ) ) {
422
- const rp = path . resolve ( util . trimPrefix ( p , apiDir ) )
423
- await this . _compile ( '/api/' + rp )
421
+ await this . _compile ( '/api' + util . trimPrefix ( p , apiDir ) )
424
422
}
425
423
break
426
424
case 'data' :
@@ -444,7 +442,7 @@ export default class Project {
444
442
}
445
443
446
444
for await ( const { path : p } of walk ( pagesDir , { ...walkOptions , exts : [ ...walkOptions . exts , '.jsx' , '.tsx' , '.md' , '.mdx' ] } ) ) {
447
- const rp = path . resolve ( util . trimPrefix ( p , pagesDir ) ) || '/'
445
+ const rp = util . trimPrefix ( p , pagesDir )
448
446
const pagePath = rp . replace ( reModuleExt , '' ) . replace ( / \s + / g, '-' ) . replace ( / \/ i n d e x $ / i, '' ) || '/'
449
447
const mod = await this . _compile ( '/pages' + rp )
450
448
this . #pageModules. set ( pagePath , {
@@ -485,7 +483,7 @@ export default class Project {
485
483
log . info ( 'Start watching code changes...' )
486
484
for await ( const event of w ) {
487
485
for ( const p of event . paths ) {
488
- const path = util . trimPrefix ( util . trimPrefix ( p , this . appDir ) , '/' )
486
+ const path = util . trimPrefix ( util . trimPrefix ( p , this . appRoot ) , '/' )
489
487
const validated = ( ( ) => {
490
488
if ( ! reModuleExt . test ( path ) && ! reStyleModuleExt . test ( path ) ) {
491
489
return false
@@ -634,9 +632,8 @@ export default class Project {
634
632
}
635
633
const module = this . _moduleFromURL ( '/main.js' )
636
634
const deps = [
637
- 'https://deno.land/x/aleph/tsc/tslib.js' ,
638
- 'https://deno.land/x/aleph/app.ts' ,
639
- this . isDev && 'https://deno.land/x/aleph/hmr.ts'
635
+ this . isDev && 'https://deno.land/x/aleph/hmr.ts' ,
636
+ 'https://deno.land/x/aleph/bootstrap.ts'
640
637
] . filter ( Boolean ) . map ( url => ( {
641
638
url : String ( url ) ,
642
639
hash : this . #modules. get ( String ( url ) . replace ( reHttp , '//' ) . replace ( reModuleExt , '.js' ) ) ?. hash || ''
@@ -674,7 +671,6 @@ export default class Project {
674
671
675
672
module . jsContent = [
676
673
this . isDev && 'import "./-/deno.land/x/aleph/hmr.js";' ,
677
- 'import "./-/deno.land/x/aleph/tsc/tslib.js";' ,
678
674
'import bootstrap from "./-/deno.land/x/aleph/bootstrap.js";' ,
679
675
`bootstrap(${ JSON . stringify ( config , undefined , this . isDev ? 4 : undefined ) } );`
680
676
] . filter ( Boolean ) . join ( this . isDev ? '\n' : '' )
@@ -927,7 +923,7 @@ export default class Project {
927
923
if ( ! reHttp . test ( dep . url ) ) {
928
924
const depImportPath = relativePath (
929
925
path . dirname ( url ) ,
930
- path . resolve ( '/' , dep . url . replace ( reModuleExt , '' ) )
926
+ dep . url . replace ( reModuleExt , '' )
931
927
)
932
928
mod . jsContent = mod . jsContent . replace ( / ( i m p o r t | I m p o r t | e x p o r t ) ( [ ^ ' " ] * ) ( " | ' ) ( [ ^ ' " ] + ) ( " | ' ) ( \) | ; ) ? / g, ( s , key , from , ql , importPath , qr , end ) => {
933
929
if (
@@ -969,8 +965,8 @@ export default class Project {
969
965
mod . deps . forEach ( dep => {
970
966
if ( dep . url === depPath && dep . hash !== depHash && ! trace ?. has ( mod . id ) ) {
971
967
const depImportPath = relativePath (
972
- path . dirname ( path . resolve ( '/' , mod . url ) ) ,
973
- path . resolve ( '/' , dep . url . replace ( reModuleExt , '' ) )
968
+ path . dirname ( mod . url ) ,
969
+ dep . url . replace ( reModuleExt , '' )
974
970
)
975
971
dep . hash = depHash
976
972
if ( mod . id === '/main.js' ) {
@@ -1016,12 +1012,12 @@ export default class Project {
1016
1012
if ( reHttp . test ( importPath ) ) {
1017
1013
if ( mod . isRemote ) {
1018
1014
rewrittenPath = relativePath (
1019
- path . dirname ( path . resolve ( '/' , mod . url . replace ( reHttp , '-/' ) . replace ( / : ( \d + ) / , '/$1' ) ) ) ,
1015
+ path . dirname ( mod . url . replace ( reHttp , '/ -/' ) . replace ( / : ( \d + ) / , '/$1' ) ) ,
1020
1016
renameImportUrl ( importPath )
1021
1017
)
1022
1018
} else {
1023
1019
rewrittenPath = relativePath (
1024
- path . dirname ( path . resolve ( '/' , mod . url ) ) ,
1020
+ path . dirname ( mod . url ) ,
1025
1021
renameImportUrl ( importPath )
1026
1022
)
1027
1023
}
@@ -1052,7 +1048,7 @@ export default class Project {
1052
1048
}
1053
1049
mod . deps . push ( { url : sourceUrl . protocol + '//' + sourceUrl . host + pathname , hash : '' , async } )
1054
1050
} else {
1055
- mod . deps . push ( { url : path . resolve ( '/' , path . dirname ( mod . url ) , importPath ) , hash : '' , async } )
1051
+ mod . deps . push ( { url : path . join ( path . dirname ( mod . url ) , importPath ) , hash : '' , async } )
1056
1052
}
1057
1053
}
1058
1054
@@ -1186,7 +1182,7 @@ function relativePath(from: string, to: string): string {
1186
1182
1187
1183
function renameImportUrl ( importUrl : string ) : string {
1188
1184
const isRemote = reHttp . test ( importUrl )
1189
- const url = new URL ( isRemote ? importUrl : 'file://' + path . resolve ( '/' , importUrl ) )
1185
+ const url = new URL ( isRemote ? importUrl : 'file://' + importUrl )
1190
1186
const ext = path . extname ( path . basename ( url . pathname ) ) || '.js'
1191
1187
let pathname = util . trimSuffix ( url . pathname , ext )
1192
1188
let search = Array . from ( url . searchParams . entries ( ) ) . map ( ( [ key , value ] ) => value ? `${ key } =${ value } ` : key )
0 commit comments