@@ -338,21 +338,24 @@ compileJS' indent (JSWord word)
338338 | JSWord64 b <- word = idrRTNamespace ++ "bigInt(\"" ++ show b ++ "\")"
339339
340340codegenJavaScript :: CodeGenerator
341−codegenJavaScript ci = codegenJS_all JavaScript (simpleDecls ci)
342− (includes ci) (outputFile ci) (outputType ci)
341+codegenJavaScript ci =
342+ codegenJS_all JavaScript (simpleDecls ci)
343+ (includes ci) [] (outputFile ci) (outputType ci)
343344
344345codegenNode :: CodeGenerator
345−codegenNode ci = codegenJS_all Node (simpleDecls ci)
346− (includes ci) (outputFile ci) (outputType ci)
346+codegenNode ci =
347+ codegenJS_all Node (simpleDecls ci)
348+ (includes ci) (compileLibs ci) (outputFile ci) (outputType ci)
347349
348350codegenJS_all
349351 :: JSTarget
350352 -> [(Name, SDecl)]
351353 -> [FilePath]
354+ -> [String]
352355 -> FilePath
353356 -> OutputType
354357 -> IO ()
355−codegenJS_all target definitions includes filename outputType = do
358+codegenJS_all target definitions includes libs filename outputType = do
356359 let bytecode = map toBC definitions
357360 let info = initCompileInfo bytecode
358361 let js = concatMap (translateDecl info) bytecode
@@ -366,13 +369,23 @@ codegenJS_all target definitions includes filename outputType = do
366369 idrRuntime <- readFile $ path ++ "Runtime-common.js"
367370 tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
368371 jsbn <- readFile $ path ++ "jsbn/jsbn.js"
369− let runtime = header ++ included ++ jsbn ++ idrRuntime ++ tgtRuntime
372+ let runtime = ( header
373+ ++ includeLibs libs
374+ ++ included
375+ ++ jsbn
376+ ++ idrRuntime
377+ ++ tgtRuntime
378+ )
370379 writeFile filename $ runtime ++ concat code ++ main ++ invokeMain
371380 setPermissions filename (emptyPermissions { readable = True
372381 , executable = target == Node
373382 , writable = True
374383 })
375384 where
385+ includeLibs :: [String] -> String
386+ includeLibs =
387+ concatMap (\lib -> "var " ++ lib ++ " = require(\"" ++ lib ++"\");\n")
388+
376389 getIncludes :: [FilePath] -> IO [String]
377390 getIncludes = mapM readFile
378391