Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = [
'**/dist/',
'**/build/',
'examples/blockly-svelte/public/bundle.js',
'plugins/migration/test/manual-test-data/',
// specific examples that are sometimes copied into plugins
'plugins/dev-create/templates/sample-app',
'plugins/dev-create/templates/sample-app-ts',
Expand Down
20 changes: 18 additions & 2 deletions plugins/migration/bin/fix-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ const database = [
newImport: `import * as libraryBlocks from 'blockly/blocks';`,
newRequire: `const libraryBlocks = require('blockly/blocks');`,
},
{
import: 'blockly',
oldIdentifier: 'Blockly',
newIdentifier: 'Blockly', // no-op
newImport: `import * as Blockly from 'blockly';`,
newRequire: `const Blockly = require('blockly');`, // no-op
},
];

/**
Expand All @@ -125,9 +132,18 @@ function migrateContents(contents) {
*/
function fixImport(contents, migrationData) {
const identifier = getIdentifier(contents, migrationData);
// Don't need to run if there are no references.
if (!identifier) return contents;
const newContents = replaceReferences(contents, migrationData, identifier);
if (newContents !== contents) return addImport(newContents, migrationData);
// If the identifier changed, update all references to it and the import
if (migrationData.oldIdentifier !== migrationData.newIdentifier) {
const newContents = replaceReferences(contents, migrationData, identifier);
if (newContents !== contents) {
return addImport(newContents, migrationData);
}
} else {
// Just the import changed
return addImport(contents, migrationData);
}
return contents;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Manual test data for the renamings migration.
// Run using:
// node ./bin/migrate fix-imports --from <version> ./test/manual-test-data/fix-imports/import.txt
// node ./bin/migrate fix-imports --from <version> ./test/manual-test-data/fix-imports/import.js

import Blockly from 'blockly';
import * as BlocklyDart from "blockly/dart";
import * as BlocklyDart from 'blockly/dart';
import * as BlocklyLua from 'blockly/lua';
import * as BlocklyPhp from "blockly/php";
import * as BlocklyPhp from 'blockly/php';
import * as BlocklyPython from 'blockly/python';

Blockly.JavaScript.something;
Expand All @@ -31,3 +31,5 @@ Some.Other.identifer;
Blockly.libraryBlocks.something;
const something = Blockly.libraryBlocks.something;
Some.Other.identifer;

Blockly.zelos;
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ Some.Other.identifer;
Blockly.libraryBlocks.something;
const something = Blockly.libraryBlocks.something;
Some.Other.identifer;

Blockly.zelos;
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// node ./bin/migrate fix-imports --from <version> ./test/manual-test-data/fix-imports/mixed-1.txt

const Blockly = require('blockly');
import * as BlocklyDart from "blockly/dart";
import * as BlocklyDart from 'blockly/dart';
const BlocklyLua = require('blockly/lua');
import * as BlocklyPhp from "blockly/php";
import * as BlocklyPhp from 'blockly/php';
const BlocklyPython = require('blockly/python');

Blockly.JavaScript.something;
Expand All @@ -31,3 +31,5 @@ Some.Other.identifer;
Blockly.libraryBlocks.something;
const something = Blockly.libraryBlocks.something;
Some.Other.identifer;

Blockly.zelos;
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// node ./bin/migrate fix-imports --from <version> ./test/manual-test-data/fix-imports/require.txt

const Blockly = require('blockly');
const BlocklyDart = require("blockly/dart");
const BlocklyDart = require('blockly/dart');
const BlocklyLua = require('blockly/lua');
let BlocklyPhp = require("blockly/php");
let BlocklyPhp = require('blockly/php');
var BlocklyPython = require('blockly/python');

Blockly.JavaScript.something;
Expand All @@ -31,3 +31,5 @@ Some.Other.identifer;
Blockly.libraryBlocks.something;
const something = Blockly.libraryBlocks.something;
Some.Other.identifer;

Blockly.zelos;
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ class SubClass extends Blockly.moduleC {
const thingA = /** @type {Blockly.moduleD} */ (new Blockly.moduleE());
return thingA.someMethod(paramA, paramB);
}
};
}
Loading