@@ -12,7 +12,7 @@ import { colors, ensureDir, fromStreamReader, path, ServerRequest, Sha1, walk }
12
12
import { compile } from './tsc/compile.ts'
13
13
import type { AlephEnv , APIHandler , Config , RouterURL } from './types.ts'
14
14
import util , { hashShort , MB , reHashJs , reHttp , reLocaleID , reMDExt , reModuleExt , reStyleModuleExt } from './util.ts'
15
- import { cleanCSS , Document , less } from './vendor/mod.ts'
15
+ import { cleanCSS , less } from './vendor/mod.ts'
16
16
import { version } from './version.ts'
17
17
18
18
interface Module {
@@ -32,7 +32,8 @@ interface Module {
32
32
interface Dep {
33
33
url : string
34
34
hash : string
35
- async ?: boolean
35
+ isStyle ?: boolean
36
+ isData ?: boolean
36
37
external ?: boolean
37
38
}
38
39
@@ -680,9 +681,6 @@ export class Project {
680
681
const path = util . cleanPath ( util . trimPrefix ( p , this . appRoot ) )
681
682
// handle `api` dir remove directly
682
683
const validated = ( ( ) => {
683
- if ( ! reModuleExt . test ( path ) && ! reStyleModuleExt . test ( path ) && ! reMDExt . test ( path ) ) {
684
- return false
685
- }
686
684
// ignore `.aleph` and output directories
687
685
if ( path . startsWith ( '/.aleph/' ) || path . startsWith ( this . config . outputDir ) ) {
688
686
return false
@@ -790,8 +788,8 @@ export class Project {
790
788
}
791
789
792
790
private _getRouteModule ( { id, hash } : Module ) : RouteModule {
793
- const asyncDeps = this . _lookupAsyncDeps ( id ) . filter ( ( { async } ) => ! ! async ) . map ( ( { async , ...rest } ) => rest )
794
- return { id, hash, asyncDeps : asyncDeps . length > 0 ? asyncDeps : undefined }
791
+ const deps = this . _lookupDeps ( id ) . filter ( ( { isData , isStyle } ) => ! ! isData || ! ! isStyle ) . map ( ( { external , ...rest } ) => rest )
792
+ return { id, hash, deps : deps . length > 0 ? deps : undefined }
795
793
}
796
794
797
795
private _moduleFromURL ( url : string ) : Module {
@@ -1064,7 +1062,7 @@ export class Project {
1064
1062
mode : this . mode ,
1065
1063
target : options ?. forceTarget || this . config . buildTarget ,
1066
1064
reactRefresh : this . isDev && ! mod . isRemote ,
1067
- rewriteImportPath : ( path : string , async ?: boolean ) => this . _resolveImportURL ( mod , path , async ) ,
1065
+ rewriteImportPath : ( path : string ) => this . _resolveImportURL ( mod , path ) ,
1068
1066
signUseDeno : ( id : string ) => {
1069
1067
const sig = 'useDeno.' + ( new Sha1 ( ) ) . update ( id ) . update ( version ) . update ( Date . now ( ) . toString ( ) ) . hex ( ) . slice ( 0 , hashShort )
1070
1068
useDenos . push ( sig )
@@ -1101,7 +1099,7 @@ export class Project {
1101
1099
}
1102
1100
mod . hash = getHash ( mod . jsContent )
1103
1101
useDenos . forEach ( sig => {
1104
- mod . deps . push ( { url : '#' + sig , hash : '' , async : true } )
1102
+ mod . deps . push ( { url : '#' + sig , hash : '' , isData : true } )
1105
1103
} )
1106
1104
} else {
1107
1105
throw new Error ( `Unknown loader '${ mod . loader } '` )
@@ -1119,14 +1117,17 @@ export class Project {
1119
1117
// compile deps
1120
1118
for ( const dep of mod . deps . filter ( ( { url, external } ) => ! url . startsWith ( '#useDeno.' ) && ! external ) ) {
1121
1119
const depMod = await this . _compile ( dep . url )
1120
+ if ( depMod . loader === 'css' && ! dep . isStyle ) {
1121
+ dep . isStyle = true
1122
+ }
1122
1123
if ( dep . hash !== depMod . hash ) {
1123
1124
dep . hash = depMod . hash
1124
1125
if ( ! reHttp . test ( dep . url ) ) {
1125
1126
const depImportPath = getRelativePath (
1126
1127
path . dirname ( url ) ,
1127
1128
dep . url . replace ( reModuleExt , '' )
1128
1129
)
1129
- mod . jsContent = mod . jsContent . replace ( / ( i m p o r t | I m p o r t | e x p o r t ) ( [ \s \S ] * ?) ( f r o m \s * : ? \s * | \( ) ( " | ' ) ( [ ^ ' " ] + ) ( " | ' ) ( \) | ; ) ? / g, ( s , key , fields , from , ql , importPath , qr , end ) => {
1130
+ mod . jsContent = mod . jsContent . replace ( / ( i m p o r t | I m p o r t | e x p o r t ) ( [ \s \S ] * ?) ( f r o m \s * : ? \s * | \( | ) ( " | ' ) ( [ ^ ' " ] + ) ( " | ' ) ( \) | ; ) ? / g, ( s , key , fields , from , ql , importPath , qr , end ) => {
1130
1131
if (
1131
1132
reHashJs . test ( importPath ) &&
1132
1133
importPath . slice ( 0 , importPath . length - ( hashShort + 4 ) ) === depImportPath
@@ -1204,7 +1205,7 @@ export class Project {
1204
1205
} )
1205
1206
}
1206
1207
1207
- private _resolveImportURL ( importer : Module , url : string , async ?: boolean ) : string {
1208
+ private _resolveImportURL ( importer : Module , url : string ) : string {
1208
1209
let rewrittenURL : string
1209
1210
let pluginsResolveRet : { url : string , external ?: boolean } | null = null
1210
1211
for ( const plugin of this . config . plugins ) {
@@ -1255,7 +1256,7 @@ export class Project {
1255
1256
}
1256
1257
1257
1258
if ( reHttp . test ( url ) ) {
1258
- importer . deps . push ( { url, hash : '' , async , external : pluginsResolveRet ?. external } )
1259
+ importer . deps . push ( { url, hash : '' , external : pluginsResolveRet ?. external } )
1259
1260
} else {
1260
1261
if ( importer . isRemote ) {
1261
1262
const sourceUrl = new URL ( importer . url )
@@ -1266,14 +1267,12 @@ export class Project {
1266
1267
importer . deps . push ( {
1267
1268
url : sourceUrl . protocol + '//' + sourceUrl . host + pathname ,
1268
1269
hash : '' ,
1269
- async,
1270
1270
external : pluginsResolveRet ?. external
1271
1271
} )
1272
1272
} else {
1273
1273
importer . deps . push ( {
1274
1274
url : util . cleanPath ( path . dirname ( importer . url ) + '/' + url ) ,
1275
1275
hash : '' ,
1276
- async,
1277
1276
external : pluginsResolveRet ?. external
1278
1277
} )
1279
1278
}
@@ -1325,8 +1324,8 @@ export class Project {
1325
1324
await Promise . all ( imports )
1326
1325
const [ html , data ] = await this . #renderer. renderPage ( url , App , undefined , pageComponentTree )
1327
1326
const head = await this . #renderer. renderHead ( [
1328
- appModule ? this . _lookupAsyncDeps ( appModule . id ) . filter ( ( { url } ) => reStyleModuleExt . test ( url ) ) : [ ] ,
1329
- ...pageModuleTree . map ( ( { id } ) => this . _lookupAsyncDeps ( id ) . filter ( ( { url } ) => reStyleModuleExt . test ( url ) ) )
1327
+ appModule ? this . _lookupDeps ( appModule . id ) . filter ( dep => ! ! dep . isStyle ) : [ ] ,
1328
+ ...pageModuleTree . map ( ( { id } ) => this . _lookupDeps ( id ) . filter ( dep => ! ! dep . isStyle ) ) . flat ( )
1330
1329
] . flat ( ) )
1331
1330
ret . head = head
1332
1331
ret . scripts = await Promise . all ( this . #renderer. renderScripts ( ) . map ( async ( script : Record < string , any > ) => {
@@ -1357,7 +1356,7 @@ export class Project {
1357
1356
const { default : E404 } = e404Module ? await import ( 'file://' + e404Module . jsFile ) : { } as any
1358
1357
const [ html , data ] = await this . #renderer. renderPage ( url , undefined , E404 , [ ] )
1359
1358
const head = await this . #renderer. renderHead ( [
1360
- e404Module ? this . _lookupAsyncDeps ( e404Module . id ) . filter ( ( { url } ) => reStyleModuleExt . test ( url ) ) : [ ]
1359
+ e404Module ? this . _lookupDeps ( e404Module . id ) . filter ( dep => ! ! dep . isStyle ) : [ ]
1361
1360
] . flat ( ) )
1362
1361
ret . head = head
1363
1362
ret . scripts = await Promise . all ( this . #renderer. renderScripts ( ) . map ( async ( script : Record < string , any > ) => {
@@ -1384,7 +1383,7 @@ export class Project {
1384
1383
const url = { locale : this . config . defaultLocale , pagePath : '' , pathname : '/' , params : { } , query : new URLSearchParams ( ) }
1385
1384
const [ html , data ] = await this . #renderer. renderPage ( url , undefined , undefined , [ { id : '/loading.js' , Component : Loading } ] )
1386
1385
const head = await this . #renderer. renderHead ( [
1387
- this . _lookupAsyncDeps ( loadingModule . id ) . filter ( ( { url } ) => reStyleModuleExt . test ( url ) )
1386
+ this . _lookupDeps ( loadingModule . id ) . filter ( dep => ! ! dep . isStyle )
1388
1387
] . flat ( ) )
1389
1388
return {
1390
1389
head,
@@ -1395,7 +1394,7 @@ export class Project {
1395
1394
return null
1396
1395
}
1397
1396
1398
- private _lookupAsyncDeps ( moduleID : string , __deps : { url : string , hash : string , async ?: boolean } [ ] = [ ] , __tracing : Set < string > = new Set ( ) ) {
1397
+ private _lookupDeps ( moduleID : string , __deps : Dep [ ] = [ ] , __tracing : Set < string > = new Set ( ) ) {
1399
1398
const mod = this . getModule ( moduleID )
1400
1399
if ( ! mod ) {
1401
1400
return __deps
@@ -1404,10 +1403,10 @@ export class Project {
1404
1403
return __deps
1405
1404
}
1406
1405
__tracing . add ( moduleID )
1407
- __deps . push ( ...mod . deps . filter ( ( { url, async } ) => ! ! async && __deps . findIndex ( i => i . url === url ) === - 1 ) )
1406
+ __deps . push ( ...mod . deps . filter ( ( { url } ) => __deps . findIndex ( i => i . url === url ) === - 1 ) )
1408
1407
mod . deps . forEach ( ( { url } ) => {
1409
1408
if ( reModuleExt . test ( url ) && ! reHttp . test ( url ) ) {
1410
- this . _lookupAsyncDeps ( url . replace ( reModuleExt , '.js' ) , __deps , __tracing )
1409
+ this . _lookupDeps ( url . replace ( reModuleExt , '.js' ) , __deps , __tracing )
1411
1410
}
1412
1411
} )
1413
1412
return __deps
@@ -1416,7 +1415,7 @@ export class Project {
1416
1415
1417
1416
// add virtual browser global objects
1418
1417
Object . assign ( globalThis , {
1419
- document : new Document ( ) ,
1418
+ // document: new Document(),
1420
1419
location : {
1421
1420
protocol : 'http:' ,
1422
1421
host : 'localhost' ,
0 commit comments