Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit f2d82ac

Browse files
petetntficristo
authored andcommitted
Use the global RequireJS config for ExtensionLoader. Fixes #1087 (#12041)
* Use the global RequireJS config for ExtensionLoader. Fixes #1087
1 parent 23f3eb6 commit f2d82ac

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/utils/ExtensionLoader.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ define(function (require, exports, module) {
4141
FileUtils = require("file/FileUtils"),
4242
Async = require("utils/Async"),
4343
ExtensionUtils = require("utils/ExtensionUtils"),
44-
UrlParams = require("utils/UrlParams").UrlParams;
44+
UrlParams = require("utils/UrlParams").UrlParams,
45+
PathUtils = require("thirdparty/path-utils/path-utils");
4546

4647
// default async initExtension timeout
4748
var INIT_EXTENSION_TIMEOUT = 10000;
@@ -61,10 +62,14 @@ define(function (require, exports, module) {
6162
// load the text and i18n modules.
6263
srcPath = srcPath.replace(/\/test$/, "/src"); // convert from "test" to "src"
6364

64-
var globalConfig = {
65-
"text" : srcPath + "/thirdparty/text/text",
66-
"i18n" : srcPath + "/thirdparty/i18n/i18n"
67-
};
65+
66+
// Retrieve the global paths
67+
var globalPaths = brackets._getGlobalRequireJSConfig().paths;
68+
69+
// Convert the relative paths to absolute
70+
Object.keys(globalPaths).forEach(function (key) {
71+
globalPaths[key] = PathUtils.makePathAbsolute(srcPath + "/" + globalPaths[key]);
72+
});
6873

6974
/**
7075
* Returns the full path of the default user extensions directory. This is in the users
@@ -157,8 +162,7 @@ define(function (require, exports, module) {
157162
var extensionConfig = {
158163
context: name,
159164
baseUrl: config.baseUrl,
160-
/* FIXME (issue #1087): can we pass this from the global require context instead of hardcoding twice? */
161-
paths: globalConfig,
165+
paths: globalPaths,
162166
locale: brackets.getLocale()
163167
};
164168

@@ -282,7 +286,7 @@ define(function (require, exports, module) {
282286
var extensionRequire = brackets.libRequire.config({
283287
context: name,
284288
baseUrl: config.baseUrl,
285-
paths: $.extend({}, config.paths, globalConfig)
289+
paths: $.extend({}, config.paths, globalPaths)
286290
});
287291

288292
extensionRequire([entryPoint], function () {

src/utils/Global.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,12 @@ define(function (require, exports, module) {
121121
// only be able to load modules that have already been loaded once.
122122
global.brackets.getModule = require;
123123

124+
/* API for retrieving the global RequireJS config
125+
* For internal use only
126+
*/
127+
global.brackets._getGlobalRequireJSConfig = function () {
128+
return global.require.s.contexts._.config;
129+
};
130+
124131
exports.global = global;
125132
});

0 commit comments

Comments
 (0)