@@ -22,7 +22,7 @@ import Node.ChildProcess.Types as StdIO
2222import Node.Path as NodePath
2323import Partial.Unsafe (unsafePartial )
2424import Spago.Generated.BuildInfo as BuildInfo
25- import Whine.Bootstrap.Execa (execResultSuccessOrDie , execSuccessOrDie_ , execa )
25+ import Whine.Bootstrap.Execa (execSuccessOrDie , execSuccessOrDie_ , execa )
2626import Whine.Bootstrap.Hash (hashString )
2727import Whine.Bootstrap.JsonCodecs as J
2828import Whine.Runner.Config (PackageSpec (..))
@@ -106,6 +106,7 @@ rebuildCache { rulePackages, bundleFile } = do
106106 let mainModule = " Main" <> unique
107107 packageName = " whine-cached-bootstrap"
108108 dependencies = Map .union rulePackages (uncurry Map .singleton whineCorePackage)
109+ entryPointFile = cacheDir <> " /src/Main.purs"
109110
110111 FS .mkDirP (cacheDir <> " /src" )
111112 FS .writeFile (cacheDir <> " /package.json" ) " {}"
@@ -150,15 +151,14 @@ rebuildCache { rulePackages, bundleFile } = do
150151 , " vscode-languageserver"
151152 , " vscode-languageserver-textdocument"
152153 ]
153- _
154- { cwd = Just cacheDir
155- , stdout = Just StdIO .pipe
156- , stderr = Just StdIO .pipe
157- }
154+ inCacheDirAndPipeOutputs
158155
159156 logSameLine " Making a pitiful face..."
160157 logDebug " Installed NPM dependencies"
161158
159+ whenM (FS .exists entryPointFile) $
160+ FS .unlink entryPointFile # tryOrDie
161+
162162 moduleGraphJson <- spagoGraphModules
163163 moduleGraph <- moduleGraphJson # JSON .parse # lmap DecodeError .basic >>= J .decode moduleGraphCodec # rightOrDie
164164 logDebug " Obtained dependency module graph"
@@ -176,18 +176,14 @@ rebuildCache { rulePackages, bundleFile } = do
176176 inferredModule = Map .lookup package candidateModules
177177 pure $ specifiedModule <|> inferredModule
178178
179- FS .writeFile (cacheDir <> " /src/Main.purs " ) $
179+ FS .writeFile entryPointFile $
180180 cachedBundleMainModule { moduleName: mainModule, ruleModules }
181181
182182 logSameLine " Revisiting complaints..."
183183 logDebug " Wrote executable entry point"
184184
185185 execSuccessOrDie_ " spago bundle" =<<
186- execa " npx" [" spago" , " bundle" , " --source-maps" ] _
187- { cwd = Just cacheDir
188- , stdout = Just StdIO .pipe
189- , stderr = Just StdIO .pipe
190- }
186+ execa " npx" [" spago" , " bundle" , " --source-maps" ] inCacheDirAndPipeOutputs
191187
192188 logSameLine " Done, ready to whine."
193189 logDebug " Bundled the executable"
@@ -203,30 +199,23 @@ rebuildCache { rulePackages, bundleFile } = do
203199 logInfo $ prefix <> msg
204200
205201 spagoGraphModules = do
206- proc <-
207- execa " npx" [" spago" , " graph" , " modules" , " --json" ] _
208- { cwd = Just cacheDir
209- , stdout = Just StdIO .pipe
210- , stderr = Just StdIO .pipe
211- }
212-
213- res <- liftAff proc.getResult
214-
215- unless (res.exitCode == Just 0 ) do
216- logDebug " 'spago graph modules' failed. Trying to build to see what the error was..."
217- FS .writeFile (cacheDir <> " /src/Main.purs" ) " module M where\n x = 42 :: Int"
218- execSuccessOrDie_ " spago build" =<<
219- execa " npx" [" spago" , " build" ] _
220- { cwd = Just cacheDir
221- , stdout = Just StdIO .pipe
222- , stderr = Just StdIO .pipe
223- }
224-
225- logDebug " Building succeeded, but 'spago graph modules' still failed."
226- execResultSuccessOrDie " spago graph modules" res
202+ -- First build to make sure all modules are fresh, in case we just
203+ -- overwrote a previous config that was somehow incompatible.
204+ execSuccessOrDie_ " spago build" =<<
205+ execa " npx" [" spago" , " build" ] inCacheDirAndPipeOutputs
206+
207+ -- Then get the module graph.
208+ res <- execSuccessOrDie " spago graph modules" =<<
209+ execa " npx" [" spago" , " graph" , " modules" , " --json" ] inCacheDirAndPipeOutputs
227210
228211 pure res.stdout
229212
213+ inCacheDirAndPipeOutputs = _
214+ { cwd = Just cacheDir
215+ , stdout = Just StdIO .pipe
216+ , stderr = Just StdIO .pipe
217+ }
218+
230219whineCorePackage :: { package :: String } /\ PackageSpec
231220whineCorePackage = { package: " whine-core" } /\ PackageVersion version
232221 where
0 commit comments