fromdeno / deno2node

Compile your Deno project to run on Node.js.
MIT License
115 stars 3 forks source link

Drop `fixMissingImports` #4

Closed KnorpelSenf closed 3 years ago

KnorpelSenf commented 3 years ago

Problem description

Using sourceFile.fixMissingImports(); is opaque. It is not clear which dependencies are imported. Also, the imported things are not necessarily stable, they could suddenly change as I add new source files. It is not clear which symbol will be imported on clashing names. If symbols are re-exported (e.g. in mod.ts, it is not clear which location will be picked, original declaration or re-export.

Desired solution

Let users specify a file with the explicit dependencies to be used that are expected to be missing, either via a program argument or just by using a default hard-coded file name for now. Then add a import * from './<filename>.ts' as a first line to every source file.

It may be possible to explicitly import all members from that given file, and then let https://ts-morph.com/details/source-files#organizing-imports remove the unused things. This has a similar effect as fixing all missing imports, but it is explicit and there are no doubts about where things are coming from. Being explicit is a good thing, and so is reproducibility.

wojpawlik commented 3 years ago

sourceFile.fixMissingImports(); also makes the tool ~1.8x slower.

// tsconfig.json
{
    "deno2node": {
        "ponyfills": "<path>" // or "polyfills"
    }
}

would be ideal, CLI option is 2nd best thing.

KnorpelSenf commented 3 years ago

Pending question: what to do with clashing names, i.e. what if I define

function foo() {}

but then the import of foo is also added.

wojpawlik commented 3 years ago

Initial implementation will simply report duplicate identifier and exit.