oven-sh / bun

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

`namespace` property is undefined in `OnLoadArgs` of Bun plugin #3894

Open tr1ckydev opened 1 year ago

tr1ckydev commented 1 year ago

What version of Bun is running?

0.7.2

What platform is your computer?

Linux 6.4.6-1-cachyos x86_64 unknown

What steps can reproduce the bug?

  1. Create plugin.ts
    Bun.plugin({
    name: "url text file loader",
    async setup(builder) {
        builder.onLoad({ namespace: "https", filter: /.*/ }, async args => {
            return {
                exports: { namespace: args.namespace },
                loader: "object",
            };
        });
    },
    });
  2. Create bunfig.toml
    preload = ["./plugin.ts"]
  3. Create index.ts
    import {namespace} from "https://raw.githubusercontent.com/itsfoss/text-files/master/agatha.txt";
    console.log(namespace);

What is the expected behavior?

https should be logged in the console.

What do you see instead?

undefined is logged in the console.

Additional information

No response

wobsoriano commented 1 year ago

It's not supported yet - https://bun.sh/docs/bundler/vs-esbuild#onload.

Screenshot 2023-07-30 at 10 24 10 AM
tr1ckydev commented 1 year ago

But it used to work in the previous version. Even though Jarred told this will be changed in future but right now its unexpected and asked me to file an issue.

paperdave commented 1 year ago

what is bad is that if you use bun.build this probably works

we have two implementations of plugins and the bundler version is more correct than the runtime one. there isnt a lot of reasoning why these are separate.

the real solution is to merge the implementations (as opposed to just implementing the namespace stuff correctly for the runtime one), which is why we havent yet addressed this.