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

Use the global RequireJS config for ExtensionLoader. Fixes #1087 #12041

Merged
merged 3 commits into from
Aug 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/utils/ExtensionLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ define(function (require, exports, module) {
FileUtils = require("file/FileUtils"),
Async = require("utils/Async"),
ExtensionUtils = require("utils/ExtensionUtils"),
UrlParams = require("utils/UrlParams").UrlParams;
UrlParams = require("utils/UrlParams").UrlParams,
PathUtils = require("thirdparty/path-utils/path-utils");

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

var globalConfig = {
"text" : srcPath + "/thirdparty/text/text",
"i18n" : srcPath + "/thirdparty/i18n/i18n"
};

// Retrieve the global paths
var globalPaths = brackets._getGlobalRequireJSConfig().paths;

// Convert the relative paths to absolute
Object.keys(globalPaths).forEach(function (key) {
globalPaths[key] = PathUtils.makePathAbsolute(srcPath + "/" + globalPaths[key]);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope not, but if we'll find problems with this approach we'll have to dupe again this configuration:

paths: {

right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ficristo, yup. There shouldn't be any problems with the approach however.


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

Expand Down Expand Up @@ -282,7 +286,7 @@ define(function (require, exports, module) {
var extensionRequire = brackets.libRequire.config({
context: name,
baseUrl: config.baseUrl,
paths: $.extend({}, config.paths, globalConfig)
paths: $.extend({}, config.paths, globalPaths)
});

extensionRequire([entryPoint], function () {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/Global.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,12 @@ define(function (require, exports, module) {
// only be able to load modules that have already been loaded once.
global.brackets.getModule = require;

/* API for retrieving the global RequireJS config
* For internal use only
*/
global.brackets._getGlobalRequireJSConfig = function () {
return global.require.s.contexts._.config;
};

exports.global = global;
});