@typestyles/build-runner 0.0.0-unstable.dc32065699a4 → 0.0.0-unstable.dda865821d0c
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 +1 -1
- package/dist/index.cjs +60 -10
- package/dist/index.d.cts +26 -2
- package/dist/index.d.ts +26 -2
- package/dist/index.js +58 -10
- package/package.json +2 -2
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
|
-
//
|
|
167
|
+
// recipe('button', ...) → prefixes includes '.button-'
|
|
168
168
|
```
|
|
169
169
|
|
|
170
170
|
### `reportDuplicateNamespaces(map, fileId, prefixes, reporter)`
|
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
DEFAULT_EXTRACT_MODULE_CANDIDATES: () => DEFAULT_EXTRACT_MODULE_CANDIDATES,
|
|
24
|
+
DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES: () => DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES,
|
|
24
25
|
TYPESTYLES_IMPORT_RE: () => TYPESTYLES_IMPORT_RE,
|
|
25
26
|
VerifyTypestylesBuildError: () => VerifyTypestylesBuildError,
|
|
26
27
|
buildManifestV2: () => buildManifestV2,
|
|
@@ -28,6 +29,7 @@ __export(index_exports, {
|
|
|
28
29
|
createModuleLoader: () => createModuleLoader,
|
|
29
30
|
discoverDefaultExtractModules: () => discoverDefaultExtractModules,
|
|
30
31
|
discoverNextAppRoutes: () => discoverNextAppRoutes,
|
|
32
|
+
discoverRegisteredComponentsModule: () => discoverRegisteredComponentsModule,
|
|
31
33
|
extractNamespaces: () => extractNamespaces,
|
|
32
34
|
getRouteCss: () => getRouteCss,
|
|
33
35
|
isManifestV2: () => isManifestV2,
|
|
@@ -60,6 +62,12 @@ var DISCOVERY_EXTENSIONS = [".ts", ".tsx", ".js", ".mjs"];
|
|
|
60
62
|
var DEFAULT_EXTRACT_MODULE_CANDIDATES = DEFAULT_EXTRACT_MODULE_BASES.map(
|
|
61
63
|
(base) => `${base}.ts`
|
|
62
64
|
);
|
|
65
|
+
var DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES = [
|
|
66
|
+
"src/themeable-refs",
|
|
67
|
+
"src/typestyles/themeable-refs",
|
|
68
|
+
"src/typestyles-registry",
|
|
69
|
+
"styles/themeable-refs"
|
|
70
|
+
];
|
|
63
71
|
function discoverDefaultExtractModules(root) {
|
|
64
72
|
const absRoot = (0, import_node_path.resolve)(root);
|
|
65
73
|
for (const base of DEFAULT_EXTRACT_MODULE_BASES) {
|
|
@@ -72,15 +80,44 @@ function discoverDefaultExtractModules(root) {
|
|
|
72
80
|
}
|
|
73
81
|
return [];
|
|
74
82
|
}
|
|
83
|
+
function discoverRegisteredComponentsModule(root) {
|
|
84
|
+
const absRoot = (0, import_node_path.resolve)(root);
|
|
85
|
+
for (const base of DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES) {
|
|
86
|
+
for (const ext of DISCOVERY_EXTENSIONS) {
|
|
87
|
+
const rel = `${base}${ext}`;
|
|
88
|
+
if ((0, import_node_fs.existsSync)((0, import_node_path.resolve)(absRoot, rel))) {
|
|
89
|
+
return rel.replace(/\\/g, "/");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
75
95
|
|
|
76
96
|
// src/namespaces.ts
|
|
77
|
-
var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
|
|
78
|
-
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;
|
|
79
99
|
var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
|
|
80
|
-
var
|
|
100
|
+
var CREATE_THEME_CALL_RE = /(?:tokens\.)?createTheme\s*\(/g;
|
|
81
101
|
var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
|
|
82
|
-
var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
|
|
102
|
+
var GLOBAL_STYLE_RE = /global\.(?:rule|style)\(\s*['"]([^'"]+)['"]/g;
|
|
83
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
|
+
}
|
|
84
121
|
var OVERRIDE_HMR_EXPORT_NAMES = /* @__PURE__ */ new Set(["createDesignTheme", "overrideComponent"]);
|
|
85
122
|
var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
|
|
86
123
|
function stripCommentsForHmrScan(code) {
|
|
@@ -113,7 +150,7 @@ function collectOverrideHmrCallTargets(code) {
|
|
|
113
150
|
}
|
|
114
151
|
function moduleNeedsOverrideHmr(code) {
|
|
115
152
|
const scan = stripCommentsForHmrScan(code);
|
|
116
|
-
if (/\
|
|
153
|
+
if (/\b(?:styles\.)?override\s*\(/.test(scan)) return true;
|
|
117
154
|
const { locals, namespaces } = collectOverrideHmrCallTargets(scan);
|
|
118
155
|
for (const name of locals) {
|
|
119
156
|
if (new RegExp(`\\b${name}\\s*\\(`).test(scan)) return true;
|
|
@@ -137,8 +174,8 @@ function extractNamespaces(code) {
|
|
|
137
174
|
for (const match of code.matchAll(TOKENS_CREATE_RE)) {
|
|
138
175
|
keys.push(`tokens:${match[1]}`);
|
|
139
176
|
}
|
|
140
|
-
for (const
|
|
141
|
-
keys.push(`theme:${
|
|
177
|
+
for (const themeName of extractCreateThemeNames(code)) {
|
|
178
|
+
keys.push(`theme:${themeName}`);
|
|
142
179
|
}
|
|
143
180
|
for (const match of code.matchAll(KEYFRAMES_CREATE_RE)) {
|
|
144
181
|
keys.push(`keyframes:${match[1]}`);
|
|
@@ -167,10 +204,20 @@ function reportDuplicateNamespaces(moduleNamespaces, id, prefixes, reporter) {
|
|
|
167
204
|
|
|
168
205
|
// src/resolve-extract.ts
|
|
169
206
|
function resolveExtractModules(root, extract) {
|
|
207
|
+
let modules;
|
|
170
208
|
if (extract?.modules !== void 0) {
|
|
171
|
-
|
|
209
|
+
modules = [...extract.modules];
|
|
210
|
+
} else {
|
|
211
|
+
modules = discoverDefaultExtractModules(root);
|
|
212
|
+
}
|
|
213
|
+
let registeredModule = extract?.registeredComponentsModule;
|
|
214
|
+
if (!registeredModule && extract?.include === "allRegisteredComponents") {
|
|
215
|
+
registeredModule = discoverRegisteredComponentsModule(root);
|
|
216
|
+
}
|
|
217
|
+
if (registeredModule && !modules.includes(registeredModule)) {
|
|
218
|
+
modules.push(registeredModule);
|
|
172
219
|
}
|
|
173
|
-
return
|
|
220
|
+
return modules;
|
|
174
221
|
}
|
|
175
222
|
function resolveExtractMode(explicitMode, resolvedModules) {
|
|
176
223
|
return explicitMode ?? (resolvedModules.length > 0 ? "build" : "runtime");
|
|
@@ -468,10 +515,11 @@ async function traceTypestylesModules(root, entryFiles) {
|
|
|
468
515
|
}
|
|
469
516
|
return [...traced].sort();
|
|
470
517
|
}
|
|
518
|
+
var moduleLoadNonce = 0;
|
|
471
519
|
function createModuleLoader(root, modulePath) {
|
|
472
520
|
const abs = (0, import_node_path4.resolve)(root, modulePath);
|
|
473
521
|
const href = (0, import_node_url.pathToFileURL)(abs).href;
|
|
474
|
-
return () => import(href);
|
|
522
|
+
return () => import(`${href}?typestyles-extract=${++moduleLoadNonce}`);
|
|
475
523
|
}
|
|
476
524
|
|
|
477
525
|
// src/route-css.ts
|
|
@@ -647,6 +695,7 @@ ${result.stderr || result.stdout || "unknown error"}`
|
|
|
647
695
|
// Annotate the CommonJS export names for ESM import in node:
|
|
648
696
|
0 && (module.exports = {
|
|
649
697
|
DEFAULT_EXTRACT_MODULE_CANDIDATES,
|
|
698
|
+
DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES,
|
|
650
699
|
TYPESTYLES_IMPORT_RE,
|
|
651
700
|
VerifyTypestylesBuildError,
|
|
652
701
|
buildManifestV2,
|
|
@@ -654,6 +703,7 @@ ${result.stderr || result.stdout || "unknown error"}`
|
|
|
654
703
|
createModuleLoader,
|
|
655
704
|
discoverDefaultExtractModules,
|
|
656
705
|
discoverNextAppRoutes,
|
|
706
|
+
discoverRegisteredComponentsModule,
|
|
657
707
|
extractNamespaces,
|
|
658
708
|
getRouteCss,
|
|
659
709
|
isManifestV2,
|
package/dist/index.d.cts
CHANGED
|
@@ -3,11 +3,22 @@
|
|
|
3
3
|
* Shared by bundler integrations and `@typestyles/next/build`.
|
|
4
4
|
*/
|
|
5
5
|
declare const DEFAULT_EXTRACT_MODULE_CANDIDATES: readonly string[];
|
|
6
|
+
/**
|
|
7
|
+
* Side-effect modules that import every recipe and export `getRegisteredComponentRefs(styles)`.
|
|
8
|
+
* Used when `extract.include` is `"allRegisteredComponents"`.
|
|
9
|
+
*/
|
|
10
|
+
declare const DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES: readonly ["src/themeable-refs", "src/typestyles/themeable-refs", "src/typestyles-registry", "styles/themeable-refs"];
|
|
6
11
|
/**
|
|
7
12
|
* Resolve the default extraction module when the user did not pass explicit `modules`.
|
|
8
13
|
* Returns at most one path using `/` separators, relative to `root`.
|
|
9
14
|
*/
|
|
10
15
|
declare function discoverDefaultExtractModules(root: string): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Convention registry module for `extract.include: 'allRegisteredComponents'`.
|
|
18
|
+
* The file should import all recipe modules and
|
|
19
|
+
* export `getRegisteredComponentRefs(styles)` from your `createTypeStyles` entry.
|
|
20
|
+
*/
|
|
21
|
+
declare function discoverRegisteredComponentsModule(root: string): string | undefined;
|
|
11
22
|
|
|
12
23
|
declare const TYPESTYLES_IMPORT_RE: RegExp;
|
|
13
24
|
/**
|
|
@@ -48,6 +59,19 @@ interface TypestylesExtractOptions {
|
|
|
48
59
|
* Output CSS filename. Defaults to `typestyles.css`.
|
|
49
60
|
*/
|
|
50
61
|
fileName?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Additional module that re-exports {@link getRegisteredComponentRefs} (or an
|
|
64
|
+
* equivalent object of every themeable recipe handle) so extract bundles retain
|
|
65
|
+
* full design-system CSS without a hand-maintained registry object.
|
|
66
|
+
*/
|
|
67
|
+
registeredComponentsModule?: string;
|
|
68
|
+
/**
|
|
69
|
+
* When `"allRegisteredComponents"`, appends a convention registry module if present
|
|
70
|
+
* ({@link discoverRegisteredComponentsModule}) or {@link registeredComponentsModule}
|
|
71
|
+
* when set. That file must side-effect-import every recipe and reference
|
|
72
|
+
* `getRegisteredComponentRefs(styles)` — the extract entry alone is not enough.
|
|
73
|
+
*/
|
|
74
|
+
include?: 'allRegisteredComponents';
|
|
51
75
|
}
|
|
52
76
|
/**
|
|
53
77
|
* Resolve extraction modules from explicit config or convention entry discovery.
|
|
@@ -143,7 +167,7 @@ declare function discoverNextAppRoutes(root: string, appDir?: string): NextAppRo
|
|
|
143
167
|
* Paths are relative to `root` with `/` separators.
|
|
144
168
|
*/
|
|
145
169
|
declare function traceTypestylesModules(root: string, entryFiles: string[]): Promise<string[]>;
|
|
146
|
-
/** Load a traced module for style extraction. */
|
|
170
|
+
/** Load a traced module for style extraction (cache-busted so re-runs re-register styles). */
|
|
147
171
|
declare function createModuleLoader(root: string, modulePath: string): () => Promise<unknown>;
|
|
148
172
|
|
|
149
173
|
interface CollectRouteCssOptions {
|
|
@@ -203,4 +227,4 @@ interface RunTypestylesBuildOptions {
|
|
|
203
227
|
*/
|
|
204
228
|
declare function runTypestylesBuild({ root, modules, }: RunTypestylesBuildOptions): Promise<string>;
|
|
205
229
|
|
|
206
|
-
export { type CollectRouteCssOptions, type CollectRouteCssResult, DEFAULT_EXTRACT_MODULE_CANDIDATES, type DuplicateNamespaceReporter, type GetRouteCssOptions, type NextAppRoute, type RunTypestylesBuildOptions, TYPESTYLES_IMPORT_RE, type TypestylesExtractManifest, type TypestylesExtractManifestV1, type TypestylesExtractManifestV2, type TypestylesExtractOptions, type TypestylesIntegrationMode, type TypestylesRouteCssEntry, VerifyTypestylesBuildError, type VerifyTypestylesBuildOptions, type VerifyTypestylesBuildResult, buildManifestV2, collectAndWriteRouteCss, createModuleLoader, discoverDefaultExtractModules, discoverNextAppRoutes, extractNamespaces, getRouteCss, isManifestV2, moduleNeedsOverrideHmr, normalizeRoutePath, pageRelPathToRoutePath, readCssFile, readTypestylesManifest, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild, traceTypestylesModules, verifyTypestylesBuild };
|
|
230
|
+
export { type CollectRouteCssOptions, type CollectRouteCssResult, DEFAULT_EXTRACT_MODULE_CANDIDATES, DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES, type DuplicateNamespaceReporter, type GetRouteCssOptions, type NextAppRoute, type RunTypestylesBuildOptions, TYPESTYLES_IMPORT_RE, type TypestylesExtractManifest, type TypestylesExtractManifestV1, type TypestylesExtractManifestV2, type TypestylesExtractOptions, type TypestylesIntegrationMode, type TypestylesRouteCssEntry, VerifyTypestylesBuildError, type VerifyTypestylesBuildOptions, type VerifyTypestylesBuildResult, buildManifestV2, collectAndWriteRouteCss, createModuleLoader, discoverDefaultExtractModules, discoverNextAppRoutes, discoverRegisteredComponentsModule, extractNamespaces, getRouteCss, isManifestV2, moduleNeedsOverrideHmr, normalizeRoutePath, pageRelPathToRoutePath, readCssFile, readTypestylesManifest, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild, traceTypestylesModules, verifyTypestylesBuild };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,11 +3,22 @@
|
|
|
3
3
|
* Shared by bundler integrations and `@typestyles/next/build`.
|
|
4
4
|
*/
|
|
5
5
|
declare const DEFAULT_EXTRACT_MODULE_CANDIDATES: readonly string[];
|
|
6
|
+
/**
|
|
7
|
+
* Side-effect modules that import every recipe and export `getRegisteredComponentRefs(styles)`.
|
|
8
|
+
* Used when `extract.include` is `"allRegisteredComponents"`.
|
|
9
|
+
*/
|
|
10
|
+
declare const DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES: readonly ["src/themeable-refs", "src/typestyles/themeable-refs", "src/typestyles-registry", "styles/themeable-refs"];
|
|
6
11
|
/**
|
|
7
12
|
* Resolve the default extraction module when the user did not pass explicit `modules`.
|
|
8
13
|
* Returns at most one path using `/` separators, relative to `root`.
|
|
9
14
|
*/
|
|
10
15
|
declare function discoverDefaultExtractModules(root: string): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Convention registry module for `extract.include: 'allRegisteredComponents'`.
|
|
18
|
+
* The file should import all recipe modules and
|
|
19
|
+
* export `getRegisteredComponentRefs(styles)` from your `createTypeStyles` entry.
|
|
20
|
+
*/
|
|
21
|
+
declare function discoverRegisteredComponentsModule(root: string): string | undefined;
|
|
11
22
|
|
|
12
23
|
declare const TYPESTYLES_IMPORT_RE: RegExp;
|
|
13
24
|
/**
|
|
@@ -48,6 +59,19 @@ interface TypestylesExtractOptions {
|
|
|
48
59
|
* Output CSS filename. Defaults to `typestyles.css`.
|
|
49
60
|
*/
|
|
50
61
|
fileName?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Additional module that re-exports {@link getRegisteredComponentRefs} (or an
|
|
64
|
+
* equivalent object of every themeable recipe handle) so extract bundles retain
|
|
65
|
+
* full design-system CSS without a hand-maintained registry object.
|
|
66
|
+
*/
|
|
67
|
+
registeredComponentsModule?: string;
|
|
68
|
+
/**
|
|
69
|
+
* When `"allRegisteredComponents"`, appends a convention registry module if present
|
|
70
|
+
* ({@link discoverRegisteredComponentsModule}) or {@link registeredComponentsModule}
|
|
71
|
+
* when set. That file must side-effect-import every recipe and reference
|
|
72
|
+
* `getRegisteredComponentRefs(styles)` — the extract entry alone is not enough.
|
|
73
|
+
*/
|
|
74
|
+
include?: 'allRegisteredComponents';
|
|
51
75
|
}
|
|
52
76
|
/**
|
|
53
77
|
* Resolve extraction modules from explicit config or convention entry discovery.
|
|
@@ -143,7 +167,7 @@ declare function discoverNextAppRoutes(root: string, appDir?: string): NextAppRo
|
|
|
143
167
|
* Paths are relative to `root` with `/` separators.
|
|
144
168
|
*/
|
|
145
169
|
declare function traceTypestylesModules(root: string, entryFiles: string[]): Promise<string[]>;
|
|
146
|
-
/** Load a traced module for style extraction. */
|
|
170
|
+
/** Load a traced module for style extraction (cache-busted so re-runs re-register styles). */
|
|
147
171
|
declare function createModuleLoader(root: string, modulePath: string): () => Promise<unknown>;
|
|
148
172
|
|
|
149
173
|
interface CollectRouteCssOptions {
|
|
@@ -203,4 +227,4 @@ interface RunTypestylesBuildOptions {
|
|
|
203
227
|
*/
|
|
204
228
|
declare function runTypestylesBuild({ root, modules, }: RunTypestylesBuildOptions): Promise<string>;
|
|
205
229
|
|
|
206
|
-
export { type CollectRouteCssOptions, type CollectRouteCssResult, DEFAULT_EXTRACT_MODULE_CANDIDATES, type DuplicateNamespaceReporter, type GetRouteCssOptions, type NextAppRoute, type RunTypestylesBuildOptions, TYPESTYLES_IMPORT_RE, type TypestylesExtractManifest, type TypestylesExtractManifestV1, type TypestylesExtractManifestV2, type TypestylesExtractOptions, type TypestylesIntegrationMode, type TypestylesRouteCssEntry, VerifyTypestylesBuildError, type VerifyTypestylesBuildOptions, type VerifyTypestylesBuildResult, buildManifestV2, collectAndWriteRouteCss, createModuleLoader, discoverDefaultExtractModules, discoverNextAppRoutes, extractNamespaces, getRouteCss, isManifestV2, moduleNeedsOverrideHmr, normalizeRoutePath, pageRelPathToRoutePath, readCssFile, readTypestylesManifest, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild, traceTypestylesModules, verifyTypestylesBuild };
|
|
230
|
+
export { type CollectRouteCssOptions, type CollectRouteCssResult, DEFAULT_EXTRACT_MODULE_CANDIDATES, DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES, type DuplicateNamespaceReporter, type GetRouteCssOptions, type NextAppRoute, type RunTypestylesBuildOptions, TYPESTYLES_IMPORT_RE, type TypestylesExtractManifest, type TypestylesExtractManifestV1, type TypestylesExtractManifestV2, type TypestylesExtractOptions, type TypestylesIntegrationMode, type TypestylesRouteCssEntry, VerifyTypestylesBuildError, type VerifyTypestylesBuildOptions, type VerifyTypestylesBuildResult, buildManifestV2, collectAndWriteRouteCss, createModuleLoader, discoverDefaultExtractModules, discoverNextAppRoutes, discoverRegisteredComponentsModule, extractNamespaces, getRouteCss, isManifestV2, moduleNeedsOverrideHmr, normalizeRoutePath, pageRelPathToRoutePath, readCssFile, readTypestylesManifest, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild, traceTypestylesModules, verifyTypestylesBuild };
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,12 @@ var DISCOVERY_EXTENSIONS = [".ts", ".tsx", ".js", ".mjs"];
|
|
|
13
13
|
var DEFAULT_EXTRACT_MODULE_CANDIDATES = DEFAULT_EXTRACT_MODULE_BASES.map(
|
|
14
14
|
(base) => `${base}.ts`
|
|
15
15
|
);
|
|
16
|
+
var DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES = [
|
|
17
|
+
"src/themeable-refs",
|
|
18
|
+
"src/typestyles/themeable-refs",
|
|
19
|
+
"src/typestyles-registry",
|
|
20
|
+
"styles/themeable-refs"
|
|
21
|
+
];
|
|
16
22
|
function discoverDefaultExtractModules(root) {
|
|
17
23
|
const absRoot = resolvePath(root);
|
|
18
24
|
for (const base of DEFAULT_EXTRACT_MODULE_BASES) {
|
|
@@ -25,15 +31,44 @@ function discoverDefaultExtractModules(root) {
|
|
|
25
31
|
}
|
|
26
32
|
return [];
|
|
27
33
|
}
|
|
34
|
+
function discoverRegisteredComponentsModule(root) {
|
|
35
|
+
const absRoot = resolvePath(root);
|
|
36
|
+
for (const base of DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES) {
|
|
37
|
+
for (const ext of DISCOVERY_EXTENSIONS) {
|
|
38
|
+
const rel = `${base}${ext}`;
|
|
39
|
+
if (existsSync(resolvePath(absRoot, rel))) {
|
|
40
|
+
return rel.replace(/\\/g, "/");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
28
46
|
|
|
29
47
|
// src/namespaces.ts
|
|
30
|
-
var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
|
|
31
|
-
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;
|
|
32
50
|
var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
|
|
33
|
-
var
|
|
51
|
+
var CREATE_THEME_CALL_RE = /(?:tokens\.)?createTheme\s*\(/g;
|
|
34
52
|
var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
|
|
35
|
-
var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
|
|
53
|
+
var GLOBAL_STYLE_RE = /global\.(?:rule|style)\(\s*['"]([^'"]+)['"]/g;
|
|
36
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
|
+
}
|
|
37
72
|
var OVERRIDE_HMR_EXPORT_NAMES = /* @__PURE__ */ new Set(["createDesignTheme", "overrideComponent"]);
|
|
38
73
|
var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
|
|
39
74
|
function stripCommentsForHmrScan(code) {
|
|
@@ -66,7 +101,7 @@ function collectOverrideHmrCallTargets(code) {
|
|
|
66
101
|
}
|
|
67
102
|
function moduleNeedsOverrideHmr(code) {
|
|
68
103
|
const scan = stripCommentsForHmrScan(code);
|
|
69
|
-
if (/\
|
|
104
|
+
if (/\b(?:styles\.)?override\s*\(/.test(scan)) return true;
|
|
70
105
|
const { locals, namespaces } = collectOverrideHmrCallTargets(scan);
|
|
71
106
|
for (const name of locals) {
|
|
72
107
|
if (new RegExp(`\\b${name}\\s*\\(`).test(scan)) return true;
|
|
@@ -90,8 +125,8 @@ function extractNamespaces(code) {
|
|
|
90
125
|
for (const match of code.matchAll(TOKENS_CREATE_RE)) {
|
|
91
126
|
keys.push(`tokens:${match[1]}`);
|
|
92
127
|
}
|
|
93
|
-
for (const
|
|
94
|
-
keys.push(`theme:${
|
|
128
|
+
for (const themeName of extractCreateThemeNames(code)) {
|
|
129
|
+
keys.push(`theme:${themeName}`);
|
|
95
130
|
}
|
|
96
131
|
for (const match of code.matchAll(KEYFRAMES_CREATE_RE)) {
|
|
97
132
|
keys.push(`keyframes:${match[1]}`);
|
|
@@ -120,10 +155,20 @@ function reportDuplicateNamespaces(moduleNamespaces, id, prefixes, reporter) {
|
|
|
120
155
|
|
|
121
156
|
// src/resolve-extract.ts
|
|
122
157
|
function resolveExtractModules(root, extract) {
|
|
158
|
+
let modules;
|
|
123
159
|
if (extract?.modules !== void 0) {
|
|
124
|
-
|
|
160
|
+
modules = [...extract.modules];
|
|
161
|
+
} else {
|
|
162
|
+
modules = discoverDefaultExtractModules(root);
|
|
163
|
+
}
|
|
164
|
+
let registeredModule = extract?.registeredComponentsModule;
|
|
165
|
+
if (!registeredModule && extract?.include === "allRegisteredComponents") {
|
|
166
|
+
registeredModule = discoverRegisteredComponentsModule(root);
|
|
167
|
+
}
|
|
168
|
+
if (registeredModule && !modules.includes(registeredModule)) {
|
|
169
|
+
modules.push(registeredModule);
|
|
125
170
|
}
|
|
126
|
-
return
|
|
171
|
+
return modules;
|
|
127
172
|
}
|
|
128
173
|
function resolveExtractMode(explicitMode, resolvedModules) {
|
|
129
174
|
return explicitMode ?? (resolvedModules.length > 0 ? "build" : "runtime");
|
|
@@ -421,10 +466,11 @@ async function traceTypestylesModules(root, entryFiles) {
|
|
|
421
466
|
}
|
|
422
467
|
return [...traced].sort();
|
|
423
468
|
}
|
|
469
|
+
var moduleLoadNonce = 0;
|
|
424
470
|
function createModuleLoader(root, modulePath) {
|
|
425
471
|
const abs = resolve3(root, modulePath);
|
|
426
472
|
const href = pathToFileURL(abs).href;
|
|
427
|
-
return () => import(href);
|
|
473
|
+
return () => import(`${href}?typestyles-extract=${++moduleLoadNonce}`);
|
|
428
474
|
}
|
|
429
475
|
|
|
430
476
|
// src/route-css.ts
|
|
@@ -599,6 +645,7 @@ ${result.stderr || result.stdout || "unknown error"}`
|
|
|
599
645
|
}
|
|
600
646
|
export {
|
|
601
647
|
DEFAULT_EXTRACT_MODULE_CANDIDATES,
|
|
648
|
+
DEFAULT_REGISTERED_COMPONENTS_MODULE_BASES,
|
|
602
649
|
TYPESTYLES_IMPORT_RE,
|
|
603
650
|
VerifyTypestylesBuildError,
|
|
604
651
|
buildManifestV2,
|
|
@@ -606,6 +653,7 @@ export {
|
|
|
606
653
|
createModuleLoader,
|
|
607
654
|
discoverDefaultExtractModules,
|
|
608
655
|
discoverNextAppRoutes,
|
|
656
|
+
discoverRegisteredComponentsModule,
|
|
609
657
|
extractNamespaces,
|
|
610
658
|
getRouteCss,
|
|
611
659
|
isManifestV2,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/build-runner",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.dda865821d0c",
|
|
4
4
|
"description": "Shared module execution utilities for typestyles build integrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"eslint": "^9.39.2",
|
|
30
30
|
"tsup": "^8.0.0",
|
|
31
31
|
"typescript": "^5.4.0",
|
|
32
|
-
"typestyles": "0.0.0-unstable.
|
|
32
|
+
"typestyles": "0.0.0-unstable.dda865821d0c",
|
|
33
33
|
"vitest": "^3.0.0"
|
|
34
34
|
},
|
|
35
35
|
"license": "Apache-2.0",
|