denoland / deno_emit

Transpile and bundle JavaScript and TypeScript under Deno and Deno Deploy
https://jsr.io/@deno/emit
MIT License
223 stars 23 forks source link

feat: support import maps #114

Closed yacinehmito closed 1 year ago

yacinehmito commented 1 year ago

Adds import map support to both bundle and transpile.

Like with Deno config, there are two ways to define an import map. You can either:

If the later is chosen, relative paths are resolved from the current working directory (output of Deno.cwd()). This can be overridden with the property baseUrl. I welcome suggestions of other names for that property.

To provide an import map, you can set the property ˋimportMapˋ with either:

Closes #67. Closes #56. Closes #14.

yacinehmito commented 1 year ago

I just realized that the proposed API in this PR is different than the ones of Deno.emit() (see docs).

The proposed API attempts to be consistent with Deno's config, at the cost of introducing baseUrl which is "weird". Deno.emit() does not have this issues as it defines both importMap and importMapPath, which is more elegant, but inconsistent with Deno's config.

@dsherret @bartlomieju Any opinions as to which design is preferable? I don't mind changing.

yacinehmito commented 1 year ago

@dsherret This is ready.

I performed the required API changes in this commit: https://github.com/denoland/deno_emit/pull/114/commits/97010086d2aff5c5d7284652c04a049bff779818

Then, I modified the implementation so that the import map is loaded on the Rust side instead of the JS side. This also means that we reuse the loader instead of doing an ad-hoc fetch, which matches how dnt works.