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
Implement loading biome.config.js
#1825
Conversation
✅ Deploy Preview for biomejs canceled.
|
@@ -82,7 +82,7 @@ pub struct CliOptions { | |||
|
|||
impl CliOptions { | |||
/// Computes the [ConfigurationBasePath] based on the options passed by the user | |||
pub(crate) fn as_configuration_base_path(&self) -> ConfigurationBasePath { | |||
pub(crate) fn to_configuration_base_path(&self) -> ConfigurationBasePath { |
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.
Sorry for the distraction, just renamed this to follow Rust's naming conventions: https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv
fn format_with_js_configuration() { | ||
let mut console = BufferConsole::default(); | ||
let mut fs = MemoryFileSystem::default(); | ||
fs.set_working_directory("/"); |
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.
Boa's default module loader didn't like it if there's no working directory, so I had to add one to the memory filesystem. Note the main module is currently loaded from a string that is read from disk by our config finder, so I expect this might need a little bit more before loading external modules will work through the memory file system.
As far as I understood, Boa is an interpreter, not an engine/runtime. Right? Can we do things like this? // biome.js
let severity = "warn";
if (isProd()) {
severity = "error"
}
export const config = {
linter: {
rules: {
correctness: {
noDebugger: severity
}
}
}
} |
/// | ||
/// The data structures that need to be deserialized have to implement the [Deserializable] trait. | ||
/// For most data structures, this can be achieved using the | ||
/// [biome_deserialize_macros::Deserializable] derive. |
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.
Note this comment is not entirely correct, since the function uses Serde traits for now, instead of our Deserializable
. If we agree on picking Boa, I would optimize this function to use Deserializable
again so we can go straight from boa_engine::JsValue
to our own types, instead of using serde_json::Value
as intermediary.
It is an interpreter, but that is also an engine/runtime. Internally it compiles the JavaScript to bytecode, which it operates on for execution. The only thing it lacks compared to "big" engines such as V8 and JavaScriptCore is a JIT engine. This basically creates the following trade-off for us:
Btw, there is also a
Yes! That's one of the main benefits of a JS config. |
Btw, since I mentioned latency with Boa is very good: I did some preliminary tests on my admittedly not very beefy laptop (it has a low-power Intel CPU with only 2 performance cores) and evaluating a simple script in Boa takes 11ms in debug builds. I would expect much better performance in a release build still (quite possibly bringing it to <1ms), but I have to set up some proper benchmarks for that. |
In order to do those things, for example we need to also implement |
I would certainly consider implementing such features within scope of our runtime, even if it's not in the initial PoC. |
Even better than I had hoped for. Less than 0.2ms for instantiating the engine, parsing and evaluating the script and converting the result to our |
@ematipico @Conaclos I wouldn't want to merge this if it's too controversial, so I'd like to ask your opinion:
|
These are important requirements |
CodSpeed Performance ReportMerging #1825 will improve performances by 36.33%Comparing Summary
Benchmarks breakdown
|
how does this js config system perform compared to the json one? |
Boa is a very promising/interesting option and I like the idea o using it. However, I am a bit frustrated by the fact we didn't test other options... Regarding js config, I could delay its support. We are planning to change some parts of our config. It will be difficult or even impossible to provide a way to automatically migrate the ks config. I am not against this support, but I could wait until some users ask for it? |
@ematipico I think your concerns are good ones, and I don't see any issue addressing them except one:
I think we may be able to provide a text range that would point to the @Conaclos said:
I took the JIT-powered engines out of the equation because you were worried about increasing the binary size and others expressed concerns about latency of spinning up the engine (both valid concerns!). But frankly, that only leaves the interpreters and there aren't that many good ones out there that we can use:
Boa covers the platforms we need, has good ECMAScript coverage, and is easy to integrate since it's also written in Rust. The latter I consider an extra advantage, because it means Biome contributors probably wouldn't have much issue jumping in to help with engine work too. Of course, if you would like to reconsider JIT engines, I guess I could try a Deno PoC as I originally intended :) But I have played around with this before, and it's not going be as easy as working with Boa.
I think GritQL should be able to support migrations for most common JS configs :) But yeah, given the hesitance towards JS configs, let's postpone this for now so we can focus on the choice of engine. |
I agree with all your points, and I think Boa is a great fit foor us. I was wondering if llrt or workerd could be worth to test.
+1 |
Both of those are very explicitly tailored to server-side use-cases though. For workerd the docs even explicitly mention "Designed for servers, not CLIs nor GUIs.". Neither of them are independent engines either, llrt is based on QuickJS (they also don't publish Windows binaries), while workerd is based on V8 (and comes with a full JIT overhead). |
Closing this one since we won’t do JS configs for now. I’ll probably make a new effort with Boa when starting on actual JS plugins. |
Summary
This PR implements loading config from
biome.config.js
. I don't think this necessarily needs to be merged as is. Instead, I hope it can help us to find answers to the following two questions:main
. So the dependency is pinned to their repository rather than a release for now.PartialConfiguration
exactly like the config we load directly from a JSON file.extends
with pure JS syntax.Note that this intentionally doesn't support TypeScript yet, so I didn't need a transpiler just now.
Test Plan
Added a test case for loading JS config.