-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Improve PluginOptions types, JSDoc examples, and exports for Vite & PostCSS #20522
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
base: main
Are you sure you want to change the base?
Changes from all commits
ce0bb58
5c88d71
864b06b
fd60994
823d995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,19 +53,54 @@ export type PluginOptions = { | |
| /** | ||
| * The base directory to scan for class candidates. | ||
| * | ||
| * Defaults to the current working directory. | ||
| * @default process.cwd() | ||
| * | ||
| * @example | ||
| * ```js | ||
| * export default { | ||
| * plugins: { | ||
| * '@tailwindcss/postcss': { | ||
| * base: './src', | ||
| * }, | ||
| * }, | ||
| * } | ||
| * ``` | ||
| */ | ||
| base?: string | ||
|
|
||
| /** | ||
| * Optimize and minify the output CSS. | ||
| * | ||
| * @default true in production, false in development | ||
| * | ||
| * @example | ||
| * ```js | ||
| * export default { | ||
| * plugins: { | ||
| * '@tailwindcss/postcss': { | ||
| * optimize: { minify: true }, | ||
| * }, | ||
| * }, | ||
| * } | ||
| * ``` | ||
| */ | ||
| optimize?: boolean | { minify?: boolean } | ||
|
|
||
| /** | ||
| * Enable or disable asset URL rewriting. | ||
| * | ||
| * Defaults to `true`. | ||
| * @default true | ||
| * | ||
| * @example | ||
| * ```js | ||
| * export default { | ||
| * plugins: { | ||
| * '@tailwindcss/postcss': { | ||
| * transformAssetUrls: false, | ||
| * }, | ||
| * }, | ||
| * } | ||
| * ``` | ||
| */ | ||
| transformAssetUrls?: boolean | ||
| } | ||
|
|
@@ -375,3 +410,4 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin { | |
| } | ||
|
|
||
| export default Object.assign(tailwindcss, { postcss: true }) as PluginCreator<PluginOptions> | ||
| export { tailwindcss } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The named and default exports refer to the same function at runtime, but only the default is typed as Knowledge Base Used: PostCSS plugin
Comment on lines
412
to
+413
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: cat packages/@tailwindcss-postcss/src/index.cts
cat packages/@tailwindcss-postcss/package.json
rg -n 'require\\(|from .@tailwindcss/postcss.|tailwindcss.*export|named export|export =|export \\{ tailwindcss' packages/@tailwindcss-postcss packages --glob '*.{ts,tsx,cts,mts,js,md,json}'Repository: tailwindlabs/tailwindcss Length of output: 1943 🏁 Script executed: set -o pipefail
printf '%s\n' '--- PostCSS package files ---'
git ls-files packages/@tailwindcss-postcss
printf '%s\n' '--- PostCSS references and export expectations ---'
rg -n -F -e '@tailwindcss/postcss' -e 'tailwindcss' -e 'export =' -e 'export { tailwindcss }' packages/@tailwindcss-postcss packages --glob '*.{ts,tsx,cts,mts,js,md,json}' | head -240
printf '%s\n' '--- package entry patterns ---'
rg -n -F -e '"require"' -e '"import"' -e 'export =' packages --glob 'package.json' --glob '*.cts' --glob '*.ts' | head -240Repository: tailwindlabs/tailwindcss Length of output: 34233 🏁 Script executed: set -o pipefail
printf '%s\n' '--- PostCSS README API examples ---'
sed -n '40,115p' packages/@tailwindcss-postcss/README.md
printf '%s\n' '--- PostCSS test imports and entry usage ---'
sed -n '1,30p' packages/@tailwindcss-postcss/src/index.test.ts
printf '%s\n' '--- PostCSS source export area ---'
sed -n '100,116p' packages/@tailwindcss-postcss/src/index.ts
sed -n '406,416p' packages/@tailwindcss-postcss/src/index.ts
printf '%s\n' '--- analogous core package exports ---'
sed -n '1,35p' packages/tailwindcss/src/index.ts
sed -n '1,22p' packages/tailwindcss/src/index.cts
sed -n '15,60p' packages/tailwindcss/package.json
printf '%s\n' '--- analogous plugin exports ---'
cat packages/tailwindcss/src/plugin.ts
cat packages/tailwindcss/src/plugin.ctsRepository: tailwindlabs/tailwindcss Length of output: 8376 🏁 Script executed: set -o pipefail
printf '%s\n' '--- exact PR diff ---'
git diff --unified=8 fa81d697fe572a10ac150d18964a093a7a874081 823d99541b313d90ad59ae0f5a13a010753885fc -- packages/@tailwindcss-postcss/src/index.ts packages/@tailwindcss-postcss/src/index.cts packages/@tailwindcss-postcss/package.json
printf '%s\n' '--- core ESM exports and CJS bridge ---'
rg -n -F -e 'export default' -e 'export {' -e 'for (let key in tailwindcss)' -e 'postcssPlugin[key]' packages/tailwindcss/src/index.ts packages/tailwindcss/src/index.cts
sed -n '1,28p' packages/tailwindcss/src/index.ctsRepository: tailwindlabs/tailwindcss Length of output: 2810 Preserve the named export in the CommonJS entry.
Suggested fix-import tailwindcss from './index.ts'
+import postcssPlugin, * as tailwindcss from './index.ts'
// This is used instead of `export default` to work around a bug in
// `postcss-load-config`
+for (let key in tailwindcss) {
+ if (key === 'default') continue
+ // @ts-ignore
+ postcssPlugin[key] = tailwindcss[key]
+}
+
// @ts-ignore
-export = tailwindcss
+export = postcssPlugin |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,6 +22,22 @@ const INLINE_STYLE_ID_RE = /[?&]index=\d+\.css$/ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export type PluginOptions = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Optimize and minify the output CSS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @default true in production build, false in development | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @example | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * ```ts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * import tailwindcss from '@tailwindcss/vite' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * import { defineConfig } from 'vite' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * export default defineConfig({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * plugins: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * tailwindcss({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * optimize: { minify: true }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * ``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: rg -n 'shouldOptimize|optimize\\(|generateBundle|transform\\(|apply:|command|NODE_ENV|cssMinify' packages/@tailwindcss-vite/src/index.ts
sed -n '70,115p' packages/@tailwindcss-vite/src/index.ts
sed -n '175,225p' packages/@tailwindcss-vite/src/index.ts
sed -n '260,315p' packages/@tailwindcss-vite/src/index.tsRepository: tailwindlabs/tailwindcss Length of output: 4959 Clarify the development default The Suggested fix- * @default true in production build, false in development
+ * @default true during Vite builds, and false in the Vite development server📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| optimize?: boolean | { minify?: boolean } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -541,3 +557,5 @@ class Root { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export { tailwindcss } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a CommonJS TypeScript project,
import { tailwindcss } from '@tailwindcss/postcss'uses the package’s separaterequireentry. That entry exports only the function, not atailwindcssproperty, so the new named import fails type-checking or resolves toundefinedwhen required. The CommonJS entry needs to expose it too.Knowledge Base Used: PostCSS plugin