зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1309866 - Add option for loading common libraries to BrowserLoader r=Honza,jlongster
MozReview-Commit-ID: HGS3T6QcOvF
This commit is contained in:
Родитель
e778ffb693
Коммит
79f7a22b80
|
@ -18,6 +18,10 @@ const BROWSER_BASED_DIRS = [
|
|||
"resource://devtools/client/shared/redux",
|
||||
];
|
||||
|
||||
const COMMON_LIBRARY_DIRS = [
|
||||
"resource://devtools/client/shared/vendor",
|
||||
];
|
||||
|
||||
// Any directory that matches the following regular expression
|
||||
// is also considered as browser based module directory.
|
||||
// ('resource://devtools/client/.*/components/')
|
||||
|
@ -81,8 +85,12 @@ function BrowserLoader(options) {
|
|||
* @param Boolean useOnlyShared
|
||||
* If true, ignores `baseURI` and only loads the shared
|
||||
* BROWSER_BASED_DIRS via BrowserLoader.
|
||||
* @param Function commonLibRequire
|
||||
* Require function that should be used to load common libraries, like React.
|
||||
* Allows for sharing common modules between tools, instead of loading a new
|
||||
* instance into each tool. For example, pass "toolbox.browserRequire" here.
|
||||
*/
|
||||
function BrowserLoaderBuilder({ baseURI, window, useOnlyShared }) {
|
||||
function BrowserLoaderBuilder({ baseURI, window, useOnlyShared, commonLibRequire }) {
|
||||
assert(!!baseURI !== !!useOnlyShared,
|
||||
"Cannot use both `baseURI` and `useOnlyShared`.");
|
||||
|
||||
|
@ -109,15 +117,15 @@ function BrowserLoaderBuilder({ baseURI, window, useOnlyShared }) {
|
|||
}
|
||||
|
||||
const uri = require.resolve(id);
|
||||
let isBrowserDir = BROWSER_BASED_DIRS.filter(dir => {
|
||||
return uri.startsWith(dir);
|
||||
}).length > 0;
|
||||
|
||||
// If the URI doesn't match hardcoded paths try the regexp.
|
||||
if (!isBrowserDir) {
|
||||
isBrowserDir = uri.match(browserBasedDirsRegExp) != null;
|
||||
if (commonLibRequire && COMMON_LIBRARY_DIRS.some(dir => uri.startsWith(dir))) {
|
||||
return commonLibRequire(uri);
|
||||
}
|
||||
|
||||
// Check if the URI matches one of hardcoded paths or a regexp.
|
||||
let isBrowserDir = BROWSER_BASED_DIRS.some(dir => uri.startsWith(dir)) ||
|
||||
uri.match(browserBasedDirsRegExp) != null;
|
||||
|
||||
if ((useOnlyShared || !uri.startsWith(baseURI)) && !isBrowserDir) {
|
||||
return devtools.require(uri);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче