Skip to content

Commit ce6b878

Browse files
fix: tailwindcss import insertions and execution order (#221)
* dont add existing imports * temp fix exec order * Create silver-geese-punch.md --------- Co-authored-by: Manuel <30698007+manuel3108@users.noreply.github.com>
1 parent 45552df commit ce6b878

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

.changeset/silver-geese-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"sv": patch
3+
---
4+
5+
fix: `tailwindcss` import insertions and execution order

packages/adders/tailwindcss/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,18 @@ export default defineAdder({
128128
{
129129
name: () => 'src/app.css',
130130
content: ({ content }) => {
131-
const { ast, generateCode } = parseCss(content);
132131
const layerImports = ['base', 'components', 'utilities'].map(
133-
(layer) => `"tailwindcss/${layer}"`
132+
(layer) => `tailwindcss/${layer}`
134133
);
134+
if (layerImports.every((i) => content.includes(i))) {
135+
return content;
136+
}
137+
138+
const { ast, generateCode } = parseCss(content);
135139
const originalFirst = ast.first;
136140

137-
const nodes = addImports(ast, layerImports);
141+
const specifiers = layerImports.map((i) => `'${i}'`);
142+
const nodes = addImports(ast, specifiers);
138143

139144
if (
140145
originalFirst !== ast.first &&

packages/cli/commands/add/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ async function runAdders({
508508
// and adders with dependencies runs later on, based on the adders they depend on.
509509
// based on https://stackoverflow.com/a/72030336/16075084
510510
details.sort((a, b) => {
511+
if (!a.dependsOn && !b.dependsOn) return 0;
511512
if (!a.dependsOn) return -1;
512513
if (!b.dependsOn) return 1;
513514

0 commit comments

Comments
 (0)