1
- use std:: {
2
- process:: Stdio ,
3
- sync:: { Arc , Mutex } ,
4
- thread,
5
- } ;
6
-
7
- use futures:: {
8
- future:: { self , BoxFuture } ,
9
- stream, Stream , StreamExt ,
10
- } ;
11
- use prost:: Message as _;
12
- use tokio:: {
13
- io:: { AsyncBufReadExt , AsyncWriteExt , BufReader } ,
14
- process:: Command ,
15
- } ;
16
- // use tokio_stream::StreamExt as _;
17
- use tokio_util:: io:: ReaderStream ;
18
-
19
1
use crate :: {
20
- api:: {
21
- CompileResult , Exception , Result , StringOptions ,
22
- StringOptionsWithoutImporter ,
23
- } ,
2
+ api:: { CompileResult , Exception , Result , StringOptions } ,
24
3
compiler:: Embedded ,
25
4
compiler_path,
26
5
importer_registry:: ImporterRegistry ,
27
- packet_transformer:: PacketTransformer ,
28
- pb:: {
29
- inbound_message:: {
30
- compile_request:: { Input , StringInput } ,
31
- CompileRequest , Message ,
32
- } ,
33
- outbound_message:: {
34
- compile_response:: { self , CompileSuccess } ,
35
- CompileResponse ,
36
- } ,
37
- InboundMessage , OutboundMessage , OutputStyle , Syntax ,
38
- } ,
6
+ logger_registry:: LoggerRegistry ,
7
+ pb:: { inbound_message:: CompileRequest , outbound_message:: compile_response} ,
39
8
} ;
40
9
41
10
pub async fn compile_string (
@@ -45,9 +14,13 @@ pub async fn compile_string(
45
14
let base = options. get_options_mut ( ) ;
46
15
let mut importers =
47
16
ImporterRegistry :: new ( base. importers . take ( ) , base. load_paths . take ( ) ) ;
17
+ let logger = LoggerRegistry :: new ( base. logger . take ( ) ) ;
18
+
48
19
let request = CompileRequest :: with_string ( source, & mut importers, options) ;
49
20
let mut embedded = Embedded :: new ( compiler_path:: compiler_path ( ) . unwrap ( ) ) ;
50
- let response = embedded. send_compile_request ( request, importers) . await ?;
21
+ let response = embedded
22
+ . send_compile_request ( request, importers, logger)
23
+ . await ?;
51
24
match response. result . unwrap ( ) {
52
25
compile_response:: Result :: Success ( success) => {
53
26
let css = success. css ;
@@ -65,63 +38,20 @@ pub async fn compile_string(
65
38
}
66
39
}
67
40
68
- #[ tokio:: test]
69
- async fn test_compile_string ( ) {
70
- let res = compile_string (
71
- ".foo {a: b}" . to_string ( ) ,
72
- StringOptions :: WithoutImporter ( StringOptionsWithoutImporter :: default ( ) ) ,
73
- )
74
- . await
75
- . unwrap ( ) ;
76
- dbg ! ( res) ;
77
- }
41
+ #[ cfg( test) ]
42
+ mod tests {
43
+ use crate :: api:: StringOptionsWithoutImporter ;
78
44
79
- #[ tokio:: test]
80
- async fn t_compile_string ( ) {
81
- let source = ".a { color: red; }" . to_string ( ) ;
82
- let mut string = StringInput :: default ( ) ;
83
- string. source = source;
84
- string. set_syntax ( Syntax :: Scss ) ;
85
- let mut request = CompileRequest :: default ( ) ;
86
- request. set_style ( OutputStyle :: Expanded ) ;
87
- request. input = Some ( Input :: String ( string) ) ;
88
- // request.id = 0;
89
- let mut inbound_message = InboundMessage :: default ( ) ;
90
- inbound_message. message = Some ( Message :: CompileRequest ( request) ) ;
91
- let buf = inbound_message. encode_length_delimited_to_vec ( ) ;
92
- // let buf = PacketTransformer::encode(buf);
45
+ use super :: * ;
93
46
94
- let path = compiler_path:: compiler_path ( ) . unwrap ( ) ;
95
- let mut child = Command :: new ( path)
96
- . stdin ( Stdio :: piped ( ) )
97
- . stdout ( Stdio :: piped ( ) )
98
- . stderr ( Stdio :: piped ( ) )
99
- . spawn ( )
100
- . unwrap ( ) ;
101
- dbg ! ( & buf) ;
102
- child
103
- . stdin
104
- . as_mut ( )
105
- . unwrap ( )
106
- . write_all ( buf. as_ref ( ) )
47
+ #[ tokio:: test]
48
+ async fn test_compile_string ( ) {
49
+ let res = compile_string (
50
+ ".foo {a: b}" . to_string ( ) ,
51
+ StringOptions :: WithoutImporter ( StringOptionsWithoutImporter :: default ( ) ) ,
52
+ )
107
53
. await
108
54
. unwrap ( ) ;
109
- let stdout = child. stdout . take ( ) . unwrap ( ) ;
110
- let reader = BufReader :: new ( stdout) ;
111
- let stream = ReaderStream :: new ( reader) ;
112
- stream
113
- // .flat_map(|buf| {
114
- // let ps = pt.decode(buf.unwrap().to_vec());
115
- // stream::iter(ps)
116
- // })
117
- . map ( |buf| {
118
- let buf = buf. unwrap ( ) . to_vec ( ) ;
119
- let m = OutboundMessage :: decode_length_delimited ( buf. as_ref ( ) ) . unwrap ( ) ;
120
- m
121
- } )
122
- . for_each ( |m| {
123
- dbg ! ( m) ;
124
- future:: ready ( ( ) )
125
- } )
126
- . await ;
55
+ dbg ! ( res) ;
56
+ }
127
57
}
0 commit comments