oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.53k stars 2.71k forks source link

Implement `watchFiles` and `watchDirs` in plugin API #4689

Open lucas-jones opened 1 year ago

lucas-jones commented 1 year ago

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Linux 5.15.0-67-generic x86_64 x86_64

What steps can reproduce the bug?

When using a plugin --watch & --hot no longer work

Basic Example

Just transpiles .ts into javascript using Bun's transpiler

Command

bun --watch ./src/index.ts

bunfig.toml

preload = ["./plugin.ts"]

plugin.ts

import { BunPlugin, plugin, Transpiler } from "bun";

export default BunPlugin;

plugin(BunPlugin());

export function BunPlugin(): BunPlugin {
    return {
        name: "Test",
        async setup(build) {

            const transpiler = new Transpiler({ loader: "ts" });

            build.onLoad({ filter: /\.(ts)$/ }, async (args) => {
                const typescript = await Bun.file(args.path).text();
                const javascript = transpiler.transformSync(typescript);
                return {
                    contents: javascript,
                    loader: "js",
                };
            });
        },
    }
};

What is the expected behavior?

Reloading of the application on file changes

What do you see instead?

No reloading

Additional information

No response

alpharder commented 3 months ago

This is really frustrating. Used nodemon as a workaround for now

kirankunigiri commented 2 months ago

I saw the latest comment on the PR https://github.com/oven-sh/bun/pull/8679 that adding the watchedFilePaths parameter will be added in a separate new PR. I wanted to ask if this issue could also be fixed in that PR because they are so similar. Specifically, allowing any plugin that uses build.onLoad to automatically keep the built-in --watch behavior (or a general plugin boolean flag to enable it), so all existing bun plugins can also work with --watch without needing to update their code.

riepspellz commented 1 week ago

Hello, any updates about this ?