@@ -14,7 +14,6 @@ import {
14
14
buildChecksum ,
15
15
ImportMap ,
16
16
parseExportNames ,
17
- ReactResolve ,
18
17
SourceType ,
19
18
transform ,
20
19
TransformOptions
@@ -31,12 +30,11 @@ import {
31
30
import log from '../shared/log.ts'
32
31
import util from '../shared/util.ts'
33
32
import type {
34
- Config ,
35
33
RouterURL ,
36
34
ServerApplication
37
35
} from '../types.ts'
38
36
import { VERSION } from '../version.ts'
39
- import { defaultConfig , loadConfig , loadImportMap } from './config.ts'
37
+ import { defaultConfig , loadConfig , loadImportMap , RequiredConfig } from './config.ts'
40
38
import { CSSProcessor } from './css.ts'
41
39
import {
42
40
computeHash ,
@@ -72,7 +70,7 @@ type TransformFn = (url: string, code: string) => string
72
70
export class Application implements ServerApplication {
73
71
readonly workingDir : string
74
72
readonly mode : 'development' | 'production'
75
- readonly config : Required < Config & { react : ReactResolve } >
73
+ readonly config : RequiredConfig
76
74
readonly importMap : ImportMap
77
75
readonly ready : Promise < void >
78
76
@@ -113,7 +111,7 @@ export class Application implements ServerApplication {
113
111
Object . assign ( this . config , config )
114
112
Object . assign ( this . importMap , importMap )
115
113
this . #pageRouting. config ( this . config )
116
- this . #cssProcesser. config ( ! this . isDev , this . config . postcss . plugins )
114
+ this . #cssProcesser. config ( ! this . isDev , this . config . css )
117
115
118
116
// inject env variables
119
117
Deno . env . set ( 'ALEPH_VERSION' , VERSION )
@@ -145,15 +143,18 @@ export class Application implements ServerApplication {
145
143
const buildManifestFile = join ( this . buildDir , 'build.manifest.json' )
146
144
const plugins = computeHash ( JSON . stringify ( {
147
145
plugins : this . config . plugins . filter ( isLoaderPlugin ) . map ( ( { name } ) => name ) ,
148
- postcssPlugins : this . config . postcss . plugins . map ( p => {
149
- if ( util . isString ( p ) ) {
150
- return p
151
- } else if ( util . isArray ( p ) ) {
152
- return p [ 0 ] + JSON . stringify ( p [ 1 ] )
153
- } else {
154
- p . toString ( )
155
- }
156
- } ) ,
146
+ css : {
147
+ modules : this . config . css . modules ,
148
+ postcss : this . config . css . postcss . plugins . map ( p => {
149
+ if ( util . isString ( p ) ) {
150
+ return p
151
+ } else if ( util . isArray ( p ) ) {
152
+ return p [ 0 ] + JSON . stringify ( p [ 1 ] )
153
+ } else {
154
+ p . toString ( )
155
+ }
156
+ } )
157
+ } ,
157
158
react : this . config . react ,
158
159
} , ( key : string , value : any ) => {
159
160
if ( key === 'inlineStylePreprocess' ) {
@@ -711,7 +712,6 @@ export class Application implements ServerApplication {
711
712
const { code, type } = await loader . transform ( { url : key , content : ( new TextEncoder ) . encode ( tpl ) } )
712
713
if ( type === 'css' ) {
713
714
tpl = code
714
- break
715
715
}
716
716
}
717
717
}
@@ -918,9 +918,11 @@ export class Application implements ServerApplication {
918
918
sourceContent : Uint8Array ,
919
919
contentType : string | null
920
920
) : Promise < { code : string , type : SourceType , map : string | null } | null > {
921
- let sourceCode = ( new TextDecoder ) . decode ( sourceContent )
921
+ const encoder = new TextEncoder ( )
922
+ const decoder = new TextDecoder ( )
923
+
922
924
let sourceType : SourceType | null = null
923
- let sourceMap : string | null = null
925
+ let sourceMap : Uint8Array | null = null
924
926
925
927
if ( contentType !== null ) {
926
928
switch ( contentType . split ( ';' ) [ 0 ] . trim ( ) ) {
@@ -944,10 +946,10 @@ export class Application implements ServerApplication {
944
946
945
947
for ( const loader of this . loaders ) {
946
948
if ( loader . test . test ( url ) && loader . transform ) {
947
- const { code, type = 'js' , map } = await loader . transform ( { url, content : sourceContent } )
948
- sourceCode = code
949
+ const { code, type = 'js' , map } = await loader . transform ( { url, content : sourceContent , map : sourceMap ?? undefined } )
950
+ sourceContent = encoder . encode ( code )
949
951
if ( map ) {
950
- sourceMap = map
952
+ sourceMap = encoder . encode ( map )
951
953
}
952
954
switch ( type ) {
953
955
case 'js' :
@@ -966,7 +968,6 @@ export class Application implements ServerApplication {
966
968
sourceType = SourceType . CSS
967
969
break
968
970
}
969
- break
970
971
}
971
972
}
972
973
@@ -985,6 +986,7 @@ export class Application implements ServerApplication {
985
986
case 'tsx' :
986
987
sourceType = SourceType . TSX
987
988
break
989
+ case 'postcss' :
988
990
case 'pcss' :
989
991
case 'css' :
990
992
sourceType = SourceType . CSS
@@ -995,15 +997,19 @@ export class Application implements ServerApplication {
995
997
}
996
998
997
999
if ( sourceType === SourceType . CSS ) {
998
- const { code, map } = await this . #cssProcesser. transform ( url , sourceCode )
999
- sourceCode = code
1000
+ const { code, map } = await this . #cssProcesser. transform ( url , ( new TextDecoder ) . decode ( sourceContent ) )
1001
+ sourceContent = encoder . encode ( code )
1000
1002
sourceType = SourceType . JS
1001
1003
if ( map ) {
1002
- sourceMap = map
1004
+ sourceMap = encoder . encode ( map )
1003
1005
}
1004
1006
}
1005
1007
1006
- return { code : sourceCode , type : sourceType , map : sourceMap }
1008
+ return {
1009
+ code : decoder . decode ( sourceContent ) ,
1010
+ type : sourceType ,
1011
+ map : sourceMap ? decoder . decode ( sourceMap ) : null
1012
+ }
1007
1013
}
1008
1014
1009
1015
/** compile a moudle by given url, then cache on the disk. */
0 commit comments