The Open Standard for Generative UI
fix tailwind plugin for tailwind v3.xx
abhishek1e1d6edf320e
diff --git a/js/packages/react-ui/package.json b/js/packages/react-ui/package.jsonindex fda1a2d91..a70e62add 100644--- a/js/packages/react-ui/package.json+++ b/js/packages/react-ui/package.json@@ -78,6 +78,7 @@"sass": "^1.83.4"},"devDependencies": {+ "postcss-remove-duplicate-values": "^1.0.0","@chromatic-com/storybook": "^3.2.4","@storybook/addon-essentials": "^8.5.3","@storybook/addon-interactions": "^8.5.3",@@ -89,7 +90,6 @@"@storybook/test": "^8.5.3","@types/lodash-es": "^4.17.12","@types/node": "^22.12.0",- "@types/postcss-js": "^4.0.4","@types/react": ">=18.0.0","@types/react-dom": "^19.0.3","@typescript-eslint/eslint-plugin": "^8.18.0",diff --git a/js/packages/react-ui/src/lib/tailwind/generateTailwindPlugin.ts b/js/packages/react-ui/src/lib/tailwind/generateTailwindPlugin.tsindex 3a9f19425..3fb1944f5 100644--- a/js/packages/react-ui/src/lib/tailwind/generateTailwindPlugin.ts+++ b/js/packages/react-ui/src/lib/tailwind/generateTailwindPlugin.ts@@ -2,6 +2,7 @@ import fs from "fs";import path from "path";import postcss from "postcss";import postcssJs from "postcss-js";+import postcssDiscardDuplicates from "postcss-remove-duplicate-values";import prettierTypescriptParser from "prettier/parser-typescript";import prettierEstreePlugin from "prettier/plugins/estree";import prettier from "prettier/standalone";@@ -161,8 +162,8 @@ const convertNumericValuesToStrings = (obj: object): object => {};const transformCssToJson = async (css: string) => {- const root = postcss.parse(css);- const json = replaceNullWithObject(postcssJs.objectify(root));+ const parsed = await postcss([postcssDiscardDuplicates({})]).process(css, {from: undefined});+ const json = replaceNullWithObject(postcssJs.objectify(parsed.root));return convertNumericValuesToStrings(json);};diff --git a/js/packages/react-ui/src/lib/tailwind/pluginTemplate.txt b/js/packages/react-ui/src/lib/tailwind/pluginTemplate.txtindex 96184e2ff..417bce4f1 100644--- a/js/packages/react-ui/src/lib/tailwind/pluginTemplate.txt+++ b/js/packages/react-ui/src/lib/tailwind/pluginTemplate.txt@@ -18,7 +18,12 @@ const crayonPlugin = plugin.withOptions<CrayonPluginOptions>(},() => {return {- safelist: [{pattern: /^crayon-/}]+ content: [+ require('path').join(+ require.resolve('@crayonai/react-ui'),+ '/**/*.{js}'+ )+ ]}});diff --git a/js/packages/react-ui/src/types/postcss-js.d.ts b/js/packages/react-ui/src/types/postcss-js.d.tsnew file mode 100644index 000000000..6be29c471--- /dev/null+++ b/js/packages/react-ui/src/types/postcss-js.d.ts@@ -0,0 +1,9 @@+// creating a custom type for postcss-js and not using @types/postcss-js+// because it's not updated for postcss v8+declare module 'postcss-js' {+ import { Root } from 'postcss';++ export function objectify(root: Root): Record<string, any>;+ export function parse(obj: object): Root;+ export function sync(obj: object): Root;+}\ No newline at end of filediff --git a/js/pnpm-lock.yaml b/js/pnpm-lock.yamlindex e15f38095..7aed00946 100644--- a/js/pnpm-lock.yaml+++ b/js/pnpm-lock.yaml@@ -58,7 +58,7 @@ importers:version: 2.6.0tailwindcss-animate:specifier: ^1.0.7- version: 1.0.7+ version: 1.0.7([email protected])tiny-invariant:specifier: ^1.3.3version: 1.3.3@@ -217,9 +217,6 @@ importers:'@types/node':specifier: ^22.12.0version: 22.13.1- '@types/postcss-js':- specifier: ^4.0.4- version: 4.0.4'@types/react':specifier: '>=18.0.0'version: 19.0.8@@ -256,6 +253,9 @@ importers:postcss-js:specifier: ^4.0.1version: 4.0.1([email protected])+ postcss-remove-duplicate-values:+ specifier: ^1.0.0+ version: 1.0.0([email protected])prettier-plugin-organize-imports:specifier: ^3.2.4version: 3.2.4([email protected])([email protected])@@ -1805,9 +1805,6 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-jK8uzQlrvXqEU91UxiK5J7pKHyzgnI1Qnl0QDHIgVGuolJhRb9EEl28Cj9b3rGR8B2lhFCtvIm5os8lFnO/1Ew==}- '@types/[email protected]':- resolution: {integrity: sha512-j5+GMZVIPCJpRTwI/mO64mCzv7X+zAEq3JP0EV2lo/BrLWHAohEubUJimIAY23rH27+wKce0fXUYjAdBoqlaYw==}-'@types/[email protected]':resolution: {integrity: sha512-0Knk+HJiMP/qOZgMyNFamlIjw9OFCsyC2ZbigmEEyXXixgre6IQpm/4V+r3qH4GC1JPvRJKInw+on2rV6YZLeA==}peerDependencies:@@ -2992,6 +2989,11 @@ packages:peerDependencies:postcss: ^8.2.14+ resolution: {integrity: sha512-VImaiZvSTs2E0DeJ1QAFhgfWx1zi8SobgpsauLQt9Ixy5B9gtRi943IMYvVgOkFYFjcXJ1FQWEaC1iv7Y75ckw==}+ peerDependencies:+ postcss: ^8.4+resolution: {integrity: sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==}engines: {node: '>=4'}@@ -4962,10 +4964,6 @@ snapshots:dependencies:undici-types: 6.20.0- '@types/[email protected]':- dependencies:- postcss: 8.5.1-'@types/[email protected](@types/[email protected])':dependencies:'@types/react': 19.0.8@@ -6161,6 +6159,10 @@ snapshots:postcss: 8.5.1postcss-selector-parser: 6.1.2+ dependencies:+ postcss: 8.5.1+dependencies:cssesc: 3.0.0@@ -6529,8 +6531,6 @@ snapshots:- [email protected]: {}-dependencies:tailwindcss: 3.4.17