git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1958 from nwolverson/requirepath

Default require path to ../, warn from psc

commit546809cbc318ebbcff7e16764ec32710090d1eaf authorGary Burgess <gary.burgess@gmail.com> dateWed 16 Mar 2016, 02:31 (11 years ago) parent5db88e455731aa
6 files changed+13−5
psc-bundle/Main.hs+2−2 psc/Main.hs+1−1 src/Language/PureScript/Bundle.hs+1−1 src/Language/PureScript/CodeGen/JS.hs+1−1 src/Language/PureScript/Errors.hs+5 src/Language/PureScript/Make.hs+3
psc-bundle/Main.hs+2−2
@@ -119,13 +119,13 @@ options = Options <$> some inputFile
119119 requirePath = strOption $
120120 short 'r'
121121 <> long "require-path"
122− <> Opts.value ""
123− <> help "The path prefix used in require() calls in the generated JavaScript"
122+ <> help "The path prefix used in require() calls in the generated JavaScript [deprecated]"
124123
125124-- | Make it go.
126125main :: IO ()
127126main = do
128127 opts <- execParser (info (version <*> helper <*> options) infoModList)
128+ when (optionsRequirePath opts /= Nothing) $ hPutStrLn stderr "The require-path option is deprecated and will be removed in PureScript 0.9."
129129 output <- runExceptT (app opts)
130130 case output of
131131 Left err -> do
psc/Main.hs+1−1
@@ -138,7 +138,7 @@ requirePath :: Parser (Maybe FilePath)
138138requirePath = optional $ strOption $
139139 short 'r'
140140 <> long "require-path"
141− <> help "The path prefix to use for require() calls in the generated JavaScript"
141+ <> help "The path prefix to use for require() calls in the generated JavaScript [deprecated]"
142142
143143noTco :: Parser Bool
144144noTco = switch $
src/Language/PureScript/Bundle.hs+1−1
@@ -141,7 +141,7 @@ checkImportPath :: Maybe FilePath -> String -> ModuleIdentifier -> S.Set String
141141checkImportPath _ "./foreign" m _ =
142142 Right (ModuleIdentifier (moduleName m) Foreign)
143143checkImportPath requirePath name _ names
144− | Just name' <- stripPrefix (fromMaybe "" requirePath) name
144+ | Just name' <- stripPrefix (fromMaybe "../" requirePath) name
145145 , name' `S.member` names = Right (ModuleIdentifier name' Regular)
146146checkImportPath _ name _ _ = Left name
147147
src/Language/PureScript/CodeGen/JS.hs+1−1
@@ -111,7 +111,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign_ =
111111 importToJs mnLookup mn' = do
112112 path <- asks optionsRequirePath
113113 let ((ss, _, _, _), mnSafe) = fromMaybe (internalError "Missing value in mnLookup") $ M.lookup mn' mnLookup
114− let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (maybe id (</>) path $ runModuleName mn')]
114+ let moduleBody = JSApp Nothing (JSVar Nothing "require") [JSStringLiteral Nothing (fromMaybe ".." path </> runModuleName mn')]
115115 withPos ss $ JSVariableIntroduction Nothing (moduleNameToJs mnSafe) (Just moduleBody)
116116
117117 -- |
src/Language/PureScript/Errors.hs+5
@@ -148,6 +148,7 @@ data SimpleErrorMessage
148148 | CaseBinderLengthDiffers Int [Binder]
149149 | IncorrectAnonymousArgument
150150 | InvalidOperatorInBinder Ident Ident
151+ | DeprecatedRequirePath
151152 deriving (Show)
152153
153154-- | Error message hints, providing more detailed information about failure.
@@ -328,6 +329,7 @@ errorCode em = case unwrapErrorMessage em of
328329 CaseBinderLengthDiffers{} -> "CaseBinderLengthDiffers"
329330 IncorrectAnonymousArgument -> "IncorrectAnonymousArgument"
330331 InvalidOperatorInBinder{} -> "InvalidOperatorInBinder"
332+ DeprecatedRequirePath{} -> "DeprecatedRequirePath"
331333
332334-- |
333335-- A stack trace for an error
@@ -975,6 +977,9 @@ prettyPrintSingleError full level showWiki e = flip evalState defaultUnknownMap
975977 , line "Only aliases for data constructors may be used in patterns."
976978 ]
977979
980+ renderSimpleErrorMessage DeprecatedRequirePath =
981+ line "The require-path option is deprecated and will be removed in PureScript 0.9."
982+
978983 renderHint :: ErrorMessageHint -> Box.Box -> Box.Box
979984 renderHint (ErrorUnifyingTypes t1 t2) detail =
980985 paras [ detail
src/Language/PureScript/Make.hs+3
@@ -150,6 +150,9 @@ make :: forall m. (Monad m, MonadBaseControl IO m, MonadReader Options m, MonadE
150150 -> [Module]
151151 -> m Environment
152152make MakeActions{..} ms = do
153+ requirePath <- asks optionsRequirePath
154+ when (requirePath /= Nothing) $ tell $ errorMessage DeprecatedRequirePath
155+
153156 checkModuleNamesAreUnique
154157
155158 (sorted, graph) <- sortModules ms