Removes circular dependencies from the CSS, which breaks webpack.
(file, seen = new Set())
| 509 | |
| 510 | /** Removes circular dependencies from the CSS, which breaks webpack. */ |
| 511 | function removeCircularDeps(file, seen = new Set()) { |
| 512 | let ast = postcss.parse(fs.readFileSync(file, 'utf8')); |
| 513 | |
| 514 | let deps = new Set(); |
| 515 | let modified = false; |
| 516 | ast.walkAtRules('import', rule => { |
| 517 | let dep = resolve(dirname(file), rule.params.match(/['"](.*?)['"]/)[1]); |
| 518 | if (seen.has(dep)) { |
| 519 | console.log(`removing circular dep ${rule.params} in ${file}`); |
| 520 | rule.remove(); |
| 521 | modified = true; |
| 522 | } else { |
| 523 | deps.add(dep); |
| 524 | } |
| 525 | }); |
| 526 | |
| 527 | if (modified) { |
| 528 | fs.writeFileSync(file, ast.toString()); |
| 529 | } |
| 530 | |
| 531 | seen.add(file); |
| 532 | for (let dep of deps) { |
| 533 | removeCircularDeps(dep, seen); |
| 534 | } |
| 535 | seen.delete(file); |
| 536 | } |
| 537 | |
| 538 | /** Generates a wrapper component when there is no Reusable wrappers section. */ |
| 539 | function generateWrapper(name) { |