Skip to content

Conversation

@Gedochao
Copy link
Contributor

@Gedochao Gedochao commented Dec 4, 2025

Fixes #3964

@Gedochao Gedochao marked this pull request as ready for review December 5, 2025 07:34
@Gedochao Gedochao requested review from tgodzik and zielinsky December 5, 2025 07:34
@Gedochao
Copy link
Contributor Author

Gedochao commented Dec 5, 2025

Random question - @sjrd is what I do here a good idea?
We've been sort of arbitrarily assuming there's a main.js during linking (which there is, if there's a main method).
I guess we could try to parse what the defined module is with scalameta... and then use whatever we find?
What I do right now is look for a <module>.js in the linking directory, blindly.

@sjrd
Copy link

sjrd commented Dec 5, 2025

That's what the Report returned by Linker.link is supposed to be for. It tells you the set of modules that it produced.

But I'm not sure what you're even trying to achieve here. What is the expected result of that function?

@Gedochao
Copy link
Contributor Author

Gedochao commented Dec 8, 2025

That's what the Report returned by Linker.link is supposed to be for. It tells you the set of modules that it produced.

Ah, that's a piece of information I was missing. I suppose that's a potential follow-up refactor, so that the modules' .js files produced by the linker could be verified...

But I'm not sure what you're even trying to achieve here. What is the expected result of that function?

https://scala-cli.virtuslab.org/docs/commands/package#scalajs
package --js produces .js files to be run by Node.
It generally seems the old code arbitrarily assumed there'd be a main method somewhere, and thus the main.js was obligatory.
The aim is to make Scala CLI to package something the users can use even if there isn't one, as per #3964
Which seems to already work with the current implementation in this PR.

@sjrd
Copy link

sjrd commented Dec 8, 2025

package --js itself should indeed not assume there's a main method/main.js module. It shouldn't need to. The linker will produce "a bunch of files" in the target directory, and that's it. That's the output.

If you want to run the code, that's a bit more difficult. Then you need to know which module to start executing, basically. For that, even the sbt plugin assumes there is a main method in main.js (marked with the setting scalaJSUseMainModuleInitializer). If not, run fails.

@Gedochao
Copy link
Contributor Author

Gedochao commented Dec 8, 2025

package --js itself should indeed not assume there's a main method/main.js module. It shouldn't need to. The linker will produce "a bunch of files" in the target directory, and that's it. That's the output.

If you want to run the code, that's a bit more difficult. Then you need to know which module to start executing, basically. For that, even the sbt plugin assumes there is a main method in main.js (marked with the setting scalaJSUseMainModuleInitializer). If not, run fails.

Thanks, that confirms my assumptions.
The current approach should be good enough, then.

@Gedochao Gedochao force-pushed the fix/package-js-without-main branch from 793ae8b to 4b76d8e Compare December 9, 2025 12:17
@Gedochao Gedochao requested review from tgodzik and zielinsky and removed request for tgodzik and zielinsky December 9, 2025 12:17
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.

package --js failed when source contains no main method

2 participants