UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

44 lines (38 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; const stylable = require('stylable'); function _default(src) { const css = stylable.safeParse(src); const dependencies = {}; const addDependency = dependency => { if (!dependencies[dependency]) { dependencies[dependency] = {}; } }; const addImportSpecifier = (dependency, importSpecifier) => { if (dependencies[dependency].importSpecifiers) { dependencies[dependency].importSpecifiers.push(importSpecifier); } else { dependencies[dependency].importSpecifiers = [importSpecifier]; } }; css.walkRules(rule => { const stFrom = rule.nodes.find(node => node.prop === '-st-from'); if (!stFrom) return; const stFromValue = stFrom.value.replace(/["']/g, ''); addDependency(stFromValue); const stNamed = rule.nodes.find(node => node.prop === '-st-named'); if (!stNamed) return; const specifierValue = { isDefault: false, // @todo, name: stNamed.value, exported: true }; addImportSpecifier(stFromValue, specifierValue); }); return dependencies; }