@typestyles/vite 0.0.0-unstable.29db9c6fb45f → 0.0.0-unstable.3219eb7a3a97

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/dist/index.cjs CHANGED
@@ -31,7 +31,6 @@ var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
31
31
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
32
32
  var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
33
33
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
34
- var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
35
34
  function extractNamespaces(code) {
36
35
  const keys = [];
37
36
  const prefixes = [];
@@ -62,6 +61,7 @@ function typestylesPlugin(options = {}) {
62
61
  const moduleNamespaces = /* @__PURE__ */ new Map();
63
62
  let resolvedConfig = null;
64
63
  let isBuildCommand = false;
64
+ let isServe = false;
65
65
  let devExtractCss = null;
66
66
  let devExtractInFlight = null;
67
67
  return {
@@ -80,6 +80,7 @@ function typestylesPlugin(options = {}) {
80
80
  },
81
81
  configResolved(config) {
82
82
  resolvedConfig = config;
83
+ isServe = config.command === "serve";
83
84
  },
84
85
  configureServer(server) {
85
86
  if (!extract || extractModules.length === 0) return;
@@ -142,7 +143,6 @@ function typestylesPlugin(options = {}) {
142
143
  transform(code, id) {
143
144
  if (!/\.[jt]sx?$/.test(id)) return null;
144
145
  if (id.includes("node_modules")) return null;
145
- if (!TYPESTYLES_IMPORT_RE.test(code)) return null;
146
146
  const { keys, prefixes } = extractNamespaces(code);
147
147
  if (keys.length === 0 && prefixes.length === 0) return null;
148
148
  if (warnDuplicates) {
@@ -159,19 +159,22 @@ function typestylesPlugin(options = {}) {
159
159
  }
160
160
  }
161
161
  moduleNamespaces.set(id, { keys, prefixes });
162
+ if (!isServe) {
163
+ return null;
164
+ }
162
165
  const keysJSON = JSON.stringify(keys);
163
166
  const prefixesJSON = JSON.stringify(prefixes);
167
+ const hmrImport = `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
168
+ `;
164
169
  const hmrCode = `
165
170
  if (import.meta.hot) {
166
- import('typestyles/hmr').then(({ invalidateKeys: __typestyles_invalidateKeys }) => {
167
- import.meta.hot.accept();
168
- import.meta.hot.dispose(() => {
169
- __typestyles_invalidateKeys(${keysJSON}, ${prefixesJSON});
170
- });
171
+ import.meta.hot.accept();
172
+ import.meta.hot.dispose(() => {
173
+ __typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});
171
174
  });
172
175
  }`;
173
176
  return {
174
- code: code + hmrCode,
177
+ code: hmrImport + code + hmrCode,
175
178
  map: null
176
179
  };
177
180
  },
package/dist/index.d.cts CHANGED
@@ -43,9 +43,10 @@ declare function extractNamespaces(code: string): {
43
43
  /**
44
44
  * Vite plugin for typestyles HMR support.
45
45
  *
46
- * When a module that uses typestyles is edited, this plugin injects HMR
47
- * accept/dispose handlers that invalidate the module's style registrations
48
- * before re-execution — so updated CSS takes effect without a full reload.
46
+ * When a module that registers typestyles (e.g. `styles.component`, `tokens.create`) is edited,
47
+ * this plugin injects HMR accept/dispose handlers that invalidate that module's registrations
48
+ * before re-execution. Files may import from a local re-export such as `./typestyles` rather
49
+ * than `from 'typestyles'` directly — we key off API call patterns in the source, not the import path.
49
50
  */
50
51
  declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
51
52
 
package/dist/index.d.ts CHANGED
@@ -43,9 +43,10 @@ declare function extractNamespaces(code: string): {
43
43
  /**
44
44
  * Vite plugin for typestyles HMR support.
45
45
  *
46
- * When a module that uses typestyles is edited, this plugin injects HMR
47
- * accept/dispose handlers that invalidate the module's style registrations
48
- * before re-execution — so updated CSS takes effect without a full reload.
46
+ * When a module that registers typestyles (e.g. `styles.component`, `tokens.create`) is edited,
47
+ * this plugin injects HMR accept/dispose handlers that invalidate that module's registrations
48
+ * before re-execution. Files may import from a local re-export such as `./typestyles` rather
49
+ * than `from 'typestyles'` directly — we key off API call patterns in the source, not the import path.
49
50
  */
50
51
  declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
51
52
 
package/dist/index.js CHANGED
@@ -6,7 +6,6 @@ var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
6
6
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
7
7
  var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
8
8
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
9
- var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
10
9
  function extractNamespaces(code) {
11
10
  const keys = [];
12
11
  const prefixes = [];
@@ -37,6 +36,7 @@ function typestylesPlugin(options = {}) {
37
36
  const moduleNamespaces = /* @__PURE__ */ new Map();
38
37
  let resolvedConfig = null;
39
38
  let isBuildCommand = false;
39
+ let isServe = false;
40
40
  let devExtractCss = null;
41
41
  let devExtractInFlight = null;
42
42
  return {
@@ -55,6 +55,7 @@ function typestylesPlugin(options = {}) {
55
55
  },
56
56
  configResolved(config) {
57
57
  resolvedConfig = config;
58
+ isServe = config.command === "serve";
58
59
  },
59
60
  configureServer(server) {
60
61
  if (!extract || extractModules.length === 0) return;
@@ -117,7 +118,6 @@ function typestylesPlugin(options = {}) {
117
118
  transform(code, id) {
118
119
  if (!/\.[jt]sx?$/.test(id)) return null;
119
120
  if (id.includes("node_modules")) return null;
120
- if (!TYPESTYLES_IMPORT_RE.test(code)) return null;
121
121
  const { keys, prefixes } = extractNamespaces(code);
122
122
  if (keys.length === 0 && prefixes.length === 0) return null;
123
123
  if (warnDuplicates) {
@@ -134,19 +134,22 @@ function typestylesPlugin(options = {}) {
134
134
  }
135
135
  }
136
136
  moduleNamespaces.set(id, { keys, prefixes });
137
+ if (!isServe) {
138
+ return null;
139
+ }
137
140
  const keysJSON = JSON.stringify(keys);
138
141
  const prefixesJSON = JSON.stringify(prefixes);
142
+ const hmrImport = `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
143
+ `;
139
144
  const hmrCode = `
140
145
  if (import.meta.hot) {
141
- import('typestyles/hmr').then(({ invalidateKeys: __typestyles_invalidateKeys }) => {
142
- import.meta.hot.accept();
143
- import.meta.hot.dispose(() => {
144
- __typestyles_invalidateKeys(${keysJSON}, ${prefixesJSON});
145
- });
146
+ import.meta.hot.accept();
147
+ import.meta.hot.dispose(() => {
148
+ __typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});
146
149
  });
147
150
  }`;
148
151
  return {
149
- code: code + hmrCode,
152
+ code: hmrImport + code + hmrCode,
150
153
  map: null
151
154
  };
152
155
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/vite",
3
- "version": "0.0.0-unstable.29db9c6fb45f",
3
+ "version": "0.0.0-unstable.3219eb7a3a97",
4
4
  "description": "Vite plugin for typestyles HMR support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -41,12 +41,12 @@
41
41
  "eslint": "^9.39.2",
42
42
  "tsup": "^8.0.0",
43
43
  "typescript": "^5.4.0",
44
- "typestyles": "0.0.0-unstable.29db9c6fb45f",
44
+ "typestyles": "0.0.0-unstable.3219eb7a3a97",
45
45
  "vite": "^6.0.0",
46
46
  "vitest": "^3.0.0"
47
47
  },
48
48
  "dependencies": {
49
- "@typestyles/build-runner": "0.0.0-unstable.29db9c6fb45f"
49
+ "@typestyles/build-runner": "0.0.0-unstable.3219eb7a3a97"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --external typestyles,@typestyles/build-runner",