@typestyles/vite 0.5.3 → 0.5.4

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
@@ -99,6 +99,13 @@ typestyles({
99
99
  /** Default: true — fail the build on duplicate recipe / style namespaces */
100
100
  warnDuplicates?: boolean;
101
101
 
102
+ /**
103
+ * Default: true — fail `vite build` when a local module reachable from the app
104
+ * calls `recipe()` and is missing from the extract entry. Set false to extract
105
+ * a subset on purpose.
106
+ */
107
+ coverage?: boolean;
108
+
102
109
  /**
103
110
  * - 'runtime': HMR only, no extraction
104
111
  * - 'build': extract on vite build; runtime stays on during vite dev (default when modules resolve)
@@ -146,7 +153,9 @@ Even with a convention entry present, this keeps `<style>` injection in producti
146
153
 
147
154
  ## Verify production output
148
155
 
149
- Extraction is execute-and-collect: styles unreachable from your entry file are silently dropped. After `vite build`, run:
156
+ On `vite build`, the plugin fails if a local module reachable from the app calls `recipe()` and that file is missing from the extract entry. The error names the module and the recipe `name`. Import the module from the convention entry, or set `coverage: false` when the production CSS is meant to omit it.
157
+
158
+ Tokens, themes, and `style()` calls are still execute-and-collect: anything the entry file does not run is omitted. After `vite build`, assert on the emitted file:
150
159
 
151
160
  ```ts
152
161
  import { verifyTypestylesBuild } from '@typestyles/build-runner';
package/dist/index.cjs CHANGED
@@ -25,14 +25,27 @@ function htmlLinksTypestylesCss(html, cssHref, fileName) {
25
25
  }
26
26
  return false;
27
27
  }
28
+ function formatUnextractedRecipeError(missing, extractEntries) {
29
+ const entries = extractEntries.map((entry) => entry.replace(/\\/g, "/")).join(", ");
30
+ return [
31
+ "[typestyles] Production extract is missing app recipes:",
32
+ ...missing.map((item) => {
33
+ const quoted = item.names.map((name) => `"${name}"`).join(", ");
34
+ return ` ${item.names.length === 1 ? "recipe" : "recipes"} ${quoted} in ${item.modulePath}`;
35
+ }),
36
+ `These modules are reachable from the app and missing from the extract entry (${entries}).`,
37
+ "Import them from the extract entry, or set coverage: false to extract a subset."
38
+ ].join("\n");
39
+ }
28
40
  function typestylesPlugin(options = {}) {
29
- const { warnDuplicates = true, extract } = options;
41
+ const { warnDuplicates = true, coverage = true, extract } = options;
30
42
  let resolvedExtractModules = [];
31
43
  let resolvedMode = "runtime";
32
44
  const moduleNamespaces = new Map();
33
45
  let resolvedConfig = null;
34
46
  let isBuildCommand = false;
35
47
  let isServe = false;
48
+ const recipeModules = new Map();
36
49
  let devExtractCss = null;
37
50
  let devExtractInFlight = null;
38
51
  return {
@@ -110,8 +123,9 @@ function typestylesPlugin(options = {}) {
110
123
  transform(code, id) {
111
124
  if (!/\.[jt]sx?$/.test(id)) return null;
112
125
  if (id.includes("node_modules")) return null;
113
- const { keys, prefixes } = (0, _typestyles_build_runner.extractNamespaces)(code);
126
+ const { keys, prefixes, recipeNames } = (0, _typestyles_build_runner.extractNamespaces)(code);
114
127
  const overrideHmr = (0, _typestyles_build_runner.moduleNeedsOverrideHmr)(code);
128
+ if (coverage && isBuildCommand && resolvedMode !== "runtime" && resolvedExtractModules.length > 0 && recipeNames.length > 0) recipeModules.set(id, recipeNames);
115
129
  if (keys.length === 0 && prefixes.length === 0 && !overrideHmr) return null;
116
130
  if (warnDuplicates && prefixes.length > 0) (0, _typestyles_build_runner.reportDuplicateNamespaces)(moduleNamespaces, id, prefixes, this);
117
131
  if (keys.length > 0 || prefixes.length > 0) moduleNamespaces.set(id, {
@@ -161,6 +175,26 @@ if (import.meta.hot) {
161
175
  if (!resolvedConfig) return;
162
176
  const root = resolvedConfig.root ?? process.cwd();
163
177
  const fileName = extract?.fileName ?? "typestyles.css";
178
+ if (coverage && recipeModules.size > 0) {
179
+ let missing = [];
180
+ try {
181
+ missing = await (0, _typestyles_build_runner.findUnextractedRecipes)({
182
+ root,
183
+ extractEntries: resolvedExtractModules,
184
+ recipeModules: [...recipeModules.entries()].map(([id, names]) => ({
185
+ id,
186
+ names
187
+ }))
188
+ });
189
+ } catch (err) {
190
+ this.error(`[typestyles] Failed to check extract coverage: ${err instanceof Error ? err.message : String(err)}`);
191
+ return;
192
+ }
193
+ if (missing.length > 0) {
194
+ this.error(formatUnextractedRecipeError(missing, resolvedExtractModules));
195
+ return;
196
+ }
197
+ }
164
198
  try {
165
199
  const css = await (0, _typestyles_build_runner.runTypestylesBuild)({
166
200
  root,
package/dist/index.d.cts CHANGED
@@ -20,6 +20,14 @@ export interface TypestylesPluginOptions {
20
20
  * namespace appears in more than one module. Set to `false` to skip this check.
21
21
  */
22
22
  warnDuplicates?: boolean;
23
+ /**
24
+ * When true (default), fail `vite build` if a local module reachable from the app calls
25
+ * `recipe()` (or `styles.component()`) and that module is missing from the extract entry.
26
+ * The error names the module and the recipe. Set to `false` when the production extract
27
+ * is meant to cover only part of the app. Ignored in `runtime` mode and when nothing
28
+ * is extracted.
29
+ */
30
+ coverage?: boolean;
23
31
  /**
24
32
  * Mode for typestyles integration:
25
33
  * - `"runtime"`: HMR only, no build-time extraction.
package/dist/index.d.ts CHANGED
@@ -20,6 +20,14 @@ export interface TypestylesPluginOptions {
20
20
  * namespace appears in more than one module. Set to `false` to skip this check.
21
21
  */
22
22
  warnDuplicates?: boolean;
23
+ /**
24
+ * When true (default), fail `vite build` if a local module reachable from the app calls
25
+ * `recipe()` (or `styles.component()`) and that module is missing from the extract entry.
26
+ * The error names the module and the recipe. Set to `false` when the production extract
27
+ * is meant to cover only part of the app. Ignored in `runtime` mode and when nothing
28
+ * is extracted.
29
+ */
30
+ coverage?: boolean;
23
31
  /**
24
32
  * Mode for typestyles integration:
25
33
  * - `"runtime"`: HMR only, no build-time extraction.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { resolve } from "node:path";
2
- import { DEFAULT_EXTRACT_MODULE_CANDIDATES, discoverDefaultExtractModules, extractNamespaces, moduleNeedsOverrideHmr, moduleNeedsOverrideHmr as moduleNeedsOverrideHmr$1, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild } from "@typestyles/build-runner";
2
+ import { DEFAULT_EXTRACT_MODULE_CANDIDATES, discoverDefaultExtractModules, extractNamespaces, findUnextractedRecipes, moduleNeedsOverrideHmr, moduleNeedsOverrideHmr as moduleNeedsOverrideHmr$1, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild } from "@typestyles/build-runner";
3
3
  //#region src/index.ts
4
4
  function resolveExtractModulesForVite(root, extract) {
5
5
  return resolveExtractModules(root, extract);
@@ -21,14 +21,27 @@ function htmlLinksTypestylesCss(html, cssHref, fileName) {
21
21
  }
22
22
  return false;
23
23
  }
24
+ function formatUnextractedRecipeError(missing, extractEntries) {
25
+ const entries = extractEntries.map((entry) => entry.replace(/\\/g, "/")).join(", ");
26
+ return [
27
+ "[typestyles] Production extract is missing app recipes:",
28
+ ...missing.map((item) => {
29
+ const quoted = item.names.map((name) => `"${name}"`).join(", ");
30
+ return ` ${item.names.length === 1 ? "recipe" : "recipes"} ${quoted} in ${item.modulePath}`;
31
+ }),
32
+ `These modules are reachable from the app and missing from the extract entry (${entries}).`,
33
+ "Import them from the extract entry, or set coverage: false to extract a subset."
34
+ ].join("\n");
35
+ }
24
36
  function typestylesPlugin(options = {}) {
25
- const { warnDuplicates = true, extract } = options;
37
+ const { warnDuplicates = true, coverage = true, extract } = options;
26
38
  let resolvedExtractModules = [];
27
39
  let resolvedMode = "runtime";
28
40
  const moduleNamespaces = new Map();
29
41
  let resolvedConfig = null;
30
42
  let isBuildCommand = false;
31
43
  let isServe = false;
44
+ const recipeModules = new Map();
32
45
  let devExtractCss = null;
33
46
  let devExtractInFlight = null;
34
47
  return {
@@ -106,8 +119,9 @@ function typestylesPlugin(options = {}) {
106
119
  transform(code, id) {
107
120
  if (!/\.[jt]sx?$/.test(id)) return null;
108
121
  if (id.includes("node_modules")) return null;
109
- const { keys, prefixes } = extractNamespaces(code);
122
+ const { keys, prefixes, recipeNames } = extractNamespaces(code);
110
123
  const overrideHmr = moduleNeedsOverrideHmr$1(code);
124
+ if (coverage && isBuildCommand && resolvedMode !== "runtime" && resolvedExtractModules.length > 0 && recipeNames.length > 0) recipeModules.set(id, recipeNames);
111
125
  if (keys.length === 0 && prefixes.length === 0 && !overrideHmr) return null;
112
126
  if (warnDuplicates && prefixes.length > 0) reportDuplicateNamespaces(moduleNamespaces, id, prefixes, this);
113
127
  if (keys.length > 0 || prefixes.length > 0) moduleNamespaces.set(id, {
@@ -157,6 +171,26 @@ if (import.meta.hot) {
157
171
  if (!resolvedConfig) return;
158
172
  const root = resolvedConfig.root ?? process.cwd();
159
173
  const fileName = extract?.fileName ?? "typestyles.css";
174
+ if (coverage && recipeModules.size > 0) {
175
+ let missing = [];
176
+ try {
177
+ missing = await findUnextractedRecipes({
178
+ root,
179
+ extractEntries: resolvedExtractModules,
180
+ recipeModules: [...recipeModules.entries()].map(([id, names]) => ({
181
+ id,
182
+ names
183
+ }))
184
+ });
185
+ } catch (err) {
186
+ this.error(`[typestyles] Failed to check extract coverage: ${err instanceof Error ? err.message : String(err)}`);
187
+ return;
188
+ }
189
+ if (missing.length > 0) {
190
+ this.error(formatUnextractedRecipeError(missing, resolvedExtractModules));
191
+ return;
192
+ }
193
+ }
160
194
  try {
161
195
  const css = await runTypestylesBuild({
162
196
  root,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/vite",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Vite plugin for typestyles HMR support",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -41,10 +41,10 @@
41
41
  "typescript": "^6.0.0",
42
42
  "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
43
43
  "vite-plus": "1.3.0",
44
- "typestyles": "0.32.3"
44
+ "typestyles": "0.33.0"
45
45
  },
46
46
  "dependencies": {
47
- "@typestyles/build-runner": "0.6.3"
47
+ "@typestyles/build-runner": "0.6.4"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "vp pack",