@@ -206,9 +206,6 @@ var rootCmd = &cobra.Command{
206206
207207 os .MkdirAll (tempDir , os .ModePerm )
208208
209- // save current directory because we might change it to compile the script
210- currentDir , _ := os .Getwd ()
211-
212209 if _ , err = os .Stat (filepath .Join (tempDir , "script.ts" )); os .IsNotExist (err ) {
213210 for fl , data := range tempFiles {
214211 os .WriteFile (filepath .Join (tempDir , fl ), data , os .ModePerm )
@@ -217,26 +214,36 @@ var rootCmd = &cobra.Command{
217214
218215 if _ , err = os .Stat (filepath .Join (tempDir , "node_modules" )); os .IsNotExist (err ) {
219216 // Install modules
217+ pwd , _ := os .Getwd ()
218+ os .Chdir (tempDir )
220219 command := exec .Command ("npm" , "install" )
221220 if err := command .Run (); err != nil {
222221 logger .Errorf ("Error installing modules: %v" , err )
223222 }
223+ os .Chdir (pwd )
224224 }
225225
226226 agentPath := filepath .Join (tempDir , agentFilename )
227227 var scriptBody string
228228
229229 // check if we have script.ts already compiled
230230 if _ , err = os .Stat (agentPath ); os .IsNotExist (err ) {
231- os .Chdir (tempDir )
232-
233231 comp := frida .NewCompiler ()
234232
235233 comp .On ("finished" , func () {
236234 logger .Infof ("Done compiling script" )
237235 })
238236
239- bundle , err := comp .Build ("script.ts" )
237+ comp .On ("diagnostics" , func (diag string ) {
238+ logger .Errorf ("compilation error: %v" , diag )
239+ })
240+
241+ buildOptions := frida .NewCompilerOptions ()
242+ buildOptions .SetProjectRoot (tempDir )
243+ buildOptions .SetJSCompression (frida .JSCompressionTerser )
244+ buildOptions .SetSourceMaps (frida .SourceMapsOmitted )
245+
246+ bundle , err := comp .Build ("script.ts" , buildOptions )
240247 if err != nil {
241248 return fmt .Errorf ("error compiling script: %v" , err )
242249 }
@@ -246,8 +253,6 @@ var rootCmd = &cobra.Command{
246253 }
247254
248255 scriptBody = bundle
249-
250- os .Chdir (currentDir )
251256 } else {
252257 data , err := os .ReadFile (agentPath )
253258 if err != nil {
0 commit comments