Skip to content

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 2 commits into from
Mar 11, 2023
Merged

Initial implementation. #1

merged 2 commits into from
Mar 11, 2023

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Mar 1, 2023

This plugin can be used as follows (or will be, once published):
sjrd/scalajs-sbt-vite-laminar-chartjs-example@getting-started-tutorial-series...vite-plugin

This is as a follow-up to scala-js/scala-js-website#590 (comment)


Regarding tests: they directly interact with the plugin, without going through Vite or Rollup. This seems to be standard practice among all the Vite and/or Rollup plugins I looked at. Apparently, integration tests (like with have with sbt scripted) are not a thing in that universe.

@sjrd sjrd requested a review from gzm0 March 1, 2023 17:15
@sjrd
Copy link
Member Author

sjrd commented Mar 1, 2023

@sjrd sjrd force-pushed the initial-implementation branch from b8ca73d to 6a9a3d3 Compare March 2, 2023 10:15
@sjrd
Copy link
Member Author

sjrd commented Mar 8, 2023

@gzm0 Do you think you might have some time for this PR in the coming week? Should I ask someone else to review?

Does this plugin make sense to you overall, in terms of what it offers?

@gzm0
Copy link
Contributor

gzm0 commented Mar 8, 2023

Sorry, I missed this over the weekend. Given the current forecast for the weekend, I'm quite confident I can find the time to review this. Is that enough?

@sjrd
Copy link
Member Author

sjrd commented Mar 8, 2023

Given the current forecast for the weekend

😄

Yes, sure, that's enough. Thank you!

@sjrd sjrd force-pushed the initial-implementation branch 2 times, most recently from 37335b4 to 440d099 Compare March 9, 2023 15:43
@sjrd
Copy link
Member Author

sjrd commented Mar 9, 2023

As an additional confidence test, here is a "real-world" usage of the plugin: scalacenter/scastie#790

Copy link
Contributor

@gzm0 gzm0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all LG. Just some nits and details.

package.json Outdated
},
"dependencies": {
"vite": "^4.1.4",
"vitest": "^0.29.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this shouldn't go into the devDependencies?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, indeed. I moved it to devDependencies.

tsconfig.json Outdated
"./*.ts"
],
"exclude": [
"__test__/**.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What generates this directory? vitest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo-cult copy-paste. :p I removed it.

index.ts Outdated

// standard Rollup
resolveId(source, importer, options) {
const parts = /^scalajs:(.*)$/g.exec(source);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making the prefix configurable. Otherwise it's impossible to use this plugin with multiple sbt projects (not a core use-case of course, but it seems very inconsistent to me otherwise).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a uriPrefix configuration for this.

tsconfig.json Outdated
},
"include": [
"./*.ts"
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider leaving the default (include: ["**/*"]).

@@ -0,0 +1,47 @@
name: Node.js test and Build
Copy link
Contributor

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...

Copy link
Member Author

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

return path === null ? null : path.replace(/\\/g, '/');
}

describe("scalaJSPlugin", () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case that sets isDev to true?

index.ts Outdated
export default function scalaJSPlugin(options: ScalaJSPluginOptions = {}): VitePlugin {
const { projectID, cwd } = options;

let isDev = false; // when resolving the Vite config, this may turn into true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider being stricter here and type isDef: boolean | undefined. Then fail if configResolved didn't get called.

index.ts Outdated
const { projectID, cwd } = options;

let isDev = false; // when resolving the Vite config, this may turn into true
let scalaJSOutputDir: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here actually: Don't resolve to the empty string if you didn't get the callbacks you expected.

@sjrd sjrd force-pushed the initial-implementation branch from 5e97fa9 to f460a9a Compare March 11, 2023 10:18
@sjrd sjrd force-pushed the initial-implementation branch from f460a9a to 95b4d9a Compare March 11, 2023 10:48
@sjrd
Copy link
Member Author

sjrd commented Mar 11, 2023

Thanks for the review! I believe I have addressed all the comments.
New green build available at: https://github.com/sjrd/vite-plugin-scalajs/actions/runs/4391908549

@sjrd sjrd requested a review from gzm0 March 11, 2023 10:52
@gzm0 gzm0 merged commit 8d03edd into scala-js:main Mar 11, 2023
@sjrd sjrd deleted the initial-implementation branch March 11, 2023 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants