src/utils/ExtensionLoader.js
function loadExtensionModule(name, config, entryPoint) {
        var extensionConfig = {
            context: name,
            baseUrl: config.baseUrl,
            paths: globalPaths,
            locale: brackets.getLocale()
        };

        // Read optional requirejs-config.json
        var promise = _mergeConfig(extensionConfig).then(function (mergedConfig) {
            // Create new RequireJS context and load extension entry point
            var extensionRequire = brackets.libRequire.config(mergedConfig),
                extensionRequireDeferred = new $.Deferred();

            contexts[name] = extensionRequire;
            extensionRequire([entryPoint], extensionRequireDeferred.resolve, extensionRequireDeferred.reject);

            return extensionRequireDeferred.promise();
        }).then(function (module) {
            // Extension loaded normally
            var initPromise;

            _extensions[name] = module;

            // Optional sync/async initExtension
            if (module && module.initExtension && (typeof module.initExtension === "function")) {
                // optional async extension init
                try {
                    initPromise = Async.withTimeout(module.initExtension(), _getInitExtensionTimeout());
                } catch (err) {
                    // Synchronous error while initializing extension
                    console.error("[Extension] Error -- error thrown during initExtension for " + name + ": " + err);
                    return new $.Deferred().reject(err).promise();
                }

                // initExtension may be synchronous and may not return a promise
                if (initPromise) {
                    // WARNING: These calls to initPromise.fail() and initPromise.then(),
                    // could also result in a runtime error if initPromise is not a valid
                    // promise. Currently, the promise is wrapped via Async.withTimeout(),
                    // so the call is safe as-is.
                    initPromise.fail(function (err) {
                        if (err === Async.ERROR_TIMEOUT) {
                            console.error("[Extension] Error -- timeout during initExtension for " + name);
                        } else {
                            console.error("[Extension] Error -- failed initExtension for " + name + (err ? ": " + err : ""));
                        }
                    });

                    return initPromise;
                }
            }
        }, function errback(err) {
            // Extension failed to load during the initial require() call
            var additionalInfo = String(err);
            if (err.requireType === "scripterror" && err.originalError) {
                // This type has a misleading error message - replace it with something clearer (URL of require() call that got a 404 result)
                additionalInfo = "Module does not exist: " + err.originalError.target.src;
            }
            console.error("[Extension] failed to load " + config.baseUrl + " - " + additionalInfo);

            if (err.requireType === "define") {
                // This type has a useful stack (exception thrown by ext code or info on bad getModule() call)
                console.log(err.stack);
            }
        });

        return promise;
    }
function loadExtensionModule(name, config, entryPoint) {
        var extensionConfig = {
            context: name,
            baseUrl: config.baseUrl,
            paths: globalPaths,
            locale: brackets.getLocale()
        };

        // Read optional requirejs-config.json
        var promise = _mergeConfig(extensionConfig).then(function (mergedConfig) {
            // Create new RequireJS context and load extension entry point
            var extensionRequire = brackets.libRequire.config(mergedConfig),
                extensionRequireDeferred = new $.Deferred();

            contexts[name] = extensionRequire;
            extensionRequire([entryPoint], extensionRequireDeferred.resolve, extensionRequireDeferred.reject);

            return extensionRequireDeferred.promise();
        }).then(function (module) {
            // Extension loaded normally
            var initPromise;

            _extensions[name] = module;

            // Optional sync/async initExtension
            if (module && module.initExtension && (typeof module.initExtension === "function")) {
                // optional async extension init
                try {
                    initPromise = Async.withTimeout(module.initExtension(), _getInitExtensionTimeout());
                } catch (err) {
                    // Synchronous error while initializing extension
                    console.error("[Extension] Error -- error thrown during initExtension for " + name + ": " + err);
                    return new $.Deferred().reject(err).promise();
                }

                // initExtension may be synchronous and may not return a promise
                if (initPromise) {
                    // WARNING: These calls to initPromise.fail() and initPromise.then(),
                    // could also result in a runtime error if initPromise is not a valid
                    // promise. Currently, the promise is wrapped via Async.withTimeout(),
                    // so the call is safe as-is.
                    initPromise.fail(function (err) {
                        if (err === Async.ERROR_TIMEOUT) {
                            console.error("[Extension] Error -- timeout during initExtension for " + name);
                        } else {
                            console.error("[Extension] Error -- failed initExtension for " + name + (err ? ": " + err : ""));
                        }
                    });

                    return initPromise;
                }
            }
        }, function errback(err) {
            // Extension failed to load during the initial require() call
            var additionalInfo = String(err);
            if (err.requireType === "scripterror" && err.originalError) {
                // This type has a misleading error message - replace it with something clearer (URL of require() call that got a 404 result)
                additionalInfo = "Module does not exist: " + err.originalError.target.src;
            }
            console.error("[Extension] failed to load " + config.baseUrl + " - " + additionalInfo);

            if (err.requireType === "define") {
                // This type has a useful stack (exception thrown by ext code or info on bad getModule() call)
                console.log(err.stack);
            }
        });

        return promise;
    }
