Skip to content

Commit 8396281

Browse files
authored
fix: cli global css has tailwind import twice and cut in the middle (#1146)
* fix: cli global css has tailwind import twice and cut in the middle * chore: changeset
1 parent 8237a0f commit 8396281

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

.changeset/public-peaches-think.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'qwik-ui': patch
3+
---
4+
5+
fix: the cli now properly injects the theme into your global css file.

packages/cli/src/generators/setup-tailwind/setup-tailwind-generator.spec.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ describe('Setup Tailwind generator', () => {
88
const options: SetupTailwindGeneratorSchema = {};
99
const tree = createTreeWithEmptyWorkspace();
1010

11-
tree.write('src/global.css', '');
11+
// add class before tailwind base import to make sure we append the extracted theme css in the right place
12+
tree.write(
13+
'src/global.css',
14+
`
15+
test {
16+
color: red;
17+
}
18+
19+
@import "tailwindcss";
20+
`,
21+
);
1222

1323
return {
1424
tree,
@@ -28,7 +38,11 @@ describe('Setup Tailwind generator', () => {
2838
const updatedGlobalCssContent = tree.read('src/global.css', 'utf-8');
2939

3040
expect(updatedGlobalCssContent).toMatchInlineSnapshot(`
31-
"@layer base, qwik-ui, popover-polyfill, theme, components, utilities;
41+
"test {
42+
color: red;
43+
}
44+
45+
@layer base, qwik-ui, popover-polyfill, theme, components, utilities;
3246
@import 'tailwindcss';
3347
@import 'tw-animate-css';
3448
@@ -219,7 +233,11 @@ describe('Setup Tailwind generator', () => {
219233
const updatedGlobalCssContent = tree.read('src/global.css', 'utf-8');
220234

221235
expect(updatedGlobalCssContent).toMatchInlineSnapshot(`
222-
"@layer base, qwik-ui, popover-polyfill, theme, components, utilities;
236+
"test {
237+
color: red;
238+
}
239+
240+
@layer base, qwik-ui, popover-polyfill, theme, components, utilities;
223241
@import 'tailwindcss';
224242
@import 'tw-animate-css';
225243

packages/cli/src/generators/setup-tailwind/setup-tailwind-generator.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,27 @@ function updateRootCss(
4545

4646
const rootCssContent = tree.read(globalCssPath, 'utf-8');
4747

48-
const tailwindUtilsDirective = '@tailwind utilities;';
49-
const utilsDirectiveIndex = rootCssContent?.indexOf(tailwindUtilsDirective);
48+
console.log('rootCssContent', rootCssContent);
5049

51-
if (!utilsDirectiveIndex) {
52-
console.error('Could not find the tailwind directives in your global css file');
53-
return;
54-
}
50+
const tailwindBaseImport = '@import "tailwindcss";';
5551

56-
const afterTailwindDirectives = utilsDirectiveIndex + tailwindUtilsDirective.length;
52+
const rootCssContentWithoutTailwindBaseImport = rootCssContent.replace(
53+
tailwindBaseImport,
54+
'',
55+
);
56+
57+
const utilsDirectiveIndex = rootCssContent?.indexOf(tailwindBaseImport);
58+
59+
const afterTailwindDirectives = utilsDirectiveIndex + tailwindBaseImport.length;
5760

58-
const firstPart = rootCssContent?.slice(0, afterTailwindDirectives);
61+
const firstPart = rootCssContentWithoutTailwindBaseImport?.slice(
62+
0,
63+
afterTailwindDirectives,
64+
);
5965

60-
const secondPart = rootCssContent?.slice(
66+
const secondPart = rootCssContentWithoutTailwindBaseImport?.slice(
6167
afterTailwindDirectives,
62-
rootCssContent.length,
68+
rootCssContentWithoutTailwindBaseImport.length,
6369
);
6470

6571
const themeStr = `${themeConfig.style} ${themeConfig.baseColor} ${themeConfig.primaryColor} ${themeConfig.borderRadius}`;

0 commit comments

Comments
 (0)