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

Modify sbt output parsing to allow .sbtopts with modified output #20

Open
wants to merge 5 commits 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
9 changes: 8 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { spawn, SpawnOptions } from "child_process";
import type { Plugin as VitePlugin } from "vite";
import fs from "fs";

// Utility to invoke a given sbt task and fetch its output
function printSbtTask(task: string, cwd?: string): Promise<string> {
Expand Down Expand Up @@ -33,7 +34,13 @@ function printSbtTask(task: string, cwd?: string): Promise<string> {
}
reject(new Error(errorMessage));
} else {
resolve(fullOutput.trimEnd().split('\n').at(-1)!);
const separator = process.platform === 'win32' ? '\r\n' : '\n';
const lines = fullOutput.trimEnd().split(separator);
const withoutLog = lines.filter(line => !line.startsWith('['));
const pathExists = withoutLog.filter(line => fs.existsSync(line));
pathExists.length > 0
? resolve(pathExists.at(-1)!)
: reject(new Error(`Couldn't find a valid path in sbt output: ${fullOutput}`));
}
});
});
Expand Down
20 changes: 16 additions & 4 deletions test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ describe("scalaJSPlugin", () => {
await plugin.configResolved.call(undefined, { mode: MODE_PRODUCTION });
await plugin.buildStart.call(fakePluginContext, {});

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

expect(normalized)
.toContain('/testproject/target/scala-3.2.2/testproject-opt/main.js');

expect(await plugin.resolveId.call(fakePluginContext, 'scalajs/main.js'))
Expand All @@ -65,7 +68,10 @@ describe("scalaJSPlugin", () => {
await plugin.configResolved.call(undefined, { mode: MODE_DEVELOPMENT });
await plugin.buildStart.call(fakePluginContext, {});

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

expect(normalized)
.toContain('/testproject/target/scala-3.2.2/testproject-fastopt/main.js');

expect(await plugin.resolveId.call(fakePluginContext, 'scalajs/main.js'))
Expand All @@ -80,7 +86,10 @@ describe("scalaJSPlugin", () => {
await plugin.configResolved.call(undefined, { mode: MODE_PRODUCTION });
await plugin.buildStart.call(fakePluginContext, {});

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

expect(normalized)
.toContain('/testproject/other-project/target/scala-3.2.2/otherproject-opt/main.js');

expect(await plugin.resolveId.call(fakePluginContext, 'scalajs/main.js'))
Expand All @@ -95,7 +104,10 @@ describe("scalaJSPlugin", () => {
await plugin.configResolved.call(undefined, { mode: MODE_DEVELOPMENT });
await plugin.buildStart.call(fakePluginContext, {});

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

expect(normalized)
.toContain('/testproject/target/scala-3.2.2/testproject-fastopt/main.js');

expect(await plugin.resolveId.call(fakePluginContext, 'scalajs:main.js'))
Expand Down
3 changes: 3 additions & 0 deletions test/testproject/.sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-Dsbt.task.timings=true
-Dsbt.task.timings.unit=s
-Dsbt.task.timings.on.shutdown=true