Skip to content
Draft
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
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"resolve-from": "^5.0.0",
"rimraf": "^6.0.1",
"svelte": "^5.38.2",
"tailwindcss": "^4.1.12",
"tailwindcss-v3": "npm:tailwindcss@^3.4.17",
"tsup": "^8.5.0",
"vitest": "^3.2.4"
Expand Down
10 changes: 1 addition & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
//
// For the same reasons as the v4 stylesheet, it's important that the config
// file be resolved relative to the file it's configured in.
if (!stylesheet && !mod?.__unstable__loadDesignSystem) {
if (!stylesheet && mod && !mod.__unstable__loadDesignSystem) {
jsConfig = jsConfig ?? findClosestJsConfig(inputDir)
}

Expand Down Expand Up @@ -112,14 +112,6 @@ export async function getTailwindConfig(options: ParserOptions): Promise<any> {
stylesheet ??= `${pkgDir}/theme.css`
}

// No stylesheet was given or otherwise found in a local v4 installation
// nor was a tailwind config given or found.
//
// Fallback to v3
if (!stylesheet) {
return pathToApiMap.remember(null, () => loadV3(null, null))
}

return pathToApiMap.remember(`${pkgDir}:${stylesheet}`, () => loadV4(mod, stylesheet))
}

Expand Down
2 changes: 1 addition & 1 deletion src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const esmResolver = ResolverFactory.createResolver({
fileSystem,
useSyncFileSystemCalls: true,
extensions: ['.mjs', '.js'],
mainFields: ['module'],
mainFields: ['module', 'main'],
conditionNames: ['node', 'import'],
})

Expand Down
13 changes: 4 additions & 9 deletions src/versions/v4.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @ts-check
import * as fs from 'fs/promises'
import * as path from 'path'
import { pathToFileURL } from 'url'
import { createJiti, type Jiti } from 'jiti'
import postcss from 'postcss'
import { __unstable__loadDesignSystem } from 'tailwindcss'
// @ts-ignore
import postcssImport from 'postcss-import'
import themeCss from 'tailwindcss/theme.css'
import { resolveCssFrom, resolveJsFrom } from '../resolve'
import type { UnifiedApi } from '../types'

Expand Down Expand Up @@ -44,9 +43,7 @@ interface ApiV4 {
export async function loadV4(mod: ApiV4 | null, stylesheet: string | null): Promise<UnifiedApi> {
// This is not Tailwind v4
if (!mod || !mod.__unstable__loadDesignSystem) {
throw new Error('TODO')
// TODO
// mod = (await import('tailwindcss-v4')) as ApiV4
mod = (await import('tailwindcss')) as ApiV4
}

// Create a Jiti instance that can be used to load plugins and config files
Expand All @@ -65,9 +62,7 @@ export async function loadV4(mod: ApiV4 | null, stylesheet: string | null): Prom
} else {
importBasePath = process.cwd()
stylesheet = path.join(importBasePath, 'fake.css')

// TODO: bundled theme.css file?
css = ''
css = themeCss
}

// Load the design system and set up a compatible context object that is
Expand Down
8 changes: 7 additions & 1 deletion tests/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ describe('other', () => {

expect(result).toEqual('<div class="unknown-class group peer container p-0"></div>')
})

test('parasite utilities', async ({ expect }) => {
let result = await format('<div class="group peer unknown-class p-0 container"></div>')

expect(result).toEqual('<div class="group peer unknown-class container p-0"></div>')
})
})

describe('whitespace', () => {
Expand Down Expand Up @@ -61,6 +67,6 @@ describe('whitespace', () => {
test('duplicate classes are dropped', async ({ expect }) => {
let result = await format('<div class="underline line-through underline flex"></div>')

expect(result).toEqual('<div class="flex underline line-through"></div>')
expect(result).toEqual('<div class="flex line-through underline"></div>')
})
})