@typestyles/build-runner 0.0.0-unstable.5df620f04ca1 → 0.0.0-unstable.5e4858efecfc
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 +64 -0
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +63 -0
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
extractNamespaces: () => extractNamespaces,
|
|
32
32
|
getRouteCss: () => getRouteCss,
|
|
33
33
|
isManifestV2: () => isManifestV2,
|
|
34
|
+
moduleNeedsOverrideHmr: () => moduleNeedsOverrideHmr,
|
|
34
35
|
normalizeRoutePath: () => normalizeRoutePath,
|
|
35
36
|
pageRelPathToRoutePath: () => pageRelPathToRoutePath,
|
|
36
37
|
readCssFile: () => readCssFile,
|
|
@@ -80,7 +81,50 @@ var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
|
|
|
80
81
|
var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
|
|
81
82
|
var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
|
|
82
83
|
var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
|
|
84
|
+
var OVERRIDE_HMR_EXPORT_NAMES = /* @__PURE__ */ new Set(["createDesignTheme", "overrideComponent"]);
|
|
83
85
|
var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
|
|
86
|
+
function stripCommentsForHmrScan(code) {
|
|
87
|
+
return code.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1");
|
|
88
|
+
}
|
|
89
|
+
function collectOverrideHmrCallTargets(code) {
|
|
90
|
+
const locals = new Set(OVERRIDE_HMR_EXPORT_NAMES);
|
|
91
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
92
|
+
for (const match of code.matchAll(/import\s*{([^}]+)}\s*from\s*['"][^'"]+['"]/g)) {
|
|
93
|
+
for (const rawPart of match[1].split(",")) {
|
|
94
|
+
const part = rawPart.trim();
|
|
95
|
+
if (!part || part.startsWith("type ")) continue;
|
|
96
|
+
const asMatch = part.match(/^(\w+)\s+as\s+(\w+)$/);
|
|
97
|
+
if (asMatch) {
|
|
98
|
+
if (OVERRIDE_HMR_EXPORT_NAMES.has(asMatch[1])) {
|
|
99
|
+
locals.add(asMatch[2]);
|
|
100
|
+
}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const name = part.match(/^(\w+)$/)?.[1];
|
|
104
|
+
if (name && OVERRIDE_HMR_EXPORT_NAMES.has(name)) {
|
|
105
|
+
locals.add(name);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (const match of code.matchAll(/import\s*\*\s*as\s+(\w+)\s*from\s*['"][^'"]+['"]/g)) {
|
|
110
|
+
namespaces.add(match[1]);
|
|
111
|
+
}
|
|
112
|
+
return { locals, namespaces };
|
|
113
|
+
}
|
|
114
|
+
function moduleNeedsOverrideHmr(code) {
|
|
115
|
+
const scan = stripCommentsForHmrScan(code);
|
|
116
|
+
if (/\bstyles\.override\s*\(/.test(scan)) return true;
|
|
117
|
+
const { locals, namespaces } = collectOverrideHmrCallTargets(scan);
|
|
118
|
+
for (const name of locals) {
|
|
119
|
+
if (new RegExp(`\\b${name}\\s*\\(`).test(scan)) return true;
|
|
120
|
+
}
|
|
121
|
+
for (const ns of namespaces) {
|
|
122
|
+
if (new RegExp(`\\b${ns}\\.(?:createDesignTheme|overrideComponent)\\s*\\(`).test(scan)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
84
128
|
function extractNamespaces(code) {
|
|
85
129
|
const keys = [];
|
|
86
130
|
const prefixes = [];
|
|
@@ -540,6 +584,25 @@ async function runTypestylesBuild({
|
|
|
540
584
|
format: "cjs",
|
|
541
585
|
target: "node18",
|
|
542
586
|
external: ["typestyles"],
|
|
587
|
+
// Style registration calls (styles.component/class, createTypeStyles) are
|
|
588
|
+
// side-effect-only: the CSS they register into the global registry is the
|
|
589
|
+
// point, regardless of whether the returned classname function is ever
|
|
590
|
+
// read. esbuild's default tree shaking doesn't know that, so any
|
|
591
|
+
// consumer module reached only through an unread namespace/barrel import
|
|
592
|
+
// (or a package marked "sideEffects": false) can have its registration
|
|
593
|
+
// calls silently dropped as "unused". Disable tree shaking here so every
|
|
594
|
+
// registration in the extraction graph survives.
|
|
595
|
+
treeShaking: false,
|
|
596
|
+
// `treeShaking: false` only stops esbuild from pruning declarations
|
|
597
|
+
// *within* an already-included module. It's a separate esbuild behavior
|
|
598
|
+
// by the treeShaking option — that drops a plain bare import entirely
|
|
599
|
+
// (`import './some-lib'` with no binding at all) when it resolves to a
|
|
600
|
+
// module/package marked "sideEffects": false, before that module is ever
|
|
601
|
+
// considered for inclusion. A real extraction entry is exactly this
|
|
602
|
+
// shape: several side-effect-only imports, any one of which may point at
|
|
603
|
+
// a (correctly) tree-shakeable component library. Ignore both kinds of
|
|
604
|
+
// annotation so every import in the extraction graph is included.
|
|
605
|
+
ignoreAnnotations: true,
|
|
543
606
|
stdin: {
|
|
544
607
|
contents: importLines,
|
|
545
608
|
resolveDir: root,
|
|
@@ -594,6 +657,7 @@ ${result.stderr || result.stdout || "unknown error"}`
|
|
|
594
657
|
extractNamespaces,
|
|
595
658
|
getRouteCss,
|
|
596
659
|
isManifestV2,
|
|
660
|
+
moduleNeedsOverrideHmr,
|
|
597
661
|
normalizeRoutePath,
|
|
598
662
|
pageRelPathToRoutePath,
|
|
599
663
|
readCssFile,
|
package/dist/index.d.cts
CHANGED
|
@@ -10,6 +10,15 @@ declare const DEFAULT_EXTRACT_MODULE_CANDIDATES: readonly string[];
|
|
|
10
10
|
declare function discoverDefaultExtractModules(root: string): string[];
|
|
11
11
|
|
|
12
12
|
declare const TYPESTYLES_IMPORT_RE: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* True when this module may register `styles.override` rules and needs Vite HMR
|
|
15
|
+
* dispose tracking — including Var UI sugar (`createDesignTheme` / `overrideComponent`)
|
|
16
|
+
* that never spells `styles.override` in source.
|
|
17
|
+
*
|
|
18
|
+
* Detects renamed imports (`createDesignTheme as cdt`) and namespace imports
|
|
19
|
+
* (`Core.createDesignTheme(`), not only the canonical identifier spelling.
|
|
20
|
+
*/
|
|
21
|
+
declare function moduleNeedsOverrideHmr(code: string): boolean;
|
|
13
22
|
/**
|
|
14
23
|
* Extract namespace information from source code for invalidation and duplicate checks.
|
|
15
24
|
*/
|
|
@@ -194,4 +203,4 @@ interface RunTypestylesBuildOptions {
|
|
|
194
203
|
*/
|
|
195
204
|
declare function runTypestylesBuild({ root, modules, }: RunTypestylesBuildOptions): Promise<string>;
|
|
196
205
|
|
|
197
|
-
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, normalizeRoutePath, pageRelPathToRoutePath, readCssFile, readTypestylesManifest, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild, traceTypestylesModules, verifyTypestylesBuild };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,15 @@ declare const DEFAULT_EXTRACT_MODULE_CANDIDATES: readonly string[];
|
|
|
10
10
|
declare function discoverDefaultExtractModules(root: string): string[];
|
|
11
11
|
|
|
12
12
|
declare const TYPESTYLES_IMPORT_RE: RegExp;
|
|
13
|
+
/**
|
|
14
|
+
* True when this module may register `styles.override` rules and needs Vite HMR
|
|
15
|
+
* dispose tracking — including Var UI sugar (`createDesignTheme` / `overrideComponent`)
|
|
16
|
+
* that never spells `styles.override` in source.
|
|
17
|
+
*
|
|
18
|
+
* Detects renamed imports (`createDesignTheme as cdt`) and namespace imports
|
|
19
|
+
* (`Core.createDesignTheme(`), not only the canonical identifier spelling.
|
|
20
|
+
*/
|
|
21
|
+
declare function moduleNeedsOverrideHmr(code: string): boolean;
|
|
13
22
|
/**
|
|
14
23
|
* Extract namespace information from source code for invalidation and duplicate checks.
|
|
15
24
|
*/
|
|
@@ -194,4 +203,4 @@ interface RunTypestylesBuildOptions {
|
|
|
194
203
|
*/
|
|
195
204
|
declare function runTypestylesBuild({ root, modules, }: RunTypestylesBuildOptions): Promise<string>;
|
|
196
205
|
|
|
197
|
-
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, normalizeRoutePath, pageRelPathToRoutePath, readCssFile, readTypestylesManifest, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesBuild, traceTypestylesModules, verifyTypestylesBuild };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,50 @@ var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
|
|
|
34
34
|
var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
|
|
35
35
|
var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
|
|
36
36
|
var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
|
|
37
|
+
var OVERRIDE_HMR_EXPORT_NAMES = /* @__PURE__ */ new Set(["createDesignTheme", "overrideComponent"]);
|
|
37
38
|
var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
|
|
39
|
+
function stripCommentsForHmrScan(code) {
|
|
40
|
+
return code.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1");
|
|
41
|
+
}
|
|
42
|
+
function collectOverrideHmrCallTargets(code) {
|
|
43
|
+
const locals = new Set(OVERRIDE_HMR_EXPORT_NAMES);
|
|
44
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const match of code.matchAll(/import\s*{([^}]+)}\s*from\s*['"][^'"]+['"]/g)) {
|
|
46
|
+
for (const rawPart of match[1].split(",")) {
|
|
47
|
+
const part = rawPart.trim();
|
|
48
|
+
if (!part || part.startsWith("type ")) continue;
|
|
49
|
+
const asMatch = part.match(/^(\w+)\s+as\s+(\w+)$/);
|
|
50
|
+
if (asMatch) {
|
|
51
|
+
if (OVERRIDE_HMR_EXPORT_NAMES.has(asMatch[1])) {
|
|
52
|
+
locals.add(asMatch[2]);
|
|
53
|
+
}
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const name = part.match(/^(\w+)$/)?.[1];
|
|
57
|
+
if (name && OVERRIDE_HMR_EXPORT_NAMES.has(name)) {
|
|
58
|
+
locals.add(name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const match of code.matchAll(/import\s*\*\s*as\s+(\w+)\s*from\s*['"][^'"]+['"]/g)) {
|
|
63
|
+
namespaces.add(match[1]);
|
|
64
|
+
}
|
|
65
|
+
return { locals, namespaces };
|
|
66
|
+
}
|
|
67
|
+
function moduleNeedsOverrideHmr(code) {
|
|
68
|
+
const scan = stripCommentsForHmrScan(code);
|
|
69
|
+
if (/\bstyles\.override\s*\(/.test(scan)) return true;
|
|
70
|
+
const { locals, namespaces } = collectOverrideHmrCallTargets(scan);
|
|
71
|
+
for (const name of locals) {
|
|
72
|
+
if (new RegExp(`\\b${name}\\s*\\(`).test(scan)) return true;
|
|
73
|
+
}
|
|
74
|
+
for (const ns of namespaces) {
|
|
75
|
+
if (new RegExp(`\\b${ns}\\.(?:createDesignTheme|overrideComponent)\\s*\\(`).test(scan)) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
38
81
|
function extractNamespaces(code) {
|
|
39
82
|
const keys = [];
|
|
40
83
|
const prefixes = [];
|
|
@@ -494,6 +537,25 @@ async function runTypestylesBuild({
|
|
|
494
537
|
format: "cjs",
|
|
495
538
|
target: "node18",
|
|
496
539
|
external: ["typestyles"],
|
|
540
|
+
// Style registration calls (styles.component/class, createTypeStyles) are
|
|
541
|
+
// side-effect-only: the CSS they register into the global registry is the
|
|
542
|
+
// point, regardless of whether the returned classname function is ever
|
|
543
|
+
// read. esbuild's default tree shaking doesn't know that, so any
|
|
544
|
+
// consumer module reached only through an unread namespace/barrel import
|
|
545
|
+
// (or a package marked "sideEffects": false) can have its registration
|
|
546
|
+
// calls silently dropped as "unused". Disable tree shaking here so every
|
|
547
|
+
// registration in the extraction graph survives.
|
|
548
|
+
treeShaking: false,
|
|
549
|
+
// `treeShaking: false` only stops esbuild from pruning declarations
|
|
550
|
+
// *within* an already-included module. It's a separate esbuild behavior
|
|
551
|
+
// by the treeShaking option — that drops a plain bare import entirely
|
|
552
|
+
// (`import './some-lib'` with no binding at all) when it resolves to a
|
|
553
|
+
// module/package marked "sideEffects": false, before that module is ever
|
|
554
|
+
// considered for inclusion. A real extraction entry is exactly this
|
|
555
|
+
// shape: several side-effect-only imports, any one of which may point at
|
|
556
|
+
// a (correctly) tree-shakeable component library. Ignore both kinds of
|
|
557
|
+
// annotation so every import in the extraction graph is included.
|
|
558
|
+
ignoreAnnotations: true,
|
|
497
559
|
stdin: {
|
|
498
560
|
contents: importLines,
|
|
499
561
|
resolveDir: root,
|
|
@@ -547,6 +609,7 @@ export {
|
|
|
547
609
|
extractNamespaces,
|
|
548
610
|
getRouteCss,
|
|
549
611
|
isManifestV2,
|
|
612
|
+
moduleNeedsOverrideHmr,
|
|
550
613
|
normalizeRoutePath,
|
|
551
614
|
pageRelPathToRoutePath,
|
|
552
615
|
readCssFile,
|
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.5e4858efecfc",
|
|
4
4
|
"description": "Shared module execution utilities for typestyles build integrations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -29,6 +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.5e4858efecfc",
|
|
32
33
|
"vitest": "^3.0.0"
|
|
33
34
|
},
|
|
34
35
|
"license": "Apache-2.0",
|