File tree Expand file tree Collapse file tree 4 files changed +23
-9
lines changed
Expand file tree Collapse file tree 4 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -105,6 +105,12 @@ outputDirectory = strOption $
105105 <> showDefault
106106 <> help " The output directory"
107107
108+ requirePath :: Parser (Maybe FilePath )
109+ requirePath = optional $ strOption $
110+ short ' r'
111+ <> long " require-path"
112+ <> help " The path prefix to use for require() calls in the generated JavaScript"
113+
108114noTco :: Parser Bool
109115noTco = switch $
110116 long " no-tco"
@@ -113,18 +119,18 @@ noTco = switch $
113119noMagicDo :: Parser Bool
114120noMagicDo = switch $
115121 long " no-magic-do"
116- <> help " Disable the optimization that overloads the do keyword to generate efficient code specifically for the Eff monad. "
122+ <> help " Disable the optimization that overloads the do keyword to generate efficient code specifically for the Eff monad"
117123
118124noOpts :: Parser Bool
119125noOpts = switch $
120126 long " no-opts"
121- <> help " Skip the optimization phase. "
127+ <> help " Skip the optimization phase"
122128
123129comments :: Parser Bool
124130comments = switch $
125131 short ' c'
126132 <> long " comments"
127- <> help " Include comments in the generated code. "
133+ <> help " Include comments in the generated code"
128134
129135verboseErrors :: Parser Bool
130136verboseErrors = switch $
@@ -146,7 +152,10 @@ options = P.Options <$> noTco
146152 <*> noOpts
147153 <*> verboseErrors
148154 <*> (not <$> comments)
149- <*> pure P. MakeOptions
155+ <*> additionalOptions
156+ where
157+ additionalOptions =
158+ P. MakeOptions <$> requirePath
150159
151160pscMakeOptions :: Parser PSCMakeOptions
152161pscMakeOptions = PSCMakeOptions <$> many inputFile
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ import qualified Language.PureScript.CoreFn as CF
4343import IO (mkdirp )
4444
4545options :: P. Options P. Make
46- options = P. Options False False Nothing False False False P. MakeOptions
46+ options = P. Options False False Nothing False False False ( P. MakeOptions Nothing )
4747
4848modulesDir :: FilePath
4949modulesDir = " .psci_modules" ++ pathSeparator : " node_modules"
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ import Language.PureScript.Options
4444import Language.PureScript.Traversals (sndM )
4545import qualified Language.PureScript.Constants as C
4646
47+ import System.FilePath.Posix ((</>) )
48+
4749-- |
4850-- Generate code in the simplified Javascript intermediate representation for all declarations in a
4951-- module.
@@ -66,7 +68,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign = do
6668 let exps' = JSObjectLiteral $ map (runIdent &&& JSVar . identToJs) standardExps
6769 ++ map (runIdent &&& foreignIdent) foreignExps
6870 return $ case additional of
69- MakeOptions -> moduleBody ++ [JSAssignment (JSAccessor " exports" (JSVar " module" )) exps']
71+ MakeOptions _ -> moduleBody ++ [JSAssignment (JSAccessor " exports" (JSVar " module" )) exps']
7072 CompileOptions ns _ _ | not isModuleEmpty ->
7173 [ JSVariableIntroduction ns
7274 (Just (JSBinary Or (JSVar ns) (JSObjectLiteral [] )) )
@@ -84,7 +86,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign = do
8486 importToJs mn' = do
8587 additional <- asks optionsAdditional
8688 let moduleBody = case additional of
87- MakeOptions -> JSApp (JSVar " require" ) [JSStringLiteral (runModuleName mn')]
89+ MakeOptions path -> JSApp (JSVar " require" ) [JSStringLiteral (maybe id (</>) path $ runModuleName mn')]
8890 CompileOptions ns _ _ -> JSAccessor (moduleNameToJs mn') (JSVar ns)
8991 return $ JSVariableIntroduction (moduleNameToJs mn') (Just moduleBody)
9092
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ data Mode = Compile | Make
2727--
2828data ModeOptions mode where
2929 CompileOptions :: String -> [String ] -> [String ] -> ModeOptions Compile
30- MakeOptions :: ModeOptions Make
30+ MakeOptions :: Maybe FilePath -> ModeOptions Make
3131
3232browserNamespace :: ModeOptions Compile -> String
3333browserNamespace (CompileOptions ns _ _) = ns
@@ -38,6 +38,9 @@ entryPointModules (CompileOptions _ ms _) = ms
3838codeGenModules :: ModeOptions Compile -> [String ]
3939codeGenModules (CompileOptions _ _ ms) = ms
4040
41+ requirePath :: ModeOptions Make -> Maybe FilePath
42+ requirePath (MakeOptions mp) = mp
43+
4144deriving instance Show (ModeOptions mode )
4245
4346-- |
@@ -85,4 +88,4 @@ defaultCompileOptions = Options False False Nothing False False False (CompileOp
8588-- Default make options
8689--
8790defaultMakeOptions :: Options Make
88- defaultMakeOptions = Options False False Nothing False False False MakeOptions
91+ defaultMakeOptions = Options False False Nothing False False False ( MakeOptions Nothing )
You can’t perform that action at this time.
0 commit comments