Skip to content

Reinstate spago script command - #1416

Draft
tomatotomata wants to merge 1 commit into
purescript:masterfrom
tomatotomata:codex/spago-script
Draft

tomatotomata wants to merge 1 commit into
purescript:masterfrom
tomatotomata:codex/spago-script

Conversation

@tomatotomata

Copy link
Copy Markdown

Description of the change

Reinstates the spago script command from the documented interface in issue #1000.

The command accepts a standalone Main module, optional --package-set, and repeatable -d/--dependency flags. 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:

  • Added the change to the "Unreleased" section of the changelog
  • Added some example of the new feature to the README (the existing example now works)
  • Added a test for the contribution

Verification

  • purs-tidy check passed for the changed PureScript files.
  • spago build -p spago-bin passed with zero warnings and errors.
  • The focused Windows smoke test passed: spago script -d node-fs test-fixtures/spago-script-make-file.purs wrote HELLO in the caller's directory.
  • The full test command currently reaches the existing Windows purs graph invocation failure before running the suite.

Closes #1000

Signed-off-by: ahmad <ahmadalgaidy@hotmail.com>
Comment thread bin/src/Main.purs
, statVerbosity: Nothing
, pure: false
}
runEnv <- runSpago env (mkRunEnv runArgs buildEnv (Just $ Path.toGlobal originalCwd))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.purs

Compilation 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.

Comment thread bin/src/Main.purs
}
runEnv <- runSpago env (mkRunEnv runArgs buildEnv (Just $ Path.toGlobal originalCwd))
runSpago runEnv Run.run
Paths.chdir originalCwd

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reinstate spago script

2 participants