git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove --require-path completely, merge #1996
b34f5f9Phil Freeman
psc-bundle/Main.hs+1−11
@@ -6,7 +6,6 @@
6-- | Bundles compiled PureScript modules for the browser.
6-- | Bundles compiled PureScript modules for the browser.
7module Main (main) where
7module Main (main) where
8
8
9−import Data.Maybe
10import Data.Traversable (for)
9import Data.Traversable (for)
11import Data.Version (showVersion)
10import Data.Version (showVersion)
12
11
@@ -36,7 +35,6 @@ data Options = Options
36 , optionsEntryPoints :: [String]
35 , optionsEntryPoints :: [String]
37 , optionsMainModule :: Maybe String
36 , optionsMainModule :: Maybe String
38 , optionsNamespace :: String
37 , optionsNamespace :: String
39− , optionsRequirePath :: Maybe FilePath
40 } deriving Show
38 } deriving Show
41
39
42-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
40-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
@@ -63,7 +61,7 @@ app Options{..} = do
63
61
64 let entryIds = map (`ModuleIdentifier` Regular) optionsEntryPoints
62 let entryIds = map (`ModuleIdentifier` Regular) optionsEntryPoints
65
63
66− bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
64+ bundle input entryIds optionsMainModule optionsNamespace
67
65
68-- | Command line options parser.
66-- | Command line options parser.
69options :: Parser Options
67options :: Parser Options
@@ -72,7 +70,6 @@ options = Options <$> some inputFile
72 <*> many entryPoint
70 <*> many entryPoint
73 <*> optional mainModule
71 <*> optional mainModule
74 <*> namespace
72 <*> namespace
75− <*> optional requirePath
76 where
73 where
77 inputFile :: Parser FilePath
74 inputFile :: Parser FilePath
78 inputFile = strArgument $
75 inputFile = strArgument $
@@ -104,19 +101,12 @@ options = Options <$> some inputFile
104 <> showDefault
101 <> showDefault
105 <> help "Specify the namespace that PureScript modules will be exported to when running in the browser."
102 <> help "Specify the namespace that PureScript modules will be exported to when running in the browser."
106
103
107− requirePath :: Parser FilePath
108− requirePath = strOption $
109− short 'r'
110− <> long "require-path"
111− <> help "The path prefix used in require() calls in the generated JavaScript [deprecated]"
112−
113-- | Make it go.
104-- | Make it go.
114main :: IO ()
105main :: IO ()
115main = do
106main = do
116 hSetEncoding stdout utf8
107 hSetEncoding stdout utf8
117 hSetEncoding stderr utf8
108 hSetEncoding stderr utf8
118 opts <- execParser (info (version <*> helper <*> options) infoModList)
109 opts <- execParser (info (version <*> helper <*> options) infoModList)
119− when (isJust (optionsRequirePath opts)) $ hPutStrLn stderr "The require-path option is deprecated and will be removed in PureScript 0.9."
120 output <- runExceptT (app opts)
110 output <- runExceptT (app opts)
121 case output of
111 case output of
122 Left err -> do
112 Left err -> do
psc/Main.hs−7
@@ -119,12 +119,6 @@ outputDirectory = strOption $
119 <> showDefault
119 <> showDefault
120 <> help "The output directory"
120 <> help "The output directory"
121
121
122−requirePath :: Parser (Maybe FilePath)
123−requirePath = optional $ strOption $
124− short 'r'
125− <> long "require-path"
126− <> help "The path prefix to use for require() calls in the generated JavaScript [deprecated]"
127−
128noTco :: Parser Bool
122noTco :: Parser Bool
129noTco = switch $
123noTco = switch $
130 long "no-tco"
124 long "no-tco"
@@ -175,7 +169,6 @@ options = P.Options <$> noTco
175 <*> noOpts
169 <*> noOpts
176 <*> verboseErrors
170 <*> verboseErrors
177 <*> (not <$> comments)
171 <*> (not <$> comments)
178− <*> requirePath
179 <*> sourceMaps
172 <*> sourceMaps
180
173
181pscMakeOptions :: Parser PSCMakeOptions
174pscMakeOptions :: Parser PSCMakeOptions
src/Language/PureScript/Bundle.hs+14−16
@@ -34,7 +34,7 @@ import Prelude ()
34import Prelude.Compat
34import Prelude.Compat
35
35
36import Data.List (nub, stripPrefix)
36import Data.List (nub, stripPrefix)
37−import Data.Maybe (mapMaybe, catMaybes, fromMaybe)
37+import Data.Maybe (mapMaybe, catMaybes)
38import Data.Generics (everything, everywhere, mkQ, mkT)
38import Data.Generics (everything, everywhere, mkQ, mkT)
39import Data.Graph
39import Data.Graph
40import Data.Version (showVersion)
40import Data.Version (showVersion)
@@ -134,13 +134,13 @@ printErrorMessage (ErrorInModule mid e) =
134 name ++ " (" ++ showModuleType ty ++ ")"
134 name ++ " (" ++ showModuleType ty ++ ")"
135
135
136-- | Calculate the ModuleIdentifier which a require(...) statement imports.
136-- | Calculate the ModuleIdentifier which a require(...) statement imports.
137−checkImportPath :: Maybe FilePath -> String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
137+checkImportPath :: String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
138−checkImportPath _ "./foreign" m _ =
138+checkImportPath "./foreign" m _ =
139 Right (ModuleIdentifier (moduleName m) Foreign)
139 Right (ModuleIdentifier (moduleName m) Foreign)
140−checkImportPath requirePath name _ names
140+checkImportPath name _ names
141− | Just name' <- stripPrefix (fromMaybe "../" requirePath) name
141+ | Just name' <- stripPrefix "../" name
142 , name' `S.member` names = Right (ModuleIdentifier name' Regular)
142 , name' `S.member` names = Right (ModuleIdentifier name' Regular)
143−checkImportPath _ name _ _ = Left name
143+checkImportPath name _ _ = Left name
144
144
145-- | Compute the dependencies of all elements in a module, and add them to the tree.
145-- | Compute the dependencies of all elements in a module, and add them to the tree.
146--
146--
@@ -222,8 +222,8 @@ trailingCommaList (JSCTLNone l) = commaList l
222--
222--
223-- Each type of module element is matched using pattern guards, and everything else is bundled into the
223-- Each type of module element is matched using pattern guards, and everything else is bundled into the
224-- Other constructor.
224-- Other constructor.
225−toModule :: forall m. (MonadError ErrorMessage m) => Maybe FilePath -> S.Set String -> ModuleIdentifier -> JSAST -> m Module
225+toModule :: forall m. (MonadError ErrorMessage m) => S.Set String -> ModuleIdentifier -> JSAST -> m Module
226−toModule requirePath mids mid top
226+toModule mids mid top
227 | JSAstProgram smts _ <- top = Module mid <$> traverse toModuleElement smts
227 | JSAstProgram smts _ <- top = Module mid <$> traverse toModuleElement smts
228 | otherwise = err InvalidTopLevel
228 | otherwise = err InvalidTopLevel
229 where
229 where
@@ -231,7 +231,7 @@ toModule requirePath mids mid top
231
231
232 toModuleElement :: JSStatement -> m ModuleElement
232 toModuleElement :: JSStatement -> m ModuleElement
233 toModuleElement stmt
233 toModuleElement stmt
234− | Just (importName, importPath) <- matchRequire requirePath mids mid stmt
234+ | Just (importName, importPath) <- matchRequire mids mid stmt
235 = pure (Require stmt importName importPath)
235 = pure (Require stmt importName importPath)
236 toModuleElement stmt
236 toModuleElement stmt
237 | Just (exported, name, decl) <- matchMember stmt
237 | Just (exported, name, decl) <- matchMember stmt
@@ -291,12 +291,11 @@ getExportedIdentifiers mname top
291
291
292-- Matches JS statements like this:
292-- Matches JS statements like this:
293-- var ModuleName = require("file");
293-- var ModuleName = require("file");
294−matchRequire :: Maybe FilePath
295− -> S.Set String
294+matchRequire :: S.Set String
296 -> ModuleIdentifier
295 -> ModuleIdentifier
297 -> JSStatement
296 -> JSStatement
298 -> Maybe (String, Either String ModuleIdentifier)
297 -> Maybe (String, Either String ModuleIdentifier)
299−matchRequire requirePath mids mid stmt
298+matchRequire mids mid stmt
300 | JSVariable _ jsInit _ <- stmt
299 | JSVariable _ jsInit _ <- stmt
301 , [JSVarInitExpression var varInit] <- commaList jsInit
300 , [JSVarInitExpression var varInit] <- commaList jsInit
302 , JSIdentifier _ importName <- var
301 , JSIdentifier _ importName <- var
@@ -304,7 +303,7 @@ matchRequire requirePath mids mid stmt
304 , JSMemberExpression req _ argsE _ <- jsInitEx
303 , JSMemberExpression req _ argsE _ <- jsInitEx
305 , JSIdentifier _ "require" <- req
304 , JSIdentifier _ "require" <- req
306 , [ Just importPath ] <- map fromStringLiteral (commaList argsE)
305 , [ Just importPath ] <- map fromStringLiteral (commaList argsE)
307− , importPath' <- checkImportPath requirePath importPath mid mids
306+ , importPath' <- checkImportPath importPath mid mids
308 = Just (importName, importPath')
307 = Just (importName, importPath')
309 | otherwise
308 | otherwise
310 = Nothing
309 = Nothing
@@ -590,16 +589,15 @@ bundle :: (MonadError ErrorMessage m)
590 -> [ModuleIdentifier] -- ^ Entry points. These module identifiers are used as the roots for dead-code elimination
589 -> [ModuleIdentifier] -- ^ Entry points. These module identifiers are used as the roots for dead-code elimination
591 -> Maybe String -- ^ An optional main module.
590 -> Maybe String -- ^ An optional main module.
592 -> String -- ^ The namespace (e.g. PS).
591 -> String -- ^ The namespace (e.g. PS).
593− -> Maybe FilePath -- ^ The require path prefix
594 -> m String
592 -> m String
595−bundle inputStrs entryPoints mainModule namespace requirePath = do
593+bundle inputStrs entryPoints mainModule namespace = do
596 input <- forM inputStrs $ \(ident, js) -> do
594 input <- forM inputStrs $ \(ident, js) -> do
597 ast <- either (throwError . ErrorInModule ident . UnableToParseModule) pure $ parse js (moduleName ident)
595 ast <- either (throwError . ErrorInModule ident . UnableToParseModule) pure $ parse js (moduleName ident)
598 return (ident, ast)
596 return (ident, ast)
599
597
600 let mids = S.fromList (map (moduleName . fst) input)
598 let mids = S.fromList (map (moduleName . fst) input)
601
599
602− modules <- traverse (fmap withDeps . uncurry (toModule requirePath mids)) input
600+ modules <- traverse (fmap withDeps . uncurry (toModule mids)) input
603
601
604 let compiled = compile modules entryPoints
602 let compiled = compile modules entryPoints
605 sorted = sortModules (filter (not . isModuleEmpty) compiled)
603 sorted = sortModules (filter (not . isModuleEmpty) compiled)
src/Language/PureScript/CodeGen/JS.hs+1−2
@@ -109,9 +109,8 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
109 --
109 --
110 importToJs :: M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m JS
110 importToJs :: M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m JS
111 importToJs mnLookup mn' = do
111 importToJs mnLookup mn' = do
112− path <- asks optionsRequirePath
113 let ((ss, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
112 let ((ss, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
114− let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (fromMaybe ".." path </> runModuleName mn')]
113+ let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (".." </> runModuleName mn')]
115 withPos ss $ JSVariableIntroduction Nothing (moduleNameToJs mnSafe) (Just moduleBody)
114 withPos ss $ JSVariableIntroduction Nothing (moduleNameToJs mnSafe) (Just moduleBody)
116
115
117 -- |
116 -- |
src/Language/PureScript/Make.hs+1−4
@@ -42,7 +42,7 @@ import Control.Monad.Trans.Control (MonadBaseControl(..))
42import Control.Concurrent.Lifted as C
42import Control.Concurrent.Lifted as C
43
43
44import Data.List (foldl', sort)
44import Data.List (foldl', sort)
45−import Data.Maybe (fromMaybe, catMaybes, isJust)
45+import Data.Maybe (fromMaybe, catMaybes)
46import Data.Either (partitionEithers)
46import Data.Either (partitionEithers)
47import Data.Time.Clock
47import Data.Time.Clock
48import Data.String (fromString)
48import Data.String (fromString)
@@ -181,9 +181,6 @@ make :: forall m. (Monad m, MonadBaseControl IO m, MonadReader Options m, MonadE
181 -> [Module]
181 -> [Module]
182 -> m Environment
182 -> m Environment
183make ma@MakeActions{..} ms = do
183make ma@MakeActions{..} ms = do
184− requirePath <- asks optionsRequirePath
185− when (isJust requirePath) $ tell $ errorMessage DeprecatedRequirePath
186−
187 checkModuleNamesAreUnique
184 checkModuleNamesAreUnique
188
185
189 (sorted, graph) <- sortModules ms
186 (sorted, graph) <- sortModules ms
src/Language/PureScript/Options.hs+1−4
@@ -38,9 +38,6 @@ data Options = Options {
38 -- |
38 -- |
39 -- Remove the comments from the generated js
39 -- Remove the comments from the generated js
40 , optionsNoComments :: Bool
40 , optionsNoComments :: Bool
41− -- |
42− -- The path to prepend to require statements
43− , optionsRequirePath :: Maybe FilePath
44 -- |
41 -- |
45 -- Generate soure maps
42 -- Generate soure maps
46 , optionsSourceMaps :: Bool
43 , optionsSourceMaps :: Bool
@@ -49,4 +46,4 @@ data Options = Options {
49-- |
46-- |
50-- Default make options
47-- Default make options
51defaultOptions :: Options
48defaultOptions :: Options
52−defaultOptions = Options False False Nothing False False False Nothing False
49+defaultOptions = Options False False Nothing False False False False