@poveste/plugin-tailwind 0.14.0 → 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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +27 -27
  3. package/package.json +6 -6
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.html) ·
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 api.fs.ensureDir(api.pluginTempDir);
83
- await api.fs.emptyDir(api.pluginTempDir);
83
+ await rm(api.pluginTempDir, { recursive: true, force: true });
84
+ await mkdir(api.pluginTempDir, { recursive: true });
84
85
  api.moduleLoader.clearCache();
85
- await api.fs.writeFile(api.path.resolve(api.pluginTempDir, 'style.css'), css);
86
- const theme = await loadTailwindTheme(api, tailwindCssFile);
87
- const storyFile = api.path.resolve(api.pluginTempDir, 'Tailwind.story.js');
88
- await api.fs.writeFile(storyFile, storyTemplate({ theme }));
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, onCleanup) {
122
+ async onDev(api) {
122
123
  if (tailwindCssFile) {
123
- await generate(api);
124
- const watcher = api.watcher.watch(tailwindCssFile)
125
- .on('change', () => generate(api))
126
- .on('add', () => generate(api));
127
- onCleanup(() => {
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(api, id, importBase) {
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 api.path.resolve(importBase, id);
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 api.fs.readFile(packageJsonPath, 'utf8'));
161
- return api.path.resolve(api.path.dirname(packageJsonPath), packageJson.style ?? 'index.css');
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(api, cssFile) {
183
+ async function loadTailwindTheme(cssFile) {
184
184
  const __unstable__loadDesignSystem = await resolveDesignSystemLoader();
185
- const base = api.path.dirname(cssFile);
186
- const designSystem = await __unstable__loadDesignSystem(await api.fs.readFile(cssFile, 'utf8'), {
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(api, id, importBase);
189
+ const resolved = await resolveStylesheet(id, importBase);
190
190
  return {
191
191
  path: resolved,
192
- base: api.path.dirname(resolved),
193
- content: await api.fs.readFile(resolved, 'utf8'),
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.14.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,18 +47,18 @@
47
47
  "node": "^22.22.2 || ^24.15.0 || >=26.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "poveste": "^0.14.0",
50
+ "poveste": "^0.15.0",
51
51
  "tailwindcss": "^4.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@poveste/shared": "0.14.0",
55
- "pathe": "^1.1.2"
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.14.0",
59
+ "poveste": "0.15.0",
60
60
  "tailwindcss": "^4.3.3",
61
- "typescript": "5.6.3",
61
+ "typescript": "6.0.3",
62
62
  "vite": "^8.2.0",
63
63
  "vitest": "^5.0.0"
64
64
  },