Skip to content

Commit 53c6ef2

Browse files
committed
Add blockly import migration and rename manual test files to .js
1 parent 369c0cc commit 53c6ef2

6 files changed

Lines changed: 26 additions & 3 deletions

File tree

plugins/migration/bin/fix-imports.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ const database = [
9999
newImport: `import * as libraryBlocks from 'blockly/blocks';`,
100100
newRequire: `const libraryBlocks = require('blockly/blocks');`,
101101
},
102+
{
103+
import: 'blockly',
104+
oldIdentifier: 'Blockly',
105+
newIdentifier: 'Blockly', // no-op
106+
newImport: `import * as Blockly from 'blockly';`,
107+
newRequire: `const Blockly = require('blockly');`, // no-op
108+
},
102109
];
103110

104111
/**
@@ -125,9 +132,17 @@ function migrateContents(contents) {
125132
*/
126133
function fixImport(contents, migrationData) {
127134
const identifier = getIdentifier(contents, migrationData);
135+
// Don't need to run if there are no references.
128136
if (!identifier) return contents;
129-
const newContents = replaceReferences(contents, migrationData, identifier);
130-
if (newContents !== contents) return addImport(newContents, migrationData);
137+
// If the identifier changed, update all references to it and the import
138+
if (migrationData.oldIdentifier !== migrationData.newIdentifier) {
139+
const newContents = replaceReferences(contents, migrationData, identifier);
140+
if (newContents !== contents) {
141+
return addImport(newContents, migrationData);
142+
}
143+
} else { // Just the import changed
144+
return addImport(contents, migrationData);
145+
}
131146
return contents;
132147
}
133148

plugins/migration/test/manual-test-data/fix-imports/import.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Manual test data for the renamings migration.
22
// Run using:
3-
// node ./bin/migrate fix-imports --from <version> ./test/manual-test-data/fix-imports/import.txt
3+
// node ./bin/migrate fix-imports --from <version> ./test/manual-test-data/fix-imports/import.js
44

55
import Blockly from 'blockly';
66
import * as BlocklyDart from "blockly/dart";
@@ -31,3 +31,5 @@ Some.Other.identifer;
3131
Blockly.libraryBlocks.something;
3232
const something = Blockly.libraryBlocks.something;
3333
Some.Other.identifer;
34+
35+
Blockly.zelos;

plugins/migration/test/manual-test-data/fix-imports/mixed-1.txt renamed to plugins/migration/test/manual-test-data/fix-imports/mixed-1.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ Some.Other.identifer;
3131
Blockly.libraryBlocks.something;
3232
const something = Blockly.libraryBlocks.something;
3333
Some.Other.identifer;
34+
35+
Blockly.zelos;

plugins/migration/test/manual-test-data/fix-imports/mixed-2.txt renamed to plugins/migration/test/manual-test-data/fix-imports/mixed-2.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ Some.Other.identifer;
3131
Blockly.libraryBlocks.something;
3232
const something = Blockly.libraryBlocks.something;
3333
Some.Other.identifer;
34+
35+
Blockly.zelos;

plugins/migration/test/manual-test-data/fix-imports/require.txt renamed to plugins/migration/test/manual-test-data/fix-imports/require.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ Some.Other.identifer;
3131
Blockly.libraryBlocks.something;
3232
const something = Blockly.libraryBlocks.something;
3333
Some.Other.identifer;
34+
35+
Blockly.zelos;
File renamed without changes.

0 commit comments

Comments
 (0)