-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: add support for tailwindcss v4 (#25)
* refactor: remove tailwind imports * feat: support tailwind 4 * refactor: update test * ci: inline tests * chore: change semver range * chore: remove `local-pkg` * chore: add `fast-glob` as a dependency * refactor: add lightningcss to inline imported css * refactor: use tailwindcss v3 and tailwindcss v4 simultaneously * chore: regenerate `package-lock.json` * fix: cache full context/design system * fix: load tailwind config without import assertions * chore: fix semver range * fix: dynamically import tailwind versions * fix: use `import-sync` to dynamically and synchronously import tailwindcss utilities * refactor: simplify build system (#26) * refactor: use native test runner, remove vite, use tsc * ci: use `zsh` to glob test files * ci: use `glob` package for older node versions that don't support glob patterns * ci: remove eslint9 workaround * style: fix linting issues * chore: update eslint config * chore: fix glob pattern on windows * ci: upgrade to node 22 * ci: update npm test command to use "npm test" instead of "npm t" * refactor: use `require` for synchronous dynamic imports * fix: infinite recursion * style: code cleanup * feat: resolve import statements * wip: try to replace imports with custom visitor * refactor: remove `lightningcss` * refactor: use `synckit` to run async tasks in worker thread * style: eslint fixes * fix: caching of tailwindcss 3 * fix: rewrite recursive config finder * fix: entry point option * fix: use file url on windows * refactor!: drop support for node <=18 --------- Co-authored-by: zcf0508 <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,273 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"objstr", | ||
"OBJSTR", | ||
"quasis", | ||
"shadcn" | ||
"shadcn", | ||
"synckit" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
import { writeFile } from "fs/promises"; | ||
import { $ } from "readable-tailwind:build:utils.js"; | ||
import { mkdir, writeFile } from "fs/promises"; | ||
import { transformImports } from "readable-tailwind:build:transform.js"; | ||
import { $ } from "readable-tailwind:build:utils.js"; | ||
|
||
const esmDir = "lib/esm" | ||
const cjsDir = "lib/cjs" | ||
async function build(){ | ||
|
||
await $`npx tsc --module preserve --project tsconfig.build.esm.json --outDir ${esmDir}` | ||
await $`npx tsc-alias --outDir ${esmDir}` | ||
await writeFile(`${esmDir}/package.json`, JSON.stringify({ type: "module" }), "utf-8") | ||
const esmDir = "lib/esm" | ||
const cjsDir = "lib/cjs" | ||
|
||
await $`npx tsc --module commonjs --moduleResolution node --project tsconfig.build.cjs.json --verbatimModuleSyntax false --outDir ${cjsDir}` | ||
await $`npx tsc-alias --outDir ${cjsDir}` | ||
await writeFile(`${cjsDir}/package.json`, JSON.stringify({ type: "commonjs" }), "utf-8") | ||
console.info("Building ESM...") | ||
await mkdir(esmDir, { recursive: true }); | ||
await $`npx tsc --project tsconfig.build.esm.json --outDir ${esmDir}` | ||
await $`npx tsc-alias --outDir ${esmDir}` | ||
await writeFile(`${esmDir}/package.json`, JSON.stringify({ type: "module" }), "utf-8") | ||
await transformImports([`${esmDir}/**/*.js`], "tailwindcss3", "tailwindcss") | ||
await transformImports([`${esmDir}/**/*.js`], "tailwindcss4", "tailwindcss") | ||
|
||
console.info("Building CJS...") | ||
await mkdir(cjsDir, { recursive: true }); | ||
await $`npx tsc --project tsconfig.build.cjs.json --outDir ${cjsDir}` | ||
await $`npx tsc-alias --outDir ${cjsDir}` | ||
await writeFile(`${cjsDir}/package.json`, JSON.stringify({ type: "commonjs" }), "utf-8") | ||
await transformImports([`${cjsDir}/**/*.js`], "tailwindcss3", "tailwindcss") | ||
await transformImports([`${cjsDir}/**/*.js`], "tailwindcss4", "tailwindcss") | ||
|
||
console.info("Build complete") | ||
|
||
} | ||
|
||
build().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { readFile, writeFile } from 'fs/promises'; | ||
import { glob } from 'glob' | ||
|
||
export async function transformImports(globPatterns: string[], search: string, replace: string) { | ||
const files = await glob(globPatterns); | ||
|
||
for(const file of files) { | ||
const content = await readFile(file, 'utf-8'); | ||
const transformed = content.replaceAll(search, replace); | ||
|
||
await writeFile(file, transformed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.