UNPKG

@stylable/core

Version:

CSS for Components

38 lines 1.77 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.noCollisionNamespace = exports.packageNamespaceFactory = void 0; const murmurhash_1 = __importDefault(require("murmurhash")); function packageNamespaceFactory(findConfig, loadConfig, { dirname, relative }, hashSalt = '', prefix = '', normalizeVersion = (semver) => semver) { return (namespace, stylesheetPath) => { const configPath = findConfig('package.json', { cwd: dirname(stylesheetPath) }); if (!configPath) { throw new Error(`Could not find package.json for ${stylesheetPath}`); } const config = loadConfig(configPath); const fromRoot = relative(dirname(configPath), stylesheetPath).replace(/\\/g, '/'); return (prefix + namespace + murmurhash_1.default.v3(hashSalt + config.name + '@' + normalizeVersion(config.version) + '/' + fromRoot)); }; } exports.packageNamespaceFactory = packageNamespaceFactory; 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