-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(build)!: Provide all generator exports when loaded as script #7169
refactor(build)!: Provide all generator exports when loaded as script #7169
Conversation
0d53c49
to
0abdb9e
Compare
Previously, when loading a generator chunk (e.g., javascript_compressed.js) as a script (e.g., in a browser using a <SCRIPT> tag), only a single named export from that chunk would be made available (e.g, javascriptGenerator would be made availabe as Blockly.JavaScript). Until recently, that was fine because each generator chunk had only a single named export, but now each one additionally has a <Lang>Generator class and Order enum export. To allow these new exports to be accessed by script users, the chunk wrappers are modified to provide the whole export object at a correspondingly-named global variable—e.g., when loaded as a script javascript_compressed.js creates a global variable named javascript, so the named exports can be accessed as javascript.javascriptGenerator, javascript.JavascriptGenerator and javascript.Order, as if the user had imported them via import * as javascript from 'blockly/javascript'; This PR includes a breaking change and a deprecation, both of which are only applicable when loading generators as scripts (e.g. via a <SCRIPT> tag): BREAKING CHANGE: The generator chunks will, when loaded as scripts (e.g. via a <SCRIPT> tag, now clobber any existing global variable of the corresponding name: - dart_compresed.js will set dart - javascript_compresed.js will set javascript - lua_compresed.js will set lua - php_compresed.js will set php - python_compresed.js will set python DEPRECATION: Accessing the generator instances at their previous locations (Blockly.Dart, Blockly.JavaScript, Blockly.Lua, Blockly.PHP, and Blockly.Python) is deprecated and may cease to work in a future version of Blockly.
0abdb9e
to
5984070
Compare
Updated PR description and force-pushed to update commit message to note that there is in fact a breaking change. |
@cpcallen This PR sets the script export to Also, only JavaScript and Python set the old backwards-compatible In other words, while it was my understanding that |
reexport: 'Blockly.JavaScript', | ||
reexportOnly: 'javascriptGenerator', | ||
scriptExport: 'javascript', | ||
scriptNamedExports: {'Blockly.Javascript': 'javascriptGenerator'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @maribethb noted: this should have been Blockly.JavaScript
, not …Javascript
.
That is unexpected.
That doesn't make any sense (because the "main [Edited to add: also doesn't make any sense because the "main
Yes, those should all work (provided you |
No, PHP does as well, it turns out. |
Three separate mistakes left only the Python and PHP chunks with the correct code for the legacy script exports.
GitHub needs to add the 🤔 emoji as a reaction. |
The basics
npm run format
andnpm run lint
The details
Resolves
Implements proposal 3 (option 3B) of #7086.
Reason for Changes
Previously, when loading a generator chunk (e.g.,
javascript_compressed.js
) as a script (e.g., in a browser using a<SCRIPT>
tag), only a single named export from that chunk would be made available (e.g,javascriptGenerator
would be made available asBlockly.JavaScript
).Until recently, that was fine because each generator chunk had only a single named export, but now each one additionally has a
<Lang>Generator
class andOrder
enum export. At present developers loading generator chunks as scripts have no way to access these additional named exports.Proposed Changes
To allow these new exports to be accessed by script users, the chunk wrappers are modified to provide the whole export object at a correspondingly-named global variable—e.g., when loaded as a script,
javascript_compressed.js
creates a global variable namedjavascript
, so the named exports can be accessed asjavascript.javascriptGenerator
,javascript.JavascriptGenerator
andjavascript.Order
, as if the user had imported them viaBehaviour Before Change
javascript_compressed.js
's chunk wrapper looks like:Note that this sets only
Blockly.Javascript
.Behaviour After Change
javascript_compressed.js
's chunk wrapper looks like:Note that this sets both
javascript
andBlockly.Javascript
.Test Coverage
Passes
npm test
; will need to verify that generators are fully working when loaded via<SCRIPT>
tags (but this will happen automatically when we update the test server, which runs in compressed mode when served from a non-local web server).Documentation
We should update any generator usage documentation and codelabs that use
<SCRIPT>
tags to use the new export objects.Additional Information
BREAKING CHANGE:: The generator chunks will, when loaded as scripts (e.g. via a
<SCRIPT>
tag, now clobber any existing global variable of the corresponding name:dart_compresed.js
will setdart
javascript_compresed.js
will setjavascript
lua_compresed.js
will setlua
php_compresed.js
will setphp
python_compresed.js
will setpython
DEPRECATION: Accessing the generator instances at their previous locations (
Blockly.Dart
,Blockly.JavaScript
,Blockly.Lua
,Blockly.PHP
, andBlockly.Python
) is deprecated and may cease to work in a future version of Blockly.