<h2 dir="auto">Problem</h2>
<ol dir="auto">
<li>
<p dir="auto">The files struct (<code class="notranslate">Record&lt;string,string&gt;</code>), returned by running <code class="notranslate">Deno.emit</code> has the (semi) correct extensions for the file names (the keys of the struct), but the code inside the emitted output uses the original <code class="notranslate">.ts</code> extension for the <code class="notranslate">import</code> statements.<br>
This requires special handling after emitting the output to search and replace all references to the old file extensions (as using the old ones won't work).</p>
</li>
<li>
<p dir="auto">I wrote above that the keys have "semi" correct extensions, because the <code class="notranslate">emit</code> method only appends <code class="notranslate">.js</code>, <code class="notranslate">.js.map</code> &amp; <code class="notranslate">.d.ts</code> to the keys, without considering that the <em>"real"</em> output file shouldn't have <code class="notranslate">.ts</code> in it's name.</p>
</li>
</ol>
<h2 dir="auto">Example</h2>
<p dir="auto">You can see below that the output for <code class="notranslate">a.ts.js</code> has <code class="notranslate">import * as b from '/b.ts';</code> instead of <code class="notranslate">a.ts.js</code> has <code class="notranslate">import * as b from '/b.ts.js';</code></p>
<p dir="auto"><strong>build.ts</strong></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const {files} = await Deno.emit(
  &quot;/a.ts&quot;,
  {
    sources: {
      &quot;/b.ts&quot;: &quot;export const foo=true&quot;,
      &quot;/a.ts&quot;: &quot;import * as b from '/b.ts';\nconsole.log(b)&quot;
    }
  }
);
console.log(files)"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-kos">{</span>files<span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-smi">Deno</span><span class="pl-kos">.</span><span class="pl-en">emit</span><span class="pl-kos">(</span>
  <span class="pl-s">"/a.ts"</span><span class="pl-kos">,</span>
  <span class="pl-kos">{</span>
    <span class="pl-c1">sources</span>: <span class="pl-kos">{</span>
      <span class="pl-s">"/b.ts"</span>: <span class="pl-s">"export const foo=true"</span><span class="pl-kos">,</span>
      <span class="pl-s">"/a.ts"</span>: <span class="pl-s">"import * as b from '/b.ts';\nconsole.log(b)"</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">files</span><span class="pl-kos">)</span></pre></div>
<p dir="auto"><strong>command</strong></p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="deno run -q --unstable build.ts"><pre class="notranslate">deno run -q --unstable build.ts</pre></div>
<p dir="auto"><strong>output</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;file:///b.ts.js.map&quot;: '{&quot;version&quot;:3,&quot;file&quot;:&quot;&quot;,&quot;sourceRoot&quot;:&quot;&quot;,&quot;sources&quot;:[&quot;file:///b.ts&quot;],&quot;names&quot;:[],&quot;mappings&quot;:&quot;AAAA,MAAM,C...',
  &quot;file:///a.ts.js.map&quot;: '{&quot;version&quot;:3,&quot;file&quot;:&quot;&quot;,&quot;sourceRoot&quot;:&quot;&quot;,&quot;sources&quot;:[&quot;file:///a.ts&quot;],&quot;names&quot;:[],&quot;mappings&quot;:&quot;AAAA,OAAO,K...',
  &quot;file:///a.ts.js&quot;: &quot;import * as b from '/b.ts';\nconsole.log(b);\n&quot;,
  &quot;file:///b.ts.js&quot;: &quot;export const foo = true;\n&quot;
}"><pre class="notranslate"><code class="notranslate">{
  "file:///b.ts.js.map": '{"version":3,"file":"","sourceRoot":"","sources":["file:///b.ts"],"names":[],"mappings":"AAAA,MAAM,C...',
  "file:///a.ts.js.map": '{"version":3,"file":"","sourceRoot":"","sources":["file:///a.ts"],"names":[],"mappings":"AAAA,OAAO,K...',
  "file:///a.ts.js": "import * as b from '/b.ts';\nconsole.log(b);\n",
  "file:///b.ts.js": "export const foo = true;\n"
}
</code></pre></div>
<h2 dir="auto">Problem</h2>
<p dir="auto"><code class="notranslate">Deno.compile()</code> does not convert local import URLs from <code class="notranslate">.ts</code> extension to <code class="notranslate">.js</code> extension, making it impossible to use inside browser and Node.js.</p>
<h2 dir="auto">Steps to reproduce</h2>
<p dir="auto">Run <a href="https://gist.github.com/KSXGitHub/c94a9d7eb8e976f1126b4b9dfeba0497">this file</a> (<code class="notranslate">deno run https://gist.githubusercontent.com/KSXGitHub/c94a9d7eb8e976f1126b4b9dfeba0497/raw/004a9ddb6872b9a2f05506f13f3efdfd6edd6d69/tmp.ts</code>).</p>
<h2 dir="auto">Expected behavior</h2>
<ol dir="auto">
<li>All local import URLs in output JS files should have <code class="notranslate">.js</code> extension.</li>
</ol>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// foo.js should look like this
export * from &quot;./bar.js&quot;;"><pre class="notranslate"><span class="pl-c">// foo.js should look like this</span>
<span class="pl-k">export</span> <span class="pl-c1">*</span> <span class="pl-k">from</span> <span class="pl-s">"./bar.js"</span><span class="pl-kos">;</span></pre></div>
<ol start="2" dir="auto">
<li>All local import URLs in output TypeScript definition files (<code class="notranslate">.d.ts</code>) should have no extension.</li>
</ol>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// foo.d.ts should look like this
export * from &quot;./bar&quot;;"><pre class="notranslate"><span class="pl-c">// foo.d.ts should look like this</span>
<span class="pl-k">export</span> <span class="pl-c1">*</span> <span class="pl-k">from</span> <span class="pl-s">"./bar"</span><span class="pl-kos">;</span></pre></div>
<h2 dir="auto">Actual behavior</h2>
<p dir="auto">All local import URLs are preserved, which is incorrect.</p>