deno_emit icon indicating copy to clipboard operation
deno_emit copied to clipboard

Implement compiler options

Open kitsonk opened this issue 3 years ago • 3 comments

Currently the compiler options are ignored (or not available). They need to be passed to Rust and affect the emit just like with CLI.

kitsonk avatar May 20 '22 04:05 kitsonk

Any update on this? Looking to support specifying a target as we used to be able to with Deno.emit (https://github.com/denoland/deno_emit/issues/44#issuecomment-1149868071)

Can't even use deno bundle as a workaround, since target is not one of the compilerOptions that can be configured with a custom deno config.

I guess I'll need to use esbuild or something in the meantime - feels like we've lost so much since deno v1.21.3.

(update) was able to use the esbuild Deno x module to bundle with a custom target, which runs an esbuild binary under the hood

johnspurlock avatar Jun 16 '22 15:06 johnspurlock

Hmm, I'm also stuck trying to find a replacement for old Deno.emit code that used:

compilerOptions: { 
    declaration: true,
    emitDeclarationOnly: true,
    removeComments: false,
}

It seems there is no upgrade path for me.

  • deno bundle does not support those compilerOptions
  • esbuild does not deal with types at all
  • swc does not do this (yet)
  • tsc supports those options in a tsconfig but does not work on Deno source files (different import style, and tsc has no import map support)

Any ideas?

johnspurlock avatar Jun 16 '22 16:06 johnspurlock

I also don't understand the reason for including compilerOptions in the types and then not passing them through. Modifying mod.ts's bundle function to simply grab compilerOptions out of options and pass it as the fifth argument to jsBundle allowed me to compile without source maps as well as modify the jsxFactory and jsxFragmentFactory, which is necessary if you are compiling something other than React. It seems to work fine in simple tests.

export async function bundle(
  root: string | URL,
  options: BundleOptions = {},
): Promise<BundleEmit> {
  const {
    imports,
    load,
    cacheSetting,
    cacheRoot,
    allowRemote,
    compilerOptions
  } = options;
  let bundleLoad = load;
  if (!bundleLoad) {
    const cache = createCache({ root: cacheRoot, cacheSetting, allowRemote });
    bundleLoad = cache.load;
  }
  root = root instanceof URL ? root : toFileUrl(resolve(root));
  const { bundle: jsBundle } = await instantiate();
  console.log('got compiler options', compilerOptions)
  return jsBundle(
    root.toString(),
    bundleLoad,
    JSON.stringify(imports),
    undefined,
    compilerOptions,
  );
}

dylanmcdiarmid avatar Jul 27 '22 23:07 dylanmcdiarmid