Skip to content

Commit

Permalink
Fix resolution issues with aggregating projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcclell committed Feb 21, 2024
1 parent c5ac901 commit 15882c8
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 @@ -80,7 +80,7 @@ export default function scalaJSPlugin(options: ScalaJSPluginOptions = {}): ViteP
return null;
const path = source.substring(fullURIPrefix.length);

return `${scalaJSOutputDir}/${path}`;
return `${scalaJSOutputDir}/${path}`.trimStart();
},
};
}
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 15882c8

Please sign in to comment.