From 621e5db9357a6e6290fb5a66a1f5c146b3f3a7da Mon Sep 17 00:00:00 2001 From: lizschwab Date: Mon, 9 Nov 2026 14:55:21 -0800 Subject: [PATCH 1/5] feat: Update cross-tab-copy-paste to ESM --- eslint.config.mjs | 1 + .../plugins/cross-tab-copy-paste/package.json | 17 ++++++++++++++--- .../plugins/cross-tab-copy-paste/test/index.ts | 2 +- .../plugins/cross-tab-copy-paste/tsconfig.json | 10 ++-------- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 0624174c8cd..7a2947fcb1a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -416,6 +416,7 @@ export default defineConfig( 'packages/plugins/block-test/**', 'packages/plugins/content-highlight/**', 'packages/plugins/continuous-toolbox/**', + 'packages/plugins/cross-tab-copy-paste/**', 'packages/plugins/dev-scripts/**', 'packages/plugins/dev-tools/**', 'packages/plugins/theme-dark/**', diff --git a/packages/plugins/cross-tab-copy-paste/package.json b/packages/plugins/cross-tab-copy-paste/package.json index 210522a8728..71d3ed1ae96 100644 --- a/packages/plugins/cross-tab-copy-paste/package.json +++ b/packages/plugins/cross-tab-copy-paste/package.json @@ -12,9 +12,13 @@ "start": "blockly-scripts start", "test": "blockly-scripts test" }, - "main": "./dist/index.js", - "types": "./dist/index.d.ts", - "unpkg": "./dist/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "unpkg": "./dist/esm/index.js", + "type": "module", + "engines": { + "node": ">=24" + }, "author": "", "keywords": [ "blockly", @@ -38,6 +42,13 @@ "dist", "src" ], + "exports": { + ".": { + "node": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"}, + "import": {"types": "./dist/esm/index.d.ts", "default": "./dist/esm/index.js"}, + "require": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"} + } + }, "devDependencies": { "@blockly/dev-scripts": "^13.4.0", "@blockly/dev-tools": "^13.4.0" diff --git a/packages/plugins/cross-tab-copy-paste/test/index.ts b/packages/plugins/cross-tab-copy-paste/test/index.ts index 42083841470..a73162f3ba5 100644 --- a/packages/plugins/cross-tab-copy-paste/test/index.ts +++ b/packages/plugins/cross-tab-copy-paste/test/index.ts @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {toolboxCategories, createPlayground} from '@blockly/dev-tools'; -import {CrossTabCopyPaste} from '../src/index'; +import {CrossTabCopyPaste} from '../src/index.js'; /** * Create a workspace. diff --git a/packages/plugins/cross-tab-copy-paste/tsconfig.json b/packages/plugins/cross-tab-copy-paste/tsconfig.json index 99858c525f1..a6e04369c08 100644 --- a/packages/plugins/cross-tab-copy-paste/tsconfig.json +++ b/packages/plugins/cross-tab-copy-paste/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@blockly/dev-scripts/config/tsconfig.base.json", "compilerOptions": { "rootDir": "./src", - "outDir": "dist", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "module": "es2015", - "moduleResolution": "bundler", - "target": "es6", - "strict": true + "outDir": "dist/esm" }, // NOTE: `test/**/*` is automatically included in `blockly-scripts start`. // Only src matters for production builds. From b617dda70e5e1fb0fa056f1ecbd29c984588c0cb Mon Sep 17 00:00:00 2001 From: lizschwab Date: Tue, 10 Nov 2026 16:30:48 -0800 Subject: [PATCH 2/5] feat: Updated dev-create to ESM --- eslint.config.mjs | 1 + packages/plugins/dev-create/bin/app.js | 25 +++++---- packages/plugins/dev-create/bin/common.js | 6 +-- packages/plugins/dev-create/bin/create.js | 16 +++--- packages/plugins/dev-create/bin/plugin.js | 52 +++++++++++++------ packages/plugins/dev-create/package.json | 4 ++ .../block/template/test/block_test.mocha.js | 33 ++++++------ .../templates/block/template/test/index.js | 2 +- .../field/template/test/field_test.mocha.js | 4 +- .../templates/field/template/test/index.js | 2 +- .../templates/plugin/template/test/index.js | 2 +- .../templates/theme/template/test/index.js | 2 +- .../typescript-block/template/test/index.ts | 12 ++--- .../typescript-block/template/tsconfig.json | 10 +--- .../typescript-field/template/src/index.ts | 12 ++++- .../typescript-field/template/test/index.ts | 12 ++--- .../typescript-field/template/tsconfig.json | 10 +--- .../typescript-plugin/template/test/index.ts | 2 +- .../typescript-plugin/template/tsconfig.json | 10 +--- .../typescript-theme/template/src/index.ts | 3 +- .../typescript-theme/template/test/index.ts | 12 ++--- .../typescript-theme/template/tsconfig.json | 10 +--- 22 files changed, 128 insertions(+), 114 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 7a2947fcb1a..fa39f149fdb 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -417,6 +417,7 @@ export default defineConfig( 'packages/plugins/content-highlight/**', 'packages/plugins/continuous-toolbox/**', 'packages/plugins/cross-tab-copy-paste/**', + 'packages/plugins/dev-create/**', 'packages/plugins/dev-scripts/**', 'packages/plugins/dev-tools/**', 'packages/plugins/theme-dark/**', diff --git a/packages/plugins/dev-create/bin/app.js b/packages/plugins/dev-create/bin/app.js index 79c94b1f011..0005fa4915b 100644 --- a/packages/plugins/dev-create/bin/app.js +++ b/packages/plugins/dev-create/bin/app.js @@ -1,10 +1,10 @@ -const chalk = require('chalk').default; -const fs = require('fs-extra'); -const path = require('path'); -const execSync = require('child_process').execSync; -const {checkAndCreateDir} = require('./common'); +import chalk from 'chalk'; +import fs from 'fs-extra'; +import path from 'path'; +import {execSync} from 'child_process'; +import {checkAndCreateDir} from './common.js'; -exports.createApp = function (name, options) { +export function createApp(name, options) { const root = process.cwd(); const dir = options.dir ?? name; const appPath = path.join(root, dir); @@ -25,16 +25,21 @@ exports.createApp = function (name, options) { 'package-lock.json', 'package.json', ].map((file) => { - return path.resolve(__dirname, sampleDir, file); + return path.resolve(import.meta.dirname, sampleDir, file); }); - fs.copySync(path.resolve(__dirname, sampleDir), appPath, { + fs.copySync(path.resolve(import.meta.dirname, sampleDir), appPath, { filter(src) { return !excludes.includes(src); }, }); // Create package.json file for app. - const templateJson = require(path.join(sampleDir, 'package.json')); + const templateJson = JSON.parse( + fs.readFileSync( + path.resolve(import.meta.dirname, sampleDir, 'package.json'), + 'utf8', + ), + ); const packageJson = { ...templateJson, name: name, @@ -63,4 +68,4 @@ exports.createApp = function (name, options) { } console.log(chalk.blue(' npm start')); console.log('See README.md for more commands and information.'); -}; +} diff --git a/packages/plugins/dev-create/bin/common.js b/packages/plugins/dev-create/bin/common.js index 1dac2bf07b9..27a0f965665 100644 --- a/packages/plugins/dev-create/bin/common.js +++ b/packages/plugins/dev-create/bin/common.js @@ -1,11 +1,11 @@ -const fs = require('fs-extra'); +import fs from 'fs-extra'; /** * Create package directory if it doesn't exist yet. * Throws if the directory exists and isn't the current directory. * @param {string} path Path at which to create directory. */ -exports.checkAndCreateDir = function (path) { +export function checkAndCreateDir(path) { const root = process.cwd(); // If we're already in the desired directory, don't need to create it. if (path == root) { @@ -20,4 +20,4 @@ exports.checkAndCreateDir = function (path) { // Create the directory. fs.mkdirSync(path); } -}; +} diff --git a/packages/plugins/dev-create/bin/create.js b/packages/plugins/dev-create/bin/create.js index 367f180bc4d..b926f9c58a1 100755 --- a/packages/plugins/dev-create/bin/create.js +++ b/packages/plugins/dev-create/bin/create.js @@ -10,17 +10,19 @@ * templates. */ -'use strict'; - -const commander = require('commander'); -const scriptPackageJson = require('../package.json'); -const {createApp} = require('./app'); -const {createPlugin} = require('./plugin'); +import {Command} from 'commander'; +import fs from 'fs-extra'; +import path from 'path'; +import {createApp} from './app.js'; +import {createPlugin} from './plugin.js'; const pluginTypes = ['plugin', 'field', 'block', 'theme']; +const scriptPackageJson = JSON.parse( + fs.readFileSync(path.join(import.meta.dirname, '../package.json'), 'utf8'), +); const scriptName = scriptPackageJson.name; -const program = new commander.Command(scriptName); +const program = new Command(scriptName); program .command('plugin', {isDefault: true}) diff --git a/packages/plugins/dev-create/bin/plugin.js b/packages/plugins/dev-create/bin/plugin.js index efd8ed151ce..e3cc5723aeb 100644 --- a/packages/plugins/dev-create/bin/plugin.js +++ b/packages/plugins/dev-create/bin/plugin.js @@ -10,19 +10,17 @@ * templates. */ -'use strict'; - -const chalk = require('chalk').default; -const fs = require('fs-extra'); -const path = require('path'); -const execSync = require('child_process').execSync; -const {checkAndCreateDir} = require('./common'); +import chalk from 'chalk'; +import fs from 'fs-extra'; +import path from 'path'; +import {execSync} from 'child_process'; +import {checkAndCreateDir} from './common.js'; const pluginTypes = ['plugin', 'field', 'block', 'theme']; const root = process.cwd(); -exports.createPlugin = function (pluginName, options) { +export function createPlugin(pluginName, options) { let gitRoot = ''; let gitURL = ''; try { @@ -38,7 +36,7 @@ exports.createPlugin = function (pluginName, options) { const isGit = !!gitURL; const isFirstParty = options.firstParty || - gitURL == 'https://github.com/RaspberryPiFoundation/blockly-samples'; + gitURL == 'https://github.com/RaspberryPiFoundation/blockly'; /** * Gets the name of the plugin prefixed with the type. @@ -108,9 +106,13 @@ exports.createPlugin = function (pluginName, options) { 'start': 'blockly-scripts start', 'test': 'blockly-scripts test', }, - main: './dist/index.js', - module: './src/index.js', - unpkg: './dist/index.js', + main: './dist/cjs/index.js', + module: './dist/esm/index.js', + unpkg: './dist/esm/index.js', + type: 'module', + engines: { + node: '>=24', + }, author: pluginAuthor, keywords: [ 'blockly', @@ -118,7 +120,7 @@ exports.createPlugin = function (pluginName, options) { pluginType != 'plugin' && `blockly-${pluginType}`, pluginName, ].filter(Boolean), - homepage: isGit ? `${gitURL}/tree/master/${gitPluginPath}#readme` : '', + homepage: isGit ? `${gitURL}/tree/main/${gitPluginPath}#readme` : '', bugs: isGit ? { url: `${gitURL}/issues`, @@ -137,6 +139,19 @@ exports.createPlugin = function (pluginName, options) { src: 'src', }, files: ['dist', 'src'], + exports: { + '.': { + node: {types: './dist/cjs/index.d.ts', default: './dist/cjs/index.js'}, + import: { + types: './dist/esm/index.d.ts', + default: './dist/esm/index.js', + }, + require: { + types: './dist/cjs/index.d.ts', + default: './dist/cjs/index.js', + }, + }, + }, devDependencies: {}, peerDependencies: { blockly: `^${latestBlocklyVersion}`, @@ -165,19 +180,22 @@ exports.createPlugin = function (pluginName, options) { // Write the README.md to the new package. let readme = fs.readFileSync( - path.resolve(__dirname, templateDir, 'README.md'), + path.resolve(import.meta.dirname, templateDir, 'README.md'), 'utf-8', ); readme = readme.replace(/@blockly\/plugin/gim, `${pluginPackageName}`); fs.writeFileSync(path.join(pluginPath, 'README.md'), readme, 'utf-8'); // Copy the rest of the template folder into the new package. - fs.copySync(path.resolve(__dirname, templateDir, 'template'), pluginPath); + fs.copySync( + path.resolve(import.meta.dirname, templateDir, 'template'), + pluginPath, + ); // Copy third party plugin files to the new package if third-party. if (!isFirstParty) { fs.copySync( - path.resolve(__dirname, templatesDir, 'third_party'), + path.resolve(import.meta.dirname, templatesDir, 'third_party'), pluginPath, ); } @@ -213,4 +231,4 @@ exports.createPlugin = function (pluginName, options) { console.log(`Search ${chalk.red(`'TODO'`)} to see remaining tasks.`); process.exit(1); -}; +} diff --git a/packages/plugins/dev-create/package.json b/packages/plugins/dev-create/package.json index 77bd00c89ec..9247f5af293 100644 --- a/packages/plugins/dev-create/package.json +++ b/packages/plugins/dev-create/package.json @@ -3,6 +3,10 @@ "version": "13.4.0", "description": "A tool for creating a Blockly plugin based on a template.", "bin": "./bin/create.js", + "type": "module", + "engines": { + "node": ">=24" + }, "author": "Blockly Team", "keywords": [ "blockly", diff --git a/packages/plugins/dev-create/templates/block/template/test/block_test.mocha.js b/packages/plugins/dev-create/templates/block/template/test/block_test.mocha.js index 9115752ce67..45243872a1a 100644 --- a/packages/plugins/dev-create/templates/block/template/test/block_test.mocha.js +++ b/packages/plugins/dev-create/templates/block/template/test/block_test.mocha.js @@ -4,18 +4,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -const chai = require('chai'); -const Blockly = require('blockly/core'); -const {testHelpers} = require('@blockly/dev-tools'); -const {dartGenerator} = require('blockly/dart'); -const {javascriptGenerator} = require('blockly/javascript'); -const {luaGenerator} = require('blockly/lua'); -const {phpGenerator} = require('blockly/php'); -const {pythonGenerator} = require('blockly/python'); - -require('../src/index'); - -const assert = chai.assert; +import {assert} from 'chai'; +import * as Blockly from 'blockly/core'; +import {testHelpers} from '@blockly/dev-tools'; +import {dartGenerator} from 'blockly/dart'; +import {javascriptGenerator} from 'blockly/javascript'; +import {luaGenerator} from 'blockly/lua'; +import {phpGenerator} from 'blockly/php'; +import {pythonGenerator} from 'blockly/python'; +import '../src/index.js'; const { CodeGenerationTestSuite, @@ -44,14 +41,16 @@ suite('BlockTemplate', function () { suite('Creation', function () { // TODO Add basic test for creation of block using newBlock call. - const block = this.workspace.newBlock('block_type'); - assertBlockStructure(block); + test('newBlock', function () { + const block = this.workspace.newBlock('block_template'); + assertBlockStructure(block); + }); }); suite('Code generation', function () { const trivialCreateBlock = (workspace) => { // TODO implement. - // return workspace.newBlock('block_type'); + // return workspace.newBlock('block_template'); }; /** @@ -129,10 +128,10 @@ suite('BlockTemplate', function () { // TODO update xml and expectedXml. { title: 'Empty XML', - xml: '', + xml: '', expectedXml: '', + 'type="block_template" id="1">', assertBlockStructure: (block) => { // TODO implement. // assertBlockStructure(block); diff --git a/packages/plugins/dev-create/templates/block/template/test/index.js b/packages/plugins/dev-create/templates/block/template/test/index.js index 35fbb31e20c..fc14efa7676 100644 --- a/packages/plugins/dev-create/templates/block/template/test/index.js +++ b/packages/plugins/dev-create/templates/block/template/test/index.js @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {createPlayground} from '@blockly/dev-tools'; -import '../src/index'; +import '../src/index.js'; // TODO: Edit list of blocks. const allBlocks = ['block_template']; diff --git a/packages/plugins/dev-create/templates/field/template/test/field_test.mocha.js b/packages/plugins/dev-create/templates/field/template/test/field_test.mocha.js index 02cff48f809..cfb41fa9bca 100644 --- a/packages/plugins/dev-create/templates/field/template/test/field_test.mocha.js +++ b/packages/plugins/dev-create/templates/field/template/test/field_test.mocha.js @@ -4,8 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -const {testHelpers} = require('@blockly/dev-tools'); -const {FieldTemplate} = require('../src/index'); +import {testHelpers} from '@blockly/dev-tools'; +import {FieldTemplate} from '../src/index.js'; const { FieldCreationTestCase, diff --git a/packages/plugins/dev-create/templates/field/template/test/index.js b/packages/plugins/dev-create/templates/field/template/test/index.js index 884fc568ea3..b77365b086c 100644 --- a/packages/plugins/dev-create/templates/field/template/test/index.js +++ b/packages/plugins/dev-create/templates/field/template/test/index.js @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {generateFieldTestBlocks, createPlayground} from '@blockly/dev-tools'; -import '../src/index'; +import '../src/index.js'; const toolbox = generateFieldTestBlocks('field_template', [ { diff --git a/packages/plugins/dev-create/templates/plugin/template/test/index.js b/packages/plugins/dev-create/templates/plugin/template/test/index.js index 7286510122e..978a21e181d 100644 --- a/packages/plugins/dev-create/templates/plugin/template/test/index.js +++ b/packages/plugins/dev-create/templates/plugin/template/test/index.js @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {toolboxCategories, createPlayground} from '@blockly/dev-tools'; -import {Plugin} from '../src/index'; +import {Plugin} from '../src/index.js'; /** * Create a workspace. diff --git a/packages/plugins/dev-create/templates/theme/template/test/index.js b/packages/plugins/dev-create/templates/theme/template/test/index.js index de643e27203..6ca5b88c46e 100644 --- a/packages/plugins/dev-create/templates/theme/template/test/index.js +++ b/packages/plugins/dev-create/templates/theme/template/test/index.js @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {toolboxCategories, createPlayground} from '@blockly/dev-tools'; -import Theme from '../src/index'; +import Theme from '../src/index.js'; /** * Create a workspace. diff --git a/packages/plugins/dev-create/templates/typescript-block/template/test/index.ts b/packages/plugins/dev-create/templates/typescript-block/template/test/index.ts index 7872103b2f1..33f9c617f8b 100644 --- a/packages/plugins/dev-create/templates/typescript-block/template/test/index.ts +++ b/packages/plugins/dev-create/templates/typescript-block/template/test/index.ts @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {createPlayground} from '@blockly/dev-tools'; -import '../src/index'; +import '../src/index.js'; // TODO: Edit list of blocks. const allBlocks = ['block_template']; @@ -42,9 +42,9 @@ document.addEventListener('DOMContentLoaded', function () { }), }, }; - createPlayground( - document.getElementById('root'), - createWorkspace, - defaultOptions, - ); + const rootElement = document.getElementById('root'); + if (!rootElement) { + throw new Error(`div with id 'root' not found`); + } + createPlayground(rootElement, createWorkspace, defaultOptions); }); diff --git a/packages/plugins/dev-create/templates/typescript-block/template/tsconfig.json b/packages/plugins/dev-create/templates/typescript-block/template/tsconfig.json index 99858c525f1..a6e04369c08 100644 --- a/packages/plugins/dev-create/templates/typescript-block/template/tsconfig.json +++ b/packages/plugins/dev-create/templates/typescript-block/template/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@blockly/dev-scripts/config/tsconfig.base.json", "compilerOptions": { "rootDir": "./src", - "outDir": "dist", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "module": "es2015", - "moduleResolution": "bundler", - "target": "es6", - "strict": true + "outDir": "dist/esm" }, // NOTE: `test/**/*` is automatically included in `blockly-scripts start`. // Only src matters for production builds. diff --git a/packages/plugins/dev-create/templates/typescript-field/template/src/index.ts b/packages/plugins/dev-create/templates/typescript-field/template/src/index.ts index 389cd6f790f..66911905586 100644 --- a/packages/plugins/dev-create/templates/typescript-field/template/src/index.ts +++ b/packages/plugins/dev-create/templates/typescript-field/template/src/index.ts @@ -24,12 +24,20 @@ export class FieldTemplate extends Blockly.Field { * @package * @nocollapse */ - static fromJson(options): Blockly.Field { + static fromJson(options: FieldTemplateFromJsonConfig): FieldTemplate { // `this` might be a subclass of FieldTemplate if that class doesn't // override the static fromJson method. - return new this(options['value']); + return new this(options.value); } } +// TODO: Edit the type of value and add any other JSON options. +/** + * fromJson configuration options for the template field. + */ +export interface FieldTemplateFromJsonConfig extends Blockly.FieldConfig { + value?: string; +} + // TODO: Edit field registration key. Blockly.fieldRegistry.register('field_template', FieldTemplate); diff --git a/packages/plugins/dev-create/templates/typescript-field/template/test/index.ts b/packages/plugins/dev-create/templates/typescript-field/template/test/index.ts index e86fe1e3d09..dfcefa1cfe9 100644 --- a/packages/plugins/dev-create/templates/typescript-field/template/test/index.ts +++ b/packages/plugins/dev-create/templates/typescript-field/template/test/index.ts @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {generateFieldTestBlocks, createPlayground} from '@blockly/dev-tools'; -import '../src/index'; +import '../src/index.js'; const toolbox = generateFieldTestBlocks('field_template', [ { @@ -39,9 +39,9 @@ document.addEventListener('DOMContentLoaded', function () { const defaultOptions = { toolbox, }; - createPlayground( - document.getElementById('root'), - createWorkspace, - defaultOptions, - ); + const rootElement = document.getElementById('root'); + if (!rootElement) { + throw new Error(`div with id 'root' not found`); + } + createPlayground(rootElement, createWorkspace, defaultOptions); }); diff --git a/packages/plugins/dev-create/templates/typescript-field/template/tsconfig.json b/packages/plugins/dev-create/templates/typescript-field/template/tsconfig.json index 99858c525f1..a6e04369c08 100644 --- a/packages/plugins/dev-create/templates/typescript-field/template/tsconfig.json +++ b/packages/plugins/dev-create/templates/typescript-field/template/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@blockly/dev-scripts/config/tsconfig.base.json", "compilerOptions": { "rootDir": "./src", - "outDir": "dist", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "module": "es2015", - "moduleResolution": "bundler", - "target": "es6", - "strict": true + "outDir": "dist/esm" }, // NOTE: `test/**/*` is automatically included in `blockly-scripts start`. // Only src matters for production builds. diff --git a/packages/plugins/dev-create/templates/typescript-plugin/template/test/index.ts b/packages/plugins/dev-create/templates/typescript-plugin/template/test/index.ts index fe68e35be37..eec4e7a9ccf 100644 --- a/packages/plugins/dev-create/templates/typescript-plugin/template/test/index.ts +++ b/packages/plugins/dev-create/templates/typescript-plugin/template/test/index.ts @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {toolboxCategories, createPlayground} from '@blockly/dev-tools'; -import {Plugin} from '../src/index'; +import {Plugin} from '../src/index.js'; /** * Create a workspace. diff --git a/packages/plugins/dev-create/templates/typescript-plugin/template/tsconfig.json b/packages/plugins/dev-create/templates/typescript-plugin/template/tsconfig.json index 99858c525f1..a6e04369c08 100644 --- a/packages/plugins/dev-create/templates/typescript-plugin/template/tsconfig.json +++ b/packages/plugins/dev-create/templates/typescript-plugin/template/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@blockly/dev-scripts/config/tsconfig.base.json", "compilerOptions": { "rootDir": "./src", - "outDir": "dist", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "module": "es2015", - "moduleResolution": "bundler", - "target": "es6", - "strict": true + "outDir": "dist/esm" }, // NOTE: `test/**/*` is automatically included in `blockly-scripts start`. // Only src matters for production builds. diff --git a/packages/plugins/dev-create/templates/typescript-theme/template/src/index.ts b/packages/plugins/dev-create/templates/typescript-theme/template/src/index.ts index a03b6b9948e..534acdfef3a 100644 --- a/packages/plugins/dev-create/templates/typescript-theme/template/src/index.ts +++ b/packages/plugins/dev-create/templates/typescript-theme/template/src/index.ts @@ -13,10 +13,11 @@ import * as Blockly from 'blockly/core'; // TODO: Edit theme name. export default Blockly.Theme.defineTheme('THEME_NAME', { + name: 'THEME_NAME', base: Blockly.Themes.Classic, blockStyles: {}, categoryStyles: {}, componentStyles: {}, fontStyle: {}, - startHats: null, + startHats: false, }); diff --git a/packages/plugins/dev-create/templates/typescript-theme/template/test/index.ts b/packages/plugins/dev-create/templates/typescript-theme/template/test/index.ts index ffe3bc49d62..25348d7ec5f 100644 --- a/packages/plugins/dev-create/templates/typescript-theme/template/test/index.ts +++ b/packages/plugins/dev-create/templates/typescript-theme/template/test/index.ts @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {toolboxCategories, createPlayground} from '@blockly/dev-tools'; -import Theme from '../src/index'; +import Theme from '../src/index.js'; /** * Create a workspace. @@ -32,9 +32,9 @@ document.addEventListener('DOMContentLoaded', function () { toolbox: toolboxCategories, theme: Theme, }; - createPlayground( - document.getElementById('root'), - createWorkspace, - defaultOptions, - ); + const rootElement = document.getElementById('root'); + if (!rootElement) { + throw new Error(`div with id 'root' not found`); + } + createPlayground(rootElement, createWorkspace, defaultOptions); }); diff --git a/packages/plugins/dev-create/templates/typescript-theme/template/tsconfig.json b/packages/plugins/dev-create/templates/typescript-theme/template/tsconfig.json index 99858c525f1..a6e04369c08 100644 --- a/packages/plugins/dev-create/templates/typescript-theme/template/tsconfig.json +++ b/packages/plugins/dev-create/templates/typescript-theme/template/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@blockly/dev-scripts/config/tsconfig.base.json", "compilerOptions": { "rootDir": "./src", - "outDir": "dist", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "module": "es2015", - "moduleResolution": "bundler", - "target": "es6", - "strict": true + "outDir": "dist/esm" }, // NOTE: `test/**/*` is automatically included in `blockly-scripts start`. // Only src matters for production builds. From b6f3d1c37b297142ed1381857fc1e29b62e83899 Mon Sep 17 00:00:00 2001 From: lizschwab Date: Wed, 11 Nov 2026 13:02:54 -0800 Subject: [PATCH 3/5] feat: Update disable-top-blocks to ESM --- eslint.config.mjs | 1 + .../plugins/disable-top-blocks/package.json | 17 ++++++++++++++--- .../plugins/disable-top-blocks/test/index.js | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index f492ada6f7e..6f4eb93878c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -420,6 +420,7 @@ export default defineConfig( 'packages/plugins/dev-create/**', 'packages/plugins/dev-scripts/**', 'packages/plugins/dev-tools/**', + 'packages/plugins/disable-top-blocks/**', 'packages/plugins/field-colour/**', 'packages/plugins/field-colour-hsv-sliders/**', 'packages/plugins/field-grid-dropdown/**', diff --git a/packages/plugins/disable-top-blocks/package.json b/packages/plugins/disable-top-blocks/package.json index 3da0f0a7078..2b922bef4bb 100644 --- a/packages/plugins/disable-top-blocks/package.json +++ b/packages/plugins/disable-top-blocks/package.json @@ -10,9 +10,13 @@ "start": "blockly-scripts start", "predeploy": "npm run build && blockly-scripts predeploy" }, - "main": "./dist/index.js", - "module": "./src/index.js", - "unpkg": "./dist/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "unpkg": "./dist/esm/index.js", + "type": "module", + "engines": { + "node": ">=24" + }, "author": "", "keywords": [ "blockly", @@ -37,6 +41,13 @@ "dist", "src" ], + "exports": { + ".": { + "node": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"}, + "import": {"types": "./dist/esm/index.d.ts", "default": "./dist/esm/index.js"}, + "require": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"} + } + }, "devDependencies": { "@blockly/dev-scripts": "^13.4.0", "@blockly/dev-tools": "^13.4.0" diff --git a/packages/plugins/disable-top-blocks/test/index.js b/packages/plugins/disable-top-blocks/test/index.js index 553569f1069..aebe8669d6c 100644 --- a/packages/plugins/disable-top-blocks/test/index.js +++ b/packages/plugins/disable-top-blocks/test/index.js @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {toolboxCategories, createPlayground} from '@blockly/dev-tools'; -import {DisableTopBlocks} from '../src/index'; +import {DisableTopBlocks} from '../src/index.js'; /** * Create a workspace. From 082f13ad822056ef98777480d4761bbe9f01cd05 Mon Sep 17 00:00:00 2001 From: lizschwab Date: Wed, 11 Nov 2026 13:18:40 -0800 Subject: [PATCH 4/5] feat: Updated field-angle to ESM --- eslint.config.mjs | 1 + packages/plugins/field-angle/package.json | 17 ++++++++++++++--- packages/plugins/field-angle/src/index.ts | 2 +- .../field-angle/test/field_angle_test.mocha.js | 6 +++--- packages/plugins/field-angle/test/index.ts | 2 +- packages/plugins/field-angle/tsconfig.json | 10 ++-------- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 6f4eb93878c..5c9cb263a81 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -421,6 +421,7 @@ export default defineConfig( 'packages/plugins/dev-scripts/**', 'packages/plugins/dev-tools/**', 'packages/plugins/disable-top-blocks/**', + 'packages/plugins/field-angle/**', 'packages/plugins/field-colour/**', 'packages/plugins/field-colour-hsv-sliders/**', 'packages/plugins/field-grid-dropdown/**', diff --git a/packages/plugins/field-angle/package.json b/packages/plugins/field-angle/package.json index 09e8ac7a4a0..dc90e29d823 100644 --- a/packages/plugins/field-angle/package.json +++ b/packages/plugins/field-angle/package.json @@ -12,9 +12,13 @@ "start": "blockly-scripts start", "test": "blockly-scripts test" }, - "main": "./dist/index.js", - "types": "./dist/index.d.ts", - "unpkg": "./dist/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "unpkg": "./dist/esm/index.js", + "type": "module", + "engines": { + "node": ">=24" + }, "author": "Blockly Team", "keywords": [ "blockly", @@ -39,6 +43,13 @@ "dist", "src" ], + "exports": { + ".": { + "node": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"}, + "import": {"types": "./dist/esm/index.d.ts", "default": "./dist/esm/index.js"}, + "require": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"} + } + }, "devDependencies": { "@blockly/dev-scripts": "^13.4.0", "@blockly/dev-tools": "^13.4.0", diff --git a/packages/plugins/field-angle/src/index.ts b/packages/plugins/field-angle/src/index.ts index ab5c4477016..70e86453270 100644 --- a/packages/plugins/field-angle/src/index.ts +++ b/packages/plugins/field-angle/src/index.ts @@ -4,4 +4,4 @@ * SPDX-License-Identifier: Apache-2.0 */ -export * from './field_angle'; +export * from './field_angle.js'; diff --git a/packages/plugins/field-angle/test/field_angle_test.mocha.js b/packages/plugins/field-angle/test/field_angle_test.mocha.js index 3b519343eee..029f7224043 100644 --- a/packages/plugins/field-angle/test/field_angle_test.mocha.js +++ b/packages/plugins/field-angle/test/field_angle_test.mocha.js @@ -4,9 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -const {testHelpers} = require('@blockly/dev-tools'); -const {FieldAngle, registerFieldAngle} = require('../src/index'); -const {assert} = require('chai'); +import {testHelpers} from '@blockly/dev-tools'; +import {FieldAngle, registerFieldAngle} from '../src/index.js'; +import {assert} from 'chai'; const { assertFieldValue, diff --git a/packages/plugins/field-angle/test/index.ts b/packages/plugins/field-angle/test/index.ts index 643a45a4d58..dd17e5161a1 100644 --- a/packages/plugins/field-angle/test/index.ts +++ b/packages/plugins/field-angle/test/index.ts @@ -10,7 +10,7 @@ import * as Blockly from 'blockly'; import {createPlayground} from '@blockly/dev-tools'; -import {registerFieldAngle} from '../src/index'; +import {registerFieldAngle} from '../src/index.js'; /** * An array of blocks that are defined only for the purposes of diff --git a/packages/plugins/field-angle/tsconfig.json b/packages/plugins/field-angle/tsconfig.json index 99858c525f1..a6e04369c08 100644 --- a/packages/plugins/field-angle/tsconfig.json +++ b/packages/plugins/field-angle/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@blockly/dev-scripts/config/tsconfig.base.json", "compilerOptions": { "rootDir": "./src", - "outDir": "dist", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "module": "es2015", - "moduleResolution": "bundler", - "target": "es6", - "strict": true + "outDir": "dist/esm" }, // NOTE: `test/**/*` is automatically included in `blockly-scripts start`. // Only src matters for production builds. From 17afe370ed2265c97a17a4f5233ef26535678cc2 Mon Sep 17 00:00:00 2001 From: lizschwab Date: Wed, 11 Nov 2026 13:29:00 -0800 Subject: [PATCH 5/5] feat: Update field-bitmap to ESM --- eslint.config.mjs | 1 + packages/plugins/field-bitmap/package.json | 17 ++++++++++++++--- packages/plugins/field-bitmap/src/index.ts | 2 +- .../field-bitmap/test/field_test.mocha.js | 6 +++--- packages/plugins/field-bitmap/test/index.js | 2 +- packages/plugins/field-bitmap/tsconfig.json | 10 ++-------- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 5c9cb263a81..bba050d0296 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -422,6 +422,7 @@ export default defineConfig( 'packages/plugins/dev-tools/**', 'packages/plugins/disable-top-blocks/**', 'packages/plugins/field-angle/**', + 'packages/plugins/field-bitmap/**', 'packages/plugins/field-colour/**', 'packages/plugins/field-colour-hsv-sliders/**', 'packages/plugins/field-grid-dropdown/**', diff --git a/packages/plugins/field-bitmap/package.json b/packages/plugins/field-bitmap/package.json index dac204b37c2..fc9f168c5e1 100644 --- a/packages/plugins/field-bitmap/package.json +++ b/packages/plugins/field-bitmap/package.json @@ -11,9 +11,13 @@ "start": "blockly-scripts start", "test": "blockly-scripts test" }, - "main": "./dist/index.js", - "module": "./src/index.js", - "unpkg": "./dist/index.js", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "unpkg": "./dist/esm/index.js", + "type": "module", + "engines": { + "node": ">=24" + }, "author": "", "keywords": [ "blockly", @@ -39,6 +43,13 @@ "dist", "src" ], + "exports": { + ".": { + "node": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"}, + "import": {"types": "./dist/esm/index.d.ts", "default": "./dist/esm/index.js"}, + "require": {"types": "./dist/cjs/index.d.ts", "default": "./dist/cjs/index.js"} + } + }, "devDependencies": { "@blockly/dev-scripts": "^13.4.0", "@blockly/dev-tools": "^13.4.0", diff --git a/packages/plugins/field-bitmap/src/index.ts b/packages/plugins/field-bitmap/src/index.ts index 1e196ea9b27..787b5b15e95 100644 --- a/packages/plugins/field-bitmap/src/index.ts +++ b/packages/plugins/field-bitmap/src/index.ts @@ -4,4 +4,4 @@ * SPDX-License-Identifier: Apache-2.0 */ -export * from './field-bitmap'; +export * from './field-bitmap.js'; diff --git a/packages/plugins/field-bitmap/test/field_test.mocha.js b/packages/plugins/field-bitmap/test/field_test.mocha.js index d809bb21b22..016bc8feccd 100644 --- a/packages/plugins/field-bitmap/test/field_test.mocha.js +++ b/packages/plugins/field-bitmap/test/field_test.mocha.js @@ -4,9 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -const {testHelpers} = require('@blockly/dev-tools'); -const {assert} = require('chai'); -const {FieldBitmap, DEFAULT_HEIGHT, DEFAULT_WIDTH} = require('../src/index'); +import {testHelpers} from '@blockly/dev-tools'; +import {assert} from 'chai'; +import {FieldBitmap, DEFAULT_HEIGHT, DEFAULT_WIDTH} from '../src/index.js'; /** * Helper method to reformat raw test cases to a format that the diff --git a/packages/plugins/field-bitmap/test/index.js b/packages/plugins/field-bitmap/test/index.js index 8eef0a91a7b..1baa97dac78 100644 --- a/packages/plugins/field-bitmap/test/index.js +++ b/packages/plugins/field-bitmap/test/index.js @@ -8,7 +8,7 @@ * @fileoverview Field test. */ -import '../src/field-bitmap'; +import '../src/field-bitmap.js'; import {createPlayground} from '@blockly/dev-tools'; import * as Blockly from 'blockly'; diff --git a/packages/plugins/field-bitmap/tsconfig.json b/packages/plugins/field-bitmap/tsconfig.json index 99858c525f1..a6e04369c08 100644 --- a/packages/plugins/field-bitmap/tsconfig.json +++ b/packages/plugins/field-bitmap/tsconfig.json @@ -1,14 +1,8 @@ { + "extends": "@blockly/dev-scripts/config/tsconfig.base.json", "compilerOptions": { "rootDir": "./src", - "outDir": "dist", - "declaration": true, - "declarationMap": true, - "sourceMap": true, - "module": "es2015", - "moduleResolution": "bundler", - "target": "es6", - "strict": true + "outDir": "dist/esm" }, // NOTE: `test/**/*` is automatically included in `blockly-scripts start`. // Only src matters for production builds.