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

Fix resolution issues with aggregating projects. #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Plugin as VitePlugin } from "vite";

// Utility to invoke a given sbt task and fetch its output
function printSbtTask(task: string, cwd?: string): Promise<string> {
const args = ["--batch", "-no-colors", "-Dsbt.supershell=false", `print ${task}`];
const args = ["--batch", "-no-colors", "-Dsbt.supershell=false", `set ${task} / aggregate := false; print ${task}`];
const options: SpawnOptions = {
cwd: cwd,
stdio: ['ignore', 'pipe', 'inherit'],
Expand Down
42 changes: 42 additions & 0 deletions test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,48 @@ describe("scalaJSPlugin", () => {
.toBeNull();
}, testOptions);

it("works with a project that aggregates other ScalaJS enabled projects) (development)", async () => {
const [plugin, fakePluginContext] = setup({
projectID: "aggregatedProject",
});

await plugin.configResolved.call(undefined, { mode: MODE_DEVELOPMENT });
await plugin.buildStart.call(fakePluginContext, {});

const path = normalizeSlashes(await plugin.resolveId.call(fakePluginContext, 'scalajs:main.js')) ;

expect(path)
.toContain('/testproject/aggregated-project/target/scala-3.2.2/aggregatedproject-fastopt/main.js');

expect(path)
.toMatch(/^[^ \t]/); // Should not start with whitespace

expect(await plugin.resolveId.call(fakePluginContext, 'scalajs/main.js'))
.toBeNull();
}, testOptions);

it("works with a project that aggregates other ScalaJS enabled projects) (production)", async () => {
const [plugin, fakePluginContext] = setup({
projectID: "aggregatedProject",
});

await plugin.configResolved.call(undefined, { mode: MODE_PRODUCTION });
await plugin.buildStart.call(fakePluginContext, {});

const path = normalizeSlashes(await plugin.resolveId.call(fakePluginContext, 'scalajs:main.js')) ;

console.log("Found path: " + path);

expect(path)
.toContain('/testproject/aggregated-project/target/scala-3.2.2/aggregatedproject-opt/main.js');

expect(path)
.toMatch(/^[^ \t]/); // Should not start with whitespace

expect(await plugin.resolveId.call(fakePluginContext, 'scalajs/main.js'))
.toBeNull();
}, testOptions);

it("works with a custom URI prefix (development)", async () => {
const [plugin, fakePluginContext] = setup({
uriPrefix: "customsjs",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package aggregatedproject

@main def AggregatedProject(): Unit =
println("hello")
end AggregatedProject
5 changes: 5 additions & 0 deletions test/testproject/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ lazy val otherProject = project.in(file("other-project"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)

lazy val aggregatedProject = project.in(file("aggregated-project"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings)
.aggregate(otherProject)

// This project does not link because it has no main method
lazy val invalidProject = project.in(file("invalid-project"))
.enablePlugins(ScalaJSPlugin)
Expand Down