1
- import { delay } from 'https://deno.land/[email protected] /async/delay.ts'
2
1
import { dim } from 'https://deno.land/[email protected] /fmt/colors.ts'
3
2
import { indexOf , copy , equals } from 'https://deno.land/[email protected] /bytes/mod.ts'
4
3
import { ensureDir } from 'https://deno.land/[email protected] /fs/ensure_dir.ts'
@@ -31,7 +30,6 @@ import { createHtml, Renderer } from './renderer.ts'
31
30
type ModuleSource = {
32
31
code : string
33
32
type : SourceType
34
- isStyle : boolean
35
33
map ?: string
36
34
}
37
35
@@ -523,21 +521,13 @@ export class Aleph implements IAleph {
523
521
/** add a module by given path and optional source code. */
524
522
async addModule ( specifier : string , sourceCode : string ) : Promise < Module > {
525
523
let sourceType = getSourceType ( specifier )
526
- let isStyle = false
527
524
if ( sourceType === SourceType . Unknown ) {
528
525
throw new Error ( "addModule: unknown souce type" )
529
526
}
530
- if ( sourceType === SourceType . CSS ) {
531
- const ret = await cssLoader ( { specifier, data : ( new TextEncoder ) . encode ( sourceCode ) } , this )
532
- sourceCode = ret . code
533
- sourceType = SourceType . JS
534
- isStyle = true
535
- }
536
527
const module = await this . compile ( specifier , {
537
528
source : {
538
529
code : sourceCode ,
539
530
type : sourceType ,
540
- isStyle,
541
531
}
542
532
} )
543
533
if ( specifier . startsWith ( 'pages/' ) || specifier . startsWith ( 'api/' ) ) {
@@ -1047,20 +1037,9 @@ export class Aleph implements IAleph {
1047
1037
}
1048
1038
}
1049
1039
1050
- if ( sourceType === SourceType . CSS ) {
1051
- isStyle = true
1052
- // todo: covert source map
1053
- const { code, type = 'js' } = await cssLoader ( { specifier, data : sourceCode } , this )
1054
- if ( type === 'js' ) {
1055
- sourceCode = code
1056
- sourceType = SourceType . JS
1057
- }
1058
- }
1059
-
1060
1040
return {
1061
1041
code : sourceCode ,
1062
1042
type : sourceType ,
1063
- isStyle,
1064
1043
map : sourceMap ? sourceMap : undefined
1065
1044
}
1066
1045
}
@@ -1074,7 +1053,11 @@ export class Aleph implements IAleph {
1074
1053
return module
1075
1054
}
1076
1055
1077
- private async initModule ( specifier : string , { source : customSource , forceRefresh, httpExternal } : CompileOptions = { } ) : Promise < [ Module , ModuleSource | null ] > {
1056
+ /** init the module by given specifier, don't transpile the code when the returned `source` is equal to null */
1057
+ private async initModule (
1058
+ specifier : string ,
1059
+ { source : customSource , forceRefresh, httpExternal } : CompileOptions = { }
1060
+ ) : Promise < [ Module , ModuleSource | null ] > {
1078
1061
let external = false
1079
1062
let data : any = null
1080
1063
@@ -1161,19 +1144,14 @@ export class Aleph implements IAleph {
1161
1144
} catch ( e ) { }
1162
1145
}
1163
1146
1164
- const shouldLoad = ! (
1165
- ( isRemote && ! this . #reloading && mod . sourceHash !== '' ) &&
1166
- await existsFile ( cacheFp )
1167
- )
1168
- if ( shouldLoad ) {
1147
+ if ( ! isRemote || this . #reloading || mod . sourceHash === '' || ! await existsFile ( cacheFp ) ) {
1169
1148
try {
1170
1149
const src = customSource || await this . resolveModuleSource ( specifier , data )
1171
1150
const sourceHash = computeHash ( src . code )
1172
1151
if ( mod . sourceHash === '' || mod . sourceHash !== sourceHash ) {
1173
1152
mod . sourceHash = sourceHash
1174
1153
source = src
1175
1154
}
1176
- mod . isStyle = src . isStyle
1177
1155
} catch ( err ) {
1178
1156
defer ( err )
1179
1157
return [ mod , null ]
@@ -1205,6 +1183,14 @@ export class Aleph implements IAleph {
1205
1183
return
1206
1184
}
1207
1185
1186
+ if ( source . type === SourceType . CSS ) {
1187
+ const { code, map } = await cssLoader ( { specifier, data : source . code } , this )
1188
+ source . code = code
1189
+ source . map = map
1190
+ source . type = SourceType . JS
1191
+ module . isStyle = true
1192
+ }
1193
+
1208
1194
const ms = new Measure ( )
1209
1195
const encoder = new TextEncoder ( )
1210
1196
const { code, deps = [ ] , denoHooks, ssrPropsFn, ssgPathsFn, starExports, jsxStaticClassNames, map } = await transform ( specifier , source . code , {
@@ -1318,7 +1304,7 @@ export class Aleph implements IAleph {
1318
1304
}
1319
1305
depModule = mod
1320
1306
}
1321
- if ( depModule ) {
1307
+ if ( ! ignoreDeps && depModule ) {
1322
1308
const hash = depModule . hash || depModule . sourceHash
1323
1309
if ( hashLoc !== undefined ) {
1324
1310
if ( await this . replaceDepHash ( module , hashLoc , hash ) ) {
0 commit comments