Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link Scala.js using Directory path when available #1714

Merged
merged 2 commits into from
Jan 29, 2022

Conversation

lolgab
Copy link
Member

@lolgab lolgab commented Jan 28, 2022

This doesn't change any API but makes the Scala.js emit top level
exports.

Motivation

Thinking about APIs is hard, so I tried to make the process of support the new faskLinkJS a two step approach. For now I migrated only the implementation to the new api using DirectoryOutputPath (in Scala. js 1.3+ only) but maintaed the out.js output path. It doesn't fail anymore if you try to export a module from the Scala.js code. At the same time it is not optimal since the ausiliary files are not returned by the fastOpt task, so are not considered for the tasks cache purposes.

This doesn't change any API but makes the Scala.js emit top level
exports.
@lolgab lolgab marked this pull request as ready for review January 29, 2022 07:54
@lolgab lolgab requested a review from lefou January 29, 2022 08:21
Copy link
Member

@lefou lefou left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you!

@lefou lefou merged commit 0f1a378 into com-lihaoyi:main Jan 29, 2022
@lefou lefou added this to the after 0.10.0 milestone Jan 29, 2022
@lefou
Copy link
Member

lefou commented Jan 29, 2022

Does this fix #1684 ?

@lolgab lolgab deleted the migrate-new-scala-js-api branch January 29, 2022 11:52
@lefou lefou linked an issue Jan 29, 2022 that may be closed by this pull request
lefou added a commit that referenced this pull request May 3, 2022
## Motivation
We want to support the latest Scala.js features without breaking the support for older versions.
In #1714 I migrated to the new Scala.js API which generated a wrong filename
(`main.js` instead of `out.js`) in case the build contained multiple modules.
It broke some people tests that were assuming a `out.js` file being created where the real file was a different one.

## Approach
Since workers are internal API, this PR takes a step further in insulating them (using the same approach adopted in mill-mima https://github.com/lolgab/mill-mima/pull/42/files) by duplicating its model classes in two sets:
  - the user facing APIs need to be stable and are serialized to json with upickle
  - the worker facing APIs need to not depend on mill internals and are unstable/internal.
  
Now the worker is responsible to convert between these two APIs.
The user facing API was moved into the main artifact, while the new internal worker-api was moved to a new artifact which is not checked by mima.

## New Features

This PR introduces two new targets that deprecate the main `fastOpt` and `fullOpt`:
`fastLinkJS` and `fullLinkJS`.
These two targets return a `Report` which is an adaptation of the Scala.js API [`Report`](https://www.scala-js.org/api/scalajs-linker-interface/1.10.0/org/scalajs/linker/interface/Report.html)

These two targets are polyfilled for Scala.js 0.6 - 1.2 by generating the new output from the old API output.
This is needed to make `test` work consistently on all versions since it's hard in Mill to run different targets depending on the value of a target like:

```scala
val task = if(scalaJSVersion() > "1.2") fastLinkJSTest else fastOptTest 
```

## Changes
- Introduce `Report` adapted from ScalaJS linker API
- Introduce `fastLinkJS` and `fastOptJS` which return `Report`
- Make test use `fastLinkJSTest`
- Make Scala.js 1.2- and 0.6 always link in legacy mode
- Pass `forceOutJs` boolean parameter to Worker implementation
  to switch between Directory API and File (legacy) API
- deprecate old implementation

Pull request: #1851
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.

Scala.js linking to support multiple modules
2 participants