@@ -32,7 +32,7 @@ Deno.serve(
3232 }
3333 return runStream ( parameters ) ;
3434 } ,
35- } ) ,
35+ } )
3636) ;
3737
3838async function swiftVersion ( ) : Promise < string > {
@@ -48,34 +48,28 @@ async function runOutput(parameters: RequestParameters): Promise<Response> {
4848 const output = new TextDecoder ( ) . decode ( stdout ) ;
4949 const errors = new TextDecoder ( ) . decode ( stderr ) ;
5050
51- return responseJSON (
52- new OutputResponse (
53- output ,
54- errors ,
55- version ,
56- ) ,
57- ) ;
51+ return responseJSON ( new OutputResponse ( output , errors , version ) ) ;
5852}
5953
6054function runStream ( parameters : RequestParameters ) : Response {
6155 return new Response (
6256 zipReadableStreams (
6357 spawn ( makeVersionCommand ( ) , undefined , "version" , "version" ) ,
64- spawn ( makeSwiftCommand ( parameters ) , parameters . code , "stdout" , "stderr" ) ,
58+ spawn ( makeSwiftCommand ( parameters ) , parameters . code , "stdout" , "stderr" )
6559 ) ,
6660 {
6761 headers : {
6862 "content-type" : "text/plain; charset=utf-8" ,
6963 } ,
70- } ,
64+ }
7165 ) ;
7266}
7367
7468function spawn (
7569 command : Deno . Command ,
7670 input : string | undefined ,
7771 stdoutKey : string ,
78- stderrKey : string ,
72+ stderrKey : string
7973) : ReadableStream < Uint8Array > {
8074 const process = command . spawn ( ) ;
8175
@@ -89,76 +83,62 @@ function spawn(
8983
9084 return mergeReadableStreams (
9185 makeStreamResponse ( process . stderr , stderrKey ) ,
92- makeStreamResponse ( process . stdout , stdoutKey ) ,
86+ makeStreamResponse ( process . stdout , stdoutKey )
9387 ) ;
9488}
9589
9690function makeVersionCommand ( ) : Deno . Command {
97- return new Deno . Command (
98- "swift" ,
99- {
100- args : [ "-version" ] ,
101- stdout : "piped" ,
102- stderr : "piped" ,
103- } ,
104- ) ;
91+ return new Deno . Command ( "swift" , {
92+ args : [ "-version" ] ,
93+ stdout : "piped" ,
94+ stderr : "piped" ,
95+ } ) ;
10596}
10697
107- function makeSwiftCommand (
108- parameters : RequestParameters ,
109- ) : Deno . Command {
98+ function makeSwiftCommand ( parameters : RequestParameters ) : Deno . Command {
11099 const command = parameters . command || "swift" ;
111- const options = parameters . options ||
112- "-I ./swiftfiddle.com/_Packages/.build/release/ -I ./swiftfiddle.com/_Packages/.build/checkouts/swift-numerics/Sources/_NumericsShims/include/ -L ./swiftfiddle.com/_Packages/.build/release/ -l_Packages -enable-bare-slash-regex" ;
100+ const options =
101+ parameters . options ||
102+ "-I ./swiftfiddle.com/_Packages/.build/release/ -I ./swiftfiddle.com/_Packages/.build/checkouts/swift-numerics/Sources/_NumericsShims/include/ -L ./swiftfiddle.com/_Packages/.build/release/ -l_Packages" ;
113103
114104 const timeout = parameters . timeout || 60 ;
115105 const color = parameters . _color || false ;
116106 const env = color
117107 ? {
118- " TERM" : "xterm-256color" ,
119- " LD_PRELOAD" : "./faketty.so" ,
120- }
108+ TERM : "xterm-256color" ,
109+ LD_PRELOAD : "./faketty.so" ,
110+ }
121111 : undefined ;
122- const args = [
123- "-i0" ,
124- "-oL" ,
125- "-eL" ,
126- "timeout" ,
127- `${ timeout } ` ,
128- command ,
129- ] ;
112+ const args = [ "-i0" , "-oL" , "-eL" , "timeout" , `${ timeout } ` , command ] ;
130113 if ( options ) {
131114 args . push ( ...options . split ( " " ) ) ;
132115 }
133116 args . push ( "-" ) ;
134117
135- return new Deno . Command (
136- "stdbuf" ,
137- {
138- args : args ,
139- env : env ,
140- stdin : "piped" ,
141- stdout : "piped" ,
142- stderr : "piped" ,
143- } ,
144- ) ;
118+ return new Deno . Command ( "stdbuf" , {
119+ args : args ,
120+ env : env ,
121+ stdin : "piped" ,
122+ stdout : "piped" ,
123+ stderr : "piped" ,
124+ } ) ;
145125}
146126
147127function makeStreamResponse (
148128 stream : ReadableStream < Uint8Array > ,
149- key : string ,
129+ key : string
150130) : ReadableStream < Uint8Array > {
151131 return stream . pipeThrough (
152132 new TransformStream < Uint8Array , Uint8Array > ( {
153133 transform ( chunk , controller ) {
154134 const text = new TextDecoder ( ) . decode ( chunk ) ;
155135 controller . enqueue (
156136 new TextEncoder ( ) . encode (
157- `${ JSON . stringify ( new StreamResponse ( key , text ) ) } \n` ,
158- ) ,
137+ `${ JSON . stringify ( new StreamResponse ( key , text ) ) } \n`
138+ )
159139 ) ;
160140 } ,
161- } ) ,
141+ } )
162142 ) ;
163143}
164144
@@ -168,14 +148,11 @@ async function responseHealthCheck(): Promise<Response> {
168148}
169149
170150function responseJSON ( json : unknown ) : Response {
171- return new Response (
172- JSON . stringify ( json ) ,
173- {
174- headers : {
175- "content-type" : "application/json; charset=utf-8" ,
176- } ,
151+ return new Response ( JSON . stringify ( json ) , {
152+ headers : {
153+ "content-type" : "application/json; charset=utf-8" ,
177154 } ,
178- ) ;
155+ } ) ;
179156}
180157
181158function resposeError ( message : string , status : number ) : Response {
0 commit comments