function loadExtensionModule ( name , config , entryPoint ) { var extensionConfig = { context : name , baseUrl : config . baseUrl , paths : globalPaths , locale : brackets . getLocale ( ) } ; // Read optional requirejs-config.json var promise = _mergeConfig ( extensionConfig ) . then ( function ( mergedConfig ) { // Create new RequireJS context and load extension entry point var extensionRequire = brackets . libRequire . config ( mergedConfig ) , extensionRequireDeferred = new $ . Deferred ( ) ; contexts [ name ] = extensionRequire ; extensionRequire ( [ entryPoint ] , extensionRequireDeferred . resolve , extensionRequireDeferred . reject ) ; return extensionRequireDeferred . promise ( ) ; } ) . then ( function ( module ) { // Extension loaded normally var initPromise ; _extensions [ name ] = module ; // Optional sync/async initExtension if ( module && module . initExtension && ( typeof module . initExtension === "function" ) ) { // optional async extension init try { initPromise = Async . withTimeout ( module . initExtension ( ) , _getInitExtensionTimeout ( ) ) ; } catch ( err ) { // Synchronous error while initializing extension console . error ( "[Extension] Error -- error thrown during initExtension for " + name + ": " + err ) ; return new $ . Deferred ( ) . reject ( err ) . promise ( ) ; } // initExtension may be synchronous and may not return a promise if ( initPromise ) { // WARNING: These calls to initPromise.fail() and initPromise.then(), // could also result in a runtime error if initPromise is not a valid // promise. Currently, the promise is wrapped via Async.withTimeout(), // so the call is safe as-is. initPromise . fail ( function ( err ) { if ( err === Async . ERROR_TIMEOUT ) { console . error ( "[Extension] Error -- timeout during initExtension for " + name ) ; } else { console . error ( "[Extension] Error -- failed initExtension for " + name + ( err ? ": " + err : "" ) ) ; } } ) ; return initPromise ; } } } , function errback ( err ) { // Extension failed to load during the initial require() call var additionalInfo = String ( err ) ; if ( err . requireType === "scripterror" && err . originalError ) { // This type has a misleading error message - replace it with something clearer (URL of require() call that got a 404 result) additionalInfo = "Module does not exist: " + err . originalError . target . src ; } console . error ( "[Extension] failed to load " + config . baseUrl + " - " + additionalInfo ) ; if ( err . requireType === "define" ) { // This type has a useful stack (exception thrown by ext code or info on bad getModule() call) console . log ( err . stack ) ; } } ) ; return promise ; }
Loads the extension module that lives at baseUrl into its own Require.js context

@param {!string} name, used to identify the extension
@param {!{baseUrl: string}} config object with baseUrl property containing absolute path of extension
@param {!string} entryPoint, name of the main js file to load
@return {!$.Promise} A promise object that is resolved when the extension is loaded, or rejected
if the extension fails to load or throws an exception immediately when loaded.
(Note: if extension contains a JS syntax error, promise is resolved not rejected).
Loads the extension module that lives at baseUrl into its own Require . js context