esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Imports from stdio entrypoint don't have a namespace set

Open MariusVatasoiu opened this issue 10 months ago • 0 comments

Imports used in the stdio.contents don't get a namespace set. This is a small code snippet where I have a plugin that needs the namespace porperty.

I thought the namespace is set based only on the import's path, so shouldn't be any difference between stdio and physical entryPoints. Unless, there are other limitations.

import * as esbuild from "npm:[email protected]";

const myPlugin = {
  name: "myPlugin",
  setup(build) {
    build.onResolve({ filter: /.*?/ }, (args) => {
      console.log(args);       
    //    args.namespace is empty for both imports used in the stdio content
    //    {
    //     path: "https://deno.land/[email protected]/bytes/mod.ts",
    //     importer: "<stdin>",
    //     namespace: "",
    //     resolveDir: "/Users/..",
    //     kind: "import-statement",
    //     pluginData: undefined
    //     }
    
    //     {
    //     path: "./main.ts",
    //     importer: "<stdin>",
    //     namespace: "",
    //     resolveDir: "/Users/...",
    //     kind: "import-statement",
    //     pluginData: undefined
    //     }
       
    });
  },
};

const result = await esbuild.build({
  stdin: {
    contents: `
    import "https://deno.land/[email protected]/bytes/mod.ts";
    import "./main.ts";       
    `,
    resolveDir: Deno.cwd(),
  },
  plugins: [myPlugin],
  outfile: "./test.bundle.js",
  bundle: true,
  format: "esm",
});

console.log(result.outputFiles);

esbuild.stop();

MariusVatasoiu avatar Apr 11 '24 07:04 MariusVatasoiu