@poveste/plugin-tailwind 0.13.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +27 -27
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -34,5 +34,5 @@ Adding the plugin also adds a `Design System` group to the story tree.
|
|
|
34
34
|
> project that merely had a file named `src/app.css` got a design-system group
|
|
35
35
|
> and a story full of Tailwind's defaults it never asked for. It is opt-in now.
|
|
36
36
|
|
|
37
|
-
[Configuration](https://poveste.dev/reference/config
|
|
37
|
+
[Configuration](https://poveste.dev/reference/config) ·
|
|
38
38
|
[Documentation](https://poveste.dev)
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
3
|
import path from 'pathe';
|
|
3
4
|
import { getInjectedImport } from 'poveste';
|
|
4
5
|
import { css } from './tokens-style.js';
|
|
@@ -77,19 +78,19 @@ export function isTailwindEntry(filePath) {
|
|
|
77
78
|
export function HstTailwind(options = {}) {
|
|
78
79
|
// An explicit `cssFile` is the caller saying so, and is taken at their word.
|
|
79
80
|
const tailwindCssFile = options.cssFile ?? findUp(process.cwd(), CSS_ENTRY_CANDIDATES, isTailwindEntry);
|
|
80
|
-
async function generate(api) {
|
|
81
|
+
async function generate(api, cssFile) {
|
|
81
82
|
try {
|
|
82
|
-
await
|
|
83
|
-
await
|
|
83
|
+
await rm(api.pluginTempDir, { recursive: true, force: true });
|
|
84
|
+
await mkdir(api.pluginTempDir, { recursive: true });
|
|
84
85
|
api.moduleLoader.clearCache();
|
|
85
|
-
await
|
|
86
|
-
const theme = await loadTailwindTheme(
|
|
87
|
-
const storyFile =
|
|
88
|
-
await
|
|
86
|
+
await writeFile(path.resolve(api.pluginTempDir, 'style.css'), css);
|
|
87
|
+
const theme = await loadTailwindTheme(cssFile);
|
|
88
|
+
const storyFile = path.resolve(api.pluginTempDir, 'Tailwind.story.js');
|
|
89
|
+
await writeFile(storyFile, storyTemplate({ theme }));
|
|
89
90
|
api.addStoryFile(storyFile);
|
|
90
91
|
}
|
|
91
92
|
catch (e) {
|
|
92
|
-
api.error(e.stack ?? e.message);
|
|
93
|
+
api.error(e instanceof Error ? e.stack ?? e.message : String(e));
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
return {
|
|
@@ -118,20 +119,19 @@ export function HstTailwind(options = {}) {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
},
|
|
121
|
-
async onDev(api
|
|
122
|
+
async onDev(api) {
|
|
122
123
|
if (tailwindCssFile) {
|
|
123
|
-
await generate(api);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
watcher.close();
|
|
124
|
+
await generate(api, tailwindCssFile);
|
|
125
|
+
api.watch(tailwindCssFile, async (event) => {
|
|
126
|
+
if (event !== 'unlink') {
|
|
127
|
+
await generate(api, tailwindCssFile);
|
|
128
|
+
}
|
|
129
129
|
});
|
|
130
130
|
}
|
|
131
131
|
},
|
|
132
132
|
async onBuild(api) {
|
|
133
133
|
if (tailwindCssFile) {
|
|
134
|
-
await generate(api);
|
|
134
|
+
await generate(api, tailwindCssFile);
|
|
135
135
|
}
|
|
136
136
|
},
|
|
137
137
|
};
|
|
@@ -147,18 +147,18 @@ export function HstTailwind(options = {}) {
|
|
|
147
147
|
* to the JS entry, so its `style` field is used instead — that is how
|
|
148
148
|
* `@import 'tailwindcss'` reaches `tailwindcss/index.css`.
|
|
149
149
|
*/
|
|
150
|
-
async function resolveStylesheet(
|
|
150
|
+
async function resolveStylesheet(id, importBase) {
|
|
151
151
|
const { createRequire } = await import('node:module');
|
|
152
152
|
const require = createRequire(`${importBase}/`);
|
|
153
153
|
if (id.startsWith('.')) {
|
|
154
|
-
return
|
|
154
|
+
return path.resolve(importBase, id);
|
|
155
155
|
}
|
|
156
156
|
if (id.endsWith('.css')) {
|
|
157
157
|
return require.resolve(id);
|
|
158
158
|
}
|
|
159
159
|
const packageJsonPath = require.resolve(`${id}/package.json`);
|
|
160
|
-
const packageJson = JSON.parse(await
|
|
161
|
-
return
|
|
160
|
+
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'));
|
|
161
|
+
return path.resolve(path.dirname(packageJsonPath), packageJson.style ?? 'index.css');
|
|
162
162
|
}
|
|
163
163
|
export const TAILWIND_V4_REQUIRED = '@poveste/plugin-tailwind needs Tailwind v4: the installed tailwindcss does not export '
|
|
164
164
|
+ '`__unstable__loadDesignSystem`. A v3 project has nothing for this plugin to read — install tailwindcss@^4.';
|
|
@@ -180,17 +180,17 @@ export async function resolveDesignSystemLoader(importTailwind = () => import('t
|
|
|
180
180
|
}
|
|
181
181
|
return tailwind.__unstable__loadDesignSystem;
|
|
182
182
|
}
|
|
183
|
-
async function loadTailwindTheme(
|
|
183
|
+
async function loadTailwindTheme(cssFile) {
|
|
184
184
|
const __unstable__loadDesignSystem = await resolveDesignSystemLoader();
|
|
185
|
-
const base =
|
|
186
|
-
const designSystem = await __unstable__loadDesignSystem(await
|
|
185
|
+
const base = path.dirname(cssFile);
|
|
186
|
+
const designSystem = await __unstable__loadDesignSystem(await readFile(cssFile, 'utf8'), {
|
|
187
187
|
base,
|
|
188
188
|
loadStylesheet: async (id, importBase) => {
|
|
189
|
-
const resolved = await resolveStylesheet(
|
|
189
|
+
const resolved = await resolveStylesheet(id, importBase);
|
|
190
190
|
return {
|
|
191
191
|
path: resolved,
|
|
192
|
-
base:
|
|
193
|
-
content: await
|
|
192
|
+
base: path.dirname(resolved),
|
|
193
|
+
content: await readFile(resolved, 'utf8'),
|
|
194
194
|
};
|
|
195
195
|
},
|
|
196
196
|
});
|
|
@@ -213,7 +213,7 @@ async function loadTailwindTheme(api, cssFile) {
|
|
|
213
213
|
const out = {};
|
|
214
214
|
for (const [key, value] of Object.entries(group('--color'))) {
|
|
215
215
|
const match = key.match(/^(.*)-(\d+)$/);
|
|
216
|
-
if (match) {
|
|
216
|
+
if (match?.[1] !== undefined && match[2] !== undefined) {
|
|
217
217
|
out[match[1]] ??= {};
|
|
218
218
|
out[match[1]][match[2]] = value;
|
|
219
219
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poveste/plugin-tailwind",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.15.0",
|
|
5
5
|
"description": "Poveste plugin that renders a Tailwind design system as a story",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Sorin Gitlan",
|
|
@@ -47,20 +47,20 @@
|
|
|
47
47
|
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"poveste": "^0.
|
|
50
|
+
"poveste": "^0.15.0",
|
|
51
51
|
"tailwindcss": "^4.0.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@poveste/shared": "0.
|
|
55
|
-
"pathe": "^
|
|
54
|
+
"@poveste/shared": "0.15.0",
|
|
55
|
+
"pathe": "^2.0.3"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/node": "^22.10.1",
|
|
59
|
-
"poveste": "0.
|
|
59
|
+
"poveste": "0.15.0",
|
|
60
60
|
"tailwindcss": "^4.3.3",
|
|
61
|
-
"typescript": "
|
|
61
|
+
"typescript": "6.0.3",
|
|
62
62
|
"vite": "^8.2.0",
|
|
63
|
-
"vitest": "^
|
|
63
|
+
"vitest": "^5.0.0"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "rimraf dist && tsc -d",
|