@@ -266,6 +266,17 @@ createTemporaryModuleForKind PSCiState{psciImportedModuleNames = imports} typ =
267 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
267 P.Module moduleName ((importDecl `map` imports) ++ [itDecl]) Nothing
270+-- Makes a volatile module to execute the current imports.
272+createTemporaryModuleForImports :: PSCiState -> P.Module
273+createTemporaryModuleForImports PSCiState{psciImportedModuleNames = imports} =
275+ moduleName = P.ModuleName [P.ProperName "$PSCI"]
276+ importDecl m = P.ImportDeclaration m P.Unqualified Nothing
278+ P.Module moduleName (importDecl `map` imports) Nothing
269modulesDir :: FilePath
280modulesDir :: FilePath
270modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
281modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
@@ -291,6 +302,20 @@ handleDeclaration value = do
291 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
302 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
292 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
303 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
306+-- Imports a module, preserving the initial state on failure.
308+handleImport :: P.ModuleName -> PSCI ()
309+handleImport moduleName = do
310+ s <- liftM (updateImports moduleName) $ PSCI $ lift get
311+ let m = createTemporaryModuleForImports s
312+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules s ++ [("$PSCI.purs", m)]) []
314+ Left err -> PSCI $ outputStrLn err
295-- Takes a value and prints its type
320-- Takes a value and prints its type
@@ -350,7 +375,7 @@ getCommand singleLineMode = do
350handleCommand :: Command -> PSCI ()
375handleCommand :: Command -> PSCI ()
351handleCommand (Expression val) = handleDeclaration val
376handleCommand (Expression val) = handleDeclaration val
352handleCommand Help = PSCI $ outputStrLn helpMessage
377handleCommand Help = PSCI $ outputStrLn helpMessage
353−handleCommand (Import moduleName) = PSCI $ lift $ modify (updateImports moduleName)
378+handleCommand (Import moduleName) = handleImport moduleName
354handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
379handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
355handleCommand (LoadFile filePath) = do
380handleCommand (LoadFile filePath) = do
356 absPath <- psciIO $ expandTilde filePath
381 absPath <- psciIO $ expandTilde filePath
@@ -438,4 +463,3 @@ termInfo = Cmd.defTI
439main :: IO ()
464main :: IO ()
440main = Cmd.run (term, termInfo)
465main = Cmd.run (term, termInfo)