Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno.compile appends extensions to URIs ending with a hash or search #7005

Closed
jeroenptrs opened this issue Aug 10, 2020 · 1 comment
Closed
Assignees
Labels
cli related to cli/ dir design limitation something that can't be fixed or is too hard to fix

Comments

@jeroenptrs
Copy link

The compiler API does compile the source code and emits a sourcemap, but the filenames in the emit map are not correct.

This example shows a basic discrepancy:

const [diag, emit] = await Deno.compile("https://deno.land/[email protected]/examples/welcome.ts");
console.log(Object.keys(emit));
/*
[
  "https://deno.land/[email protected]/examples/welcome.js.map",
  "https://deno.land/[email protected]/examples/welcome.js"
]
*/
const [diagHash, emitHash] = await Deno.compile(
  "https://deno.land/[email protected]/examples/welcome.ts#1"
);
console.log(Object.keys(emitHash));
/*
[
  "https://deno.land/[email protected]/examples/welcome.ts#1.js.map",
  "https://deno.land/[email protected]/examples/welcome.ts#1.js"
]
*/

Using something with a circular dependency like https://deno.land/[email protected]/http/server.ts obviously renders both because the hash or search is only in the root module:

const [diag, emit] = await Deno.compile("https://deno.land/[email protected]/http/server.ts?abc=def");
console.log(Object.keys(emit));
/*
[
  ...
  "https://deno.land/[email protected]/http/server.js.map",
  "https://deno.land/[email protected]/http/server.js",
  ...
  "https://deno.land/[email protected]/http/server.ts?abc=def.js.map",
  "https://deno.land/[email protected]/http/server.ts?abc=def.js"
]
*/
@jeroenptrs jeroenptrs changed the title Deno.compile appends extensions to URI's ending with a hash or search Deno.compile appends extensions to URIs ending with a hash or search Aug 10, 2020
@lucacasonato lucacasonato added bug Something isn't working correctly cli related to cli/ dir labels Aug 17, 2020
@kitsonk kitsonk added design limitation something that can't be fixed or is too hard to fix and removed bug Something isn't working correctly labels Nov 9, 2020
@kitsonk
Copy link
Contributor

kitsonk commented Nov 9, 2020

This has changed subtly in Deno 1.5.2, the following:

const [diag, emit] = await Deno.compile(
  "https://deno.land/[email protected]/http/server.ts?abc=def",
);
console.log(Object.keys(emit));

Outputs:

[
  "https://deno.land/[email protected]/bytes/mod.ts.js.map",
  "https://deno.land/[email protected]/async/pool.ts.js.map",
  "https://deno.land/[email protected]/_util/assert.ts.js",
  "https://deno.land/[email protected]/async/delay.ts.js",
  "https://deno.land/[email protected]/http/server.ts.js",
  "https://deno.land/[email protected]/http/_io.ts.js",
  "https://deno.land/[email protected]/bytes/mod.ts.js",
  "https://deno.land/[email protected]/async/deferred.ts.js",
  "https://deno.land/[email protected]/async/delay.ts.js.map",
  "https://deno.land/[email protected]/async/mux_async_iterator.ts.js",
  "https://deno.land/[email protected]/io/bufio.ts.js.map",
  "https://deno.land/[email protected]/async/mod.ts.js.map",
  "https://deno.land/[email protected]/http/_io.ts.js.map",
  "https://deno.land/[email protected]/http/http_status.ts.js",
  "https://deno.land/[email protected]/http/server.ts?abc=def.js",
  "https://deno.land/[email protected]/textproto/mod.ts.js.map",
  "https://deno.land/[email protected]/_util/assert.ts.js.map",
  "https://deno.land/[email protected]/io/bufio.ts.js",
  "https://deno.land/[email protected]/encoding/utf8.ts.js",
  "https://deno.land/[email protected]/async/deferred.ts.js.map",
  "https://deno.land/[email protected]/async/pool.ts.js",
  "https://deno.land/[email protected]/textproto/mod.ts.js",
  "https://deno.land/[email protected]/async/mux_async_iterator.ts.js.map",
  "https://deno.land/[email protected]/async/mod.ts.js",
  "https://deno.land/[email protected]/encoding/utf8.ts.js.map",
  "https://deno.land/[email protected]/http/http_status.ts.js.map",
  "https://deno.land/[email protected]/http/server.ts?abc=def.js.map",
  "https://deno.land/[email protected]/http/server.ts.js.map"
]

Instead of just replacing some extensions, we always append the extension to the end of the URL, as it is impossible to "guess" at what would really work for the target runtime environment. Deno treats each unique URL as a seperate module, so the duplicate emits of server.ts are expected, because as far as Deno knows those query params impact the source being served up.

There is denoland/deno_emit#41 which could possible provide a replacer "built in" which is still worth considering, but for right now it is Deno.bundle() to do some post processing on Deno.compile() emit to get it into a situation where it can be run in whatever target environment you need.

So respectfully closing.

@kitsonk kitsonk closed this as completed Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir design limitation something that can't be fixed or is too hard to fix
Projects
None yet
Development

No branches or pull requests

3 participants