@typestyles/vite 0.0.0-unstable.835df2a09a6d → 0.0.0-unstable.8bf64b0f3f7d

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,17 +20,27 @@ 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");
31
+ var import_build_runner2 = require("@typestyles/build-runner");
28
32
  var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
29
33
  var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
30
34
  var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
31
35
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
32
36
  var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
33
37
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
38
+ function resolveExtractModules(root, extract) {
39
+ if (extract?.modules !== void 0) {
40
+ return extract.modules;
41
+ }
42
+ return (0, import_build_runner.discoverDefaultExtractModules)(root);
43
+ }
34
44
  function extractNamespaces(code) {
35
45
  const keys = [];
36
46
  const prefixes = [];
@@ -56,8 +66,8 @@ function extractNamespaces(code) {
56
66
  }
57
67
  function typestylesPlugin(options = {}) {
58
68
  const { warnDuplicates = true, extract } = options;
59
- const extractModules = extract?.modules ?? [];
60
- const mode = options.mode ?? (extractModules.length > 0 ? "build" : "runtime");
69
+ let resolvedExtractModules = [];
70
+ let resolvedMode = "runtime";
61
71
  const moduleNamespaces = /* @__PURE__ */ new Map();
62
72
  let resolvedConfig = null;
63
73
  let isBuildCommand = false;
@@ -69,7 +79,10 @@ function typestylesPlugin(options = {}) {
69
79
  enforce: "pre",
70
80
  config(config, env) {
71
81
  isBuildCommand = env.command === "build";
72
- if (env.command === "build" && (mode === "build" || mode === "hybrid")) {
82
+ const root = (0, import_node_path.resolve)(config.root ?? process.cwd());
83
+ resolvedExtractModules = resolveExtractModules(root, extract);
84
+ resolvedMode = options.mode ?? (resolvedExtractModules.length > 0 ? "build" : "runtime");
85
+ if (env.command === "build" && (resolvedMode === "build" || resolvedMode === "hybrid")) {
73
86
  config.define = {
74
87
  ...config.define ?? {},
75
88
  // Inlined by the bundler so typestyles sheet skips creating <style> in production
@@ -83,9 +96,9 @@ function typestylesPlugin(options = {}) {
83
96
  isServe = config.command === "serve";
84
97
  },
85
98
  configureServer(server) {
86
- if (!extract || extractModules.length === 0) return;
87
- if (mode === "runtime") return;
88
- const fileName = extract.fileName ?? "typestyles.css";
99
+ if (resolvedExtractModules.length === 0) return;
100
+ if (resolvedMode === "runtime") return;
101
+ const fileName = extract?.fileName ?? "typestyles.css";
89
102
  const invalidateDevExtract = () => {
90
103
  devExtractCss = null;
91
104
  devExtractInFlight = null;
@@ -122,7 +135,7 @@ function typestylesPlugin(options = {}) {
122
135
  if (!devExtractInFlight) {
123
136
  devExtractInFlight = (0, import_build_runner.runTypestylesBuild)({
124
137
  root,
125
- modules: extractModules
138
+ modules: resolvedExtractModules
126
139
  }).then((css2) => {
127
140
  devExtractCss = css2;
128
141
  return css2;
@@ -180,15 +193,15 @@ if (import.meta.hot) {
180
193
  },
181
194
  async generateBundle() {
182
195
  if (!isBuildCommand) return;
183
- if (mode === "runtime") return;
184
- if (!extract || !extractModules.length) return;
196
+ if (resolvedMode === "runtime") return;
197
+ if (!resolvedExtractModules.length) return;
185
198
  if (!resolvedConfig) return;
186
199
  const root = resolvedConfig.root ?? process.cwd();
187
- const fileName = extract.fileName ?? "typestyles.css";
200
+ const fileName = extract?.fileName ?? "typestyles.css";
188
201
  try {
189
202
  const css = await (0, import_build_runner.runTypestylesBuild)({
190
203
  root,
191
- modules: extractModules
204
+ modules: resolvedExtractModules
192
205
  });
193
206
  this.emitFile({
194
207
  type: "asset",
@@ -205,5 +218,7 @@ if (import.meta.hot) {
205
218
  }
206
219
  // Annotate the CommonJS export names for ESM import in node:
207
220
  0 && (module.exports = {
221
+ DEFAULT_EXTRACT_MODULE_CANDIDATES,
222
+ discoverDefaultExtractModules,
208
223
  extractNamespaces
209
224
  });
package/dist/index.d.cts CHANGED
@@ -1,11 +1,16 @@
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
  */
@@ -20,15 +25,19 @@ interface TypestylesPluginOptions {
20
25
  * - `"build"`: emit a static CSS asset on `vite build` and disable client injection there.
21
26
  * - `"hybrid"`: extract on build and keep runtime-compatible behavior.
22
27
  *
23
- * When omitted and `extract.modules` is non-empty, defaults to `"build"`: `vite dev` keeps
24
- * runtime injection + HMR (runtime is only disabled during `vite build`), serves the same
25
- * extracted CSS at `extract.fileName` so `<link href="/typestyles.css">` is valid (avoids SPA
26
- * fallback returning HTML for that URL), and production emits the CSS file. With no `extract`
27
- * config, defaults to `"runtime"`.
28
+ * When omitted and at least one extraction module is resolved (explicit `extract.modules`, or a
29
+ * discovered convention entry file), defaults to `"build"`: `vite dev` keeps runtime
30
+ * injection + HMR (runtime is only disabled during `vite build`), serves the same extracted CSS
31
+ * at `extract.fileName` so `<link href="/typestyles.css">` is valid (avoids SPA fallback
32
+ * returning HTML for that URL), and production emits the CSS file. If no modules are resolved,
33
+ * defaults to `"runtime"`.
28
34
  */
29
35
  mode?: 'runtime' | 'build' | 'hybrid';
30
36
  /**
31
37
  * Options for build-time CSS extraction when mode is "build" or "hybrid".
38
+ *
39
+ * Omitted entirely: discover a convention entry under the project root (see
40
+ * {@link discoverDefaultExtractModules}); if none exist, stays in runtime-only mode.
32
41
  */
33
42
  extract?: TypestylesExtractOptions;
34
43
  }
package/dist/index.d.ts CHANGED
@@ -1,11 +1,16 @@
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
  */
@@ -20,15 +25,19 @@ interface TypestylesPluginOptions {
20
25
  * - `"build"`: emit a static CSS asset on `vite build` and disable client injection there.
21
26
  * - `"hybrid"`: extract on build and keep runtime-compatible behavior.
22
27
  *
23
- * When omitted and `extract.modules` is non-empty, defaults to `"build"`: `vite dev` keeps
24
- * runtime injection + HMR (runtime is only disabled during `vite build`), serves the same
25
- * extracted CSS at `extract.fileName` so `<link href="/typestyles.css">` is valid (avoids SPA
26
- * fallback returning HTML for that URL), and production emits the CSS file. With no `extract`
27
- * config, defaults to `"runtime"`.
28
+ * When omitted and at least one extraction module is resolved (explicit `extract.modules`, or a
29
+ * discovered convention entry file), defaults to `"build"`: `vite dev` keeps runtime
30
+ * injection + HMR (runtime is only disabled during `vite build`), serves the same extracted CSS
31
+ * at `extract.fileName` so `<link href="/typestyles.css">` is valid (avoids SPA fallback
32
+ * returning HTML for that URL), and production emits the CSS file. If no modules are resolved,
33
+ * defaults to `"runtime"`.
28
34
  */
29
35
  mode?: 'runtime' | 'build' | 'hybrid';
30
36
  /**
31
37
  * Options for build-time CSS extraction when mode is "build" or "hybrid".
38
+ *
39
+ * Omitted entirely: discover a convention entry under the project root (see
40
+ * {@link discoverDefaultExtractModules}); if none exist, stays in runtime-only mode.
32
41
  */
33
42
  extract?: TypestylesExtractOptions;
34
43
  }
package/dist/index.js CHANGED
@@ -1,11 +1,22 @@
1
1
  // src/index.ts
2
- import { runTypestylesBuild } from "@typestyles/build-runner";
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";
3
8
  var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
4
9
  var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
5
10
  var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
6
11
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
7
12
  var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
8
13
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
14
+ function resolveExtractModules(root, extract) {
15
+ if (extract?.modules !== void 0) {
16
+ return extract.modules;
17
+ }
18
+ return discoverDefaultExtractModules(root);
19
+ }
9
20
  function extractNamespaces(code) {
10
21
  const keys = [];
11
22
  const prefixes = [];
@@ -31,8 +42,8 @@ function extractNamespaces(code) {
31
42
  }
32
43
  function typestylesPlugin(options = {}) {
33
44
  const { warnDuplicates = true, extract } = options;
34
- const extractModules = extract?.modules ?? [];
35
- const mode = options.mode ?? (extractModules.length > 0 ? "build" : "runtime");
45
+ let resolvedExtractModules = [];
46
+ let resolvedMode = "runtime";
36
47
  const moduleNamespaces = /* @__PURE__ */ new Map();
37
48
  let resolvedConfig = null;
38
49
  let isBuildCommand = false;
@@ -44,7 +55,10 @@ function typestylesPlugin(options = {}) {
44
55
  enforce: "pre",
45
56
  config(config, env) {
46
57
  isBuildCommand = env.command === "build";
47
- if (env.command === "build" && (mode === "build" || mode === "hybrid")) {
58
+ const root = resolvePath(config.root ?? process.cwd());
59
+ resolvedExtractModules = resolveExtractModules(root, extract);
60
+ resolvedMode = options.mode ?? (resolvedExtractModules.length > 0 ? "build" : "runtime");
61
+ if (env.command === "build" && (resolvedMode === "build" || resolvedMode === "hybrid")) {
48
62
  config.define = {
49
63
  ...config.define ?? {},
50
64
  // Inlined by the bundler so typestyles sheet skips creating <style> in production
@@ -58,9 +72,9 @@ function typestylesPlugin(options = {}) {
58
72
  isServe = config.command === "serve";
59
73
  },
60
74
  configureServer(server) {
61
- if (!extract || extractModules.length === 0) return;
62
- if (mode === "runtime") return;
63
- const fileName = extract.fileName ?? "typestyles.css";
75
+ if (resolvedExtractModules.length === 0) return;
76
+ if (resolvedMode === "runtime") return;
77
+ const fileName = extract?.fileName ?? "typestyles.css";
64
78
  const invalidateDevExtract = () => {
65
79
  devExtractCss = null;
66
80
  devExtractInFlight = null;
@@ -97,7 +111,7 @@ function typestylesPlugin(options = {}) {
97
111
  if (!devExtractInFlight) {
98
112
  devExtractInFlight = runTypestylesBuild({
99
113
  root,
100
- modules: extractModules
114
+ modules: resolvedExtractModules
101
115
  }).then((css2) => {
102
116
  devExtractCss = css2;
103
117
  return css2;
@@ -155,15 +169,15 @@ if (import.meta.hot) {
155
169
  },
156
170
  async generateBundle() {
157
171
  if (!isBuildCommand) return;
158
- if (mode === "runtime") return;
159
- if (!extract || !extractModules.length) return;
172
+ if (resolvedMode === "runtime") return;
173
+ if (!resolvedExtractModules.length) return;
160
174
  if (!resolvedConfig) return;
161
175
  const root = resolvedConfig.root ?? process.cwd();
162
- const fileName = extract.fileName ?? "typestyles.css";
176
+ const fileName = extract?.fileName ?? "typestyles.css";
163
177
  try {
164
178
  const css = await runTypestylesBuild({
165
179
  root,
166
- modules: extractModules
180
+ modules: resolvedExtractModules
167
181
  });
168
182
  this.emitFile({
169
183
  type: "asset",
@@ -179,6 +193,8 @@ if (import.meta.hot) {
179
193
  };
180
194
  }
181
195
  export {
196
+ DEFAULT_EXTRACT_MODULE_CANDIDATES,
182
197
  typestylesPlugin as default,
198
+ discoverDefaultExtractModules2 as discoverDefaultExtractModules,
183
199
  extractNamespaces
184
200
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/vite",
3
- "version": "0.0.0-unstable.835df2a09a6d",
3
+ "version": "0.0.0-unstable.8bf64b0f3f7d",
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.835df2a09a6d",
44
+ "typestyles": "0.0.0-unstable.8bf64b0f3f7d",
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.835df2a09a6d"
49
+ "@typestyles/build-runner": "0.0.0-unstable.8bf64b0f3f7d"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup src/index.ts --format esm,cjs --dts --clean --external typestyles,@typestyles/build-runner",