mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Install dynamic modules with correct meteorInstall options.
This commit is contained in:
@@ -21,4 +21,5 @@ Remaining work:
|
||||
- [ ] Batch multiple __dynamicImport method calls.
|
||||
- [x] Make sure client-only reloads work (revisit _read caching).
|
||||
- [x] Make sure path manipulation is Windows-safe.
|
||||
- [x] Install dynamic modules with correct `meteorInstall` options.
|
||||
- [ ] Tests!
|
||||
|
||||
@@ -43,24 +43,50 @@ Module.prototype.dynamicImport = function (id) {
|
||||
}
|
||||
);
|
||||
|
||||
}).then(function (resultsTree) {
|
||||
function walk(tree) {
|
||||
if (typeof tree === "string") {
|
||||
return (0, eval)("(" + tree + ")");
|
||||
}
|
||||
|
||||
Object.keys(tree).forEach(function (name) {
|
||||
tree[name] = walk(tree[name]);
|
||||
});
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
meteorInstall(walk(resultsTree)); // TODO Options!
|
||||
}).then(get);
|
||||
}).then(installResults).then(get);
|
||||
});
|
||||
};
|
||||
|
||||
function installResults(resultsTree) {
|
||||
var parts = [""];
|
||||
var trees = [];
|
||||
var options = [];
|
||||
|
||||
function walk(tree) {
|
||||
if (typeof tree === "string") {
|
||||
var meta = requireMeta(parts.join("/"));
|
||||
var optionsIndex = options.indexOf(meta.options);
|
||||
if (optionsIndex < 0) {
|
||||
options[optionsIndex = options.length] = meta.options;
|
||||
trees.push(Object.create(null));
|
||||
}
|
||||
|
||||
// The results tree is partitioned into separate trees according
|
||||
// to the meta.options object that governs the tree. Usually the
|
||||
// number of trees will be approximately one, because options
|
||||
// are shared by entire bundles.
|
||||
addToTree(
|
||||
trees[optionsIndex],
|
||||
meta.module.id,
|
||||
(0, eval)("(" + tree + ")")
|
||||
);
|
||||
|
||||
} else {
|
||||
Object.keys(tree).forEach(function (name) {
|
||||
parts.push(name);
|
||||
walk(tree[name]);
|
||||
parts.pop(name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
walk(resultsTree);
|
||||
|
||||
trees.forEach(function (tree, i) {
|
||||
meteorInstall(tree, options[i]);
|
||||
});
|
||||
}
|
||||
|
||||
function addToTree(tree, id, value) {
|
||||
var parts = id.split("/");
|
||||
var lastIndex = parts.length - 1;
|
||||
|
||||
Reference in New Issue
Block a user