@stylable/core
Version:
CSS for Components
37 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.noCollisionNamespace = exports.packageNamespaceFactory = void 0;
const murmurhash_1 = require("./murmurhash");
/** @deprecated use createNamespaceStrategy */
function packageNamespaceFactory(findConfig, loadConfig, { dirname, relative, }, hashSalt = '', prefix = '', normalizeVersion = (semver) => semver) {
return (namespace, originStylesheetPath, stylesheetPath = originStylesheetPath) => {
const configPath = findConfig('package.json', { cwd: dirname(stylesheetPath) });
if (!configPath) {
throw new Error(`Could not find package.json for ${originStylesheetPath}`);
}
const config = loadConfig(configPath);
const fromRoot = relative(dirname(configPath), originStylesheetPath).replace(/\\/g, '/');
return (prefix +
namespace +
(0, murmurhash_1.murmurhash3_32_gc)(hashSalt + config.name + '@' + normalizeVersion(config.version) + '/' + fromRoot));
};
}
exports.packageNamespaceFactory = packageNamespaceFactory;
/** @deprecated use createNamespaceStrategy */
function noCollisionNamespace({ prefix = '', used: usedNamespaces = new Map(), } = {}) {
return (namespace, stylesheetPath) => {
const ns = prefix + namespace;
const used = usedNamespaces.get(ns);
if (used) {
if (used.stylesheetPath !== stylesheetPath) {
throw new Error(`namespace (${ns} of ${stylesheetPath}) is already in use`);
}
}
else {
usedNamespaces.set(ns, { prefix, namespace, stylesheetPath });
}
return ns;
};
}
exports.noCollisionNamespace = noCollisionNamespace;
//# sourceMappingURL=resolve-namespace-factories.js.map