Skip to content

Commit

Permalink
Fix resolution issues with aggregating projects.
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
jmcclell committed Feb 22, 2024
1 parent c5ac901 commit d2c3ecb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
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

0 comments on commit d2c3ecb

Please sign in to comment.