Skip to content

fix: Fix incorrect Blockly imports#2339

Merged
cpcallen merged 1 commit intoRaspberryPiFoundation:masterfrom
cpcallen:fix/imports
May 9, 2024
Merged

fix: Fix incorrect Blockly imports#2339
cpcallen merged 1 commit intoRaspberryPiFoundation:masterfrom
cpcallen:fix/imports

Conversation

@cpcallen
Copy link
Collaborator

@cpcallen cpcallen commented May 2, 2024

The basics

The details

Proposed Changes

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.

Reason for Changes

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.

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.
@cpcallen cpcallen added category: plugin Anything in the plugins folder cleanup labels May 2, 2024
@cpcallen cpcallen requested a review from a team as a code owner May 2, 2024 10:12
@cpcallen cpcallen requested review from maribethb and removed request for a team May 2, 2024 10:12
@cpcallen cpcallen merged commit 9af40b9 into RaspberryPiFoundation:master May 9, 2024
@cpcallen cpcallen deleted the fix/imports branch May 9, 2024 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: plugin Anything in the plugins folder cleanup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants