git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Allow a prefix to be specified for require() paths
75b0284Gary Burgess
psc-make/Main.hs+13−4
@@ -105,6 +105,12 @@ outputDirectory = strOption $
105 <> showDefault
105 <> showDefault
106 <> help "The output directory"
106 <> help "The output directory"
107
107
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+
108noTco :: Parser Bool
114noTco :: Parser Bool
109noTco = switch $
115noTco = switch $
110 long "no-tco"
116 long "no-tco"
@@ -113,18 +119,18 @@ noTco = switch $
113noMagicDo :: Parser Bool
119noMagicDo :: Parser Bool
114noMagicDo = switch $
120noMagicDo = switch $
115 long "no-magic-do"
121 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"
117
123
118noOpts :: Parser Bool
124noOpts :: Parser Bool
119noOpts = switch $
125noOpts = switch $
120 long "no-opts"
126 long "no-opts"
121− <> help "Skip the optimization phase."
127+ <> help "Skip the optimization phase"
122
128
123comments :: Parser Bool
129comments :: Parser Bool
124comments = switch $
130comments = switch $
125 short 'c'
131 short 'c'
126 <> long "comments"
132 <> long "comments"
127− <> help "Include comments in the generated code."
133+ <> help "Include comments in the generated code"
128
134
129verboseErrors :: Parser Bool
135verboseErrors :: Parser Bool
130verboseErrors = switch $
136verboseErrors = switch $
@@ -146,7 +152,10 @@ options = P.Options <$> noTco
146 <*> noOpts
152 <*> noOpts
147 <*> verboseErrors
153 <*> verboseErrors
148 <*> (not <$> comments)
154 <*> (not <$> comments)
155+ <*> additionalOptions
156+ where
157+ additionalOptions =
149− <*> pure P.MakeOptions
158+ P.MakeOptions <$> requirePath
150
159
151pscMakeOptions :: Parser PSCMakeOptions
160pscMakeOptions :: Parser PSCMakeOptions
152pscMakeOptions = PSCMakeOptions <$> many inputFile
161pscMakeOptions = PSCMakeOptions <$> many inputFile
psci/Make.hs+1−1
@@ -43,7 +43,7 @@ import qualified Language.PureScript.CoreFn as CF
43import IO (mkdirp)
43import IO (mkdirp)
44
44
45options :: P.Options P.Make
45options :: 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)
47
47
48modulesDir :: FilePath
48modulesDir :: FilePath
49modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
49modulesDir = ".psci_modules" ++ pathSeparator : "node_modules"
src/Language/PureScript/CodeGen/JS.hs+4−2
@@ -44,6 +44,8 @@ import Language.PureScript.Options
44import Language.PureScript.Traversals (sndM)
44import Language.PureScript.Traversals (sndM)
45import qualified Language.PureScript.Constants as C
45import qualified Language.PureScript.Constants as C
46
46
47+import System.FilePath.Posix ((</>))
48+
47-- |
49-- |
48-- Generate code in the simplified Javascript intermediate representation for all declarations in a
50-- Generate code in the simplified Javascript intermediate representation for all declarations in a
49-- module.
51-- module.
@@ -66,7 +68,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign = do
66 let exps' = JSObjectLiteral $ map (runIdent &&& JSVar . identToJs) standardExps
68 let exps' = JSObjectLiteral $ map (runIdent &&& JSVar . identToJs) standardExps
67 ++ map (runIdent &&& foreignIdent) foreignExps
69 ++ map (runIdent &&& foreignIdent) foreignExps
68 return $ case additional of
70 return $ case additional of
69− MakeOptions -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) exps']
71+ MakeOptions _ -> moduleBody ++ [JSAssignment (JSAccessor "exports" (JSVar "module")) exps']
70 CompileOptions ns _ _ | not isModuleEmpty ->
72 CompileOptions ns _ _ | not isModuleEmpty ->
71 [ JSVariableIntroduction ns
73 [ JSVariableIntroduction ns
72 (Just (JSBinary Or (JSVar ns) (JSObjectLiteral [])) )
74 (Just (JSBinary Or (JSVar ns) (JSObjectLiteral [])) )
@@ -84,7 +86,7 @@ moduleToJs (Module coms mn imps exps foreigns decls) foreign = do
84 importToJs mn' = do
86 importToJs mn' = do
85 additional <- asks optionsAdditional
87 additional <- asks optionsAdditional
86 let moduleBody = case additional of
88 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')]
88 CompileOptions ns _ _ -> JSAccessor (moduleNameToJs mn') (JSVar ns)
90 CompileOptions ns _ _ -> JSAccessor (moduleNameToJs mn') (JSVar ns)
89 return $ JSVariableIntroduction (moduleNameToJs mn') (Just moduleBody)
91 return $ JSVariableIntroduction (moduleNameToJs mn') (Just moduleBody)
90
92
src/Language/PureScript/Options.hs+5−2
@@ -27,7 +27,7 @@ data Mode = Compile | Make
27--
27--
28data ModeOptions mode where
28data ModeOptions mode where
29 CompileOptions :: String -> [String] -> [String] -> ModeOptions Compile
29 CompileOptions :: String -> [String] -> [String] -> ModeOptions Compile
30− MakeOptions :: ModeOptions Make
30+ MakeOptions :: Maybe FilePath -> ModeOptions Make
31
31
32browserNamespace :: ModeOptions Compile -> String
32browserNamespace :: ModeOptions Compile -> String
33browserNamespace (CompileOptions ns _ _) = ns
33browserNamespace (CompileOptions ns _ _) = ns
@@ -38,6 +38,9 @@ entryPointModules (CompileOptions _ ms _) = ms
38codeGenModules :: ModeOptions Compile -> [String]
38codeGenModules :: ModeOptions Compile -> [String]
39codeGenModules (CompileOptions _ _ ms) = ms
39codeGenModules (CompileOptions _ _ ms) = ms
40
40
41+requirePath :: ModeOptions Make -> Maybe FilePath
42+requirePath (MakeOptions mp) = mp
43+
41deriving instance Show (ModeOptions mode)
44deriving instance Show (ModeOptions mode)
42
45
43-- |
46-- |
@@ -85,4 +88,4 @@ defaultCompileOptions = Options False False Nothing False False False (CompileOp
85-- Default make options
88-- Default make options
86--
89--
87defaultMakeOptions :: Options Make
90defaultMakeOptions :: Options Make
88−defaultMakeOptions = Options False False Nothing False False False MakeOptions
91+defaultMakeOptions = Options False False Nothing False False False (MakeOptions Nothing)