-
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
fix: loading messages from script tags. #6184
Conversation
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.
Comments as discussed.
scripts/gulpfiles/package_tasks.js
Outdated
@@ -29,12 +29,14 @@ const TEMPLATE_DIR = 'scripts/package/templates'; | |||
* @param {string} namespace The export namespace. | |||
* @param {Array<Object>} dependencies An array of dependencies to inject. | |||
*/ | |||
function packageUMD(namespace, dependencies) { | |||
function packageUMD( | |||
namespace, dependencies, exportsName = namespace, template = 'umd.template' |
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 noted we can probably omit the exportsName
parameter and just hardcode return messages'
in msg-umd.template
.
} else if (typeof exports === 'object') { // Node.js | ||
module.exports = factory(); | ||
} else { // Browser | ||
Object.assign(root.<%= namespace %>, factory()); |
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.
This will not be compatible with IE11. As discussed: it should be fine to use .setLocale
here.
amd: '../core', | ||
cjs: '../core', |
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.
Remove dependencies because messages don't actually depend on core.
scripts/gulpfiles/package_tasks.js
Outdated
function packageUMD( | ||
namespace, dependencies, template = 'umd.template' | ||
) { |
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.
Formatting.
const messages = factory(); | ||
for (const key in messages) { |
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 noted: IE11 doesn't much like const
, so use var
.
* fix: loading messages in the browser * chore: fix comment * fix: change unwrapped message files to write to a new object, rather than Blockly.Msg * fix: fixup exports * fix: PR comments * fix: change to use for-in loop * fix: ES6 compatibility and formatting
The basics
npm run format
andnpm run lint
The details
Resolves
Fixes #6123, fixes google/blockly-samples#1066 and fixes google/blockly-samples#1065
Same as #6060, but hopefully this also works for requiring multiple CJS modules.
Proposed Changes
See #6123 (comment)
Also changed the generated, but unwrapped, msg.js files to write to a new
messages
object, rather thanBlockly.Msg
to be clearer about what we're doing, and hopefully prevent errors in the future.Behavior Before Change
Message loading from script tags does not work.
Behavior After Change
Message loading from script tags works.
Reason for Changes
See #6123 (comment)
Test Coverage
prepare.js
to pull thedist/msg/es.js
file instead ofmsg/messages.js
import Fr from 'blockly/msg/fr'
andBlockly.setLocale(Fr)
I couldn't find anything that actually uses CJS modules to be able to test.
Documentation
N/A
Additional Information
Will undraft after testing.