@typestyles/cli 0.0.0-unstable.3a8feb2a3be6 → 0.0.0-unstable.3b624adca193
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cli.cjs +86 -488
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +83 -84
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +12 -457
- package/dist/index.d.cts +31 -29
- package/dist/index.d.ts +31 -29
- package/dist/index.js +1 -3
- package/dist/snapshot-classnames-BVrvtE-T.cjs +515 -0
- package/dist/snapshot-classnames-BVrvtE-T.cjs.map +1 -0
- package/dist/snapshot-classnames-Blbh1QKS.js +424 -0
- package/dist/snapshot-classnames-Blbh1QKS.js.map +1 -0
- package/package.json +8 -10
- package/dist/chunk-33SCDWZ3.js +0 -439
- package/dist/chunk-33SCDWZ3.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,457 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var fg__default = /*#__PURE__*/_interopDefault(fg);
|
|
14
|
-
|
|
15
|
-
// src/snapshot-classnames.ts
|
|
16
|
-
function sanitizeClassSegment(label) {
|
|
17
|
-
const normalized = label.trim().toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
18
|
-
return normalized.replace(/-+/g, "-").replace(/^-|-$/g, "") || "style";
|
|
19
|
-
}
|
|
20
|
-
var RESERVED_COMPONENT_KEYS = /* @__PURE__ */ new Set([
|
|
21
|
-
"base",
|
|
22
|
-
"variants",
|
|
23
|
-
"compoundVariants",
|
|
24
|
-
"defaultVariants",
|
|
25
|
-
"slots"
|
|
26
|
-
]);
|
|
27
|
-
var PUBLIC_CLASSNAMES_SNAPSHOT = ".typestyles-public-classnames.json";
|
|
28
|
-
var DEFAULT_INCLUDE = ["**/*.{ts,tsx}"];
|
|
29
|
-
var DEFAULT_EXCLUDE = [
|
|
30
|
-
"**/node_modules/**",
|
|
31
|
-
"**/dist/**",
|
|
32
|
-
"**/*.d.ts",
|
|
33
|
-
"**/*.test.{ts,tsx}",
|
|
34
|
-
"**/*.spec.{ts,tsx}"
|
|
35
|
-
];
|
|
36
|
-
function semanticScopePrefix(scopeId) {
|
|
37
|
-
if (!scopeId.trim()) return "";
|
|
38
|
-
return `${sanitizeClassSegment(scopeId)}-`;
|
|
39
|
-
}
|
|
40
|
-
function semanticClassName(config, namespace, suffix) {
|
|
41
|
-
if (config.mode === "hashed" || config.mode === "compact" || config.mode === "atomic" || config.mode === "template") {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
const prefix = semanticScopePrefix(config.scopeId);
|
|
45
|
-
if (suffix === void 0 || suffix === "base") return `${prefix}${namespace}`;
|
|
46
|
-
if (config.mode === "attribute") return `${prefix}${namespace}`;
|
|
47
|
-
if (config.mode === "bem") return `${prefix}${namespace}--${suffix}`;
|
|
48
|
-
return `${prefix}${namespace}--${suffix}`;
|
|
49
|
-
}
|
|
50
|
-
function getStaticObjectKey(name) {
|
|
51
|
-
if (ts__default.default.isIdentifier(name)) return name.text;
|
|
52
|
-
if (ts__default.default.isStringLiteral(name)) return name.text;
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
function firstStringArg(args) {
|
|
56
|
-
const first = args[0];
|
|
57
|
-
if (!first || !ts__default.default.isStringLiteral(first)) return null;
|
|
58
|
-
return first.text;
|
|
59
|
-
}
|
|
60
|
-
function unwrapExpression(expr) {
|
|
61
|
-
let current = expr;
|
|
62
|
-
while (ts__default.default.isParenthesizedExpression(current)) {
|
|
63
|
-
current = current.expression;
|
|
64
|
-
}
|
|
65
|
-
return current;
|
|
66
|
-
}
|
|
67
|
-
function objectExpressionFromConfigArg(arg) {
|
|
68
|
-
if (!arg) return null;
|
|
69
|
-
const expr = unwrapExpression(arg);
|
|
70
|
-
if (ts__default.default.isObjectLiteralExpression(expr)) return expr;
|
|
71
|
-
if (ts__default.default.isArrowFunction(expr)) {
|
|
72
|
-
if (ts__default.default.isObjectLiteralExpression(expr.body)) return expr.body;
|
|
73
|
-
if (ts__default.default.isBlock(expr.body)) {
|
|
74
|
-
for (const stmt of expr.body.statements) {
|
|
75
|
-
if (ts__default.default.isReturnStatement(stmt) && stmt.expression && ts__default.default.isObjectLiteralExpression(unwrapExpression(stmt.expression))) {
|
|
76
|
-
return unwrapExpression(stmt.expression);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
function literalFromProperty(obj, key) {
|
|
84
|
-
for (const prop of obj.properties) {
|
|
85
|
-
if (!ts__default.default.isPropertyAssignment(prop)) continue;
|
|
86
|
-
const propKey = getStaticObjectKey(prop.name);
|
|
87
|
-
if (propKey !== key) continue;
|
|
88
|
-
const init = unwrapExpression(prop.initializer);
|
|
89
|
-
if (ts__default.default.isStringLiteral(init)) return init.text;
|
|
90
|
-
if (ts__default.default.isNoSubstitutionTemplateLiteral(init)) return init.text;
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
function hasObjectKey(obj, key) {
|
|
95
|
-
return obj.properties.some((prop) => {
|
|
96
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
97
|
-
return getStaticObjectKey(prop.name) === key;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
function collectClassNamePartsFromConfig(obj) {
|
|
101
|
-
const parts = [];
|
|
102
|
-
const hasVariants = hasObjectKey(obj, "variants");
|
|
103
|
-
const hasCompound = hasObjectKey(obj, "compoundVariants");
|
|
104
|
-
const hasDefaults = hasObjectKey(obj, "defaultVariants");
|
|
105
|
-
const hasSlots = hasObjectKey(obj, "slots");
|
|
106
|
-
if (hasSlots && (hasVariants || hasCompound || hasDefaults)) {
|
|
107
|
-
const baseObj = obj.properties.find((prop) => {
|
|
108
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
109
|
-
return getStaticObjectKey(prop.name) === "base";
|
|
110
|
-
});
|
|
111
|
-
if (baseObj && ts__default.default.isPropertyAssignment(baseObj) && ts__default.default.isObjectLiteralExpression(baseObj.initializer)) {
|
|
112
|
-
for (const slotProp of baseObj.initializer.properties) {
|
|
113
|
-
if (!ts__default.default.isPropertyAssignment(slotProp)) continue;
|
|
114
|
-
const slot = getStaticObjectKey(slotProp.name);
|
|
115
|
-
if (slot) parts.push({ element: slot === "root" ? void 0 : slot });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const variantsProp = obj.properties.find((prop) => {
|
|
119
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
120
|
-
return getStaticObjectKey(prop.name) === "variants";
|
|
121
|
-
});
|
|
122
|
-
if (variantsProp && ts__default.default.isPropertyAssignment(variantsProp) && ts__default.default.isObjectLiteralExpression(variantsProp.initializer)) {
|
|
123
|
-
for (const dimProp of variantsProp.initializer.properties) {
|
|
124
|
-
if (!ts__default.default.isPropertyAssignment(dimProp) || !ts__default.default.isObjectLiteralExpression(dimProp.initializer)) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
const dimension = getStaticObjectKey(dimProp.name);
|
|
128
|
-
if (!dimension) continue;
|
|
129
|
-
for (const optProp of dimProp.initializer.properties) {
|
|
130
|
-
if (!ts__default.default.isPropertyAssignment(optProp) || !ts__default.default.isObjectLiteralExpression(optProp.initializer)) {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
const option = getStaticObjectKey(optProp.name);
|
|
134
|
-
if (!option) continue;
|
|
135
|
-
for (const slotProp of optProp.initializer.properties) {
|
|
136
|
-
if (!ts__default.default.isPropertyAssignment(slotProp)) continue;
|
|
137
|
-
const slot = getStaticObjectKey(slotProp.name);
|
|
138
|
-
if (slot) {
|
|
139
|
-
parts.push({
|
|
140
|
-
element: slot === "root" ? void 0 : slot,
|
|
141
|
-
dimension,
|
|
142
|
-
modifier: option
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return parts;
|
|
150
|
-
}
|
|
151
|
-
if (hasSlots && !hasVariants && !hasCompound && !hasDefaults) {
|
|
152
|
-
const slotsProp = obj.properties.find((prop) => {
|
|
153
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
154
|
-
return getStaticObjectKey(prop.name) === "slots";
|
|
155
|
-
});
|
|
156
|
-
if (slotsProp && ts__default.default.isPropertyAssignment(slotsProp) && ts__default.default.isArrayLiteralExpression(slotsProp.initializer)) {
|
|
157
|
-
for (const element of slotsProp.initializer.elements) {
|
|
158
|
-
if (element && ts__default.default.isStringLiteral(element)) {
|
|
159
|
-
parts.push({ element: element.text === "root" ? void 0 : element.text });
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
for (const prop of obj.properties) {
|
|
164
|
-
if (!ts__default.default.isPropertyAssignment(prop)) continue;
|
|
165
|
-
const key = getStaticObjectKey(prop.name);
|
|
166
|
-
if (!key || key === "slots") continue;
|
|
167
|
-
parts.push({ element: key === "root" ? void 0 : key });
|
|
168
|
-
}
|
|
169
|
-
return parts;
|
|
170
|
-
}
|
|
171
|
-
if (hasVariants || hasCompound || hasDefaults) {
|
|
172
|
-
parts.push({});
|
|
173
|
-
const variantsProp = obj.properties.find((prop) => {
|
|
174
|
-
if (!ts__default.default.isPropertyAssignment(prop)) return false;
|
|
175
|
-
return getStaticObjectKey(prop.name) === "variants";
|
|
176
|
-
});
|
|
177
|
-
if (variantsProp && ts__default.default.isPropertyAssignment(variantsProp) && ts__default.default.isObjectLiteralExpression(variantsProp.initializer)) {
|
|
178
|
-
for (const dimProp of variantsProp.initializer.properties) {
|
|
179
|
-
if (!ts__default.default.isPropertyAssignment(dimProp) || !ts__default.default.isObjectLiteralExpression(dimProp.initializer)) {
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
const dimension = getStaticObjectKey(dimProp.name);
|
|
183
|
-
if (!dimension) continue;
|
|
184
|
-
for (const optProp of dimProp.initializer.properties) {
|
|
185
|
-
if (!ts__default.default.isPropertyAssignment(optProp)) continue;
|
|
186
|
-
const option = getStaticObjectKey(optProp.name);
|
|
187
|
-
if (option) parts.push({ dimension, modifier: option });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return parts;
|
|
192
|
-
}
|
|
193
|
-
for (const prop of obj.properties) {
|
|
194
|
-
if (!ts__default.default.isPropertyAssignment(prop)) continue;
|
|
195
|
-
const key = getStaticObjectKey(prop.name);
|
|
196
|
-
if (!key) continue;
|
|
197
|
-
if (key === "base") {
|
|
198
|
-
parts.push({});
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
if (RESERVED_COMPONENT_KEYS.has(key)) continue;
|
|
202
|
-
parts.push({ modifier: key });
|
|
203
|
-
}
|
|
204
|
-
return parts;
|
|
205
|
-
}
|
|
206
|
-
function componentClassName(config, namespace, part) {
|
|
207
|
-
if (config.mode === "hashed" || config.mode === "compact" || config.mode === "atomic" || config.mode === "template") {
|
|
208
|
-
return null;
|
|
209
|
-
}
|
|
210
|
-
const prefix = semanticScopePrefix(config.scopeId);
|
|
211
|
-
const block = `${prefix}${namespace}${part.element ? `__${part.element}` : ""}`;
|
|
212
|
-
if (!part.modifier) return block;
|
|
213
|
-
if (config.mode === "attribute" && part.dimension) return block;
|
|
214
|
-
if (config.mode === "bem") return `${block}--${part.modifier}`;
|
|
215
|
-
return `${block}--${part.dimension ? `${part.dimension}-` : ""}${part.modifier}`;
|
|
216
|
-
}
|
|
217
|
-
function parseCreateStylesConfig(init) {
|
|
218
|
-
const config = { mode: "semantic", scopeId: "" };
|
|
219
|
-
let expr = unwrapExpression(init);
|
|
220
|
-
if (ts__default.default.isCallExpression(expr)) {
|
|
221
|
-
const firstArg = expr.arguments[0];
|
|
222
|
-
if (!firstArg) return config;
|
|
223
|
-
expr = unwrapExpression(firstArg);
|
|
224
|
-
}
|
|
225
|
-
if (!ts__default.default.isObjectLiteralExpression(expr)) return config;
|
|
226
|
-
const mode = literalFromProperty(expr, "mode");
|
|
227
|
-
if (mode === "semantic" || mode === "hashed" || mode === "compact" || mode === "atomic" || mode === "attribute" || mode === "bem" || mode === "template") {
|
|
228
|
-
config.mode = mode;
|
|
229
|
-
}
|
|
230
|
-
const scopeId = literalFromProperty(expr, "scopeId");
|
|
231
|
-
if (scopeId != null) config.scopeId = scopeId;
|
|
232
|
-
return config;
|
|
233
|
-
}
|
|
234
|
-
function isCreateStylesCall(expr) {
|
|
235
|
-
const unwrapped = unwrapExpression(expr);
|
|
236
|
-
if (!ts__default.default.isCallExpression(unwrapped)) return false;
|
|
237
|
-
const callee = unwrapped.expression;
|
|
238
|
-
if (ts__default.default.isIdentifier(callee) && (callee.text === "createStyles" || callee.text === "createTypeStyles")) {
|
|
239
|
-
return true;
|
|
240
|
-
}
|
|
241
|
-
if (ts__default.default.isPropertyAccessExpression(callee) && ts__default.default.isIdentifier(callee.expression) && callee.expression.text === "typestyles" && (callee.name.text === "createStyles" || callee.name.text === "createTypeStyles")) {
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
function registerBindingFromCreateCall(bindings, name, init) {
|
|
247
|
-
bindings.set(name, parseCreateStylesConfig(init));
|
|
248
|
-
}
|
|
249
|
-
function collectBindings(sourceFile) {
|
|
250
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
251
|
-
const visit = (node) => {
|
|
252
|
-
if (ts__default.default.isVariableDeclaration(node) && node.initializer && isCreateStylesCall(node.initializer)) {
|
|
253
|
-
if (ts__default.default.isIdentifier(node.name)) {
|
|
254
|
-
registerBindingFromCreateCall(bindings, node.name.text, node.initializer);
|
|
255
|
-
} else if (ts__default.default.isObjectBindingPattern(node.name)) {
|
|
256
|
-
const config = parseCreateStylesConfig(node.initializer);
|
|
257
|
-
for (const element of node.name.elements) {
|
|
258
|
-
if (ts__default.default.isBindingElement(element) && ts__default.default.isIdentifier(element.name)) {
|
|
259
|
-
bindings.set(element.name.text, config);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
ts__default.default.forEachChild(node, visit);
|
|
265
|
-
};
|
|
266
|
-
visit(sourceFile);
|
|
267
|
-
return bindings;
|
|
268
|
-
}
|
|
269
|
-
function calleeMethodName(expr) {
|
|
270
|
-
if (!ts__default.default.isPropertyAccessExpression(expr)) return null;
|
|
271
|
-
if (ts__default.default.isIdentifier(expr.name)) return expr.name.text;
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
function lineOf(sourceFile, node) {
|
|
275
|
-
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
276
|
-
return line + 1;
|
|
277
|
-
}
|
|
278
|
-
function stylesBindingFromCallee(expr, bindings, defaultConfig) {
|
|
279
|
-
if (ts__default.default.isPropertyAccessExpression(expr) && ts__default.default.isIdentifier(expr.expression)) {
|
|
280
|
-
const binding = bindings.get(expr.expression.text);
|
|
281
|
-
if (binding) return binding;
|
|
282
|
-
if (expr.expression.text === "styles" && defaultConfig) return defaultConfig;
|
|
283
|
-
}
|
|
284
|
-
if (ts__default.default.isIdentifier(expr) && expr.text === "styles") {
|
|
285
|
-
return bindings.get("styles") ?? defaultConfig ?? { mode: "semantic", scopeId: "" };
|
|
286
|
-
}
|
|
287
|
-
return defaultConfig ?? { mode: "semantic", scopeId: "" };
|
|
288
|
-
}
|
|
289
|
-
function mergeProjectBindings(sourceFiles) {
|
|
290
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
291
|
-
const configs = [];
|
|
292
|
-
for (const sourceFile of sourceFiles) {
|
|
293
|
-
const fileBindings = collectBindings(sourceFile);
|
|
294
|
-
for (const [key, value] of fileBindings) {
|
|
295
|
-
bindings.set(key, value);
|
|
296
|
-
configs.push(value);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
const unique = /* @__PURE__ */ new Map();
|
|
300
|
-
for (const config of configs) {
|
|
301
|
-
unique.set(`${config.mode}:${config.scopeId}`, config);
|
|
302
|
-
}
|
|
303
|
-
const defaultConfig = unique.size === 1 ? [...unique.values()][0] : void 0;
|
|
304
|
-
return { bindings, defaultConfig };
|
|
305
|
-
}
|
|
306
|
-
function collectCallsFromSourceFile(sourceFile, relativePath, bindings, defaultConfig) {
|
|
307
|
-
const entries = [];
|
|
308
|
-
const visit = (node) => {
|
|
309
|
-
if (ts__default.default.isCallExpression(node)) {
|
|
310
|
-
const method = calleeMethodName(node.expression);
|
|
311
|
-
if (method === "class" || method === "component") {
|
|
312
|
-
const namespace = firstStringArg(node.arguments);
|
|
313
|
-
if (!namespace) {
|
|
314
|
-
ts__default.default.forEachChild(node, visit);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const config = stylesBindingFromCallee(node.expression, bindings, defaultConfig);
|
|
318
|
-
const line = lineOf(sourceFile, node.arguments[0] ?? node);
|
|
319
|
-
if (method === "class") {
|
|
320
|
-
const className = semanticClassName(config, namespace);
|
|
321
|
-
if (className) {
|
|
322
|
-
entries.push({
|
|
323
|
-
className,
|
|
324
|
-
kind: "class",
|
|
325
|
-
namespace,
|
|
326
|
-
file: relativePath,
|
|
327
|
-
line
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
} else {
|
|
331
|
-
const configObj = objectExpressionFromConfigArg(node.arguments[1]);
|
|
332
|
-
const parts = configObj ? collectClassNamePartsFromConfig(configObj) : [{}];
|
|
333
|
-
for (const part of parts) {
|
|
334
|
-
const className = componentClassName(config, namespace, part);
|
|
335
|
-
if (className) {
|
|
336
|
-
entries.push({
|
|
337
|
-
className,
|
|
338
|
-
kind: "component",
|
|
339
|
-
namespace,
|
|
340
|
-
suffix: part.modifier ? `${part.element ? `${part.element}-` : ""}${part.dimension ? `${part.dimension}-` : ""}${part.modifier}` : part.element ?? "base",
|
|
341
|
-
file: relativePath,
|
|
342
|
-
line
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
ts__default.default.forEachChild(node, visit);
|
|
350
|
-
};
|
|
351
|
-
visit(sourceFile);
|
|
352
|
-
return entries;
|
|
353
|
-
}
|
|
354
|
-
function collectPublicClassNamesFromFiles(filePaths, rootDir) {
|
|
355
|
-
const parsed = filePaths.map((filePath) => {
|
|
356
|
-
const sourceText = fs__default.default.readFileSync(filePath, "utf8");
|
|
357
|
-
const sourceFile = ts__default.default.createSourceFile(
|
|
358
|
-
filePath,
|
|
359
|
-
sourceText,
|
|
360
|
-
ts__default.default.ScriptTarget.Latest,
|
|
361
|
-
true,
|
|
362
|
-
filePath.endsWith(".tsx") ? ts__default.default.ScriptKind.TSX : ts__default.default.ScriptKind.TS
|
|
363
|
-
);
|
|
364
|
-
return { filePath, sourceFile, relativePath: path__default.default.relative(rootDir, filePath) };
|
|
365
|
-
});
|
|
366
|
-
const { bindings, defaultConfig } = mergeProjectBindings(parsed.map((item) => item.sourceFile));
|
|
367
|
-
const entries = [];
|
|
368
|
-
for (const { sourceFile, relativePath } of parsed) {
|
|
369
|
-
entries.push(...collectCallsFromSourceFile(sourceFile, relativePath, bindings, defaultConfig));
|
|
370
|
-
}
|
|
371
|
-
return dedupeEntries(entries);
|
|
372
|
-
}
|
|
373
|
-
function dedupeEntries(entries) {
|
|
374
|
-
const byClass = /* @__PURE__ */ new Map();
|
|
375
|
-
for (const entry of entries) {
|
|
376
|
-
if (!byClass.has(entry.className)) {
|
|
377
|
-
byClass.set(entry.className, entry);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return [...byClass.values()].sort((a, b) => a.className.localeCompare(b.className));
|
|
381
|
-
}
|
|
382
|
-
async function collectPublicClassNames(options = {}) {
|
|
383
|
-
const rootDir = path__default.default.resolve(options.rootDir ?? process.cwd());
|
|
384
|
-
const include = options.include ?? DEFAULT_INCLUDE;
|
|
385
|
-
const exclude = options.exclude ?? DEFAULT_EXCLUDE;
|
|
386
|
-
const files = await fg__default.default(include, {
|
|
387
|
-
cwd: rootDir,
|
|
388
|
-
absolute: true,
|
|
389
|
-
ignore: exclude
|
|
390
|
-
});
|
|
391
|
-
return collectPublicClassNamesFromFiles(files, rootDir);
|
|
392
|
-
}
|
|
393
|
-
function collectPublicClassNamesSync(options = {}) {
|
|
394
|
-
const rootDir = path__default.default.resolve(options.rootDir ?? process.cwd());
|
|
395
|
-
const include = options.include ?? DEFAULT_INCLUDE;
|
|
396
|
-
const exclude = options.exclude ?? DEFAULT_EXCLUDE;
|
|
397
|
-
const files = fg__default.default.sync(include, {
|
|
398
|
-
cwd: rootDir,
|
|
399
|
-
absolute: true,
|
|
400
|
-
ignore: exclude
|
|
401
|
-
});
|
|
402
|
-
return collectPublicClassNamesFromFiles(files, rootDir);
|
|
403
|
-
}
|
|
404
|
-
function resolveProjectStylesBindings(filePaths, _rootDir) {
|
|
405
|
-
const parsed = filePaths.map((filePath) => {
|
|
406
|
-
const sourceText = fs__default.default.readFileSync(filePath, "utf8");
|
|
407
|
-
return ts__default.default.createSourceFile(
|
|
408
|
-
filePath,
|
|
409
|
-
sourceText,
|
|
410
|
-
ts__default.default.ScriptTarget.Latest,
|
|
411
|
-
true,
|
|
412
|
-
filePath.endsWith(".tsx") ? ts__default.default.ScriptKind.TSX : ts__default.default.ScriptKind.TS
|
|
413
|
-
);
|
|
414
|
-
});
|
|
415
|
-
return mergeProjectBindings(parsed).bindings;
|
|
416
|
-
}
|
|
417
|
-
function buildSnapshot(entries) {
|
|
418
|
-
const sorted = dedupeEntries(entries);
|
|
419
|
-
return {
|
|
420
|
-
version: 1,
|
|
421
|
-
classNames: sorted.map((entry) => entry.className),
|
|
422
|
-
entries: sorted
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
function loadPublicClassNamesSnapshot(snapshotPath) {
|
|
426
|
-
if (!fs__default.default.existsSync(snapshotPath)) return null;
|
|
427
|
-
const raw = JSON.parse(fs__default.default.readFileSync(snapshotPath, "utf8"));
|
|
428
|
-
if (!raw || raw.version !== 1 || !Array.isArray(raw.classNames)) {
|
|
429
|
-
throw new Error(
|
|
430
|
-
`[typestyles] Invalid public class name snapshot at ${snapshotPath}. Regenerate with \`typestyles snapshot --write\`.`
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
return raw;
|
|
434
|
-
}
|
|
435
|
-
function writePublicClassNamesSnapshot(snapshotPath, entries) {
|
|
436
|
-
const snapshot = buildSnapshot(entries);
|
|
437
|
-
fs__default.default.writeFileSync(snapshotPath, `${JSON.stringify(snapshot, null, 2)}
|
|
438
|
-
`, "utf8");
|
|
439
|
-
return snapshot;
|
|
440
|
-
}
|
|
441
|
-
function diffRemovedPublicClassNames(snapshot, current) {
|
|
442
|
-
const currentSet = new Set(current.map((entry) => entry.className));
|
|
443
|
-
return snapshot.entries.filter((entry) => !currentSet.has(entry.className));
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
exports.PUBLIC_CLASSNAMES_SNAPSHOT = PUBLIC_CLASSNAMES_SNAPSHOT;
|
|
447
|
-
exports.buildSnapshot = buildSnapshot;
|
|
448
|
-
exports.collectPublicClassNames = collectPublicClassNames;
|
|
449
|
-
exports.collectPublicClassNamesFromFiles = collectPublicClassNamesFromFiles;
|
|
450
|
-
exports.collectPublicClassNamesSync = collectPublicClassNamesSync;
|
|
451
|
-
exports.diffRemovedPublicClassNames = diffRemovedPublicClassNames;
|
|
452
|
-
exports.loadPublicClassNamesSnapshot = loadPublicClassNamesSnapshot;
|
|
453
|
-
exports.resolveProjectStylesBindings = resolveProjectStylesBindings;
|
|
454
|
-
exports.semanticClassName = semanticClassName;
|
|
455
|
-
exports.writePublicClassNamesSnapshot = writePublicClassNamesSnapshot;
|
|
456
|
-
//# sourceMappingURL=index.cjs.map
|
|
457
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_snapshot_classnames = require("./snapshot-classnames-BVrvtE-T.cjs");
|
|
3
|
+
exports.PUBLIC_CLASSNAMES_SNAPSHOT = require_snapshot_classnames.PUBLIC_CLASSNAMES_SNAPSHOT;
|
|
4
|
+
exports.buildSnapshot = require_snapshot_classnames.buildSnapshot;
|
|
5
|
+
exports.collectPublicClassNames = require_snapshot_classnames.collectPublicClassNames;
|
|
6
|
+
exports.collectPublicClassNamesFromFiles = require_snapshot_classnames.collectPublicClassNamesFromFiles;
|
|
7
|
+
exports.collectPublicClassNamesSync = require_snapshot_classnames.collectPublicClassNamesSync;
|
|
8
|
+
exports.diffRemovedPublicClassNames = require_snapshot_classnames.diffRemovedPublicClassNames;
|
|
9
|
+
exports.loadPublicClassNamesSnapshot = require_snapshot_classnames.loadPublicClassNamesSnapshot;
|
|
10
|
+
exports.resolveProjectStylesBindings = require_snapshot_classnames.resolveProjectStylesBindings;
|
|
11
|
+
exports.semanticClassName = require_snapshot_classnames.semanticClassName;
|
|
12
|
+
exports.writePublicClassNamesSnapshot = require_snapshot_classnames.writePublicClassNamesSnapshot;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/snapshot-classnames.d.ts
|
|
2
|
+
export declare const PUBLIC_CLASSNAMES_SNAPSHOT = ".typestyles-public-classnames.json";
|
|
2
3
|
type PublicClassNameEntry = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
className: string;
|
|
5
|
+
kind: 'class' | 'component';
|
|
6
|
+
namespace: string;
|
|
7
|
+
suffix?: string;
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
9
10
|
};
|
|
10
11
|
type PublicClassNamesSnapshot = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
version: 1;
|
|
13
|
+
classNames: string[];
|
|
14
|
+
entries: PublicClassNameEntry[];
|
|
14
15
|
};
|
|
15
16
|
type StylesBindingConfig = {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
mode: 'semantic' | 'hashed' | 'compact' | 'atomic' | 'attribute' | 'bem' | 'template';
|
|
18
|
+
scopeId: string;
|
|
18
19
|
};
|
|
19
20
|
type CollectPublicClassNamesOptions = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/** Project root for resolving snapshot paths and globs */
|
|
22
|
+
rootDir?: string;
|
|
23
|
+
/** Glob patterns relative to rootDir */
|
|
24
|
+
include?: string[];
|
|
25
|
+
/** Glob patterns to exclude */
|
|
26
|
+
exclude?: string[];
|
|
26
27
|
};
|
|
27
|
-
declare function semanticClassName(config: StylesBindingConfig, namespace: string, suffix?: string): string | null;
|
|
28
|
-
declare function collectPublicClassNamesFromFiles(filePaths: string[], rootDir: string): PublicClassNameEntry[];
|
|
29
|
-
declare function collectPublicClassNames(options?: CollectPublicClassNamesOptions): Promise<PublicClassNameEntry[]>;
|
|
30
|
-
declare function collectPublicClassNamesSync(options?: CollectPublicClassNamesOptions): PublicClassNameEntry[];
|
|
28
|
+
export declare function semanticClassName(config: StylesBindingConfig, namespace: string, suffix?: string): string | null;
|
|
29
|
+
export declare function collectPublicClassNamesFromFiles(filePaths: string[], rootDir: string): PublicClassNameEntry[];
|
|
30
|
+
export declare function collectPublicClassNames(options?: CollectPublicClassNamesOptions): Promise<PublicClassNameEntry[]>;
|
|
31
|
+
export declare function collectPublicClassNamesSync(options?: CollectPublicClassNamesOptions): PublicClassNameEntry[];
|
|
31
32
|
/** @internal Resolve merged `createStyles` / `createTypeStyles` bindings for tests. */
|
|
32
|
-
declare function resolveProjectStylesBindings(filePaths: string[], _rootDir: string): Map<string, StylesBindingConfig>;
|
|
33
|
-
declare function buildSnapshot(entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
34
|
-
declare function loadPublicClassNamesSnapshot(snapshotPath: string): PublicClassNamesSnapshot | null;
|
|
35
|
-
declare function writePublicClassNamesSnapshot(snapshotPath: string, entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
36
|
-
declare function diffRemovedPublicClassNames(snapshot: PublicClassNamesSnapshot, current: PublicClassNameEntry[]): PublicClassNameEntry[];
|
|
37
|
-
|
|
38
|
-
export {
|
|
33
|
+
export declare function resolveProjectStylesBindings(filePaths: string[], _rootDir: string): Map<string, StylesBindingConfig>;
|
|
34
|
+
export declare function buildSnapshot(entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
35
|
+
export declare function loadPublicClassNamesSnapshot(snapshotPath: string): PublicClassNamesSnapshot | null;
|
|
36
|
+
export declare function writePublicClassNamesSnapshot(snapshotPath: string, entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
37
|
+
export declare function diffRemovedPublicClassNames(snapshot: PublicClassNamesSnapshot, current: PublicClassNameEntry[]): PublicClassNameEntry[];
|
|
38
|
+
//#endregion
|
|
39
|
+
export type { CollectPublicClassNamesOptions, PublicClassNameEntry, PublicClassNamesSnapshot, StylesBindingConfig };
|
|
40
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/snapshot-classnames.d.ts
|
|
2
|
+
export declare const PUBLIC_CLASSNAMES_SNAPSHOT = ".typestyles-public-classnames.json";
|
|
2
3
|
type PublicClassNameEntry = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
className: string;
|
|
5
|
+
kind: 'class' | 'component';
|
|
6
|
+
namespace: string;
|
|
7
|
+
suffix?: string;
|
|
8
|
+
file: string;
|
|
9
|
+
line: number;
|
|
9
10
|
};
|
|
10
11
|
type PublicClassNamesSnapshot = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
version: 1;
|
|
13
|
+
classNames: string[];
|
|
14
|
+
entries: PublicClassNameEntry[];
|
|
14
15
|
};
|
|
15
16
|
type StylesBindingConfig = {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
mode: 'semantic' | 'hashed' | 'compact' | 'atomic' | 'attribute' | 'bem' | 'template';
|
|
18
|
+
scopeId: string;
|
|
18
19
|
};
|
|
19
20
|
type CollectPublicClassNamesOptions = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/** Project root for resolving snapshot paths and globs */
|
|
22
|
+
rootDir?: string;
|
|
23
|
+
/** Glob patterns relative to rootDir */
|
|
24
|
+
include?: string[];
|
|
25
|
+
/** Glob patterns to exclude */
|
|
26
|
+
exclude?: string[];
|
|
26
27
|
};
|
|
27
|
-
declare function semanticClassName(config: StylesBindingConfig, namespace: string, suffix?: string): string | null;
|
|
28
|
-
declare function collectPublicClassNamesFromFiles(filePaths: string[], rootDir: string): PublicClassNameEntry[];
|
|
29
|
-
declare function collectPublicClassNames(options?: CollectPublicClassNamesOptions): Promise<PublicClassNameEntry[]>;
|
|
30
|
-
declare function collectPublicClassNamesSync(options?: CollectPublicClassNamesOptions): PublicClassNameEntry[];
|
|
28
|
+
export declare function semanticClassName(config: StylesBindingConfig, namespace: string, suffix?: string): string | null;
|
|
29
|
+
export declare function collectPublicClassNamesFromFiles(filePaths: string[], rootDir: string): PublicClassNameEntry[];
|
|
30
|
+
export declare function collectPublicClassNames(options?: CollectPublicClassNamesOptions): Promise<PublicClassNameEntry[]>;
|
|
31
|
+
export declare function collectPublicClassNamesSync(options?: CollectPublicClassNamesOptions): PublicClassNameEntry[];
|
|
31
32
|
/** @internal Resolve merged `createStyles` / `createTypeStyles` bindings for tests. */
|
|
32
|
-
declare function resolveProjectStylesBindings(filePaths: string[], _rootDir: string): Map<string, StylesBindingConfig>;
|
|
33
|
-
declare function buildSnapshot(entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
34
|
-
declare function loadPublicClassNamesSnapshot(snapshotPath: string): PublicClassNamesSnapshot | null;
|
|
35
|
-
declare function writePublicClassNamesSnapshot(snapshotPath: string, entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
36
|
-
declare function diffRemovedPublicClassNames(snapshot: PublicClassNamesSnapshot, current: PublicClassNameEntry[]): PublicClassNameEntry[];
|
|
37
|
-
|
|
38
|
-
export {
|
|
33
|
+
export declare function resolveProjectStylesBindings(filePaths: string[], _rootDir: string): Map<string, StylesBindingConfig>;
|
|
34
|
+
export declare function buildSnapshot(entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
35
|
+
export declare function loadPublicClassNamesSnapshot(snapshotPath: string): PublicClassNamesSnapshot | null;
|
|
36
|
+
export declare function writePublicClassNamesSnapshot(snapshotPath: string, entries: PublicClassNameEntry[]): PublicClassNamesSnapshot;
|
|
37
|
+
export declare function diffRemovedPublicClassNames(snapshot: PublicClassNamesSnapshot, current: PublicClassNameEntry[]): PublicClassNameEntry[];
|
|
38
|
+
//#endregion
|
|
39
|
+
export type { CollectPublicClassNamesOptions, PublicClassNameEntry, PublicClassNamesSnapshot, StylesBindingConfig };
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export { PUBLIC_CLASSNAMES_SNAPSHOT, buildSnapshot, collectPublicClassNames, collectPublicClassNamesFromFiles, collectPublicClassNamesSync, diffRemovedPublicClassNames, loadPublicClassNamesSnapshot, resolveProjectStylesBindings, semanticClassName, writePublicClassNamesSnapshot } from
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { t as PUBLIC_CLASSNAMES_SNAPSHOT, n as buildSnapshot, r as collectPublicClassNames, i as collectPublicClassNamesFromFiles, a as collectPublicClassNamesSync, o as diffRemovedPublicClassNames, s as loadPublicClassNamesSnapshot, c as resolveProjectStylesBindings, l as semanticClassName, u as writePublicClassNamesSnapshot } from "./snapshot-classnames-Blbh1QKS.js";
|