@typestyles/vite 0.0.0-unstable.1f1acfdf2902 → 0.0.0-unstable.28a3f8233b47

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
@@ -20,26 +20,35 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ DEFAULT_EXTRACT_MODULE_CANDIDATES: () => import_build_runner2.DEFAULT_EXTRACT_MODULE_CANDIDATES,
23
24
  default: () => typestylesPlugin,
25
+ discoverDefaultExtractModules: () => import_build_runner2.discoverDefaultExtractModules,
24
26
  extractNamespaces: () => extractNamespaces
25
27
  });
26
28
  module.exports = __toCommonJS(index_exports);
29
+ var import_node_path = require("path");
27
30
  var import_build_runner = require("@typestyles/build-runner");
28
- var STYLES_CREATE_RE = /styles\.create\(\s*['"]([^'"]+)['"]/g;
31
+ var import_build_runner2 = require("@typestyles/build-runner");
29
32
  var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
33
+ var STYLES_CLASS_RE = /styles\.class\(\s*['"]([^'"]+)['"]/g;
30
34
  var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
31
35
  var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
32
36
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
33
37
  var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
34
38
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
35
- var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
39
+ function resolveExtractModules(root, extract) {
40
+ if (extract?.modules !== void 0) {
41
+ return extract.modules;
42
+ }
43
+ return (0, import_build_runner.discoverDefaultExtractModules)(root);
44
+ }
36
45
  function extractNamespaces(code) {
37
46
  const keys = [];
38
47
  const prefixes = [];
39
- for (const match of code.matchAll(STYLES_CREATE_RE)) {
48
+ for (const match of code.matchAll(STYLES_COMPONENT_RE)) {
40
49
  prefixes.push(`.${match[1]}-`);
41
50
  }
42
- for (const match of code.matchAll(STYLES_COMPONENT_RE)) {
51
+ for (const match of code.matchAll(STYLES_CLASS_RE)) {
43
52
  prefixes.push(`.${match[1]}-`);
44
53
  }
45
54
  for (const match of code.matchAll(TOKENS_CREATE_RE)) {
@@ -60,16 +69,24 @@ function extractNamespaces(code) {
60
69
  return { keys, prefixes };
61
70
  }
62
71
  function typestylesPlugin(options = {}) {
63
- const { warnDuplicates = true, mode = "runtime", extract } = options;
72
+ const { warnDuplicates = true, extract } = options;
73
+ let resolvedExtractModules = [];
74
+ let resolvedMode = "runtime";
64
75
  const moduleNamespaces = /* @__PURE__ */ new Map();
65
76
  let resolvedConfig = null;
66
77
  let isBuildCommand = false;
78
+ let isServe = false;
79
+ let devExtractCss = null;
80
+ let devExtractInFlight = null;
67
81
  return {
68
82
  name: "typestyles",
69
83
  enforce: "pre",
70
84
  config(config, env) {
71
85
  isBuildCommand = env.command === "build";
72
- if (env.command === "build" && (mode === "build" || mode === "hybrid")) {
86
+ const root = (0, import_node_path.resolve)(config.root ?? process.cwd());
87
+ resolvedExtractModules = resolveExtractModules(root, extract);
88
+ resolvedMode = options.mode ?? (resolvedExtractModules.length > 0 ? "build" : "runtime");
89
+ if (env.command === "build" && (resolvedMode === "build" || resolvedMode === "hybrid")) {
73
90
  config.define = {
74
91
  ...config.define ?? {},
75
92
  // Inlined by the bundler so typestyles sheet skips creating <style> in production
@@ -80,11 +97,69 @@ function typestylesPlugin(options = {}) {
80
97
  },
81
98
  configResolved(config) {
82
99
  resolvedConfig = config;
100
+ isServe = config.command === "serve";
101
+ },
102
+ configureServer(server) {
103
+ if (resolvedExtractModules.length === 0) return;
104
+ if (resolvedMode === "runtime") return;
105
+ const fileName = extract?.fileName ?? "typestyles.css";
106
+ const invalidateDevExtract = () => {
107
+ devExtractCss = null;
108
+ devExtractInFlight = null;
109
+ };
110
+ server.watcher.on("change", invalidateDevExtract);
111
+ server.watcher.on("add", invalidateDevExtract);
112
+ server.watcher.on("unlink", invalidateDevExtract);
113
+ server.middlewares.use(async (req, res, next) => {
114
+ if (req.method !== "GET" && req.method !== "HEAD") {
115
+ next();
116
+ return;
117
+ }
118
+ const config = resolvedConfig;
119
+ if (!config) {
120
+ next();
121
+ return;
122
+ }
123
+ const url = req.url?.split("?")[0] ?? "";
124
+ const base = config.base.replace(/\/$/, "") || "";
125
+ const expectedPath = base === "" || base === "/" ? `/${fileName.replace(/^\//, "")}` : `${base}/${fileName.replace(/^\//, "")}`;
126
+ if (url !== expectedPath) {
127
+ next();
128
+ return;
129
+ }
130
+ const root = config.root ?? process.cwd();
131
+ try {
132
+ if (devExtractCss !== null) {
133
+ res.statusCode = 200;
134
+ res.setHeader("Content-Type", "text/css; charset=utf-8");
135
+ res.setHeader("Cache-Control", "no-cache");
136
+ res.end(devExtractCss);
137
+ return;
138
+ }
139
+ if (!devExtractInFlight) {
140
+ devExtractInFlight = (0, import_build_runner.runTypestylesBuild)({
141
+ root,
142
+ modules: resolvedExtractModules
143
+ }).then((css2) => {
144
+ devExtractCss = css2;
145
+ return css2;
146
+ }).finally(() => {
147
+ devExtractInFlight = null;
148
+ });
149
+ }
150
+ const css = await devExtractInFlight;
151
+ res.statusCode = 200;
152
+ res.setHeader("Content-Type", "text/css; charset=utf-8");
153
+ res.setHeader("Cache-Control", "no-cache");
154
+ res.end(css);
155
+ } catch (err) {
156
+ next(err);
157
+ }
158
+ });
83
159
  },
84
160
  transform(code, id) {
85
161
  if (!/\.[jt]sx?$/.test(id)) return null;
86
162
  if (id.includes("node_modules")) return null;
87
- if (!TYPESTYLES_IMPORT_RE.test(code)) return null;
88
163
  const { keys, prefixes } = extractNamespaces(code);
89
164
  if (keys.length === 0 && prefixes.length === 0) return null;
90
165
  if (warnDuplicates) {
@@ -93,41 +168,44 @@ function typestylesPlugin(options = {}) {
93
168
  for (const prefix of prefixes) {
94
169
  if (other.prefixes.includes(prefix)) {
95
170
  const ns = prefix.slice(1, -1);
96
- this.warn(
97
- `Style namespace "${ns}" is also used in ${otherId}. Duplicate namespaces cause class name collisions.`
171
+ this.error(
172
+ `[typestyles] Style namespace "${ns}" is also used in ${otherId}. Duplicate namespaces cause class name collisions. Use a distinct name or isolate with createStyles({ scopeId: fileScopeId(import.meta) }).`
98
173
  );
99
174
  }
100
175
  }
101
176
  }
102
177
  }
103
178
  moduleNamespaces.set(id, { keys, prefixes });
179
+ if (!isServe) {
180
+ return null;
181
+ }
104
182
  const keysJSON = JSON.stringify(keys);
105
183
  const prefixesJSON = JSON.stringify(prefixes);
184
+ const hmrImport = `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
185
+ `;
106
186
  const hmrCode = `
107
187
  if (import.meta.hot) {
108
- import('typestyles/hmr').then(({ invalidateKeys: __typestyles_invalidateKeys }) => {
109
- import.meta.hot.accept();
110
- import.meta.hot.dispose(() => {
111
- __typestyles_invalidateKeys(${keysJSON}, ${prefixesJSON});
112
- });
188
+ import.meta.hot.accept();
189
+ import.meta.hot.dispose(() => {
190
+ __typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});
113
191
  });
114
192
  }`;
115
193
  return {
116
- code: code + hmrCode,
194
+ code: hmrImport + code + hmrCode,
117
195
  map: null
118
196
  };
119
197
  },
120
198
  async generateBundle() {
121
199
  if (!isBuildCommand) return;
122
- if (mode === "runtime") return;
123
- if (!extract || !extract.modules.length) return;
200
+ if (resolvedMode === "runtime") return;
201
+ if (!resolvedExtractModules.length) return;
124
202
  if (!resolvedConfig) return;
125
203
  const root = resolvedConfig.root ?? process.cwd();
126
- const fileName = extract.fileName ?? "typestyles.css";
204
+ const fileName = extract?.fileName ?? "typestyles.css";
127
205
  try {
128
206
  const css = await (0, import_build_runner.runTypestylesBuild)({
129
207
  root,
130
- modules: extract.modules
208
+ modules: resolvedExtractModules
131
209
  });
132
210
  this.emitFile({
133
211
  type: "asset",
@@ -144,5 +222,7 @@ if (import.meta.hot) {
144
222
  }
145
223
  // Annotate the CommonJS export names for ESM import in node:
146
224
  0 && (module.exports = {
225
+ DEFAULT_EXTRACT_MODULE_CANDIDATES,
226
+ discoverDefaultExtractModules,
147
227
  extractNamespaces
148
228
  });
package/dist/index.d.cts CHANGED
@@ -1,28 +1,46 @@
1
1
  import { Plugin } from 'vite';
2
+ export { DEFAULT_EXTRACT_MODULE_CANDIDATES, discoverDefaultExtractModules } from '@typestyles/build-runner';
2
3
 
3
4
  interface TypestylesExtractOptions {
4
5
  /**
5
6
  * Modules that should be imported during build to register styles.
6
7
  * Paths are resolved relative to Vite's project root.
8
+ *
9
+ * When omitted, the plugin looks for the first existing file among
10
+ * {@link DEFAULT_EXTRACT_MODULE_CANDIDATES} under the project root (same resolution as when
11
+ * `extract` itself is omitted).
7
12
  */
8
- modules: string[];
13
+ modules?: string[];
9
14
  /**
10
15
  * Output CSS filename (in the build assets). Defaults to "typestyles.css".
11
16
  */
12
17
  fileName?: string;
13
18
  }
14
19
  interface TypestylesPluginOptions {
15
- /** Warn about duplicate namespaces across modules. Defaults to true. */
20
+ /**
21
+ * When true (default), fail the build if the same logical `styles.component` / `styles.class`
22
+ * namespace appears in more than one module. Set to `false` to skip this check.
23
+ */
16
24
  warnDuplicates?: boolean;
17
25
  /**
18
26
  * Mode for typestyles integration:
19
- * - "runtime" (default): HMR only, no build-time extraction.
20
- * - "build": emit a static CSS asset during build using typestyles/build.
21
- * - "hybrid": both runtime injection and build-time CSS asset.
27
+ * - `"runtime"`: HMR only, no build-time extraction.
28
+ * - `"build"`: emit a static CSS asset on `vite build` and disable client injection there.
29
+ * - `"hybrid"`: extract on build and keep runtime-compatible behavior.
30
+ *
31
+ * When omitted and at least one extraction module is resolved (explicit `extract.modules`, or a
32
+ * discovered convention entry file), defaults to `"build"`: `vite dev` keeps runtime
33
+ * injection + HMR (runtime is only disabled during `vite build`), serves the same extracted CSS
34
+ * at `extract.fileName` so `<link href="/typestyles.css">` is valid (avoids SPA fallback
35
+ * returning HTML for that URL), and production emits the CSS file. If no modules are resolved,
36
+ * defaults to `"runtime"`.
22
37
  */
23
38
  mode?: 'runtime' | 'build' | 'hybrid';
24
39
  /**
25
40
  * Options for build-time CSS extraction when mode is "build" or "hybrid".
41
+ *
42
+ * Omitted entirely: discover a convention entry under the project root (see
43
+ * {@link discoverDefaultExtractModules}); if none exist, stays in runtime-only mode.
26
44
  */
27
45
  extract?: TypestylesExtractOptions;
28
46
  }
@@ -37,9 +55,10 @@ declare function extractNamespaces(code: string): {
37
55
  /**
38
56
  * Vite plugin for typestyles HMR support.
39
57
  *
40
- * When a module that uses typestyles is edited, this plugin injects HMR
41
- * accept/dispose handlers that invalidate the module's style registrations
42
- * before re-execution — so updated CSS takes effect without a full reload.
58
+ * When a module that registers typestyles (e.g. `styles.component`, `styles.class`, `tokens.create`) is edited,
59
+ * this plugin injects HMR accept/dispose handlers that invalidate that module's registrations
60
+ * before re-execution. Files may import from a local re-export such as `./typestyles` rather
61
+ * than `from 'typestyles'` directly — we key off API call patterns in the source, not the import path.
43
62
  */
44
63
  declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
45
64
 
package/dist/index.d.ts CHANGED
@@ -1,28 +1,46 @@
1
1
  import { Plugin } from 'vite';
2
+ export { DEFAULT_EXTRACT_MODULE_CANDIDATES, discoverDefaultExtractModules } from '@typestyles/build-runner';
2
3
 
3
4
  interface TypestylesExtractOptions {
4
5
  /**
5
6
  * Modules that should be imported during build to register styles.
6
7
  * Paths are resolved relative to Vite's project root.
8
+ *
9
+ * When omitted, the plugin looks for the first existing file among
10
+ * {@link DEFAULT_EXTRACT_MODULE_CANDIDATES} under the project root (same resolution as when
11
+ * `extract` itself is omitted).
7
12
  */
8
- modules: string[];
13
+ modules?: string[];
9
14
  /**
10
15
  * Output CSS filename (in the build assets). Defaults to "typestyles.css".
11
16
  */
12
17
  fileName?: string;
13
18
  }
14
19
  interface TypestylesPluginOptions {
15
- /** Warn about duplicate namespaces across modules. Defaults to true. */
20
+ /**
21
+ * When true (default), fail the build if the same logical `styles.component` / `styles.class`
22
+ * namespace appears in more than one module. Set to `false` to skip this check.
23
+ */
16
24
  warnDuplicates?: boolean;
17
25
  /**
18
26
  * Mode for typestyles integration:
19
- * - "runtime" (default): HMR only, no build-time extraction.
20
- * - "build": emit a static CSS asset during build using typestyles/build.
21
- * - "hybrid": both runtime injection and build-time CSS asset.
27
+ * - `"runtime"`: HMR only, no build-time extraction.
28
+ * - `"build"`: emit a static CSS asset on `vite build` and disable client injection there.
29
+ * - `"hybrid"`: extract on build and keep runtime-compatible behavior.
30
+ *
31
+ * When omitted and at least one extraction module is resolved (explicit `extract.modules`, or a
32
+ * discovered convention entry file), defaults to `"build"`: `vite dev` keeps runtime
33
+ * injection + HMR (runtime is only disabled during `vite build`), serves the same extracted CSS
34
+ * at `extract.fileName` so `<link href="/typestyles.css">` is valid (avoids SPA fallback
35
+ * returning HTML for that URL), and production emits the CSS file. If no modules are resolved,
36
+ * defaults to `"runtime"`.
22
37
  */
23
38
  mode?: 'runtime' | 'build' | 'hybrid';
24
39
  /**
25
40
  * Options for build-time CSS extraction when mode is "build" or "hybrid".
41
+ *
42
+ * Omitted entirely: discover a convention entry under the project root (see
43
+ * {@link discoverDefaultExtractModules}); if none exist, stays in runtime-only mode.
26
44
  */
27
45
  extract?: TypestylesExtractOptions;
28
46
  }
@@ -37,9 +55,10 @@ declare function extractNamespaces(code: string): {
37
55
  /**
38
56
  * Vite plugin for typestyles HMR support.
39
57
  *
40
- * When a module that uses typestyles is edited, this plugin injects HMR
41
- * accept/dispose handlers that invalidate the module's style registrations
42
- * before re-execution — so updated CSS takes effect without a full reload.
58
+ * When a module that registers typestyles (e.g. `styles.component`, `styles.class`, `tokens.create`) is edited,
59
+ * this plugin injects HMR accept/dispose handlers that invalidate that module's registrations
60
+ * before re-execution. Files may import from a local re-export such as `./typestyles` rather
61
+ * than `from 'typestyles'` directly — we key off API call patterns in the source, not the import path.
43
62
  */
44
63
  declare function typestylesPlugin(options?: TypestylesPluginOptions): Plugin;
45
64
 
package/dist/index.js CHANGED
@@ -1,20 +1,30 @@
1
1
  // src/index.ts
2
- import { runTypestylesBuild } from "@typestyles/build-runner";
3
- var STYLES_CREATE_RE = /styles\.create\(\s*['"]([^'"]+)['"]/g;
2
+ import { resolve as resolvePath } from "path";
3
+ import { discoverDefaultExtractModules, runTypestylesBuild } from "@typestyles/build-runner";
4
+ import {
5
+ DEFAULT_EXTRACT_MODULE_CANDIDATES,
6
+ discoverDefaultExtractModules as discoverDefaultExtractModules2
7
+ } from "@typestyles/build-runner";
4
8
  var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
9
+ var STYLES_CLASS_RE = /styles\.class\(\s*['"]([^'"]+)['"]/g;
5
10
  var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
6
11
  var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
7
12
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
8
13
  var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
9
14
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
10
- var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
15
+ function resolveExtractModules(root, extract) {
16
+ if (extract?.modules !== void 0) {
17
+ return extract.modules;
18
+ }
19
+ return discoverDefaultExtractModules(root);
20
+ }
11
21
  function extractNamespaces(code) {
12
22
  const keys = [];
13
23
  const prefixes = [];
14
- for (const match of code.matchAll(STYLES_CREATE_RE)) {
24
+ for (const match of code.matchAll(STYLES_COMPONENT_RE)) {
15
25
  prefixes.push(`.${match[1]}-`);
16
26
  }
17
- for (const match of code.matchAll(STYLES_COMPONENT_RE)) {
27
+ for (const match of code.matchAll(STYLES_CLASS_RE)) {
18
28
  prefixes.push(`.${match[1]}-`);
19
29
  }
20
30
  for (const match of code.matchAll(TOKENS_CREATE_RE)) {
@@ -35,16 +45,24 @@ function extractNamespaces(code) {
35
45
  return { keys, prefixes };
36
46
  }
37
47
  function typestylesPlugin(options = {}) {
38
- const { warnDuplicates = true, mode = "runtime", extract } = options;
48
+ const { warnDuplicates = true, extract } = options;
49
+ let resolvedExtractModules = [];
50
+ let resolvedMode = "runtime";
39
51
  const moduleNamespaces = /* @__PURE__ */ new Map();
40
52
  let resolvedConfig = null;
41
53
  let isBuildCommand = false;
54
+ let isServe = false;
55
+ let devExtractCss = null;
56
+ let devExtractInFlight = null;
42
57
  return {
43
58
  name: "typestyles",
44
59
  enforce: "pre",
45
60
  config(config, env) {
46
61
  isBuildCommand = env.command === "build";
47
- if (env.command === "build" && (mode === "build" || mode === "hybrid")) {
62
+ const root = resolvePath(config.root ?? process.cwd());
63
+ resolvedExtractModules = resolveExtractModules(root, extract);
64
+ resolvedMode = options.mode ?? (resolvedExtractModules.length > 0 ? "build" : "runtime");
65
+ if (env.command === "build" && (resolvedMode === "build" || resolvedMode === "hybrid")) {
48
66
  config.define = {
49
67
  ...config.define ?? {},
50
68
  // Inlined by the bundler so typestyles sheet skips creating <style> in production
@@ -55,11 +73,69 @@ function typestylesPlugin(options = {}) {
55
73
  },
56
74
  configResolved(config) {
57
75
  resolvedConfig = config;
76
+ isServe = config.command === "serve";
77
+ },
78
+ configureServer(server) {
79
+ if (resolvedExtractModules.length === 0) return;
80
+ if (resolvedMode === "runtime") return;
81
+ const fileName = extract?.fileName ?? "typestyles.css";
82
+ const invalidateDevExtract = () => {
83
+ devExtractCss = null;
84
+ devExtractInFlight = null;
85
+ };
86
+ server.watcher.on("change", invalidateDevExtract);
87
+ server.watcher.on("add", invalidateDevExtract);
88
+ server.watcher.on("unlink", invalidateDevExtract);
89
+ server.middlewares.use(async (req, res, next) => {
90
+ if (req.method !== "GET" && req.method !== "HEAD") {
91
+ next();
92
+ return;
93
+ }
94
+ const config = resolvedConfig;
95
+ if (!config) {
96
+ next();
97
+ return;
98
+ }
99
+ const url = req.url?.split("?")[0] ?? "";
100
+ const base = config.base.replace(/\/$/, "") || "";
101
+ const expectedPath = base === "" || base === "/" ? `/${fileName.replace(/^\//, "")}` : `${base}/${fileName.replace(/^\//, "")}`;
102
+ if (url !== expectedPath) {
103
+ next();
104
+ return;
105
+ }
106
+ const root = config.root ?? process.cwd();
107
+ try {
108
+ if (devExtractCss !== null) {
109
+ res.statusCode = 200;
110
+ res.setHeader("Content-Type", "text/css; charset=utf-8");
111
+ res.setHeader("Cache-Control", "no-cache");
112
+ res.end(devExtractCss);
113
+ return;
114
+ }
115
+ if (!devExtractInFlight) {
116
+ devExtractInFlight = runTypestylesBuild({
117
+ root,
118
+ modules: resolvedExtractModules
119
+ }).then((css2) => {
120
+ devExtractCss = css2;
121
+ return css2;
122
+ }).finally(() => {
123
+ devExtractInFlight = null;
124
+ });
125
+ }
126
+ const css = await devExtractInFlight;
127
+ res.statusCode = 200;
128
+ res.setHeader("Content-Type", "text/css; charset=utf-8");
129
+ res.setHeader("Cache-Control", "no-cache");
130
+ res.end(css);
131
+ } catch (err) {
132
+ next(err);
133
+ }
134
+ });
58
135
  },
59
136
  transform(code, id) {
60
137
  if (!/\.[jt]sx?$/.test(id)) return null;
61
138
  if (id.includes("node_modules")) return null;
62
- if (!TYPESTYLES_IMPORT_RE.test(code)) return null;
63
139
  const { keys, prefixes } = extractNamespaces(code);
64
140
  if (keys.length === 0 && prefixes.length === 0) return null;
65
141
  if (warnDuplicates) {
@@ -68,41 +144,44 @@ function typestylesPlugin(options = {}) {
68
144
  for (const prefix of prefixes) {
69
145
  if (other.prefixes.includes(prefix)) {
70
146
  const ns = prefix.slice(1, -1);
71
- this.warn(
72
- `Style namespace "${ns}" is also used in ${otherId}. Duplicate namespaces cause class name collisions.`
147
+ this.error(
148
+ `[typestyles] Style namespace "${ns}" is also used in ${otherId}. Duplicate namespaces cause class name collisions. Use a distinct name or isolate with createStyles({ scopeId: fileScopeId(import.meta) }).`
73
149
  );
74
150
  }
75
151
  }
76
152
  }
77
153
  }
78
154
  moduleNamespaces.set(id, { keys, prefixes });
155
+ if (!isServe) {
156
+ return null;
157
+ }
79
158
  const keysJSON = JSON.stringify(keys);
80
159
  const prefixesJSON = JSON.stringify(prefixes);
160
+ const hmrImport = `import { invalidateKeys as __typestylesInvalidateKeys } from 'typestyles/hmr';
161
+ `;
81
162
  const hmrCode = `
82
163
  if (import.meta.hot) {
83
- import('typestyles/hmr').then(({ invalidateKeys: __typestyles_invalidateKeys }) => {
84
- import.meta.hot.accept();
85
- import.meta.hot.dispose(() => {
86
- __typestyles_invalidateKeys(${keysJSON}, ${prefixesJSON});
87
- });
164
+ import.meta.hot.accept();
165
+ import.meta.hot.dispose(() => {
166
+ __typestylesInvalidateKeys(${keysJSON}, ${prefixesJSON});
88
167
  });
89
168
  }`;
90
169
  return {
91
- code: code + hmrCode,
170
+ code: hmrImport + code + hmrCode,
92
171
  map: null
93
172
  };
94
173
  },
95
174
  async generateBundle() {
96
175
  if (!isBuildCommand) return;
97
- if (mode === "runtime") return;
98
- if (!extract || !extract.modules.length) return;
176
+ if (resolvedMode === "runtime") return;
177
+ if (!resolvedExtractModules.length) return;
99
178
  if (!resolvedConfig) return;
100
179
  const root = resolvedConfig.root ?? process.cwd();
101
- const fileName = extract.fileName ?? "typestyles.css";
180
+ const fileName = extract?.fileName ?? "typestyles.css";
102
181
  try {
103
182
  const css = await runTypestylesBuild({
104
183
  root,
105
- modules: extract.modules
184
+ modules: resolvedExtractModules
106
185
  });
107
186
  this.emitFile({
108
187
  type: "asset",
@@ -118,6 +197,8 @@ if (import.meta.hot) {
118
197
  };
119
198
  }
120
199
  export {
200
+ DEFAULT_EXTRACT_MODULE_CANDIDATES,
121
201
  typestylesPlugin as default,
202
+ discoverDefaultExtractModules2 as discoverDefaultExtractModules,
122
203
  extractNamespaces
123
204
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/vite",
3
- "version": "0.0.0-unstable.1f1acfdf2902",
3
+ "version": "0.0.0-unstable.28a3f8233b47",
4
4
  "description": "Vite plugin for typestyles HMR support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -38,18 +38,20 @@
38
38
  "vite": ">=5.0.0"
39
39
  },
40
40
  "devDependencies": {
41
+ "eslint": "^9.39.2",
41
42
  "tsup": "^8.0.0",
42
43
  "typescript": "^5.4.0",
43
- "typestyles": "0.0.0-unstable.1f1acfdf2902",
44
+ "typestyles": "0.0.0-unstable.28a3f8233b47",
44
45
  "vite": "^6.0.0",
45
46
  "vitest": "^3.0.0"
46
47
  },
47
48
  "dependencies": {
48
- "@typestyles/build-runner": "0.0.0-unstable.1f1acfdf2902"
49
+ "@typestyles/build-runner": "0.0.0-unstable.28a3f8233b47"
49
50
  },
50
51
  "scripts": {
51
52
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --external typestyles,@typestyles/build-runner",
52
53
  "test": "vitest run",
54
+ "lint": "eslint .",
53
55
  "typecheck": "tsc --noEmit"
54
56
  }
55
57
  }