diff --git a/index.ts b/index.ts index 8d6878b..693fcc8 100644 --- a/index.ts +++ b/index.ts @@ -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(); }, }; } diff --git a/test/plugin.test.ts b/test/plugin.test.ts index f48f503..9cc8be8 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -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", diff --git a/test/testproject/aggregated-project/src/main/scala/aggregatedproject/AggregatedProject.scala b/test/testproject/aggregated-project/src/main/scala/aggregatedproject/AggregatedProject.scala new file mode 100644 index 0000000..e33e8e3 --- /dev/null +++ b/test/testproject/aggregated-project/src/main/scala/aggregatedproject/AggregatedProject.scala @@ -0,0 +1,5 @@ +package aggregatedproject + +@main def AggregatedProject(): Unit = + println("hello") +end AggregatedProject diff --git a/test/testproject/build.sbt b/test/testproject/build.sbt index 781256d..10f8eae 100644 --- a/test/testproject/build.sbt +++ b/test/testproject/build.sbt @@ -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)