tailwind-styled-v4 5.0.8 → 5.0.10
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/CHANGELOG.md +204 -416
- package/README.md +45 -15
- package/dist/{analyzeWorkspace-DuJKh7Ty.d.mts → analyzeWorkspace-BS5O4rhC.d.mts} +47 -2
- package/dist/{analyzeWorkspace-Ct_NTAWt.d.ts → analyzeWorkspace-DDOQdzzI.d.ts} +47 -2
- package/dist/analyzer.d.mts +5 -3
- package/dist/analyzer.d.ts +5 -3
- package/dist/analyzer.js +563 -468
- package/dist/analyzer.js.map +1 -1
- package/dist/analyzer.mjs +562 -467
- package/dist/analyzer.mjs.map +1 -1
- package/dist/animate.d.mts +4 -7
- package/dist/animate.d.ts +4 -7
- package/dist/animate.js +171 -265
- package/dist/animate.js.map +1 -1
- package/dist/animate.mjs +165 -264
- package/dist/animate.mjs.map +1 -1
- package/dist/atomic.d.mts +22 -1
- package/dist/atomic.d.ts +22 -1
- package/dist/atomic.js +221 -165
- package/dist/atomic.js.map +1 -1
- package/dist/atomic.mjs +200 -165
- package/dist/atomic.mjs.map +1 -1
- package/dist/cli.d.mts +60 -1
- package/dist/cli.d.ts +60 -1
- package/dist/cli.js +1261 -1517
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1238 -1513
- package/dist/cli.mjs.map +1 -1
- package/dist/compiler.d.mts +38 -7
- package/dist/compiler.d.ts +38 -7
- package/dist/compiler.js +174 -197
- package/dist/compiler.js.map +1 -1
- package/dist/compiler.mjs +151 -194
- package/dist/compiler.mjs.map +1 -1
- package/dist/devtools.js +7 -31
- package/dist/devtools.js.map +1 -1
- package/dist/devtools.mjs +7 -31
- package/dist/devtools.mjs.map +1 -1
- package/dist/engine.d.mts +134 -63
- package/dist/engine.d.ts +134 -63
- package/dist/engine.js +2863 -2482
- package/dist/engine.js.map +1 -1
- package/dist/engine.mjs +2852 -2485
- package/dist/engine.mjs.map +1 -1
- package/dist/{index-eWAocnD2.d.mts → index-NDINUhLN.d.mts} +3 -1
- package/dist/{index-eWAocnD2.d.ts → index-NDINUhLN.d.ts} +3 -1
- package/dist/index.d.mts +63 -32
- package/dist/index.d.ts +63 -32
- package/dist/index.js +335 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +315 -169
- package/dist/index.mjs.map +1 -1
- package/dist/{liveTokenEngine-DSUk88P6.d.ts → liveTokenEngine-CN9ian1R.d.ts} +1 -1
- package/dist/{liveTokenEngine-CX5_0c4q.d.mts → liveTokenEngine-DKoWRtqH.d.mts} +1 -1
- package/dist/next.d.mts +10 -4
- package/dist/next.d.ts +10 -4
- package/dist/next.js +32 -45
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +30 -43
- package/dist/next.mjs.map +1 -1
- package/dist/plugin-api.d.mts +8 -2
- package/dist/plugin-api.d.ts +8 -2
- package/dist/plugin-api.js +14 -2
- package/dist/plugin-api.js.map +1 -1
- package/dist/plugin-api.mjs +14 -3
- package/dist/plugin-api.mjs.map +1 -1
- package/dist/plugin-registry.js +51 -11
- package/dist/plugin-registry.js.map +1 -1
- package/dist/plugin-registry.mjs +51 -11
- package/dist/plugin-registry.mjs.map +1 -1
- package/dist/plugin.d.mts +5 -7
- package/dist/plugin.d.ts +5 -7
- package/dist/plugin.js +16 -15
- package/dist/plugin.js.map +1 -1
- package/dist/plugin.mjs +16 -16
- package/dist/plugin.mjs.map +1 -1
- package/dist/rspack.js +17 -38
- package/dist/rspack.js.map +1 -1
- package/dist/rspack.mjs +15 -36
- package/dist/rspack.mjs.map +1 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.d.ts +2 -2
- package/dist/scanner.d.mts +10 -1
- package/dist/scanner.d.ts +10 -1
- package/dist/scanner.js +298 -124
- package/dist/scanner.js.map +1 -1
- package/dist/scanner.mjs +296 -124
- package/dist/scanner.mjs.map +1 -1
- package/dist/shared.d.mts +1 -1
- package/dist/shared.d.ts +1 -1
- package/dist/shared.js +104 -176
- package/dist/shared.js.map +1 -1
- package/dist/shared.mjs +85 -176
- package/dist/shared.mjs.map +1 -1
- package/dist/storybook-addon.d.mts +1 -1
- package/dist/storybook-addon.d.ts +1 -1
- package/dist/svelte.d.mts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +166 -3
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +143 -1
- package/dist/svelte.mjs.map +1 -1
- package/dist/syntax.js +21 -21
- package/dist/syntax.js.map +1 -1
- package/dist/syntax.mjs +21 -21
- package/dist/syntax.mjs.map +1 -1
- package/dist/testing.js +9 -1
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +9 -1
- package/dist/testing.mjs.map +1 -1
- package/dist/theme.d.mts +2 -2
- package/dist/theme.d.ts +2 -2
- package/dist/theme.js +40 -112
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +37 -110
- package/dist/theme.mjs.map +1 -1
- package/dist/turbopackLoader.js +84 -126
- package/dist/turbopackLoader.js.map +1 -1
- package/dist/turbopackLoader.mjs +68 -124
- package/dist/turbopackLoader.mjs.map +1 -1
- package/dist/tw.js +1256 -1517
- package/dist/tw.js.map +1 -1
- package/dist/tw.mjs +1236 -1513
- package/dist/tw.mjs.map +1 -1
- package/dist/vite.js +1783 -823
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +1767 -821
- package/dist/vite.mjs.map +1 -1
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +165 -4
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +141 -1
- package/dist/vue.mjs.map +1 -1
- package/dist/webpackLoader.js +69 -108
- package/dist/webpackLoader.js.map +1 -1
- package/dist/webpackLoader.mjs +49 -104
- package/dist/webpackLoader.mjs.map +1 -1
- package/native/tailwind-styled-native.node +0 -0
- package/package.json +22 -24
package/dist/vite.js
CHANGED
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var zod = require('zod');
|
|
3
4
|
var module$1 = require('module');
|
|
4
|
-
var
|
|
5
|
+
var fs4 = require('fs');
|
|
6
|
+
var path6 = require('path');
|
|
7
|
+
var crypto = require('crypto');
|
|
5
8
|
var url = require('url');
|
|
6
|
-
var fs = require('fs');
|
|
7
9
|
var worker_threads = require('worker_threads');
|
|
8
|
-
var
|
|
10
|
+
var os = require('os');
|
|
9
11
|
require('perf_hooks');
|
|
10
12
|
|
|
11
13
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
12
|
-
function
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
13
31
|
|
|
14
|
-
var
|
|
15
|
-
var
|
|
32
|
+
var fs4__namespace = /*#__PURE__*/_interopNamespace(fs4);
|
|
33
|
+
var path6__namespace = /*#__PURE__*/_interopNamespace(path6);
|
|
16
34
|
|
|
17
35
|
/* tailwind-styled-v4 v5.0.4 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
|
|
18
36
|
var __defProp = Object.defineProperty;
|
|
@@ -42,6 +60,260 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
42
60
|
};
|
|
43
61
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
44
62
|
|
|
63
|
+
// packages/domain/shared/src/trace.ts
|
|
64
|
+
function getHealthColor(status) {
|
|
65
|
+
switch (status) {
|
|
66
|
+
case "healthy":
|
|
67
|
+
return "#34d399";
|
|
68
|
+
case "degraded":
|
|
69
|
+
return "#fbbf24";
|
|
70
|
+
case "unhealthy":
|
|
71
|
+
return "#f87171";
|
|
72
|
+
default:
|
|
73
|
+
return "#52525b";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function getModeColor(mode) {
|
|
77
|
+
switch (mode) {
|
|
78
|
+
case "build":
|
|
79
|
+
return "#fbbf24";
|
|
80
|
+
case "watch":
|
|
81
|
+
return "#34d399";
|
|
82
|
+
case "jit":
|
|
83
|
+
return "#60a5fa";
|
|
84
|
+
case "error":
|
|
85
|
+
return "#f87171";
|
|
86
|
+
case "idle":
|
|
87
|
+
return "#71717a";
|
|
88
|
+
default:
|
|
89
|
+
return "#52525b";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function formatMemory(bytes) {
|
|
93
|
+
if (bytes < 1024) return `${Math.round(bytes)}B`;
|
|
94
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
95
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
96
|
+
}
|
|
97
|
+
function formatDuration(ms) {
|
|
98
|
+
if (ms === null) return "\u2014";
|
|
99
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
100
|
+
return `${(ms / 1e3).toFixed(1)}s`;
|
|
101
|
+
}
|
|
102
|
+
function calculateHealth(metrics, summary) {
|
|
103
|
+
if (summary?.health?.status) return summary.health.status;
|
|
104
|
+
if (metrics.mode === "error") return "unhealthy";
|
|
105
|
+
if ((metrics.buildMs ?? 0) > 5e3) return "degraded";
|
|
106
|
+
if (metrics.memoryMb && metrics.memoryMb.heapUsed > 500) return "degraded";
|
|
107
|
+
return "healthy";
|
|
108
|
+
}
|
|
109
|
+
function getBuildTimeColor(ms) {
|
|
110
|
+
if (ms === null) return "#52525b";
|
|
111
|
+
if (ms > 1e3) return "#f87171";
|
|
112
|
+
if (ms > 500) return "#fbbf24";
|
|
113
|
+
return "#34d399";
|
|
114
|
+
}
|
|
115
|
+
function getMemoryColor(mb) {
|
|
116
|
+
if (mb > 500) return "#f87171";
|
|
117
|
+
if (mb > 250) return "#fbbf24";
|
|
118
|
+
return "#34d399";
|
|
119
|
+
}
|
|
120
|
+
function createTraceSnapshot(data) {
|
|
121
|
+
return {
|
|
122
|
+
generatedAt: data.generatedAt || (/* @__PURE__ */ new Date()).toISOString(),
|
|
123
|
+
buildMs: data.buildMs ?? null,
|
|
124
|
+
scanMs: data.scanMs ?? null,
|
|
125
|
+
analyzeMs: data.analyzeMs ?? null,
|
|
126
|
+
compileMs: data.compileMs ?? null,
|
|
127
|
+
memoryMb: data.memoryMb ?? null,
|
|
128
|
+
classCount: data.classCount ?? null,
|
|
129
|
+
fileCount: data.fileCount ?? null,
|
|
130
|
+
cssBytes: data.cssBytes ?? null,
|
|
131
|
+
mode: data.mode ?? null,
|
|
132
|
+
eventsReceived: data.eventsReceived ?? void 0,
|
|
133
|
+
eventsProcessed: data.eventsProcessed ?? void 0,
|
|
134
|
+
batchesProcessed: data.batchesProcessed ?? void 0,
|
|
135
|
+
incrementalUpdates: data.incrementalUpdates ?? void 0,
|
|
136
|
+
fullRescans: data.fullRescans ?? void 0
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function getPipelinePercentages(metrics) {
|
|
140
|
+
const scan = metrics.scanMs ?? 0;
|
|
141
|
+
const analyze = metrics.analyzeMs ?? 0;
|
|
142
|
+
const compile = metrics.compileMs ?? 0;
|
|
143
|
+
const total = scan + analyze + compile;
|
|
144
|
+
if (total === 0) {
|
|
145
|
+
return { scanPct: 0, analyzePct: 0, compilePct: 0 };
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
scanPct: scan / total * 100,
|
|
149
|
+
analyzePct: analyze / total * 100,
|
|
150
|
+
compilePct: compile / total * 100
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
var init_trace = __esm({
|
|
154
|
+
"packages/domain/shared/src/trace.ts"() {
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// packages/domain/shared/src/error-codes.ts
|
|
159
|
+
function getSuggestion(code) {
|
|
160
|
+
return ERROR_SUGGESTIONS[code];
|
|
161
|
+
}
|
|
162
|
+
function formatErrorCode(code) {
|
|
163
|
+
const prefix = code.startsWith("E") ? "Error" : code.startsWith("W") ? "Warning" : "Code";
|
|
164
|
+
return `[${prefix} ${code}]`;
|
|
165
|
+
}
|
|
166
|
+
var ERROR_CODES, ERROR_SUGGESTIONS;
|
|
167
|
+
var init_error_codes = __esm({
|
|
168
|
+
"packages/domain/shared/src/error-codes.ts"() {
|
|
169
|
+
ERROR_CODES = {
|
|
170
|
+
// E0xx — Native binding
|
|
171
|
+
NATIVE_NOT_FOUND: "E001",
|
|
172
|
+
NATIVE_LOAD_FAILED: "E002",
|
|
173
|
+
NATIVE_VERSION_MISMATCH: "E003",
|
|
174
|
+
SCANNER_NATIVE_NOT_FOUND: "E004",
|
|
175
|
+
SCANNER_HASH_FAILED: "E005",
|
|
176
|
+
NATIVE_TRANSFORM_UNAVAILABLE: "E006",
|
|
177
|
+
// E2xx — Compilation
|
|
178
|
+
MISSING_REACT_IMPORT: "E201",
|
|
179
|
+
UNSUPPORTED_PATTERN: "E202",
|
|
180
|
+
TEMPLATE_PARSE_ERROR: "E203",
|
|
181
|
+
COMPILE_TIMEOUT: "E204",
|
|
182
|
+
// E3xx — Compatibility
|
|
183
|
+
TAILWIND_VERSION_UNSUPPORTED: "E301",
|
|
184
|
+
NODE_VERSION_UNSUPPORTED: "E302",
|
|
185
|
+
// E4xx — Cache
|
|
186
|
+
CACHE_READ_FAILED: "E401",
|
|
187
|
+
CACHE_WRITE_FAILED: "E402",
|
|
188
|
+
CACHE_CORRUPTED: "E403",
|
|
189
|
+
// E5xx — RSC
|
|
190
|
+
RSC_BOUNDARY_CONFLICT: "E501",
|
|
191
|
+
// W1xx — Warnings
|
|
192
|
+
DYNAMIC_CONTENT: "W101",
|
|
193
|
+
INVALID_VARIANT_VALUE: "W201",
|
|
194
|
+
DEPRECATED_MODE: "W301"
|
|
195
|
+
};
|
|
196
|
+
ERROR_SUGGESTIONS = {
|
|
197
|
+
E001: "Run: npm install @tailwind-styled/native-{platform} or build from source",
|
|
198
|
+
E002: "Try: npm rebuild or reinstall the package",
|
|
199
|
+
E003: "Run: npm install tailwind-styled-v4@latest to sync versions",
|
|
200
|
+
E004: "Run: npm install @tailwind-styled/scanner",
|
|
201
|
+
E006: "Run: npm install @tailwind-styled/compiler",
|
|
202
|
+
E301: "Upgrade: npm install tailwindcss@^4"
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// packages/domain/shared/src/compatibility.ts
|
|
208
|
+
function detectTailwind() {
|
|
209
|
+
try {
|
|
210
|
+
const pkgPath = __require.resolve("tailwindcss/package.json");
|
|
211
|
+
const { version } = __require(pkgPath);
|
|
212
|
+
const major = Number.parseInt(version.split(".")[0], 10);
|
|
213
|
+
return { version, major, supported: major >= 4, path: pkgPath };
|
|
214
|
+
} catch {
|
|
215
|
+
return { version: "not-installed", major: 0, supported: false, path: null };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function assertTailwindV4() {
|
|
219
|
+
const info = detectTailwind();
|
|
220
|
+
if (!info.supported) {
|
|
221
|
+
const message = info.major === 0 ? "tailwindcss is not installed. Run: npm install tailwindcss@^4" : `tailwind-styled-v4 requires Tailwind CSS v4.x. Found: v${info.version}. Upgrade: npm install tailwindcss@^4`;
|
|
222
|
+
if (process.env.NODE_ENV !== "production") {
|
|
223
|
+
console.warn(`[tailwind-styled] ${message}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function getTailwindVersion() {
|
|
228
|
+
return detectTailwind().version;
|
|
229
|
+
}
|
|
230
|
+
function isTailwindV4() {
|
|
231
|
+
return detectTailwind().supported;
|
|
232
|
+
}
|
|
233
|
+
var init_compatibility = __esm({
|
|
234
|
+
"packages/domain/shared/src/compatibility.ts"() {
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
function safeParseNative(schema, data, fallback) {
|
|
238
|
+
const result = schema.safeParse(data);
|
|
239
|
+
return result.success ? result.data : fallback;
|
|
240
|
+
}
|
|
241
|
+
function parseNative(schema, data, context) {
|
|
242
|
+
const result = schema.safeParse(data);
|
|
243
|
+
if (!result.success) {
|
|
244
|
+
const first = result.error.issues[0];
|
|
245
|
+
const path13 = first?.path?.join(".") ?? "(root)";
|
|
246
|
+
throw new Error(
|
|
247
|
+
`[${context}] Native binding returned unexpected data: ${path13}: ${first?.message ?? "validation failed"}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return result.data;
|
|
251
|
+
}
|
|
252
|
+
var NativeScanFileSchema, NativeScanResultSchema, NativeClassUsageSchema, NativeAnalyzerReportSchema, NativeTransformResultSchema, NativeCssCompileResultSchema, NativeWatchResultSchema, NativeCacheEntrySchema, NativeCacheReadResultSchema;
|
|
253
|
+
var init_native_schemas = __esm({
|
|
254
|
+
"packages/domain/shared/src/native-schemas.ts"() {
|
|
255
|
+
NativeScanFileSchema = zod.z.object({
|
|
256
|
+
file: zod.z.string().min(1, "file path cannot be empty"),
|
|
257
|
+
classes: zod.z.array(zod.z.string()),
|
|
258
|
+
hash: zod.z.string().optional()
|
|
259
|
+
});
|
|
260
|
+
NativeScanResultSchema = zod.z.object({
|
|
261
|
+
files: zod.z.array(NativeScanFileSchema),
|
|
262
|
+
totalFiles: zod.z.number().int().nonnegative(),
|
|
263
|
+
uniqueClasses: zod.z.array(zod.z.string())
|
|
264
|
+
});
|
|
265
|
+
NativeClassUsageSchema = zod.z.object({
|
|
266
|
+
name: zod.z.string(),
|
|
267
|
+
count: zod.z.number().int().nonnegative(),
|
|
268
|
+
files: zod.z.array(zod.z.string()).optional()
|
|
269
|
+
});
|
|
270
|
+
NativeAnalyzerReportSchema = zod.z.object({
|
|
271
|
+
root: zod.z.string(),
|
|
272
|
+
topClasses: zod.z.array(NativeClassUsageSchema).optional(),
|
|
273
|
+
safelist: zod.z.array(zod.z.string()).optional(),
|
|
274
|
+
css: zod.z.string().optional(),
|
|
275
|
+
conflicts: zod.z.array(zod.z.unknown()).optional(),
|
|
276
|
+
unusedClasses: zod.z.array(zod.z.string()).optional(),
|
|
277
|
+
durationMs: zod.z.number().nonnegative().optional()
|
|
278
|
+
});
|
|
279
|
+
NativeTransformResultSchema = zod.z.object({
|
|
280
|
+
code: zod.z.string(),
|
|
281
|
+
classes: zod.z.array(zod.z.string()),
|
|
282
|
+
changed: zod.z.boolean(),
|
|
283
|
+
rsc: zod.z.object({
|
|
284
|
+
isServer: zod.z.boolean(),
|
|
285
|
+
needsClientDirective: zod.z.boolean(),
|
|
286
|
+
clientReasons: zod.z.array(zod.z.string())
|
|
287
|
+
}).optional()
|
|
288
|
+
});
|
|
289
|
+
NativeCssCompileResultSchema = zod.z.object({
|
|
290
|
+
css: zod.z.string(),
|
|
291
|
+
resolvedClasses: zod.z.array(zod.z.string()),
|
|
292
|
+
unresolvedClasses: zod.z.array(zod.z.string()).optional()
|
|
293
|
+
});
|
|
294
|
+
zod.z.object({
|
|
295
|
+
type: zod.z.enum(["change", "unlink", "create"]),
|
|
296
|
+
path: zod.z.string()
|
|
297
|
+
});
|
|
298
|
+
NativeWatchResultSchema = zod.z.object({
|
|
299
|
+
status: zod.z.enum(["ok", "error"]),
|
|
300
|
+
handleId: zod.z.string().optional(),
|
|
301
|
+
error: zod.z.string().optional()
|
|
302
|
+
});
|
|
303
|
+
NativeCacheEntrySchema = zod.z.object({
|
|
304
|
+
file: zod.z.string(),
|
|
305
|
+
hash: zod.z.string(),
|
|
306
|
+
classes: zod.z.array(zod.z.string()),
|
|
307
|
+
timestamp: zod.z.number(),
|
|
308
|
+
size: zod.z.number().optional()
|
|
309
|
+
});
|
|
310
|
+
NativeCacheReadResultSchema = zod.z.object({
|
|
311
|
+
entries: zod.z.array(NativeCacheEntrySchema),
|
|
312
|
+
version: zod.z.string().optional()
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
45
317
|
// packages/domain/shared/src/esmHelpers.ts
|
|
46
318
|
function getNodeModuleRef() {
|
|
47
319
|
if (isBrowser) return null;
|
|
@@ -69,88 +341,551 @@ function getNodeUrl() {
|
|
|
69
341
|
if (!_nodeUrl) _nodeUrl = nodeRequire.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)))("node:url");
|
|
70
342
|
return _nodeUrl;
|
|
71
343
|
}
|
|
344
|
+
function getNodeFs() {
|
|
345
|
+
if (isBrowser) throw new Error("node:fs not available in browser");
|
|
346
|
+
const nodeRequire = getNodeModuleRef();
|
|
347
|
+
if (!nodeRequire) throw new Error("require not available");
|
|
348
|
+
if (!_nodeFs) _nodeFs = nodeRequire.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)))("node:fs");
|
|
349
|
+
return _nodeFs;
|
|
350
|
+
}
|
|
351
|
+
function createEsmRequire(importMetaUrl) {
|
|
352
|
+
if (isBrowser) throw new Error("require not available in browser");
|
|
353
|
+
const nodeRequire = getNodeModuleRef();
|
|
354
|
+
if (!nodeRequire) throw new Error("require not available");
|
|
355
|
+
return nodeRequire.createRequire(importMetaUrl);
|
|
356
|
+
}
|
|
72
357
|
function getDirname(importMetaUrl) {
|
|
73
358
|
if (isBrowser) return "";
|
|
74
359
|
const nodePath = getNodePath();
|
|
75
360
|
const nodeUrl = getNodeUrl();
|
|
76
361
|
return nodePath.dirname(nodeUrl.fileURLToPath(importMetaUrl));
|
|
77
362
|
}
|
|
78
|
-
|
|
363
|
+
function getFilename(importMetaUrl) {
|
|
364
|
+
if (isBrowser) return "";
|
|
365
|
+
return getNodeUrl().fileURLToPath(importMetaUrl);
|
|
366
|
+
}
|
|
367
|
+
function resolveFromRoot(...segments) {
|
|
368
|
+
if (isBrowser) return segments.join("/");
|
|
369
|
+
const nodePath = getNodePath();
|
|
370
|
+
const nodeFs = getNodeFs();
|
|
371
|
+
let dir = getDirname((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
372
|
+
for (let i = 0; i < 10; i++) {
|
|
373
|
+
const pkgPath = nodePath.join(dir, "package.json");
|
|
374
|
+
try {
|
|
375
|
+
const pkg = JSON.parse(nodeFs.readFileSync(pkgPath, "utf-8"));
|
|
376
|
+
if (pkg.workspaces) {
|
|
377
|
+
return nodePath.resolve(dir, ...segments);
|
|
378
|
+
}
|
|
379
|
+
} catch {
|
|
380
|
+
}
|
|
381
|
+
dir = nodePath.dirname(dir);
|
|
382
|
+
}
|
|
383
|
+
return nodePath.resolve(process.cwd(), ...segments);
|
|
384
|
+
}
|
|
385
|
+
function tryRequire(moduleName, importMetaUrl) {
|
|
386
|
+
if (isBrowser) return null;
|
|
387
|
+
try {
|
|
388
|
+
return createEsmRequire(importMetaUrl)(moduleName);
|
|
389
|
+
} catch {
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
function resolveNativeNodePath(importMetaUrl, ...relativeSegments) {
|
|
394
|
+
if (isBrowser) return relativeSegments.join("/");
|
|
395
|
+
return getNodePath().resolve(getDirname(importMetaUrl), ...relativeSegments);
|
|
396
|
+
}
|
|
397
|
+
var isBrowser, nodeModuleRef, _nodePath, _nodeUrl, _nodeFs;
|
|
79
398
|
var init_esmHelpers = __esm({
|
|
80
399
|
"packages/domain/shared/src/esmHelpers.ts"() {
|
|
81
400
|
isBrowser = typeof window !== "undefined" || typeof document !== "undefined";
|
|
82
401
|
nodeModuleRef = null;
|
|
83
402
|
_nodePath = null;
|
|
84
403
|
_nodeUrl = null;
|
|
404
|
+
_nodeFs = null;
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
// packages/domain/shared/src/telemetry.ts
|
|
409
|
+
function getGlobalTelemetry() {
|
|
410
|
+
if (!_globalCollector) {
|
|
411
|
+
_globalCollector = new TelemetryCollector();
|
|
412
|
+
}
|
|
413
|
+
return _globalCollector;
|
|
414
|
+
}
|
|
415
|
+
function resetGlobalTelemetry() {
|
|
416
|
+
_globalCollector = null;
|
|
417
|
+
}
|
|
418
|
+
function createBuildTimer() {
|
|
419
|
+
const start = Date.now();
|
|
420
|
+
const phases = {};
|
|
421
|
+
let phaseStart = start;
|
|
422
|
+
return {
|
|
423
|
+
phase(name) {
|
|
424
|
+
const now = Date.now();
|
|
425
|
+
phases[name] = now - phaseStart;
|
|
426
|
+
phaseStart = now;
|
|
427
|
+
},
|
|
428
|
+
finish(opts) {
|
|
429
|
+
const now = Date.now();
|
|
430
|
+
const record = {
|
|
431
|
+
timestamp: start,
|
|
432
|
+
durationMs: now - start,
|
|
433
|
+
phases: {
|
|
434
|
+
scan: phases.scan ?? 0,
|
|
435
|
+
compile: phases.compile ?? 0,
|
|
436
|
+
engine: phases.engine ?? 0,
|
|
437
|
+
output: phases.output ?? now - start
|
|
438
|
+
},
|
|
439
|
+
cacheHitRate: opts.cacheHitRate ?? 0,
|
|
440
|
+
...opts
|
|
441
|
+
};
|
|
442
|
+
getGlobalTelemetry().record(record);
|
|
443
|
+
return record;
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
var RING_BUFFER_SIZE, TelemetryCollector, _globalCollector;
|
|
448
|
+
var init_telemetry = __esm({
|
|
449
|
+
"packages/domain/shared/src/telemetry.ts"() {
|
|
450
|
+
RING_BUFFER_SIZE = 100;
|
|
451
|
+
TelemetryCollector = class {
|
|
452
|
+
data = [];
|
|
453
|
+
enabled;
|
|
454
|
+
constructor(enabled) {
|
|
455
|
+
this.enabled = enabled ?? (process.env.TWS_TELEMETRY === "1" || process.env.TWS_TELEMETRY === "true");
|
|
456
|
+
}
|
|
457
|
+
record(build) {
|
|
458
|
+
if (!this.enabled) return;
|
|
459
|
+
if (this.data.length >= RING_BUFFER_SIZE) {
|
|
460
|
+
this.data.shift();
|
|
461
|
+
}
|
|
462
|
+
this.data.push(build);
|
|
463
|
+
}
|
|
464
|
+
snapshot() {
|
|
465
|
+
return [...this.data];
|
|
466
|
+
}
|
|
467
|
+
summary() {
|
|
468
|
+
if (this.data.length === 0) return null;
|
|
469
|
+
const durations = this.data.map((d) => d.durationMs).sort((a, b) => a - b);
|
|
470
|
+
const p95Idx = Math.floor(durations.length * 0.95);
|
|
471
|
+
const avg = (arr) => arr.reduce((a, b) => a + b, 0) / arr.length;
|
|
472
|
+
return {
|
|
473
|
+
totalBuilds: this.data.length,
|
|
474
|
+
avgDurationMs: avg(durations),
|
|
475
|
+
p95DurationMs: durations[p95Idx] ?? durations[durations.length - 1] ?? 0,
|
|
476
|
+
avgCacheHitRate: avg(this.data.map((d) => d.cacheHitRate)),
|
|
477
|
+
avgFilesScanned: avg(this.data.map((d) => d.filesScanned)),
|
|
478
|
+
avgClassesExtracted: avg(this.data.map((d) => d.classesExtracted)),
|
|
479
|
+
phaseAvgs: {
|
|
480
|
+
scan: avg(this.data.map((d) => d.phases.scan)),
|
|
481
|
+
compile: avg(this.data.map((d) => d.phases.compile)),
|
|
482
|
+
engine: avg(this.data.map((d) => d.phases.engine)),
|
|
483
|
+
output: avg(this.data.map((d) => d.phases.output))
|
|
484
|
+
},
|
|
485
|
+
slowestBuildMs: durations[durations.length - 1] ?? 0,
|
|
486
|
+
fastestBuildMs: durations[0] ?? 0
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
reset() {
|
|
490
|
+
this.data = [];
|
|
491
|
+
}
|
|
492
|
+
/** Format ringkas untuk CLI output */
|
|
493
|
+
formatCli() {
|
|
494
|
+
const s = this.summary();
|
|
495
|
+
if (!s) return "[telemetry] no data";
|
|
496
|
+
return [
|
|
497
|
+
`[telemetry] ${s.totalBuilds} builds`,
|
|
498
|
+
`avg ${s.avgDurationMs.toFixed(0)}ms`,
|
|
499
|
+
`p95 ${s.p95DurationMs.toFixed(0)}ms`,
|
|
500
|
+
`cache hit ${(s.avgCacheHitRate * 100).toFixed(0)}%`,
|
|
501
|
+
`${s.avgFilesScanned.toFixed(0)} files`
|
|
502
|
+
].join(" \xB7 ");
|
|
503
|
+
}
|
|
504
|
+
/** Export sebagai JSON untuk dashboard/prometheus */
|
|
505
|
+
toJSON() {
|
|
506
|
+
return {
|
|
507
|
+
summary: this.summary(),
|
|
508
|
+
history: this.data.slice(-20)
|
|
509
|
+
// last 20 builds
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
_globalCollector = null;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
function parseJsonWithSchema(jsonString, schema, sourceName) {
|
|
517
|
+
let parsed;
|
|
518
|
+
try {
|
|
519
|
+
parsed = JSON.parse(jsonString);
|
|
520
|
+
} catch (err) {
|
|
521
|
+
throw new Error(
|
|
522
|
+
`[${sourceName}] Invalid JSON: ${err instanceof Error ? err.message : String(err)}`
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
const result = schema.safeParse(parsed);
|
|
526
|
+
if (!result.success) {
|
|
527
|
+
const issues = result.error.issues.map((e) => ` ${e.path.join(".")}: ${e.message}`).join("\n");
|
|
528
|
+
throw new Error(`[${sourceName}] Schema validation failed:
|
|
529
|
+
${issues}`);
|
|
530
|
+
}
|
|
531
|
+
return result.data;
|
|
532
|
+
}
|
|
533
|
+
function parseJsonFileWithSchema(filePath, schema) {
|
|
534
|
+
const { readFileSync } = __require("fs");
|
|
535
|
+
const { basename } = __require("path");
|
|
536
|
+
let content;
|
|
537
|
+
try {
|
|
538
|
+
content = readFileSync(filePath, "utf-8");
|
|
539
|
+
} catch (err) {
|
|
540
|
+
throw new Error(
|
|
541
|
+
`[${basename(filePath)}] Could not read file: ${err instanceof Error ? err.message : String(err)}`
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
return parseJsonWithSchema(content, schema, basename(filePath));
|
|
545
|
+
}
|
|
546
|
+
var ScanCacheClassEntrySchema, ScanCacheSchema, TailwindContentItemSchema, TailwindConfigSchema, RegistryPluginEntrySchema, RegistryFileSchema, PackageJsonSchema;
|
|
547
|
+
var init_configSchemas = __esm({
|
|
548
|
+
"packages/domain/shared/src/configSchemas.ts"() {
|
|
549
|
+
ScanCacheClassEntrySchema = zod.z.object({
|
|
550
|
+
name: zod.z.string().min(1),
|
|
551
|
+
usedIn: zod.z.array(zod.z.string()),
|
|
552
|
+
risk: zod.z.enum(["low", "medium", "high"]).default("low"),
|
|
553
|
+
bundleContribution: zod.z.number().nonnegative().default(0),
|
|
554
|
+
variants: zod.z.array(zod.z.string()).default([])
|
|
555
|
+
});
|
|
556
|
+
ScanCacheSchema = zod.z.object({
|
|
557
|
+
version: zod.z.string().default("1"),
|
|
558
|
+
generatedAt: zod.z.string(),
|
|
559
|
+
root: zod.z.string(),
|
|
560
|
+
classNames: zod.z.array(ScanCacheClassEntrySchema),
|
|
561
|
+
totalFiles: zod.z.number().int().nonnegative(),
|
|
562
|
+
uniqueCount: zod.z.number().int().nonnegative()
|
|
563
|
+
});
|
|
564
|
+
TailwindContentItemSchema = zod.z.union([
|
|
565
|
+
zod.z.string(),
|
|
566
|
+
zod.z.object({
|
|
567
|
+
raw: zod.z.string(),
|
|
568
|
+
extension: zod.z.string().optional()
|
|
569
|
+
}),
|
|
570
|
+
zod.z.object({
|
|
571
|
+
files: zod.z.array(zod.z.string()),
|
|
572
|
+
transform: zod.z.record(zod.z.string(), zod.z.unknown()).optional()
|
|
573
|
+
})
|
|
574
|
+
]);
|
|
575
|
+
TailwindConfigSchema = zod.z.object({
|
|
576
|
+
content: zod.z.array(TailwindContentItemSchema).optional(),
|
|
577
|
+
theme: zod.z.record(zod.z.string(), zod.z.unknown()).optional(),
|
|
578
|
+
plugins: zod.z.array(zod.z.unknown()).optional(),
|
|
579
|
+
darkMode: zod.z.union([zod.z.literal("class"), zod.z.literal("media"), zod.z.literal(false)]).optional(),
|
|
580
|
+
prefix: zod.z.string().optional(),
|
|
581
|
+
safelist: zod.z.array(zod.z.union([zod.z.string(), zod.z.object({ pattern: zod.z.instanceof(RegExp) })])).optional(),
|
|
582
|
+
blocklist: zod.z.array(zod.z.string()).optional()
|
|
583
|
+
}).passthrough();
|
|
584
|
+
RegistryPluginEntrySchema = zod.z.object({
|
|
585
|
+
name: zod.z.string().min(1),
|
|
586
|
+
description: zod.z.string(),
|
|
587
|
+
version: zod.z.string(),
|
|
588
|
+
tags: zod.z.array(zod.z.string()).default([]),
|
|
589
|
+
official: zod.z.boolean().default(false),
|
|
590
|
+
docs: zod.z.string().url().optional(),
|
|
591
|
+
install: zod.z.string().optional(),
|
|
592
|
+
integrity: zod.z.string().optional()
|
|
593
|
+
});
|
|
594
|
+
RegistryFileSchema = zod.z.object({
|
|
595
|
+
version: zod.z.string(),
|
|
596
|
+
official: zod.z.array(RegistryPluginEntrySchema).default([]),
|
|
597
|
+
community: zod.z.array(RegistryPluginEntrySchema).default([])
|
|
598
|
+
});
|
|
599
|
+
PackageJsonSchema = zod.z.object({
|
|
600
|
+
name: zod.z.string(),
|
|
601
|
+
version: zod.z.string(),
|
|
602
|
+
scripts: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
603
|
+
dependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
604
|
+
devDependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
605
|
+
peerDependencies: zod.z.record(zod.z.string(), zod.z.string()).optional(),
|
|
606
|
+
main: zod.z.string().optional(),
|
|
607
|
+
module: zod.z.string().optional(),
|
|
608
|
+
exports: zod.z.unknown().optional(),
|
|
609
|
+
type: zod.z.enum(["module", "commonjs"]).optional()
|
|
610
|
+
}).passthrough();
|
|
85
611
|
}
|
|
86
612
|
});
|
|
87
613
|
|
|
88
|
-
// packages/domain/shared/src/
|
|
89
|
-
function
|
|
90
|
-
if (
|
|
91
|
-
if (
|
|
614
|
+
// packages/domain/shared/src/workerResolver.ts
|
|
615
|
+
function getDirnameFromUrl(importMetaUrl) {
|
|
616
|
+
if (!importMetaUrl) return "";
|
|
617
|
+
if (isBrowser2) return "";
|
|
92
618
|
try {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
return
|
|
619
|
+
const nodeUrl = __require(NODE_URL);
|
|
620
|
+
const nodePath = __require(NODE_PATH);
|
|
621
|
+
return nodePath.dirname(nodeUrl.fileURLToPath(importMetaUrl));
|
|
96
622
|
} catch {
|
|
97
|
-
|
|
98
|
-
|
|
623
|
+
if (importMetaUrl.startsWith("file://")) {
|
|
624
|
+
const filePath = importMetaUrl.slice(7);
|
|
625
|
+
const lastSlash = filePath.lastIndexOf("/");
|
|
626
|
+
return lastSlash >= 0 ? filePath.slice(0, lastSlash) : filePath;
|
|
627
|
+
}
|
|
628
|
+
return "";
|
|
99
629
|
}
|
|
100
630
|
}
|
|
101
|
-
function
|
|
102
|
-
if (isBrowser2) return
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
631
|
+
function resolvePath(...segments) {
|
|
632
|
+
if (isBrowser2) return segments.join("/").replace(/\/+/g, "/");
|
|
633
|
+
try {
|
|
634
|
+
const nodePath = __require(NODE_PATH);
|
|
635
|
+
return nodePath.resolve(...segments);
|
|
636
|
+
} catch {
|
|
637
|
+
return segments.join("/").replace(/\/+/g, "/");
|
|
638
|
+
}
|
|
107
639
|
}
|
|
108
|
-
function
|
|
109
|
-
if (isBrowser2) return
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
640
|
+
function existsSync(path13) {
|
|
641
|
+
if (isBrowser2) return false;
|
|
642
|
+
try {
|
|
643
|
+
const nodeFs = __require(NODE_FS);
|
|
644
|
+
return nodeFs.existsSync(path13);
|
|
645
|
+
} catch {
|
|
646
|
+
return false;
|
|
647
|
+
}
|
|
114
648
|
}
|
|
115
|
-
function
|
|
116
|
-
if (isBrowser2)
|
|
117
|
-
throw new Error("
|
|
118
|
-
}
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
649
|
+
function resolveWorkerPath(opts) {
|
|
650
|
+
if (isBrowser2) {
|
|
651
|
+
throw new Error("Worker resolution not available in browser");
|
|
652
|
+
}
|
|
653
|
+
const {
|
|
654
|
+
basename,
|
|
655
|
+
importMetaUrl,
|
|
656
|
+
extensions = [".cjs", ".js", ".mjs"],
|
|
657
|
+
subdirs = [".", "workers", "lib"],
|
|
658
|
+
required = true
|
|
659
|
+
} = opts;
|
|
660
|
+
const runtimeDir = getDirnameFromUrl(importMetaUrl);
|
|
661
|
+
for (const subdir of subdirs) {
|
|
662
|
+
for (const ext of extensions) {
|
|
663
|
+
const candidate = resolvePath(runtimeDir, subdir, `${basename}${ext}`);
|
|
664
|
+
if (existsSync(candidate)) {
|
|
665
|
+
return {
|
|
666
|
+
path: candidate,
|
|
667
|
+
extension: ext,
|
|
668
|
+
format: ext === ".cjs" ? "cjs" : "esm"
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (required) {
|
|
674
|
+
const tried = subdirs.flatMap(
|
|
675
|
+
(d) => extensions.map((e) => resolvePath(runtimeDir, d, `${basename}${e}`))
|
|
676
|
+
);
|
|
677
|
+
throw new Error(
|
|
678
|
+
`[worker-resolver] Could not find worker script "${basename}".
|
|
679
|
+
Tried:
|
|
680
|
+
${tried.map((p) => ` - ${p}`).join("\n")}
|
|
681
|
+
Ensure the package is built: npm run build`
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
return { path: "", extension: "", format: "cjs" };
|
|
685
|
+
}
|
|
686
|
+
function resolveLoaderPath(loaderBasename, importMetaUrl) {
|
|
687
|
+
return resolveWorkerPath({
|
|
688
|
+
basename: loaderBasename,
|
|
689
|
+
importMetaUrl,
|
|
690
|
+
extensions: [".cjs", ".js", ".mjs"],
|
|
691
|
+
subdirs: [".", "loaders", "lib"]
|
|
692
|
+
}).path;
|
|
693
|
+
}
|
|
694
|
+
var isBrowser2, NODE_URL, NODE_FS, NODE_PATH;
|
|
695
|
+
var init_workerResolver = __esm({
|
|
696
|
+
"packages/domain/shared/src/workerResolver.ts"() {
|
|
697
|
+
isBrowser2 = typeof window !== "undefined" || typeof document !== "undefined";
|
|
698
|
+
NODE_URL = typeof window === "undefined" || typeof document === "undefined" ? "node:url" : null;
|
|
699
|
+
NODE_FS = typeof window === "undefined" || typeof document === "undefined" ? "node:fs" : null;
|
|
700
|
+
NODE_PATH = typeof window === "undefined" || typeof document === "undefined" ? "node:path" : null;
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
// packages/domain/shared/src/codegen.ts
|
|
705
|
+
function generateComponentCode(opts) {
|
|
706
|
+
const {
|
|
707
|
+
name,
|
|
708
|
+
tag = "div",
|
|
709
|
+
base = "",
|
|
710
|
+
variants = {},
|
|
711
|
+
defaultVariants = {},
|
|
712
|
+
compoundVariants = [],
|
|
713
|
+
framework = "react",
|
|
714
|
+
withTypes = true
|
|
715
|
+
} = opts;
|
|
716
|
+
const variantKeys = Object.keys(variants);
|
|
717
|
+
const lines = [];
|
|
718
|
+
if (framework === "react") {
|
|
719
|
+
lines.push(`import { tw } from "tailwind-styled-v4"`);
|
|
720
|
+
if (withTypes && variantKeys.length > 0) {
|
|
721
|
+
lines.push(`import type { InferVariantProps } from "tailwind-styled-v4"`);
|
|
722
|
+
}
|
|
723
|
+
} else if (framework === "vue") {
|
|
724
|
+
lines.push(`import { tw } from "@tailwind-styled/vue"`);
|
|
725
|
+
} else if (framework === "svelte") {
|
|
726
|
+
lines.push(`import { tw } from "@tailwind-styled/svelte"`);
|
|
727
|
+
}
|
|
728
|
+
lines.push("");
|
|
729
|
+
const configLines = [`export const ${name} = tw.${tag}({`];
|
|
730
|
+
if (base) configLines.push(` base: "${base}",`);
|
|
731
|
+
if (variantKeys.length > 0) {
|
|
732
|
+
configLines.push(` variants: {`);
|
|
733
|
+
for (const [key, values] of Object.entries(variants)) {
|
|
734
|
+
configLines.push(` ${key}: {`);
|
|
735
|
+
for (const [val, cls] of Object.entries(values)) {
|
|
736
|
+
configLines.push(` ${val}: "${cls}",`);
|
|
737
|
+
}
|
|
738
|
+
configLines.push(` },`);
|
|
739
|
+
}
|
|
740
|
+
configLines.push(` },`);
|
|
741
|
+
}
|
|
742
|
+
if (compoundVariants.length > 0) {
|
|
743
|
+
configLines.push(` compoundVariants: [`);
|
|
744
|
+
for (const cv of compoundVariants) {
|
|
745
|
+
const { class: cls, ...conditions } = cv;
|
|
746
|
+
const condStr = Object.entries(conditions).map(([k, v]) => `${k}: "${v}"`).join(", ");
|
|
747
|
+
configLines.push(` { ${condStr}, class: "${cls}" },`);
|
|
748
|
+
}
|
|
749
|
+
configLines.push(` ],`);
|
|
750
|
+
}
|
|
751
|
+
if (Object.keys(defaultVariants).length > 0) {
|
|
752
|
+
configLines.push(` defaultVariants: {`);
|
|
753
|
+
for (const [k, v] of Object.entries(defaultVariants)) {
|
|
754
|
+
configLines.push(` ${k}: "${v}",`);
|
|
755
|
+
}
|
|
756
|
+
configLines.push(` },`);
|
|
757
|
+
}
|
|
758
|
+
configLines.push(`})`);
|
|
759
|
+
lines.push(...configLines);
|
|
760
|
+
if (withTypes && variantKeys.length > 0 && framework === "react") {
|
|
761
|
+
lines.push("");
|
|
762
|
+
lines.push(`export type ${name}Props = InferVariantProps<typeof ${name}> & {`);
|
|
763
|
+
lines.push(` children?: React.ReactNode`);
|
|
764
|
+
lines.push(` className?: string`);
|
|
765
|
+
lines.push(`}`);
|
|
766
|
+
}
|
|
767
|
+
return lines.join("\n");
|
|
768
|
+
}
|
|
769
|
+
function generateStorybookStory(opts) {
|
|
770
|
+
const { name, variants = {}, defaultVariants = {} } = opts;
|
|
771
|
+
const lines = [];
|
|
772
|
+
lines.push(`import type { Meta, StoryObj } from "@storybook/react"`);
|
|
773
|
+
lines.push(`import { ${name} } from "./${name}"`);
|
|
774
|
+
lines.push(`import { generateArgTypes, generateDefaultArgs } from "tailwind-styled-v4"`);
|
|
775
|
+
lines.push(``);
|
|
776
|
+
lines.push(`const config = {`);
|
|
777
|
+
if (Object.keys(variants).length > 0) {
|
|
778
|
+
lines.push(` variants: ${JSON.stringify(variants, null, 2).replace(/^/gm, " ")},`);
|
|
779
|
+
}
|
|
780
|
+
if (Object.keys(defaultVariants).length > 0) {
|
|
781
|
+
lines.push(` defaultVariants: ${JSON.stringify(defaultVariants)},`);
|
|
782
|
+
}
|
|
783
|
+
lines.push(`}`);
|
|
784
|
+
lines.push(``);
|
|
785
|
+
lines.push(`const meta: Meta<typeof ${name}> = {`);
|
|
786
|
+
lines.push(` title: "Components/${name}",`);
|
|
787
|
+
lines.push(` component: ${name},`);
|
|
788
|
+
lines.push(` argTypes: generateArgTypes(config),`);
|
|
789
|
+
lines.push(` args: generateDefaultArgs(config),`);
|
|
790
|
+
lines.push(`}`);
|
|
791
|
+
lines.push(``);
|
|
792
|
+
lines.push(`export default meta`);
|
|
793
|
+
lines.push(`type Story = StoryObj<typeof ${name}>`);
|
|
794
|
+
lines.push(``);
|
|
795
|
+
lines.push(`export const Default: Story = {}`);
|
|
796
|
+
const variantEntries = Object.entries(variants);
|
|
797
|
+
if (variantEntries.length > 0) {
|
|
798
|
+
const [firstKey, firstValues] = variantEntries[0];
|
|
799
|
+
const valueKeys = Object.keys(firstValues).slice(0, 4);
|
|
800
|
+
for (const val of valueKeys) {
|
|
801
|
+
const storyName = `${firstKey.charAt(0).toUpperCase()}${firstKey.slice(1)}${val.charAt(0).toUpperCase()}${val.slice(1)}`;
|
|
802
|
+
lines.push(``);
|
|
803
|
+
lines.push(`export const ${storyName}: Story = {`);
|
|
804
|
+
lines.push(` args: { ${firstKey}: "${val}" },`);
|
|
805
|
+
lines.push(`}`);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
return lines.join("\n");
|
|
809
|
+
}
|
|
810
|
+
function generateClassRenameCodemod(renames, opts = {}) {
|
|
811
|
+
const { format = "regex", filename = "rename-classes.mjs" } = opts;
|
|
812
|
+
const lines = [];
|
|
813
|
+
if (format === "regex") {
|
|
814
|
+
lines.push(`#!/usr/bin/env node`);
|
|
815
|
+
lines.push(`/**`);
|
|
816
|
+
lines.push(` * Auto-generated class rename codemod`);
|
|
817
|
+
lines.push(` * Usage: node ${filename} ./src`);
|
|
818
|
+
lines.push(` */`);
|
|
819
|
+
lines.push(`import fs from "node:fs"`);
|
|
820
|
+
lines.push(`import path from "node:path"`);
|
|
821
|
+
lines.push(`import { execSync } from "node:child_process"`);
|
|
822
|
+
lines.push(``);
|
|
823
|
+
lines.push(`const RENAMES = {`);
|
|
824
|
+
for (const [from, to] of Object.entries(renames)) {
|
|
825
|
+
lines.push(` "${from}": "${to}",`);
|
|
826
|
+
}
|
|
827
|
+
lines.push(`}`);
|
|
828
|
+
lines.push(``);
|
|
829
|
+
lines.push(`const dir = process.argv[2] ?? "."`);
|
|
830
|
+
lines.push(`const files = execSync(\`find \${dir} -name "*.tsx" -o -name "*.ts" -o -name "*.jsx"\`, { encoding: "utf-8" }).split("\\n").filter(Boolean)`);
|
|
831
|
+
lines.push(``);
|
|
832
|
+
lines.push(`let total = 0`);
|
|
833
|
+
lines.push(`for (const file of files) {`);
|
|
834
|
+
lines.push(` let content = fs.readFileSync(file, "utf-8")`);
|
|
835
|
+
lines.push(` let changed = false`);
|
|
836
|
+
lines.push(` for (const [from, to] of Object.entries(RENAMES)) {`);
|
|
837
|
+
lines.push(' const re = new RegExp(`\\\\b${from.replace(/[.*+?^${}()|[\\\\]\\\\]/g, "\\\\$&")}\\\\b`, "g")');
|
|
838
|
+
lines.push(` if (re.test(content)) { content = content.replace(re, to); changed = true; total++ }`);
|
|
839
|
+
lines.push(` }`);
|
|
840
|
+
lines.push(` if (changed) fs.writeFileSync(file, content)`);
|
|
841
|
+
lines.push(`}`);
|
|
842
|
+
lines.push(`console.log(\`Renamed \${total} occurrences in \${files.length} files\`)`);
|
|
843
|
+
}
|
|
844
|
+
return lines.join("\n");
|
|
845
|
+
}
|
|
846
|
+
function generateBarrelFile(exports$1, dir, opts = {}) {
|
|
847
|
+
const { includeTypes = true } = opts;
|
|
848
|
+
const lines = [];
|
|
849
|
+
lines.push(`// Auto-generated barrel file for ${dir}`);
|
|
850
|
+
lines.push(`// Run: npx tsx scripts/generate-barrel.ts to regenerate`);
|
|
851
|
+
lines.push(``);
|
|
852
|
+
for (const name of exports$1) {
|
|
853
|
+
lines.push(`export { default as ${name}, type ${name}Props } from "./${name}"`);
|
|
854
|
+
if (includeTypes) {
|
|
855
|
+
lines.push(`export type * from "./${name}"`);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return lines.join("\n");
|
|
125
859
|
}
|
|
860
|
+
var init_codegen = __esm({
|
|
861
|
+
"packages/domain/shared/src/codegen.ts"() {
|
|
862
|
+
}
|
|
863
|
+
});
|
|
126
864
|
function platformKey() {
|
|
127
|
-
if (
|
|
865
|
+
if (isBrowser3) return "browser";
|
|
128
866
|
return `${process.platform}-${process.arch}`;
|
|
129
867
|
}
|
|
130
868
|
function resolveNativeBinary(runtimeDir) {
|
|
131
869
|
const platform = platformKey();
|
|
132
870
|
const tried = [];
|
|
133
|
-
if (
|
|
871
|
+
if (isBrowser3) {
|
|
134
872
|
return { path: null, source: "not-found", platform, tried: ["not available in browser"] };
|
|
135
873
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
874
|
+
if (process.env.TWS_DISABLE_NATIVE === "1") {
|
|
875
|
+
return { path: null, source: "not-found", platform, tried: [] };
|
|
876
|
+
}
|
|
139
877
|
const envPath = process.env.TW_NATIVE_PATH?.trim();
|
|
140
878
|
if (envPath) {
|
|
141
|
-
if (
|
|
879
|
+
if (fs4__namespace.existsSync(envPath)) {
|
|
142
880
|
return { path: envPath, source: "env", platform, tried };
|
|
143
881
|
}
|
|
144
882
|
tried.push(`env:${envPath} (not found)`);
|
|
145
883
|
}
|
|
146
|
-
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1" || process.env.TWS_DISABLE_NATIVE === "1") {
|
|
147
|
-
return { path: null, source: "not-found", platform, tried: ["disabled by env"] };
|
|
148
|
-
}
|
|
149
884
|
const prebuiltPkgs = PLATFORM_MAP[platform] ?? [];
|
|
150
885
|
for (const pkg of prebuiltPkgs) {
|
|
151
886
|
try {
|
|
152
|
-
const candidate =
|
|
153
|
-
if (
|
|
887
|
+
const candidate = _require.resolve(`${pkg}/tailwind_styled_parser.node`);
|
|
888
|
+
if (fs4__namespace.existsSync(candidate)) {
|
|
154
889
|
return { path: candidate, source: "prebuilt", platform, tried };
|
|
155
890
|
}
|
|
156
891
|
tried.push(`prebuilt:${pkg} (resolved but missing)`);
|
|
@@ -160,30 +895,57 @@ function resolveNativeBinary(runtimeDir) {
|
|
|
160
895
|
}
|
|
161
896
|
const cwd = process.cwd();
|
|
162
897
|
const base = runtimeDir ?? cwd;
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
898
|
+
const napiPlatform = platform === "linux-x64" ? "linux-x64-gnu" : platform === "linux-arm64" ? "linux-arm64-gnu" : platform;
|
|
899
|
+
const BINARY_NAMES = ["tailwind-styled-native", "tailwind_styled_parser"];
|
|
900
|
+
const localCandidates = [];
|
|
901
|
+
for (const bin of BINARY_NAMES) {
|
|
902
|
+
localCandidates.push(path6__namespace.resolve(base, `${bin}.node`));
|
|
903
|
+
localCandidates.push(path6__namespace.resolve(base, "..", `${bin}.node`));
|
|
904
|
+
localCandidates.push(path6__namespace.resolve(base, `${bin}.${platform}.node`));
|
|
905
|
+
localCandidates.push(path6__namespace.resolve(base, `${bin}.${napiPlatform}.node`));
|
|
906
|
+
}
|
|
907
|
+
for (const startDir of [cwd, base]) {
|
|
908
|
+
let dir = startDir;
|
|
909
|
+
for (let i = 0; i < 6; i++) {
|
|
910
|
+
const nativeDir = path6__namespace.resolve(dir, "native");
|
|
911
|
+
for (const bin of BINARY_NAMES) {
|
|
912
|
+
localCandidates.push(path6__namespace.resolve(nativeDir, `${bin}.node`));
|
|
913
|
+
localCandidates.push(path6__namespace.resolve(nativeDir, `${bin}.${platform}.node`));
|
|
914
|
+
localCandidates.push(path6__namespace.resolve(nativeDir, `${bin}.${napiPlatform}.node`));
|
|
915
|
+
localCandidates.push(path6__namespace.resolve(nativeDir, "target", "release", `${bin}.node`));
|
|
916
|
+
}
|
|
917
|
+
const parent = path6__namespace.resolve(dir, "..");
|
|
918
|
+
if (parent === dir) break;
|
|
919
|
+
dir = parent;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
171
922
|
for (const candidate of localCandidates) {
|
|
172
923
|
tried.push(`local:${candidate}`);
|
|
173
|
-
if (
|
|
924
|
+
if (fs4__namespace.existsSync(candidate)) {
|
|
174
925
|
return { path: candidate, source: "local", platform, tried };
|
|
175
926
|
}
|
|
176
927
|
}
|
|
177
928
|
return { path: null, source: "not-found", platform, tried };
|
|
178
929
|
}
|
|
179
|
-
|
|
930
|
+
function formatNativeNotFoundError(result) {
|
|
931
|
+
const lines = [
|
|
932
|
+
`[tailwind-styled] Native binding not found for ${result.platform}`,
|
|
933
|
+
``,
|
|
934
|
+
`Tried:`,
|
|
935
|
+
...result.tried.map((t) => ` - ${t}`),
|
|
936
|
+
``,
|
|
937
|
+
`Solutions:`,
|
|
938
|
+
` 1. Build locally: npm run build:rust`,
|
|
939
|
+
` 2. Install prebuilt: npm install @tailwind-styled/native-${result.platform}`,
|
|
940
|
+
` 3. Override path: TW_NATIVE_PATH=/path/to/parser.node`
|
|
941
|
+
];
|
|
942
|
+
return lines.join("\n");
|
|
943
|
+
}
|
|
944
|
+
var isBrowser3, _require, PLATFORM_MAP;
|
|
180
945
|
var init_native_resolution = __esm({
|
|
181
946
|
"packages/domain/shared/src/native-resolution.ts"() {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
_nodeFs = null;
|
|
185
|
-
_nodePath2 = null;
|
|
186
|
-
_require = null;
|
|
947
|
+
isBrowser3 = typeof window !== "undefined" || typeof document !== "undefined";
|
|
948
|
+
_require = typeof __require !== "undefined" ? __require : module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
187
949
|
PLATFORM_MAP = {
|
|
188
950
|
"linux-x64": ["@tailwind-styled/native-linux-x64"],
|
|
189
951
|
"linux-arm64": ["@tailwind-styled/native-linux-arm64"],
|
|
@@ -195,40 +957,111 @@ var init_native_resolution = __esm({
|
|
|
195
957
|
}
|
|
196
958
|
});
|
|
197
959
|
|
|
198
|
-
// packages/domain/shared/src/
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
960
|
+
// packages/domain/shared/src/observability.ts
|
|
961
|
+
function createObservabilityClient(opts = {}) {
|
|
962
|
+
const { baseUrl = "http://localhost:7421", timeoutMs = 3e3 } = opts;
|
|
963
|
+
async function fetchJson(path13) {
|
|
964
|
+
try {
|
|
965
|
+
const res = await fetch(`${baseUrl}${path13}`, {
|
|
966
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
967
|
+
});
|
|
968
|
+
if (!res.ok) return null;
|
|
969
|
+
return await res.json();
|
|
970
|
+
} catch {
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
209
973
|
}
|
|
974
|
+
return {
|
|
975
|
+
async inspectClass(className) {
|
|
976
|
+
const data = await fetchJson(`/inspect?class=${encodeURIComponent(className)}`);
|
|
977
|
+
if (!data) return null;
|
|
978
|
+
return { ...data, inspectedAt: Date.now() };
|
|
979
|
+
},
|
|
980
|
+
async getMetrics() {
|
|
981
|
+
return fetchJson("/metrics");
|
|
982
|
+
},
|
|
983
|
+
async getSummary() {
|
|
984
|
+
return fetchJson("/summary");
|
|
985
|
+
},
|
|
986
|
+
async getHistory() {
|
|
987
|
+
const data = await fetchJson("/history");
|
|
988
|
+
return Array.isArray(data) ? data : [];
|
|
989
|
+
}
|
|
990
|
+
};
|
|
210
991
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
992
|
+
var init_observability = __esm({
|
|
993
|
+
"packages/domain/shared/src/observability.ts"() {
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
|
|
997
|
+
// packages/domain/shared/src/index.ts
|
|
998
|
+
var src_exports = {};
|
|
999
|
+
__export(src_exports, {
|
|
1000
|
+
ERROR_CODES: () => ERROR_CODES,
|
|
1001
|
+
LRUCache: () => LRUCache,
|
|
1002
|
+
NativeAnalyzerReportSchema: () => NativeAnalyzerReportSchema,
|
|
1003
|
+
NativeCacheEntrySchema: () => NativeCacheEntrySchema,
|
|
1004
|
+
NativeCacheReadResultSchema: () => NativeCacheReadResultSchema,
|
|
1005
|
+
NativeCssCompileResultSchema: () => NativeCssCompileResultSchema,
|
|
1006
|
+
NativeScanFileSchema: () => NativeScanFileSchema,
|
|
1007
|
+
NativeScanResultSchema: () => NativeScanResultSchema,
|
|
1008
|
+
NativeTransformResultSchema: () => NativeTransformResultSchema,
|
|
1009
|
+
NativeWatchResultSchema: () => NativeWatchResultSchema,
|
|
1010
|
+
PackageJsonSchema: () => PackageJsonSchema,
|
|
1011
|
+
RegistryFileSchema: () => RegistryFileSchema,
|
|
1012
|
+
RegistryPluginEntrySchema: () => RegistryPluginEntrySchema,
|
|
1013
|
+
ScanCacheClassEntrySchema: () => ScanCacheClassEntrySchema,
|
|
1014
|
+
ScanCacheSchema: () => ScanCacheSchema,
|
|
1015
|
+
TailwindConfigSchema: () => TailwindConfigSchema,
|
|
1016
|
+
TelemetryCollector: () => TelemetryCollector,
|
|
1017
|
+
TwError: () => TwError,
|
|
1018
|
+
assertTailwindV4: () => assertTailwindV4,
|
|
1019
|
+
calculateHealth: () => calculateHealth,
|
|
1020
|
+
createBuildTimer: () => createBuildTimer,
|
|
1021
|
+
createDebugLogger: () => createDebugLogger,
|
|
1022
|
+
createEsmRequire: () => createEsmRequire,
|
|
1023
|
+
createLogger: () => createLogger,
|
|
1024
|
+
createObservabilityClient: () => createObservabilityClient,
|
|
1025
|
+
createTraceSnapshot: () => createTraceSnapshot,
|
|
1026
|
+
detectTailwind: () => detectTailwind,
|
|
1027
|
+
formatDuration: () => formatDuration,
|
|
1028
|
+
formatErrorCode: () => formatErrorCode,
|
|
1029
|
+
formatErrorMessage: () => formatErrorMessage,
|
|
1030
|
+
formatMemory: () => formatMemory,
|
|
1031
|
+
formatNativeNotFoundError: () => formatNativeNotFoundError,
|
|
1032
|
+
generateBarrelFile: () => generateBarrelFile,
|
|
1033
|
+
generateClassRenameCodemod: () => generateClassRenameCodemod,
|
|
1034
|
+
generateComponentCode: () => generateComponentCode,
|
|
1035
|
+
generateStorybookStory: () => generateStorybookStory,
|
|
1036
|
+
getBuildTimeColor: () => getBuildTimeColor,
|
|
1037
|
+
getDirname: () => getDirname,
|
|
1038
|
+
getFilename: () => getFilename,
|
|
1039
|
+
getGlobalTelemetry: () => getGlobalTelemetry,
|
|
1040
|
+
getHealthColor: () => getHealthColor,
|
|
1041
|
+
getMemoryColor: () => getMemoryColor,
|
|
1042
|
+
getModeColor: () => getModeColor,
|
|
1043
|
+
getPipelinePercentages: () => getPipelinePercentages,
|
|
1044
|
+
getSuggestion: () => getSuggestion,
|
|
1045
|
+
getTailwindVersion: () => getTailwindVersion,
|
|
1046
|
+
hashContent: () => hashContent,
|
|
1047
|
+
isTailwindV4: () => isTailwindV4,
|
|
1048
|
+
isTwError: () => isTwError,
|
|
1049
|
+
loadNativeBinding: () => loadNativeBinding,
|
|
1050
|
+
parseJsonFileWithSchema: () => parseJsonFileWithSchema,
|
|
1051
|
+
parseJsonWithSchema: () => parseJsonWithSchema,
|
|
1052
|
+
parseNative: () => parseNative,
|
|
1053
|
+
resetGlobalTelemetry: () => resetGlobalTelemetry,
|
|
1054
|
+
resolveFromRoot: () => resolveFromRoot,
|
|
1055
|
+
resolveLoaderPath: () => resolveLoaderPath,
|
|
1056
|
+
resolveNativeBinary: () => resolveNativeBinary,
|
|
1057
|
+
resolveNativeBindingCandidates: () => resolveNativeBindingCandidates,
|
|
1058
|
+
resolveNativeNodePath: () => resolveNativeNodePath,
|
|
1059
|
+
resolveRuntimeDir: () => resolveRuntimeDir,
|
|
1060
|
+
resolveWorkerPath: () => resolveWorkerPath,
|
|
1061
|
+
safeParseNative: () => safeParseNative,
|
|
1062
|
+
tryRequire: () => tryRequire,
|
|
1063
|
+
wrapUnknownError: () => wrapUnknownError
|
|
1064
|
+
});
|
|
232
1065
|
function createLogger(namespace) {
|
|
233
1066
|
const prefix = `[${namespace}]`;
|
|
234
1067
|
return {
|
|
@@ -258,27 +1091,25 @@ function createDebugLogger(namespace, label) {
|
|
|
258
1091
|
}
|
|
259
1092
|
};
|
|
260
1093
|
}
|
|
261
|
-
function formatIssuePath(
|
|
262
|
-
if (!
|
|
263
|
-
return
|
|
1094
|
+
function formatIssuePath(path13) {
|
|
1095
|
+
if (!path13 || path13.length === 0) return "(root)";
|
|
1096
|
+
return path13.map(
|
|
264
1097
|
(segment) => typeof segment === "symbol" ? segment.description ?? segment.toString() : String(segment)
|
|
265
1098
|
).join(".");
|
|
266
1099
|
}
|
|
267
1100
|
function wrapUnknownError(domain, code, error) {
|
|
268
1101
|
return TwError.wrap(domain, code, error);
|
|
269
1102
|
}
|
|
1103
|
+
function isTwError(err) {
|
|
1104
|
+
return err instanceof TwError;
|
|
1105
|
+
}
|
|
270
1106
|
function loadNativeBinding(options) {
|
|
271
|
-
if (isBrowser3) {
|
|
272
|
-
return { binding: null, loadErrors: [{ path: "", message: "Native bindings not available in browser" }] };
|
|
273
|
-
}
|
|
274
1107
|
const { runtimeDir, candidates, isValid } = options;
|
|
275
1108
|
const loadErrors = [];
|
|
276
|
-
const path11 = getNodePath3();
|
|
277
|
-
const fs9 = getNodeFs2();
|
|
278
1109
|
for (const candidate of candidates) {
|
|
279
|
-
const candidatePath =
|
|
1110
|
+
const candidatePath = path6__namespace.default.resolve(runtimeDir, candidate);
|
|
280
1111
|
try {
|
|
281
|
-
if (!
|
|
1112
|
+
if (!fs4__namespace.default.existsSync(candidatePath) && !fs4__namespace.default.existsSync(candidatePath + ".node")) {
|
|
282
1113
|
continue;
|
|
283
1114
|
}
|
|
284
1115
|
const mod = requireNativeModule(candidatePath);
|
|
@@ -292,74 +1123,76 @@ function loadNativeBinding(options) {
|
|
|
292
1123
|
}
|
|
293
1124
|
return { binding: null, loadErrors };
|
|
294
1125
|
}
|
|
295
|
-
function
|
|
296
|
-
|
|
297
|
-
throw new Error("require not available in browser");
|
|
298
|
-
});
|
|
299
|
-
const nodeRequire = getNodeModuleRef3();
|
|
300
|
-
if (!nodeRequire) return (() => {
|
|
301
|
-
throw new Error("require not available");
|
|
302
|
-
});
|
|
303
|
-
return nodeRequire.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
304
|
-
}
|
|
305
|
-
function requireNativeModule(path11) {
|
|
306
|
-
return _require2(path11);
|
|
1126
|
+
function requireNativeModule(p) {
|
|
1127
|
+
return _require2(p);
|
|
307
1128
|
}
|
|
308
1129
|
function resolveNativeBindingCandidates(options) {
|
|
309
|
-
|
|
310
|
-
|
|
1130
|
+
const {
|
|
1131
|
+
envVarNames = ["TW_NATIVE_PATH", "TWS_NATIVE_PATH"],
|
|
1132
|
+
includeDefaultCandidates = true,
|
|
1133
|
+
enforceNodeExtensionForEnvPath = false
|
|
1134
|
+
} = options;
|
|
1135
|
+
const runtimeDir = options.runtimeDir || process.cwd();
|
|
311
1136
|
const candidates = [];
|
|
312
|
-
const path11 = getNodePath3();
|
|
313
|
-
const fs9 = getNodeFs2();
|
|
314
1137
|
for (const envVar of envVarNames) {
|
|
315
1138
|
const envPath = process.env[envVar];
|
|
316
1139
|
if (envPath) {
|
|
317
|
-
|
|
318
|
-
candidates.push(envPath + ".node");
|
|
319
|
-
} else {
|
|
320
|
-
candidates.push(envPath);
|
|
321
|
-
}
|
|
1140
|
+
candidates.push(enforceNodeExtensionForEnvPath && !envPath.endsWith(".node") ? envPath + ".node" : envPath);
|
|
322
1141
|
}
|
|
323
1142
|
}
|
|
324
1143
|
if (!includeDefaultCandidates) return candidates;
|
|
325
|
-
if (
|
|
1144
|
+
if (fs4__namespace.default.existsSync(runtimeDir)) {
|
|
326
1145
|
try {
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
if (entry.endsWith(".node")) {
|
|
330
|
-
candidates.push(entry);
|
|
331
|
-
}
|
|
1146
|
+
for (const entry of fs4__namespace.default.readdirSync(runtimeDir)) {
|
|
1147
|
+
if (entry.endsWith(".node")) candidates.push(entry);
|
|
332
1148
|
}
|
|
333
1149
|
} catch {
|
|
334
1150
|
}
|
|
335
1151
|
}
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
1152
|
+
const BINARY_NAMES = ["tailwind-styled-native", "tailwind_styled_parser"];
|
|
1153
|
+
const napiPlatform = process.platform === "linux" && process.arch === "x64" ? "linux-x64-gnu" : process.platform === "linux" && process.arch === "arm64" ? "linux-arm64-gnu" : `${process.platform}-${process.arch}`;
|
|
1154
|
+
for (const bin of BINARY_NAMES) {
|
|
1155
|
+
candidates.push(path6__namespace.default.resolve(runtimeDir, `${bin}.node`));
|
|
1156
|
+
candidates.push(path6__namespace.default.resolve(runtimeDir, `${bin}.${napiPlatform}.node`));
|
|
1157
|
+
candidates.push(path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "..", "native", `${bin}.node`));
|
|
1158
|
+
candidates.push(path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "..", "native", `${bin}.${napiPlatform}.node`));
|
|
1159
|
+
candidates.push(path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "native", `${bin}.node`));
|
|
1160
|
+
candidates.push(path6__namespace.default.resolve(process.cwd(), "native", `${bin}.node`));
|
|
1161
|
+
candidates.push(path6__namespace.default.resolve(process.cwd(), "native", `${bin}.${napiPlatform}.node`));
|
|
1162
|
+
}
|
|
342
1163
|
return Array.from(new Set(candidates));
|
|
343
1164
|
}
|
|
344
1165
|
function resolveRuntimeDir(dir, importMetaUrl) {
|
|
345
|
-
if (
|
|
346
|
-
if (dir) return getNodePath3().resolve(dir);
|
|
1166
|
+
if (dir) return path6__namespace.default.resolve(dir);
|
|
347
1167
|
try {
|
|
348
|
-
return
|
|
1168
|
+
return path6__namespace.default.dirname(url.fileURLToPath(importMetaUrl));
|
|
349
1169
|
} catch {
|
|
350
1170
|
return process.cwd();
|
|
351
1171
|
}
|
|
352
1172
|
}
|
|
353
|
-
|
|
1173
|
+
function hashContent(content, algorithm = "md5", length) {
|
|
1174
|
+
const hash = crypto.createHash(algorithm).update(content).digest("hex");
|
|
1175
|
+
return length ? hash.slice(0, length) : hash;
|
|
1176
|
+
}
|
|
1177
|
+
function formatErrorMessage(error) {
|
|
1178
|
+
if (error instanceof TwError) return error.toString();
|
|
1179
|
+
if (error instanceof Error) return error.message;
|
|
1180
|
+
return String(error);
|
|
1181
|
+
}
|
|
1182
|
+
var TwError, _require2, LRUCache;
|
|
354
1183
|
var init_src = __esm({
|
|
355
1184
|
"packages/domain/shared/src/index.ts"() {
|
|
1185
|
+
init_trace();
|
|
1186
|
+
init_error_codes();
|
|
1187
|
+
init_compatibility();
|
|
1188
|
+
init_native_schemas();
|
|
356
1189
|
init_esmHelpers();
|
|
1190
|
+
init_telemetry();
|
|
1191
|
+
init_configSchemas();
|
|
1192
|
+
init_workerResolver();
|
|
1193
|
+
init_codegen();
|
|
357
1194
|
init_native_resolution();
|
|
358
|
-
|
|
359
|
-
nodeModuleRef3 = null;
|
|
360
|
-
_nodeFs2 = null;
|
|
361
|
-
_nodePath3 = null;
|
|
362
|
-
_nodeUrl2 = null;
|
|
1195
|
+
init_observability();
|
|
363
1196
|
TwError = class _TwError extends Error {
|
|
364
1197
|
/** @deprecated Gunakan source */
|
|
365
1198
|
domain;
|
|
@@ -393,8 +1226,8 @@ var init_src = __esm({
|
|
|
393
1226
|
/** Buat TwError dari ZodError — dukung shape Zod v3 (`errors`) dan v4 (`issues`). */
|
|
394
1227
|
static fromZod(err) {
|
|
395
1228
|
const first = err.issues?.[0] ?? err.errors?.[0];
|
|
396
|
-
const
|
|
397
|
-
const message = first ? `${
|
|
1229
|
+
const path13 = formatIssuePath(first?.path);
|
|
1230
|
+
const message = first ? `${path13}: ${first.message}` : "Schema validation failed";
|
|
398
1231
|
return new _TwError("validation", "SCHEMA_VALIDATION_FAILED", message, err);
|
|
399
1232
|
}
|
|
400
1233
|
static wrap(source, code, err) {
|
|
@@ -412,13 +1245,57 @@ var init_src = __esm({
|
|
|
412
1245
|
return `[${this.source.toUpperCase()}:${this.code}] ${this.message}`;
|
|
413
1246
|
}
|
|
414
1247
|
};
|
|
415
|
-
_require2 =
|
|
1248
|
+
_require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
1249
|
+
LRUCache = class {
|
|
1250
|
+
capacity;
|
|
1251
|
+
cache;
|
|
1252
|
+
constructor(capacity) {
|
|
1253
|
+
this.capacity = capacity;
|
|
1254
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1255
|
+
}
|
|
1256
|
+
get(key) {
|
|
1257
|
+
if (!this.cache.has(key)) return void 0;
|
|
1258
|
+
const value = this.cache.get(key);
|
|
1259
|
+
this.cache.delete(key);
|
|
1260
|
+
this.cache.set(key, value);
|
|
1261
|
+
return value;
|
|
1262
|
+
}
|
|
1263
|
+
set(key, value) {
|
|
1264
|
+
if (this.cache.has(key)) {
|
|
1265
|
+
this.cache.delete(key);
|
|
1266
|
+
} else if (this.cache.size >= this.capacity) {
|
|
1267
|
+
const firstKey = this.cache.keys().next().value;
|
|
1268
|
+
if (firstKey !== void 0) {
|
|
1269
|
+
this.cache.delete(firstKey);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
this.cache.set(key, value);
|
|
1273
|
+
}
|
|
1274
|
+
delete(key) {
|
|
1275
|
+
return this.cache.delete(key);
|
|
1276
|
+
}
|
|
1277
|
+
has(key) {
|
|
1278
|
+
return this.cache.has(key);
|
|
1279
|
+
}
|
|
1280
|
+
clear() {
|
|
1281
|
+
this.cache.clear();
|
|
1282
|
+
}
|
|
1283
|
+
entries() {
|
|
1284
|
+
return this.cache.entries();
|
|
1285
|
+
}
|
|
1286
|
+
get size() {
|
|
1287
|
+
return this.cache.size;
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
416
1290
|
}
|
|
417
1291
|
});
|
|
418
|
-
|
|
1292
|
+
|
|
1293
|
+
// packages/domain/compiler/src/nativeBridge.ts
|
|
1294
|
+
var _loadNative, log, NATIVE_UNAVAILABLE_MESSAGE, nativeBridge, bridgeLoadAttempted, bridgeLoadError, isValidNativeBridge, getNativeBridge;
|
|
419
1295
|
var init_nativeBridge = __esm({
|
|
420
1296
|
"packages/domain/compiler/src/nativeBridge.ts"() {
|
|
421
1297
|
init_src();
|
|
1298
|
+
_loadNative = (path13) => __require(path13);
|
|
422
1299
|
log = (...args) => {
|
|
423
1300
|
if (process.env.DEBUG?.includes("compiler:native")) {
|
|
424
1301
|
console.log("[compiler:native]", ...args);
|
|
@@ -445,11 +1322,10 @@ var init_nativeBridge = __esm({
|
|
|
445
1322
|
bridgeLoadAttempted = true;
|
|
446
1323
|
try {
|
|
447
1324
|
const runtimeDir = resolveRuntimeDir(void 0, (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
448
|
-
const require3 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
449
1325
|
const result = resolveNativeBinary(runtimeDir);
|
|
450
1326
|
if (result.path && result.path.endsWith(".node")) {
|
|
451
1327
|
try {
|
|
452
|
-
const binding =
|
|
1328
|
+
const binding = _loadNative(result.path);
|
|
453
1329
|
if (isValidNativeBridge(binding)) {
|
|
454
1330
|
nativeBridge = binding;
|
|
455
1331
|
log("Native bridge loaded successfully from:", result.path);
|
|
@@ -481,6 +1357,7 @@ Tried paths: ${result.tried.join("\n")}`);
|
|
|
481
1357
|
var tailwindEngine_exports = {};
|
|
482
1358
|
__export(tailwindEngine_exports, {
|
|
483
1359
|
generateRawCss: () => generateRawCss,
|
|
1360
|
+
processTailwindCssWithTargets: () => processTailwindCssWithTargets,
|
|
484
1361
|
runCssPipeline: () => runCssPipeline,
|
|
485
1362
|
runCssPipelineSync: () => runCssPipelineSync
|
|
486
1363
|
});
|
|
@@ -508,12 +1385,11 @@ function generateRawCss(classes) {
|
|
|
508
1385
|
function postProcessWithLightning(rawCss) {
|
|
509
1386
|
if (!rawCss) return "";
|
|
510
1387
|
const native = getNativeBridge();
|
|
511
|
-
if (typeof native.processTailwindCssLightning
|
|
512
|
-
|
|
513
|
-
return result?.css ?? rawCss;
|
|
1388
|
+
if (typeof native.processTailwindCssLightning !== "function") {
|
|
1389
|
+
throw new Error("FATAL: Native binding 'processTailwindCssLightning' is required but not available.");
|
|
514
1390
|
}
|
|
515
|
-
|
|
516
|
-
return rawCss;
|
|
1391
|
+
const result = native.processTailwindCssLightning(rawCss);
|
|
1392
|
+
return result?.css ?? rawCss;
|
|
517
1393
|
}
|
|
518
1394
|
async function runCssPipeline(classes) {
|
|
519
1395
|
const unique = [...new Set(classes.filter(Boolean))];
|
|
@@ -547,6 +1423,14 @@ function runCssPipelineSync(classes) {
|
|
|
547
1423
|
optimized: hasLightning
|
|
548
1424
|
};
|
|
549
1425
|
}
|
|
1426
|
+
function processTailwindCssWithTargets(css, targets) {
|
|
1427
|
+
const native = getNativeBridge();
|
|
1428
|
+
if (!native?.processTailwindCssWithTargets) {
|
|
1429
|
+
throw new Error("FATAL: Native binding 'processTailwindCssWithTargets' is required but not available.");
|
|
1430
|
+
}
|
|
1431
|
+
const result = native.processTailwindCssWithTargets(css, targets ?? null);
|
|
1432
|
+
return (result?.css ?? css).trim();
|
|
1433
|
+
}
|
|
550
1434
|
var require2, _twEngine, _twEngineError;
|
|
551
1435
|
var init_tailwindEngine = __esm({
|
|
552
1436
|
"packages/domain/compiler/src/tailwindEngine.ts"() {
|
|
@@ -560,14 +1444,26 @@ var init_tailwindEngine = __esm({
|
|
|
560
1444
|
// packages/domain/scanner/src/native-bridge.ts
|
|
561
1445
|
var native_bridge_exports = {};
|
|
562
1446
|
__export(native_bridge_exports, {
|
|
1447
|
+
batchExtractClassesNative: () => batchExtractClassesNative,
|
|
563
1448
|
cachePriorityNative: () => cachePriorityNative,
|
|
564
1449
|
cacheReadNative: () => cacheReadNative,
|
|
565
1450
|
cacheWriteNative: () => cacheWriteNative,
|
|
1451
|
+
collectFilesNative: () => collectFilesNative,
|
|
1452
|
+
computeCacheStatsNative: () => computeCacheStatsNative,
|
|
566
1453
|
extractClassesNative: () => extractClassesNative,
|
|
1454
|
+
generateSubComponentTypesNative: () => generateSubComponentTypesNative,
|
|
567
1455
|
hasNativeScannerBinding: () => hasNativeScannerBinding,
|
|
568
1456
|
hashContentNative: () => hashContentNative,
|
|
569
1457
|
isRustCacheAvailable: () => isRustCacheAvailable,
|
|
1458
|
+
pruneStaleEntriesNative: () => pruneStaleEntriesNative,
|
|
1459
|
+
rebuildWorkspaceResultNative: () => rebuildWorkspaceResultNative,
|
|
570
1460
|
resetScannerBridgeCache: () => resetScannerBridgeCache,
|
|
1461
|
+
scanCacheGet: () => scanCacheGet,
|
|
1462
|
+
scanCacheInvalidate: () => scanCacheInvalidate,
|
|
1463
|
+
scanCachePut: () => scanCachePut,
|
|
1464
|
+
scanCacheStats: () => scanCacheStats,
|
|
1465
|
+
scanFileNative: () => scanFileNative,
|
|
1466
|
+
scanFilesBatchNative: () => scanFilesBatchNative,
|
|
571
1467
|
scanWorkspaceNative: () => scanWorkspaceNative
|
|
572
1468
|
});
|
|
573
1469
|
function getDirname2() {
|
|
@@ -575,7 +1471,7 @@ function getDirname2() {
|
|
|
575
1471
|
return __dirname;
|
|
576
1472
|
}
|
|
577
1473
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)) }) !== "undefined" && (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))) {
|
|
578
|
-
return
|
|
1474
|
+
return path6__namespace.default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))));
|
|
579
1475
|
}
|
|
580
1476
|
return process.cwd();
|
|
581
1477
|
}
|
|
@@ -656,6 +1552,95 @@ function cachePriorityNative(mtimeMs, size, cachedMtimeMs, cachedSize, cachedHit
|
|
|
656
1552
|
}
|
|
657
1553
|
return result;
|
|
658
1554
|
}
|
|
1555
|
+
function batchExtractClassesNative(filePaths) {
|
|
1556
|
+
const binding = scannerGetBinding();
|
|
1557
|
+
if (!binding.batchExtractClasses) {
|
|
1558
|
+
throw new Error("FATAL: Native binding 'batchExtractClasses' is required but not available.");
|
|
1559
|
+
}
|
|
1560
|
+
return binding.batchExtractClasses(filePaths) ?? [];
|
|
1561
|
+
}
|
|
1562
|
+
function scanCacheGet(filePath, contentHash) {
|
|
1563
|
+
const binding = scannerGetBinding();
|
|
1564
|
+
if (!binding.scanCacheGet) {
|
|
1565
|
+
throw new Error("FATAL: Native binding 'scanCacheGet' is required but not available.");
|
|
1566
|
+
}
|
|
1567
|
+
return binding.scanCacheGet(filePath, contentHash) ?? null;
|
|
1568
|
+
}
|
|
1569
|
+
function scanCachePut(filePath, contentHash, classes, mtimeMs, size) {
|
|
1570
|
+
const binding = scannerGetBinding();
|
|
1571
|
+
if (!binding.scanCachePut) {
|
|
1572
|
+
throw new Error("FATAL: Native binding 'scanCachePut' is required but not available.");
|
|
1573
|
+
}
|
|
1574
|
+
binding.scanCachePut(filePath, contentHash, classes, mtimeMs, size);
|
|
1575
|
+
}
|
|
1576
|
+
function scanCacheInvalidate(filePath) {
|
|
1577
|
+
const binding = scannerGetBinding();
|
|
1578
|
+
if (!binding.scanCacheInvalidate) {
|
|
1579
|
+
throw new Error("FATAL: Native binding 'scanCacheInvalidate' is required but not available.");
|
|
1580
|
+
}
|
|
1581
|
+
binding.scanCacheInvalidate(filePath);
|
|
1582
|
+
}
|
|
1583
|
+
function scanCacheStats() {
|
|
1584
|
+
const binding = scannerGetBinding();
|
|
1585
|
+
if (!binding.scanCacheStats) {
|
|
1586
|
+
throw new Error("FATAL: Native binding 'scanCacheStats' is required but not available.");
|
|
1587
|
+
}
|
|
1588
|
+
return binding.scanCacheStats();
|
|
1589
|
+
}
|
|
1590
|
+
function scanFileNative(filePath) {
|
|
1591
|
+
const binding = scannerGetBinding();
|
|
1592
|
+
if (!binding.scanFile) {
|
|
1593
|
+
throw new Error("FATAL: Native binding 'scanFile' is required but not available.");
|
|
1594
|
+
}
|
|
1595
|
+
return binding.scanFile(filePath);
|
|
1596
|
+
}
|
|
1597
|
+
function collectFilesNative(root, extensions, ignoreDirs) {
|
|
1598
|
+
const binding = scannerGetBinding();
|
|
1599
|
+
if (!binding.collectFiles) return null;
|
|
1600
|
+
return binding.collectFiles(root, extensions, ignoreDirs);
|
|
1601
|
+
}
|
|
1602
|
+
function scanFilesBatchNative(filePaths) {
|
|
1603
|
+
const binding = scannerGetBinding();
|
|
1604
|
+
if (!binding.scanFilesBatch) {
|
|
1605
|
+
return filePaths.map((fp) => {
|
|
1606
|
+
try {
|
|
1607
|
+
const r = binding.scanFile?.(fp);
|
|
1608
|
+
return r ? { file: r.file, classes: r.classes, hash: r.hash ?? "" } : { file: fp, classes: [], hash: "" };
|
|
1609
|
+
} catch {
|
|
1610
|
+
return { file: fp, classes: [], hash: "" };
|
|
1611
|
+
}
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
return binding.scanFilesBatch(filePaths);
|
|
1615
|
+
}
|
|
1616
|
+
function generateSubComponentTypesNative(root, outputPath) {
|
|
1617
|
+
const binding = scannerGetBinding();
|
|
1618
|
+
if (!binding.generateSubComponentTypes) return null;
|
|
1619
|
+
return binding.generateSubComponentTypes(root, outputPath ?? null);
|
|
1620
|
+
}
|
|
1621
|
+
function pruneStaleEntriesNative(entries, maxAgeMs, checkExists) {
|
|
1622
|
+
const binding = scannerGetBinding();
|
|
1623
|
+
if (!binding.pruneStaleEntries) return null;
|
|
1624
|
+
return binding.pruneStaleEntries(
|
|
1625
|
+
entries.map((e) => ({ file: e.file, lastSeenMs: e.lastSeenMs ?? 0 })),
|
|
1626
|
+
maxAgeMs ?? null,
|
|
1627
|
+
checkExists ?? null
|
|
1628
|
+
);
|
|
1629
|
+
}
|
|
1630
|
+
function rebuildWorkspaceResultNative(files) {
|
|
1631
|
+
const binding = scannerBridgeLoader.get();
|
|
1632
|
+
if (!binding?.rebuildWorkspaceResult) return null;
|
|
1633
|
+
try {
|
|
1634
|
+
return binding.rebuildWorkspaceResult(files);
|
|
1635
|
+
} catch {
|
|
1636
|
+
return null;
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
function computeCacheStatsNative(filesClasses, sizes, top) {
|
|
1640
|
+
const binding = scannerGetBinding();
|
|
1641
|
+
if (!binding.computeCacheStats) return null;
|
|
1642
|
+
return binding.computeCacheStats(filesClasses, sizes, top ?? null);
|
|
1643
|
+
}
|
|
659
1644
|
var log2, isValidScannerBinding, createScannerBridgeLoader, scannerBridgeLoader, scannerGetBinding, resetScannerBridgeCache;
|
|
660
1645
|
var init_native_bridge = __esm({
|
|
661
1646
|
"packages/domain/scanner/src/native-bridge.ts"() {
|
|
@@ -739,74 +1724,9 @@ var init_native_bridge = __esm({
|
|
|
739
1724
|
resetScannerBridgeCache = scannerBridgeLoader.reset;
|
|
740
1725
|
}
|
|
741
1726
|
});
|
|
742
|
-
|
|
743
|
-
// packages/domain/compiler/src/index.ts
|
|
744
|
-
init_nativeBridge();
|
|
745
|
-
var transformSource = (source, opts) => {
|
|
746
|
-
const native = getNativeBridge();
|
|
747
|
-
if (!native?.transformSource) {
|
|
748
|
-
throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
|
|
749
|
-
}
|
|
750
|
-
const result = native.transformSource(source, opts);
|
|
751
|
-
if (!result) {
|
|
752
|
-
throw new Error("FATAL: transformSource returned null");
|
|
753
|
-
}
|
|
754
|
-
return result;
|
|
755
|
-
};
|
|
756
|
-
var generateCssForClasses = async (classes, _tailwindConfig, _root) => {
|
|
757
|
-
const { runCssPipeline: runCssPipeline2 } = await Promise.resolve().then(() => (init_tailwindEngine(), tailwindEngine_exports));
|
|
758
|
-
const result = await runCssPipeline2(classes);
|
|
759
|
-
return result.css;
|
|
760
|
-
};
|
|
761
|
-
var mergeClassesStatic = (classes) => {
|
|
762
|
-
const result = normalizeAndDedupClasses(classes);
|
|
763
|
-
return result?.normalized || "";
|
|
764
|
-
};
|
|
765
|
-
function normalizeAndDedupClassesJs(raw) {
|
|
766
|
-
const seen = /* @__PURE__ */ new Set();
|
|
767
|
-
const result = [];
|
|
768
|
-
let duplicatesRemoved = 0;
|
|
769
|
-
for (const token of raw.split(/\s+/)) {
|
|
770
|
-
if (token.length === 0) continue;
|
|
771
|
-
if (seen.has(token)) {
|
|
772
|
-
duplicatesRemoved++;
|
|
773
|
-
} else {
|
|
774
|
-
seen.add(token);
|
|
775
|
-
result.push(token);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
return {
|
|
779
|
-
normalized: result.join(" "),
|
|
780
|
-
duplicatesRemoved,
|
|
781
|
-
uniqueCount: result.length
|
|
782
|
-
};
|
|
783
|
-
}
|
|
784
|
-
var normalizeAndDedupClasses = (raw) => {
|
|
785
|
-
const native = getNativeBridge();
|
|
786
|
-
if (!native?.normalizeAndDedupClasses) {
|
|
787
|
-
return normalizeAndDedupClassesJs(raw);
|
|
788
|
-
}
|
|
789
|
-
const result = native.normalizeAndDedupClasses(raw);
|
|
790
|
-
return result || { normalized: "", duplicatesRemoved: 0, uniqueCount: 0 };
|
|
791
|
-
};
|
|
792
|
-
var runLoaderTransform = (ctx) => {
|
|
793
|
-
const { filepath, source, options } = ctx;
|
|
794
|
-
const result = transformSource(source, { filename: filepath, ...options });
|
|
795
|
-
return {
|
|
796
|
-
code: result?.code || "",
|
|
797
|
-
changed: result?.changed || false,
|
|
798
|
-
classes: result?.classes || []
|
|
799
|
-
};
|
|
800
|
-
};
|
|
801
|
-
|
|
802
|
-
// packages/domain/scanner/src/index.ts
|
|
803
|
-
init_src();
|
|
804
|
-
|
|
805
|
-
// packages/domain/scanner/src/cache-native.ts
|
|
806
|
-
init_native_bridge();
|
|
807
1727
|
function defaultCachePath(rootDir, cacheDir) {
|
|
808
|
-
const dir = cacheDir ?
|
|
809
|
-
return
|
|
1728
|
+
const dir = cacheDir ? path6__namespace.default.resolve(rootDir, cacheDir) : path6__namespace.default.join(process.cwd(), ".cache", "tailwind-styled");
|
|
1729
|
+
return path6__namespace.default.join(dir, "scanner-cache.json");
|
|
810
1730
|
}
|
|
811
1731
|
function readCache(rootDir, cacheDir) {
|
|
812
1732
|
const cachePath = defaultCachePath(rootDir, cacheDir);
|
|
@@ -842,158 +1762,219 @@ function filePriority(mtimeMs, size, cached, nowMs = Date.now()) {
|
|
|
842
1762
|
nowMs
|
|
843
1763
|
);
|
|
844
1764
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
init_native_bridge();
|
|
848
|
-
|
|
849
|
-
// packages/domain/scanner/src/schemas.ts
|
|
850
|
-
init_src();
|
|
851
|
-
var formatIssuePath2 = (path11) => path11.length > 0 ? path11.map(
|
|
852
|
-
(segment) => typeof segment === "symbol" ? segment.description ?? segment.toString() : String(segment)
|
|
853
|
-
).join(".") : "<root>";
|
|
854
|
-
var formatIssues = (error) => error.issues.map((issue) => {
|
|
855
|
-
const path11 = formatIssuePath2(issue.path);
|
|
856
|
-
return `${path11}: ${issue.message}`;
|
|
857
|
-
}).join("; ");
|
|
858
|
-
var parseWithSchema = (schema, data, label) => {
|
|
859
|
-
const parsed = schema.safeParse(data);
|
|
860
|
-
if (parsed.success) return parsed.data;
|
|
861
|
-
const details = formatIssues(parsed.error);
|
|
862
|
-
throw new TwError(
|
|
863
|
-
"validation",
|
|
864
|
-
"SCHEMA_VALIDATION_FAILED",
|
|
865
|
-
details ? `${label}: ${details}` : label,
|
|
866
|
-
parsed.error
|
|
867
|
-
);
|
|
868
|
-
};
|
|
869
|
-
var NonNegativeIntegerSchema = zod.z.number().int().min(0);
|
|
870
|
-
var ScanWorkspaceOptionsSchema = zod.z.object({
|
|
871
|
-
includeExtensions: zod.z.array(zod.z.string()).optional(),
|
|
872
|
-
ignoreDirectories: zod.z.array(zod.z.string()).optional(),
|
|
873
|
-
useCache: zod.z.boolean().optional(),
|
|
874
|
-
cacheDir: zod.z.string().min(1).optional(),
|
|
875
|
-
smartInvalidation: zod.z.boolean().optional()
|
|
876
|
-
});
|
|
877
|
-
var ScanFileResultSchema = zod.z.object({
|
|
878
|
-
file: zod.z.string(),
|
|
879
|
-
classes: zod.z.array(zod.z.string()),
|
|
880
|
-
hash: zod.z.string().optional()
|
|
881
|
-
});
|
|
882
|
-
var ScanWorkspaceResultSchema = zod.z.object({
|
|
883
|
-
files: zod.z.array(ScanFileResultSchema),
|
|
884
|
-
totalFiles: NonNegativeIntegerSchema,
|
|
885
|
-
uniqueClasses: zod.z.array(zod.z.string())
|
|
886
|
-
}).refine((value) => value.totalFiles === value.files.length, {
|
|
887
|
-
message: "scan result totalFiles must match files.length",
|
|
888
|
-
path: ["totalFiles"]
|
|
889
|
-
});
|
|
890
|
-
zod.z.object({
|
|
891
|
-
rootDir: zod.z.string().min(1),
|
|
892
|
-
options: ScanWorkspaceOptionsSchema.optional()
|
|
1765
|
+
var init_cache_native = __esm({
|
|
1766
|
+
"packages/domain/scanner/src/cache-native.ts"() {
|
|
1767
|
+
init_native_bridge();
|
|
1768
|
+
}
|
|
893
1769
|
});
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
1770
|
+
function collectFiles(rootDir, extensions, ignoreDirs) {
|
|
1771
|
+
const native = collectFilesNative(rootDir, extensions, ignoreDirs);
|
|
1772
|
+
if (native !== null) return native;
|
|
1773
|
+
const files = [];
|
|
1774
|
+
function walk(dir) {
|
|
1775
|
+
let entries;
|
|
1776
|
+
try {
|
|
1777
|
+
entries = fs4__namespace.default.readdirSync(dir, { withFileTypes: true });
|
|
1778
|
+
} catch {
|
|
1779
|
+
return;
|
|
1780
|
+
}
|
|
1781
|
+
for (const entry of entries) {
|
|
1782
|
+
const fullPath = path6__namespace.default.join(dir, entry.name);
|
|
1783
|
+
const rel = path6__namespace.default.relative(rootDir, fullPath);
|
|
1784
|
+
if (entry.isDirectory()) {
|
|
1785
|
+
const ignored = ignoreDirs.some((d) => entry.name === d || rel.startsWith(d + path6__namespace.default.sep));
|
|
1786
|
+
if (!ignored) walk(fullPath);
|
|
1787
|
+
} else if (isScannableFile(entry.name, extensions)) {
|
|
1788
|
+
files.push(fullPath);
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
walk(rootDir);
|
|
1793
|
+
return files;
|
|
1794
|
+
}
|
|
1795
|
+
function mergeResults(batchResults) {
|
|
1796
|
+
const files = batchResults.map((r) => ({
|
|
1797
|
+
file: r.file,
|
|
1798
|
+
classes: r.classes,
|
|
1799
|
+
hash: r.content_hash
|
|
1800
|
+
}));
|
|
1801
|
+
const native = rebuildWorkspaceResultNative(files);
|
|
1802
|
+
if (native) return native;
|
|
1803
|
+
const unique = new Set(files.flatMap((f) => f.classes));
|
|
1804
|
+
return { files, totalFiles: files.length, uniqueClasses: Array.from(unique).sort() };
|
|
1805
|
+
}
|
|
1806
|
+
function runChunkInWorker(filePaths) {
|
|
1807
|
+
return new Promise((resolve2, reject) => {
|
|
1808
|
+
const worker = new worker_threads.Worker(_workerFilename, {
|
|
1809
|
+
workerData: { filePaths }
|
|
1810
|
+
});
|
|
1811
|
+
worker.once("message", (payload) => {
|
|
1812
|
+
if (payload.ok) {
|
|
1813
|
+
resolve2(payload.results);
|
|
1814
|
+
} else {
|
|
1815
|
+
reject(new Error(payload.error ?? "parallel-scanner worker failed"));
|
|
1816
|
+
}
|
|
1817
|
+
});
|
|
1818
|
+
worker.once("error", reject);
|
|
1819
|
+
worker.once("exit", (code) => {
|
|
1820
|
+
if (code !== 0) reject(new Error(`parallel-scanner worker exited with code ${code}`));
|
|
1821
|
+
});
|
|
1822
|
+
});
|
|
1823
|
+
}
|
|
1824
|
+
async function scanWorkspaceParallel(rootDir, options = {}) {
|
|
1825
|
+
const {
|
|
1826
|
+
extensions = DEFAULT_EXTENSIONS,
|
|
1827
|
+
ignoreDirs = DEFAULT_IGNORES,
|
|
1828
|
+
maxWorkers = Math.max(1, os.availableParallelism() - 1),
|
|
1829
|
+
chunkSize = DEFAULT_CHUNK_SIZE
|
|
1830
|
+
} = options;
|
|
1831
|
+
const files = collectFiles(path6__namespace.default.resolve(rootDir), extensions, ignoreDirs);
|
|
1832
|
+
if (files.length < PARALLEL_THRESHOLD) {
|
|
1833
|
+
return mergeResults(batchExtractClassesNative(files));
|
|
1834
|
+
}
|
|
1835
|
+
const chunks = [];
|
|
1836
|
+
for (let i = 0; i < files.length; i += chunkSize) {
|
|
1837
|
+
chunks.push(files.slice(i, i + chunkSize));
|
|
1838
|
+
}
|
|
1839
|
+
const allResults = [];
|
|
1840
|
+
for (let i = 0; i < chunks.length; i += maxWorkers) {
|
|
1841
|
+
const batch = chunks.slice(i, i + maxWorkers);
|
|
1842
|
+
const batchResults = await Promise.all(batch.map(runChunkInWorker));
|
|
1843
|
+
allResults.push(...batchResults.flat());
|
|
1844
|
+
}
|
|
1845
|
+
return mergeResults(allResults);
|
|
1846
|
+
}
|
|
1847
|
+
var PARALLEL_THRESHOLD, DEFAULT_CHUNK_SIZE, _workerFilename;
|
|
1848
|
+
var init_parallel_scanner = __esm({
|
|
1849
|
+
"packages/domain/scanner/src/parallel-scanner.ts"() {
|
|
1850
|
+
init_src2();
|
|
1851
|
+
init_native_bridge();
|
|
1852
|
+
PARALLEL_THRESHOLD = 50;
|
|
1853
|
+
DEFAULT_CHUNK_SIZE = 150;
|
|
1854
|
+
if (!worker_threads.isMainThread && worker_threads.parentPort) {
|
|
1855
|
+
const { filePaths } = worker_threads.workerData;
|
|
1856
|
+
try {
|
|
1857
|
+
const results = batchExtractClassesNative(filePaths);
|
|
1858
|
+
const msg = { ok: true, results };
|
|
1859
|
+
worker_threads.parentPort.postMessage(msg);
|
|
1860
|
+
} catch (error) {
|
|
1861
|
+
const msg = {
|
|
1862
|
+
ok: false,
|
|
1863
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1864
|
+
};
|
|
1865
|
+
worker_threads.parentPort.postMessage(msg);
|
|
1866
|
+
}
|
|
1867
|
+
}
|
|
1868
|
+
_workerFilename = typeof __filename !== "undefined" ? __filename : url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
1869
|
+
}
|
|
897
1870
|
});
|
|
898
|
-
var ScannerWorkerErrorMessageSchema
|
|
899
|
-
|
|
900
|
-
|
|
1871
|
+
var formatIssuePath2, formatIssues, parseWithSchema, NonNegativeIntegerSchema, ScanWorkspaceOptionsSchema, ScanFileResultSchema, ScanWorkspaceResultSchema, ScannerWorkerSuccessMessageSchema, ScannerWorkerErrorMessageSchema, ScannerWorkerMessageSchema, parseScanWorkspaceOptions, parseScanWorkspaceResult, parseScannerWorkerMessage;
|
|
1872
|
+
var init_schemas = __esm({
|
|
1873
|
+
"packages/domain/scanner/src/schemas.ts"() {
|
|
1874
|
+
init_src();
|
|
1875
|
+
formatIssuePath2 = (path13) => path13.length > 0 ? path13.map(
|
|
1876
|
+
(segment) => typeof segment === "symbol" ? segment.description ?? segment.toString() : String(segment)
|
|
1877
|
+
).join(".") : "<root>";
|
|
1878
|
+
formatIssues = (error) => error.issues.map((issue) => {
|
|
1879
|
+
const path13 = formatIssuePath2(issue.path);
|
|
1880
|
+
return `${path13}: ${issue.message}`;
|
|
1881
|
+
}).join("; ");
|
|
1882
|
+
parseWithSchema = (schema, data, label) => {
|
|
1883
|
+
const parsed = schema.safeParse(data);
|
|
1884
|
+
if (parsed.success) return parsed.data;
|
|
1885
|
+
const details = formatIssues(parsed.error);
|
|
1886
|
+
throw new TwError(
|
|
1887
|
+
"validation",
|
|
1888
|
+
"SCHEMA_VALIDATION_FAILED",
|
|
1889
|
+
details ? `${label}: ${details}` : label,
|
|
1890
|
+
parsed.error
|
|
1891
|
+
);
|
|
1892
|
+
};
|
|
1893
|
+
NonNegativeIntegerSchema = zod.z.number().int().min(0);
|
|
1894
|
+
ScanWorkspaceOptionsSchema = zod.z.object({
|
|
1895
|
+
includeExtensions: zod.z.array(zod.z.string()).optional(),
|
|
1896
|
+
ignoreDirectories: zod.z.array(zod.z.string()).optional(),
|
|
1897
|
+
useCache: zod.z.boolean().optional(),
|
|
1898
|
+
cacheDir: zod.z.string().min(1).optional(),
|
|
1899
|
+
smartInvalidation: zod.z.boolean().optional()
|
|
1900
|
+
});
|
|
1901
|
+
ScanFileResultSchema = zod.z.object({
|
|
1902
|
+
file: zod.z.string(),
|
|
1903
|
+
classes: zod.z.array(zod.z.string()),
|
|
1904
|
+
hash: zod.z.string().optional()
|
|
1905
|
+
});
|
|
1906
|
+
ScanWorkspaceResultSchema = zod.z.object({
|
|
1907
|
+
files: zod.z.array(ScanFileResultSchema),
|
|
1908
|
+
totalFiles: NonNegativeIntegerSchema,
|
|
1909
|
+
uniqueClasses: zod.z.array(zod.z.string())
|
|
1910
|
+
}).refine((value) => value.totalFiles === value.files.length, {
|
|
1911
|
+
message: "scan result totalFiles must match files.length",
|
|
1912
|
+
path: ["totalFiles"]
|
|
1913
|
+
});
|
|
1914
|
+
zod.z.object({
|
|
1915
|
+
rootDir: zod.z.string().min(1),
|
|
1916
|
+
options: ScanWorkspaceOptionsSchema.optional()
|
|
1917
|
+
});
|
|
1918
|
+
ScannerWorkerSuccessMessageSchema = zod.z.object({
|
|
1919
|
+
ok: zod.z.literal(true),
|
|
1920
|
+
result: ScanWorkspaceResultSchema
|
|
1921
|
+
});
|
|
1922
|
+
ScannerWorkerErrorMessageSchema = zod.z.object({
|
|
1923
|
+
ok: zod.z.literal(false),
|
|
1924
|
+
error: zod.z.string().optional()
|
|
1925
|
+
});
|
|
1926
|
+
ScannerWorkerMessageSchema = zod.z.union([
|
|
1927
|
+
ScannerWorkerSuccessMessageSchema,
|
|
1928
|
+
ScannerWorkerErrorMessageSchema
|
|
1929
|
+
]);
|
|
1930
|
+
parseScanWorkspaceOptions = (options) => parseWithSchema(ScanWorkspaceOptionsSchema, options ?? {}, "scanner options are invalid");
|
|
1931
|
+
parseScanWorkspaceResult = (result) => parseWithSchema(ScanWorkspaceResultSchema, result, "scanner workspace result is invalid");
|
|
1932
|
+
parseScannerWorkerMessage = (message) => parseWithSchema(ScannerWorkerMessageSchema, message, "scanner worker message is invalid");
|
|
1933
|
+
}
|
|
901
1934
|
});
|
|
902
|
-
var ScannerWorkerMessageSchema = zod.z.union([
|
|
903
|
-
ScannerWorkerSuccessMessageSchema,
|
|
904
|
-
ScannerWorkerErrorMessageSchema
|
|
905
|
-
]);
|
|
906
|
-
var parseScanWorkspaceOptions = (options) => parseWithSchema(ScanWorkspaceOptionsSchema, options ?? {}, "scanner options are invalid");
|
|
907
|
-
var parseScanWorkspaceResult = (result) => parseWithSchema(ScanWorkspaceResultSchema, result, "scanner workspace result is invalid");
|
|
908
|
-
var parseScannerWorkerMessage = (message) => parseWithSchema(ScannerWorkerMessageSchema, message, "scanner worker message is invalid");
|
|
909
1935
|
|
|
910
1936
|
// packages/domain/scanner/src/index.ts
|
|
911
|
-
var
|
|
912
|
-
|
|
1937
|
+
var src_exports2 = {};
|
|
1938
|
+
__export(src_exports2, {
|
|
1939
|
+
DEFAULT_EXTENSIONS: () => DEFAULT_EXTENSIONS,
|
|
1940
|
+
DEFAULT_IGNORES: () => DEFAULT_IGNORES,
|
|
1941
|
+
batchExtractClassesNative: () => batchExtractClassesNative,
|
|
1942
|
+
extractClassesNative: () => extractClassesNative,
|
|
1943
|
+
isScannableFile: () => isScannableFile,
|
|
1944
|
+
parseScanWorkspaceOptions: () => parseScanWorkspaceOptions,
|
|
1945
|
+
parseScanWorkspaceResult: () => parseScanWorkspaceResult,
|
|
1946
|
+
parseScannerWorkerMessage: () => parseScannerWorkerMessage,
|
|
1947
|
+
scanFile: () => scanFile,
|
|
1948
|
+
scanSource: () => scanSource,
|
|
1949
|
+
scanWorkspace: () => scanWorkspace,
|
|
1950
|
+
scanWorkspaceAsync: () => scanWorkspaceAsync
|
|
1951
|
+
});
|
|
913
1952
|
function getRuntimeDir() {
|
|
914
1953
|
if (typeof __dirname !== "undefined" && __dirname.length > 0) {
|
|
915
1954
|
return __dirname;
|
|
916
1955
|
}
|
|
917
1956
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)) }) !== "undefined" && (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))) {
|
|
918
|
-
return
|
|
1957
|
+
return path6__namespace.default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))));
|
|
919
1958
|
}
|
|
920
1959
|
return process.cwd();
|
|
921
|
-
}
|
|
922
|
-
var createNativeParserLoader = () => {
|
|
923
|
-
const _state = {
|
|
924
|
-
binding: void 0,
|
|
925
|
-
initError: null
|
|
926
|
-
};
|
|
927
|
-
const debugNative = (message) => {
|
|
928
|
-
log3.debug(`[native] ${message}`);
|
|
929
|
-
};
|
|
930
|
-
const loadNativeParserBinding = () => {
|
|
931
|
-
if (_state.binding !== void 0) return _state.binding;
|
|
932
|
-
const runtimeDir = getRuntimeDir();
|
|
933
|
-
const req = module$1.createRequire(path3__default.default.join(runtimeDir, "noop.cjs"));
|
|
934
|
-
const candidates = [
|
|
935
|
-
path3__default.default.resolve(process.cwd(), "native/tailwind_styled_parser.node"),
|
|
936
|
-
path3__default.default.resolve(process.cwd(), "native/build/Release/tailwind_styled_parser.node"),
|
|
937
|
-
path3__default.default.resolve(runtimeDir, "..", "..", "..", "native", "tailwind_styled_parser.node"),
|
|
938
|
-
path3__default.default.resolve(
|
|
939
|
-
runtimeDir,
|
|
940
|
-
"..",
|
|
941
|
-
"..",
|
|
942
|
-
"..",
|
|
943
|
-
"native",
|
|
944
|
-
"build",
|
|
945
|
-
"Release",
|
|
946
|
-
"tailwind_styled_parser.node"
|
|
947
|
-
)
|
|
948
|
-
];
|
|
949
|
-
for (const fullPath of candidates) {
|
|
950
|
-
if (!fs__default.default.existsSync(fullPath)) continue;
|
|
951
|
-
try {
|
|
952
|
-
const required = req(fullPath);
|
|
953
|
-
if (required && (typeof required.extractClassesFromSource === "function" || typeof required.parseClasses === "function" || typeof required.parse_classes === "function")) {
|
|
954
|
-
_state.binding = required;
|
|
955
|
-
debugNative(`using native parser from ${fullPath}`);
|
|
956
|
-
return _state.binding;
|
|
957
|
-
}
|
|
958
|
-
} catch (error) {
|
|
959
|
-
_state.initError = error instanceof Error ? error.message : String(error);
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
_state.binding = null;
|
|
963
|
-
if (!_state.initError) {
|
|
964
|
-
_state.initError = "native .node binding not found";
|
|
965
|
-
}
|
|
966
|
-
debugNative(`native binding not available: ${_state.initError}`);
|
|
967
|
-
return _state.binding;
|
|
968
|
-
};
|
|
969
|
-
return {
|
|
970
|
-
get: loadNativeParserBinding,
|
|
971
|
-
reset: () => {
|
|
972
|
-
_state.binding = void 0;
|
|
973
|
-
_state.initError = null;
|
|
974
|
-
}
|
|
975
|
-
};
|
|
976
|
-
};
|
|
977
|
-
var nativeParserLoader = createNativeParserLoader();
|
|
978
|
-
var DEFAULT_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
979
|
-
var DEFAULT_IGNORES = ["node_modules", ".git", ".next", "dist", "out", ".turbo", ".cache"];
|
|
1960
|
+
}
|
|
980
1961
|
function resolveScannerWorkerModulePath() {
|
|
981
1962
|
const runtimeDir = (() => {
|
|
982
1963
|
if (typeof __dirname !== "undefined" && __dirname.length > 0) {
|
|
983
1964
|
return __dirname;
|
|
984
1965
|
}
|
|
985
1966
|
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)) }) !== "undefined" && (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))) {
|
|
986
|
-
return
|
|
1967
|
+
return path6__namespace.default.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))));
|
|
987
1968
|
}
|
|
988
1969
|
return process.cwd();
|
|
989
1970
|
})();
|
|
990
1971
|
const candidates = [
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1972
|
+
path6__namespace.default.resolve(runtimeDir, "worker.cjs"),
|
|
1973
|
+
path6__namespace.default.resolve(runtimeDir, "worker.js"),
|
|
1974
|
+
path6__namespace.default.resolve(runtimeDir, "worker.ts")
|
|
994
1975
|
];
|
|
995
1976
|
for (const candidate of candidates) {
|
|
996
|
-
if (
|
|
1977
|
+
if (fs4__namespace.default.existsSync(candidate)) return candidate;
|
|
997
1978
|
}
|
|
998
1979
|
return null;
|
|
999
1980
|
}
|
|
@@ -1003,7 +1984,7 @@ function scanWorkspaceInWorker(rootDir, options) {
|
|
|
1003
1984
|
if (!modulePath) {
|
|
1004
1985
|
return Promise.reject(new Error("scanner worker module path could not be resolved"));
|
|
1005
1986
|
}
|
|
1006
|
-
return new Promise((
|
|
1987
|
+
return new Promise((resolve2, reject) => {
|
|
1007
1988
|
const settleState = { settled: false };
|
|
1008
1989
|
const worker = new worker_threads.Worker(modulePath, { workerData: { rootDir, options: normalizedOptions } });
|
|
1009
1990
|
const timeout = setTimeout(() => {
|
|
@@ -1023,7 +2004,7 @@ function scanWorkspaceInWorker(rootDir, options) {
|
|
|
1023
2004
|
const message = parseScannerWorkerMessage(payload);
|
|
1024
2005
|
finish(() => {
|
|
1025
2006
|
if (message?.ok) {
|
|
1026
|
-
|
|
2007
|
+
resolve2(parseScanWorkspaceResult(message.result));
|
|
1027
2008
|
return;
|
|
1028
2009
|
}
|
|
1029
2010
|
reject(new Error(message?.error ?? "scanner worker failed without an error message"));
|
|
@@ -1050,19 +2031,19 @@ function collectCandidates(rootDir, ignoreDirectories, extensionSet) {
|
|
|
1050
2031
|
if (!currentDir) continue;
|
|
1051
2032
|
const entries = (() => {
|
|
1052
2033
|
try {
|
|
1053
|
-
return
|
|
2034
|
+
return fs4__namespace.default.readdirSync(currentDir, { withFileTypes: true });
|
|
1054
2035
|
} catch {
|
|
1055
2036
|
return [];
|
|
1056
2037
|
}
|
|
1057
2038
|
})();
|
|
1058
2039
|
for (const entry of entries) {
|
|
1059
|
-
const fullPath =
|
|
2040
|
+
const fullPath = path6__namespace.default.join(currentDir, entry.name);
|
|
1060
2041
|
if (entry.isDirectory()) {
|
|
1061
2042
|
if (!ignoreDirectories.has(entry.name)) directories.push(fullPath);
|
|
1062
2043
|
continue;
|
|
1063
2044
|
}
|
|
1064
2045
|
if (!entry.isFile()) continue;
|
|
1065
|
-
if (!extensionSet.has(
|
|
2046
|
+
if (!extensionSet.has(path6__namespace.default.extname(entry.name))) continue;
|
|
1066
2047
|
candidates.push(fullPath);
|
|
1067
2048
|
}
|
|
1068
2049
|
}
|
|
@@ -1076,9 +2057,12 @@ function toCacheSize(size) {
|
|
|
1076
2057
|
function scanSource(source) {
|
|
1077
2058
|
const nativeBinding = nativeParserLoader.get();
|
|
1078
2059
|
if (nativeBinding?.extractClassesFromSource) {
|
|
1079
|
-
const
|
|
1080
|
-
if (Array.isArray(
|
|
1081
|
-
return Array.from(new Set(
|
|
2060
|
+
const result = nativeBinding.extractClassesFromSource(source);
|
|
2061
|
+
if (Array.isArray(result)) {
|
|
2062
|
+
return Array.from(new Set(result.filter(Boolean)));
|
|
2063
|
+
}
|
|
2064
|
+
if (result !== null && result !== void 0 && Array.isArray(result.classes)) {
|
|
2065
|
+
return Array.from(new Set(result.classes.filter(Boolean)));
|
|
1082
2066
|
}
|
|
1083
2067
|
}
|
|
1084
2068
|
throw new Error(
|
|
@@ -1086,15 +2070,18 @@ function scanSource(source) {
|
|
|
1086
2070
|
);
|
|
1087
2071
|
}
|
|
1088
2072
|
function isScannableFile(filePath, includeExtensions = DEFAULT_EXTENSIONS) {
|
|
1089
|
-
return includeExtensions.includes(
|
|
2073
|
+
return includeExtensions.includes(path6__namespace.default.extname(filePath));
|
|
1090
2074
|
}
|
|
1091
2075
|
function scanFile(filePath) {
|
|
1092
|
-
const
|
|
1093
|
-
const
|
|
2076
|
+
const { scanFileNative: scanFileNative2 } = (init_native_bridge(), __toCommonJS(native_bridge_exports));
|
|
2077
|
+
const result = scanFileNative2(filePath);
|
|
2078
|
+
if (!result.ok) {
|
|
2079
|
+
throw new Error(`scanFile failed for ${filePath}: ${result.error ?? "unknown error"}`);
|
|
2080
|
+
}
|
|
1094
2081
|
return {
|
|
1095
|
-
file:
|
|
1096
|
-
classes:
|
|
1097
|
-
...hash ? { hash } : {}
|
|
2082
|
+
file: result.file,
|
|
2083
|
+
classes: result.classes,
|
|
2084
|
+
...result.hash ? { hash: result.hash } : {}
|
|
1098
2085
|
};
|
|
1099
2086
|
}
|
|
1100
2087
|
function scanWorkspace(rootDir, options = {}) {
|
|
@@ -1143,7 +2130,7 @@ function scanWorkspace(rootDir, options = {}) {
|
|
|
1143
2130
|
for (const filePath of candidates) {
|
|
1144
2131
|
const stat = (() => {
|
|
1145
2132
|
try {
|
|
1146
|
-
return
|
|
2133
|
+
return fs4__namespace.default.statSync(filePath);
|
|
1147
2134
|
} catch {
|
|
1148
2135
|
return null;
|
|
1149
2136
|
}
|
|
@@ -1169,7 +2156,7 @@ function scanWorkspace(rootDir, options = {}) {
|
|
|
1169
2156
|
for (const { filePath, stat, size, cached } of ranked) {
|
|
1170
2157
|
const content = (() => {
|
|
1171
2158
|
try {
|
|
1172
|
-
return
|
|
2159
|
+
return fs4__namespace.default.readFileSync(filePath, "utf8");
|
|
1173
2160
|
} catch {
|
|
1174
2161
|
return null;
|
|
1175
2162
|
}
|
|
@@ -1231,18 +2218,245 @@ function scanWorkspace(rootDir, options = {}) {
|
|
|
1231
2218
|
}
|
|
1232
2219
|
async function scanWorkspaceAsync(rootDir, options = {}) {
|
|
1233
2220
|
const normalizedOptions = parseScanWorkspaceOptions(options);
|
|
1234
|
-
|
|
1235
|
-
return
|
|
2221
|
+
try {
|
|
2222
|
+
return await scanWorkspaceParallel(rootDir, {
|
|
2223
|
+
extensions: normalizedOptions.includeExtensions,
|
|
2224
|
+
ignoreDirs: normalizedOptions.ignoreDirectories
|
|
2225
|
+
});
|
|
2226
|
+
} catch (parallelError) {
|
|
2227
|
+
log3.debug(
|
|
2228
|
+
`parallel scan failed, retrying with single worker: ${parallelError instanceof Error ? parallelError.message : String(parallelError)}`
|
|
2229
|
+
);
|
|
1236
2230
|
}
|
|
1237
2231
|
try {
|
|
1238
2232
|
return await scanWorkspaceInWorker(rootDir, normalizedOptions);
|
|
1239
2233
|
} catch (error) {
|
|
1240
2234
|
log3.debug(
|
|
1241
|
-
`worker scan failed,
|
|
2235
|
+
`worker scan failed, retrying with sync native scanner: ${error instanceof Error ? error.message : String(error)}`
|
|
1242
2236
|
);
|
|
1243
2237
|
return scanWorkspace(rootDir, normalizedOptions);
|
|
1244
2238
|
}
|
|
1245
2239
|
}
|
|
2240
|
+
var log3, SCAN_WORKER_TIMEOUT_MS, createNativeParserLoader, nativeParserLoader, DEFAULT_EXTENSIONS, DEFAULT_IGNORES;
|
|
2241
|
+
var init_src2 = __esm({
|
|
2242
|
+
"packages/domain/scanner/src/index.ts"() {
|
|
2243
|
+
init_src();
|
|
2244
|
+
init_cache_native();
|
|
2245
|
+
init_native_bridge();
|
|
2246
|
+
init_parallel_scanner();
|
|
2247
|
+
init_schemas();
|
|
2248
|
+
init_schemas();
|
|
2249
|
+
init_native_bridge();
|
|
2250
|
+
log3 = createLogger("scanner");
|
|
2251
|
+
SCAN_WORKER_TIMEOUT_MS = 12e4;
|
|
2252
|
+
createNativeParserLoader = () => {
|
|
2253
|
+
const _state = {
|
|
2254
|
+
binding: void 0,
|
|
2255
|
+
initError: null
|
|
2256
|
+
};
|
|
2257
|
+
const debugNative = (message) => {
|
|
2258
|
+
log3.debug(`[native] ${message}`);
|
|
2259
|
+
};
|
|
2260
|
+
const loadNativeParserBinding = () => {
|
|
2261
|
+
if (_state.binding !== void 0) return _state.binding;
|
|
2262
|
+
const runtimeDir = getRuntimeDir();
|
|
2263
|
+
const req = module$1.createRequire(path6__namespace.default.join(runtimeDir, "noop.cjs"));
|
|
2264
|
+
const candidates = [
|
|
2265
|
+
// ── binaryName baru: tailwind-styled-native (napi-rs naming) ──
|
|
2266
|
+
// cwd = repo root saat run dari root, atau package dir saat workspaces
|
|
2267
|
+
path6__namespace.default.resolve(process.cwd(), "native", "tailwind-styled-native.node"),
|
|
2268
|
+
path6__namespace.default.resolve(process.cwd(), "native", `tailwind-styled-native.${process.platform}-${process.arch}.node`),
|
|
2269
|
+
path6__namespace.default.resolve(process.cwd(), "native", `tailwind-styled-native.${process.platform}-${process.arch}-gnu.node`),
|
|
2270
|
+
// runtimeDir = dist/ → naik 4 level ke repo root
|
|
2271
|
+
path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "..", "native", "tailwind-styled-native.node"),
|
|
2272
|
+
path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "..", "native", `tailwind-styled-native.${process.platform}-${process.arch}-gnu.node`),
|
|
2273
|
+
// 3 level fallback (jika package di-nest lebih dangkal)
|
|
2274
|
+
path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "native", "tailwind-styled-native.node"),
|
|
2275
|
+
path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "native", `tailwind-styled-native.${process.platform}-${process.arch}-gnu.node`),
|
|
2276
|
+
// ── binaryName lama: tailwind_styled_parser (backward compat) ──
|
|
2277
|
+
path6__namespace.default.resolve(process.cwd(), "native/tailwind_styled_parser.node"),
|
|
2278
|
+
path6__namespace.default.resolve(process.cwd(), "native/build/Release/tailwind_styled_parser.node"),
|
|
2279
|
+
path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "..", "native", "tailwind_styled_parser.node"),
|
|
2280
|
+
path6__namespace.default.resolve(runtimeDir, "..", "..", "..", "native", "tailwind_styled_parser.node"),
|
|
2281
|
+
path6__namespace.default.resolve(
|
|
2282
|
+
runtimeDir,
|
|
2283
|
+
"..",
|
|
2284
|
+
"..",
|
|
2285
|
+
"..",
|
|
2286
|
+
"native",
|
|
2287
|
+
"build",
|
|
2288
|
+
"Release",
|
|
2289
|
+
"tailwind_styled_parser.node"
|
|
2290
|
+
)
|
|
2291
|
+
];
|
|
2292
|
+
for (const fullPath of candidates) {
|
|
2293
|
+
if (!fs4__namespace.default.existsSync(fullPath)) continue;
|
|
2294
|
+
try {
|
|
2295
|
+
const required = req(fullPath);
|
|
2296
|
+
if (required && (typeof required.extractClassesFromSource === "function" || typeof required.parseClasses === "function" || typeof required.parse_classes === "function")) {
|
|
2297
|
+
_state.binding = required;
|
|
2298
|
+
debugNative(`using native parser from ${fullPath}`);
|
|
2299
|
+
return _state.binding;
|
|
2300
|
+
}
|
|
2301
|
+
} catch (error) {
|
|
2302
|
+
_state.initError = error instanceof Error ? error.message : String(error);
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
_state.binding = null;
|
|
2306
|
+
if (!_state.initError) {
|
|
2307
|
+
_state.initError = "native .node binding not found";
|
|
2308
|
+
}
|
|
2309
|
+
debugNative(`native binding not available: ${_state.initError}`);
|
|
2310
|
+
return _state.binding;
|
|
2311
|
+
};
|
|
2312
|
+
return {
|
|
2313
|
+
get: loadNativeParserBinding,
|
|
2314
|
+
reset: () => {
|
|
2315
|
+
_state.binding = void 0;
|
|
2316
|
+
_state.initError = null;
|
|
2317
|
+
}
|
|
2318
|
+
};
|
|
2319
|
+
};
|
|
2320
|
+
nativeParserLoader = createNativeParserLoader();
|
|
2321
|
+
DEFAULT_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2322
|
+
DEFAULT_IGNORES = ["node_modules", ".git", ".next", "dist", "out", ".turbo", ".cache"];
|
|
2323
|
+
}
|
|
2324
|
+
});
|
|
2325
|
+
|
|
2326
|
+
// packages/domain/engine/src/native-bridge.ts
|
|
2327
|
+
function getDirname3() {
|
|
2328
|
+
if (typeof __dirname !== "undefined") return __dirname;
|
|
2329
|
+
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)) }) !== "undefined" && (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))) {
|
|
2330
|
+
return getDirname((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
2331
|
+
}
|
|
2332
|
+
return process.cwd();
|
|
2333
|
+
}
|
|
2334
|
+
function getNativeEngineBinding() {
|
|
2335
|
+
return engineBindingLoader.get();
|
|
2336
|
+
}
|
|
2337
|
+
var log4, isValidEngineBinding, createEngineBindingLoader, engineBindingLoader;
|
|
2338
|
+
var init_native_bridge2 = __esm({
|
|
2339
|
+
"packages/domain/engine/src/native-bridge.ts"() {
|
|
2340
|
+
init_src();
|
|
2341
|
+
log4 = createDebugLogger("engine:native");
|
|
2342
|
+
isValidEngineBinding = (module) => {
|
|
2343
|
+
const candidate = module;
|
|
2344
|
+
return !!(candidate && (candidate.computeIncrementalDiff || candidate.processFileChange || candidate.hashFileContent));
|
|
2345
|
+
};
|
|
2346
|
+
createEngineBindingLoader = () => {
|
|
2347
|
+
const _state = {
|
|
2348
|
+
binding: void 0,
|
|
2349
|
+
loadError: null,
|
|
2350
|
+
candidatePaths: []
|
|
2351
|
+
};
|
|
2352
|
+
const throwNativeBindingError = () => {
|
|
2353
|
+
const lines = [
|
|
2354
|
+
"FATAL: Native engine binding not found.",
|
|
2355
|
+
"",
|
|
2356
|
+
"This package requires the Rust native binding 'tailwind_styled_parser.node'.",
|
|
2357
|
+
"The binding was not found in any of these paths:",
|
|
2358
|
+
..._state.candidatePaths.map((p) => ` - ${p}`),
|
|
2359
|
+
""
|
|
2360
|
+
];
|
|
2361
|
+
if (_state.loadError) {
|
|
2362
|
+
lines.push("Load error:", ` ${_state.loadError}`, "");
|
|
2363
|
+
}
|
|
2364
|
+
lines.push(
|
|
2365
|
+
"To fix this, run:",
|
|
2366
|
+
" npm run build:rust",
|
|
2367
|
+
"",
|
|
2368
|
+
"This will build the native Rust module from the 'native/' directory.",
|
|
2369
|
+
"If you're using this package in a CI/CD environment, ensure Rust toolchain is installed",
|
|
2370
|
+
"and 'npm run build:rust' is executed before running tests or building."
|
|
2371
|
+
);
|
|
2372
|
+
throw new TwError("rust", "ENGINE_NATIVE_BINDING_NOT_FOUND", lines.join("\n"));
|
|
2373
|
+
};
|
|
2374
|
+
const getBinding = () => {
|
|
2375
|
+
const cached = _state.binding;
|
|
2376
|
+
if (cached !== void 0) {
|
|
2377
|
+
if (cached === null) {
|
|
2378
|
+
return throwNativeBindingError();
|
|
2379
|
+
}
|
|
2380
|
+
return cached;
|
|
2381
|
+
}
|
|
2382
|
+
const runtimeDir = getDirname3();
|
|
2383
|
+
const candidates = resolveNativeBindingCandidates({
|
|
2384
|
+
runtimeDir,
|
|
2385
|
+
includeDefaultCandidates: true
|
|
2386
|
+
});
|
|
2387
|
+
_state.candidatePaths = candidates;
|
|
2388
|
+
const { binding, loadErrors } = loadNativeBinding({
|
|
2389
|
+
runtimeDir,
|
|
2390
|
+
candidates,
|
|
2391
|
+
isValid: isValidEngineBinding,
|
|
2392
|
+
invalidExportMessage: "Module loaded but missing expected engine binding functions"
|
|
2393
|
+
});
|
|
2394
|
+
if (binding) {
|
|
2395
|
+
log4(`engine native binding loaded successfully`);
|
|
2396
|
+
_state.binding = binding;
|
|
2397
|
+
return binding;
|
|
2398
|
+
}
|
|
2399
|
+
if (loadErrors.length > 0) {
|
|
2400
|
+
_state.loadError = loadErrors.map((e) => `${e.path}: ${e.message}`).join("; ");
|
|
2401
|
+
}
|
|
2402
|
+
_state.binding = null;
|
|
2403
|
+
return throwNativeBindingError();
|
|
2404
|
+
};
|
|
2405
|
+
return {
|
|
2406
|
+
get: getBinding,
|
|
2407
|
+
reset: () => {
|
|
2408
|
+
_state.binding = void 0;
|
|
2409
|
+
_state.loadError = null;
|
|
2410
|
+
_state.candidatePaths = [];
|
|
2411
|
+
}
|
|
2412
|
+
};
|
|
2413
|
+
};
|
|
2414
|
+
engineBindingLoader = createEngineBindingLoader();
|
|
2415
|
+
}
|
|
2416
|
+
});
|
|
2417
|
+
|
|
2418
|
+
// packages/domain/compiler/src/index.ts
|
|
2419
|
+
init_nativeBridge();
|
|
2420
|
+
var transformSource = (source, opts) => {
|
|
2421
|
+
const native = getNativeBridge();
|
|
2422
|
+
if (!native?.transformSource) {
|
|
2423
|
+
throw new Error("FATAL: Native binding 'transformSource' is required but not available.");
|
|
2424
|
+
}
|
|
2425
|
+
const result = native.transformSource(source, opts);
|
|
2426
|
+
if (!result) {
|
|
2427
|
+
throw new Error("FATAL: transformSource returned null");
|
|
2428
|
+
}
|
|
2429
|
+
return result;
|
|
2430
|
+
};
|
|
2431
|
+
var generateCssForClasses = async (classes, _tailwindConfig, _root) => {
|
|
2432
|
+
const { runCssPipeline: runCssPipeline2 } = await Promise.resolve().then(() => (init_tailwindEngine(), tailwindEngine_exports));
|
|
2433
|
+
const result = await runCssPipeline2(classes);
|
|
2434
|
+
return result.css;
|
|
2435
|
+
};
|
|
2436
|
+
var mergeClassesStatic = (classes) => {
|
|
2437
|
+
const result = normalizeAndDedupClasses(classes);
|
|
2438
|
+
return result?.normalized || "";
|
|
2439
|
+
};
|
|
2440
|
+
var normalizeAndDedupClasses = (raw) => {
|
|
2441
|
+
const native = getNativeBridge();
|
|
2442
|
+
if (!native?.normalizeAndDedupClasses) {
|
|
2443
|
+
throw new Error("FATAL: Native binding 'normalizeAndDedupClasses' is required but not available.");
|
|
2444
|
+
}
|
|
2445
|
+
const result = native.normalizeAndDedupClasses(raw);
|
|
2446
|
+
return result || { normalized: "", duplicatesRemoved: 0, uniqueCount: 0 };
|
|
2447
|
+
};
|
|
2448
|
+
var runLoaderTransform = (ctx) => {
|
|
2449
|
+
const { filepath, source, options } = ctx;
|
|
2450
|
+
const result = transformSource(source, { filename: filepath, ...options });
|
|
2451
|
+
return {
|
|
2452
|
+
code: result?.code || "",
|
|
2453
|
+
changed: result?.changed || false,
|
|
2454
|
+
classes: result?.classes || []
|
|
2455
|
+
};
|
|
2456
|
+
};
|
|
2457
|
+
|
|
2458
|
+
// packages/domain/analyzer/src/analyzeWorkspace.ts
|
|
2459
|
+
init_src2();
|
|
1246
2460
|
|
|
1247
2461
|
// packages/domain/analyzer/src/binding.ts
|
|
1248
2462
|
init_src();
|
|
@@ -1252,7 +2466,7 @@ init_src();
|
|
|
1252
2466
|
var DEFAULT_TOP_LIMIT = 10;
|
|
1253
2467
|
var DEFAULT_FREQUENT_THRESHOLD = 2;
|
|
1254
2468
|
var DEBUG_NAMESPACE = "tailwind-styled:analyzer";
|
|
1255
|
-
function
|
|
2469
|
+
function formatErrorMessage2(error) {
|
|
1256
2470
|
return error instanceof Error ? error.message : String(error);
|
|
1257
2471
|
}
|
|
1258
2472
|
function isRecord(value) {
|
|
@@ -1262,7 +2476,7 @@ function isRecord(value) {
|
|
|
1262
2476
|
}
|
|
1263
2477
|
async function pathExists(filePath) {
|
|
1264
2478
|
try {
|
|
1265
|
-
await
|
|
2479
|
+
await fs4__namespace.default.promises.access(filePath, fs4__namespace.default.constants.F_OK);
|
|
1266
2480
|
return true;
|
|
1267
2481
|
} catch {
|
|
1268
2482
|
return false;
|
|
@@ -1325,6 +2539,9 @@ var createAnalyzerBindingLoader = () => {
|
|
|
1325
2539
|
};
|
|
1326
2540
|
};
|
|
1327
2541
|
var analyzerBindingLoader = createAnalyzerBindingLoader();
|
|
2542
|
+
async function getNativeBinding() {
|
|
2543
|
+
return analyzerBindingLoader.get();
|
|
2544
|
+
}
|
|
1328
2545
|
async function requireNativeBinding() {
|
|
1329
2546
|
const binding = await analyzerBindingLoader.get();
|
|
1330
2547
|
if (binding?.analyzeClasses) return binding;
|
|
@@ -1358,7 +2575,7 @@ async function requireNativeBinding() {
|
|
|
1358
2575
|
|
|
1359
2576
|
// packages/domain/analyzer/src/schemas.ts
|
|
1360
2577
|
init_src();
|
|
1361
|
-
var formatIssuePath3 = (
|
|
2578
|
+
var formatIssuePath3 = (path13) => path13.length > 0 ? path13.map(
|
|
1362
2579
|
(segment) => typeof segment === "symbol" ? segment.description ?? segment.toString() : String(segment)
|
|
1363
2580
|
).join(".") : "<root>";
|
|
1364
2581
|
var isPlainObject = (value) => {
|
|
@@ -1367,8 +2584,8 @@ var isPlainObject = (value) => {
|
|
|
1367
2584
|
return proto === Object.prototype || proto === null;
|
|
1368
2585
|
};
|
|
1369
2586
|
var formatIssues2 = (error) => error.issues.map((issue) => {
|
|
1370
|
-
const
|
|
1371
|
-
return `${
|
|
2587
|
+
const path13 = formatIssuePath3(issue.path);
|
|
2588
|
+
return `${path13}: ${issue.message}`;
|
|
1372
2589
|
}).join("; ");
|
|
1373
2590
|
var parseWithSchema2 = (schema, data, label) => {
|
|
1374
2591
|
const parsed = schema.safeParse(data);
|
|
@@ -1457,183 +2674,29 @@ zod.z.object({
|
|
|
1457
2674
|
var parseAnalyzerOptions = (options) => parseWithSchema2(AnalyzerOptionsSchema, options ?? {}, "analyzeWorkspace options are invalid");
|
|
1458
2675
|
var parseNativeReport = (report) => parseWithSchema2(NativeReportSchema, report, "Native analyzer report is invalid");
|
|
1459
2676
|
var SUPPORTED_TAILWIND_CONFIG_EXTENSIONS = /* @__PURE__ */ new Set([".ts", ".js", ".cjs", ".mjs"]);
|
|
1460
|
-
var KNOWN_UTILITY_PREFIXES = /* @__PURE__ */ new Set([
|
|
1461
|
-
"absolute",
|
|
1462
|
-
"align",
|
|
1463
|
-
"animate",
|
|
1464
|
-
"arbitrary",
|
|
1465
|
-
"aspect",
|
|
1466
|
-
"backdrop",
|
|
1467
|
-
"basis",
|
|
1468
|
-
"bg",
|
|
1469
|
-
"block",
|
|
1470
|
-
"border",
|
|
1471
|
-
"bottom",
|
|
1472
|
-
"col",
|
|
1473
|
-
"container",
|
|
1474
|
-
"contents",
|
|
1475
|
-
"cursor",
|
|
1476
|
-
"dark",
|
|
1477
|
-
"display",
|
|
1478
|
-
"divide",
|
|
1479
|
-
"fill",
|
|
1480
|
-
"fixed",
|
|
1481
|
-
"flex",
|
|
1482
|
-
"float",
|
|
1483
|
-
"font",
|
|
1484
|
-
"from",
|
|
1485
|
-
"gap",
|
|
1486
|
-
"grid",
|
|
1487
|
-
"grow",
|
|
1488
|
-
"h",
|
|
1489
|
-
"hidden",
|
|
1490
|
-
"inset",
|
|
1491
|
-
"inline",
|
|
1492
|
-
"isolate",
|
|
1493
|
-
"items",
|
|
1494
|
-
"justify",
|
|
1495
|
-
"left",
|
|
1496
|
-
"leading",
|
|
1497
|
-
"line",
|
|
1498
|
-
"list",
|
|
1499
|
-
"m",
|
|
1500
|
-
"max-h",
|
|
1501
|
-
"max-w",
|
|
1502
|
-
"mb",
|
|
1503
|
-
"min-h",
|
|
1504
|
-
"min-w",
|
|
1505
|
-
"ml",
|
|
1506
|
-
"mr",
|
|
1507
|
-
"mt",
|
|
1508
|
-
"mx",
|
|
1509
|
-
"my",
|
|
1510
|
-
"object",
|
|
1511
|
-
"opacity",
|
|
1512
|
-
"order",
|
|
1513
|
-
"origin",
|
|
1514
|
-
"outline",
|
|
1515
|
-
"overflow",
|
|
1516
|
-
"overscroll",
|
|
1517
|
-
"p",
|
|
1518
|
-
"pb",
|
|
1519
|
-
"pe",
|
|
1520
|
-
"perspective",
|
|
1521
|
-
"place",
|
|
1522
|
-
"pl",
|
|
1523
|
-
"pointer",
|
|
1524
|
-
"position",
|
|
1525
|
-
"pr",
|
|
1526
|
-
"ps",
|
|
1527
|
-
"pt",
|
|
1528
|
-
"px",
|
|
1529
|
-
"py",
|
|
1530
|
-
"relative",
|
|
1531
|
-
"right",
|
|
1532
|
-
"ring",
|
|
1533
|
-
"rotate",
|
|
1534
|
-
"rounded",
|
|
1535
|
-
"row",
|
|
1536
|
-
"scale",
|
|
1537
|
-
"shadow",
|
|
1538
|
-
"shrink",
|
|
1539
|
-
"size",
|
|
1540
|
-
"skew",
|
|
1541
|
-
"snap",
|
|
1542
|
-
"space-x",
|
|
1543
|
-
"space-y",
|
|
1544
|
-
"sr",
|
|
1545
|
-
"start",
|
|
1546
|
-
"static",
|
|
1547
|
-
"sticky",
|
|
1548
|
-
"stroke",
|
|
1549
|
-
"table",
|
|
1550
|
-
"text",
|
|
1551
|
-
"to",
|
|
1552
|
-
"top",
|
|
1553
|
-
"touch",
|
|
1554
|
-
"tracking",
|
|
1555
|
-
"transform",
|
|
1556
|
-
"transition",
|
|
1557
|
-
"translate",
|
|
1558
|
-
"truncate",
|
|
1559
|
-
"underline",
|
|
1560
|
-
"via",
|
|
1561
|
-
"visible",
|
|
1562
|
-
"w",
|
|
1563
|
-
"whitespace",
|
|
1564
|
-
"z"
|
|
1565
|
-
]);
|
|
1566
2677
|
var tailwindConfigCache = /* @__PURE__ */ new Map();
|
|
1567
|
-
var
|
|
1568
|
-
const
|
|
1569
|
-
if (
|
|
1570
|
-
|
|
1571
|
-
return { variantKey: parts.join(":"), base };
|
|
1572
|
-
};
|
|
1573
|
-
var isArbitraryUtility = (baseClass) => {
|
|
1574
|
-
return baseClass.includes("[") && baseClass.includes("]");
|
|
1575
|
-
};
|
|
1576
|
-
var resolveConflictGroup = (base) => {
|
|
1577
|
-
if (isArbitraryUtility(base)) return null;
|
|
1578
|
-
if (["block", "inline", "inline-block", "inline-flex", "flex", "grid", "hidden"].includes(base))
|
|
1579
|
-
return "display";
|
|
1580
|
-
if (base.startsWith("bg-")) return "bg";
|
|
1581
|
-
if (base.startsWith("text-")) return "text";
|
|
1582
|
-
if (base.startsWith("font-")) return "font";
|
|
1583
|
-
if (base.startsWith("rounded")) return "rounded";
|
|
1584
|
-
if (base.startsWith("shadow")) return "shadow";
|
|
1585
|
-
if (base.startsWith("border-")) return "border";
|
|
1586
|
-
if (base.startsWith("opacity-")) return "opacity";
|
|
1587
|
-
if (base.startsWith("w-") || base.startsWith("min-w-") || base.startsWith("max-w-"))
|
|
1588
|
-
return "width";
|
|
1589
|
-
if (base.startsWith("h-") || base.startsWith("min-h-") || base.startsWith("max-h-"))
|
|
1590
|
-
return "height";
|
|
1591
|
-
if (base.startsWith("p-") || base.startsWith("px-") || base.startsWith("py-")) return "padding";
|
|
1592
|
-
if (base.startsWith("m-") || base.startsWith("mx-") || base.startsWith("my-")) return "margin";
|
|
1593
|
-
return null;
|
|
1594
|
-
};
|
|
1595
|
-
var detectConflicts = (usages) => {
|
|
1596
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
1597
|
-
for (const usage of usages) {
|
|
1598
|
-
const { variantKey, base } = splitVariantAndBase(usage.name);
|
|
1599
|
-
const group = resolveConflictGroup(base);
|
|
1600
|
-
if (!group) continue;
|
|
1601
|
-
const key = `${variantKey}::${group}`;
|
|
1602
|
-
const bucket = buckets.get(key) ?? {
|
|
1603
|
-
variantKey,
|
|
1604
|
-
group,
|
|
1605
|
-
classes: /* @__PURE__ */ new Set()
|
|
1606
|
-
};
|
|
1607
|
-
bucket.classes.add(usage.name);
|
|
1608
|
-
buckets.set(key, bucket);
|
|
1609
|
-
}
|
|
1610
|
-
const conflicts = [];
|
|
1611
|
-
const conflictedClassNames = /* @__PURE__ */ new Set();
|
|
1612
|
-
for (const bucket of buckets.values()) {
|
|
1613
|
-
if (bucket.classes.size <= 1) continue;
|
|
1614
|
-
const classes = Array.from(bucket.classes).sort();
|
|
1615
|
-
for (const className of classes) conflictedClassNames.add(className);
|
|
1616
|
-
const variantLabel = bucket.variantKey.length > 0 ? bucket.variantKey : "base";
|
|
1617
|
-
conflicts.push({
|
|
1618
|
-
className: bucket.group,
|
|
1619
|
-
variants: bucket.variantKey.length > 0 ? bucket.variantKey.split(":") : [],
|
|
1620
|
-
classes,
|
|
1621
|
-
message: `Multiple ${bucket.group} utilities detected for "${variantLabel}".`
|
|
1622
|
-
});
|
|
2678
|
+
var detectConflicts = async (usages) => {
|
|
2679
|
+
const native = await getNativeBinding();
|
|
2680
|
+
if (!native?.detectClassConflicts) {
|
|
2681
|
+
throw new Error("FATAL: Native binding 'detectClassConflicts' is required but not available.");
|
|
1623
2682
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
2683
|
+
const result = native.detectClassConflicts(JSON.stringify(usages.map((u) => ({ name: u.name, count: u.count }))));
|
|
2684
|
+
return {
|
|
2685
|
+
conflicts: result.conflicts.map((c) => ({
|
|
2686
|
+
className: c.group,
|
|
2687
|
+
variants: c.variantKey.length > 0 ? c.variantKey.split(":") : [],
|
|
2688
|
+
classes: c.classes,
|
|
2689
|
+
message: c.message
|
|
2690
|
+
})),
|
|
2691
|
+
conflictedClassNames: new Set(result.conflictedClassNames)
|
|
2692
|
+
};
|
|
1630
2693
|
};
|
|
1631
2694
|
var isSupportedTailwindConfigPath = (configPath) => {
|
|
1632
|
-
return SUPPORTED_TAILWIND_CONFIG_EXTENSIONS.has(
|
|
2695
|
+
return SUPPORTED_TAILWIND_CONFIG_EXTENSIONS.has(path6__namespace.default.extname(configPath).toLowerCase());
|
|
1633
2696
|
};
|
|
1634
2697
|
var resolveTailwindConfigPath = async (root, explicitPath) => {
|
|
1635
2698
|
if (explicitPath) {
|
|
1636
|
-
const resolved =
|
|
2699
|
+
const resolved = path6__namespace.default.resolve(root, explicitPath);
|
|
1637
2700
|
if (!await pathExists(resolved)) return null;
|
|
1638
2701
|
return resolved;
|
|
1639
2702
|
}
|
|
@@ -1644,7 +2707,7 @@ var resolveTailwindConfigPath = async (root, explicitPath) => {
|
|
|
1644
2707
|
"tailwind.config.mjs"
|
|
1645
2708
|
];
|
|
1646
2709
|
for (const candidate of candidates) {
|
|
1647
|
-
const fullPath =
|
|
2710
|
+
const fullPath = path6__namespace.default.resolve(root, candidate);
|
|
1648
2711
|
if (await pathExists(fullPath)) return fullPath;
|
|
1649
2712
|
}
|
|
1650
2713
|
return null;
|
|
@@ -1698,15 +2761,19 @@ var collectCustomUtilities = (config) => {
|
|
|
1698
2761
|
return out;
|
|
1699
2762
|
};
|
|
1700
2763
|
var collectSafelistFromSource = async (configPath) => {
|
|
1701
|
-
const source = await
|
|
1702
|
-
const
|
|
1703
|
-
|
|
1704
|
-
const
|
|
1705
|
-
|
|
2764
|
+
const source = await fs4__namespace.default.promises.readFile(configPath, "utf8");
|
|
2765
|
+
const { extractClassesNative: extractClassesNative2 } = await Promise.resolve().then(() => (init_src2(), src_exports2));
|
|
2766
|
+
const allTokens = extractClassesNative2(source);
|
|
2767
|
+
const hasSafelist = source.includes("safelist");
|
|
2768
|
+
if (!hasSafelist) return [];
|
|
2769
|
+
const safelistMatch = source.match(/safelist\s*:\s*\[([\s\S]*?)\]/m)?.[1];
|
|
2770
|
+
if (!safelistMatch) return [];
|
|
2771
|
+
const safelistSet = /* @__PURE__ */ new Set();
|
|
2772
|
+
for (const token of safelistMatch.matchAll(/["'`]([^"'`]+)["'`]/g)) {
|
|
1706
2773
|
const value = token[1].trim();
|
|
1707
|
-
if (value.length > 0)
|
|
2774
|
+
if (value.length > 0) safelistSet.add(value);
|
|
1708
2775
|
}
|
|
1709
|
-
return
|
|
2776
|
+
return allTokens.filter((t) => safelistSet.has(t));
|
|
1710
2777
|
};
|
|
1711
2778
|
var loadTailwindConfig = async (root, semanticOption) => {
|
|
1712
2779
|
const startMs = Date.now();
|
|
@@ -1721,7 +2788,7 @@ var loadTailwindConfig = async (root, semanticOption) => {
|
|
|
1721
2788
|
customUtilities: /* @__PURE__ */ new Set()
|
|
1722
2789
|
};
|
|
1723
2790
|
}
|
|
1724
|
-
const configStat = await
|
|
2791
|
+
const configStat = await fs4__namespace.default.promises.stat(configPath).catch(() => null);
|
|
1725
2792
|
if (configStat) {
|
|
1726
2793
|
const cached = tailwindConfigCache.get(configPath);
|
|
1727
2794
|
if (cached && cached.mtimeMs === configStat.mtimeMs && cached.size === configStat.size) {
|
|
@@ -1750,7 +2817,7 @@ var loadTailwindConfig = async (root, semanticOption) => {
|
|
|
1750
2817
|
warning: "Tailwind config export must be an object or a function returning an object."
|
|
1751
2818
|
};
|
|
1752
2819
|
} catch (error) {
|
|
1753
|
-
return { config: null, warning:
|
|
2820
|
+
return { config: null, warning: formatErrorMessage2(error) };
|
|
1754
2821
|
}
|
|
1755
2822
|
})();
|
|
1756
2823
|
const { config, warning } = result;
|
|
@@ -1765,7 +2832,7 @@ var loadTailwindConfig = async (root, semanticOption) => {
|
|
|
1765
2832
|
for (const item of await collectSafelistFromSource(configPath)) safelist.add(item);
|
|
1766
2833
|
} catch (error) {
|
|
1767
2834
|
debugLog(
|
|
1768
|
-
`failed to parse safelist from source at "${configPath}": ${
|
|
2835
|
+
`failed to parse safelist from source at "${configPath}": ${formatErrorMessage2(error)}`
|
|
1769
2836
|
);
|
|
1770
2837
|
}
|
|
1771
2838
|
}
|
|
@@ -1788,40 +2855,27 @@ var loadTailwindConfig = async (root, semanticOption) => {
|
|
|
1788
2855
|
);
|
|
1789
2856
|
return loaded;
|
|
1790
2857
|
};
|
|
1791
|
-
var utilityPrefix = (baseClass) => {
|
|
1792
|
-
const normalized = baseClass.startsWith("-") ? baseClass.slice(1) : baseClass;
|
|
1793
|
-
if (normalized.includes("[") && normalized.includes("]")) return "arbitrary";
|
|
1794
|
-
if (normalized.startsWith("min-w-")) return "min-w";
|
|
1795
|
-
if (normalized.startsWith("max-w-")) return "max-w";
|
|
1796
|
-
if (normalized.startsWith("min-h-")) return "min-h";
|
|
1797
|
-
if (normalized.startsWith("max-h-")) return "max-h";
|
|
1798
|
-
if (normalized.startsWith("space-x-")) return "space-x";
|
|
1799
|
-
if (normalized.startsWith("space-y-")) return "space-y";
|
|
1800
|
-
if (normalized.startsWith("inline-")) return "inline";
|
|
1801
|
-
if (normalized.startsWith("border-")) return "border";
|
|
1802
|
-
if (normalized.startsWith("text-")) return "text";
|
|
1803
|
-
if (normalized.startsWith("bg-")) return "bg";
|
|
1804
|
-
if (normalized.startsWith("rounded")) return "rounded";
|
|
1805
|
-
if (normalized.startsWith("shadow")) return "shadow";
|
|
1806
|
-
const hyphen = normalized.indexOf("-");
|
|
1807
|
-
if (hyphen < 0) return normalized;
|
|
1808
|
-
return normalized.slice(0, hyphen);
|
|
1809
|
-
};
|
|
1810
|
-
var isKnownTailwindClass = (className, safelist, customUtilities) => {
|
|
1811
|
-
if (safelist.has(className) || customUtilities.has(className)) return true;
|
|
1812
|
-
const { base } = splitVariantAndBase(className);
|
|
1813
|
-
if (customUtilities.has(base)) return true;
|
|
1814
|
-
const prefix = utilityPrefix(base);
|
|
1815
|
-
return KNOWN_UTILITY_PREFIXES.has(prefix);
|
|
1816
|
-
};
|
|
1817
2858
|
var buildSemanticReport = async (usages, root, semanticOption) => {
|
|
1818
2859
|
const loadedConfig = await loadTailwindConfig(root, semanticOption);
|
|
1819
2860
|
const safelist = loadedConfig?.safelist ?? /* @__PURE__ */ new Set();
|
|
1820
2861
|
const customUtilities = loadedConfig?.customUtilities ?? /* @__PURE__ */ new Set();
|
|
1821
2862
|
const usageNames = new Set(usages.map((usage) => usage.name));
|
|
1822
2863
|
const unusedClasses = Array.from(safelist).filter((className) => !usageNames.has(className)).sort().map((className) => ({ name: className, count: 0, isUnused: true }));
|
|
1823
|
-
const
|
|
1824
|
-
|
|
2864
|
+
const native = await getNativeBinding();
|
|
2865
|
+
if (!native?.classifyKnownClasses) {
|
|
2866
|
+
throw new Error("FATAL: Native binding 'classifyKnownClasses' is required but not available.");
|
|
2867
|
+
}
|
|
2868
|
+
const classNames = usages.map((u) => u.name);
|
|
2869
|
+
const results = native.classifyKnownClasses(
|
|
2870
|
+
classNames,
|
|
2871
|
+
Array.from(safelist),
|
|
2872
|
+
Array.from(customUtilities)
|
|
2873
|
+
);
|
|
2874
|
+
const unknownSet = new Set(
|
|
2875
|
+
results.filter((r) => !r.isKnown).map((r) => r.className)
|
|
2876
|
+
);
|
|
2877
|
+
const unknownClasses = usages.filter((usage) => unknownSet.has(usage.name)).map((usage) => ({ ...usage, isUnused: true }));
|
|
2878
|
+
const { conflicts } = await detectConflicts(usages);
|
|
1825
2879
|
return {
|
|
1826
2880
|
unusedClasses,
|
|
1827
2881
|
unknownClasses,
|
|
@@ -1857,13 +2911,17 @@ function normalizeScan(scan, includeClass) {
|
|
|
1857
2911
|
uniqueClasses: Array.from(unique).sort()
|
|
1858
2912
|
};
|
|
1859
2913
|
}
|
|
1860
|
-
function collectClassCounts(scan) {
|
|
1861
|
-
const
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
counts.set(className, (counts.get(className) ?? 0) + 1);
|
|
1865
|
-
}
|
|
2914
|
+
async function collectClassCounts(scan) {
|
|
2915
|
+
const native = await requireNativeBinding();
|
|
2916
|
+
if (!native?.collectClassCounts) {
|
|
2917
|
+
throw new Error("FATAL: Native binding 'collectClassCounts' is required but not available.");
|
|
1866
2918
|
}
|
|
2919
|
+
const filesJson = JSON.stringify(
|
|
2920
|
+
scan.files.map((f) => ({ file: f.file ?? "", classes: f.classes }))
|
|
2921
|
+
);
|
|
2922
|
+
const result = native.collectClassCounts(filesJson);
|
|
2923
|
+
const counts = /* @__PURE__ */ new Map();
|
|
2924
|
+
for (const entry of result) counts.set(entry.name, entry.count);
|
|
1867
2925
|
return counts;
|
|
1868
2926
|
}
|
|
1869
2927
|
function buildClassUsage(counts) {
|
|
@@ -1872,29 +2930,24 @@ function buildClassUsage(counts) {
|
|
|
1872
2930
|
return left.name.localeCompare(right.name);
|
|
1873
2931
|
});
|
|
1874
2932
|
}
|
|
1875
|
-
function buildDistribution(usages) {
|
|
1876
|
-
const
|
|
1877
|
-
|
|
1878
|
-
"
|
|
1879
|
-
"4-7": 0,
|
|
1880
|
-
"8+": 0
|
|
1881
|
-
};
|
|
1882
|
-
for (const usage of usages) {
|
|
1883
|
-
if (usage.count === 1) {
|
|
1884
|
-
distribution["1"] += 1;
|
|
1885
|
-
} else if (usage.count <= 3) {
|
|
1886
|
-
distribution["2-3"] += 1;
|
|
1887
|
-
} else if (usage.count <= 7) {
|
|
1888
|
-
distribution["4-7"] += 1;
|
|
1889
|
-
} else {
|
|
1890
|
-
distribution["8+"] += 1;
|
|
1891
|
-
}
|
|
2933
|
+
async function buildDistribution(usages, native) {
|
|
2934
|
+
const binding = native ?? await requireNativeBinding();
|
|
2935
|
+
if (!binding?.buildDistribution) {
|
|
2936
|
+
throw new Error("FATAL: Native binding 'buildDistribution' is required but not available.");
|
|
1892
2937
|
}
|
|
1893
|
-
|
|
2938
|
+
const result = binding.buildDistribution(
|
|
2939
|
+
JSON.stringify(usages.map((u) => ({ name: u.name, count: u.count })))
|
|
2940
|
+
);
|
|
2941
|
+
return {
|
|
2942
|
+
"1": result.once,
|
|
2943
|
+
"2-3": result.few,
|
|
2944
|
+
"4-7": result.moderate,
|
|
2945
|
+
"8+": result.frequent
|
|
2946
|
+
};
|
|
1894
2947
|
}
|
|
1895
2948
|
async function analyzeWorkspace(root, options = {}) {
|
|
1896
2949
|
const startedAtMs = Date.now();
|
|
1897
|
-
const resolvedRoot =
|
|
2950
|
+
const resolvedRoot = path6__namespace.default.resolve(root);
|
|
1898
2951
|
const normalizedOptions = parseAnalyzerOptions(options);
|
|
1899
2952
|
const scan = await (async () => {
|
|
1900
2953
|
const scanStartedAtMs = Date.now();
|
|
@@ -1906,7 +2959,7 @@ async function analyzeWorkspace(root, options = {}) {
|
|
|
1906
2959
|
return result;
|
|
1907
2960
|
} catch (error) {
|
|
1908
2961
|
throw new Error(
|
|
1909
|
-
`Failed to scan workspace at "${resolvedRoot}": ${
|
|
2962
|
+
`Failed to scan workspace at "${resolvedRoot}": ${formatErrorMessage2(error)}`,
|
|
1910
2963
|
{
|
|
1911
2964
|
cause: error
|
|
1912
2965
|
}
|
|
@@ -1931,14 +2984,14 @@ async function analyzeWorkspace(root, options = {}) {
|
|
|
1931
2984
|
return parseNativeReport(report);
|
|
1932
2985
|
} catch (error) {
|
|
1933
2986
|
throw new Error(
|
|
1934
|
-
`Native analyzer failed for "${resolvedRoot}": ${
|
|
2987
|
+
`Native analyzer failed for "${resolvedRoot}": ${formatErrorMessage2(error)}`,
|
|
1935
2988
|
{
|
|
1936
2989
|
cause: error
|
|
1937
2990
|
}
|
|
1938
2991
|
);
|
|
1939
2992
|
}
|
|
1940
2993
|
})();
|
|
1941
|
-
const counts = collectClassCounts(normalizedScan);
|
|
2994
|
+
const counts = await collectClassCounts(normalizedScan);
|
|
1942
2995
|
const baseAll = buildClassUsage(counts);
|
|
1943
2996
|
const { all, semanticReport } = await (async () => {
|
|
1944
2997
|
if (!normalizedOptions.semantic) {
|
|
@@ -1959,18 +3012,24 @@ async function analyzeWorkspace(root, options = {}) {
|
|
|
1959
3012
|
return { all: updatedAll, semanticReport: report };
|
|
1960
3013
|
} catch (error) {
|
|
1961
3014
|
throw new Error(
|
|
1962
|
-
`Failed to build semantic report for "${resolvedRoot}": ${
|
|
3015
|
+
`Failed to build semantic report for "${resolvedRoot}": ${formatErrorMessage2(error)}`,
|
|
1963
3016
|
{ cause: error }
|
|
1964
3017
|
);
|
|
1965
3018
|
}
|
|
1966
3019
|
})();
|
|
1967
|
-
const
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
3020
|
+
const classStatsNative = binding?.computeClassStats?.(
|
|
3021
|
+
JSON.stringify(all),
|
|
3022
|
+
topLimit,
|
|
3023
|
+
frequentThreshold
|
|
3024
|
+
);
|
|
3025
|
+
const top = classStatsNative ? JSON.parse(classStatsNative.topJson) : all.slice(0, topLimit);
|
|
3026
|
+
const frequent = classStatsNative ? JSON.parse(classStatsNative.frequentJson) : all.filter((usage) => usage.count >= frequentThreshold).slice(0, topLimit);
|
|
3027
|
+
const unique = classStatsNative ? JSON.parse(classStatsNative.uniqueJson) : all.filter((usage) => usage.count === 1);
|
|
3028
|
+
const totalClassOccurrences = classStatsNative ? classStatsNative.totalClassOccurrences : all.reduce((sum, usage) => sum + usage.count, 0);
|
|
1971
3029
|
debugLog(
|
|
1972
3030
|
`analyzeWorkspace completed in ${Date.now() - startedAtMs}ms (files=${normalizedScan.totalFiles}, uniqueClasses=${all.length})`
|
|
1973
3031
|
);
|
|
3032
|
+
const distribution = await buildDistribution(all, binding);
|
|
1974
3033
|
return {
|
|
1975
3034
|
root: nativeReport.root || resolvedRoot,
|
|
1976
3035
|
totalFiles: nativeReport.totalFiles,
|
|
@@ -1981,138 +3040,57 @@ async function analyzeWorkspace(root, options = {}) {
|
|
|
1981
3040
|
top,
|
|
1982
3041
|
frequent,
|
|
1983
3042
|
unique,
|
|
1984
|
-
distribution
|
|
3043
|
+
distribution
|
|
1985
3044
|
},
|
|
3045
|
+
// topClasses — alias for classStats.top (test contract & backward compat)
|
|
3046
|
+
topClasses: top,
|
|
1986
3047
|
safelist: all.map((usage) => usage.name),
|
|
1987
3048
|
...semanticReport ? { semantic: semanticReport } : {}
|
|
1988
3049
|
};
|
|
1989
3050
|
}
|
|
1990
3051
|
|
|
1991
3052
|
// packages/domain/engine/src/index.ts
|
|
3053
|
+
init_src2();
|
|
1992
3054
|
init_src();
|
|
1993
|
-
init_src();
|
|
1994
|
-
|
|
1995
|
-
// packages/domain/engine/src/native-bridge.ts
|
|
1996
|
-
init_src();
|
|
1997
|
-
var log4 = createDebugLogger("engine:native");
|
|
1998
|
-
function getDirname3() {
|
|
1999
|
-
if (typeof __dirname !== "undefined") return __dirname;
|
|
2000
|
-
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)) }) !== "undefined" && (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href))) {
|
|
2001
|
-
return getDirname((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('vite.js', document.baseURI).href)));
|
|
2002
|
-
}
|
|
2003
|
-
return process.cwd();
|
|
2004
|
-
}
|
|
2005
|
-
var isValidEngineBinding = (module) => {
|
|
2006
|
-
const candidate = module;
|
|
2007
|
-
return !!(candidate && (candidate.computeIncrementalDiff || candidate.processFileChange || candidate.hashFileContent));
|
|
2008
|
-
};
|
|
2009
|
-
var createEngineBindingLoader = () => {
|
|
2010
|
-
const _state = {
|
|
2011
|
-
binding: void 0,
|
|
2012
|
-
loadError: null,
|
|
2013
|
-
candidatePaths: []
|
|
2014
|
-
};
|
|
2015
|
-
const throwNativeBindingError = () => {
|
|
2016
|
-
const lines = [
|
|
2017
|
-
"FATAL: Native engine binding not found.",
|
|
2018
|
-
"",
|
|
2019
|
-
"This package requires the Rust native binding 'tailwind_styled_parser.node'.",
|
|
2020
|
-
"The binding was not found in any of these paths:",
|
|
2021
|
-
..._state.candidatePaths.map((p) => ` - ${p}`),
|
|
2022
|
-
""
|
|
2023
|
-
];
|
|
2024
|
-
if (_state.loadError) {
|
|
2025
|
-
lines.push("Load error:", ` ${_state.loadError}`, "");
|
|
2026
|
-
}
|
|
2027
|
-
lines.push(
|
|
2028
|
-
"To fix this, run:",
|
|
2029
|
-
" npm run build:rust",
|
|
2030
|
-
"",
|
|
2031
|
-
"This will build the native Rust module from the 'native/' directory.",
|
|
2032
|
-
"If you're using this package in a CI/CD environment, ensure Rust toolchain is installed",
|
|
2033
|
-
"and 'npm run build:rust' is executed before running tests or building."
|
|
2034
|
-
);
|
|
2035
|
-
throw new TwError("rust", "ENGINE_NATIVE_BINDING_NOT_FOUND", lines.join("\n"));
|
|
2036
|
-
};
|
|
2037
|
-
const getBinding = () => {
|
|
2038
|
-
const cached = _state.binding;
|
|
2039
|
-
if (cached !== void 0) {
|
|
2040
|
-
if (cached === null) {
|
|
2041
|
-
return throwNativeBindingError();
|
|
2042
|
-
}
|
|
2043
|
-
return cached;
|
|
2044
|
-
}
|
|
2045
|
-
const runtimeDir = getDirname3();
|
|
2046
|
-
const candidates = resolveNativeBindingCandidates({
|
|
2047
|
-
runtimeDir,
|
|
2048
|
-
includeDefaultCandidates: true
|
|
2049
|
-
});
|
|
2050
|
-
_state.candidatePaths = candidates;
|
|
2051
|
-
const { binding, loadErrors } = loadNativeBinding({
|
|
2052
|
-
runtimeDir,
|
|
2053
|
-
candidates,
|
|
2054
|
-
isValid: isValidEngineBinding,
|
|
2055
|
-
invalidExportMessage: "Module loaded but missing expected engine binding functions"
|
|
2056
|
-
});
|
|
2057
|
-
if (binding) {
|
|
2058
|
-
log4(`engine native binding loaded successfully`);
|
|
2059
|
-
_state.binding = binding;
|
|
2060
|
-
return binding;
|
|
2061
|
-
}
|
|
2062
|
-
if (loadErrors.length > 0) {
|
|
2063
|
-
_state.loadError = loadErrors.map((e) => `${e.path}: ${e.message}`).join("; ");
|
|
2064
|
-
}
|
|
2065
|
-
_state.binding = null;
|
|
2066
|
-
return throwNativeBindingError();
|
|
2067
|
-
};
|
|
2068
|
-
return {
|
|
2069
|
-
get: getBinding,
|
|
2070
|
-
reset: () => {
|
|
2071
|
-
_state.binding = void 0;
|
|
2072
|
-
_state.loadError = null;
|
|
2073
|
-
_state.candidatePaths = [];
|
|
2074
|
-
}
|
|
2075
|
-
};
|
|
2076
|
-
};
|
|
2077
|
-
var engineBindingLoader = createEngineBindingLoader();
|
|
2078
|
-
function getNativeEngineBinding() {
|
|
2079
|
-
return engineBindingLoader.get();
|
|
2080
|
-
}
|
|
2081
3055
|
|
|
2082
3056
|
// packages/domain/engine/src/incremental.ts
|
|
3057
|
+
init_src2();
|
|
3058
|
+
init_src();
|
|
3059
|
+
init_native_bridge2();
|
|
2083
3060
|
var DEFAULT_EXTENSIONS2 = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2084
3061
|
var log5 = createLogger("engine:incremental");
|
|
2085
3062
|
function rebuildWorkspaceResult(byFile) {
|
|
2086
3063
|
const files = Array.from(byFile.values());
|
|
2087
|
-
const
|
|
2088
|
-
|
|
2089
|
-
|
|
3064
|
+
const native = getNativeEngineBinding();
|
|
3065
|
+
if (native?.rebuildWorkspaceResult) {
|
|
3066
|
+
const result = native.rebuildWorkspaceResult(files);
|
|
3067
|
+
return {
|
|
3068
|
+
files: result.files,
|
|
3069
|
+
totalFiles: result.totalFiles,
|
|
3070
|
+
uniqueClasses: result.uniqueClasses
|
|
3071
|
+
};
|
|
2090
3072
|
}
|
|
2091
|
-
|
|
2092
|
-
files,
|
|
2093
|
-
totalFiles: files.length,
|
|
2094
|
-
uniqueClasses: Array.from(unique).sort()
|
|
2095
|
-
};
|
|
3073
|
+
throw new Error("FATAL: Native binding 'rebuildWorkspaceResult' is required but not available.");
|
|
2096
3074
|
}
|
|
2097
3075
|
function applyClassDiff(existing, added, removed) {
|
|
2098
|
-
const
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
3076
|
+
const native = getNativeEngineBinding();
|
|
3077
|
+
if (native?.applyClassDiff) {
|
|
3078
|
+
return native.applyClassDiff(existing, added, removed);
|
|
3079
|
+
}
|
|
3080
|
+
throw new Error("FATAL: Native binding 'applyClassDiff' is required but not available.");
|
|
2102
3081
|
}
|
|
2103
3082
|
function areClassSetsEqual(a, b) {
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
if (!bSet.has(cls)) return false;
|
|
3083
|
+
const native = getNativeEngineBinding();
|
|
3084
|
+
if (native?.areClassSetsEqual) {
|
|
3085
|
+
return native.areClassSetsEqual(a, b);
|
|
2108
3086
|
}
|
|
2109
|
-
|
|
3087
|
+
throw new Error("FATAL: Native binding 'areClassSetsEqual' is required but not available.");
|
|
2110
3088
|
}
|
|
2111
3089
|
function applyIncrementalChange(previous, filePath, type, scanner) {
|
|
2112
3090
|
const includeExtensions = scanner?.includeExtensions ?? DEFAULT_EXTENSIONS2;
|
|
2113
3091
|
if (!isScannableFile(filePath, includeExtensions)) return previous;
|
|
2114
|
-
const byFile = new Map(previous.files.map((f) => [
|
|
2115
|
-
const normalizedPath =
|
|
3092
|
+
const byFile = new Map(previous.files.map((f) => [path6__namespace.default.resolve(f.file), f]));
|
|
3093
|
+
const normalizedPath = path6__namespace.default.resolve(filePath);
|
|
2116
3094
|
const native = getNativeEngineBinding();
|
|
2117
3095
|
if (!native?.processFileChange) {
|
|
2118
3096
|
throw new Error(
|
|
@@ -2128,7 +3106,7 @@ function applyIncrementalChange(previous, filePath, type, scanner) {
|
|
|
2128
3106
|
}
|
|
2129
3107
|
log5.debug(`native change ${normalizedPath}`);
|
|
2130
3108
|
const scanned = scanFile(normalizedPath);
|
|
2131
|
-
const content =
|
|
3109
|
+
const content = fs4__namespace.default.readFileSync(normalizedPath, "utf8");
|
|
2132
3110
|
const diff = native.processFileChange(normalizedPath, scanned.classes, content);
|
|
2133
3111
|
const existing = byFile.get(normalizedPath);
|
|
2134
3112
|
if (diff && existing) {
|
|
@@ -2197,8 +3175,8 @@ var METRICS_FILE_NAME = "metrics.json";
|
|
|
2197
3175
|
var CACHE_DIR = ".tw-cache";
|
|
2198
3176
|
function writeMetrics(metrics, cwd = process.cwd()) {
|
|
2199
3177
|
try {
|
|
2200
|
-
const cacheDir =
|
|
2201
|
-
|
|
3178
|
+
const cacheDir = path6__namespace.default.join(cwd, CACHE_DIR);
|
|
3179
|
+
fs4__namespace.default.mkdirSync(cacheDir, { recursive: true });
|
|
2202
3180
|
const mem = process.memoryUsage();
|
|
2203
3181
|
const data = {
|
|
2204
3182
|
...metrics,
|
|
@@ -2209,7 +3187,7 @@ function writeMetrics(metrics, cwd = process.cwd()) {
|
|
|
2209
3187
|
},
|
|
2210
3188
|
generatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
2211
3189
|
};
|
|
2212
|
-
|
|
3190
|
+
fs4__namespace.default.writeFileSync(path6__namespace.default.join(cacheDir, METRICS_FILE_NAME), JSON.stringify(data, null, 2));
|
|
2213
3191
|
} catch {
|
|
2214
3192
|
}
|
|
2215
3193
|
}
|
|
@@ -2314,96 +3292,78 @@ zod.z.object({
|
|
|
2314
3292
|
});
|
|
2315
3293
|
var parseEngineOptions = (options) => parseWithSchema3(EngineOptionsSchema, options ?? {}, "engine options are invalid");
|
|
2316
3294
|
var parseEngineWatchOptions = (options) => parseWithSchema3(EngineWatchOptionsSchema, options ?? {}, "engine watch options are invalid");
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
3295
|
+
|
|
3296
|
+
// packages/domain/engine/src/watch.ts
|
|
3297
|
+
var _native = null;
|
|
3298
|
+
function getNativeWatcher() {
|
|
3299
|
+
if (_native !== null) return _native;
|
|
3300
|
+
try {
|
|
3301
|
+
const { resolveNativeBinary: resolveNativeBinary2 } = (init_src(), __toCommonJS(src_exports));
|
|
3302
|
+
const { path: binPath } = resolveNativeBinary2(__dirname);
|
|
3303
|
+
if (binPath) {
|
|
3304
|
+
_native = __require(binPath);
|
|
3305
|
+
}
|
|
3306
|
+
} catch {
|
|
3307
|
+
_native = {};
|
|
3308
|
+
}
|
|
3309
|
+
return _native;
|
|
3310
|
+
}
|
|
3311
|
+
function watchWorkspaceNative(rootDir, onEvent, options) {
|
|
3312
|
+
const native = getNativeWatcher();
|
|
3313
|
+
if (!native?.startWatch || !native?.pollWatchEvents || !native?.stopWatch) {
|
|
3314
|
+
return null;
|
|
3315
|
+
}
|
|
3316
|
+
const result = native.startWatch(rootDir);
|
|
3317
|
+
if (!result || result.status !== "ok") {
|
|
3318
|
+
return null;
|
|
3319
|
+
}
|
|
3320
|
+
const { handleId } = result;
|
|
3321
|
+
const pollMs = options.pollIntervalMs ?? 200;
|
|
2323
3322
|
const pending = /* @__PURE__ */ new Map();
|
|
2324
|
-
const
|
|
2325
|
-
|
|
2326
|
-
return parts.some((part) => ignoreDirectories.has(part));
|
|
2327
|
-
};
|
|
2328
|
-
const enqueue = (event) => {
|
|
3323
|
+
const debounceMs = options.debounceMs ?? 100;
|
|
3324
|
+
function enqueue(event) {
|
|
2329
3325
|
const key = `${event.type}:${event.filePath}`;
|
|
2330
3326
|
const existing = pending.get(key);
|
|
2331
|
-
if (existing) clearTimeout(existing);
|
|
3327
|
+
if (existing) clearTimeout(existing.timer);
|
|
2332
3328
|
const timer = setTimeout(() => {
|
|
2333
3329
|
pending.delete(key);
|
|
2334
3330
|
onEvent(event);
|
|
2335
3331
|
}, debounceMs);
|
|
2336
|
-
pending.set(key, timer);
|
|
2337
|
-
}
|
|
2338
|
-
const
|
|
2339
|
-
const watcher = watchers.get(dir);
|
|
2340
|
-
if (!watcher) return;
|
|
2341
|
-
try {
|
|
2342
|
-
watcher.close();
|
|
2343
|
-
} catch {
|
|
2344
|
-
}
|
|
2345
|
-
watchers.delete(dir);
|
|
2346
|
-
};
|
|
2347
|
-
const scheduleRestart = (dir) => {
|
|
2348
|
-
const previous = restartTimers.get(dir);
|
|
2349
|
-
if (previous) clearTimeout(previous);
|
|
2350
|
-
const timer = setTimeout(() => {
|
|
2351
|
-
restartTimers.delete(dir);
|
|
2352
|
-
watchDir(dir);
|
|
2353
|
-
}, 250);
|
|
2354
|
-
restartTimers.set(dir, timer);
|
|
2355
|
-
};
|
|
2356
|
-
const watchDir = (dir) => {
|
|
2357
|
-
if (watchers.has(dir) || shouldIgnore(dir) || !fs__default.default.existsSync(dir)) return;
|
|
3332
|
+
pending.set(key, { event, timer });
|
|
3333
|
+
}
|
|
3334
|
+
const intervalId = setInterval(() => {
|
|
2358
3335
|
try {
|
|
2359
|
-
const
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
}
|
|
2364
|
-
const watcher = fs__default.default.watch(dir, { persistent: true }, (_eventType, fileName) => {
|
|
2365
|
-
if (!fileName) return;
|
|
2366
|
-
const fullPath = path3__default.default.join(dir, fileName.toString());
|
|
2367
|
-
if (shouldIgnore(fullPath)) return;
|
|
2368
|
-
if (fs__default.default.existsSync(fullPath)) {
|
|
2369
|
-
try {
|
|
2370
|
-
const stat = fs__default.default.lstatSync(fullPath);
|
|
2371
|
-
if (stat.isSymbolicLink()) return;
|
|
2372
|
-
if (stat.isDirectory()) {
|
|
2373
|
-
watchDir(fullPath);
|
|
2374
|
-
return;
|
|
2375
|
-
}
|
|
2376
|
-
enqueue({ type: "change", filePath: fullPath });
|
|
2377
|
-
return;
|
|
2378
|
-
} catch {
|
|
2379
|
-
}
|
|
3336
|
+
const events = native.pollWatchEvents(handleId);
|
|
3337
|
+
for (const ev of events) {
|
|
3338
|
+
const type = ev.kind === "unlink" ? "unlink" : "change";
|
|
3339
|
+
enqueue({ type, filePath: ev.path });
|
|
2380
3340
|
}
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
options.onError?.(watcherError, dir);
|
|
2387
|
-
scheduleRestart(dir);
|
|
2388
|
-
});
|
|
2389
|
-
watchers.set(dir, watcher);
|
|
2390
|
-
for (const entry of fs__default.default.readdirSync(dir, { withFileTypes: true })) {
|
|
2391
|
-
if (!entry.isDirectory()) continue;
|
|
2392
|
-
watchDir(path3__default.default.join(dir, entry.name));
|
|
3341
|
+
} catch (err) {
|
|
3342
|
+
options.onError?.(
|
|
3343
|
+
err instanceof Error ? err : new Error(String(err)),
|
|
3344
|
+
rootDir
|
|
3345
|
+
);
|
|
2393
3346
|
}
|
|
2394
|
-
};
|
|
2395
|
-
watchDir(path3__default.default.resolve(rootDir));
|
|
3347
|
+
}, pollMs);
|
|
2396
3348
|
return {
|
|
2397
3349
|
close() {
|
|
2398
|
-
|
|
3350
|
+
clearInterval(intervalId);
|
|
3351
|
+
for (const { timer } of pending.values()) clearTimeout(timer);
|
|
2399
3352
|
pending.clear();
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
3353
|
+
try {
|
|
3354
|
+
native.stopWatch(handleId);
|
|
3355
|
+
} catch {
|
|
3356
|
+
}
|
|
2404
3357
|
}
|
|
2405
3358
|
};
|
|
2406
3359
|
}
|
|
3360
|
+
function watchWorkspace(rootDir, onEvent, options = {}) {
|
|
3361
|
+
const nativeWatcher = watchWorkspaceNative(rootDir, onEvent, options);
|
|
3362
|
+
if (!nativeWatcher) {
|
|
3363
|
+
throw new Error("FATAL: Native watcher is required but not available. Build the native module: npm run build:rust");
|
|
3364
|
+
}
|
|
3365
|
+
return nativeWatcher;
|
|
3366
|
+
}
|
|
2407
3367
|
|
|
2408
3368
|
// packages/domain/engine/src/index.ts
|
|
2409
3369
|
var DEFAULT_LARGE_FILE_THRESHOLD_BYTES = 10 * 1024 * 1024;
|
|
@@ -2426,8 +3386,8 @@ var configState = {
|
|
|
2426
3386
|
var log6 = createLogger("engine");
|
|
2427
3387
|
async function loadTailwindConfigFromPath(root, tailwindConfigPath) {
|
|
2428
3388
|
if (!tailwindConfigPath) return void 0;
|
|
2429
|
-
const configPath =
|
|
2430
|
-
if (!
|
|
3389
|
+
const configPath = path6__namespace.default.resolve(root, tailwindConfigPath);
|
|
3390
|
+
if (!fs4__namespace.default.existsSync(configPath)) {
|
|
2431
3391
|
throw TwError.fromIo("CONFIG_NOT_FOUND", `tailwindConfigPath not found: ${configPath}`);
|
|
2432
3392
|
}
|
|
2433
3393
|
const imported = await import(url.pathToFileURL(configPath).href);
|
|
@@ -2490,11 +3450,11 @@ async function buildFromScan(scan, root, options, tailwindConfig) {
|
|
|
2490
3450
|
};
|
|
2491
3451
|
}
|
|
2492
3452
|
function countWorkspacePackages(root) {
|
|
2493
|
-
const packagesDir =
|
|
2494
|
-
if (!
|
|
3453
|
+
const packagesDir = path6__namespace.default.join(root, "packages");
|
|
3454
|
+
if (!fs4__namespace.default.existsSync(packagesDir)) return 0;
|
|
2495
3455
|
try {
|
|
2496
|
-
return
|
|
2497
|
-
(entry) => entry.isDirectory() &&
|
|
3456
|
+
return fs4__namespace.default.readdirSync(packagesDir, { withFileTypes: true }).filter(
|
|
3457
|
+
(entry) => entry.isDirectory() && fs4__namespace.default.existsSync(path6__namespace.default.join(packagesDir, entry.name, "package.json"))
|
|
2498
3458
|
).length;
|
|
2499
3459
|
} catch {
|
|
2500
3460
|
return 0;
|
|
@@ -2530,7 +3490,7 @@ function writeDashboardMetrics(root, mode, result, metrics) {
|
|
|
2530
3490
|
async function createEngine(rawOptions = {}) {
|
|
2531
3491
|
const options = parseEngineOptions(rawOptions);
|
|
2532
3492
|
const root = options.root ?? process.cwd();
|
|
2533
|
-
const resolvedRoot =
|
|
3493
|
+
const resolvedRoot = path6__namespace.default.resolve(root);
|
|
2534
3494
|
const plugins = rawOptions.plugins ?? [];
|
|
2535
3495
|
const getTailwindConfig = async () => {
|
|
2536
3496
|
if (configState.isLoaded()) return configState.getConfig();
|
|
@@ -2677,7 +3637,7 @@ async function createEngine(rawOptions = {}) {
|
|
|
2677
3637
|
const shouldForceFullRescan = (event) => {
|
|
2678
3638
|
if (event.type === "unlink") return false;
|
|
2679
3639
|
try {
|
|
2680
|
-
const stat =
|
|
3640
|
+
const stat = fs4__namespace.default.statSync(event.filePath);
|
|
2681
3641
|
if (stat.size > largeFileThreshold) {
|
|
2682
3642
|
metrics.markSkippedLargeFile();
|
|
2683
3643
|
return true;
|
|
@@ -2796,7 +3756,7 @@ async function createEngine(rawOptions = {}) {
|
|
|
2796
3756
|
|
|
2797
3757
|
// packages/presentation/vite/src/schemas.ts
|
|
2798
3758
|
init_src();
|
|
2799
|
-
var formatIssuePath4 = (
|
|
3759
|
+
var formatIssuePath4 = (path13) => path13.length > 0 ? path13.map(
|
|
2800
3760
|
(segment) => typeof segment === "symbol" ? segment.description ?? segment.toString() : String(segment)
|
|
2801
3761
|
).join(".") : "<root>";
|
|
2802
3762
|
var formatIssues4 = (error) => error.issues.map((issue) => {
|
|
@@ -2842,14 +3802,14 @@ function warnDeprecated(options, key, message) {
|
|
|
2842
3802
|
}
|
|
2843
3803
|
}
|
|
2844
3804
|
function isInsideDirectory(filePath, directory) {
|
|
2845
|
-
const relative =
|
|
2846
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
3805
|
+
const relative = path6__namespace.default.relative(directory, filePath);
|
|
3806
|
+
return relative === "" || !relative.startsWith("..") && !path6__namespace.default.isAbsolute(relative);
|
|
2847
3807
|
}
|
|
2848
3808
|
function filterScanToDirs(scan, root, scanDirs) {
|
|
2849
|
-
const resolvedDirs = scanDirs.map((dir) =>
|
|
3809
|
+
const resolvedDirs = scanDirs.map((dir) => path6__namespace.default.resolve(root, dir));
|
|
2850
3810
|
if (resolvedDirs.length === 0) return scan;
|
|
2851
3811
|
const files = scan.files.filter((file) => {
|
|
2852
|
-
const absoluteFile =
|
|
3812
|
+
const absoluteFile = path6__namespace.default.resolve(file.file);
|
|
2853
3813
|
return resolvedDirs.some((directory) => isInsideDirectory(absoluteFile, directory));
|
|
2854
3814
|
});
|
|
2855
3815
|
const uniqueClasses = Array.from(new Set(files.flatMap((file) => file.classes))).sort();
|
|
@@ -2860,9 +3820,9 @@ function filterScanToDirs(scan, root, scanDirs) {
|
|
|
2860
3820
|
};
|
|
2861
3821
|
}
|
|
2862
3822
|
function writeJsonArtifact(root, relativePath, value) {
|
|
2863
|
-
const outputPath =
|
|
2864
|
-
|
|
2865
|
-
|
|
3823
|
+
const outputPath = path6__namespace.default.resolve(root, relativePath);
|
|
3824
|
+
fs4__namespace.default.mkdirSync(path6__namespace.default.dirname(outputPath), { recursive: true });
|
|
3825
|
+
fs4__namespace.default.writeFileSync(outputPath, `${JSON.stringify(value, null, 2)}
|
|
2866
3826
|
`);
|
|
2867
3827
|
}
|
|
2868
3828
|
function tailwindStyledPlugin(opts = {}) {
|