refactor: remove remaining dynamic require usages in package output (#43431)

Removes the remaining usages of dynamic require statements in the
package output. Since we declare all shipped packages as strict ESM,
we cannot use dynamic require statements anymore. This commit switches
these usages to actual `import` statements.

Note: Tsickle continues to remain an optional dependency since bundling
does not work with its UMD package output. Also tsickle is rarely used by
consumers, if at all, so bundling does not really provide any significant
value. To continue keeping tsickle optional (since it's still needed by the
`annotateForClosureCompiler` option which is also respected in ngtsc), we
pass-through a tsickle instance as a parameter to `main`. This allows us to
keep the compile functions synchronous without having to refactor the majority
of the watch compilation code, and majority of tests for ngc, ngtsc.

Consumers (like the `ngc` bin entry-point) can then load tsickle based on their
module format. e.g. tsickle can be imported through `require` to keep everything
sync, but in ESM, the dynamic import can be used beforehand to pass `tsickle` to
the `main` function. We can revisit this in the future but for now this does the
trick without exceeding the scope of this commit..

PR Close #43431
This commit is contained in:
Paul Gschwendtner
2021-09-25 17:26:04 +02:00
committed by Dylan Hunn
parent 634e6662c6
commit b46b3cf43e
13 changed files with 91 additions and 47 deletions
@@ -7,6 +7,7 @@
*/
import {DepGraph} from 'dependency-graph';
import module from 'module';
import {AbsoluteFsPath, ReadonlyFileSystem} from '../../../src/ngtsc/file_system';
import {Logger} from '../../../src/ngtsc/logging';
@@ -16,7 +17,7 @@ import {PartiallyOrderedList} from '../utils';
import {createDependencyInfo, DependencyHost, EntryPointWithDependencies} from './dependency_host';
const builtinNodeJsModules = new Set<string>(require('module').builtinModules);
const builtinNodeJsModules = new Set<string>(module.builtinModules);
/**
* Holds information about entry points that are removed because