From e22136d56d3488502cf3ade97e81377bc46bc819 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Thu, 26 Jan 2017 17:53:32 -0500 Subject: [PATCH] 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. --- index.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 15cd1918e3..209db5ae63 100644 --- a/index.js +++ b/index.js @@ -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(){};