Skip to content

Commit

Permalink
refactor(blocks)!: Rename Blockly.blocks.* modules to Blockly.library…
Browse files Browse the repository at this point in the history
…Blocks.* (google#5953)

...and rename Blockly.blocks.all (blocks/all.js) to
Blockly.libraryBlocks (blocks/blocks.js

BREAKING CHANGE: (only) because the exports object from the
`blocks_compressed.js` chunk will be accessed as
`Blockly.libraryBlocks` instead of `Blockly.blocks.all` when the
chunk is loaded in a browser via a `<script>` tag.  There will
be no changes visible when the chunk is loaded via ES module
`import` or CJS `require`.
  • Loading branch information
cpcallen authored Feb 23, 2022
1 parent 0c1362f commit 5078dcb
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 67 deletions.
22 changes: 11 additions & 11 deletions blocks/all.js → blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
*/
'use strict';

goog.module('Blockly.blocks.all');
goog.module('Blockly.libraryBlocks');
goog.module.declareLegacyNamespace();

const colour = goog.require('Blockly.blocks.colour');
const lists = goog.require('Blockly.blocks.lists');
const logic = goog.require('Blockly.blocks.logic');
const loops = goog.require('Blockly.blocks.loops');
const math = goog.require('Blockly.blocks.math');
const procedures = goog.require('Blockly.blocks.procedures');
const texts = goog.require('Blockly.blocks.texts');
const variables = goog.require('Blockly.blocks.variables');
const variablesDynamic = goog.require('Blockly.blocks.variablesDynamic');
const colour = goog.require('Blockly.libraryBlocks.colour');
const lists = goog.require('Blockly.libraryBlocks.lists');
const logic = goog.require('Blockly.libraryBlocks.logic');
const loops = goog.require('Blockly.libraryBlocks.loops');
const math = goog.require('Blockly.libraryBlocks.math');
const procedures = goog.require('Blockly.libraryBlocks.procedures');
const texts = goog.require('Blockly.libraryBlocks.texts');
const variables = goog.require('Blockly.libraryBlocks.variables');
const variablesDynamic = goog.require('Blockly.libraryBlocks.variablesDynamic');
/* eslint-disable-next-line no-unused-vars */
const {BlockDefinition} = goog.requireType('Blockly.blocks');

Expand All @@ -38,7 +38,7 @@ exports.variablesDynamic = variablesDynamic;

/**
* A dictionary of the block definitions provided by all the
* Blockly.blocks.* modules.
* Blockly.libraryBlocks.* modules.
* @type {!Object<string, !BlockDefinition>}
*/
const blocks = Object.assign(
Expand Down
2 changes: 1 addition & 1 deletion blocks/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
'use strict';

goog.module('Blockly.blocks.colour');
goog.module('Blockly.libraryBlocks.colour');

/* eslint-disable-next-line no-unused-vars */
const {BlockDefinition} = goog.requireType('Blockly.blocks');
Expand Down
2 changes: 1 addition & 1 deletion blocks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.lists');
goog.module('Blockly.libraryBlocks.lists');

const xmlUtils = goog.require('Blockly.utils.xml');
const {Align} = goog.require('Blockly.Input');
Expand Down
2 changes: 1 addition & 1 deletion blocks/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.logic');
goog.module('Blockly.libraryBlocks.logic');

/* eslint-disable-next-line no-unused-vars */
const AbstractEvent = goog.requireType('Blockly.Events.Abstract');
Expand Down
7 changes: 5 additions & 2 deletions blocks/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.loops');
goog.module('Blockly.libraryBlocks.loops');

/* eslint-disable-next-line no-unused-vars */
const AbstractEvent = goog.requireType('Blockly.Events.Abstract');
Expand Down Expand Up @@ -297,9 +297,12 @@ Extensions.register(
* loopTypes.add('custom_loop');
*
* // Else if using Closure Compiler and goog.modules:
* const {loopTypes} = goog.require('Blockly.blocks.loops');
* const {loopTypes} = goog.require('Blockly.libraryBlocks.loops');
* loopTypes.add('custom_loop');
*
* // Else if using blockly_compressed + blockss_compressed.js in browser:
* Blockly.libraryBlocks.loopTypes.add('custom_loop');
*
* @type {!Set<string>}
*/
const loopTypes = new Set([
Expand Down
2 changes: 1 addition & 1 deletion blocks/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.math');
goog.module('Blockly.libraryBlocks.math');

const Extensions = goog.require('Blockly.Extensions');
// N.B.: Blockly.FieldDropdown needed for type AND side-effects.
Expand Down
2 changes: 1 addition & 1 deletion blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.procedures');
goog.module('Blockly.libraryBlocks.procedures');

/* eslint-disable-next-line no-unused-vars */
const AbstractEvent = goog.requireType('Blockly.Events.Abstract');
Expand Down
2 changes: 1 addition & 1 deletion blocks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.texts');
goog.module('Blockly.libraryBlocks.texts');

const Extensions = goog.require('Blockly.Extensions');
const {Msg} = goog.require('Blockly.Msg');
Expand Down
2 changes: 1 addition & 1 deletion blocks/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.variables');
goog.module('Blockly.libraryBlocks.variables');

const ContextMenu = goog.require('Blockly.ContextMenu');
const Extensions = goog.require('Blockly.Extensions');
Expand Down
2 changes: 1 addition & 1 deletion blocks/variables_dynamic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
'use strict';

goog.module('Blockly.blocks.variablesDynamic');
goog.module('Blockly.libraryBlocks.variablesDynamic');

/* eslint-disable-next-line no-unused-vars */
const AbstractEvent = goog.requireType('Blockly.Events.Abstract');
Expand Down
8 changes: 4 additions & 4 deletions scripts/gulpfiles/build_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const NAMESPACE_OBJECT = '$';
* - .importAs: the name that this chunk's exports object will be
* given when passed to the factory function of other chunks that
* depend on it. (Needs to be distinct from .exports since (e.g.)
* "Blockly.blocks.all" is not a valid variable name.)
* "Blockly.libraryBlocks" is not a valid variable name.)
* - .factoryPreamble: code to override the default wrapper factory
* function preamble.
* - .factoryPostamble: code to override the default wrapper factory
Expand All @@ -107,9 +107,9 @@ const chunks = [
},
{
name: 'blocks',
entry: 'blocks/all.js',
exports: 'Blockly.blocks.all',
importAs: 'BlocklyBlocks',
entry: 'blocks/blocks.js',
exports: 'Blockly.libraryBlocks',
importAs: 'libraryBlocks',
},
{
name: 'javascript',
Expand Down
26 changes: 13 additions & 13 deletions scripts/gulpfiles/chunks.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"chunk": [
"blockly:259",
"all:10:blockly",
"blocks:10:blockly",
"all:11:blockly",
"all1:11:blockly",
"all2:11:blockly",
"all3:11:blockly",
"all4:11:blockly",
"all5:11:blockly"
"all4:11:blockly"
],
"js": [
"./core/inject.js",
Expand Down Expand Up @@ -80,11 +80,9 @@
"./core/utils/math.js",
"./core/utils/array.js",
"./core/workspace.js",
"./core/events/events_block_delete.js",
"./core/keyboard_nav/basic_cursor.js",
"./core/keyboard_nav/tab_navigate_cursor.js",
"./core/warning.js",
"./core/events/events_bubble_open.js",
"./core/comment.js",
"./core/events/events_block_drag.js",
"./core/events/events_block_move.js",
Expand All @@ -99,21 +97,22 @@
"./core/zoom_controls.js",
"./core/workspace_drag_surface_svg.js",
"./core/events/events_selected.js",
"./core/events/events_comment_move.js",
"./core/events/events_comment_delete.js",
"./core/events/events_comment_create.js",
"./core/events/events_comment_base.js",
"./core/events/events_comment_change.js",
"./core/workspace_comment.js",
"./core/interfaces/i_movable.js",
"./core/interfaces/i_selectable.js",
"./core/interfaces/i_copyable.js",
"./core/events/events_comment_delete.js",
"./core/events/events_comment_change.js",
"./core/workspace_comment.js",
"./core/events/events_comment_create.js",
"./core/events/events_comment_base.js",
"./core/events/events_comment_move.js",
"./core/workspace_comment_svg.js",
"./core/workspace_audio.js",
"./core/events/events_trashcan_open.js",
"./core/sprites.js",
"./core/drag_target.js",
"./core/delete_area.js",
"./core/events/events_block_delete.js",
"./core/positionable_helpers.js",
"./core/trashcan.js",
"./core/touch_gesture.js",
Expand Down Expand Up @@ -197,7 +196,6 @@
"./core/events/events_var_delete.js",
"./core/variable_map.js",
"./core/names.js",
"./core/events/events_ui_base.js",
"./core/events/events_marker_move.js",
"./core/renderers/common/marker_svg.js",
"./core/keyboard_nav/marker.js",
Expand Down Expand Up @@ -226,6 +224,8 @@
"./core/utils/svg_paths.js",
"./core/renderers/common/constants.js",
"./core/field.js",
"./core/events/events_ui_base.js",
"./core/events/events_bubble_open.js",
"./core/procedures.js",
"./core/workspace_svg.js",
"./core/utils/rect.js",
Expand Down Expand Up @@ -277,7 +277,7 @@
"./blocks/logic.js",
"./blocks/lists.js",
"./blocks/colour.js",
"./blocks/all.js",
"./blocks/blocks.js",
"./generators/javascript/variables_dynamic.js",
"./generators/javascript/variables.js",
"./generators/javascript/text.js",
Expand Down
30 changes: 30 additions & 0 deletions scripts/migration/renamings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,36 @@ const renamings = {
},
},
},
'Blockly.blocks.all': {
module: 'Blockly.libraryBlocks',
},
'Blockly.blocks.colour': {
module: 'Blockly.libraryBlocks.colour',
},
'Blockly.blocks.lists': {
module: 'Blockly.libraryBlocks.lists',
},
'Blockly.blocks.logic': {
module: 'Blockly.libraryBlocks.logic',
},
'Blockly.blocks.loops': {
module: 'Blockly.libraryBlocks.loops',
},
'Blockly.blocks.math': {
module: 'Blockly.libraryBlocks.math',
},
'Blockly.blocks.procedures': {
module: 'Blockly.libraryBlocks.procedures',
},
'Blockly.blocks.text': {
module: 'Blockly.libraryBlocks.text',
},
'Blockly.blocks.variables': {
module: 'Blockly.libraryBlocks.variables',
},
'Blockly.blocks.variablesDynamic': {
module: 'Blockly.libraryBlocks.variablesDynamic',
},
},
};

Expand Down
4 changes: 2 additions & 2 deletions tests/compile/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ goog.require('Blockly');
goog.require('Blockly.geras.Renderer');
goog.require('Blockly.VerticalFlyout');
// Blocks
goog.require('Blockly.blocks.all');
goog.require('Blockly.blocks.testBlocks');
goog.require('Blockly.libraryBlocks');
goog.require('Blockly.libraryBlocks.testBlocks');

Main.init = function() {
Blockly.inject('blocklyDiv', {
Expand Down
2 changes: 1 addition & 1 deletion tests/compile/test_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
'use strict';

goog.provide('Blockly.blocks.testBlocks');
goog.provide('Blockly.libraryBlocks.testBlocks');

goog.require('Blockly');

Expand Down
20 changes: 10 additions & 10 deletions tests/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/generators/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
goog.require('Blockly.Lua.all');
goog.require('Blockly.PHP.all');
goog.require('Blockly.Python.all');
goog.require('Blockly.blocks.all');
goog.require('Blockly.libraryBlocks');
</script>
<script src="unittest_javascript.js"></script>
<script src="unittest_python.js"></script>
Expand Down
18 changes: 9 additions & 9 deletions tests/mocha/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
goog.require('Blockly.PHP.texts');
goog.require('Blockly.Python');
goog.require('Blockly.Python.texts');
goog.require('Blockly.blocks.colour');
goog.require('Blockly.blocks.logic');
goog.require('Blockly.blocks.lists');
goog.require('Blockly.blocks.loops');
goog.require('Blockly.blocks.math');
goog.require('Blockly.blocks.procedures');
goog.require('Blockly.blocks.texts');
goog.require('Blockly.blocks.variables');
goog.require('Blockly.blocks.variablesDynamic');
goog.require('Blockly.libraryBlocks.colour');
goog.require('Blockly.libraryBlocks.logic');
goog.require('Blockly.libraryBlocks.lists');
goog.require('Blockly.libraryBlocks.loops');
goog.require('Blockly.libraryBlocks.math');
goog.require('Blockly.libraryBlocks.procedures');
goog.require('Blockly.libraryBlocks.texts');
goog.require('Blockly.libraryBlocks.variables');
goog.require('Blockly.libraryBlocks.variablesDynamic');

// Run tests.
goog.require('Blockly.test.astNode');
Expand Down
2 changes: 1 addition & 1 deletion tests/playgrounds/advanced_playground.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

// Other.
goog.require('Blockly.WorkspaceCommentSvg');
goog.require('Blockly.libraryBlocks');
goog.require('Blockly.Dart.all');
goog.require('Blockly.JavaScript.all');
goog.require('Blockly.Lua.all');
goog.require('Blockly.PHP.all');
goog.require('Blockly.Python.all');
goog.require('Blockly.blocks.all');
</script>
<script>
'use strict';
Expand Down
4 changes: 2 additions & 2 deletions tests/playgrounds/load_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ if ((location.hostname === 'localhost' || location.hostname === '127.0.0.1' ||
`<script src="../node_modules/@blockly/block-test/dist/index.js"></script>`);
document.write(`<script>
// Custom requires for the playground.
goog.require('Blockly.libraryBlocks');
goog.require('Blockly.Dart.all');
goog.require('Blockly.JavaScript.all');
goog.require('Blockly.Lua.all');
goog.require('Blockly.PHP.all');
goog.require('Blockly.Python.all');
goog.require('Blockly.WorkspaceCommentSvg');
goog.require('Blockly.blocks.all');
</script>`);
} else {
document.write(
`<script src="../blockly_compressed.js" id="blockly-compressed-script"></script>`);
document.write(`<script src="../blocks_compressed.js"></script>`);
document.write(`<script src="../dart_compressed.js"></script>`);
document.write(`<script src="../javascript_compressed.js"></script>`);
document.write(`<script src="../lua_compressed.js"></script>`);
document.write(`<script src="../php_compressed.js"></script>`);
document.write(`<script src="../python_compressed.js"></script>`);
document.write(`<script src="../blocks_compressed.js"></script>`);
document.write(`<script src="../msg/messages.js"></script>`);
}
})();
Loading

0 comments on commit 5078dcb

Please sign in to comment.