@typestyles/build-runner 0.5.3 → 0.6.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
@@ -164,7 +164,7 @@ Parses a file for typestyles registration calls. Returns `{ keys, prefixes }` fo
164
164
  import { extractNamespaces } from '@typestyles/build-runner';
165
165
 
166
166
  const { prefixes } = extractNamespaces(source);
167
- // styles.component('button', ...) → prefixes includes '.button-'
167
+ // recipe('button', ...) → prefixes includes '.button-'
168
168
  ```
169
169
 
170
170
  ### `reportDuplicateNamespaces(map, fileId, prefixes, reporter)`
package/dist/index.cjs CHANGED
@@ -94,13 +94,30 @@ function discoverRegisteredComponentsModule(root) {
94
94
  }
95
95
 
96
96
  // src/namespaces.ts
97
- var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
98
- var STYLES_CLASS_RE = /styles\.class\(\s*['"]([^'"]+)['"]/g;
97
+ var STYLES_COMPONENT_RE = /(?:styles\.component|(?<![\w.])recipe)\(\s*['"]([^'"]+)['"]/g;
98
+ var STYLES_CLASS_RE = /(?:styles\.class|(?<![\w.])style)\(\s*['"]([^'"]+)['"]/g;
99
99
  var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
100
- var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
100
+ var CREATE_THEME_CALL_RE = /(?:tokens\.)?createTheme\s*\(/g;
101
101
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
102
- var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
102
+ var GLOBAL_STYLE_RE = /global\.(?:rule|style)\(\s*['"]([^'"]+)['"]/g;
103
103
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
104
+ var CREATE_THEME_ARG_SCAN = 4e3;
105
+ function extractCreateThemeNames(code) {
106
+ const names = [];
107
+ for (const match of code.matchAll(CREATE_THEME_CALL_RE)) {
108
+ const start = (match.index ?? 0) + match[0].length;
109
+ const args = code.slice(start, start + CREATE_THEME_ARG_SCAN);
110
+ const positional = args.match(/^\s*['"]([^'"]+)['"]/);
111
+ if (positional) {
112
+ names.push(positional[1]);
113
+ continue;
114
+ }
115
+ if (!/^\s*\{/.test(args)) continue;
116
+ const named = args.match(/\bname\s*:\s*['"]([^'"]+)['"]/);
117
+ if (named) names.push(named[1]);
118
+ }
119
+ return names;
120
+ }
104
121
  var OVERRIDE_HMR_EXPORT_NAMES = /* @__PURE__ */ new Set(["createDesignTheme", "overrideComponent"]);
105
122
  var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
106
123
  function stripCommentsForHmrScan(code) {
@@ -133,7 +150,7 @@ function collectOverrideHmrCallTargets(code) {
133
150
  }
134
151
  function moduleNeedsOverrideHmr(code) {
135
152
  const scan = stripCommentsForHmrScan(code);
136
- if (/\bstyles\.override\s*\(/.test(scan)) return true;
153
+ if (/\b(?:styles\.)?override\s*\(/.test(scan)) return true;
137
154
  const { locals, namespaces } = collectOverrideHmrCallTargets(scan);
138
155
  for (const name of locals) {
139
156
  if (new RegExp(`\\b${name}\\s*\\(`).test(scan)) return true;
@@ -157,8 +174,8 @@ function extractNamespaces(code) {
157
174
  for (const match of code.matchAll(TOKENS_CREATE_RE)) {
158
175
  keys.push(`tokens:${match[1]}`);
159
176
  }
160
- for (const match of code.matchAll(CREATE_THEME_RE)) {
161
- keys.push(`theme:${match[1]}`);
177
+ for (const themeName of extractCreateThemeNames(code)) {
178
+ keys.push(`theme:${themeName}`);
162
179
  }
163
180
  for (const match of code.matchAll(KEYFRAMES_CREATE_RE)) {
164
181
  keys.push(`keyframes:${match[1]}`);
@@ -498,10 +515,11 @@ async function traceTypestylesModules(root, entryFiles) {
498
515
  }
499
516
  return [...traced].sort();
500
517
  }
518
+ var moduleLoadNonce = 0;
501
519
  function createModuleLoader(root, modulePath) {
502
520
  const abs = (0, import_node_path4.resolve)(root, modulePath);
503
521
  const href = (0, import_node_url.pathToFileURL)(abs).href;
504
- return () => import(href);
522
+ return () => import(`${href}?typestyles-extract=${++moduleLoadNonce}`);
505
523
  }
506
524
 
507
525
  // src/route-css.ts
package/dist/index.d.cts CHANGED
@@ -167,7 +167,7 @@ declare function discoverNextAppRoutes(root: string, appDir?: string): NextAppRo
167
167
  * Paths are relative to `root` with `/` separators.
168
168
  */
169
169
  declare function traceTypestylesModules(root: string, entryFiles: string[]): Promise<string[]>;
170
- /** Load a traced module for style extraction. */
170
+ /** Load a traced module for style extraction (cache-busted so re-runs re-register styles). */
171
171
  declare function createModuleLoader(root: string, modulePath: string): () => Promise<unknown>;
172
172
 
173
173
  interface CollectRouteCssOptions {
package/dist/index.d.ts CHANGED
@@ -167,7 +167,7 @@ declare function discoverNextAppRoutes(root: string, appDir?: string): NextAppRo
167
167
  * Paths are relative to `root` with `/` separators.
168
168
  */
169
169
  declare function traceTypestylesModules(root: string, entryFiles: string[]): Promise<string[]>;
170
- /** Load a traced module for style extraction. */
170
+ /** Load a traced module for style extraction (cache-busted so re-runs re-register styles). */
171
171
  declare function createModuleLoader(root: string, modulePath: string): () => Promise<unknown>;
172
172
 
173
173
  interface CollectRouteCssOptions {
package/dist/index.js CHANGED
@@ -45,13 +45,30 @@ function discoverRegisteredComponentsModule(root) {
45
45
  }
46
46
 
47
47
  // src/namespaces.ts
48
- var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
49
- var STYLES_CLASS_RE = /styles\.class\(\s*['"]([^'"]+)['"]/g;
48
+ var STYLES_COMPONENT_RE = /(?:styles\.component|(?<![\w.])recipe)\(\s*['"]([^'"]+)['"]/g;
49
+ var STYLES_CLASS_RE = /(?:styles\.class|(?<![\w.])style)\(\s*['"]([^'"]+)['"]/g;
50
50
  var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
51
- var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
51
+ var CREATE_THEME_CALL_RE = /(?:tokens\.)?createTheme\s*\(/g;
52
52
  var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
53
- var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
53
+ var GLOBAL_STYLE_RE = /global\.(?:rule|style)\(\s*['"]([^'"]+)['"]/g;
54
54
  var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
55
+ var CREATE_THEME_ARG_SCAN = 4e3;
56
+ function extractCreateThemeNames(code) {
57
+ const names = [];
58
+ for (const match of code.matchAll(CREATE_THEME_CALL_RE)) {
59
+ const start = (match.index ?? 0) + match[0].length;
60
+ const args = code.slice(start, start + CREATE_THEME_ARG_SCAN);
61
+ const positional = args.match(/^\s*['"]([^'"]+)['"]/);
62
+ if (positional) {
63
+ names.push(positional[1]);
64
+ continue;
65
+ }
66
+ if (!/^\s*\{/.test(args)) continue;
67
+ const named = args.match(/\bname\s*:\s*['"]([^'"]+)['"]/);
68
+ if (named) names.push(named[1]);
69
+ }
70
+ return names;
71
+ }
55
72
  var OVERRIDE_HMR_EXPORT_NAMES = /* @__PURE__ */ new Set(["createDesignTheme", "overrideComponent"]);
56
73
  var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
57
74
  function stripCommentsForHmrScan(code) {
@@ -84,7 +101,7 @@ function collectOverrideHmrCallTargets(code) {
84
101
  }
85
102
  function moduleNeedsOverrideHmr(code) {
86
103
  const scan = stripCommentsForHmrScan(code);
87
- if (/\bstyles\.override\s*\(/.test(scan)) return true;
104
+ if (/\b(?:styles\.)?override\s*\(/.test(scan)) return true;
88
105
  const { locals, namespaces } = collectOverrideHmrCallTargets(scan);
89
106
  for (const name of locals) {
90
107
  if (new RegExp(`\\b${name}\\s*\\(`).test(scan)) return true;
@@ -108,8 +125,8 @@ function extractNamespaces(code) {
108
125
  for (const match of code.matchAll(TOKENS_CREATE_RE)) {
109
126
  keys.push(`tokens:${match[1]}`);
110
127
  }
111
- for (const match of code.matchAll(CREATE_THEME_RE)) {
112
- keys.push(`theme:${match[1]}`);
128
+ for (const themeName of extractCreateThemeNames(code)) {
129
+ keys.push(`theme:${themeName}`);
113
130
  }
114
131
  for (const match of code.matchAll(KEYFRAMES_CREATE_RE)) {
115
132
  keys.push(`keyframes:${match[1]}`);
@@ -449,10 +466,11 @@ async function traceTypestylesModules(root, entryFiles) {
449
466
  }
450
467
  return [...traced].sort();
451
468
  }
469
+ var moduleLoadNonce = 0;
452
470
  function createModuleLoader(root, modulePath) {
453
471
  const abs = resolve3(root, modulePath);
454
472
  const href = pathToFileURL(abs).href;
455
- return () => import(href);
473
+ return () => import(`${href}?typestyles-extract=${++moduleLoadNonce}`);
456
474
  }
457
475
 
458
476
  // src/route-css.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typestyles/build-runner",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "Shared module execution utilities for typestyles build integrations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -30,7 +30,7 @@
30
30
  "tsup": "^8.0.0",
31
31
  "typescript": "^5.4.0",
32
32
  "vitest": "^3.0.0",
33
- "typestyles": "0.25.0"
33
+ "typestyles": "1.0.0"
34
34
  },
35
35
  "license": "Apache-2.0",
36
36
  "repository": {