-
Notifications
You must be signed in to change notification settings - Fork 10
Initial implementation. #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Node.js test and Build | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
node-version: ['16'] | ||
java: ['8'] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Set up JDK ${{ matrix.java }} | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'adopt' | ||
java-version: ${{ matrix.java }} | ||
cache: 'sbt' | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
**/node_modules | ||
key: ${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
- name: Run sbt once in the test project to make sure sbt is downloaded | ||
run: sbt projects | ||
working-directory: ./test/testproject | ||
- name: Perform unit test | ||
run: npm test | ||
- name: Build | ||
run: npm run build |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules/ | ||
/dist/ | ||
target/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { spawn, SpawnOptions } from "child_process"; | ||
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 options: SpawnOptions = { | ||
cwd: cwd, | ||
gzm0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
stdio: ['ignore', 'pipe', 'inherit'], | ||
}; | ||
const child = process.platform === 'win32' | ||
? spawn("sbt.bat", args.map(x => `"${x}"`), {shell: true, ...options}) | ||
gzm0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: spawn("sbt", args, options); | ||
|
||
let fullOutput: string = ''; | ||
|
||
child.stdout!.setEncoding('utf-8'); | ||
child.stdout!.on('data', data => { | ||
fullOutput += data; | ||
process.stdout.write(data); // tee on my own stdout | ||
}); | ||
|
||
return new Promise((resolve, reject) => { | ||
child.on('error', err => { | ||
reject(new Error(`sbt invocation for Scala.js compilation could not start. Is it installed?\n${err}`)); | ||
}); | ||
child.on('close', code => { | ||
gzm0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (code !== 0) | ||
reject(new Error(`sbt invocation for Scala.js compilation failed with exit code ${code}.`)); | ||
else | ||
resolve(fullOutput.trimEnd().split('\n').at(-1)!); | ||
}); | ||
}); | ||
} | ||
|
||
export interface ScalaJSPluginOptions { | ||
cwd?: string, | ||
projectID?: string, | ||
uriPrefix?: string, | ||
} | ||
|
||
export default function scalaJSPlugin(options: ScalaJSPluginOptions = {}): VitePlugin { | ||
const { cwd, projectID, uriPrefix } = options; | ||
|
||
const fullURIPrefix = uriPrefix ? (uriPrefix + ':') : 'scalajs:'; | ||
|
||
let isDev: boolean | undefined = undefined; | ||
let scalaJSOutputDir: string | undefined = undefined; | ||
|
||
return { | ||
name: "scalajs:sbt-scalajs-plugin", | ||
|
||
// Vite-specific | ||
configResolved(resolvedConfig) { | ||
isDev = resolvedConfig.mode === 'development'; | ||
}, | ||
|
||
// standard Rollup | ||
async buildStart(options) { | ||
if (isDev === undefined) | ||
throw new Error("configResolved must be called before buildStart"); | ||
|
||
const task = isDev ? "fastLinkJSOutput" : "fullLinkJSOutput"; | ||
const projectTask = projectID ? `${projectID}/${task}` : task; | ||
scalaJSOutputDir = await printSbtTask(projectTask, cwd); | ||
}, | ||
|
||
// standard Rollup | ||
resolveId(source, importer, options) { | ||
gzm0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (scalaJSOutputDir === undefined) | ||
throw new Error("buildStart must be called before resolveId"); | ||
|
||
if (!source.startsWith(fullURIPrefix)) | ||
return null; | ||
const path = source.substring(fullURIPrefix.length); | ||
|
||
return `${scalaJSOutputDir}/${path}`; | ||
}, | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to actually run...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will run once the workflow hits
main
. It's always the same issue when we bootstrap a project.I linked a green build of the same commit in my
sjrd/*
repo: https://github.com/sjrd/vite-plugin-scalajs/actions/runs/4376164277