Skip to content

Commit bc24d05

Browse files
committed
Parse saved extension in ScratchX (.sbx) projects
They are treated the same as the list we store in .sb3 projects
1 parent c288c49 commit bc24d05

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/serialization/sb2.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,18 @@ const parseScratchObject = function (object, runtime, extensions, topLevel, zip,
800800
}
801801
}
802802

803+
// Parse extension list from ScratchX projects.
804+
if (topLevel) {
805+
const savedExtensions = object.info && object.info.savedExtensions;
806+
if (Array.isArray(savedExtensions)) {
807+
for (const extension of savedExtensions) {
808+
const id = ScratchXUtilities.generateExtensionId(extension.extensionName);
809+
const url = extension.javascriptURL;
810+
extensions.extensionURLs.set(id, url);
811+
}
812+
}
813+
}
814+
803815
return Promise.all(
804816
costumePromises.concat(soundPromises)
805817
).then(() =>

test/integration/tw_import_sbx.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,40 @@ test('importing ScratchX/.sbx project', async t => {
1616
],
1717
sounds: [],
1818
costumes: [],
19-
children: []
19+
children: [],
20+
info: {
21+
savedExtensions: [
22+
{
23+
menus: {
24+
// not important for this test
25+
},
26+
extensionName: 'Spotify',
27+
javascriptURL: 'https://ericrosenbaum.github.io/spotify-extension/extension.js',
28+
blockSpecs: [
29+
// not important for this test
30+
]
31+
},
32+
{
33+
extensionName: 'Weather extension',
34+
javascriptURL: 'http://khanning.github.io/scratch-weather-extension/weather_extension.js'
35+
}
36+
]
37+
}
2038
},
2139
rt
2240
);
2341

24-
const extensions = deserialized.extensions.extensionIDs;
25-
t.equal(extensions.size, 4);
26-
t.ok(extensions.has('sbxtexttospeech'));
27-
t.ok(extensions.has('sbxspotify'));
28-
t.ok(extensions.has('sbxweatherextension'));
29-
t.ok(extensions.has('sbxsynthextension'));
42+
const extensionIDs = deserialized.extensions.extensionIDs;
43+
t.equal(extensionIDs.size, 4);
44+
t.ok(extensionIDs.has('sbxtexttospeech'));
45+
t.ok(extensionIDs.has('sbxspotify'));
46+
t.ok(extensionIDs.has('sbxweatherextension'));
47+
t.ok(extensionIDs.has('sbxsynthextension'));
48+
49+
const extensionURLs = deserialized.extensions.extensionURLs;
50+
t.equal(extensionURLs.size, 2);
51+
t.equal(extensionURLs.get('sbxspotify'), 'https://ericrosenbaum.github.io/spotify-extension/extension.js');
52+
t.equal(extensionURLs.get('sbxweatherextension'), 'http://khanning.github.io/scratch-weather-extension/weather_extension.js');
3053

3154
const stage = deserialized.targets[0];
3255
const blocks = Object.values(stage.blocks._blocks);

0 commit comments

Comments
 (0)