chore(generators): Migrate generators to ES Modules #7103
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The basics
npm run format
andnpm run lint
generators/
.)The details
Resolves
Part of #6828 and #6858.
Proposed Changes
Add support for migrating renaming imports to
js2ts
: convertinto
Also fix a bug that caused relative paths to ESM in the same directory to be missing a leading
./
.Migrate all the
goog.module
modules ingenerators/
(that is: all.js
files in that subtree) to ES modules, replacinggoog.require
withimport
.js2ts
then renaming the.ts
file back to.js
, with some small manual fixup.tsc
does not permitimport type
statements in.js
files, such statements generated byjs2ts
are commented out for now.Behaviour Before Change
These modules are loaded as
goog.module
s.Behaviour After Change
These modules are loaded as ES modules.
Reason for Changes
This is the first step of migrating these files to TypeScript, and also the only part of the TypeScript migration required in order to complete (their part) of the work to remove dependencies on the Closure module system (except for
goog.declareModuleId
calls, which are still required due to a couple of the tests still usinggoog.require
).Test Coverage
Passes
npm test
and quick manual check that generators are not completely broken in the playground. No changes to manual testing anticipated.Documentation
Should be (approximately) no visible external changes.
Additional Information
As usual with such migrations there are some changes to the internal names generated by Closure Compiler. This necessitated some small changes to the chunk configuration in
build_tasks.js
and will break devs who monkey patchnon-public generator methods.
There are some additional details discussed in the individual commit messages.