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 emit doesn't replace file extensions #10272

Closed
Eyal-Shalev opened this issue Apr 20, 2021 · 1 comment
Closed

Deno emit doesn't replace file extensions #10272

Eyal-Shalev opened this issue Apr 20, 2021 · 1 comment
Labels
duplicate a duplicate of another issue

Comments

@Eyal-Shalev
Copy link
Contributor

Problem

  1. The files struct (Record<string,string>), returned by running Deno.emit has the (semi) correct extensions for the file names (the keys of the struct), but the code inside the emitted output uses the original .ts extension for the import statements.
    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).

  2. I wrote above that the keys have "semi" correct extensions, because the emit method only appends .js, .js.map & .d.ts to the keys, without considering that the "real" output file shouldn't have .ts in it's name.

Example

You can see below that the output for a.ts.js has import * as b from '/b.ts'; instead of a.ts.js has import * as b from '/b.ts.js';

build.ts

const {files} = await Deno.emit(
  "/a.ts",
  {
    sources: {
      "/b.ts": "export const foo=true",
      "/a.ts": "import * as b from '/b.ts';\nconsole.log(b)"
    }
  }
);
console.log(files)

command

deno run -q --unstable build.ts

output

{
  "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"
}
@kitsonk kitsonk added the duplicate a duplicate of another issue label Apr 21, 2021
@kitsonk
Copy link
Contributor

kitsonk commented Apr 21, 2021

This is a duplicate of denoland/deno_emit#41 and something we need to address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate a duplicate of another issue
Projects
None yet
Development

No branches or pull requests

2 participants