@tamagui/codemod-flat-values 0.0.0-bootstrap.0 → 3.0.0-beta.637.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/index.mjs ADDED
@@ -0,0 +1,342 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
3
+ import { dirname, relative, resolve } from "node:path";
4
+ import { resolveTamaguiHost } from "@tamagui/language-service/host";
5
+ import { stylePropsTextOnly } from "@tamagui/helpers";
6
+ import { ModuleKind, ModuleResolutionKind, Node, Project, ScriptTarget, SyntaxKind, ts } from "ts-morph";
7
+ import { planContainers } from "./containers.mjs";
8
+ import { convertJsxSite, convertStyleObject } from "./convert.mjs";
9
+ import { compact, unwrapExpression } from "./expressions.mjs";
10
+ import { codemodMediaNames, createModifierRegistry, grammarPlatformNames } from "./grammar.mjs";
11
+ import { createProvenance } from "./provenance.mjs";
12
+ import { renderReport } from "./report.mjs";
13
+
14
+ const projectRoot = process.cwd();
15
+ const defaultReportPath = resolve(projectRoot, "tamagui-flat-values-report.md");
16
+ const ignoreMarker = ".tamagui-flat-values-ignore";
17
+ const ignoredDirectories = /* @__PURE__ */ new Map();
18
+ function isIgnored(filePath) {
19
+ let directory = dirname(filePath);
20
+ const visited = [];
21
+ while (directory === projectRoot || !relative(projectRoot, directory).startsWith("..")) {
22
+ const cached = ignoredDirectories.get(directory);
23
+ if (cached !== void 0) {
24
+ for (const seen of visited) ignoredDirectories.set(seen, cached);
25
+ return cached;
26
+ }
27
+ visited.push(directory);
28
+ if (existsSync(resolve(directory, ignoreMarker))) {
29
+ for (const seen of visited) ignoredDirectories.set(seen, true);
30
+ return true;
31
+ }
32
+ if (directory === projectRoot) break;
33
+ const parent = dirname(directory);
34
+ if (parent === directory) break;
35
+ directory = parent;
36
+ }
37
+ for (const seen of visited) ignoredDirectories.set(seen, false);
38
+ return false;
39
+ }
40
+ function collectFiles(inputs2) {
41
+ const tsConfigFilePath = resolve(projectRoot, "tsconfig.json");
42
+ if (!existsSync(tsConfigFilePath)) {
43
+ console.error(`no tsconfig.json in ${projectRoot}; run the codemod from your project root`);
44
+ process.exit(2);
45
+ }
46
+ const project = new Project({
47
+ tsConfigFilePath,
48
+ skipAddingFilesFromTsConfig: true,
49
+ compilerOptions: {
50
+ allowJs: false,
51
+ jsx: 4,
52
+ target: ScriptTarget.ES2020,
53
+ module: ModuleKind.ESNext,
54
+ moduleResolution: ModuleResolutionKind.NodeJs,
55
+ skipLibCheck: true,
56
+ strictNullChecks: true,
57
+ baseUrl: projectRoot
58
+ }
59
+ });
60
+ const files2 = /* @__PURE__ */ new Map();
61
+ const ignored = /* @__PURE__ */ new Set();
62
+ const missing = [];
63
+ for (const input of inputs2) {
64
+ const path = resolve(projectRoot, input);
65
+ if (!existsSync(path)) {
66
+ missing.push(input);
67
+ continue;
68
+ }
69
+ const pattern = /\.[cm]?[jt]sx?$/.test(path) ? path : `${path}/**/*.{ts,tsx}`;
70
+ const matched = project.addSourceFilesAtPaths(pattern);
71
+ if (!matched.length) missing.push(input);
72
+ for (const file of matched) {
73
+ const filePath = file.getFilePath();
74
+ if (isIgnored(filePath)) ignored.add(filePath);
75
+ else files2.set(filePath, file);
76
+ }
77
+ }
78
+ if (missing.length) {
79
+ console.error(`no source file matched ${missing.map((input) => `"${input}"`).join(", ")}`);
80
+ process.exit(2);
81
+ }
82
+ if (files2.size === 0 && ignored.size > 0) {
83
+ console.error(`all ${ignored.size} matched source ${ignored.size === 1 ? "file was" : "files were"} skipped by ${ignoreMarker}; no migration report was written`);
84
+ process.exit(2);
85
+ }
86
+ return {
87
+ sourceFiles: [...files2.values()].sort((left, right) => left.getFilePath().localeCompare(right.getFilePath())),
88
+ ignoredFiles: ignored.size
89
+ };
90
+ }
91
+ function themeNames(sourceFiles2) {
92
+ const names = /* @__PURE__ */ new Set(["light", "dark"]);
93
+ for (const sourceFile of sourceFiles2) {
94
+ for (const name of conditionNames(sourceFile)) {
95
+ if (name.startsWith("$theme-")) names.add(name.slice("$theme-".length));
96
+ }
97
+ }
98
+ return names;
99
+ }
100
+ function mediaNames(sourceFiles2) {
101
+ const names = new Set(codemodMediaNames);
102
+ for (const sourceFile of sourceFiles2) {
103
+ for (const name of conditionNames(sourceFile)) {
104
+ if (!name.startsWith("$")) continue;
105
+ if (name.startsWith("$theme-") || name.startsWith("$platform-") || name.startsWith("$group-") || grammarPlatformNames.has(name.slice(1))) {
106
+ continue;
107
+ }
108
+ names.add(name.slice(1));
109
+ }
110
+ }
111
+ return names;
112
+ }
113
+ function conditionNames(sourceFile) {
114
+ const names = [];
115
+ for (const attribute of sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute)) {
116
+ const name = attribute.getNameNode();
117
+ if (Node.isIdentifier(name)) names.push(name.getText());
118
+ }
119
+ for (const property of sourceFile.getDescendantsOfKind(SyntaxKind.PropertyAssignment)) {
120
+ const name = property.getNameNode();
121
+ if (Node.isComputedPropertyName(name)) continue;
122
+ names.push(name.getText().replace(/^['"]|['"]$/g, ""));
123
+ }
124
+ return names;
125
+ }
126
+ function variantStyleObjects(value) {
127
+ const current = unwrapExpression(value);
128
+ if (Node.isObjectLiteralExpression(current)) return [current];
129
+ if (Node.isConditionalExpression(current)) {
130
+ return [...variantStyleObjects(current.getWhenTrue()), ...variantStyleObjects(current.getWhenFalse())];
131
+ }
132
+ if (Node.isArrowFunction(current) || Node.isFunctionExpression(current)) {
133
+ const body = current.getBody();
134
+ if (Node.isBlock(body)) {
135
+ return body.getDescendantsOfKind(SyntaxKind.ReturnStatement).flatMap((statement) => {
136
+ const returned = statement.getExpression();
137
+ return returned ? variantStyleObjects(returned) : [];
138
+ });
139
+ }
140
+ return variantStyleObjects(body);
141
+ }
142
+ return [];
143
+ }
144
+ function variantSites(config, label, registry, containers, targets, host, write2) {
145
+ const sites = [];
146
+ const variants = config.getProperty("variants");
147
+ if (Node.isPropertyAssignment(variants)) {
148
+ const object = unwrapExpression(variants.getInitializerOrThrow());
149
+ if (Node.isObjectLiteralExpression(object)) {
150
+ for (const variant of object.getProperties()) {
151
+ if (!Node.isPropertyAssignment(variant)) continue;
152
+ const variantName = compact(variant.getNameNode().getText());
153
+ const branches = unwrapExpression(variant.getInitializerOrThrow());
154
+ if (!Node.isObjectLiteralExpression(branches)) continue;
155
+ for (const branch of branches.getProperties()) {
156
+ if (!Node.isPropertyAssignment(branch)) continue;
157
+ const branchName = compact(branch.getNameNode().getText());
158
+ for (const style of variantStyleObjects(branch.getInitializerOrThrow())) {
159
+ const site = convertStyleObject(style, "styled", `${label} variants.${variantName}.${branchName}`, registry, containers, targets, host, write2);
160
+ if (site) sites.push(site);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ }
166
+ const compound = config.getProperty("compoundVariants");
167
+ if (Node.isPropertyAssignment(compound)) {
168
+ const array = unwrapExpression(compound.getInitializerOrThrow());
169
+ if (Node.isArrayLiteralExpression(array)) {
170
+ for (const [index, element] of array.getElements().entries()) {
171
+ const entry = unwrapExpression(element);
172
+ if (!Node.isObjectLiteralExpression(entry)) continue;
173
+ const style = entry.getProperty("style");
174
+ if (!Node.isPropertyAssignment(style)) continue;
175
+ for (const object of variantStyleObjects(style.getInitializerOrThrow())) {
176
+ const site = convertStyleObject(object, "styled", `${label} compoundVariants[${index}]`, registry, containers, targets, host, write2);
177
+ if (site) sites.push(site);
178
+ }
179
+ }
180
+ }
181
+ }
182
+ return sites;
183
+ }
184
+ function conversionTargets(filePath) {
185
+ if (/\.web\.[cm]?[jt]sx?$/.test(filePath)) return "web";
186
+ if (/\.native\.[cm]?[jt]sx?$/.test(filePath)) return "native";
187
+ return "shared";
188
+ }
189
+ function typeAwareHost(node) {
190
+ const checker = node.getProject().getTypeChecker().compilerObject;
191
+ const host = resolveTamaguiHost(checker, node.compilerNode);
192
+ if (!host || node.getText() !== "View") return host;
193
+ return {
194
+ ...host,
195
+ accepts: (property) => !(property in stylePropsTextOnly) && host.accepts(property)
196
+ };
197
+ }
198
+ function inspectFile(sourceFile, registry, provenance2, write2) {
199
+ const containers = planContainers(sourceFile, registry);
200
+ const targets = conversionTargets(sourceFile.getFilePath());
201
+ const sites = [];
202
+ const styledCalls = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).filter((call) => provenance2.isTamaguiStyledCall(call)).sort((left, right) => right.getStart() - left.getStart());
203
+ const jsxOpenings = [...sourceFile.getDescendantsOfKind(SyntaxKind.JsxOpeningElement), ...sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)].filter((opening) => provenance2.isTamaguiElement(opening)).sort((left, right) => right.getStart() - left.getStart());
204
+ for (const opening of jsxOpenings) {
205
+ const site = convertJsxSite(opening, registry, containers, targets, typeAwareHost(opening.getTagNameNode()), write2);
206
+ if (site) sites.push(site);
207
+ }
208
+ for (const call of styledCalls) {
209
+ const component = call.getArguments()[0];
210
+ const host = component ? typeAwareHost(component) : void 0;
211
+ const config = unwrapExpression(call.getArguments()[1] ?? call);
212
+ if (!Node.isObjectLiteralExpression(config)) continue;
213
+ const label = `styled(${compact(call.getArguments()[0]?.getText() ?? "unknown")}, \u2026)`;
214
+ sites.push(...variantSites(config, label, registry, containers, targets, host, write2));
215
+ const site = convertStyleObject(config, "styled", label, registry, containers, targets, host, write2);
216
+ if (site) sites.push(site);
217
+ }
218
+ sites.sort((left, right) => left.line - right.line || left.label.localeCompare(right.label));
219
+ return {
220
+ file: relative(projectRoot, sourceFile.getFilePath()),
221
+ sites
222
+ };
223
+ }
224
+ const usage = `Converts Tamagui style syntax to V3 flat property values and reports what it cannot convert.
225
+
226
+ npx @tamagui/codemod-flat-values [options] <files or directories...>
227
+
228
+ --report <path> where to write the Markdown report (default: ${relative(projectRoot, defaultReportPath)})
229
+ --json <path> also write the machine-readable report
230
+ --write rewrite every statically safe conversion in place
231
+ --help print this
232
+
233
+ Run it from your project root, which is where paths and the tsconfig resolve from.
234
+ Source files are only written with --write.`;
235
+ function parseArguments(argv) {
236
+ const inputs2 = [];
237
+ let reportPath2 = defaultReportPath;
238
+ let jsonPath2 = null;
239
+ let write2 = false;
240
+ for (let index = 0; index < argv.length; index++) {
241
+ const argument = argv[index];
242
+ if (argument === "--help" || argument === "-h") {
243
+ console.log(usage);
244
+ process.exit(0);
245
+ }
246
+ if (argument === "--write") {
247
+ write2 = true;
248
+ continue;
249
+ }
250
+ if (argument === "--report" || argument === "--json") {
251
+ const next = argv[index + 1];
252
+ if (!next) {
253
+ console.error(`${argument} requires a path
254
+
255
+ ${usage}`);
256
+ process.exit(2);
257
+ }
258
+ if (argument === "--report") reportPath2 = resolve(next);
259
+ else jsonPath2 = resolve(next);
260
+ index++;
261
+ continue;
262
+ }
263
+ if (argument.startsWith("-")) {
264
+ console.error(`unknown option "${argument}"
265
+
266
+ ${usage}`);
267
+ process.exit(2);
268
+ }
269
+ inputs2.push(argument);
270
+ }
271
+ if (!inputs2.length) {
272
+ console.error(`no files or directories given
273
+
274
+ ${usage}`);
275
+ process.exit(2);
276
+ }
277
+ return {
278
+ reportPath: reportPath2,
279
+ jsonPath: jsonPath2,
280
+ inputs: inputs2,
281
+ write: write2
282
+ };
283
+ }
284
+ const { reportPath, jsonPath, inputs, write } = parseArguments(process.argv.slice(2));
285
+ const { sourceFiles, ignoredFiles } = collectFiles(inputs);
286
+ for (const sourceFile of sourceFiles) {
287
+ const diagnostics = sourceFile.compilerNode.parseDiagnostics;
288
+ if (diagnostics?.length) {
289
+ console.error(`${relative(projectRoot, sourceFile.getFilePath())}: source has parse errors; no files were written`);
290
+ process.exit(2);
291
+ }
292
+ }
293
+ const originals = new Map(sourceFiles.map((sourceFile) => [sourceFile.getFilePath(), sourceFile.getFullText()]));
294
+ const modifierRegistry = createModifierRegistry({
295
+ mediaNames: mediaNames(sourceFiles),
296
+ themeNames: themeNames(sourceFiles)
297
+ });
298
+ const provenance = createProvenance();
299
+ const files = sourceFiles.map((sourceFile) => inspectFile(sourceFile, modifierRegistry.registry, provenance, write));
300
+ if (write) {
301
+ for (const sourceFile of sourceFiles) {
302
+ const filePath = sourceFile.getFilePath();
303
+ const parsed = ts.createSourceFile(filePath, sourceFile.getFullText(), ScriptTarget.Latest, true, filePath.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
304
+ if (parsed.parseDiagnostics?.length) {
305
+ const details = parsed.parseDiagnostics.map((diagnostic) => {
306
+ const start = diagnostic.start ?? 0;
307
+ const position = parsed.getLineAndCharacterOfPosition(start);
308
+ const line = parsed.text.split(/\r?\n/)[position.line] ?? "";
309
+ return `${position.line + 1}:${position.character + 1} ${ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n")}
310
+ ${line.trim()}`;
311
+ }).join("\n");
312
+ console.error(`${relative(projectRoot, filePath)}: rewrite produced parse errors; no files were written
313
+ ${details}`);
314
+ process.exit(2);
315
+ }
316
+ }
317
+ }
318
+ const { text, summary } = renderReport(files, inputs.map((input) => relative(projectRoot, resolve(projectRoot, input))), modifierRegistry.diagnostics, ignoredFiles, write);
319
+ mkdirSync(dirname(reportPath), { recursive: true });
320
+ writeFileSync(reportPath, text);
321
+ if (jsonPath !== null) {
322
+ mkdirSync(dirname(jsonPath), { recursive: true });
323
+ writeFileSync(jsonPath, `${JSON.stringify({
324
+ files,
325
+ summary
326
+ }, null, 2)}
327
+ `);
328
+ }
329
+ let written = 0;
330
+ if (write) {
331
+ for (const sourceFile of sourceFiles) {
332
+ const next = sourceFile.getFullText();
333
+ if (next === originals.get(sourceFile.getFilePath())) continue;
334
+ writeFileSync(sourceFile.getFilePath(), next);
335
+ written++;
336
+ }
337
+ }
338
+ console.log(`wrote ${reportPath}`);
339
+ if (write) console.log(`rewrote ${written} source files`);
340
+ console.log(`${summary.sites} sites: ${summary.clean - summary.waiting} clean, ${summary.needsRelocation} need relocation, ${summary.unknownHost} unknown host, ${summary.ineligible} ineligible, ${summary.waiting} waiting on runtime support, ${summary.flagged} syntax-flagged; ${summary.ignoredFiles} source files ignored`);
341
+
342
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["index.js"],"sourcesContent":["#!/usr/bin/env node\nimport { existsSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, relative, resolve } from \"node:path\";\nimport { resolveTamaguiHost } from \"@tamagui/language-service/host\";\nimport { stylePropsTextOnly } from \"@tamagui/helpers\";\nimport {\n ModuleKind,\n ModuleResolutionKind,\n Node,\n Project,\n ScriptTarget,\n SyntaxKind,\n ts\n} from \"ts-morph\";\nimport { planContainers } from \"./containers\";\nimport { convertJsxSite, convertStyleObject } from \"./convert\";\nimport { compact, unwrapExpression } from \"./expressions\";\nimport {\n codemodMediaNames,\n createModifierRegistry,\n grammarPlatformNames\n} from \"./grammar\";\nimport { createProvenance } from \"./provenance\";\nimport { renderReport } from \"./report\";\nconst projectRoot = process.cwd();\nconst defaultReportPath = resolve(projectRoot, \"tamagui-flat-values-report.md\");\nconst ignoreMarker = \".tamagui-flat-values-ignore\";\nconst ignoredDirectories = /* @__PURE__ */ new Map();\nfunction isIgnored(filePath) {\n let directory = dirname(filePath);\n const visited = [];\n while (directory === projectRoot || !relative(projectRoot, directory).startsWith(\"..\")) {\n const cached = ignoredDirectories.get(directory);\n if (cached !== void 0) {\n for (const seen of visited) ignoredDirectories.set(seen, cached);\n return cached;\n }\n visited.push(directory);\n if (existsSync(resolve(directory, ignoreMarker))) {\n for (const seen of visited) ignoredDirectories.set(seen, true);\n return true;\n }\n if (directory === projectRoot) break;\n const parent = dirname(directory);\n if (parent === directory) break;\n directory = parent;\n }\n for (const seen of visited) ignoredDirectories.set(seen, false);\n return false;\n}\nfunction collectFiles(inputs2) {\n const tsConfigFilePath = resolve(projectRoot, \"tsconfig.json\");\n if (!existsSync(tsConfigFilePath)) {\n console.error(\n `no tsconfig.json in ${projectRoot}; run the codemod from your project root`\n );\n process.exit(2);\n }\n const project = new Project({\n tsConfigFilePath,\n skipAddingFilesFromTsConfig: true,\n compilerOptions: {\n allowJs: false,\n jsx: 4,\n target: ScriptTarget.ES2020,\n module: ModuleKind.ESNext,\n moduleResolution: ModuleResolutionKind.NodeJs,\n skipLibCheck: true,\n strictNullChecks: true,\n baseUrl: projectRoot\n }\n });\n const files2 = /* @__PURE__ */ new Map();\n const ignored = /* @__PURE__ */ new Set();\n const missing = [];\n for (const input of inputs2) {\n const path = resolve(projectRoot, input);\n if (!existsSync(path)) {\n missing.push(input);\n continue;\n }\n const pattern = /\\.[cm]?[jt]sx?$/.test(path) ? path : `${path}/**/*.{ts,tsx}`;\n const matched = project.addSourceFilesAtPaths(pattern);\n if (!matched.length) missing.push(input);\n for (const file of matched) {\n const filePath = file.getFilePath();\n if (isIgnored(filePath)) ignored.add(filePath);\n else files2.set(filePath, file);\n }\n }\n if (missing.length) {\n console.error(\n `no source file matched ${missing.map((input) => `\"${input}\"`).join(\", \")}`\n );\n process.exit(2);\n }\n if (files2.size === 0 && ignored.size > 0) {\n console.error(\n `all ${ignored.size} matched source ${ignored.size === 1 ? \"file was\" : \"files were\"} skipped by ${ignoreMarker}; no migration report was written`\n );\n process.exit(2);\n }\n return {\n sourceFiles: [...files2.values()].sort(\n (left, right) => left.getFilePath().localeCompare(right.getFilePath())\n ),\n ignoredFiles: ignored.size\n };\n}\nfunction themeNames(sourceFiles2) {\n const names = /* @__PURE__ */ new Set([\"light\", \"dark\"]);\n for (const sourceFile of sourceFiles2) {\n for (const name of conditionNames(sourceFile)) {\n if (name.startsWith(\"$theme-\")) names.add(name.slice(\"$theme-\".length));\n }\n }\n return names;\n}\nfunction mediaNames(sourceFiles2) {\n const names = new Set(codemodMediaNames);\n for (const sourceFile of sourceFiles2) {\n for (const name of conditionNames(sourceFile)) {\n if (!name.startsWith(\"$\")) continue;\n if (name.startsWith(\"$theme-\") || name.startsWith(\"$platform-\") || name.startsWith(\"$group-\") || grammarPlatformNames.has(name.slice(1))) {\n continue;\n }\n names.add(name.slice(1));\n }\n }\n return names;\n}\nfunction conditionNames(sourceFile) {\n const names = [];\n for (const attribute of sourceFile.getDescendantsOfKind(SyntaxKind.JsxAttribute)) {\n const name = attribute.getNameNode();\n if (Node.isIdentifier(name)) names.push(name.getText());\n }\n for (const property of sourceFile.getDescendantsOfKind(SyntaxKind.PropertyAssignment)) {\n const name = property.getNameNode();\n if (Node.isComputedPropertyName(name)) continue;\n names.push(name.getText().replace(/^['\"]|['\"]$/g, \"\"));\n }\n return names;\n}\nfunction variantStyleObjects(value) {\n const current = unwrapExpression(value);\n if (Node.isObjectLiteralExpression(current)) return [current];\n if (Node.isConditionalExpression(current)) {\n return [\n ...variantStyleObjects(current.getWhenTrue()),\n ...variantStyleObjects(current.getWhenFalse())\n ];\n }\n if (Node.isArrowFunction(current) || Node.isFunctionExpression(current)) {\n const body = current.getBody();\n if (Node.isBlock(body)) {\n return body.getDescendantsOfKind(SyntaxKind.ReturnStatement).flatMap((statement) => {\n const returned = statement.getExpression();\n return returned ? variantStyleObjects(returned) : [];\n });\n }\n return variantStyleObjects(body);\n }\n return [];\n}\nfunction variantSites(config, label, registry, containers, targets, host, write2) {\n const sites = [];\n const variants = config.getProperty(\"variants\");\n if (Node.isPropertyAssignment(variants)) {\n const object = unwrapExpression(variants.getInitializerOrThrow());\n if (Node.isObjectLiteralExpression(object)) {\n for (const variant of object.getProperties()) {\n if (!Node.isPropertyAssignment(variant)) continue;\n const variantName = compact(variant.getNameNode().getText());\n const branches = unwrapExpression(variant.getInitializerOrThrow());\n if (!Node.isObjectLiteralExpression(branches)) continue;\n for (const branch of branches.getProperties()) {\n if (!Node.isPropertyAssignment(branch)) continue;\n const branchName = compact(branch.getNameNode().getText());\n for (const style of variantStyleObjects(branch.getInitializerOrThrow())) {\n const site = convertStyleObject(\n style,\n \"styled\",\n `${label} variants.${variantName}.${branchName}`,\n registry,\n containers,\n targets,\n host,\n write2\n );\n if (site) sites.push(site);\n }\n }\n }\n }\n }\n const compound = config.getProperty(\"compoundVariants\");\n if (Node.isPropertyAssignment(compound)) {\n const array = unwrapExpression(compound.getInitializerOrThrow());\n if (Node.isArrayLiteralExpression(array)) {\n for (const [index, element] of array.getElements().entries()) {\n const entry = unwrapExpression(element);\n if (!Node.isObjectLiteralExpression(entry)) continue;\n const style = entry.getProperty(\"style\");\n if (!Node.isPropertyAssignment(style)) continue;\n for (const object of variantStyleObjects(style.getInitializerOrThrow())) {\n const site = convertStyleObject(\n object,\n \"styled\",\n `${label} compoundVariants[${index}]`,\n registry,\n containers,\n targets,\n host,\n write2\n );\n if (site) sites.push(site);\n }\n }\n }\n }\n return sites;\n}\nfunction conversionTargets(filePath) {\n if (/\\.web\\.[cm]?[jt]sx?$/.test(filePath)) return \"web\";\n if (/\\.native\\.[cm]?[jt]sx?$/.test(filePath)) return \"native\";\n return \"shared\";\n}\nfunction typeAwareHost(node) {\n const checker = node.getProject().getTypeChecker().compilerObject;\n const host = resolveTamaguiHost(\n checker,\n node.compilerNode\n );\n if (!host || node.getText() !== \"View\") return host;\n return {\n ...host,\n accepts: (property) => !(property in stylePropsTextOnly) && host.accepts(property)\n };\n}\nfunction inspectFile(sourceFile, registry, provenance2, write2) {\n const containers = planContainers(sourceFile, registry);\n const targets = conversionTargets(sourceFile.getFilePath());\n const sites = [];\n const styledCalls = sourceFile.getDescendantsOfKind(SyntaxKind.CallExpression).filter((call) => provenance2.isTamaguiStyledCall(call)).sort((left, right) => right.getStart() - left.getStart());\n const jsxOpenings = [\n ...sourceFile.getDescendantsOfKind(SyntaxKind.JsxOpeningElement),\n ...sourceFile.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)\n ].filter((opening) => provenance2.isTamaguiElement(opening)).sort((left, right) => right.getStart() - left.getStart());\n for (const opening of jsxOpenings) {\n const site = convertJsxSite(\n opening,\n registry,\n containers,\n targets,\n typeAwareHost(opening.getTagNameNode()),\n write2\n );\n if (site) sites.push(site);\n }\n for (const call of styledCalls) {\n const component = call.getArguments()[0];\n const host = component ? typeAwareHost(component) : void 0;\n const config = unwrapExpression(\n call.getArguments()[1] ?? call\n );\n if (!Node.isObjectLiteralExpression(config)) continue;\n const label = `styled(${compact(call.getArguments()[0]?.getText() ?? \"unknown\")}, \\u2026)`;\n sites.push(...variantSites(config, label, registry, containers, targets, host, write2));\n const site = convertStyleObject(\n config,\n \"styled\",\n label,\n registry,\n containers,\n targets,\n host,\n write2\n );\n if (site) sites.push(site);\n }\n sites.sort(\n (left, right) => left.line - right.line || left.label.localeCompare(right.label)\n );\n return { file: relative(projectRoot, sourceFile.getFilePath()), sites };\n}\nconst usage = `Converts Tamagui style syntax to V3 flat property values and reports what it cannot convert.\n\n npx @tamagui/codemod-flat-values [options] <files or directories...>\n\n --report <path> where to write the Markdown report (default: ${relative(\n projectRoot,\n defaultReportPath\n)})\n --json <path> also write the machine-readable report\n --write rewrite every statically safe conversion in place\n --help print this\n\nRun it from your project root, which is where paths and the tsconfig resolve from.\nSource files are only written with --write.`;\nfunction parseArguments(argv) {\n const inputs2 = [];\n let reportPath2 = defaultReportPath;\n let jsonPath2 = null;\n let write2 = false;\n for (let index = 0; index < argv.length; index++) {\n const argument = argv[index];\n if (argument === \"--help\" || argument === \"-h\") {\n console.log(usage);\n process.exit(0);\n }\n if (argument === \"--write\") {\n write2 = true;\n continue;\n }\n if (argument === \"--report\" || argument === \"--json\") {\n const next = argv[index + 1];\n if (!next) {\n console.error(`${argument} requires a path\n\n${usage}`);\n process.exit(2);\n }\n if (argument === \"--report\") reportPath2 = resolve(next);\n else jsonPath2 = resolve(next);\n index++;\n continue;\n }\n if (argument.startsWith(\"-\")) {\n console.error(`unknown option \"${argument}\"\n\n${usage}`);\n process.exit(2);\n }\n inputs2.push(argument);\n }\n if (!inputs2.length) {\n console.error(`no files or directories given\n\n${usage}`);\n process.exit(2);\n }\n return { reportPath: reportPath2, jsonPath: jsonPath2, inputs: inputs2, write: write2 };\n}\nconst { reportPath, jsonPath, inputs, write } = parseArguments(process.argv.slice(2));\nconst { sourceFiles, ignoredFiles } = collectFiles(inputs);\nfor (const sourceFile of sourceFiles) {\n const diagnostics = sourceFile.compilerNode.parseDiagnostics;\n if (diagnostics?.length) {\n console.error(\n `${relative(projectRoot, sourceFile.getFilePath())}: source has parse errors; no files were written`\n );\n process.exit(2);\n }\n}\nconst originals = new Map(\n sourceFiles.map((sourceFile) => [sourceFile.getFilePath(), sourceFile.getFullText()])\n);\nconst modifierRegistry = createModifierRegistry({\n mediaNames: mediaNames(sourceFiles),\n themeNames: themeNames(sourceFiles)\n});\nconst provenance = createProvenance();\nconst files = sourceFiles.map(\n (sourceFile) => inspectFile(sourceFile, modifierRegistry.registry, provenance, write)\n);\nif (write) {\n for (const sourceFile of sourceFiles) {\n const filePath = sourceFile.getFilePath();\n const parsed = ts.createSourceFile(\n filePath,\n sourceFile.getFullText(),\n ScriptTarget.Latest,\n true,\n filePath.endsWith(\"x\") ? ts.ScriptKind.TSX : ts.ScriptKind.TS\n );\n if (parsed.parseDiagnostics?.length) {\n const details = parsed.parseDiagnostics.map((diagnostic) => {\n const start = diagnostic.start ?? 0;\n const position = parsed.getLineAndCharacterOfPosition(start);\n const line = parsed.text.split(/\\r?\\n/)[position.line] ?? \"\";\n return `${position.line + 1}:${position.character + 1} ${ts.flattenDiagnosticMessageText(\n diagnostic.messageText,\n \"\\n\"\n )}\n ${line.trim()}`;\n }).join(\"\\n\");\n console.error(\n `${relative(projectRoot, filePath)}: rewrite produced parse errors; no files were written\n${details}`\n );\n process.exit(2);\n }\n }\n}\nconst { text, summary } = renderReport(\n files,\n inputs.map((input) => relative(projectRoot, resolve(projectRoot, input))),\n modifierRegistry.diagnostics,\n ignoredFiles,\n write\n);\nmkdirSync(dirname(reportPath), { recursive: true });\nwriteFileSync(reportPath, text);\nif (jsonPath !== null) {\n mkdirSync(dirname(jsonPath), { recursive: true });\n writeFileSync(jsonPath, `${JSON.stringify({ files, summary }, null, 2)}\n`);\n}\nlet written = 0;\nif (write) {\n for (const sourceFile of sourceFiles) {\n const next = sourceFile.getFullText();\n if (next === originals.get(sourceFile.getFilePath())) continue;\n writeFileSync(sourceFile.getFilePath(), next);\n written++;\n }\n}\nconsole.log(`wrote ${reportPath}`);\nif (write) console.log(`rewrote ${written} source files`);\nconsole.log(\n `${summary.sites} sites: ${summary.clean - summary.waiting} clean, ${summary.needsRelocation} need relocation, ${summary.unknownHost} unknown host, ${summary.ineligible} ineligible, ${summary.waiting} waiting on runtime support, ${summary.flagged} syntax-flagged; ${summary.ignoredFiles} source files ignored`\n);\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAM,cAAc,QAAQ,IAAI;AAChC,MAAM,oBAAoB,QAAQ,aAAa,+BAA+B;AAC9E,MAAM,eAAe;AACrB,MAAM,qCAAqC,IAAI,IAAI;AACnD,SAAS,UAAU,UAAU;CAC3B,IAAI,YAAY,QAAQ,QAAQ;CAChC,MAAM,UAAU,CAAC;CACjB,OAAO,cAAc,eAAe,CAAC,SAAS,aAAa,SAAS,EAAE,WAAW,IAAI,GAAG;EACtF,MAAM,SAAS,mBAAmB,IAAI,SAAS;EAC/C,IAAI,WAAW,KAAK,GAAG;GACrB,KAAK,MAAM,QAAQ,SAAS,mBAAmB,IAAI,MAAM,MAAM;GAC/D,OAAO;EACT;EACA,QAAQ,KAAK,SAAS;EACtB,IAAI,WAAW,QAAQ,WAAW,YAAY,CAAC,GAAG;GAChD,KAAK,MAAM,QAAQ,SAAS,mBAAmB,IAAI,MAAM,IAAI;GAC7D,OAAO;EACT;EACA,IAAI,cAAc,aAAa;EAC/B,MAAM,SAAS,QAAQ,SAAS;EAChC,IAAI,WAAW,WAAW;EAC1B,YAAY;CACd;CACA,KAAK,MAAM,QAAQ,SAAS,mBAAmB,IAAI,MAAM,KAAK;CAC9D,OAAO;AACT;AACA,SAAS,aAAa,SAAS;CAC7B,MAAM,mBAAmB,QAAQ,aAAa,eAAe;CAC7D,IAAI,CAAC,WAAW,gBAAgB,GAAG;EACjC,QAAQ,MACN,uBAAuB,YAAY,yCACrC;EACA,QAAQ,KAAK,CAAC;CAChB;CACA,MAAM,UAAU,IAAI,QAAQ;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AAU;AACd,IAAI,OAAO;CACT,KAAK,MAAM,cAAc,aAAa;EACpC,MAAM,OAAO,WAAW,YAAY;EACpC,IAAI,SAAS,UAAU,IAAI,WAAW,YAAY,CAAC,GAAG;EACtD,cAAc,WAAW,YAAY,GAAG,IAAI;EAC5C;CACF;AACF;AACA,QAAQ,IAAI,SAAS,YAAY;AACjC,IAAI,OAAO,QAAQ,IAAI,WAAW,QAAQ,cAAc;AACxD,QAAQ,IACN,GAAG,QAAQ,MAAM,UAAU,QAAQ,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,gBAAgB,oBAAoB,QAAQ,YAAY,iBAAiB,QAAQ,WAAW,eAAe,QAAQ,QAAQ,+BAA+B,QAAQ,QAAQ,mBAAmB,QAAQ,aAAa,sBACjS"}
@@ -0,0 +1,293 @@
1
+ import { transformFamilyProps, unitlessNumberProperties } from "@tamagui/style-grammar/tooling";
2
+
3
+ const pseudoToModifier = Object.freeze({
4
+ hoverStyle: "hover",
5
+ pressStyle: "press",
6
+ focusStyle: "focus",
7
+ focusVisibleStyle: "focus-visible",
8
+ focusWithinStyle: "focus-within",
9
+ disabledStyle: "disabled",
10
+ enterStyle: "enter",
11
+ exitStyle: "exit"
12
+ });
13
+ const transformPartProperties = /* @__PURE__ */ new Set([
14
+ "scale",
15
+ "scaleX",
16
+ "scaleY",
17
+ "rotate",
18
+ "rotateX",
19
+ "rotateY",
20
+ "rotateZ",
21
+ "x",
22
+ "y",
23
+ "skewX",
24
+ "skewY",
25
+ "perspective"
26
+ ]);
27
+ function resolveLegacyCondition(propName, registry) {
28
+ const pseudoModifier = pseudoToModifier[propName];
29
+ if (pseudoModifier !== void 0) {
30
+ return registry.get(pseudoModifier) === "state" ? {
31
+ recognized: true,
32
+ modifiers: [pseudoModifier]
33
+ } : {
34
+ recognized: true,
35
+ error: {
36
+ code: "unregistered-legacy-condition",
37
+ message: `legacy condition "${propName}" maps to unregistered state modifier "${pseudoModifier}"`
38
+ }
39
+ };
40
+ }
41
+ if (propName.startsWith("$theme-")) {
42
+ const modifier = propName.slice("$theme-".length);
43
+ return modifier && registry.get(modifier) === "theme" ? {
44
+ recognized: true,
45
+ modifiers: [modifier]
46
+ } : {
47
+ recognized: true,
48
+ error: {
49
+ code: "unregistered-legacy-condition",
50
+ message: `legacy theme condition "${propName}" does not name a registered theme`
51
+ }
52
+ };
53
+ }
54
+ if (propName.startsWith("$platform-")) {
55
+ const modifier = propName.slice("$platform-".length);
56
+ return modifier && registry.get(modifier) === "platform" ? {
57
+ recognized: true,
58
+ modifiers: [modifier]
59
+ } : {
60
+ recognized: true,
61
+ error: {
62
+ code: "unregistered-legacy-condition",
63
+ message: `legacy platform condition "${propName}" does not name a registered platform`
64
+ }
65
+ };
66
+ }
67
+ if (propName.startsWith("$group-")) {
68
+ const remainder = propName.slice("$group-".length);
69
+ const candidates = [];
70
+ let start = 0;
71
+ while (start < remainder.length) {
72
+ const state2 = remainder.slice(start);
73
+ if (registry.get(state2) === "state") candidates.push(state2);
74
+ const dash = remainder.indexOf("-", start);
75
+ if (dash === -1) break;
76
+ start = dash + 1;
77
+ }
78
+ const longestLength = candidates.reduce((length, state2) => Math.max(length, state2.length), 0);
79
+ const longest = candidates.filter((state2) => state2.length === longestLength);
80
+ if (longest.length > 1) {
81
+ return {
82
+ recognized: true,
83
+ error: {
84
+ code: "ambiguous-legacy-group",
85
+ message: `legacy group condition "${propName}" has more than one equally specific state suffix`
86
+ }
87
+ };
88
+ }
89
+ const state = longest.length === 1 ? longest[0] : null;
90
+ let namePart = state === null ? remainder : state.length === remainder.length ? "" : remainder.slice(0, -(state.length + 1));
91
+ let media = null;
92
+ if (namePart) {
93
+ let scanStart = 0;
94
+ while (scanStart < namePart.length) {
95
+ const suffix2 = namePart.slice(scanStart);
96
+ if (registry.get(`@${suffix2}`) === "container") {
97
+ media = suffix2;
98
+ break;
99
+ }
100
+ const dash = namePart.indexOf("-", scanStart);
101
+ if (dash === -1) break;
102
+ scanStart = dash + 1;
103
+ }
104
+ if (media !== null) {
105
+ namePart = media.length === namePart.length ? "" : namePart.slice(0, -(media.length + 1));
106
+ } else if (state === null) {
107
+ return {
108
+ recognized: true,
109
+ error: {
110
+ code: "unregistered-legacy-condition",
111
+ message: `legacy group condition "${propName}" has no registered state or container-size suffix`
112
+ }
113
+ };
114
+ }
115
+ } else if (state === null) {
116
+ return {
117
+ recognized: true,
118
+ error: {
119
+ code: "unregistered-legacy-condition",
120
+ message: `legacy group condition "${propName}" has no registered state suffix`
121
+ }
122
+ };
123
+ }
124
+ const suffix = namePart ? `/${namePart}` : "";
125
+ const modifiers = [];
126
+ if (media !== null) modifiers.push(`@${media}${suffix}`);
127
+ if (state !== null) modifiers.push(`group-${state}${suffix}`);
128
+ return {
129
+ recognized: true,
130
+ modifiers
131
+ };
132
+ }
133
+ if (propName[0] === "$") {
134
+ const modifier = propName.slice(1);
135
+ const kind = registry.get(modifier);
136
+ if (kind === "media" || kind === "container") {
137
+ return {
138
+ recognized: true,
139
+ modifiers: [modifier]
140
+ };
141
+ }
142
+ }
143
+ return { recognized: false };
144
+ }
145
+ function isConditionObject(value) {
146
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
147
+ const prototype = Object.getPrototypeOf(value);
148
+ return prototype === Object.prototype || prototype === null;
149
+ }
150
+ function convertStyleValue(prop, value, path, errors) {
151
+ if (transformPartProperties.has(prop) && !transformFamilyProps.has(prop)) {
152
+ errors.push({
153
+ code: "legacy-transform-part",
154
+ path,
155
+ message: `legacy transform part "${prop}" has no flat spelling; author it inside a flat \`transform\` value (only x, y, scale, scaleX, scaleY, and rotate are first-class)`
156
+ });
157
+ return null;
158
+ }
159
+ if (typeof value === "number" && Number.isFinite(value) && transformFamilyProps.has(prop)) {
160
+ if (prop === "rotate") return value === 0 ? "0deg" : `${value}deg`;
161
+ if (prop === "x" || prop === "y") return value === 0 ? "0" : `${value}px`;
162
+ return String(value);
163
+ }
164
+ if (typeof value === "string") {
165
+ if (!value.length) {
166
+ errors.push({
167
+ code: "unsupported-legacy-value",
168
+ path,
169
+ message: "an empty string cannot become a condition clause payload"
170
+ });
171
+ return null;
172
+ }
173
+ if (value.indexOf("$") === -1) return value;
174
+ if (value.includes("\"") || value.includes("'") || value.includes("url(")) {
175
+ errors.push({
176
+ code: "unsupported-legacy-value",
177
+ path,
178
+ message: `"${value}" mixes "$" with quoted or url() content; migrate the token spelling by hand`
179
+ });
180
+ return null;
181
+ }
182
+ if (/\$[\w-]*\./.test(value)) {
183
+ errors.push({
184
+ code: "legacy-token-dot-path",
185
+ path,
186
+ message: `legacy token in "${value}" uses dot-path naming; rename it to one configured flat token name before conversion`
187
+ });
188
+ return null;
189
+ }
190
+ if (/\$-?\d/.test(value) && !/^\$-?[\w-]+$/.test(value)) {
191
+ errors.push({
192
+ code: "legacy-numeric-composite-token",
193
+ path,
194
+ message: `numeric token in "${value}" is embedded in a composite value; replace it with its resolved CSS value before conversion`
195
+ });
196
+ return null;
197
+ }
198
+ if (/\$(?![\w-])/.test(value)) {
199
+ errors.push({
200
+ code: "unsupported-legacy-value",
201
+ path,
202
+ message: `"$" in "${value}" is not followed by a token name`
203
+ });
204
+ return null;
205
+ }
206
+ return value.replace(/\$([\w-]+)/g, "$1");
207
+ }
208
+ if (typeof value === "number") {
209
+ if (Number.isFinite(value)) {
210
+ return unitlessNumberProperties.has(prop) ? String(value) : `${value}px`;
211
+ }
212
+ errors.push({
213
+ code: "unsupported-legacy-value",
214
+ path,
215
+ message: `non-finite number ${String(value)} cannot become a CSS payload`
216
+ });
217
+ return null;
218
+ }
219
+ errors.push({
220
+ code: "unsupported-legacy-value",
221
+ path,
222
+ message: `legacy condition value for "${prop}" must be a string or finite number`
223
+ });
224
+ return null;
225
+ }
226
+ function convertLegacyConditionProp(propName, value, options) {
227
+ const root = resolveLegacyCondition(propName, options.registry);
228
+ if (!root.recognized) return null;
229
+ const result = {
230
+ contributions: [],
231
+ errors: []
232
+ };
233
+ if ("error" in root) {
234
+ result.errors.push({
235
+ ...root.error,
236
+ path: propName
237
+ });
238
+ return result;
239
+ }
240
+ if (!isConditionObject(value)) {
241
+ result.errors.push({
242
+ code: "legacy-condition-object",
243
+ path: propName,
244
+ message: `legacy condition "${propName}" must contain a style object`
245
+ });
246
+ return result;
247
+ }
248
+ const modifiers = root.modifiers.slice();
249
+ const visit = (object, objectPath) => {
250
+ for (const childProp in object) {
251
+ if (!Object.prototype.hasOwnProperty.call(object, childProp)) continue;
252
+ const childValue = object[childProp];
253
+ const childPath = `${objectPath}.${childProp}`;
254
+ const condition = resolveLegacyCondition(childProp, options.registry);
255
+ if (condition.recognized) {
256
+ if ("error" in condition) {
257
+ result.errors.push({
258
+ ...condition.error,
259
+ path: childPath
260
+ });
261
+ continue;
262
+ }
263
+ if (!isConditionObject(childValue)) {
264
+ result.errors.push({
265
+ code: "legacy-condition-object",
266
+ path: childPath,
267
+ message: `legacy condition "${childProp}" must contain a style object`
268
+ });
269
+ continue;
270
+ }
271
+ modifiers.push(...condition.modifiers);
272
+ visit(childValue, childPath);
273
+ modifiers.length -= condition.modifiers.length;
274
+ continue;
275
+ }
276
+ const payload = convertStyleValue(childProp, childValue, childPath, result.errors);
277
+ if (payload !== null) {
278
+ result.contributions.push({
279
+ prop: childProp,
280
+ clause: {
281
+ modifiers: modifiers.slice(),
282
+ payload
283
+ }
284
+ });
285
+ }
286
+ }
287
+ };
288
+ visit(value, propName);
289
+ return result;
290
+ }
291
+
292
+ export { convertLegacyConditionProp, pseudoToModifier };
293
+ //# sourceMappingURL=legacyConditions.mjs.map