Skip to content

Commit

Permalink
fix: Fix incorrect Blockly imports (#2339)
Browse files Browse the repository at this point in the history
We have for some time promulgated

   import * as Blockly from 'blockly/core';

as the correct way to import Blockly in our documentation.
Update our own plugins and templates to match.

Because we have been packaging Blockly until now only as CJS
modules, and CJS modules always provide an (unnamed) default
export consisting of the module.exports object, importing
Blockly with

    import Blockly from 'blockly/core';

(note no "*") has worked fine (and similarly for all the
other entrypoints).

As the sources for the entrypoints (core/blockly.ts,
blocks/blocks.ts, etc.) do not explicitly declare a default
export, however, this should not be relied upon: when we start
shipping Blockly as pure-ESM there will be no default export
and so "import Blockly from …" will stop working.
  • Loading branch information
cpcallen committed May 9, 2024
1 parent 7f995dd commit 9af40b9
Show file tree
Hide file tree
Showing 24 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion plugins/block-plus-minus/src/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Changes the if block to use a +/- mutator UI.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';
import {createMinusField} from './field_minus';
import {createPlusField} from './field_plus';

Expand Down
2 changes: 1 addition & 1 deletion plugins/block-plus-minus/src/list_create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Changes the list_create block to use a +/- mutator UI.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';
import {createPlusField} from './field_plus';
import {createMinusField} from './field_minus';

Expand Down
2 changes: 1 addition & 1 deletion plugins/block-plus-minus/src/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Changes the procedure blocks to use a +/- mutator UI.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';
import {createMinusField} from './field_minus';
import {createPlusField} from './field_plus';

Expand Down
2 changes: 1 addition & 1 deletion plugins/block-plus-minus/src/text_join.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Changes the text_join block to use a +/- mutator UI.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';
import {createPlusField} from './field_plus';
import {createMinusField} from './field_minus';

Expand Down
2 changes: 1 addition & 1 deletion plugins/block-test/src/serialization/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict';

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';
import './fields';

Blockly.defineBlocksWithJsonArray([
Expand Down
2 changes: 1 addition & 1 deletion plugins/block-test/src/serialization/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict';

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';
import './blocks';

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/block-test/src/serialization/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

'use strict';

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

/**
* Field that does not override any serialization hooks.
Expand Down
2 changes: 1 addition & 1 deletion plugins/dev-create/templates/block/template/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @fileoverview Block overview.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

// TODO: Update block definition.
Blockly.defineBlocksWithJsonArray([
Expand Down
2 changes: 1 addition & 1 deletion plugins/dev-create/templates/field/template/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @fileoverview Field overview.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

// TODO: Rename field and update description.
/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/dev-create/templates/theme/template/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @fileoverview Theme overview.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

// TODO: Edit theme name.
export default Blockly.Theme.defineTheme('THEME_NAME', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @fileoverview Block overview.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

// TODO: Update block definition.
Blockly.defineBlocksWithJsonArray([
Expand Down
2 changes: 1 addition & 1 deletion plugins/dev-tools/src/debugDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Visualizer for debugging custom renderers in Blockly.
* @author fenichel@google.com (Rachel Fenichel)
*/
import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

/**
* A basic visualizer for debugging custom renderers.
Expand Down
2 changes: 1 addition & 1 deletion plugins/dev-tools/src/populateRandom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Helper for randomly populating a workspace.
* @author fenichel@google.com (Rachel Fenichel)
*/
import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

/**
* Populate the workspace with a random set of blocks, for testing.
Expand Down
2 changes: 1 addition & 1 deletion plugins/dev-tools/src/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Download screenshot.
* @author samelh@google.com (Sam El-Husseini)
*/
import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

/**
* Convert an SVG datauri into a PNG datauri.
Expand Down
2 changes: 1 addition & 1 deletion plugins/dev-tools/src/spaghetti.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* blocks, for testing.
* @author samelh@google.com (Sam El-Husseini)
*/
import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

const spaghettiXml = [
' <block type="controls_if">',
Expand Down
2 changes: 1 addition & 1 deletion plugins/field-bitmap/src/field-bitmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

export const DEFAULT_HEIGHT = 5;
export const DEFAULT_WIDTH = 5;
Expand Down
2 changes: 1 addition & 1 deletion plugins/fixed-edges/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* configurable.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

/**
* @typedef {{
Expand Down
4 changes: 2 additions & 2 deletions plugins/migration/test/rename.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ suite('Rename', function () {
],
};
const oldString = `
import Blockly from 'blockly';
import * as Blockly from 'blockly';
class SubClass extends Blockly.moduleC {
constructor() {
Expand Down Expand Up @@ -81,7 +81,7 @@ class SubClass extends Blockly.moduleC {
const newString = new Renamer(database, '0.0.0', '1.0.0').rename(oldString);

const expectedString = `
import Blockly from 'blockly';
import * as Blockly from 'blockly';
class SubClass extends Blockly.moduleC.ClassC {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion plugins/scroll-options/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';
import {EdgeScrollOptions, ScrollBlockDragger} from './ScrollBlockDragger';
import {getTranslation} from './utils';

Expand Down
2 changes: 1 addition & 1 deletion plugins/theme-dark/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Dark theme.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

/**
* Dark theme.
Expand Down
2 changes: 1 addition & 1 deletion plugins/theme-deuteranopia/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Deuteranopia theme.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

const defaultBlockStyles = {
colour_blocks: {
Expand Down
2 changes: 1 addition & 1 deletion plugins/theme-highcontrast/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Darker colours to contrast the white font.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

const defaultBlockStyles = {
colour_blocks: {
Expand Down
2 changes: 1 addition & 1 deletion plugins/theme-modern/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Modern theme.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

export default Blockly.Theme.defineTheme('modern', {
base: Blockly.Themes.Classic,
Expand Down
2 changes: 1 addition & 1 deletion plugins/theme-tritanopia/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @fileoverview Tritanopia theme.
*/

import Blockly from 'blockly/core';
import * as Blockly from 'blockly/core';

const defaultBlockStyles = {
colour_blocks: {
Expand Down

0 comments on commit 9af40b9

Please sign in to comment.