@@ -43,6 +43,8 @@ data ErrorMessage
43 | UnableToParseModule String
43 | UnableToParseModule String
44 | UnsupportedExport
44 | UnsupportedExport
45 | ErrorInModule ModuleIdentifier ErrorMessage
45 | ErrorInModule ModuleIdentifier ErrorMessage
46+ | MissingEntryPoint String
47+ | MissingMainModule String
46 deriving (Show)
48 deriving (Show)
48-- | Modules are either "regular modules" (i.e. those generated by psc) or foreign modules.
50-- | Modules are either "regular modules" (i.e. those generated by psc) or foreign modules.
@@ -125,8 +127,14 @@ printErrorMessage (ErrorInModule mid e) =
126 : map (" " ++) (printErrorMessage e)
128 : map (" " ++) (printErrorMessage e)
128− displayIdentifier (ModuleIdentifier name ty) =
130+ displayIdentifier (ModuleIdentifier name ty) =
129− name ++ " (" ++ showModuleType ty ++ ")"
131+ name ++ " (" ++ showModuleType ty ++ ")"
132+printErrorMessage (MissingEntryPoint mName) =
133+ [ "Couldn't find a CommonJS module for the specified entry point: " ++ mName
135+printErrorMessage (MissingMainModule mName) =
136+ [ "Couldn't find a CommonJS module for the specified main module: " ++ mName
131-- | Calculate the ModuleIdentifier which a require(...) statement imports.
139-- | Calculate the ModuleIdentifier which a require(...) statement imports.
132checkImportPath :: String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
140checkImportPath :: String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
@@ -609,6 +617,10 @@ bundle :: (MonadError ErrorMessage m)
609 -> String -- ^ The namespace (e.g. PS).
617 -> String -- ^ The namespace (e.g. PS).
610 -> m String
618 -> m String
611bundle inputStrs entryPoints mainModule namespace = do
619bundle inputStrs entryPoints mainModule namespace = do
620+ forM_ mainModule $ \mname ->
621+ when (mname `notElem` map (moduleName . fst) inputStrs) (throwError (MissingMainModule mname))
622+ forM_ entryPoints $ \mIdent ->
623+ when (mIdent `notElem` map fst inputStrs) (throwError (MissingEntryPoint (moduleName mIdent)))
612 input <- forM inputStrs $ \(ident, js) -> do
624 input <- forM inputStrs $ \(ident, js) -> do
613 ast <- either (throwError . ErrorInModule ident . UnableToParseModule) pure $ parse js (moduleName ident)
625 ast <- either (throwError . ErrorInModule ident . UnableToParseModule) pure $ parse js (moduleName ident)
614 return (ident, ast)
626 return (ident, ast)