git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
[psc-bundle] Verify entry points exist (#2286)

* [psc-bundle] Verify entry points exist Throws an error when an entry point could not be found in the input modules. * [psc-bundle] Also error on missing --main module * try to fix timeout on OS X instances

commitdf85f5c035b622038251e9531424a07a513bd948 authorChristoph Hegemann <kRITZCREEK@users.noreply.github.com> dateFri 26 Aug 2016, 06:06 (10 years ago) parentbdbf4e2
2 files changed+15−3
src/Language/PureScript/Bundle.hs+14−2 tests/Language/PureScript/Ide/Integration.hs+1−1
src/Language/PureScript/Bundle.hs+14−2
@@ -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)
tests/Language/PureScript/Ide/Integration.hs+1−1
@@ -95,7 +95,7 @@ compileTestProject = do
9595 pdir <- projectDirectory
9696 (_, _, _, procHandle) <- createProcess $
9797 (shell . toS $ "psc " <> fileGlob) { cwd = Just pdir }
98− r <- tryNTimes 5 (getProcessExitCode procHandle)
98+ r <- tryNTimes 10 (getProcessExitCode procHandle)
9999 pure (fromMaybe False (isSuccess <$> r))
100100
101101tryNTimes :: Int -> IO (Maybe a) -> IO (Maybe a)