You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a discussion + tracking bug for work to remove our remaining dependencies on the Closure library (of which closure/goog/base.js and …/goog.js are the only remaining pieces) and the Closure module system (goog.module / goog.require).
The existence of this bug does not denote that a decision to remove the Closure library from our codebase; it exists merely to document what would be involved in doing so and track what work is done in that direction, as well as to provide a place to discuss the merits of such work.
Background
Terminology
There are several related but separate Google products named "Closure":
The Closure Library, which Blockly previously used for various purposes (including use of its UI widgets); most of it was removed prior to 2021 and its use in this repo has since PR Remove closure base file dependency #2976 been limited to supporting the closure module system.
The Closure Compiler, which we used as a bundler, chunker and minifier.
Use of the Closure module system ties us to base.js for uncompiled-mode loading and to Closure Compiler for bundling. Since we'd like to try alternative bundlers such as Webpack, it would be good to remove our remaining use of the module system.
Even once we have fully removed use of the Closure module system we may wish to retain use of the debug module loader (in base.js) at least in the short term because it can do useful things like load JS scripts (via <script> tags) after ES modules have been imported.
We will probably wish to continue to use Closure Compiler at least until an alternative bunding/minification tool has been proven to be a good alternative. This is likely to entail our continued use of closure-calculate-chunks which depends on closure-make-deps which in turn expects the existence of at least a minimal base.js.
Work already completed
(…as of the creation of this bug, late February 2023)
We've broken all import cycles amongst modules in core/.
closure-make-deps enforces a rule against circular goog.requires because the semantics of Closure modules do not allow these.
Circular imports amongst ES modules are in general perfectly legal, although they can make module loading "fragile": particularly where a class in one module in a cycle extends a class defined in another module in that same cycle, it matters which module is imported first.
closure-make-deps does not enforce a rule against import cycles, but the debug module loader (somewhat accidentally) does in some cases, due to assertion check in its simplistic implementation of goog.declareModuleId.
Because there is no equivalent of goog.module.get for ESM modules, we introduced a number of import cycles while converting core/ from Closure modules to TypeScript modules.
core/main.js: most of this is deprecated get/set acccessors which can be deleted, but here may be some technical challenges converting any remaining code to TS or ESM because:
this file is our main entry point (for deps, chunking, and compilation), and
it was created as a refuge for code we didn't want to convert to TS when we converted the rest of core/.
The advanced compilation test (which we may also wish to convert to TypeScript at the same time):
tests/compile/test_blocks.js
tests/compile/main.js
Remove other remaining uses of goog.require
These are relatively straight forward to do once we no longer have any goog.modules.
Convert remaining mocha tests to use import:
tests/mocha/index.html
tests/mocha/field_multilineinput_test.js
tests/mocha/generator_test.js
Deprecate bootstrap.js and the debug module loader
Modify tests/bootstrap.js and helpers to use import instead of goog.require. This may involve a substantial rewrite, if we cannot continue to use goog.bootstrap. Replace tests/bootstrap.js:
Create shims: ES modules that will either import the chunk entry point or use a <script> tag to load the compressed chunk, and then (in either case) export the chunk's public API.
Convert tests/playground.html to use shims.
Convert tests/multi_playground.html to use shims.
Convert tests/playgrounds/advanced_playground.html to use shims.
Convert tests/mocha/index.html to use shims.
Convert tests/generators/index.html to use shims.
Delete tests/bootstrap.js et al.
Remove Closure library
This is lower-priority work, but would let us remove a bunch of cruft from our codebase and build pipeline.
Remove calls to goog.declareModuleId() throughout the codebase.
With no goog.require calls, these are no longer needed.
This is a discussion + tracking bug for work to remove our remaining dependencies on the Closure library (of which
closure/goog/base.js
and…/goog.js
are the only remaining pieces) and the Closure module system (goog.module
/goog.require
).The existence of this bug does not denote that a decision to remove the Closure library from our codebase; it exists merely to document what would be involved in doing so and track what work is done in that direction, as well as to provide a place to discuss the merits of such work.
Background
Terminology
There are several related but separate Google products named "Closure":
goog.module
.Overview, Motivation and Limitations
Use of the Closure module system ties us to
base.js
for uncompiled-mode loading and to Closure Compiler for bundling. Since we'd like to try alternative bundlers such as Webpack, it would be good to remove our remaining use of the module system.Even once we have fully removed use of the Closure module system we may wish to retain use of the debug module loader (in
base.js
) at least in the short term because it can do useful things like load JS scripts (via<script>
tags) after ES modules have beenimport
ed.We will probably wish to continue to use Closure Compiler at least until an alternative bunding/minification tool has been proven to be a good alternative. This is likely to entail our continued use of
closure-calculate-chunks
which depends onclosure-make-deps
which in turn expects the existence of at least a minimalbase.js
.Work already completed
(…as of the creation of this bug, late February 2023)
goog.module
etc.) incore/
was retired with PR chore: Migrate core/ to Typescript, actually #6299 (see also issue Update Blockly codebase to Typescript #5857), but we still use it in various places, notably inblocks/
andgenerators/
.import
cycles amongst modules incore/
.closure-make-deps
enforces a rule against circulargoog.require
s because the semantics of Closure modules do not allow these.import
ed first.closure-make-deps
does not enforce a rule againstimport
cycles, but the debug module loader (somewhat accidentally) does in some cases, due to assertion check in its simplistic implementation ofgoog.declareModuleId
.goog.module.get
for ESM modules, we introduced a number ofimport
cycles while convertingcore/
from Closure modules to TypeScript modules.import
incore/
#6818.Remaining Work
Convert remaining
goog.module
s to ES Modules (or TypeScript modules)We almost certainly want to do all of this, as these are blockers for trying Webpack.
blocks/*
andgenerators/*
: tracked (as part of the migration to TypeScript) in Convertblocks/
andgenerators/
to TypeScript #6828.core/main.js
: most of this is deprecatedget
/set
acccessors which can be deleted, but here may be some technical challenges converting any remaining code to TS or ESM because:core/
.tests/compile/test_blocks.js
tests/compile/main.js
Remove other remaining uses of
goog.require
These are relatively straight forward to do once we no longer have any
goog.module
s.import
:tests/mocha/index.html
tests/mocha/field_multilineinput_test.js
tests/mocha/generator_test.js
Deprecate
bootstrap.js
and the debug module loaderModifyReplacetests/bootstrap.js
and helpers to useimport
instead ofgoog.require
. This may involve a substantial rewrite, if we cannot continue to usegoog.bootstrap
.tests/bootstrap.js
:import
the chunk entry point or use a<script>
tag to load the compressed chunk, and then (in either case)export
the chunk's public API.tests/playground.html
to use shims.tests/multi_playground.html
to use shims.tests/playgrounds/advanced_playground.html
to use shims.tests/mocha/index.html
to use shims.tests/generators/index.html
to use shims.tests/bootstrap.js
et al.Remove Closure library
This is lower-priority work, but would let us remove a bunch of cruft from our codebase and build pipeline.
goog.declareModuleId()
throughout the codebase.goog.require
calls, these are no longer needed.goog.module
IDs #7471base.js
.closure-make-deps
as well as the Closure Compiler.base_minimal.js
if we continue to use those tools, as they mostly operate on paths relative tobase.js
.closure-make-deps
andclosure-calculate-chunks
#7469closure/goog/base.js
.closure/goog/goog.js
.closure/*
.Cleanup
sortRequires
gulp task #7470The text was updated successfully, but these errors were encountered: