git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove --require-path completely, merge #1996
commitb34f5f94387d21f9ee81d0ad581c5c063be2abea authorPhil Freeman <paf31@cantab.net> dateSat 30 Apr 2016, 14:33 (11 years ago) parent5aaf615
6 files changed+18−44
psc-bundle/Main.hs+1−11 psc/Main.hs−7 src/Language/PureScript/Bundle.hs+14−16 src/Language/PureScript/CodeGen/JS.hs+1−2 src/Language/PureScript/Make.hs+1−4 src/Language/PureScript/Options.hs+1−4
psc-bundle/Main.hs+1−11
@@ -6,7 +6,6 @@
66-- | Bundles compiled PureScript modules for the browser.
77module Main (main) where
88
9−import Data.Maybe
109import Data.Traversable (for)
1110import Data.Version (showVersion)
1211
@@ -36,7 +35,6 @@ data Options = Options
3635 , optionsEntryPoints :: [String]
3736 , optionsMainModule :: Maybe String
3837 , optionsNamespace :: String
39− , optionsRequirePath :: Maybe FilePath
4038 } deriving Show
4139
4240-- | Given a filename, assuming it is in the correct place on disk, infer a ModuleIdentifier.
@@ -63,7 +61,7 @@ app Options{..} = do
6361
6462 let entryIds = map (`ModuleIdentifier` Regular) optionsEntryPoints
6563
66− bundle input entryIds optionsMainModule optionsNamespace optionsRequirePath
64+ bundle input entryIds optionsMainModule optionsNamespace
6765
6866-- | Command line options parser.
6967options :: Parser Options
@@ -72,7 +70,6 @@ options = Options <$> some inputFile
7270 <*> many entryPoint
7371 <*> optional mainModule
7472 <*> namespace
75− <*> optional requirePath
7673 where
7774 inputFile :: Parser FilePath
7875 inputFile = strArgument $
@@ -104,19 +101,12 @@ options = Options <$> some inputFile
104101 <> showDefault
105102 <> help "Specify the namespace that PureScript modules will be exported to when running in the browser."
106103
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−
113104-- | Make it go.
114105main :: IO ()
115106main = do
116107 hSetEncoding stdout utf8
117108 hSetEncoding stderr utf8
118109 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."
120110 output <- runExceptT (app opts)
121111 case output of
122112 Left err -> do
psc/Main.hs−7
@@ -119,12 +119,6 @@ outputDirectory = strOption $
119119 <> showDefault
120120 <> help "The output directory"
121121
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−
128122noTco :: Parser Bool
129123noTco = switch $
130124 long "no-tco"
@@ -175,7 +169,6 @@ options = P.Options <$> noTco
175169 <*> noOpts
176170 <*> verboseErrors
177171 <*> (not <$> comments)
178− <*> requirePath
179172 <*> sourceMaps
180173
181174pscMakeOptions :: Parser PSCMakeOptions
src/Language/PureScript/Bundle.hs+14−16
@@ -34,7 +34,7 @@ import Prelude ()
3434import Prelude.Compat
3535
3636import Data.List (nub, stripPrefix)
37−import Data.Maybe (mapMaybe, catMaybes, fromMaybe)
37+import Data.Maybe (mapMaybe, catMaybes)
3838import Data.Generics (everything, everywhere, mkQ, mkT)
3939import Data.Graph
4040import Data.Version (showVersion)
@@ -134,13 +134,13 @@ printErrorMessage (ErrorInModule mid e) =
134134 name ++ " (" ++ showModuleType ty ++ ")"
135135
136136-- | Calculate the ModuleIdentifier which a require(...) statement imports.
137−checkImportPath :: Maybe FilePath -> String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
138−checkImportPath _ "./foreign" m _ =
137+checkImportPath :: String -> ModuleIdentifier -> S.Set String -> Either String ModuleIdentifier
138+checkImportPath "./foreign" m _ =
139139 Right (ModuleIdentifier (moduleName m) Foreign)
140−checkImportPath requirePath name _ names
141− | Just name' <- stripPrefix (fromMaybe "../" requirePath) name
140+checkImportPath name _ names
141+ | Just name' <- stripPrefix "../" name
142142 , name' `S.member` names = Right (ModuleIdentifier name' Regular)
143−checkImportPath _ name _ _ = Left name
143+checkImportPath name _ _ = Left name
144144
145145-- | Compute the dependencies of all elements in a module, and add them to the tree.
146146--
@@ -222,8 +222,8 @@ trailingCommaList (JSCTLNone l) = commaList l
222222--
223223-- Each type of module element is matched using pattern guards, and everything else is bundled into the
224224-- Other constructor.
225−toModule :: forall m. (MonadError ErrorMessage m) => Maybe FilePath -> S.Set String -> ModuleIdentifier -> JSAST -> m Module
226−toModule requirePath mids mid top
225+toModule :: forall m. (MonadError ErrorMessage m) => S.Set String -> ModuleIdentifier -> JSAST -> m Module
226+toModule mids mid top
227227 | JSAstProgram smts _ <- top = Module mid <$> traverse toModuleElement smts
228228 | otherwise = err InvalidTopLevel
229229 where
@@ -231,7 +231,7 @@ toModule requirePath mids mid top
231231
232232 toModuleElement :: JSStatement -> m ModuleElement
233233 toModuleElement stmt
234− | Just (importName, importPath) <- matchRequire requirePath mids mid stmt
234+ | Just (importName, importPath) <- matchRequire mids mid stmt
235235 = pure (Require stmt importName importPath)
236236 toModuleElement stmt
237237 | Just (exported, name, decl) <- matchMember stmt
@@ -291,12 +291,11 @@ getExportedIdentifiers mname top
291291
292292-- Matches JS statements like this:
293293-- var ModuleName = require("file");
294−matchRequire :: Maybe FilePath
295− -> S.Set String
294+matchRequire :: S.Set String
296295 -> ModuleIdentifier
297296 -> JSStatement
298297 -> Maybe (String, Either String ModuleIdentifier)
299−matchRequire requirePath mids mid stmt
298+matchRequire mids mid stmt
300299 | JSVariable _ jsInit _ <- stmt
301300 , [JSVarInitExpression var varInit] <- commaList jsInit
302301 , JSIdentifier _ importName <- var
@@ -304,7 +303,7 @@ matchRequire requirePath mids mid stmt
304303 , JSMemberExpression req _ argsE _ <- jsInitEx
305304 , JSIdentifier _ "require" <- req
306305 , [ Just importPath ] <- map fromStringLiteral (commaList argsE)
307− , importPath' <- checkImportPath requirePath importPath mid mids
306+ , importPath' <- checkImportPath importPath mid mids
308307 = Just (importName, importPath')
309308 | otherwise
310309 = Nothing
@@ -590,16 +589,15 @@ bundle :: (MonadError ErrorMessage m)
590589 -> [ModuleIdentifier] -- ^ Entry points. These module identifiers are used as the roots for dead-code elimination
591590 -> Maybe String -- ^ An optional main module.
592591 -> String -- ^ The namespace (e.g. PS).
593− -> Maybe FilePath -- ^ The require path prefix
594592 -> m String
595−bundle inputStrs entryPoints mainModule namespace requirePath = do
593+bundle inputStrs entryPoints mainModule namespace = do
596594 input <- forM inputStrs $ \(ident, js) -> do
597595 ast <- either (throwError . ErrorInModule ident . UnableToParseModule) pure $ parse js (moduleName ident)
598596 return (ident, ast)
599597
600598 let mids = S.fromList (map (moduleName . fst) input)
601599
602− modules <- traverse (fmap withDeps . uncurry (toModule requirePath mids)) input
600+ modules <- traverse (fmap withDeps . uncurry (toModule mids)) input
603601
604602 let compiled = compile modules entryPoints
605603 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_ =
109109 --
110110 importToJs :: M.Map ModuleName (Ann, ModuleName) -> ModuleName -> m JS
111111 importToJs mnLookup mn' = do
112− path <- asks optionsRequirePath
113112 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')]
115114 withPos ss $ JSVariableIntroduction Nothing (moduleNameToJs mnSafe) (Just moduleBody)
116115
117116 -- |
src/Language/PureScript/Make.hs+1−4
@@ -42,7 +42,7 @@ import Control.Monad.Trans.Control (MonadBaseControl(..))
4242import Control.Concurrent.Lifted as C
4343
4444import Data.List (foldl', sort)
45−import Data.Maybe (fromMaybe, catMaybes, isJust)
45+import Data.Maybe (fromMaybe, catMaybes)
4646import Data.Either (partitionEithers)
4747import Data.Time.Clock
4848import Data.String (fromString)
@@ -181,9 +181,6 @@ make :: forall m. (Monad m, MonadBaseControl IO m, MonadReader Options m, MonadE
181181 -> [Module]
182182 -> m Environment
183183make ma@MakeActions{..} ms = do
184− requirePath <- asks optionsRequirePath
185− when (isJust requirePath) $ tell $ errorMessage DeprecatedRequirePath
186−
187184 checkModuleNamesAreUnique
188185
189186 (sorted, graph) <- sortModules ms
src/Language/PureScript/Options.hs+1−4
@@ -38,9 +38,6 @@ data Options = Options {
3838 -- |
3939 -- Remove the comments from the generated js
4040 , optionsNoComments :: Bool
41− -- |
42− -- The path to prepend to require statements
43− , optionsRequirePath :: Maybe FilePath
4441 -- |
4542 -- Generate soure maps
4643 , optionsSourceMaps :: Bool
@@ -49,4 +46,4 @@ data Options = Options {
4946-- |
5047-- Default make options
5148defaultOptions :: Options
52−defaultOptions = Options False False Nothing False False False Nothing False
49+defaultOptions = Options False False Nothing False False False False