Open
Conversation
edemaine
reviewed
Feb 11, 2025
Collaborator
edemaine
left a comment
There was a problem hiding this comment.
I'm worried about this change, because it would cause bun foo.civet to merely display an error, but not give an exit code, when foo.civet has a parse error. I'm trying to figure out whether there's a better approach, though Bun's onLoad doesn't seem to have a way to return an error other than throwing one... Possibly this is just a bug in bun --watch.
| contents | ||
| loader: 'tsx' | ||
| } | ||
| const cache = new Map<string, string> |
Collaborator
There was a problem hiding this comment.
Suggested change
| const cache = new Map<string, string> | |
| cache := new Map<string, string> |
Collaborator
|
I've reported as oven-sh/bun#17270 — we'll see what the Bun folks think about it. |
|
try this # bunfig.toml
preload = ["./plugin.ts"]// plugin.ts
import { compile } from "@danielx/civet";
import { plugin } from "bun";
await plugin({
name: "Civet loader",
async setup(builder) {
builder.onLoad({ filter: /\.civet$/ }, async ({ path }) => {
- const source = await file(path).text();
+ const { default: source } = await import(`${path}?`, { with: { type: "text" } });
const contents = await compile(source);
return {
contents,
loader: "tsx",
};
});
},
});Although the above method can temporarily solve the bun bug, bun has another bug. Calling process.exit() in watch mode will exit the watch process. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hey! Thank you for this amazing software.
The only issue I had was an issue with
bunwhen using the--watchflag.When the compilation of a given module fails with a syntax error, it prevents the plugin from generating any more modules. This breaks the
--watchflag features.Instead of failing, it makes sense to catch the error, log it to stderr, and then use a previously cached version of that module.
Features added:
A few questions:
To try it out locally:
bun init -ybunfig.tomlwithpreload = ["./dist/bun-civet.mjs"]index.civetwithBun.write "./test.txt", "Hello world!"bun --watch index.civet='s) and change the"Hello world!"string to something else./text.txtremains unmodifiedindex.civet./text.txtfor the corresponding changesI'm very happy to help or make modifications.