Avoid calling require.resolve at runtime.

In an environment that supports dynamic asynchronous module fetching,
require.resolve will fail during application startup but might succeed
later, so it's safer to use a known identifier string alias.
This commit is contained in:
Ben Newman
2017-01-26 17:53:32 -05:00
parent 6d739c5cce
commit e22136d56d

View File

@@ -3,13 +3,11 @@ var meteorAliases = {};
Object.keys(map).forEach(function (id) {
if (typeof map[id] === "string") {
try {
exports[id] = meteorAliases[id + ".js"] =
require.resolve(map[id]);
} catch (e) {
// Resolution can fail at runtime if the stub was not included in the
// bundle because nothing depended on it.
}
var aliasParts = module.id.split("/");
aliasParts.pop();
aliasParts.push("node_modules", map[id]);
exports[id] = meteorAliases[id + ".js"] =
aliasParts.join("/");
} else {
exports[id] = map[id];
meteorAliases[id + ".js"] = function(){};