Skip to content

Commit 6819e77

Browse files
authored
fix(tailwind-generator): support removing tailwind import with simple quotes (#1153)
* fix(tailwind-generator): support removing tailwind import with simple quotes * chore: changeset
1 parent ede0c8e commit 6819e77

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed
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 supports handling tailwind import with simple quotes

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SetupTailwindGeneratorSchema } from './schema';
44
import { setupTailwindGenerator } from './setup-tailwind-generator';
55

66
describe('Setup Tailwind generator', () => {
7-
function setupWithProperFiles() {
7+
function setupWithProperFiles(tailwindImport = '@import "tailwindcss";') {
88
const options: SetupTailwindGeneratorSchema = {};
99
const tree = createTreeWithEmptyWorkspace();
1010

@@ -16,7 +16,7 @@ describe('Setup Tailwind generator', () => {
1616
color: red;
1717
}
1818
19-
@import "tailwindcss";
19+
${tailwindImport}
2020
`,
2121
);
2222

@@ -26,18 +26,22 @@ describe('Setup Tailwind generator', () => {
2626
};
2727
}
2828

29-
test(`
29+
const importVariants = ['@import "tailwindcss";', "@import 'tailwindcss';"];
30+
31+
test.each(importVariants)(
32+
`
3033
GIVEN no options are passed
31-
THEN it should generate "simple" style with primary color "cyan-600", base color "slate" and border-radius 0`, async () => {
32-
const { tree, options } = setupWithProperFiles();
34+
THEN it should generate "simple" style with primary color "cyan-600", base color "slate" and border-radius 0 (base import: %s)`,
35+
async (importVariant) => {
36+
const { tree, options } = setupWithProperFiles(importVariant);
3337

34-
options.rootCssPath = 'src/global.css';
38+
options.rootCssPath = 'src/global.css';
3539

36-
await setupTailwindGenerator(tree, options);
40+
await setupTailwindGenerator(tree, options);
3741

38-
const updatedGlobalCssContent = tree.read('src/global.css', 'utf-8');
42+
const updatedGlobalCssContent = tree.read('src/global.css', 'utf-8');
3943

40-
expect(updatedGlobalCssContent).toMatchInlineSnapshot(`
44+
expect(updatedGlobalCssContent).toMatchInlineSnapshot(`
4145
"test {
4246
color: red;
4347
}
@@ -217,22 +221,25 @@ describe('Setup Tailwind generator', () => {
217221
}
218222
"
219223
`);
220-
});
221-
test(`
224+
},
225+
);
226+
test.each(importVariants)(
227+
`
222228
GIVEN style is "brutalist" and primary color is "red-600" and border-radius is 1
223-
THEN it should generate the correct theme`, async () => {
224-
const { tree, options } = setupWithProperFiles();
229+
THEN it should generate the correct theme (base import: %s)`,
230+
async (importVariant) => {
231+
const { tree, options } = setupWithProperFiles(importVariant);
225232

226-
options.rootCssPath = 'src/global.css';
227-
options.borderRadius = ThemeBorderRadiuses['BORDER-RADIUS-1'];
228-
options.primaryColor = ThemePrimaryColors.RED600;
229-
options.style = ThemeStyles.BRUTALIST;
233+
options.rootCssPath = 'src/global.css';
234+
options.borderRadius = ThemeBorderRadiuses['BORDER-RADIUS-1'];
235+
options.primaryColor = ThemePrimaryColors.RED600;
236+
options.style = ThemeStyles.BRUTALIST;
230237

231-
await setupTailwindGenerator(tree, options);
238+
await setupTailwindGenerator(tree, options);
232239

233-
const updatedGlobalCssContent = tree.read('src/global.css', 'utf-8');
240+
const updatedGlobalCssContent = tree.read('src/global.css', 'utf-8');
234241

235-
expect(updatedGlobalCssContent).toMatchInlineSnapshot(`
242+
expect(updatedGlobalCssContent).toMatchInlineSnapshot(`
236243
"test {
237244
color: red;
238245
}
@@ -406,5 +413,6 @@ describe('Setup Tailwind generator', () => {
406413
}
407414
"
408415
`);
409-
});
416+
},
417+
);
410418
});

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ function updateRootCss(
4747

4848
console.log('rootCssContent', rootCssContent);
4949

50-
const tailwindBaseImport = '@import "tailwindcss";';
50+
// support both single and double quote variants
51+
const tailwindBaseImportVariants = ['@import "tailwindcss";', "@import 'tailwindcss';"];
52+
const tailwindBaseImport =
53+
tailwindBaseImportVariants.find((imp) => rootCssContent?.includes(imp)) ??
54+
tailwindBaseImportVariants[0];
5155

5256
const rootCssContentWithoutTailwindBaseImport = rootCssContent.replace(
5357
tailwindBaseImport,

0 commit comments

Comments
 (0)