@@ -43,6 +43,8 @@ data ErrorMessage
4343 | UnableToParseModule String
4444 | UnsupportedExport
4545 | ErrorInModule ModuleIdentifier ErrorMessage
46+ | MissingEntryPoint String
47+ | MissingMainModule String
4648 deriving (Show)
4749
4850-- | Modules are either "regular modules" (i.e. those generated by psc) or foreign modules.
@@ -125,8 +127,14 @@ printErrorMessage (ErrorInModule mid e) =
125127 : ""
126128 : map (" " ++) (printErrorMessage e)
127129 where
128− displayIdentifier (ModuleIdentifier name ty) =
129− name ++ " (" ++ showModuleType ty ++ ")"
130+ displayIdentifier (ModuleIdentifier name ty) =
131+ name ++ " (" ++ showModuleType ty ++ ")"
132+printErrorMessage (MissingEntryPoint mName) =
133+ [ "Couldn't find a CommonJS module for the specified entry point: " ++ mName
134+ ]
135+printErrorMessage (MissingMainModule mName) =
136+ [ "Couldn't find a CommonJS module for the specified main module: " ++ mName
137+ ]
130138
131139-- | Calculate the ModuleIdentifier which a require(...) statement imports.
132140checkImportPath :: String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
@@ -609,6 +617,10 @@ bundle :: (MonadError ErrorMessage m)
609617 -> String -- ^ The namespace (e.g. PS).
610618 -> m String
611619bundle 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)))
612624 input <- forM inputStrs $ \(ident, js) -> do
613625 ast <- either (throwError . ErrorInModule ident . UnableToParseModule) pure $ parse js (moduleName ident)
614626 return (ident, ast)