delay extension evaluation until that extension is installed

Reduce the amount of code that needs to evaluated before we can
starting the target project if there is one. It is key to note that the
music extension includes ~2MB of base64 encoded sound samples. This
skips evaluating those samples and decoding base64 into binary typed
arrays.
This commit is contained in:
Michael "Z" Goddard 2019-01-23 17:08:57 -05:00
parent a791a1e64e
commit a5009b4c59
No known key found for this signature in database
GPG key ID: 762CD40DD5349872

View file

@ -7,32 +7,21 @@ const BlockType = require('./block-type');
// These extensions are currently built into the VM repository but should not be loaded at startup. // These extensions are currently built into the VM repository but should not be loaded at startup.
// TODO: move these out into a separate repository? // TODO: move these out into a separate repository?
// TODO: change extension spec so that library info, including extension ID, can be collected through static methods // TODO: change extension spec so that library info, including extension ID, can be collected through static methods
const Scratch3PenBlocks = require('../extensions/scratch3_pen');
const Scratch3WeDo2Blocks = require('../extensions/scratch3_wedo2');
const Scratch3MusicBlocks = require('../extensions/scratch3_music');
const Scratch3MicroBitBlocks = require('../extensions/scratch3_microbit');
const Scratch3Text2SpeechBlocks = require('../extensions/scratch3_text2speech');
const Scratch3TranslateBlocks = require('../extensions/scratch3_translate');
const Scratch3VideoSensingBlocks = require('../extensions/scratch3_video_sensing');
const Scratch3Speech2TextBlocks = require('../extensions/scratch3_speech2text');
const Scratch3Ev3Blocks = require('../extensions/scratch3_ev3');
const Scratch3MakeyMakeyBlocks = require('../extensions/scratch3_makeymakey');
// todo: only load this extension once we have a compatible way to load its
// Vernier module dependency.
// const Scratch3GdxForBlocks = require('../extensions/scratch3_gdx_for');
const builtinExtensions = { const builtinExtensions = {
pen: Scratch3PenBlocks, pen: () => require('../extensions/scratch3_pen'),
wedo2: Scratch3WeDo2Blocks, wedo2: () => require('../extensions/scratch3_wedo2'),
music: Scratch3MusicBlocks, music: () => require('../extensions/scratch3_music'),
microbit: Scratch3MicroBitBlocks, microbit: () => require('../extensions/scratch3_microbit'),
text2speech: Scratch3Text2SpeechBlocks, text2speech: () => require('../extensions/scratch3_text2speech'),
translate: Scratch3TranslateBlocks, translate: () => require('../extensions/scratch3_translate'),
videoSensing: Scratch3VideoSensingBlocks, videoSensing: () => require('../extensions/scratch3_video_sensing'),
speech2text: Scratch3Speech2TextBlocks, speech2text: () => require('../extensions/scratch3_speech2text'),
ev3: Scratch3Ev3Blocks, ev3: () => require('../extensions/scratch3_ev3'),
makeymakey: Scratch3MakeyMakeyBlocks makeymakey: () => require('../extensions/scratch3_makeymakey')
// gdxfor: Scratch3GdxForBlocks // todo: only load this extension once we have a compatible way to load its
// Vernier module dependency.
// gdxfor: () => require('../extensions/scratch3_gdx_for')
}; };
/** /**
@ -133,7 +122,7 @@ class ExtensionManager {
return Promise.reject(new Error(message)); return Promise.reject(new Error(message));
} }
const extension = builtinExtensions[extensionURL]; const extension = builtinExtensions[extensionURL]();
const extensionInstance = new extension(this.runtime); const extensionInstance = new extension(this.runtime);
return this._registerInternalExtension(extensionInstance).then(serviceName => { return this._registerInternalExtension(extensionInstance).then(serviceName => {
this._loadedExtensions.set(extensionURL, serviceName); this._loadedExtensions.set(extensionURL, serviceName);