Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tailwindcss import insertions and execution order #221

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silver-geese-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sv": patch
---

fix: `tailwindcss` import insertions and execution order
11 changes: 8 additions & 3 deletions packages/adders/tailwindcss/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,18 @@ export default defineAdder({
{
name: () => 'src/app.css',
content: ({ content }) => {
const { ast, generateCode } = parseCss(content);
const layerImports = ['base', 'components', 'utilities'].map(
(layer) => `"tailwindcss/${layer}"`
(layer) => `tailwindcss/${layer}`
);
if (layerImports.every((i) => content.includes(i))) {
return content;
}

const { ast, generateCode } = parseCss(content);
const originalFirst = ast.first;

const nodes = addImports(ast, layerImports);
const specifiers = layerImports.map((i) => `'${i}'`);
const nodes = addImports(ast, specifiers);

if (
originalFirst !== ast.first &&
Expand Down
1 change: 1 addition & 0 deletions packages/cli/commands/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ async function runAdders({
// and adders with dependencies runs later on, based on the adders they depend on.
// based on https://stackoverflow.com/a/72030336/16075084
details.sort((a, b) => {
if (!a.dependsOn && !b.dependsOn) return 0;
if (!a.dependsOn) return -1;
if (!b.dependsOn) return 1;

Expand Down