@codefast/cli 0.3.13-canary.0 → 0.3.13-canary.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/dist/bin.mjs +1 -1
- package/dist/commands/arrange.mjs +106 -1
- package/dist/commands/mirror.mjs +65 -1
- package/dist/commands/tag.mjs +57 -1
- package/dist/lib/arrange/application/analyze.mjs +91 -1
- package/dist/lib/arrange/application/group-file.mjs +112 -1
- package/dist/lib/arrange/application/run-target.mjs +64 -1
- package/dist/lib/arrange/domain/ast/ast-helpers.mjs +114 -1
- package/dist/lib/arrange/domain/ast/collectors-cn.mjs +60 -1
- package/dist/lib/arrange/domain/ast/collectors-jsx.mjs +19 -1
- package/dist/lib/arrange/domain/ast/collectors-tv.mjs +169 -1
- package/dist/lib/arrange/domain/ast/targets.mjs +105 -1
- package/dist/lib/arrange/domain/constants.mjs +168 -1
- package/dist/lib/arrange/domain/errors.mjs +18 -1
- package/dist/lib/arrange/domain/grouping.mjs +234 -1
- package/dist/lib/arrange/domain/imports.mjs +53 -1
- package/dist/lib/arrange/domain/tokenizer.mjs +215 -1
- package/dist/lib/arrange/index.mjs +14 -15
- package/dist/lib/arrange/infra/walk.mjs +32 -1
- package/dist/lib/arrange/presentation/formatters.mjs +51 -1
- package/dist/lib/arrange/presentation/report.mjs +23 -1
- package/dist/lib/config/domain/schema.mjs +24 -1
- package/dist/lib/config/index.mjs +2 -3
- package/dist/lib/config/infra/loader.mjs +77 -1
- package/dist/lib/infra/caught-unknown-message.mjs +19 -1
- package/dist/lib/infra/config-reporter.mjs +9 -1
- package/dist/lib/infra/node-io.mjs +29 -1
- package/dist/lib/infra/workspace/repo-root.mjs +21 -1
- package/dist/lib/mirror/application/engine.mjs +247 -1
- package/dist/lib/mirror/application/sync.mjs +161 -1
- package/dist/lib/mirror/domain/constants.mjs +11 -1
- package/dist/lib/mirror/domain/errors.mjs +14 -1
- package/dist/lib/mirror/index.mjs +1 -2
- package/dist/lib/mirror/infra/dirent-list.mjs +13 -1
- package/dist/lib/mirror/infra/package-filter.mjs +25 -1
- package/dist/lib/mirror/infra/path-normalizer.mjs +6 -1
- package/dist/lib/mirror/infra/update-pkg.mjs +104 -1
- package/dist/lib/mirror/infra/workspace-packages.mjs +158 -1
- package/dist/lib/mirror/presentation/reporter.mjs +111 -2
- package/dist/lib/tag/application/engine.mjs +286 -1
- package/dist/lib/tag/index.mjs +3 -4
- package/dist/lib/tag/infra/target-resolver.mjs +169 -1
- package/dist/lib/tag/presentation/colors.mjs +11 -1
- package/dist/lib/tag/presentation/tag-presenter.mjs +62 -1
- package/dist/program.mjs +33 -1
- package/package.json +2 -2
- package/dist/analyze-DvtJ3j9m.mjs +0 -92
- package/dist/arrange-Bbh62DrU.mjs +0 -107
- package/dist/arrange-BqP2DI3w.mjs +0 -8
- package/dist/ast-helpers-MDRYuIAk.mjs +0 -115
- package/dist/caught-unknown-message-CRhkDWO7.mjs +0 -20
- package/dist/collectors-cn-BS8TTQ8O.mjs +0 -61
- package/dist/collectors-jsx-D9tL2ZPM.mjs +0 -20
- package/dist/collectors-tv-D2PXZaRt.mjs +0 -170
- package/dist/colors-BjdkCfGK.mjs +0 -12
- package/dist/commands/mirror.test.mjs +0 -48
- package/dist/config-DVia_f9a.mjs +0 -3
- package/dist/config-reporter-SCcWDZc1.mjs +0 -10
- package/dist/constants-AtPhF-Ct.mjs +0 -169
- package/dist/constants-Bq5wdyLC.mjs +0 -8
- package/dist/dirent-list-BSDeRG5i.mjs +0 -14
- package/dist/engine-CcWEHSCq.mjs +0 -287
- package/dist/engine-DRTdkc5u.mjs +0 -236
- package/dist/errors-CFH4w6ic.mjs +0 -15
- package/dist/errors-CpU1ogfA.mjs +0 -19
- package/dist/formatters-DGE8jJ53.mjs +0 -52
- package/dist/group-file-ClW7XdD6.mjs +0 -113
- package/dist/grouping-c1grpCQT.mjs +0 -235
- package/dist/imports-DSVq1xhB.mjs +0 -54
- package/dist/lib/arrange/application/analyze.test.mjs +0 -171
- package/dist/lib/arrange/application/group-file.test.mjs +0 -273
- package/dist/lib/arrange/application/run-target.test.mjs +0 -97
- package/dist/lib/arrange/domain/ast/ast-helpers.test.mjs +0 -148
- package/dist/lib/arrange/domain/ast/collectors-cn.test.mjs +0 -58
- package/dist/lib/arrange/domain/ast/collectors-jsx.test.mjs +0 -20
- package/dist/lib/arrange/domain/ast/collectors-tv.test.mjs +0 -145
- package/dist/lib/arrange/domain/ast/targets.test.mjs +0 -50
- package/dist/lib/arrange/domain/grouping.test.mjs +0 -186
- package/dist/lib/arrange/domain/imports.test.mjs +0 -48
- package/dist/lib/arrange/domain/tokenizer.test.mjs +0 -165
- package/dist/lib/arrange/infra/walk.test.mjs +0 -50
- package/dist/lib/arrange/presentation/formatters.test.mjs +0 -73
- package/dist/lib/config/infra/loader.test.mjs +0 -116
- package/dist/lib/infra/workspace/repo-root.test.mjs +0 -45
- package/dist/lib/mirror/application/sync.test.mjs +0 -482
- package/dist/lib/mirror/infra/dirent-list.test.mjs +0 -18
- package/dist/lib/mirror/infra/package-filter.test.mjs +0 -32
- package/dist/lib/mirror/infra/workspace-packages.test.mjs +0 -167
- package/dist/lib/tag/application/engine.test.mjs +0 -159
- package/dist/lib/tag/presentation/tag-presenter.test.mjs +0 -29
- package/dist/loader-DpN-zl5g.mjs +0 -78
- package/dist/mirror-CbGiLXKT.mjs +0 -2
- package/dist/mirror-DqJE3ejL.mjs +0 -66
- package/dist/node-io-DFRbHO6m.mjs +0 -30
- package/dist/package-filter-C_8ryqvz.mjs +0 -26
- package/dist/path-normalizer-D4ceBO3l.mjs +0 -7
- package/dist/program-DR-H4tH3.mjs +0 -34
- package/dist/repo-root-HmtIEm6J.mjs +0 -22
- package/dist/report-DYxvw34T.mjs +0 -24
- package/dist/reporter-CwIe_tAM.mjs +0 -108
- package/dist/run-target-CJWrqNT4.mjs +0 -65
- package/dist/schema-Or8RAARd.mjs +0 -25
- package/dist/sync-e1Sp-shi.mjs +0 -157
- package/dist/tag-Cd9JujU5.mjs +0 -2
- package/dist/tag-hEKVZ_-7.mjs +0 -58
- package/dist/tag-presenter-Cs66UBsH.mjs +0 -63
- package/dist/target-resolver-CR3FXMTy.mjs +0 -170
- package/dist/targets-pCTslnFh.mjs +0 -106
- package/dist/tokenizer-CeZx73Zu.mjs +0 -216
- package/dist/update-pkg-CnGfjWBy.mjs +0 -37
- package/dist/walk-DjgQn66n.mjs +0 -33
- package/dist/workspace-packages-K2NYTHJq.mjs +0 -159
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import "./constants-AtPhF-Ct.mjs";
|
|
2
|
-
import { d as tokenizeClassString } from "./tokenizer-CeZx73Zu.mjs";
|
|
3
|
-
import { r as forEachStringLiteralInClassExpression } from "./collectors-cn-BS8TTQ8O.mjs";
|
|
4
|
-
import { t as jsxClassNameStaticLiteral } from "./collectors-jsx-D9tL2ZPM.mjs";
|
|
5
|
-
import { a as isCnOrTvIdentifier, o as lineOf, r as buildKnownCnTvBindings } from "./ast-helpers-MDRYuIAk.mjs";
|
|
6
|
-
import { c as traverseTvObject, t as collectCnCallsInsideTv } from "./collectors-tv-D2PXZaRt.mjs";
|
|
7
|
-
import { n as walkTsxFiles } from "./walk-DjgQn66n.mjs";
|
|
8
|
-
import ts from "typescript";
|
|
9
|
-
//#region src/lib/arrange/application/analyze.ts
|
|
10
|
-
function analyzeCnCall(sf, call, report) {
|
|
11
|
-
for (const arg of call.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
12
|
-
const text = lit.text;
|
|
13
|
-
const tokenCount = tokenizeClassString(text).length;
|
|
14
|
-
if (tokenCount >= 18) report.longCnStringLiterals.push({
|
|
15
|
-
file: sf.fileName,
|
|
16
|
-
line: lineOf(sf, lit),
|
|
17
|
-
tokenCount,
|
|
18
|
-
preview: text.length > 72 ? `${text.slice(0, 72)}…` : text
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function visitCallExpressionForArrangeAnalyze(callExpression, sf, sourceText, knownBindings, report) {
|
|
23
|
-
if (isCnOrTvIdentifier(callExpression.expression, "cn", knownBindings)) {
|
|
24
|
-
report.cnCallExpressions++;
|
|
25
|
-
analyzeCnCall(sf, callExpression, report);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (!isCnOrTvIdentifier(callExpression.expression, "tv", knownBindings)) return;
|
|
29
|
-
report.tvCallExpressions++;
|
|
30
|
-
const arg0 = callExpression.arguments[0];
|
|
31
|
-
if (!arg0 || !ts.isObjectLiteralExpression(arg0)) return;
|
|
32
|
-
for (const nestedCn of collectCnCallsInsideTv(sf, arg0, knownBindings, 0)) {
|
|
33
|
-
const src = sourceText.slice(nestedCn.getStart(sf), nestedCn.getEnd());
|
|
34
|
-
const preview = src.length > 72 ? `${src.slice(0, 72)}…` : src;
|
|
35
|
-
report.cnInsideTvCalls.push({
|
|
36
|
-
file: sf.fileName,
|
|
37
|
-
line: lineOf(sf, nestedCn),
|
|
38
|
-
argCount: nestedCn.arguments.length,
|
|
39
|
-
preview
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
traverseTvObject(sf, arg0, (classLiteral) => {
|
|
43
|
-
const text = classLiteral.text;
|
|
44
|
-
const tokenCount = tokenizeClassString(text).length;
|
|
45
|
-
if (tokenCount >= 18) report.longTvStringLiterals.push({
|
|
46
|
-
file: sf.fileName,
|
|
47
|
-
line: lineOf(sf, classLiteral),
|
|
48
|
-
tokenCount,
|
|
49
|
-
preview: text.length > 72 ? `${text.slice(0, 72)}…` : text
|
|
50
|
-
});
|
|
51
|
-
}, 0, knownBindings);
|
|
52
|
-
}
|
|
53
|
-
function visitJsxAttributeForArrangeAnalyze(jsxClassAttribute, sf, filePath, report) {
|
|
54
|
-
if (!filePath.endsWith(".tsx")) return;
|
|
55
|
-
const parsed = jsxClassNameStaticLiteral(jsxClassAttribute);
|
|
56
|
-
if (!parsed) return;
|
|
57
|
-
const text = parsed.lit.text;
|
|
58
|
-
const tokenCount = tokenizeClassString(text).length;
|
|
59
|
-
if (tokenCount >= 18) report.longJsxClassNameLiterals.push({
|
|
60
|
-
file: sf.fileName,
|
|
61
|
-
line: lineOf(sf, parsed.lit),
|
|
62
|
-
tokenCount,
|
|
63
|
-
preview: text.length > 72 ? `${text.slice(0, 72)}…` : text
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
function analyzeDirectory(analyzeRootPath, fs) {
|
|
67
|
-
const report = {
|
|
68
|
-
files: 0,
|
|
69
|
-
cnCallExpressions: 0,
|
|
70
|
-
tvCallExpressions: 0,
|
|
71
|
-
cnInsideTvCalls: [],
|
|
72
|
-
longCnStringLiterals: [],
|
|
73
|
-
longTvStringLiterals: [],
|
|
74
|
-
longJsxClassNameLiterals: []
|
|
75
|
-
};
|
|
76
|
-
const files = fs.statSync(analyzeRootPath).isDirectory() ? walkTsxFiles(analyzeRootPath, fs) : [analyzeRootPath];
|
|
77
|
-
for (const filePath of files) {
|
|
78
|
-
const sourceText = fs.readFileSync(filePath, "utf8");
|
|
79
|
-
const sf = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true, filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
80
|
-
report.files++;
|
|
81
|
-
const knownBindings = buildKnownCnTvBindings(sf);
|
|
82
|
-
const visitTypeScriptSubtree = (tsNode) => {
|
|
83
|
-
if (ts.isCallExpression(tsNode)) visitCallExpressionForArrangeAnalyze(tsNode, sf, sourceText, knownBindings, report);
|
|
84
|
-
if (ts.isJsxAttribute(tsNode)) visitJsxAttributeForArrangeAnalyze(tsNode, sf, filePath, report);
|
|
85
|
-
ts.forEachChild(tsNode, visitTypeScriptSubtree);
|
|
86
|
-
};
|
|
87
|
-
visitTypeScriptSubtree(sf);
|
|
88
|
-
}
|
|
89
|
-
return report;
|
|
90
|
-
}
|
|
91
|
-
//#endregion
|
|
92
|
-
export { analyzeDirectory as t };
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { t as messageFromCaughtUnknown } from "./caught-unknown-message-CRhkDWO7.mjs";
|
|
2
|
-
import { t as loadConfig } from "./loader-DpN-zl5g.mjs";
|
|
3
|
-
import "./config-DVia_f9a.mjs";
|
|
4
|
-
import { t as printConfigSchemaWarnings } from "./config-reporter-SCcWDZc1.mjs";
|
|
5
|
-
import { i as DEFAULT_ARRANGE_TARGET } from "./constants-AtPhF-Ct.mjs";
|
|
6
|
-
import { t as analyzeDirectory } from "./analyze-DvtJ3j9m.mjs";
|
|
7
|
-
import { t as printAnalyzeReport } from "./report-DYxvw34T.mjs";
|
|
8
|
-
import { a as suggestCnGroups, o as summarizeGroupBucketLabels } from "./grouping-c1grpCQT.mjs";
|
|
9
|
-
import { i as formatCnCall, n as formatArray } from "./formatters-DGE8jJ53.mjs";
|
|
10
|
-
import { t as runArrangeSync } from "./run-target-CJWrqNT4.mjs";
|
|
11
|
-
import { n as createNodeCliLogger, t as createNodeCliFs } from "./node-io-DFRbHO6m.mjs";
|
|
12
|
-
import "./arrange-BqP2DI3w.mjs";
|
|
13
|
-
import { t as findRepoRoot } from "./repo-root-HmtIEm6J.mjs";
|
|
14
|
-
import process from "node:process";
|
|
15
|
-
import path from "node:path";
|
|
16
|
-
import { Option } from "commander";
|
|
17
|
-
//#region src/commands/arrange.ts
|
|
18
|
-
/** Commander attribute `withClassName` (second long flag `--with-class-name`). */
|
|
19
|
-
function createWithClassNameOption() {
|
|
20
|
-
return new Option("--with-classname, --with-class-name", "Append className as final cn() argument").default(false);
|
|
21
|
-
}
|
|
22
|
-
function defaultTargetPath() {
|
|
23
|
-
return path.resolve(process.cwd(), DEFAULT_ARRANGE_TARGET);
|
|
24
|
-
}
|
|
25
|
-
function checkTargetExists(resolved, fs, logger) {
|
|
26
|
-
if (!fs.existsSync(resolved)) {
|
|
27
|
-
logger.err(`Not found: ${resolved}`);
|
|
28
|
-
process.exitCode = 1;
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
async function loadArrangeCommandConfig(fs, logger, rootDir) {
|
|
34
|
-
try {
|
|
35
|
-
const { config, warnings } = await loadConfig(fs, rootDir);
|
|
36
|
-
printConfigSchemaWarnings(logger, warnings);
|
|
37
|
-
return { arrangeConfig: config.arrange ?? {} };
|
|
38
|
-
} catch (caughtConfigError) {
|
|
39
|
-
logger.err(messageFromCaughtUnknown(caughtConfigError));
|
|
40
|
-
process.exitCode = 1;
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
function registerArrangeCommand(program) {
|
|
45
|
-
const arrange = program.command("arrange").description("Analyze and regroup Tailwind classes in cn() / tv() calls (Tailwind v4)");
|
|
46
|
-
arrange.command("analyze").description("Report long strings, nested cn in tv(), and related findings").argument("[target]", "Directory or file (default: packages/ui/src/components)").action(async (target) => {
|
|
47
|
-
const fs = createNodeCliFs();
|
|
48
|
-
const logger = createNodeCliLogger();
|
|
49
|
-
const resolved = target ? path.resolve(target) : defaultTargetPath();
|
|
50
|
-
if (!checkTargetExists(resolved, fs, logger)) return;
|
|
51
|
-
if (!await loadArrangeCommandConfig(fs, logger, findRepoRoot(fs))) return;
|
|
52
|
-
printAnalyzeReport(resolved, analyzeDirectory(resolved, fs), logger);
|
|
53
|
-
});
|
|
54
|
-
arrange.command("preview").description("Dry-run: print suggested replacements without writing files").argument("[target]", "Directory or file (default: packages/ui/src/components)").addOption(createWithClassNameOption()).option("--cn-import <spec>", "Override module specifier when adding cn import").action(async (target, opts) => {
|
|
55
|
-
const fs = createNodeCliFs();
|
|
56
|
-
const logger = createNodeCliLogger();
|
|
57
|
-
const resolved = target ? path.resolve(target) : defaultTargetPath();
|
|
58
|
-
if (!checkTargetExists(resolved, fs, logger)) return;
|
|
59
|
-
const rootDir = findRepoRoot(fs);
|
|
60
|
-
const loaded = await loadArrangeCommandConfig(fs, logger, rootDir);
|
|
61
|
-
if (!loaded) return;
|
|
62
|
-
process.exitCode = await runArrangeSync({
|
|
63
|
-
rootDir,
|
|
64
|
-
config: loaded.arrangeConfig,
|
|
65
|
-
targetPath: resolved,
|
|
66
|
-
write: false,
|
|
67
|
-
withClassName: opts.withClassName,
|
|
68
|
-
cnImport: opts.cnImport,
|
|
69
|
-
fs,
|
|
70
|
-
logger
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
arrange.command("apply").description("Apply grouping and cn-in-tv unwrap edits to files").argument("[target]", "Directory or file (default: packages/ui/src/components)").addOption(createWithClassNameOption()).option("--cn-import <spec>", "Override module specifier when adding cn import").action(async (target, opts) => {
|
|
74
|
-
const fs = createNodeCliFs();
|
|
75
|
-
const logger = createNodeCliLogger();
|
|
76
|
-
const resolved = target ? path.resolve(target) : defaultTargetPath();
|
|
77
|
-
if (!checkTargetExists(resolved, fs, logger)) return;
|
|
78
|
-
const rootDir = findRepoRoot(fs);
|
|
79
|
-
const loaded = await loadArrangeCommandConfig(fs, logger, rootDir);
|
|
80
|
-
if (!loaded) return;
|
|
81
|
-
process.exitCode = await runArrangeSync({
|
|
82
|
-
rootDir,
|
|
83
|
-
config: loaded.arrangeConfig,
|
|
84
|
-
targetPath: resolved,
|
|
85
|
-
write: true,
|
|
86
|
-
withClassName: opts.withClassName,
|
|
87
|
-
cnImport: opts.cnImport,
|
|
88
|
-
fs,
|
|
89
|
-
logger
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
arrange.command("group").description("Try grouping on a pasted class string (stdout: cn(...) or tv array with --tv)").argument("[tokens...]", "Class tokens (quote a single string if it contains spaces)").option("--tv", "Emit tv()-style array instead of cn() call", false).addOption(createWithClassNameOption()).action((tokens, opts) => {
|
|
93
|
-
const inlineClasses = tokens.join(" ").trim();
|
|
94
|
-
if (!inlineClasses) {
|
|
95
|
-
process.stderr.write("Pass a class string. Example: codefast arrange group \"flex gap-2 text-sm rounded-md\"\n");
|
|
96
|
-
process.exitCode = 1;
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
const groups = suggestCnGroups(inlineClasses);
|
|
100
|
-
const result = opts.tv ? formatArray(groups) : formatCnCall(groups, { trailingClassName: !!opts.withClassName });
|
|
101
|
-
process.stdout.write(`${result}\n`);
|
|
102
|
-
const bucketSummary = summarizeGroupBucketLabels(groups);
|
|
103
|
-
process.stdout.write(`\n// Buckets: ${JSON.stringify(bucketSummary)}\n`);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
//#endregion
|
|
107
|
-
export { registerArrangeCommand as t };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import "./collectors-cn-BS8TTQ8O.mjs";
|
|
2
|
-
import "./ast-helpers-MDRYuIAk.mjs";
|
|
3
|
-
import "./analyze-DvtJ3j9m.mjs";
|
|
4
|
-
import "./formatters-DGE8jJ53.mjs";
|
|
5
|
-
import "./imports-DSVq1xhB.mjs";
|
|
6
|
-
import "./group-file-ClW7XdD6.mjs";
|
|
7
|
-
import "./run-target-CJWrqNT4.mjs";
|
|
8
|
-
export {};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { a as EMPTY_CN_TV_BINDINGS } from "./constants-AtPhF-Ct.mjs";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
//#region src/lib/arrange/domain/ast/ast-helpers.ts
|
|
4
|
-
/** Known module specifiers that export `cn` / `tv`. */
|
|
5
|
-
const KNOWN_CN_TV_MODULES = new Set([
|
|
6
|
-
"@codefast/tailwind-variants",
|
|
7
|
-
"clsx",
|
|
8
|
-
"class-variance-authority",
|
|
9
|
-
"tailwind-variants",
|
|
10
|
-
"#lib/utils",
|
|
11
|
-
"~/lib/utils",
|
|
12
|
-
"@/lib/utils"
|
|
13
|
-
]);
|
|
14
|
-
/**
|
|
15
|
-
* True for typical shadcn-style re-exports: `./utils`, `@/lib/utils`, `…/utils/…`,
|
|
16
|
-
* or a dedicated `cn.ts` / `cn.tsx` module.
|
|
17
|
-
*/
|
|
18
|
-
function moduleLooksLikeCnTvReexport(moduleSpecifier) {
|
|
19
|
-
const norm = moduleSpecifier.replace(/\\/g, "/");
|
|
20
|
-
if (/(?:^|[./])utils(?:\/|$)/.test(norm)) return true;
|
|
21
|
-
if (/\/utils\//.test(norm) || /\/utils$/.test(norm)) return true;
|
|
22
|
-
if (/(?:^|\/)cn\.tsx?$/.test(norm)) return true;
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Build a set of local binding names that are imported from a known cn/tv
|
|
27
|
-
* module in `sf`.
|
|
28
|
-
*/
|
|
29
|
-
function buildKnownCnTvBindings(sf) {
|
|
30
|
-
const bindings = /* @__PURE__ */ new Set();
|
|
31
|
-
for (const stmt of sf.statements) {
|
|
32
|
-
if (!ts.isImportDeclaration(stmt) || !stmt.importClause) continue;
|
|
33
|
-
if (stmt.importClause.isTypeOnly) continue;
|
|
34
|
-
const spec = stmt.moduleSpecifier;
|
|
35
|
-
if (!ts.isStringLiteral(spec)) continue;
|
|
36
|
-
const moduleSpecifier = spec.text;
|
|
37
|
-
if (!KNOWN_CN_TV_MODULES.has(moduleSpecifier) && !moduleLooksLikeCnTvReexport(moduleSpecifier)) continue;
|
|
38
|
-
const clause = stmt.importClause;
|
|
39
|
-
if (clause.name) bindings.add(clause.name.text);
|
|
40
|
-
if (!clause.namedBindings) continue;
|
|
41
|
-
if (ts.isNamedImports(clause.namedBindings)) {
|
|
42
|
-
for (const namedImport of clause.namedBindings.elements) bindings.add(namedImport.name.text);
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
bindings.add(clause.namedBindings.name.text);
|
|
46
|
-
}
|
|
47
|
-
return bindings;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Returns true when `expr` is an identifier whose name matches `name` AND
|
|
51
|
-
* that name is listed in `knownBindings` from a recognized import.
|
|
52
|
-
*/
|
|
53
|
-
function isCnOrTvIdentifier(expr, name, knownBindings = EMPTY_CN_TV_BINDINGS) {
|
|
54
|
-
if (knownBindings.size === 0) return false;
|
|
55
|
-
if (ts.isIdentifier(expr) && expr.text === name) return knownBindings.has(expr.text);
|
|
56
|
-
if (ts.isPropertyAccessExpression(expr) && expr.name.text === name) return ts.isIdentifier(expr.expression) && knownBindings.has(expr.expression.text);
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
function propertyAssignmentNameText(prop) {
|
|
60
|
-
if (ts.isIdentifier(prop.name)) return prop.name.text;
|
|
61
|
-
if (ts.isStringLiteral(prop.name)) return prop.name.text;
|
|
62
|
-
}
|
|
63
|
-
function lineOf(sf, tsNode) {
|
|
64
|
-
return sf.getLineAndCharacterOfPosition(tsNode.getStart(sf)).line + 1;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Returns only the leading whitespace (tabs / spaces) of the line containing
|
|
68
|
-
* `pos`.
|
|
69
|
-
*/
|
|
70
|
-
function indentOfLineContaining(source, pos) {
|
|
71
|
-
const searchPos = Math.max(0, Math.min(pos, source.length));
|
|
72
|
-
const prevLineBreak = Math.max(source.lastIndexOf("\n", searchPos - 1), source.lastIndexOf("\r", searchPos - 1));
|
|
73
|
-
const lineStart = prevLineBreak === -1 ? 0 : prevLineBreak + 1;
|
|
74
|
-
let lineEnd = source.length;
|
|
75
|
-
for (let i = lineStart; i < source.length; i++) {
|
|
76
|
-
const ch = source[i];
|
|
77
|
-
if (ch === "\n" || ch === "\r") {
|
|
78
|
-
lineEnd = i;
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const line = source.slice(lineStart, lineEnd);
|
|
83
|
-
return /^[\t ]*/.exec(line)?.[0] ?? "";
|
|
84
|
-
}
|
|
85
|
-
function applyEditsDescending(sourceText, edits) {
|
|
86
|
-
const sorted = [...edits].sort((editA, editB) => editB.start - editA.start);
|
|
87
|
-
let out = sourceText;
|
|
88
|
-
for (const edit of sorted) out = out.slice(0, edit.start) + edit.replacement + out.slice(edit.end);
|
|
89
|
-
return out;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Replace `cn(...)` nested in `tv({...})` with a plain string (one arg) or a string
|
|
93
|
-
* array (multiple args). Returns undefined when there are zero arguments.
|
|
94
|
-
*/
|
|
95
|
-
function unwrapCnInsideTvCallReplacement(call, sourceText, sf) {
|
|
96
|
-
const args = call.arguments;
|
|
97
|
-
if (args.length === 0) return void 0;
|
|
98
|
-
const baseIndent = indentOfLineContaining(sourceText, call.getStart(sf));
|
|
99
|
-
const innerIndent = `${baseIndent} `;
|
|
100
|
-
if (args.length === 1) {
|
|
101
|
-
const firstArg = args[0];
|
|
102
|
-
return sourceText.slice(firstArg.getStart(sf), firstArg.getEnd());
|
|
103
|
-
}
|
|
104
|
-
const lines = ["["];
|
|
105
|
-
for (let i = 0; i < args.length; i++) {
|
|
106
|
-
const arg = args[i];
|
|
107
|
-
const piece = sourceText.slice(arg.getStart(sf), arg.getEnd());
|
|
108
|
-
const comma = i < args.length - 1 || args.length > 1 ? "," : "";
|
|
109
|
-
lines.push(`${innerIndent}${piece}${comma}`);
|
|
110
|
-
}
|
|
111
|
-
lines.push(`${baseIndent}]`);
|
|
112
|
-
return lines.join("\n");
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
115
|
-
export { isCnOrTvIdentifier as a, propertyAssignmentNameText as c, indentOfLineContaining as i, unwrapCnInsideTvCallReplacement as l, applyEditsDescending as n, lineOf as o, buildKnownCnTvBindings as r, moduleLooksLikeCnTvReexport as s, KNOWN_CN_TV_MODULES as t };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//#region src/lib/infra/caught-unknown-message.ts
|
|
2
|
-
/**
|
|
3
|
-
* Stable, user-facing text for values caught as `unknown`.
|
|
4
|
-
* Avoids `String(unknown)` / `[object Object]` and satisfies strict `no-base-to-string`.
|
|
5
|
-
*/
|
|
6
|
-
function messageFromCaughtUnknown(value) {
|
|
7
|
-
if (value instanceof Error) return value.message;
|
|
8
|
-
if (typeof value === "string") return value;
|
|
9
|
-
if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return String(value);
|
|
10
|
-
if (typeof value === "symbol") return String(value);
|
|
11
|
-
if (value === null) return "null";
|
|
12
|
-
if (value === void 0) return "undefined";
|
|
13
|
-
try {
|
|
14
|
-
const serialized = JSON.stringify(value);
|
|
15
|
-
if (typeof serialized === "string") return serialized;
|
|
16
|
-
} catch {}
|
|
17
|
-
return "[unserializable non-Error value]";
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { messageFromCaughtUnknown as t };
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import "./constants-AtPhF-Ct.mjs";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
//#region src/lib/arrange/domain/ast/collectors-cn.ts
|
|
4
|
-
function forEachStringLiteralInClassExpression(expr, sink, depth = 0, options) {
|
|
5
|
-
if (depth > 12) return;
|
|
6
|
-
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
|
|
7
|
-
sink(expr);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (ts.isParenthesizedExpression(expr)) {
|
|
11
|
-
forEachStringLiteralInClassExpression(expr.expression, sink, depth + 1, options);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (ts.isAsExpression(expr) || ts.isSatisfiesExpression(expr)) {
|
|
15
|
-
forEachStringLiteralInClassExpression(expr.expression, sink, depth + 1, options);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (ts.isNonNullExpression(expr)) {
|
|
19
|
-
forEachStringLiteralInClassExpression(expr.expression, sink, depth + 1, options);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
if (ts.isConditionalExpression(expr)) {
|
|
23
|
-
if (options?.descendIntoConditional === false) return;
|
|
24
|
-
forEachStringLiteralInClassExpression(expr.whenTrue, sink, depth + 1, options);
|
|
25
|
-
forEachStringLiteralInClassExpression(expr.whenFalse, sink, depth + 1, options);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
if (ts.isBinaryExpression(expr) && expr.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
29
|
-
forEachStringLiteralInClassExpression(expr.left, sink, depth + 1, options);
|
|
30
|
-
forEachStringLiteralInClassExpression(expr.right, sink, depth + 1, options);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (ts.isArrayLiteralExpression(expr)) for (const arrayElement of expr.elements) {
|
|
34
|
-
if (ts.isSpreadElement(arrayElement)) continue;
|
|
35
|
-
forEachStringLiteralInClassExpression(arrayElement, sink, depth + 1, options);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function isUnsafeLiteralForCnStyleApplySplit(classLiteral) {
|
|
39
|
-
return ts.isArrayLiteralExpression(classLiteral.parent);
|
|
40
|
-
}
|
|
41
|
-
const CN_APPLY_LITERAL_WALK_OPTS = { descendIntoConditional: false };
|
|
42
|
-
function collectUnconditionalTailwindLiteralsFromCnArguments(args) {
|
|
43
|
-
const staticLits = [];
|
|
44
|
-
for (const arg of args) if (ts.isStringLiteral(arg) || ts.isNoSubstitutionTemplateLiteral(arg)) {
|
|
45
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(arg)) staticLits.push(arg);
|
|
46
|
-
} else forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
47
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) staticLits.push(lit);
|
|
48
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
49
|
-
return staticLits;
|
|
50
|
-
}
|
|
51
|
-
function mergeCnUnconditionalLiteralPoolForTest(argsSnippet, options) {
|
|
52
|
-
const callee = options?.callee ?? "cn";
|
|
53
|
-
const sourceText = `${callee}(${argsSnippet});`;
|
|
54
|
-
const stmt = ts.createSourceFile("mergeCnUnconditionalLiteralPoolForTest.ts", sourceText, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS).statements[0];
|
|
55
|
-
if (!ts.isExpressionStatement(stmt)) throw new Error("expected expression statement");
|
|
56
|
-
const call = stmt.expression;
|
|
57
|
-
if (!ts.isCallExpression(call) || !ts.isIdentifier(call.expression) || call.expression.text !== callee) throw new Error(`expected ${callee}(...) call`);
|
|
58
|
-
return collectUnconditionalTailwindLiteralsFromCnArguments(call.arguments).map((literal) => literal.text).join(" ");
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
export { mergeCnUnconditionalLiteralPoolForTest as a, isUnsafeLiteralForCnStyleApplySplit as i, collectUnconditionalTailwindLiteralsFromCnArguments as n, forEachStringLiteralInClassExpression as r, CN_APPLY_LITERAL_WALK_OPTS as t };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
//#region src/lib/arrange/domain/ast/collectors-jsx.ts
|
|
3
|
-
function jsxClassNameStaticLiteral(jsxClassNameAttribute) {
|
|
4
|
-
if (!ts.isIdentifier(jsxClassNameAttribute.name) || jsxClassNameAttribute.name.text !== "className") return void 0;
|
|
5
|
-
const init = jsxClassNameAttribute.initializer;
|
|
6
|
-
if (!init) return void 0;
|
|
7
|
-
if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) return {
|
|
8
|
-
lit: init,
|
|
9
|
-
valueNode: init
|
|
10
|
-
};
|
|
11
|
-
if (ts.isJsxExpression(init) && init.expression) {
|
|
12
|
-
const jsxExpressionBody = init.expression;
|
|
13
|
-
if (ts.isStringLiteral(jsxExpressionBody) || ts.isNoSubstitutionTemplateLiteral(jsxExpressionBody)) return {
|
|
14
|
-
lit: jsxExpressionBody,
|
|
15
|
-
valueNode: init
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { jsxClassNameStaticLiteral as t };
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import "./constants-AtPhF-Ct.mjs";
|
|
2
|
-
import { d as tokenizeClassString } from "./tokenizer-CeZx73Zu.mjs";
|
|
3
|
-
import { i as isUnsafeLiteralForCnStyleApplySplit, n as collectUnconditionalTailwindLiteralsFromCnArguments, r as forEachStringLiteralInClassExpression, t as CN_APPLY_LITERAL_WALK_OPTS } from "./collectors-cn-BS8TTQ8O.mjs";
|
|
4
|
-
import { a as isCnOrTvIdentifier, c as propertyAssignmentNameText, r as buildKnownCnTvBindings } from "./ast-helpers-MDRYuIAk.mjs";
|
|
5
|
-
import ts from "typescript";
|
|
6
|
-
//#region src/lib/arrange/domain/ast/collectors-tv.ts
|
|
7
|
-
function traverseTvObject(sf, obj, visitor, depth = 0, knownBindings) {
|
|
8
|
-
if (depth > 12) return;
|
|
9
|
-
for (const prop of obj.properties) {
|
|
10
|
-
if (!ts.isPropertyAssignment(prop)) continue;
|
|
11
|
-
const init = prop.initializer;
|
|
12
|
-
if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) visitor(init, sf, void 0);
|
|
13
|
-
else if (ts.isArrayLiteralExpression(init)) for (const arrayElement of init.elements) {
|
|
14
|
-
if (ts.isSpreadElement(arrayElement)) continue;
|
|
15
|
-
if (ts.isStringLiteral(arrayElement) || ts.isNoSubstitutionTemplateLiteral(arrayElement)) visitor(arrayElement, sf, void 0);
|
|
16
|
-
else if (ts.isCallExpression(arrayElement) && isCnOrTvIdentifier(arrayElement.expression, "cn", knownBindings)) for (const arg of arrayElement.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
17
|
-
visitor(lit, sf, arrayElement);
|
|
18
|
-
});
|
|
19
|
-
else if (ts.isObjectLiteralExpression(arrayElement)) for (const objectProperty of arrayElement.properties) {
|
|
20
|
-
if (!ts.isPropertyAssignment(objectProperty)) continue;
|
|
21
|
-
const propName = propertyAssignmentNameText(objectProperty);
|
|
22
|
-
if (propName !== "className" && propName !== "class") continue;
|
|
23
|
-
const innerInit = objectProperty.initializer;
|
|
24
|
-
if (ts.isStringLiteral(innerInit) || ts.isNoSubstitutionTemplateLiteral(innerInit)) visitor(innerInit, sf, void 0);
|
|
25
|
-
else if (ts.isArrayLiteralExpression(innerInit)) for (const nestedArrayElement of innerInit.elements) {
|
|
26
|
-
if (ts.isSpreadElement(nestedArrayElement)) continue;
|
|
27
|
-
if (ts.isStringLiteral(nestedArrayElement) || ts.isNoSubstitutionTemplateLiteral(nestedArrayElement)) visitor(nestedArrayElement, sf, void 0);
|
|
28
|
-
}
|
|
29
|
-
else if (ts.isCallExpression(innerInit) && isCnOrTvIdentifier(innerInit.expression, "cn", knownBindings)) for (const arg of innerInit.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
30
|
-
visitor(lit, sf, innerInit);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else if (ts.isObjectLiteralExpression(init)) traverseTvObject(sf, init, visitor, depth + 1, knownBindings);
|
|
35
|
-
else if (ts.isCallExpression(init) && isCnOrTvIdentifier(init.expression, "cn", knownBindings)) for (const arg of init.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
36
|
-
visitor(lit, sf, init);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function collectCnCallsInsideTv(sf, obj, knownBindings, depth = 0) {
|
|
41
|
-
if (depth > 12) return [];
|
|
42
|
-
const calls = [];
|
|
43
|
-
for (const prop of obj.properties) {
|
|
44
|
-
if (!ts.isPropertyAssignment(prop)) continue;
|
|
45
|
-
const init = prop.initializer;
|
|
46
|
-
if (ts.isArrayLiteralExpression(init)) for (const arrayElement of init.elements) {
|
|
47
|
-
if (ts.isSpreadElement(arrayElement)) continue;
|
|
48
|
-
if (ts.isCallExpression(arrayElement) && isCnOrTvIdentifier(arrayElement.expression, "cn", knownBindings)) calls.push(arrayElement);
|
|
49
|
-
else if (ts.isObjectLiteralExpression(arrayElement)) for (const objectProperty of arrayElement.properties) {
|
|
50
|
-
if (!ts.isPropertyAssignment(objectProperty)) continue;
|
|
51
|
-
const propName = propertyAssignmentNameText(objectProperty);
|
|
52
|
-
if (propName !== "className" && propName !== "class") continue;
|
|
53
|
-
const innerInit = objectProperty.initializer;
|
|
54
|
-
if (ts.isCallExpression(innerInit) && isCnOrTvIdentifier(innerInit.expression, "cn", knownBindings)) calls.push(innerInit);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else if (ts.isObjectLiteralExpression(init)) calls.push(...collectCnCallsInsideTv(sf, init, knownBindings, depth + 1));
|
|
58
|
-
else if (ts.isCallExpression(init) && isCnOrTvIdentifier(init.expression, "cn", knownBindings)) calls.push(init);
|
|
59
|
-
}
|
|
60
|
-
return calls;
|
|
61
|
-
}
|
|
62
|
-
function listAllCnCallsInsideTvInSourceFile(sf, knownBindings) {
|
|
63
|
-
const calls = [];
|
|
64
|
-
const visitTypeScriptSubtree = (tsNode) => {
|
|
65
|
-
if (ts.isCallExpression(tsNode) && isCnOrTvIdentifier(tsNode.expression, "tv", knownBindings)) {
|
|
66
|
-
const arg0 = tsNode.arguments[0];
|
|
67
|
-
if (arg0 && ts.isObjectLiteralExpression(arg0)) calls.push(...collectCnCallsInsideTv(sf, arg0, knownBindings, 0));
|
|
68
|
-
}
|
|
69
|
-
ts.forEachChild(tsNode, visitTypeScriptSubtree);
|
|
70
|
-
};
|
|
71
|
-
visitTypeScriptSubtree(sf);
|
|
72
|
-
return calls;
|
|
73
|
-
}
|
|
74
|
-
function makeStringNode(nodes, sf, isTvContext, cnCall) {
|
|
75
|
-
return {
|
|
76
|
-
nodes,
|
|
77
|
-
sf,
|
|
78
|
-
isTvContext,
|
|
79
|
-
cnCall,
|
|
80
|
-
get primaryClassLiteral() {
|
|
81
|
-
return this.nodes[0];
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function slotClassString(stringNode) {
|
|
86
|
-
return stringNode.nodes.map((literal) => literal.text).join(" ");
|
|
87
|
-
}
|
|
88
|
-
function emitTvSlot(lits, sf, cnCall, results, seenNodePos) {
|
|
89
|
-
if (lits.length === 0) return;
|
|
90
|
-
const firstPos = lits[0].getStart(sf);
|
|
91
|
-
if (seenNodePos.has(firstPos)) return;
|
|
92
|
-
seenNodePos.add(firstPos);
|
|
93
|
-
if (lits.reduce((accumulatedTokenCount, literal) => accumulatedTokenCount + tokenizeClassString(literal.text).length, 0) < 2) return;
|
|
94
|
-
results.push(makeStringNode(lits, sf, true, cnCall));
|
|
95
|
-
}
|
|
96
|
-
function collectTvSlots(sf, obj, knownBindings, results, seenNodePos, depth = 0) {
|
|
97
|
-
if (depth > 12) return;
|
|
98
|
-
for (const prop of obj.properties) {
|
|
99
|
-
if (!ts.isPropertyAssignment(prop)) continue;
|
|
100
|
-
const init = prop.initializer;
|
|
101
|
-
if (ts.isStringLiteral(init) || ts.isNoSubstitutionTemplateLiteral(init)) emitTvSlot([init], sf, void 0, results, seenNodePos);
|
|
102
|
-
else if (ts.isArrayLiteralExpression(init)) {
|
|
103
|
-
const arrayPos = init.getStart(sf);
|
|
104
|
-
if (seenNodePos.has(arrayPos)) continue;
|
|
105
|
-
seenNodePos.add(arrayPos);
|
|
106
|
-
const staticLits = [];
|
|
107
|
-
for (const arrayElement of init.elements) {
|
|
108
|
-
if (ts.isSpreadElement(arrayElement)) continue;
|
|
109
|
-
if (ts.isStringLiteral(arrayElement) || ts.isNoSubstitutionTemplateLiteral(arrayElement)) staticLits.push(arrayElement);
|
|
110
|
-
else if (ts.isCallExpression(arrayElement) && isCnOrTvIdentifier(arrayElement.expression, "cn", knownBindings)) for (const arg of arrayElement.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
111
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) staticLits.push(lit);
|
|
112
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
113
|
-
else if (ts.isObjectLiteralExpression(arrayElement)) for (const objectProperty of arrayElement.properties) {
|
|
114
|
-
if (!ts.isPropertyAssignment(objectProperty)) continue;
|
|
115
|
-
const propName = propertyAssignmentNameText(objectProperty);
|
|
116
|
-
if (propName !== "className" && propName !== "class") continue;
|
|
117
|
-
const innerInit = objectProperty.initializer;
|
|
118
|
-
if (ts.isStringLiteral(innerInit) || ts.isNoSubstitutionTemplateLiteral(innerInit)) emitTvSlot([innerInit], sf, void 0, results, seenNodePos);
|
|
119
|
-
else if (ts.isArrayLiteralExpression(innerInit)) {
|
|
120
|
-
const innerLits = [];
|
|
121
|
-
for (const nestedArrayElement of innerInit.elements) if (!ts.isSpreadElement(nestedArrayElement) && (ts.isStringLiteral(nestedArrayElement) || ts.isNoSubstitutionTemplateLiteral(nestedArrayElement))) innerLits.push(nestedArrayElement);
|
|
122
|
-
emitTvSlot(innerLits, sf, void 0, results, seenNodePos);
|
|
123
|
-
} else if (ts.isCallExpression(innerInit) && isCnOrTvIdentifier(innerInit.expression, "cn", knownBindings)) {
|
|
124
|
-
const cnLits = [];
|
|
125
|
-
for (const arg of innerInit.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
126
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) cnLits.push(lit);
|
|
127
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
128
|
-
emitTvSlot(cnLits, sf, innerInit, results, seenNodePos);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
if (staticLits.length > 0) emitTvSlot(staticLits, sf, void 0, results, seenNodePos);
|
|
133
|
-
} else if (ts.isObjectLiteralExpression(init)) collectTvSlots(sf, init, knownBindings, results, seenNodePos, depth + 1);
|
|
134
|
-
else if (ts.isCallExpression(init) && isCnOrTvIdentifier(init.expression, "cn", knownBindings)) {
|
|
135
|
-
const cnLits = [];
|
|
136
|
-
for (const arg of init.arguments) forEachStringLiteralInClassExpression(arg, (lit) => {
|
|
137
|
-
if (!isUnsafeLiteralForCnStyleApplySplit(lit)) cnLits.push(lit);
|
|
138
|
-
}, 0, CN_APPLY_LITERAL_WALK_OPTS);
|
|
139
|
-
emitTvSlot(cnLits, sf, init, results, seenNodePos);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function collectGroupableStringNodes(sf) {
|
|
144
|
-
const results = [];
|
|
145
|
-
const seenNodePos = /* @__PURE__ */ new Set();
|
|
146
|
-
const knownBindings = buildKnownCnTvBindings(sf);
|
|
147
|
-
const visitTypeScriptSubtree = (tsNode) => {
|
|
148
|
-
if (ts.isCallExpression(tsNode)) {
|
|
149
|
-
if (isCnOrTvIdentifier(tsNode.expression, "cn", knownBindings)) {
|
|
150
|
-
const callPos = tsNode.getStart(sf);
|
|
151
|
-
if (seenNodePos.has(callPos)) {
|
|
152
|
-
ts.forEachChild(tsNode, visitTypeScriptSubtree);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
seenNodePos.add(callPos);
|
|
156
|
-
const staticLits = collectUnconditionalTailwindLiteralsFromCnArguments(tsNode.arguments);
|
|
157
|
-
const totalTokens = staticLits.reduce((accumulatedTokenCount, literal) => accumulatedTokenCount + tokenizeClassString(literal.text).length, 0);
|
|
158
|
-
if (staticLits.length > 0 && totalTokens >= 2) results.push(makeStringNode(staticLits, sf, false, tsNode));
|
|
159
|
-
} else if (isCnOrTvIdentifier(tsNode.expression, "tv", knownBindings)) {
|
|
160
|
-
const arg0 = tsNode.arguments[0];
|
|
161
|
-
if (arg0 && ts.isObjectLiteralExpression(arg0)) collectTvSlots(sf, arg0, knownBindings, results, seenNodePos);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
ts.forEachChild(tsNode, visitTypeScriptSubtree);
|
|
165
|
-
};
|
|
166
|
-
visitTypeScriptSubtree(sf);
|
|
167
|
-
return results;
|
|
168
|
-
}
|
|
169
|
-
//#endregion
|
|
170
|
-
export { listAllCnCallsInsideTvInSourceFile as a, traverseTvObject as c, emitTvSlot as i, collectGroupableStringNodes as n, makeStringNode as o, collectTvSlots as r, slotClassString as s, collectCnCallsInsideTv as t };
|
package/dist/colors-BjdkCfGK.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//#region src/lib/tag/presentation/colors.ts
|
|
2
|
-
const TAG_COLORS = {
|
|
3
|
-
RESET: "\x1B[0m",
|
|
4
|
-
RED: "\x1B[31m",
|
|
5
|
-
GREEN: "\x1B[32m",
|
|
6
|
-
YELLOW: "\x1B[33m"
|
|
7
|
-
};
|
|
8
|
-
function withTagColor(line, colorCode) {
|
|
9
|
-
return `${colorCode}${line}${TAG_COLORS.RESET}`;
|
|
10
|
-
}
|
|
11
|
-
//#endregion
|
|
12
|
-
export { withTagColor as n, TAG_COLORS as t };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { t as packageArgToRelative } from "../mirror-DqJE3ejL.mjs";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
//#region src/commands/mirror.test.ts
|
|
6
|
-
describe("packageArgToRelative", () => {
|
|
7
|
-
it("returns undefined when arg is undefined", () => {
|
|
8
|
-
expect(packageArgToRelative("/repo", void 0)).toBeUndefined();
|
|
9
|
-
});
|
|
10
|
-
it("returns a normalized path for a package under the repo root", () => {
|
|
11
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), "mirror-pkg-"));
|
|
12
|
-
const pkgDir = path.join(root, "packages", "widget");
|
|
13
|
-
fs.mkdirSync(pkgDir, { recursive: true });
|
|
14
|
-
const prev = process.cwd();
|
|
15
|
-
try {
|
|
16
|
-
process.chdir(root);
|
|
17
|
-
expect(packageArgToRelative(root, "packages/widget")).toBe("packages/widget");
|
|
18
|
-
expect(packageArgToRelative(root, pkgDir)).toBe("packages/widget");
|
|
19
|
-
} finally {
|
|
20
|
-
process.chdir(prev);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
it("rejects '.' and other paths that resolve to the repo root", () => {
|
|
24
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), "mirror-root-dot-"));
|
|
25
|
-
fs.mkdirSync(path.join(root, "packages", "x"), { recursive: true });
|
|
26
|
-
const prev = process.cwd();
|
|
27
|
-
try {
|
|
28
|
-
process.chdir(root);
|
|
29
|
-
expect(() => packageArgToRelative(root, ".")).toThrow(/subdirectory under monorepo root/);
|
|
30
|
-
expect(() => packageArgToRelative(root, "./")).toThrow(/subdirectory under monorepo root/);
|
|
31
|
-
} finally {
|
|
32
|
-
process.chdir(prev);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
it("rejects paths outside the monorepo root", () => {
|
|
36
|
-
const root = fs.mkdtempSync(path.join(os.tmpdir(), "mirror-out-"));
|
|
37
|
-
const outside = fs.mkdtempSync(path.join(os.tmpdir(), "mirror-outside-"));
|
|
38
|
-
const prev = process.cwd();
|
|
39
|
-
try {
|
|
40
|
-
process.chdir(root);
|
|
41
|
-
expect(() => packageArgToRelative(root, outside)).toThrow(/subdirectory under monorepo root/);
|
|
42
|
-
} finally {
|
|
43
|
-
process.chdir(prev);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
//#endregion
|
|
48
|
-
export {};
|
package/dist/config-DVia_f9a.mjs
DELETED