Skip to content
This repository was archived by the owner on May 5, 2024. It is now read-only.

Commit a1e9b43

Browse files
committed
🎨 style: linting and formatting
1 parent 2da514a commit a1e9b43

File tree

3 files changed

+66
-61
lines changed

3 files changed

+66
-61
lines changed

README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33
This is an adder for `svelte-add`; you should [read its `README`](https://github.com/svelte-add/svelte-add#readme) before continuing here.
44

55
## ➕ Adding Tailwind CSS
6+
67
This adder's codename is `tailwindcss`, and can be used like so:
8+
79
```sh
810
npx svelte-add tailwindcss
911
```
1012

1113
### 🏞 Supported environments
14+
1215
This adder supports SvelteKit and Vite-powered Svelte apps (all the environments `svelte-add` currently supports).
1316

1417
### ⚙️ Options
15-
* `jit` (default `true`): whether or not to use [Tailwind Just-in-Time Mode](https://tailwindcss.com/docs/just-in-time-mode)
18+
19+
- `jit` (default `true`): whether or not to use [Tailwind Just-in-Time Mode](https://tailwindcss.com/docs/just-in-time-mode)
1620

1721
## 🛠 Using Tailwind CSS
22+
1823
After the adder runs,
19-
* You can use Tailwind utility classes like `bg-blue-700` in the markup (components, routes, `app.html`).
2024

21-
* You can use [Tailwind directives like `@apply` and `@screen` or use the `theme` function](https://tailwindcss.com/docs/functions-and-directives) in Svelte `style lang="postcss"` blocks or the `src/app.postcss` file.
25+
- You can use Tailwind utility classes like `bg-blue-700` in the markup (components, routes, `app.html`).
26+
27+
- You can use [Tailwind directives like `@apply` and `@screen` or use the `theme` function](https://tailwindcss.com/docs/functions-and-directives) in Svelte `style lang="postcss"` blocks or the `src/app.postcss` file.
2228

23-
* You can [configure Tailwind](https://tailwindcss.com/docs/configuration) in the `tailwind.config.cjs` file.
29+
- You can [configure Tailwind](https://tailwindcss.com/docs/configuration) in the `tailwind.config.cjs` file.
2430

25-
* Your Tailwind CSS will be purged for production builds.
31+
- Your Tailwind CSS will be purged for production builds.

__metadata.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/** @type {import("../..").AdderOptions<Options>} */
44
export const options = {
5-
"jit": {
6-
description: "Do you want to use Tailwind Just-in-Time mode? https://tailwindcss.com/docs/just-in-time-mode\nIt is recommended, but you will see warning messages in the terminal (because it is in preview) and potentially run into unexpected issues, especially with @apply or nested selectors.",
7-
default: true,
8-
}
5+
jit: {
6+
description: "Do you want to use Tailwind Just-in-Time mode? https://tailwindcss.com/docs/just-in-time-mode\nIt is recommended, but you will see warning messages in the terminal (because it is in preview) and potentially run into unexpected issues, especially with @apply or nested selectors.",
7+
default: true,
8+
},
99
};

__run.js

+51-52
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ const setTailwindMode = `// Workaround until SvelteKit uses Vite 2.3.8 (and it's
5454
const mode = process.env.NODE_ENV;
5555
const dev = mode === "development";
5656
process.env.TAILWIND_MODE = dev ? "watch" : "build";
57-
`
57+
`;
5858

5959
/**
60-
* @param {import("../../ast-io.js").RecastAST} postcssConfigAst
60+
* @param {import("../../ast-io.js").RecastAST} postcssConfigAst
6161
*/
6262
const updatePostcssConfig = (postcssConfigAst) => {
6363
const configObject = getConfigObject({
@@ -72,7 +72,7 @@ const updatePostcssConfig = (postcssConfigAst) => {
7272
if (property.type !== "Property") continue;
7373
if (property.key.type !== "Identifier") continue;
7474
if (property.key.name !== "plugins") continue;
75-
75+
7676
pluginsConfig = property;
7777
}
7878

@@ -91,8 +91,8 @@ const updatePostcssConfig = (postcssConfigAst) => {
9191
value: {
9292
type: "ArrayExpression",
9393
elements: [],
94-
}
95-
}
94+
},
95+
};
9696
configObject.properties.push(pluginsConfig);
9797
}
9898

@@ -115,20 +115,19 @@ const updatePostcssConfig = (postcssConfigAst) => {
115115
if (node.type !== "VariableDeclarator") return;
116116

117117
/** @type {import("estree").VariableDeclarator} */
118-
const declarator = (node);
119-
118+
// prettier-ignore
119+
const declarator = (node)
120+
120121
if (declarator.id.type !== "Identifier") return;
121122
const identifier = declarator.id;
122-
123+
123124
if (!declarator.init) return;
124125
if (declarator.init.type !== "CallExpression") return;
125126
const callExpression = declarator.init;
126127

127128
if (callExpression.callee.type !== "Identifier") return;
128-
/** @type {import("estree").Identifier} */
129-
const callee = (callExpression.callee);
130129

131-
if (callee.name !== "require") return;
130+
if (callExpression.callee.name !== "require") return;
132131

133132
if (callExpression.arguments[0].type !== "Literal") return;
134133
const requireArgValue = callExpression.arguments[0].value;
@@ -137,14 +136,13 @@ const updatePostcssConfig = (postcssConfigAst) => {
137136
imports[identifier.name] = requireArgValue;
138137

139138
if (requireArgValue === "tailwindcss") tailwindcssImportedAs = identifier.name;
140-
}
141-
})
142-
139+
},
140+
});
143141

144142
// Add a tailwindcss import if it's not there
145143
if (!tailwindcssImportedAs) {
146144
tailwindcssImportedAs = "tailwindcss";
147-
145+
148146
/** @type {import("estree").VariableDeclaration} */
149147
const requireTailwindcssAst = {
150148
type: "VariableDeclaration",
@@ -170,15 +168,14 @@ const updatePostcssConfig = (postcssConfigAst) => {
170168
},
171169
optional: false,
172170
},
173-
}
171+
},
174172
],
175173
kind: "const",
176174
};
177175

178176
postcssConfigAst.program.body.unshift(requireTailwindcssAst);
179177
}
180178

181-
182179
for (const [index, plugin] of pluginsList.entries()) {
183180
if (!plugin) continue;
184181

@@ -205,7 +202,6 @@ const updatePostcssConfig = (postcssConfigAst) => {
205202

206203
if (minIndex > maxIndex) throw new Error("cannot find place to slot `tailwindcss()` as a plugin in the PostCSS config");
207204

208-
209205
// We have a range of acceptable values
210206
// Let's use the latest slot because it's probably the most likely to work correctly
211207
pluginsList.splice(maxIndex, 0, {
@@ -215,16 +211,20 @@ const updatePostcssConfig = (postcssConfigAst) => {
215211
value: `Some plugins, like ${goAfter[0]}, need to run before Tailwind`,
216212
});
217213

218-
pluginsList.splice(maxIndex + 1, 0, /** @type {import("estree").CallExpression} */ {
219-
type: "CallExpression",
220-
// @ts-ignore - I am not sure why this is typed wrongly (?)
221-
arguments: [],
222-
callee: {
223-
type: "Identifier",
224-
name: tailwindcssImportedAs,
225-
},
226-
optional: false,
227-
});
214+
pluginsList.splice(
215+
maxIndex + 1,
216+
0,
217+
/** @type {import("estree").CallExpression} */ {
218+
type: "CallExpression",
219+
// @ts-ignore - I am not sure why this is typed wrongly (?)
220+
arguments: [],
221+
callee: {
222+
type: "Identifier",
223+
name: tailwindcssImportedAs,
224+
},
225+
optional: false,
226+
}
227+
);
228228

229229
pluginsList.splice(maxIndex + 2, 0, {
230230
// @ts-expect-error - Force accept the comment
@@ -233,12 +233,11 @@ const updatePostcssConfig = (postcssConfigAst) => {
233233
value: `But others, like ${goBefore[0]}, need to run after`,
234234
});
235235

236-
237236
return postcssConfigAst;
238-
}
237+
};
239238

240239
/**
241-
*
240+
*
242241
* @param {import("../../ast-io.js").PostCSSAst} postcss
243242
* @returns {import("../../ast-io.js").PostCSSAst}
244243
*/
@@ -277,7 +276,7 @@ const updateGlobalStylesheet = (postcss) => {
277276
}
278277

279278
return postcss;
280-
}
279+
};
281280

282281
/** @type {import("../../index.js").AdderRun<import("./__metadata.js").Options>} */
283282
export const run = async ({ install, options, updateCss, updateJavaScript }) => {
@@ -286,46 +285,46 @@ export const run = async ({ install, options, updateCss, updateJavaScript }) =>
286285
async script() {
287286
return {
288287
typeScriptEstree: newTypeScriptEstreeAst(options.jit ? tailwindJitConfig : tailwindAotConfig),
289-
}
290-
}
288+
};
289+
},
291290
});
292291

293292
await updateJavaScript({
294293
path: postcssConfigCjsPath,
295294
async script({ typeScriptEstree }) {
296295
return {
297296
typeScriptEstree: updatePostcssConfig(typeScriptEstree),
298-
}
299-
}
297+
};
298+
},
300299
});
301300

302301
await updateCss({
303302
path: globalStylesheetPostcssPath,
304303
async style({ postcss }) {
305304
return {
306305
postcss: updateGlobalStylesheet(postcss),
307-
}
308-
}
306+
};
307+
},
309308
});
310309

311310
await install({ package: "tailwindcss" });
312311

313312
// https://github.com/svelte-add/tailwindcss/issues/59
314313
if (options.jit) {
315314
for (const svelteConfigPath of ["/svelte.config.cjs", "/svelte.config.js"])
316-
await updateJavaScript({
317-
path: svelteConfigPath,
318-
async script({ exists, typeScriptEstree }) {
319-
if (!exists) return { exists: false };
320-
321-
const setTailwindModeAst = newTypeScriptEstreeAst(setTailwindMode);
322-
323-
typeScriptEstree.program.body.push(...setTailwindModeAst.program.body);
324-
325-
return {
326-
typeScriptEstree,
327-
}
328-
}
329-
});
315+
await updateJavaScript({
316+
path: svelteConfigPath,
317+
async script({ exists, typeScriptEstree }) {
318+
if (!exists) return { exists: false };
319+
320+
const setTailwindModeAst = newTypeScriptEstreeAst(setTailwindMode);
321+
322+
typeScriptEstree.program.body.push(...setTailwindModeAst.program.body);
323+
324+
return {
325+
typeScriptEstree,
326+
};
327+
},
328+
});
330329
}
331330
};

0 commit comments

Comments
 (0)