tailwind-styled-v4 4.0.0 → 5.0.1
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 +398 -0
- package/LICENSE +21 -0
- package/README.md +532 -0
- package/dist/analyzer.d.mts +114 -0
- package/dist/analyzer.d.ts +114 -0
- package/dist/analyzer.js +1555 -0
- package/dist/analyzer.js.map +1 -0
- package/dist/analyzer.mjs +1544 -0
- package/dist/analyzer.mjs.map +1 -0
- package/dist/animate.d.mts +46 -0
- package/dist/animate.d.ts +41 -112
- package/dist/animate.js +792 -235
- package/dist/animate.js.map +1 -1
- package/dist/animate.mjs +782 -0
- package/dist/animate.mjs.map +1 -0
- package/dist/atomic.d.mts +18 -0
- package/dist/atomic.d.ts +18 -0
- package/dist/atomic.js +191 -0
- package/dist/atomic.js.map +1 -0
- package/dist/atomic.mjs +185 -0
- package/dist/atomic.mjs.map +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +6063 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +6053 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/{compiler.d.cts → compiler.d.mts} +503 -210
- package/dist/compiler.d.ts +503 -210
- package/dist/compiler.js +1549 -566
- package/dist/compiler.js.map +1 -1
- package/dist/{compiler.cjs → compiler.mjs} +1476 -627
- package/dist/compiler.mjs.map +1 -0
- package/dist/dashboard.d.mts +272 -0
- package/dist/dashboard.d.ts +272 -0
- package/dist/dashboard.js +249 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/dashboard.mjs +239 -0
- package/dist/dashboard.mjs.map +1 -0
- package/dist/devtools.js +336 -211
- package/dist/devtools.js.map +1 -1
- package/dist/{devtools.cjs → devtools.mjs} +331 -220
- package/dist/devtools.mjs.map +1 -0
- package/dist/engine.d.mts +84 -0
- package/dist/engine.d.ts +84 -0
- package/dist/engine.js +3014 -0
- package/dist/engine.js.map +1 -0
- package/dist/engine.mjs +3005 -0
- package/dist/engine.mjs.map +1 -0
- package/dist/{index.d.cts → index.d.mts} +75 -4
- package/dist/index.d.ts +75 -4
- package/dist/index.js +1341 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2162 -0
- package/dist/index.mjs.map +1 -0
- package/dist/liveTokenEngine-DYN3Zale.d.mts +34 -0
- package/dist/liveTokenEngine-DYN3Zale.d.ts +34 -0
- package/dist/next.d.mts +55 -0
- package/dist/next.d.ts +30 -20
- package/dist/next.js +6947 -149
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +7050 -0
- package/dist/next.mjs.map +1 -0
- package/dist/plugin.d.mts +90 -0
- package/dist/plugin.d.ts +90 -0
- package/dist/plugin.js +185 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.mjs +174 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/pluginRegistry.d.mts +83 -0
- package/dist/pluginRegistry.d.ts +83 -0
- package/dist/pluginRegistry.js +303 -0
- package/dist/pluginRegistry.js.map +1 -0
- package/dist/pluginRegistry.mjs +298 -0
- package/dist/pluginRegistry.mjs.map +1 -0
- package/dist/{preset.d.cts → preset.d.mts} +29 -2
- package/dist/preset.d.ts +29 -2
- package/dist/preset.js +318 -21
- package/dist/preset.js.map +1 -1
- package/dist/preset.mjs +414 -0
- package/dist/preset.mjs.map +1 -0
- package/dist/rspack.d.mts +33 -0
- package/dist/rspack.d.ts +33 -0
- package/dist/rspack.js +55 -0
- package/dist/rspack.js.map +1 -0
- package/dist/rspack.mjs +45 -0
- package/dist/rspack.mjs.map +1 -0
- package/dist/runtime.d.mts +62 -0
- package/dist/runtime.d.ts +62 -0
- package/dist/runtime.js +207 -0
- package/dist/runtime.js.map +1 -0
- package/dist/runtime.mjs +188 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/runtimeCss.d.mts +65 -0
- package/dist/runtimeCss.d.ts +65 -0
- package/dist/runtimeCss.js +188 -0
- package/dist/runtimeCss.js.map +1 -0
- package/dist/runtimeCss.mjs +173 -0
- package/dist/runtimeCss.mjs.map +1 -0
- package/dist/scanner.d.mts +25 -0
- package/dist/scanner.d.ts +25 -0
- package/dist/scanner.js +717 -0
- package/dist/scanner.js.map +1 -0
- package/dist/scanner.mjs +703 -0
- package/dist/scanner.mjs.map +1 -0
- package/dist/shared.d.mts +85 -0
- package/dist/shared.d.ts +85 -0
- package/dist/shared.js +255 -0
- package/dist/shared.js.map +1 -0
- package/dist/shared.mjs +233 -0
- package/dist/shared.mjs.map +1 -0
- package/dist/storybookAddon.d.mts +108 -0
- package/dist/storybookAddon.d.ts +108 -0
- package/dist/storybookAddon.js +95 -0
- package/dist/storybookAddon.js.map +1 -0
- package/dist/storybookAddon.mjs +88 -0
- package/dist/storybookAddon.mjs.map +1 -0
- package/dist/svelte.d.mts +114 -0
- package/dist/svelte.d.ts +114 -0
- package/dist/svelte.js +67 -0
- package/dist/svelte.js.map +1 -0
- package/dist/svelte.mjs +59 -0
- package/dist/svelte.mjs.map +1 -0
- package/dist/testing.d.mts +185 -0
- package/dist/testing.d.ts +185 -0
- package/dist/testing.js +173 -0
- package/dist/testing.js.map +1 -0
- package/dist/testing.mjs +158 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/{theme.d.cts → theme.d.mts} +18 -11
- package/dist/theme.d.ts +18 -11
- package/dist/theme.js +205 -19
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +311 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/types-DXr2PmGP.d.mts +31 -0
- package/dist/types-DXr2PmGP.d.ts +31 -0
- package/dist/vite.d.mts +51 -0
- package/dist/vite.d.ts +35 -6
- package/dist/vite.js +4254 -57
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +4281 -0
- package/dist/vite.mjs.map +1 -0
- package/dist/vue.d.mts +89 -0
- package/dist/vue.d.ts +89 -0
- package/dist/vue.js +104 -0
- package/dist/vue.js.map +1 -0
- package/dist/vue.mjs +96 -0
- package/dist/vue.mjs.map +1 -0
- package/package.json +173 -67
- package/dist/animate.cjs +0 -252
- package/dist/animate.cjs.map +0 -1
- package/dist/animate.d.cts +0 -117
- package/dist/astTransform-ua-eapqs.d.cts +0 -41
- package/dist/astTransform-ua-eapqs.d.ts +0 -41
- package/dist/compiler.cjs.map +0 -1
- package/dist/css.cjs +0 -71
- package/dist/css.cjs.map +0 -1
- package/dist/css.d.cts +0 -45
- package/dist/css.d.ts +0 -45
- package/dist/css.js +0 -62
- package/dist/css.js.map +0 -1
- package/dist/devtools.cjs.map +0 -1
- package/dist/index.cjs +0 -1058
- package/dist/index.cjs.map +0 -1
- package/dist/next.cjs +0 -268
- package/dist/next.cjs.map +0 -1
- package/dist/next.d.cts +0 -45
- package/dist/plugins.cjs +0 -396
- package/dist/plugins.cjs.map +0 -1
- package/dist/plugins.d.cts +0 -231
- package/dist/plugins.d.ts +0 -231
- package/dist/plugins.js +0 -381
- package/dist/plugins.js.map +0 -1
- package/dist/preset.cjs +0 -129
- package/dist/preset.cjs.map +0 -1
- package/dist/theme.cjs +0 -154
- package/dist/theme.cjs.map +0 -1
- package/dist/turbopackLoader.cjs +0 -2689
- package/dist/turbopackLoader.cjs.map +0 -1
- package/dist/turbopackLoader.d.cts +0 -22
- package/dist/turbopackLoader.d.ts +0 -22
- package/dist/turbopackLoader.js +0 -2681
- package/dist/turbopackLoader.js.map +0 -1
- package/dist/vite.cjs +0 -105
- package/dist/vite.cjs.map +0 -1
- package/dist/vite.d.cts +0 -22
- package/dist/webpackLoader.cjs +0 -2670
- package/dist/webpackLoader.cjs.map +0 -1
- package/dist/webpackLoader.d.cts +0 -24
- package/dist/webpackLoader.d.ts +0 -24
- package/dist/webpackLoader.js +0 -2662
- package/dist/webpackLoader.js.map +0 -1
- /package/dist/{devtools.d.cts → devtools.d.mts} +0 -0
package/dist/scanner.mjs
ADDED
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import path4 from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
import { Worker } from 'worker_threads';
|
|
6
|
+
|
|
7
|
+
/* tailwind-styled-v4 v5.0.1 | MIT | https://github.com/dictionar32/tailwind-styled-v4 */
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
13
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
14
|
+
}) : x)(function(x) {
|
|
15
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
16
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
17
|
+
});
|
|
18
|
+
var __esm = (fn, res) => function __init() {
|
|
19
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
20
|
+
};
|
|
21
|
+
var __export = (target, all) => {
|
|
22
|
+
for (var name in all)
|
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
24
|
+
};
|
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
27
|
+
for (let key of __getOwnPropNames(from))
|
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
30
|
+
}
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
|
+
|
|
35
|
+
// packages/shared/src/logger.ts
|
|
36
|
+
function getEnvLevel() {
|
|
37
|
+
const env = process.env.TWS_LOG_LEVEL?.toLowerCase();
|
|
38
|
+
if (env && env in LEVELS) return env;
|
|
39
|
+
return process.env.TWS_DEBUG_SCANNER === "1" ? "debug" : "info";
|
|
40
|
+
}
|
|
41
|
+
function createLogger(prefix, level) {
|
|
42
|
+
let currentLevel = getEnvLevel();
|
|
43
|
+
const log3 = (msgLevel, stream, args) => {
|
|
44
|
+
if (LEVELS[msgLevel] > LEVELS[currentLevel]) return;
|
|
45
|
+
const line = `[${prefix}] ${args.map(String).join(" ")}
|
|
46
|
+
`;
|
|
47
|
+
process[stream].write(line);
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
error: (...a) => log3("error", "stderr", a),
|
|
51
|
+
warn: (...a) => log3("warn", "stderr", a),
|
|
52
|
+
info: (...a) => log3("info", "stdout", a),
|
|
53
|
+
debug: (...a) => log3("debug", "stderr", a),
|
|
54
|
+
setLevel: (l) => {
|
|
55
|
+
currentLevel = l;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
var LEVELS;
|
|
60
|
+
var init_logger = __esm({
|
|
61
|
+
"packages/shared/src/logger.ts"() {
|
|
62
|
+
LEVELS = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
63
|
+
createLogger("tailwind-styled");
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// packages/shared/src/index.ts
|
|
68
|
+
var init_src = __esm({
|
|
69
|
+
"packages/shared/src/index.ts"() {
|
|
70
|
+
init_logger();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// packages/compiler/src/nativeBridge.ts
|
|
75
|
+
var nativeBridge_exports = {};
|
|
76
|
+
__export(nativeBridge_exports, {
|
|
77
|
+
adaptNativeResult: () => adaptNativeResult,
|
|
78
|
+
getNativeBridge: () => getNativeBridge,
|
|
79
|
+
resetNativeBridgeCache: () => resetNativeBridgeCache
|
|
80
|
+
});
|
|
81
|
+
function tryRequire(id) {
|
|
82
|
+
try {
|
|
83
|
+
const mod = requireFromRuntime(id);
|
|
84
|
+
return mod ?? null;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
log.debug(
|
|
87
|
+
`native bridge load miss ${id}: ${error instanceof Error ? error.message : String(error)}`
|
|
88
|
+
);
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function getNativeBridge() {
|
|
93
|
+
if (cachedBridge !== void 0) {
|
|
94
|
+
if (cachedBridge === null) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`[tailwind-styled/compiler v5] Native binding is required but not available.
|
|
97
|
+
Please ensure:
|
|
98
|
+
1. The native module is properly installed
|
|
99
|
+
2. You have run: npm run build:native (or use prebuilt binary)
|
|
100
|
+
3. TWS_NO_NATIVE environment variable is not set
|
|
101
|
+
|
|
102
|
+
For help, see: https://tailwind-styled.dev/docs/install`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
return cachedBridge;
|
|
106
|
+
}
|
|
107
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
108
|
+
cachedBridge = null;
|
|
109
|
+
throw new Error(
|
|
110
|
+
`[tailwind-styled/compiler v5] Native binding is required.
|
|
111
|
+
The TWS_NO_NATIVE or TWS_NO_RUST environment variable is set, which disables native binding.
|
|
112
|
+
Please unset this environment variable to use the native compiler.`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const candidates = [
|
|
116
|
+
"@tailwind-styled/native",
|
|
117
|
+
path4.resolve(process.cwd(), "native", "index.mjs"),
|
|
118
|
+
path4.resolve(runtimeDir, "..", "..", "native", "index.mjs"),
|
|
119
|
+
path4.resolve(runtimeDir, "..", "..", "..", "native", "index.mjs"),
|
|
120
|
+
path4.resolve(process.cwd(), "native", "index.node"),
|
|
121
|
+
path4.resolve(runtimeDir, "..", "..", "native", "index.node"),
|
|
122
|
+
path4.resolve(runtimeDir, "..", "..", "..", "native", "index.node")
|
|
123
|
+
];
|
|
124
|
+
for (const candidate of candidates) {
|
|
125
|
+
const bridge = tryRequire(candidate);
|
|
126
|
+
if (bridge) {
|
|
127
|
+
log.debug(`native bridge loaded from ${candidate}`);
|
|
128
|
+
cachedBridge = bridge;
|
|
129
|
+
return cachedBridge;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
cachedBridge = null;
|
|
133
|
+
throw new Error(
|
|
134
|
+
`[tailwind-styled/compiler v5] Native binding not found.
|
|
135
|
+
Tried loading from:
|
|
136
|
+
` + candidates.map((c) => ` - ${c}`).join("\n") + `
|
|
137
|
+
|
|
138
|
+
Please build the native module:
|
|
139
|
+
npm run build:native
|
|
140
|
+
|
|
141
|
+
Or install a prebuilt binary for your platform.`
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
function resetNativeBridgeCache() {
|
|
145
|
+
cachedBridge = void 0;
|
|
146
|
+
}
|
|
147
|
+
function adaptNativeResult(raw) {
|
|
148
|
+
let rsc;
|
|
149
|
+
if (raw.rscJson) {
|
|
150
|
+
try {
|
|
151
|
+
const parsed = JSON.parse(raw.rscJson);
|
|
152
|
+
rsc = {
|
|
153
|
+
isServer: parsed.isServer,
|
|
154
|
+
needsClientDirective: parsed.needsClientDirective,
|
|
155
|
+
clientReasons: []
|
|
156
|
+
};
|
|
157
|
+
} catch {
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let metadata;
|
|
161
|
+
if (raw.metadataJson) {
|
|
162
|
+
try {
|
|
163
|
+
metadata = JSON.parse(raw.metadataJson);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
code: raw.code,
|
|
169
|
+
classes: raw.classes,
|
|
170
|
+
changed: raw.changed,
|
|
171
|
+
rsc,
|
|
172
|
+
metadata
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
var runtimeDir, requireFromRuntime, cachedBridge, log;
|
|
176
|
+
var init_nativeBridge = __esm({
|
|
177
|
+
"packages/compiler/src/nativeBridge.ts"() {
|
|
178
|
+
init_src();
|
|
179
|
+
runtimeDir = typeof __dirname === "string" && __dirname.length > 0 ? __dirname : process.cwd();
|
|
180
|
+
requireFromRuntime = typeof module !== "undefined" && typeof module.require === "function" ? module.require.bind(module) : createRequire(path4.join(runtimeDir, "noop.cjs"));
|
|
181
|
+
log = createLogger("compiler:native");
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// packages/scanner/src/native-bridge.ts
|
|
186
|
+
var native_bridge_exports = {};
|
|
187
|
+
__export(native_bridge_exports, {
|
|
188
|
+
cachePriorityNative: () => cachePriorityNative,
|
|
189
|
+
cacheReadNative: () => cacheReadNative,
|
|
190
|
+
cacheWriteNative: () => cacheWriteNative,
|
|
191
|
+
extractClassesNative: () => extractClassesNative,
|
|
192
|
+
hasNativeScannerBinding: () => hasNativeScannerBinding,
|
|
193
|
+
hashContentNative: () => hashContentNative,
|
|
194
|
+
isRustCacheAvailable: () => isRustCacheAvailable,
|
|
195
|
+
scanWorkspaceNative: () => scanWorkspaceNative
|
|
196
|
+
});
|
|
197
|
+
function getBinding() {
|
|
198
|
+
if (_binding !== void 0) {
|
|
199
|
+
if (_binding === null) {
|
|
200
|
+
throwNativeBindingError();
|
|
201
|
+
}
|
|
202
|
+
return _binding;
|
|
203
|
+
}
|
|
204
|
+
if (process.env.TWS_NO_NATIVE === "1" || process.env.TWS_NO_RUST === "1") {
|
|
205
|
+
_loadError = "Native loading is disabled by TWS_NO_NATIVE or TWS_NO_RUST environment variable.";
|
|
206
|
+
_binding = null;
|
|
207
|
+
_candidatePaths = [];
|
|
208
|
+
throwNativeBindingError();
|
|
209
|
+
}
|
|
210
|
+
const runtimeDir2 = typeof __dirname === "string" ? __dirname : process.cwd();
|
|
211
|
+
_candidatePaths = [
|
|
212
|
+
path4.resolve(process.cwd(), "native", "tailwind_styled_parser.node"),
|
|
213
|
+
path4.resolve(runtimeDir2, "..", "..", "..", "native", "tailwind_styled_parser.node")
|
|
214
|
+
];
|
|
215
|
+
const req = typeof __require === "function" ? __require : createRequire(path4.join(runtimeDir2, "noop.cjs"));
|
|
216
|
+
for (const c of _candidatePaths) {
|
|
217
|
+
try {
|
|
218
|
+
const mod = req(c);
|
|
219
|
+
if (mod?.scanWorkspace || mod?.extractClassesFromSource || mod?.hashFileContent || mod?.cacheRead || mod?.cacheWrite) {
|
|
220
|
+
_binding = mod;
|
|
221
|
+
return _binding;
|
|
222
|
+
}
|
|
223
|
+
} catch (error) {
|
|
224
|
+
_loadError = error instanceof Error ? error.message : String(error);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
_binding = null;
|
|
228
|
+
throwNativeBindingError();
|
|
229
|
+
}
|
|
230
|
+
function throwNativeBindingError() {
|
|
231
|
+
const lines = [
|
|
232
|
+
"FATAL: Native scanner binding not found.",
|
|
233
|
+
"",
|
|
234
|
+
"This package requires the Rust native binding 'tailwind_styled_parser.node'.",
|
|
235
|
+
"The binding was not found in any of these paths:",
|
|
236
|
+
..._candidatePaths.map((p) => ` - ${p}`),
|
|
237
|
+
""
|
|
238
|
+
];
|
|
239
|
+
if (_loadError) {
|
|
240
|
+
lines.push("Load error:", ` ${_loadError}`, "");
|
|
241
|
+
}
|
|
242
|
+
lines.push(
|
|
243
|
+
"To fix this, run:",
|
|
244
|
+
" npm run build:rust",
|
|
245
|
+
"",
|
|
246
|
+
"This will build the native Rust module from the 'native/' directory.",
|
|
247
|
+
"If you're using this package in a CI/CD environment, ensure Rust toolchain is installed",
|
|
248
|
+
"and 'npm run build:rust' is executed before running tests or building."
|
|
249
|
+
);
|
|
250
|
+
throw new Error(lines.join("\n"));
|
|
251
|
+
}
|
|
252
|
+
function scanWorkspaceNative(root, extensions) {
|
|
253
|
+
return getBinding().scanWorkspace(root, extensions ?? null);
|
|
254
|
+
}
|
|
255
|
+
function extractClassesNative(source) {
|
|
256
|
+
const result = getBinding().extractClassesFromSource?.(source);
|
|
257
|
+
if (result === null || result === void 0) {
|
|
258
|
+
throw new Error("Native extractClassesFromSource returned null/undefined");
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
}
|
|
262
|
+
function hashContentNative(content) {
|
|
263
|
+
const result = getBinding().hashFileContent?.(content);
|
|
264
|
+
if (result === null || result === void 0) {
|
|
265
|
+
throw new Error("Native hashFileContent returned null/undefined");
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
function isRustCacheAvailable() {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
function hasNativeScannerBinding() {
|
|
273
|
+
try {
|
|
274
|
+
getBinding();
|
|
275
|
+
return true;
|
|
276
|
+
} catch {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function cacheReadNative(cachePath) {
|
|
281
|
+
const result = getBinding().cacheRead?.(cachePath);
|
|
282
|
+
if (result === null || result === void 0) {
|
|
283
|
+
throw new Error("Native cacheRead returned null/undefined");
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
function cacheWriteNative(cachePath, entries) {
|
|
288
|
+
const result = getBinding().cacheWrite?.(cachePath, entries);
|
|
289
|
+
if (result === null || result === void 0) {
|
|
290
|
+
throw new Error("Native cacheWrite returned null/undefined");
|
|
291
|
+
}
|
|
292
|
+
return result;
|
|
293
|
+
}
|
|
294
|
+
function cachePriorityNative(mtimeMs, size, cachedMtimeMs, cachedSize, cachedHitCount, cachedLastSeenMs, nowMs = Date.now()) {
|
|
295
|
+
const result = getBinding().cachePriority?.(
|
|
296
|
+
mtimeMs,
|
|
297
|
+
size,
|
|
298
|
+
cachedMtimeMs,
|
|
299
|
+
cachedSize,
|
|
300
|
+
cachedHitCount,
|
|
301
|
+
cachedLastSeenMs,
|
|
302
|
+
nowMs
|
|
303
|
+
);
|
|
304
|
+
if (result === null || result === void 0) {
|
|
305
|
+
throw new Error("Native cachePriority returned null/undefined");
|
|
306
|
+
}
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
var _binding, _loadError, _candidatePaths;
|
|
310
|
+
var init_native_bridge = __esm({
|
|
311
|
+
"packages/scanner/src/native-bridge.ts"() {
|
|
312
|
+
_binding = void 0;
|
|
313
|
+
_loadError = null;
|
|
314
|
+
_candidatePaths = [];
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
function extractAllClasses(source) {
|
|
318
|
+
const { getNativeBridge: getNativeBridge2 } = (init_nativeBridge(), __toCommonJS(nativeBridge_exports));
|
|
319
|
+
const native = getNativeBridge2();
|
|
320
|
+
if (!native?.extractClassesFromSourceNative) {
|
|
321
|
+
throw new Error(
|
|
322
|
+
`[tailwind-styled/compiler v5] extractClassesFromSourceNative is required but not available.
|
|
323
|
+
Please ensure the native module is properly built.`
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
const result = native.extractClassesFromSourceNative(source);
|
|
327
|
+
if (!result || result.length < 0) {
|
|
328
|
+
throw new Error(
|
|
329
|
+
`[tailwind-styled/compiler v5] extractClassesFromSourceNative returned invalid result.`
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
return result.sort();
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// packages/scanner/src/index.ts
|
|
336
|
+
init_src();
|
|
337
|
+
|
|
338
|
+
// packages/scanner/src/cache-native.ts
|
|
339
|
+
init_native_bridge();
|
|
340
|
+
function defaultCachePath(rootDir, cacheDir) {
|
|
341
|
+
const dir = cacheDir ? path4.resolve(rootDir, cacheDir) : path4.join(process.cwd(), ".cache", "tailwind-styled");
|
|
342
|
+
return path4.join(dir, "scanner-cache.json");
|
|
343
|
+
}
|
|
344
|
+
function readCache(rootDir, cacheDir) {
|
|
345
|
+
const cachePath = defaultCachePath(rootDir, cacheDir);
|
|
346
|
+
const result = cacheReadNative(cachePath);
|
|
347
|
+
return result.entries.map((e) => ({
|
|
348
|
+
file: e.file,
|
|
349
|
+
classes: e.classes,
|
|
350
|
+
hash: e.hash,
|
|
351
|
+
mtimeMs: e.mtimeMs,
|
|
352
|
+
size: e.size,
|
|
353
|
+
hitCount: e.hitCount
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
function writeCache(rootDir, entries, cacheDir) {
|
|
357
|
+
const cachePath = defaultCachePath(rootDir, cacheDir);
|
|
358
|
+
const success = cacheWriteNative(cachePath, entries);
|
|
359
|
+
if (!success) {
|
|
360
|
+
throw new Error(
|
|
361
|
+
"Native cacheWrite failed. Run 'npm run build:rust' to rebuild native bindings."
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function filePriority(mtimeMs, size, cached, nowMs = Date.now()) {
|
|
366
|
+
return cachePriorityNative(
|
|
367
|
+
mtimeMs,
|
|
368
|
+
size,
|
|
369
|
+
cached?.mtimeMs ?? 0,
|
|
370
|
+
cached?.size ?? 0,
|
|
371
|
+
cached?.hitCount ?? 0,
|
|
372
|
+
cached?.lastSeenMs ?? 0,
|
|
373
|
+
nowMs
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// packages/scanner/src/index.ts
|
|
378
|
+
init_native_bridge();
|
|
379
|
+
var log2 = createLogger("scanner");
|
|
380
|
+
var SCAN_WORKER_TIMEOUT_MS = 12e4;
|
|
381
|
+
var SCAN_WORKER_BOOTSTRAP = `
|
|
382
|
+
const { parentPort, workerData } = require("node:worker_threads")
|
|
383
|
+
try {
|
|
384
|
+
const scanner = require(workerData.modulePath)
|
|
385
|
+
const result = scanner.scanWorkspace(workerData.rootDir, workerData.options ?? {})
|
|
386
|
+
parentPort.postMessage({ ok: true, result })
|
|
387
|
+
} catch (error) {
|
|
388
|
+
parentPort.postMessage({
|
|
389
|
+
ok: false,
|
|
390
|
+
error: error instanceof Error ? error.message : String(error),
|
|
391
|
+
})
|
|
392
|
+
}
|
|
393
|
+
`;
|
|
394
|
+
var nativeParserBinding;
|
|
395
|
+
var nativeParserInitError = null;
|
|
396
|
+
function canUseCjsRequire() {
|
|
397
|
+
return typeof __require === "function";
|
|
398
|
+
}
|
|
399
|
+
function debugNative(message) {
|
|
400
|
+
log2.debug(`[native] ${message}`);
|
|
401
|
+
}
|
|
402
|
+
function loadNativeParserBinding() {
|
|
403
|
+
if (nativeParserBinding !== void 0) return nativeParserBinding;
|
|
404
|
+
if (!canUseCjsRequire()) {
|
|
405
|
+
nativeParserBinding = null;
|
|
406
|
+
nativeParserInitError = "require is unavailable in current module format";
|
|
407
|
+
debugNative(`fallback to JS: ${nativeParserInitError}`);
|
|
408
|
+
return nativeParserBinding;
|
|
409
|
+
}
|
|
410
|
+
const candidates = [
|
|
411
|
+
path4.resolve(process.cwd(), "native/tailwind_styled_parser.node"),
|
|
412
|
+
path4.resolve(process.cwd(), "native/build/Release/tailwind_styled_parser.node")
|
|
413
|
+
];
|
|
414
|
+
for (const fullPath of candidates) {
|
|
415
|
+
if (!fs.existsSync(fullPath)) continue;
|
|
416
|
+
try {
|
|
417
|
+
const required = __require(fullPath);
|
|
418
|
+
if (required && typeof required.parse_classes === "function") {
|
|
419
|
+
nativeParserBinding = required;
|
|
420
|
+
debugNative(`using native parser from ${fullPath}`);
|
|
421
|
+
return nativeParserBinding;
|
|
422
|
+
}
|
|
423
|
+
} catch (error) {
|
|
424
|
+
nativeParserInitError = error instanceof Error ? error.message : String(error);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
nativeParserBinding = null;
|
|
428
|
+
if (!nativeParserInitError) {
|
|
429
|
+
nativeParserInitError = "native .node binding not found";
|
|
430
|
+
}
|
|
431
|
+
debugNative(`fallback to JS: ${nativeParserInitError}`);
|
|
432
|
+
return nativeParserBinding;
|
|
433
|
+
}
|
|
434
|
+
function normalizeWithNativeParser(tokens) {
|
|
435
|
+
const binding = loadNativeParserBinding();
|
|
436
|
+
if (!binding || typeof binding.parse_classes !== "function") {
|
|
437
|
+
throw new Error(
|
|
438
|
+
"Native parser binding is required but not available. Run 'npm run build:rust' to build it."
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
try {
|
|
442
|
+
const parsed = binding.parse_classes(tokens.join(" "));
|
|
443
|
+
const normalized = parsed.map((item) => item.raw?.trim() ?? "").filter(Boolean);
|
|
444
|
+
return Array.from(new Set(normalized));
|
|
445
|
+
} catch (error) {
|
|
446
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
447
|
+
throw new Error(`Native parser failed: ${errorMessage}. Run 'npm run build:rust' to rebuild.`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
var DEFAULT_EXTENSIONS = [".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
451
|
+
var DEFAULT_IGNORES = ["node_modules", ".git", ".next", "dist", "out", ".turbo", ".cache"];
|
|
452
|
+
function resolveScannerWorkerModulePath() {
|
|
453
|
+
const runtimeDir2 = typeof __dirname === "string" && __dirname.length > 0 ? __dirname : path4.dirname(fileURLToPath(import.meta.url));
|
|
454
|
+
const candidates = [
|
|
455
|
+
path4.resolve(runtimeDir2, "index.cjs"),
|
|
456
|
+
path4.resolve(runtimeDir2, "index.js"),
|
|
457
|
+
path4.resolve(runtimeDir2, "index.ts")
|
|
458
|
+
];
|
|
459
|
+
for (const candidate of candidates) {
|
|
460
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
461
|
+
}
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
function scanWorkspaceInWorker(rootDir, options) {
|
|
465
|
+
const modulePath = resolveScannerWorkerModulePath();
|
|
466
|
+
if (!modulePath) {
|
|
467
|
+
return Promise.reject(new Error("scanner worker module path could not be resolved"));
|
|
468
|
+
}
|
|
469
|
+
return new Promise((resolve, reject) => {
|
|
470
|
+
let settled = false;
|
|
471
|
+
const worker = new Worker(SCAN_WORKER_BOOTSTRAP, {
|
|
472
|
+
eval: true,
|
|
473
|
+
workerData: { modulePath, rootDir, options }
|
|
474
|
+
});
|
|
475
|
+
const timeout = setTimeout(() => {
|
|
476
|
+
if (settled) return;
|
|
477
|
+
settled = true;
|
|
478
|
+
void worker.terminate();
|
|
479
|
+
reject(new Error(`scanner worker timed out after ${SCAN_WORKER_TIMEOUT_MS}ms`));
|
|
480
|
+
}, SCAN_WORKER_TIMEOUT_MS);
|
|
481
|
+
const finish = (callback) => {
|
|
482
|
+
if (settled) return;
|
|
483
|
+
settled = true;
|
|
484
|
+
clearTimeout(timeout);
|
|
485
|
+
callback();
|
|
486
|
+
};
|
|
487
|
+
worker.once("message", (payload) => {
|
|
488
|
+
const message = payload;
|
|
489
|
+
finish(() => {
|
|
490
|
+
if (message?.ok) {
|
|
491
|
+
resolve(message.result);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
reject(new Error(message?.error ?? "scanner worker failed without an error message"));
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
worker.once("error", (error) => {
|
|
498
|
+
finish(() => reject(error));
|
|
499
|
+
});
|
|
500
|
+
worker.once("exit", (code) => {
|
|
501
|
+
if (code !== 0) {
|
|
502
|
+
finish(() => reject(new Error(`scanner worker exited with code ${code}`)));
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
function buildExtensionSet(includeExtensions) {
|
|
508
|
+
return new Set(includeExtensions);
|
|
509
|
+
}
|
|
510
|
+
function collectCandidates(rootDir, ignoreDirectories, extensionSet) {
|
|
511
|
+
const candidates = [];
|
|
512
|
+
const directories = [rootDir];
|
|
513
|
+
while (directories.length > 0) {
|
|
514
|
+
const currentDir = directories.pop();
|
|
515
|
+
if (!currentDir) continue;
|
|
516
|
+
let entries = [];
|
|
517
|
+
try {
|
|
518
|
+
entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
519
|
+
} catch {
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
for (const entry of entries) {
|
|
523
|
+
const fullPath = path4.join(currentDir, entry.name);
|
|
524
|
+
if (entry.isDirectory()) {
|
|
525
|
+
if (!ignoreDirectories.has(entry.name)) directories.push(fullPath);
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
if (!entry.isFile()) continue;
|
|
529
|
+
if (!extensionSet.has(path4.extname(entry.name))) continue;
|
|
530
|
+
candidates.push(fullPath);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return candidates;
|
|
534
|
+
}
|
|
535
|
+
function toCacheSize(size) {
|
|
536
|
+
if (!Number.isFinite(size)) return 0;
|
|
537
|
+
const normalized = Math.max(0, Math.trunc(size));
|
|
538
|
+
return Math.min(normalized, 4294967295);
|
|
539
|
+
}
|
|
540
|
+
function extractClassesJs(source) {
|
|
541
|
+
return extractAllClasses(source);
|
|
542
|
+
}
|
|
543
|
+
function scanSource(source) {
|
|
544
|
+
const nativeBinding = loadNativeParserBinding();
|
|
545
|
+
if (nativeBinding && typeof nativeBinding.parse_classes === "function") {
|
|
546
|
+
try {
|
|
547
|
+
const baseClasses = extractClassesJs(source);
|
|
548
|
+
const nativeNormalized = normalizeWithNativeParser(baseClasses);
|
|
549
|
+
return nativeNormalized;
|
|
550
|
+
} catch (error) {
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
throw new Error(
|
|
555
|
+
"Native parser binding is required but not available. Run 'npm run build:rust' to build it."
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
function isScannableFile(filePath, includeExtensions = DEFAULT_EXTENSIONS) {
|
|
559
|
+
return includeExtensions.includes(path4.extname(filePath));
|
|
560
|
+
}
|
|
561
|
+
function scanFile(filePath) {
|
|
562
|
+
const source = fs.readFileSync(filePath, "utf8");
|
|
563
|
+
const hash = hashContentNative(source) ?? void 0;
|
|
564
|
+
return {
|
|
565
|
+
file: filePath,
|
|
566
|
+
classes: scanSource(source),
|
|
567
|
+
...hash ? { hash } : {}
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function scanWorkspace(rootDir, options = {}) {
|
|
571
|
+
const includeExtensions = options.includeExtensions ?? DEFAULT_EXTENSIONS;
|
|
572
|
+
const extensionSet = buildExtensionSet(includeExtensions);
|
|
573
|
+
const ignoreDirectories = new Set(options.ignoreDirectories ?? DEFAULT_IGNORES);
|
|
574
|
+
const useCache = options.useCache ?? true;
|
|
575
|
+
options.smartInvalidation ?? true;
|
|
576
|
+
const files = [];
|
|
577
|
+
const unique = /* @__PURE__ */ new Set();
|
|
578
|
+
const candidates = collectCandidates(rootDir, ignoreDirectories, extensionSet);
|
|
579
|
+
const processResult = (result) => {
|
|
580
|
+
files.push(result);
|
|
581
|
+
for (const cls of result.classes) unique.add(cls);
|
|
582
|
+
};
|
|
583
|
+
const { scanWorkspaceNative: scanWorkspaceNative2 } = (init_native_bridge(), __toCommonJS(native_bridge_exports));
|
|
584
|
+
if (!options.cacheDir && !useCache) {
|
|
585
|
+
const nativeResult = scanWorkspaceNative2(rootDir, includeExtensions);
|
|
586
|
+
if (nativeResult) {
|
|
587
|
+
return {
|
|
588
|
+
files: nativeResult.files.map((f) => ({
|
|
589
|
+
file: f.file,
|
|
590
|
+
classes: f.classes
|
|
591
|
+
})),
|
|
592
|
+
totalFiles: nativeResult.totalFiles,
|
|
593
|
+
uniqueClasses: nativeResult.uniqueClasses
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
if (useCache && isRustCacheAvailable()) {
|
|
598
|
+
let cacheEntries = [];
|
|
599
|
+
try {
|
|
600
|
+
cacheEntries = readCache(rootDir, options.cacheDir);
|
|
601
|
+
} catch (error) {
|
|
602
|
+
cacheEntries = [];
|
|
603
|
+
log2.debug(
|
|
604
|
+
`cache read failed, continuing without persisted cache: ${error instanceof Error ? error.message : String(error)}`
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
const cacheMap = new Map(cacheEntries.map((entry) => [entry.file, entry]));
|
|
608
|
+
const nowMs = Date.now();
|
|
609
|
+
const ranked = [];
|
|
610
|
+
for (const filePath of candidates) {
|
|
611
|
+
let stat;
|
|
612
|
+
try {
|
|
613
|
+
stat = fs.statSync(filePath);
|
|
614
|
+
} catch {
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
const size = toCacheSize(stat.size);
|
|
618
|
+
const cached = cacheMap.get(filePath);
|
|
619
|
+
const priority = filePriority(
|
|
620
|
+
stat.mtimeMs,
|
|
621
|
+
size,
|
|
622
|
+
cached ? {
|
|
623
|
+
mtimeMs: cached.mtimeMs,
|
|
624
|
+
size: cached.size,
|
|
625
|
+
hitCount: cached.hitCount,
|
|
626
|
+
lastSeenMs: 0
|
|
627
|
+
} : void 0,
|
|
628
|
+
nowMs
|
|
629
|
+
);
|
|
630
|
+
ranked.push({ filePath, stat, size, cached, priority });
|
|
631
|
+
}
|
|
632
|
+
ranked.sort((a, b) => b.priority - a.priority);
|
|
633
|
+
const updatedEntries = [];
|
|
634
|
+
for (const { filePath, stat, size, cached } of ranked) {
|
|
635
|
+
let content;
|
|
636
|
+
try {
|
|
637
|
+
content = fs.readFileSync(filePath, "utf8");
|
|
638
|
+
} catch {
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
const hash = hashContentNative(content);
|
|
642
|
+
if (cached && cached.hash === hash && cached.mtimeMs === stat.mtimeMs && cached.size === size) {
|
|
643
|
+
log2.debug(`cache HIT ${filePath}`);
|
|
644
|
+
processResult({ file: filePath, classes: cached.classes });
|
|
645
|
+
updatedEntries.push({
|
|
646
|
+
file: filePath,
|
|
647
|
+
classes: cached.classes,
|
|
648
|
+
hash: cached.hash,
|
|
649
|
+
mtimeMs: stat.mtimeMs,
|
|
650
|
+
size,
|
|
651
|
+
hitCount: (cached.hitCount ?? 0) + 1
|
|
652
|
+
});
|
|
653
|
+
continue;
|
|
654
|
+
}
|
|
655
|
+
log2.debug(`cache MISS ${filePath}`);
|
|
656
|
+
const classes = scanSource(content);
|
|
657
|
+
processResult({ file: filePath, classes });
|
|
658
|
+
updatedEntries.push({
|
|
659
|
+
file: filePath,
|
|
660
|
+
classes,
|
|
661
|
+
hash,
|
|
662
|
+
mtimeMs: stat.mtimeMs,
|
|
663
|
+
size,
|
|
664
|
+
hitCount: 1
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
try {
|
|
668
|
+
writeCache(rootDir, updatedEntries, options.cacheDir);
|
|
669
|
+
} catch (error) {
|
|
670
|
+
log2.debug(`cache write failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
671
|
+
}
|
|
672
|
+
return {
|
|
673
|
+
files,
|
|
674
|
+
totalFiles: files.length,
|
|
675
|
+
uniqueClasses: Array.from(unique).sort()
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
for (const filePath of candidates) {
|
|
679
|
+
processResult(scanFile(filePath));
|
|
680
|
+
}
|
|
681
|
+
return {
|
|
682
|
+
files,
|
|
683
|
+
totalFiles: files.length,
|
|
684
|
+
uniqueClasses: Array.from(unique).sort()
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
async function scanWorkspaceAsync(rootDir, options = {}) {
|
|
688
|
+
if (process.env.TWS_DISABLE_SCANNER_WORKER === "1") {
|
|
689
|
+
return scanWorkspace(rootDir, options);
|
|
690
|
+
}
|
|
691
|
+
try {
|
|
692
|
+
return await scanWorkspaceInWorker(rootDir, options);
|
|
693
|
+
} catch (error) {
|
|
694
|
+
log2.debug(
|
|
695
|
+
`worker scan failed, falling back to sync scanner: ${error instanceof Error ? error.message : String(error)}`
|
|
696
|
+
);
|
|
697
|
+
return scanWorkspace(rootDir, options);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
export { DEFAULT_EXTENSIONS, DEFAULT_IGNORES, isScannableFile, scanFile, scanSource, scanWorkspace, scanWorkspaceAsync };
|
|
702
|
+
//# sourceMappingURL=scanner.mjs.map
|
|
703
|
+
//# sourceMappingURL=scanner.mjs.map
|