deno_emit icon indicating copy to clipboard operation
deno_emit copied to clipboard

Archiving `deno_emit`

Open dsherret opened this issue 5 months ago • 4 comments

We're going to archive deno_emit sometime soon.

Reasons:

  1. deno bundle is back: https://deno.com/blog/v2.4
  2. deno_emit doesn't handle many scenarios (ex. config discovery and a whole lot more)
  3. https://github.com/denoland/deno-js-loader has been added with a completely new design from deno_emit. It uses almost the exact same code as the Deno CLI by compiling Rust to Wasm.
    • Used by: https://github.com/denoland/deno-rolldown-plugin
    • Also used internally in fresh now

dsherret avatar Jul 03 '25 01:07 dsherret

I would like to note that https://github.com/denoland/deno-js-loader only handles half of what deno_emit handles, that being resolving the modules. deno_emit's methods are targeted at transpiling / transpile & bundling code. I know I'm not the only one who has been using deno-emit to transpile code for the browser.

I think that https://github.com/lucacasonato/esbuild_deno_loader may count, however I just spent way-too-long realising that deno-js-loader didn't transpile, so I'll try to make some equivalent code snippets tomorrow.

jcc10 avatar Sep 23 '25 23:09 jcc10

The following is a valid polyfill for emit.transpile:

import * as esbuild from "npm:[email protected]";
// Import the Wasm build on platforms where running subprocesses is not
// permitted, such as Deno Deploy, or when running without `--allow-run`.
// import * as esbuild from "https://deno.land/x/[email protected]/wasm.js";

import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.11.1";

async function transpile(file: URL ): Promise<string> {
            const result = await esbuild.build({
                plugins: [...denoPlugins()], // (I run the function once and cache the results on startup, but used the example here)
                entryPoints: [file.toString()], // This is stupid, but I was using URL objects and it does work so...
                bundle: false, // Change this if you want a bundle.
                format: "esm", // Unless for some unknown reason you want common-js
                target: "chrome139", // Or deno, or whatever. See: https://esbuild.github.io/api/#target
                write: false, // So we aren't writing files.
                outdir: '/', // So we aren't in some folder somewhere on the system. Results on windows untested.
              });
              let f = ""
              const path = file.pathname;
              const fileName = path.substring(path.lastIndexOf('/') + 1).replace(/\..+?$/, "")
              console.log({fileName})
              const t = `/${fileName}.js`;
              // We have to do the following loop because ** it doesn't return a Map or Record object. **
              for(const o of result.outputFiles){
                if(o.path == t)
                    f = o.text;
              }
              if(!f)
                throw new Error("Transpile Error")
              return f;
        }

If someone else could check to ensure I'm not crazy and/or blind and/or overlooked something obvious, I'd appreciate it.

jcc10 avatar Sep 24 '25 21:09 jcc10

I'm currently using deno_emit to precompile jsx in a node.js or bun environment. Is there an alternative to deno_emit?

import { readFile } from "node:fs/promises";
import { argv, cwd } from "node:process";
import { transpile } from "@deno/emit";

(globalThis as any).Deno ??= {
  cwd,
  readFile,
  args: argv,
};

mo36924 avatar Oct 08 '25 07:10 mo36924

Is Deno.bundle() planned to be supported in Deno Deploy? It does not look like it is currently supported.

mfulton26 avatar Dec 01 '25 20:12 mfulton26