Repository navigation
Reinstate spago script command - #1416
tomatotomata wants to merge 1 commit into
Conversation
Signed-off-by: ahmad <ahmadalgaidy@hotmail.com>
| , statVerbosity: Nothing | ||
| , pure: false | ||
| } | ||
| runEnv <- runSpago env (mkRunEnv runArgs buildEnv (Just $ Path.toGlobal originalCwd)) |
There was a problem hiding this comment.
Can we make npm packages installed in the caller’s project available to the generated script? Setting executeDir preserves relative file operations, but Node resolves ESM package imports relative to the importing module, which is still under the temporary workspace.
I reproduced this with xhr2 installed in the caller directory and a script using affjax-node:
spago script --package-set 41.2.0 -d affjax-node npm-dependency.pursCompilation succeeds, but execution fails with ERR_MODULE_NOT_FOUND: Cannot find package 'xhr2'. Importing xhr2 directly from the caller directory works. Linking the caller’s node_modules into the temporary workspace also makes the same generated program run successfully.
Could we cover this case alongside the existing node-fs test? That test only needs Node built-ins, so it doesn’t catch package resolution.
| } | ||
| runEnv <- runSpago env (mkRunEnv runArgs buildEnv (Just $ Path.toGlobal originalCwd)) | ||
| runSpago runEnv Run.run | ||
| Paths.chdir originalCwd |
There was a problem hiding this comment.
Could we clean up tmpDir when the command finishes, including failure paths? mkTemp only generates a pathname; it doesn’t arrange cleanup. This branch restores the working directory without removing the workspace.
We'd need to account for the direct Process.exit calls on error paths as well; adding only an Aff finally around this block wouldn’t cover those exits.
Description of the change
Reinstates the
spago scriptcommand from the documented interface in issue #1000.The command accepts a standalone
Mainmodule, optional--package-set, and repeatable-d/--dependencyflags. It creates a temporary workspace for dependency resolution and compilation, then runs the generated program from the caller's directory so relative file operations behave as expected. The existing README already documents this interface.Checklist:
README(the existing example now works)Verification
purs-tidy checkpassed for the changed PureScript files.spago build -p spago-binpassed with zero warnings and errors.spago script -d node-fs test-fixtures/spago-script-make-file.purswroteHELLOin the caller's directory.purs graphinvocation failure before running the suite.Closes #1000