Perhaps some background information may help you to understand what's going on here better.
The
goog.provide() and
goog.require() calls are part of the old Closure module system, a module system provided (and used) by the
Closure Library and understood by the
Closure Compiler that we use to bundle and minify both the Blockly library and the individual Blockly Games games. When I say "old" module system, I mean that it was supplanted by
the "new" goog.module system starting around 2014, which was in turn supplanted by
ECMAscript modules ("ESM"), and their equivalent
TypeScript modules, in the years since then.
Now, when I say "supplanted", what I mean is that new code has generally been written in the new system, while existing code tended to be left using the old system at least until a major porting/migration effort could be undertaken; in the mean time Google developed a bunch of clever hacks sophisticated build tools that would let us combine code written in all three systems (goog.provide, goog.module and ES modules).
In fact, the Blockly library itself has literally just yesterday finished an approximately 2.5 year migration from being written in JavaScript using
goog.provides to JavaScript using
goog.module, and then to TypeScript
+ TS modules (in some cases via JS + ES modules in the interim), though a lot of our test code is still in JavaScript.
Blockly Games has not yet been migrated, and so is still using goog.provide()s.
Now, I was trying to find documentation about how the old Closure module system (
goog.provide) works, but I can't find much on the web any more. I did find
this bit of documentation for the Closure Library in the Internet Archive, but to be honest it's not the best explanation so I'll try to summarize the important things to understand here, using some of the files mentioned above as examples.
Background: Scripts vs. Modern Modules
These days almost all code written in JavaScript is written in what I would describe as "modern module systems". The first well-known one for JavaScript was probably the
CommonJS module system; other well known ones are the aforementioned "new" Closure module system using
goog.module, and ES modules.
A "modern" module system has the feature that if I create some top-level variable or functions in one file (e.g., let name = 'Alice'; or function send(from, to, message) { /*...*/ }) those name bindings (in this case name and send) are visible throughout that file but (by default) not in any other file in my project, so if I want to use them in another file I have to do something (like import them) before I can use them. That also means I'm safe to use those names in other files without risking any clash.
But in the early days of JavaScript, there were no modules, only scripts, and if I write var name = 'Alice' in one script I create a global variable that can be seen in every other script in my project. That's bad, especially for programmers writing libraries intended to be used by other developers: every variable or function name I use potentially clashes with every other JS program that my library is used in, and with every other library that those programs also use.
The usual workaround was to create some "namespace" objects, so all the code in a particular library would could be accessed by just one name, like:
var myLibrary = {};
myLibrary.name = 'Alice';
myLibrary.send = function send(from, to, message);
Then so long as no one else used the name myLibrary there would be no clashes.
What goog.provide() Does
The original closure module system wasn't a module system in the modern sense; it was just some helper functions to make it easier to use namespace objects. The file
appengine/src/html.js contains the line:
This tells the module system "if you haven't already, please go and execute the script that contained 'provide('BlocklyGames.html')' and then finish executing the rest of this file."
(Of course there's some magic that goes on behind the scenes to make all that file loading work, but none of that is important for understanding what's going on here.)
I hope this will help you understand the code and my colleague's answer.