From 363723fc84f7b8477592e0105aeb331ec9a017af Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 14 Aug 2017 05:01:11 +0200 Subject: node_modules --- node_modules/webpack/lib/util/identifier.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'node_modules/webpack/lib/util/identifier.js') diff --git a/node_modules/webpack/lib/util/identifier.js b/node_modules/webpack/lib/util/identifier.js index b1bcbf5df..82e5b811f 100644 --- a/node_modules/webpack/lib/util/identifier.js +++ b/node_modules/webpack/lib/util/identifier.js @@ -7,10 +7,32 @@ const looksLikeAbsolutePath = (maybeAbsolutePath) => { const normalizePathSeparator = (p) => p.replace(/\\/g, "/"); -exports.makePathsRelative = (context, identifier) => { +const _makePathsRelative = (context, identifier) => { return identifier .split(/([|! ])/) .map(str => looksLikeAbsolutePath(str) ? normalizePathSeparator(path.relative(context, str)) : str) .join(""); }; + +exports.makePathsRelative = (context, identifier, cache) => { + if(!cache) return _makePathsRelative(context, identifier); + + const relativePaths = cache.relativePaths || (cache.relativePaths = new Map()); + + let cachedResult; + let contextCache = relativePaths.get(context); + if(typeof contextCache === "undefined") { + relativePaths.set(context, contextCache = new Map()); + } else { + cachedResult = contextCache.get(identifier); + } + + if(typeof cachedResult !== "undefined") { + return cachedResult; + } else { + const relativePath = _makePathsRelative(context, identifier); + contextCache.set(identifier, relativePath); + return relativePath; + } +}; -- cgit v1.2.3