Skip to content

Commit c76a65b

Browse files
committed
fix(tools): permit multiple style imports when inlining css
1 parent 6261ef1 commit c76a65b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

.changeset/itchy-roses-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@patternfly/pfe-tools": minor
3+
---
4+
5+
✨ Added `minify` option to `@patternfly/pfe-tools/typescript/transformers/css-imports.cjs`

tools/pfe-tools/typescript/transformers/css-imports.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ const ts = require('typescript');
33
const fs = require('node:fs');
44
const { pathToFileURL } = require('node:url');
55

6+
const SEEN_SOURCES = new WeakSet();
7+
68
/**
79
* @param {import('typescript').CoreTransformationContext} ctx
810
* @param {import('typescript').SourceFile} sourceFile
911
*/
1012
function createLitCssImportStatement(ctx, sourceFile) {
13+
if (SEEN_SOURCES.has(sourceFile)) {
14+
return;
15+
}
1116
for (const statement of sourceFile.statements) {
1217
if (
1318
ts.isImportDeclaration(statement) &&
1419
statement.moduleSpecifier.getText() === 'lit') {
1520
for (const binding of statement.importClause?.namedBindings?.getChildren() ?? []) {
1621
if (binding.getText() === 'css') {
22+
SEEN_SOURCES.add(sourceFile);
1723
return;
1824
}
1925
}
2026
}
2127
}
28+
SEEN_SOURCES.add(sourceFile);
2229
return ctx.factory.createImportDeclaration(
2330
undefined,
2431
ctx.factory.createImportClause(
@@ -120,3 +127,4 @@ module.exports = function(_program, { inline = false } = {}) {
120127
};
121128
};
122129
};
130+

0 commit comments

Comments
 (0)