Skip to content

Commit 15882c8

Browse files
committed
Fix resolution issues with aggregating projects.
Fixes #21
1 parent c5ac901 commit 15882c8

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default function scalaJSPlugin(options: ScalaJSPluginOptions = {}): ViteP
8080
return null;
8181
const path = source.substring(fullURIPrefix.length);
8282

83-
return `${scalaJSOutputDir}/${path}`;
83+
return `${scalaJSOutputDir}/${path}`.trimStart();
8484
},
8585
};
8686
}

test/plugin.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,48 @@ describe("scalaJSPlugin", () => {
8787
.toBeNull();
8888
}, testOptions);
8989

90+
it("works with a project that aggregates other ScalaJS enabled projects) (development)", async () => {
91+
const [plugin, fakePluginContext] = setup({
92+
projectID: "aggregatedProject",
93+
});
94+
95+
await plugin.configResolved.call(undefined, { mode: MODE_DEVELOPMENT });
96+
await plugin.buildStart.call(fakePluginContext, {});
97+
98+
const path = normalizeSlashes(await plugin.resolveId.call(fakePluginContext, 'scalajs:main.js')) ;
99+
100+
expect(path)
101+
.toContain('/testproject/aggregated-project/target/scala-3.2.2/aggregatedproject-fastopt/main.js');
102+
103+
expect(path)
104+
.toMatch(/^[^ \t]/); // Should not start with whitespace
105+
106+
expect(await plugin.resolveId.call(fakePluginContext, 'scalajs/main.js'))
107+
.toBeNull();
108+
}, testOptions);
109+
110+
it("works with a project that aggregates other ScalaJS enabled projects) (production)", async () => {
111+
const [plugin, fakePluginContext] = setup({
112+
projectID: "aggregatedProject",
113+
});
114+
115+
await plugin.configResolved.call(undefined, { mode: MODE_PRODUCTION });
116+
await plugin.buildStart.call(fakePluginContext, {});
117+
118+
const path = normalizeSlashes(await plugin.resolveId.call(fakePluginContext, 'scalajs:main.js')) ;
119+
120+
console.log("Found path: " + path);
121+
122+
expect(path)
123+
.toContain('/testproject/aggregated-project/target/scala-3.2.2/aggregatedproject-opt/main.js');
124+
125+
expect(path)
126+
.toMatch(/^[^ \t]/); // Should not start with whitespace
127+
128+
expect(await plugin.resolveId.call(fakePluginContext, 'scalajs/main.js'))
129+
.toBeNull();
130+
}, testOptions);
131+
90132
it("works with a custom URI prefix (development)", async () => {
91133
const [plugin, fakePluginContext] = setup({
92134
uriPrefix: "customsjs",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package aggregatedproject
2+
3+
@main def AggregatedProject(): Unit =
4+
println("hello")
5+
end AggregatedProject

test/testproject/build.sbt

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ lazy val otherProject = project.in(file("other-project"))
1111
.enablePlugins(ScalaJSPlugin)
1212
.settings(commonSettings)
1313

14+
lazy val aggregatedProject = project.in(file("aggregated-project"))
15+
.enablePlugins(ScalaJSPlugin)
16+
.settings(commonSettings)
17+
.aggregate(otherProject)
18+
1419
// This project does not link because it has no main method
1520
lazy val invalidProject = project.in(file("invalid-project"))
1621
.enablePlugins(ScalaJSPlugin)

0 commit comments

Comments
 (0)