@@ -2,7 +2,7 @@ import { walk } from "estree-walker";
2
2
import { AtRule } from "postcss" ;
3
3
import { addImport , findImport , setDefaultDefaultExport , setDefault , addRootBlockComment } from "../../ast-tools.js" ;
4
4
import { extension , postcssConfigCjsPath , stylesHint } from "../postcss/stuff.js" ;
5
- import { tailwindConfigCjsPath } from "./stuff.js" ;
5
+ import { tailwindConfigCjsPath , prettierConfigPath } from "./stuff.js" ;
6
6
7
7
/**
8
8
* @param {import("../../ast-io.js").RecastAST } postcssConfigAst
@@ -101,7 +101,6 @@ const updatePostcssConfig = (postcssConfigAst) => {
101
101
pluginsList . elements . splice ( maxIndex , 0 , {
102
102
// @ts -expect-error - Force accept the comment - TODO: find a better way to handle this
103
103
type : "Line" ,
104
- // @ts -expect-error - Force accept the comment
105
104
value : `Some plugins, like ${ goAfter [ 0 ] } , need to run before Tailwind` ,
106
105
} ) ;
107
106
@@ -122,7 +121,6 @@ const updatePostcssConfig = (postcssConfigAst) => {
122
121
pluginsList . elements . splice ( maxIndex + 2 , 0 , {
123
122
// @ts -expect-error - Force accept the comment
124
123
type : "Line" ,
125
- // @ts -expect-error - Force accept the comment
126
124
value : `But others, like ${ goBefore [ 0 ] } , need to run after` ,
127
125
} ) ;
128
126
} else if ( pluginsList . type === "ObjectExpression" ) {
@@ -290,7 +288,7 @@ const updateGlobalStylesheet = (postcss) => {
290
288
} ;
291
289
292
290
/** @type {import("../..").AdderRun<import("./__info.js").Options> } */
293
- export const run = async ( { install, options, updateCss, updateJavaScript } ) => {
291
+ export const run = async ( { install, options, updateCss, updateJavaScript, updateJson , folderInfo } ) => {
294
292
await updateJavaScript ( {
295
293
path : tailwindConfigCjsPath ,
296
294
async script ( { typeScriptEstree } ) {
@@ -322,4 +320,27 @@ export const run = async ({ install, options, updateCss, updateJavaScript }) =>
322
320
if ( options . forms ) await install ( { package : "@tailwindcss/forms" } ) ;
323
321
if ( options . typography ) await install ( { package : "@tailwindcss/typography" } ) ;
324
322
if ( options . daisyui ) await install ( { package : "daisyui" } ) ;
323
+
324
+ if ( "prettier" in folderInfo . allDependencies ) {
325
+ // update plugins in prettier config
326
+ await updateJson ( {
327
+ path : prettierConfigPath ,
328
+ async json ( { obj } ) {
329
+ const plugins = obj . plugins . filter ( ( /** @type {string } */ plugin ) => plugin !== "prettier-plugin-svelte" ) ;
330
+ obj . plugins = [ "prettier-plugin-tailwindcss" , ...plugins ] ;
331
+ return { obj } ;
332
+ } ,
333
+ } ) ;
334
+
335
+ // update package.json
336
+ await updateJson ( {
337
+ path : "/package.json" ,
338
+ async json ( { obj } ) {
339
+ delete obj . devDependencies [ "prettier-plugin-svelte" ] ;
340
+ return { obj } ;
341
+ } ,
342
+ } ) ;
343
+
344
+ await install ( { package : "prettier-plugin-tailwindcss" } ) ;
345
+ }
325
346
} ;
0 commit comments