@typestyles/vite 0.4.4 → 0.5.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 CHANGED
@@ -38,7 +38,7 @@ export default defineConfig({
38
38
  });
39
39
  ```
40
40
 
41
- Edit any file that calls `styles.component`, `styles.class`, `tokens.create`, etc. Styles update in place without a full page reload.
41
+ Edit any file that calls `recipe`, `style`, `tokens.create`, etc. Styles update in place without a full page reload.
42
42
 
43
43
  ### Runtime in dev, zero-runtime in production (recommended)
44
44
 
@@ -96,7 +96,7 @@ import { DEFAULT_EXTRACT_MODULE_CANDIDATES, discoverDefaultExtractModules } from
96
96
 
97
97
  ```ts
98
98
  typestyles({
99
- /** Default: true — fail the build on duplicate styles.component / styles.class namespaces */
99
+ /** Default: true — fail the build on duplicate recipe / style namespaces */
100
100
  warnDuplicates?: boolean;
101
101
 
102
102
  /**
@@ -142,7 +142,7 @@ Even with a convention entry present, this keeps `<style>` injection in producti
142
142
 
143
143
  **Extraction:** On `vite build`, matching entry modules are bundled and executed in Node via `@typestyles/build-runner`. The collected CSS is emitted as a static asset. In dev, the same extraction runs on demand when the browser requests `/typestyles.css` so your `<link>` href works without SPA fallback returning HTML.
144
144
 
145
- **Duplicate detection:** The plugin scans every source file for namespace strings (`styles.component('button', …)` → `.button-`). Collisions across files fail the build with a clear error.
145
+ **Duplicate detection:** The plugin scans every source file for namespace strings (`recipe('button', …)` → `.button-`). Collisions across files fail the build with a clear error.
146
146
 
147
147
  ## Verify production output
148
148
 
package/dist/index.cjs CHANGED
@@ -25,12 +25,14 @@ __export(index_exports, {
25
25
  discoverDefaultExtractModules: () => import_build_runner2.discoverDefaultExtractModules,
26
26
  extractNamespaces: () => import_build_runner.extractNamespaces,
27
27
  htmlLinksTypestylesCss: () => htmlLinksTypestylesCss,
28
+ moduleNeedsOverrideHmr: () => import_build_runner3.moduleNeedsOverrideHmr,
28
29
  resolveTypestylesCssHref: () => resolveTypestylesCssHref
29
30
  });
30
31
  module.exports = __toCommonJS(index_exports);
31
32
  var import_node_path = require("path");
32
33
  var import_build_runner = require("@typestyles/build-runner");
33
34
  var import_build_runner2 = require("@typestyles/build-runner");
35
+ var import_build_runner3 = require("@typestyles/build-runner");
34
36
  function resolveExtractModulesForVite(root, extract) {
35
37
  return (0, import_build_runner.resolveExtractModules)(root, extract);
36
38
  }
@@ -149,27 +151,41 @@ function typestylesPlugin(options = {}) {
149
151
  if (!/\.[jt]sx?$/.test(id)) return null;
150
152
  if (id.includes("node_modules")) return null;
151
153
  const { keys, prefixes } = (0, import_build_runner.extractNamespaces)(code);
152
- if (keys.length === 0 && prefixes.length === 0) return null;
153
- if (warnDuplicates) {
154
+ const overrideHmr = (0, import_build_runner.moduleNeedsOverrideHmr)(code);
155
+ if (keys.length === 0 && prefixes.length === 0 && !overrideHmr) return null;
156
+ if (warnDuplicates && prefixes.length > 0) {
154
157
  (0, import_build_runner.reportDuplicateNamespaces)(moduleNamespaces, id, prefixes, this);
155
158
  }
156
- moduleNamespaces.set(id, { keys, prefixes });
159
+ if (keys.length > 0 || prefixes.length > 0) {
160
+ moduleNamespaces.set(id, { keys, prefixes });
161
+ }
157
162
  if (!isServe) {
158
163
  return null;
159
164
  }
160
165
  const keysJSON = JSON.stringify(keys);
161
166
  const prefixesJSON = JSON.stringify(prefixes);
162
- const hmrImport = `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
167
+ const hmrImports = overrideHmr ? `import { invalidateKeys as __typestylesInvalidateKeys, createOverrideHmrSlot as __tsCreateOvHmr } from 'typestyles/hmr';
168
+ ` : `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
163
169
  `;
164
- const hmrCode = `
170
+ const overrideBootstrap = overrideHmr ? `const __tsOvHmr = __tsCreateOvHmr();
171
+ __tsOvHmr.activate();
172
+ ` : "";
173
+ const overrideTeardown = overrideHmr ? `
174
+ __tsOvHmr.deactivate();
175
+ ` : "";
176
+ const disposeBody = [
177
+ keys.length > 0 || prefixes.length > 0 ? `__typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});` : null,
178
+ overrideHmr ? `__tsOvHmr.dispose();` : null
179
+ ].filter(Boolean).join("\n ");
180
+ const hmrCode = `${overrideTeardown}
165
181
  if (import.meta.hot) {
166
182
  import.meta.hot.accept();
167
183
  import.meta.hot.dispose(() => {
168
- __typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});
184
+ ${disposeBody}
169
185
  });
170
186
  }`;
171
187
  return {
172
- code: hmrImport + code + hmrCode,
188
+ code: hmrImports + overrideBootstrap + code + hmrCode,
173
189
  map: null
174
190
  };
175
191
  },
@@ -227,5 +243,6 @@ if (import.meta.hot) {
227
243
  discoverDefaultExtractModules,
228
244
  extractNamespaces,
229
245
  htmlLinksTypestylesCss,
246
+ moduleNeedsOverrideHmr,
230
247
  resolveTypestylesCssHref
231
248
  });
package/dist/index.d.cts CHANGED
@@ -1,17 +1,18 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { TypestylesIntegrationMode, TypestylesExtractOptions } from '@typestyles/build-runner';
3
- export { DEFAULT_EXTRACT_MODULE_CANDIDATES, TypestylesExtractOptions, discoverDefaultExtractModules, extractNamespaces } from '@typestyles/build-runner';
3
+ export { DEFAULT_EXTRACT_MODULE_CANDIDATES, TypestylesExtractOptions, discoverDefaultExtractModules, extractNamespaces, moduleNeedsOverrideHmr } from '@typestyles/build-runner';
4
4
 
5
5
  /**
6
6
  * Regex patterns to extract namespace strings from typestyles API calls.
7
7
  *
8
8
  * Matches:
9
- * styles.component('button', ...) → prefix ".button-"
10
- * styles.class('card', ...) → prefix ".card-"
9
+ * recipe('button', ...) → prefix ".button-"
10
+ * style('card', ...) → prefix ".card-"
11
11
  * tokens.create('color', ...) → key "tokens:color"
12
- * tokens.createTheme('dark', ...) → key "theme:dark" (also createTheme('dark', ...))
12
+ * tokens.createTheme({ name: 'dark', … }) → key "theme:dark"
13
+ * createTheme('dark', …) → key "theme:dark" (low-level positional)
13
14
  * keyframes.create('fadeIn', ...) → key "keyframes:fadeIn"
14
- * global.style('body', ...) → prefix "body"
15
+ * global.rule('body', ...) → prefix "body"
15
16
  * global.fontFace('Inter', ...) → prefix "font-face:Inter"
16
17
  */
17
18
  interface TypestylesPluginOptions {
package/dist/index.d.ts CHANGED
@@ -1,17 +1,18 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { TypestylesIntegrationMode, TypestylesExtractOptions } from '@typestyles/build-runner';
3
- export { DEFAULT_EXTRACT_MODULE_CANDIDATES, TypestylesExtractOptions, discoverDefaultExtractModules, extractNamespaces } from '@typestyles/build-runner';
3
+ export { DEFAULT_EXTRACT_MODULE_CANDIDATES, TypestylesExtractOptions, discoverDefaultExtractModules, extractNamespaces, moduleNeedsOverrideHmr } from '@typestyles/build-runner';
4
4
 
5
5
  /**
6
6
  * Regex patterns to extract namespace strings from typestyles API calls.
7
7
  *
8
8
  * Matches:
9
- * styles.component('button', ...) → prefix ".button-"
10
- * styles.class('card', ...) → prefix ".card-"
9
+ * recipe('button', ...) → prefix ".button-"
10
+ * style('card', ...) → prefix ".card-"
11
11
  * tokens.create('color', ...) → key "tokens:color"
12
- * tokens.createTheme('dark', ...) → key "theme:dark" (also createTheme('dark', ...))
12
+ * tokens.createTheme({ name: 'dark', … }) → key "theme:dark"
13
+ * createTheme('dark', …) → key "theme:dark" (low-level positional)
13
14
  * keyframes.create('fadeIn', ...) → key "keyframes:fadeIn"
14
- * global.style('body', ...) → prefix "body"
15
+ * global.rule('body', ...) → prefix "body"
15
16
  * global.fontFace('Inter', ...) → prefix "font-face:Inter"
16
17
  */
17
18
  interface TypestylesPluginOptions {
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { resolve as resolvePath } from "path";
3
3
  import {
4
4
  extractNamespaces,
5
+ moduleNeedsOverrideHmr,
5
6
  reportDuplicateNamespaces,
6
7
  resolveExtractMode,
7
8
  resolveExtractModules,
@@ -11,6 +12,7 @@ import {
11
12
  DEFAULT_EXTRACT_MODULE_CANDIDATES,
12
13
  discoverDefaultExtractModules
13
14
  } from "@typestyles/build-runner";
15
+ import { moduleNeedsOverrideHmr as moduleNeedsOverrideHmr2 } from "@typestyles/build-runner";
14
16
  function resolveExtractModulesForVite(root, extract) {
15
17
  return resolveExtractModules(root, extract);
16
18
  }
@@ -129,27 +131,41 @@ function typestylesPlugin(options = {}) {
129
131
  if (!/\.[jt]sx?$/.test(id)) return null;
130
132
  if (id.includes("node_modules")) return null;
131
133
  const { keys, prefixes } = extractNamespaces(code);
132
- if (keys.length === 0 && prefixes.length === 0) return null;
133
- if (warnDuplicates) {
134
+ const overrideHmr = moduleNeedsOverrideHmr(code);
135
+ if (keys.length === 0 && prefixes.length === 0 && !overrideHmr) return null;
136
+ if (warnDuplicates && prefixes.length > 0) {
134
137
  reportDuplicateNamespaces(moduleNamespaces, id, prefixes, this);
135
138
  }
136
- moduleNamespaces.set(id, { keys, prefixes });
139
+ if (keys.length > 0 || prefixes.length > 0) {
140
+ moduleNamespaces.set(id, { keys, prefixes });
141
+ }
137
142
  if (!isServe) {
138
143
  return null;
139
144
  }
140
145
  const keysJSON = JSON.stringify(keys);
141
146
  const prefixesJSON = JSON.stringify(prefixes);
142
- const hmrImport = `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
147
+ const hmrImports = overrideHmr ? `import { invalidateKeys as __typestylesInvalidateKeys, createOverrideHmrSlot as __tsCreateOvHmr } from 'typestyles/hmr';
148
+ ` : `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
143
149
  `;
144
- const hmrCode = `
150
+ const overrideBootstrap = overrideHmr ? `const __tsOvHmr = __tsCreateOvHmr();
151
+ __tsOvHmr.activate();
152
+ ` : "";
153
+ const overrideTeardown = overrideHmr ? `
154
+ __tsOvHmr.deactivate();
155
+ ` : "";
156
+ const disposeBody = [
157
+ keys.length > 0 || prefixes.length > 0 ? `__typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});` : null,
158
+ overrideHmr ? `__tsOvHmr.dispose();` : null
159
+ ].filter(Boolean).join("\n ");
160
+ const hmrCode = `${overrideTeardown}
145
161
  if (import.meta.hot) {
146
162
  import.meta.hot.accept();
147
163
  import.meta.hot.dispose(() => {
148
- __typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});
164
+ ${disposeBody}
149
165
  });
150
166
  }`;
151
167
  return {
152
- code: hmrImport + code + hmrCode,
168
+ code: hmrImports + overrideBootstrap + code + hmrCode,
153
169
  map: null
154
170
  };
155
171
  },
@@ -207,5 +223,6 @@ export {
207
223
  discoverDefaultExtractModules,
208
224
  extractNamespaces,
209
225
  htmlLinksTypestylesCss,
226
+ moduleNeedsOverrideHmr2 as moduleNeedsOverrideHmr,
210
227
  resolveTypestylesCssHref
211
228
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/vite",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "description": "Vite plugin for typestyles HMR support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -43,10 +43,10 @@
43
43
  "typescript": "^5.4.0",
44
44
  "vite": "^6.0.0",
45
45
  "vitest": "^3.0.0",
46
- "typestyles": "0.9.0"
46
+ "typestyles": "1.0.0"
47
47
  },
48
48
  "dependencies": {
49
- "@typestyles/build-runner": "0.5.2"
49
+ "@typestyles/build-runner": "0.6.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --external typestyles,@typestyles/build-runner",