Sha256: 37e56dd8b672ed9134106e974b5910fed14aa2fcda272349bf061b563bbf54e2

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

"use strict";
const path = require("path");

const looksLikeAbsolutePath = (maybeAbsolutePath) => {
	return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
};

const normalizePathSeparator = (p) => p.replace(/\\/g, "/");

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;
	}
};

Version data entries

7 entries across 3 versions & 2 rubygems

Version Path
optimacms-0.4.3 spec/dummy/node_modules/webpack/lib/util/identifier.js
optimacms-0.4.3 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/lib/util/identifier.js
optimacms-0.4.3 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/node_modules/webpack/lib/util/identifier.js
optimacms-0.4.2 spec/dummy/node_modules/webpack/lib/util/identifier.js
optimacms-0.4.2 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/lib/util/identifier.js
optimacms-0.4.2 spec/dummy/node_modules/@rails/webpacker/node_modules/webpack/node_modules/webpack/lib/util/identifier.js
cortex-0.1.3 spec/dummy/node_modules/webpack/lib/util/identifier.js