Closed KnorpelSenf closed 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.
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.
Initial implementation will simply report duplicate identifier and exit.
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. inmod.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.