git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
[psc-bundle] Verify entry points exist (#2286)
df85f5cChristoph Hegemann
src/Language/PureScript/Bundle.hs+14−2
@@ -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)
47
49
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) =
125 : ""
127 : ""
126 : map (" " ++) (printErrorMessage e)
128 : map (" " ++) (printErrorMessage e)
127 where
129 where
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
134+ ]
135+printErrorMessage (MissingMainModule mName) =
136+ [ "Couldn't find a CommonJS module for the specified main module: " ++ mName
137+ ]
130
138
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)
tests/Language/PureScript/Ide/Integration.hs+1−1
@@ -95,7 +95,7 @@ compileTestProject = do
95 pdir <- projectDirectory
95 pdir <- projectDirectory
96 (_, _, _, procHandle) <- createProcess $
96 (_, _, _, procHandle) <- createProcess $
97 (shell . toS $ "psc " <> fileGlob) { cwd = Just pdir }
97 (shell . toS $ "psc " <> fileGlob) { cwd = Just pdir }
98− r <- tryNTimes 5 (getProcessExitCode procHandle)
98+ r <- tryNTimes 10 (getProcessExitCode procHandle)
99 pure (fromMaybe False (isSuccess <$> r))
99 pure (fromMaybe False (isSuccess <$> r))
100
100
101tryNTimes :: Int -> IO (Maybe a) -> IO (Maybe a)
101tryNTimes :: Int -> IO (Maybe a) -> IO (Maybe a)