Skip to content

Commit a60f845

Browse files
authored
Remove the /bundle endpoint (#151)
This requires the server to keep a giant JS bundle in memory, and it's no longer necessary since individual modules are now loaded on demand.
1 parent ec85010 commit a60f845

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

server/Main.hs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import GHC.Generics (Generic)
3434
import qualified Language.PureScript as P
3535
import qualified Language.PureScript.CST as CST
3636
import qualified Language.PureScript.CST.Monad as CSTM
37-
import qualified Language.PureScript.Bundle as Bundle
3837
import qualified Language.PureScript.CodeGen.JS as J
3938
import qualified Language.PureScript.CodeGen.JS.Printer as P
4039
import qualified Language.PureScript.CoreFn as CF
@@ -60,8 +59,8 @@ data Error
6059

6160
instance A.ToJSON Error
6261

63-
server :: TL.Text -> [P.ExternsFile] -> P.Environment -> Int -> IO ()
64-
server bundled externs initEnv port = do
62+
server :: [P.ExternsFile] -> P.Environment -> Int -> IO ()
63+
server externs initEnv port = do
6564
let compile :: Text -> IO (Either Error ([P.JSONError], JS))
6665
compile input
6766
| T.length input > 20000 = return (Left (OtherError "Please limit your input to 20000 characters"))
@@ -92,10 +91,6 @@ server bundled externs initEnv port = do
9291
scotty port $ do
9392
get "/" $
9493
Scotty.text "POST api.purescript.org/compile"
95-
get "/bundle" $ do
96-
Scotty.setHeader "Access-Control-Allow-Origin" "*"
97-
Scotty.setHeader "Content-Type" "text/javascript"
98-
Scotty.text bundled
9994
post "/compile" $ do
10095
code <- T.decodeUtf8 . BL.toStrict <$> body
10196
response <- lift $ compile code
@@ -164,26 +159,15 @@ tryParseType = hush . fmap (CST.convertType "<file>") . runParser CST.parseTypeP
164159
. CST.runTokenParser (p <* CSTM.token CST.TokEof)
165160
. CST.lexTopLevel
166161

167-
bundle :: IO (Either Bundle.ErrorMessage String)
168-
bundle = runExceptT $ do
169-
inputFiles <- liftIO (glob (".psci_modules" </> "node_modules" </> "*" </> "*.js"))
170-
input <- for inputFiles $ \filename -> do
171-
js <- liftIO (readUTF8File filename)
172-
mid <- Bundle.guessModuleIdentifier filename
173-
length js `seq` return (mid, js)
174-
Bundle.bundle input [] Nothing "PS"
175-
176162
main :: IO ()
177163
main = do
178164
(portString : inputGlobs) <- getArgs
179165
let port = read portString
180166
inputFiles <- concat <$> traverse glob inputGlobs
181167
let onError f = either (Left . f) Right
182168
e <- runExceptT $ do
183-
modules <- ExceptT (fmap (onError Right) (I.loadAllModules inputFiles))
184-
(exts, env) <- ExceptT . fmap (onError Right) . I.runMake . I.make . map (second CST.pureResult) $ modules
185-
js <- ExceptT (fmap (onError Left) bundle)
186-
return (fromString js, exts, env)
169+
modules <- ExceptT $ I.loadAllModules inputFiles
170+
ExceptT . I.runMake . I.make $ map (second CST.pureResult) modules
187171
case e of
188172
Left err -> print err >> exitFailure
189-
Right (js, exts, env) -> server js exts env port
173+
Right (exts, env) -> server exts env port

0 commit comments

Comments
 (0)