trix-ui 0.2.8 → 0.2.9

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.
Files changed (204) hide show
  1. package/dist/__tests__/contracts/registry.test.d.ts +1 -0
  2. package/dist/__tests__/contracts/registry.test.js +42 -0
  3. package/dist/__tests__/contracts/registry.test.js.map +1 -0
  4. package/dist/__tests__/e2e/cli.test.d.ts +1 -0
  5. package/dist/__tests__/e2e/cli.test.js +67 -0
  6. package/dist/__tests__/e2e/cli.test.js.map +1 -0
  7. package/dist/__tests__/helpers/fs.d.ts +5 -0
  8. package/dist/__tests__/helpers/fs.js +26 -0
  9. package/dist/__tests__/helpers/fs.js.map +1 -0
  10. package/dist/__tests__/integration/commands.integration.test.d.ts +1 -0
  11. package/dist/__tests__/integration/commands.integration.test.js +184 -0
  12. package/dist/__tests__/integration/commands.integration.test.js.map +1 -0
  13. package/dist/commands/__tests__/add-composite.test.d.ts +2 -0
  14. package/dist/commands/__tests__/add-composite.test.js +171 -0
  15. package/dist/commands/__tests__/add-composite.test.js.map +1 -0
  16. package/dist/commands/__tests__/add-entry.mocks.d.ts +23 -0
  17. package/dist/commands/__tests__/add-entry.mocks.js +64 -0
  18. package/dist/commands/__tests__/add-entry.mocks.js.map +1 -0
  19. package/dist/commands/__tests__/add-section.test.d.ts +2 -0
  20. package/dist/commands/__tests__/add-section.test.js +191 -0
  21. package/dist/commands/__tests__/add-section.test.js.map +1 -0
  22. package/dist/commands/__tests__/add-wrapper.test.d.ts +2 -0
  23. package/dist/commands/__tests__/add-wrapper.test.js +171 -0
  24. package/dist/commands/__tests__/add-wrapper.test.js.map +1 -0
  25. package/dist/commands/__tests__/cli-mocks.d.ts +1 -0
  26. package/dist/commands/__tests__/cli-mocks.js +24 -0
  27. package/dist/commands/__tests__/cli-mocks.js.map +1 -0
  28. package/dist/commands/__tests__/doctor.mocks.d.ts +6 -0
  29. package/dist/commands/__tests__/doctor.mocks.js +20 -0
  30. package/dist/commands/__tests__/doctor.mocks.js.map +1 -0
  31. package/dist/commands/__tests__/doctor.test.d.ts +2 -0
  32. package/dist/commands/__tests__/doctor.test.js +80 -0
  33. package/dist/commands/__tests__/doctor.test.js.map +1 -0
  34. package/dist/commands/__tests__/list.mocks.d.ts +8 -0
  35. package/dist/commands/__tests__/list.mocks.js +20 -0
  36. package/dist/commands/__tests__/list.mocks.js.map +1 -0
  37. package/dist/commands/__tests__/list.test.d.ts +2 -0
  38. package/dist/commands/__tests__/list.test.js +60 -0
  39. package/dist/commands/__tests__/list.test.js.map +1 -0
  40. package/dist/commands/__tests__/remove.mocks.d.ts +9 -0
  41. package/dist/commands/__tests__/remove.mocks.js +26 -0
  42. package/dist/commands/__tests__/remove.mocks.js.map +1 -0
  43. package/dist/commands/__tests__/remove.test.d.ts +2 -0
  44. package/dist/commands/__tests__/remove.test.js +116 -0
  45. package/dist/commands/__tests__/remove.test.js.map +1 -0
  46. package/dist/commands/add/__tests__/add.mocks.d.ts +19 -19
  47. package/dist/commands/add/__tests__/add.mocks.js +59 -59
  48. package/dist/commands/add/__tests__/add.test.d.ts +2 -2
  49. package/dist/commands/add/__tests__/add.test.js +140 -140
  50. package/dist/commands/add/analysis.d.ts +4 -4
  51. package/dist/commands/add/analysis.js +56 -56
  52. package/dist/commands/add/command.d.ts +2 -2
  53. package/dist/commands/add/command.js +202 -202
  54. package/dist/commands/add/config.d.ts +2 -2
  55. package/dist/commands/add/config.js +11 -11
  56. package/dist/commands/add/install.d.ts +27 -27
  57. package/dist/commands/add/install.js +80 -80
  58. package/dist/commands/add/package-manager.d.ts +1 -1
  59. package/dist/commands/add/package-manager.js +4 -4
  60. package/dist/commands/add/project-files.d.ts +2 -2
  61. package/dist/commands/add/project-files.js +17 -17
  62. package/dist/commands/add/prompts.d.ts +3 -3
  63. package/dist/commands/add/prompts.js +28 -28
  64. package/dist/commands/add/registry.d.ts +4 -4
  65. package/dist/commands/add/registry.js +6 -6
  66. package/dist/commands/add/types.d.ts +33 -33
  67. package/dist/commands/add/types.js +1 -1
  68. package/dist/commands/add/ui.d.ts +4 -4
  69. package/dist/commands/add/ui.js +55 -55
  70. package/dist/commands/add/validation.d.ts +3 -3
  71. package/dist/commands/add/validation.js +30 -30
  72. package/dist/commands/add-collection.d.ts +1 -1
  73. package/dist/commands/add-collection.js +1 -1
  74. package/dist/commands/add-composite.d.ts +2 -2
  75. package/dist/commands/add-composite.js +201 -201
  76. package/dist/commands/add-section.d.ts +2 -2
  77. package/dist/commands/add-section.js +201 -201
  78. package/dist/commands/add-wrapper.d.ts +2 -2
  79. package/dist/commands/add-wrapper.js +201 -201
  80. package/dist/commands/add.d.ts +1 -1
  81. package/dist/commands/add.js +1 -1
  82. package/dist/commands/build.d.ts +2 -2
  83. package/dist/commands/doctor.d.ts +2 -2
  84. package/dist/commands/doctor.js +67 -67
  85. package/dist/commands/init/__tests__/init.mocks.d.ts +24 -0
  86. package/dist/commands/init/__tests__/init.mocks.js +84 -0
  87. package/dist/commands/init/__tests__/init.mocks.js.map +1 -0
  88. package/dist/commands/init/__tests__/init.test.d.ts +2 -0
  89. package/dist/commands/init/__tests__/init.test.js +283 -0
  90. package/dist/commands/init/__tests__/init.test.js.map +1 -0
  91. package/dist/commands/init/__tests__/tailwind.test.d.ts +1 -0
  92. package/dist/commands/init/__tests__/tailwind.test.js +56 -0
  93. package/dist/commands/init/__tests__/tailwind.test.js.map +1 -0
  94. package/dist/commands/init/__tests__/tsconfig.test.d.ts +1 -0
  95. package/dist/commands/init/__tests__/tsconfig.test.js +108 -0
  96. package/dist/commands/init/__tests__/tsconfig.test.js.map +1 -0
  97. package/dist/commands/init/__tests__/vite.test.d.ts +1 -0
  98. package/dist/commands/init/__tests__/vite.test.js +66 -0
  99. package/dist/commands/init/__tests__/vite.test.js.map +1 -0
  100. package/dist/commands/init/command.d.ts +2 -2
  101. package/dist/commands/init/command.js +114 -114
  102. package/dist/commands/init/config.d.ts +2 -2
  103. package/dist/commands/init/config.js +25 -25
  104. package/dist/commands/init/constants.d.ts +3 -3
  105. package/dist/commands/init/constants.js +105 -105
  106. package/dist/commands/init/dependencies.d.ts +5 -5
  107. package/dist/commands/init/dependencies.js +52 -52
  108. package/dist/commands/init/filesystem.d.ts +1 -1
  109. package/dist/commands/init/filesystem.js +10 -10
  110. package/dist/commands/init/lockfile.d.ts +1 -1
  111. package/dist/commands/init/lockfile.js +1 -1
  112. package/dist/commands/init/package-json.d.ts +6 -6
  113. package/dist/commands/init/package-json.js +18 -18
  114. package/dist/commands/init/project-files.d.ts +8 -0
  115. package/dist/commands/init/project-files.js +37 -0
  116. package/dist/commands/init/project-files.js.map +1 -0
  117. package/dist/commands/init/project.d.ts +3 -3
  118. package/dist/commands/init/project.js +97 -97
  119. package/dist/commands/init/style-imports.d.ts +9 -0
  120. package/dist/commands/init/style-imports.js +218 -0
  121. package/dist/commands/init/style-imports.js.map +1 -0
  122. package/dist/commands/init/tailwind.d.ts +3 -3
  123. package/dist/commands/init/tailwind.js +34 -34
  124. package/dist/commands/init/templates.d.ts +3 -3
  125. package/dist/commands/init/templates.js +15 -15
  126. package/dist/commands/init/tsconfig.d.ts +2 -2
  127. package/dist/commands/init/tsconfig.js +273 -273
  128. package/dist/commands/init/types.d.ts +33 -33
  129. package/dist/commands/init/types.js +1 -1
  130. package/dist/commands/init/ui.d.ts +3 -3
  131. package/dist/commands/init/ui.js +33 -33
  132. package/dist/commands/init/vite.d.ts +23 -0
  133. package/dist/commands/init/vite.js +347 -0
  134. package/dist/commands/init/vite.js.map +1 -0
  135. package/dist/commands/init.d.ts +1 -1
  136. package/dist/commands/init.js +1 -1
  137. package/dist/commands/list.d.ts +2 -2
  138. package/dist/commands/list.js +62 -62
  139. package/dist/commands/remove.d.ts +2 -2
  140. package/dist/commands/remove.js +93 -93
  141. package/dist/commands/shared/add-collection.d.ts +50 -50
  142. package/dist/commands/shared/add-collection.js +206 -206
  143. package/dist/commands/shared/list-entries.d.ts +6 -6
  144. package/dist/commands/shared/list-entries.js +12 -12
  145. package/dist/commands/shared/name-utils.d.ts +1 -1
  146. package/dist/commands/shared/name-utils.js +13 -13
  147. package/dist/commands/shared/remove-entries.d.ts +16 -16
  148. package/dist/commands/shared/remove-entries.js +41 -41
  149. package/dist/icons/index.d.ts +1 -1
  150. package/dist/icons/index.js +1 -1
  151. package/dist/icons/libraries.d.ts +37 -37
  152. package/dist/icons/libraries.js +34 -34
  153. package/dist/index.d.ts +2 -2
  154. package/dist/index.js +30 -30
  155. package/dist/lib/__tests__/config.test.d.ts +1 -0
  156. package/dist/lib/__tests__/config.test.js +49 -0
  157. package/dist/lib/__tests__/config.test.js.map +1 -0
  158. package/dist/lib/__tests__/install.test.d.ts +1 -0
  159. package/dist/lib/__tests__/install.test.js +149 -0
  160. package/dist/lib/__tests__/install.test.js.map +1 -0
  161. package/dist/lib/__tests__/lockfile.test.d.ts +1 -0
  162. package/dist/lib/__tests__/lockfile.test.js +89 -0
  163. package/dist/lib/__tests__/lockfile.test.js.map +1 -0
  164. package/dist/lib/__tests__/paths.test.d.ts +1 -0
  165. package/dist/lib/__tests__/paths.test.js +39 -0
  166. package/dist/lib/__tests__/paths.test.js.map +1 -0
  167. package/dist/lib/__tests__/registry.test.d.ts +1 -0
  168. package/dist/lib/__tests__/registry.test.js +76 -0
  169. package/dist/lib/__tests__/registry.test.js.map +1 -0
  170. package/dist/lib/config.d.ts +45 -45
  171. package/dist/lib/config.js +97 -97
  172. package/dist/lib/fs.d.ts +76 -76
  173. package/dist/lib/fs.js +302 -302
  174. package/dist/lib/highlighter.d.ts +6 -6
  175. package/dist/lib/highlighter.js +7 -7
  176. package/dist/lib/install.d.ts +19 -19
  177. package/dist/lib/install.js +55 -55
  178. package/dist/lib/lockfile.d.ts +63 -63
  179. package/dist/lib/lockfile.js +173 -173
  180. package/dist/lib/logger.d.ts +8 -8
  181. package/dist/lib/logger.js +41 -41
  182. package/dist/lib/paths.d.ts +14 -14
  183. package/dist/lib/paths.js +31 -31
  184. package/dist/lib/registry.d.ts +35 -35
  185. package/dist/lib/registry.js +180 -180
  186. package/dist/schema/index.d.ts +1128 -1128
  187. package/dist/schema/index.js +238 -238
  188. package/dist/styles/create-style-map.d.ts +4 -4
  189. package/dist/styles/create-style-map.js +68 -68
  190. package/dist/styles/transform-style-map.d.ts +3 -3
  191. package/dist/styles/transform-style-map.js +428 -428
  192. package/dist/styles/transform.d.ts +10 -10
  193. package/dist/styles/transform.js +15 -15
  194. package/dist/utils/index.d.ts +6 -6
  195. package/dist/utils/index.js +5 -5
  196. package/dist/utils/transformers/transform-icons.d.ts +2 -2
  197. package/dist/utils/transformers/transform-icons.js +164 -164
  198. package/dist/utils/transformers/transform-menu.d.ts +2 -2
  199. package/dist/utils/transformers/transform-menu.js +39 -39
  200. package/dist/utils/transformers/transform-render.d.ts +2 -2
  201. package/dist/utils/transformers/transform-render.js +97 -97
  202. package/dist/utils/transformers/types.d.ts +14 -14
  203. package/dist/utils/transformers/types.js +1 -1
  204. package/package.json +1 -1
@@ -1,35 +1,35 @@
1
- import path from "node:path";
2
- import { ensureDir, fileExists, readFile, writeFileSafe } from "../../lib/fs.js";
3
- import { BASE_CSS_VARS } from "./constants.js";
4
- export async function setupTailwind(cwd, projectInfo, options) {
5
- const ext = projectInfo.typescript ? "ts" : "js";
6
- // const contentPaths = TAILWIND_CONTENT_PATHS[projectInfo.framework]
7
- const postcssPath = path.join(cwd, "postcss.config.js");
8
- const postcssConfig = `const config = {
9
- plugins: {
10
- "@tailwindcss/postcss": {},
11
- },
12
- };
13
-
14
- export default config;
15
- `;
16
- await writeFileSafe(postcssPath, postcssConfig, Boolean(options.force));
17
- }
18
- export async function setupGlobalStyles(cwd, config, options) {
19
- const stylesPath = path.resolve(cwd, config.paths.styles);
20
- const existingStyles = (await fileExists(stylesPath))
21
- ? await readFile(stylesPath)
22
- : "";
23
- const hasVars = existingStyles.includes("--background") ||
24
- existingStyles.includes("--foreground");
25
- let finalStyles = BASE_CSS_VARS;
26
- if (existingStyles && !hasVars) {
27
- finalStyles = `${BASE_CSS_VARS}\n\n/* Existing styles */\n${existingStyles}`;
28
- }
29
- else if (hasVars && !options.force) {
30
- return;
31
- }
32
- await ensureDir(path.dirname(stylesPath));
33
- await writeFileSafe(stylesPath, finalStyles, Boolean(options.force));
34
- }
1
+ import path from "node:path";
2
+ import { ensureDir, fileExists, readFile, writeFileSafe } from "../../lib/fs.js";
3
+ import { BASE_CSS_VARS } from "./constants.js";
4
+ export async function setupTailwind(cwd, projectInfo, options) {
5
+ const ext = projectInfo.typescript ? "ts" : "js";
6
+ // const contentPaths = TAILWIND_CONTENT_PATHS[projectInfo.framework]
7
+ const postcssPath = path.join(cwd, "postcss.config.js");
8
+ const postcssConfig = `const config = {
9
+ plugins: {
10
+ "@tailwindcss/postcss": {},
11
+ },
12
+ };
13
+
14
+ export default config;
15
+ `;
16
+ await writeFileSafe(postcssPath, postcssConfig, Boolean(options.force));
17
+ }
18
+ export async function setupGlobalStyles(cwd, config, options) {
19
+ const stylesPath = path.resolve(cwd, config.paths.styles);
20
+ const existingStyles = (await fileExists(stylesPath))
21
+ ? await readFile(stylesPath)
22
+ : "";
23
+ const hasVars = existingStyles.includes("--background") ||
24
+ existingStyles.includes("--foreground");
25
+ let finalStyles = BASE_CSS_VARS;
26
+ if (existingStyles && !hasVars) {
27
+ finalStyles = `${BASE_CSS_VARS}\n\n/* Existing styles */\n${existingStyles}`;
28
+ }
29
+ else if (hasVars && !options.force) {
30
+ return;
31
+ }
32
+ await ensureDir(path.dirname(stylesPath));
33
+ await writeFileSafe(stylesPath, finalStyles, Boolean(options.force));
34
+ }
35
35
  //# sourceMappingURL=tailwind.js.map
@@ -1,3 +1,3 @@
1
- import type { InitConfig, ProjectInfo } from "./types.js";
2
- export declare function copyTemplateFiles(cwd: string, config: InitConfig, projectInfo: ProjectInfo, force: boolean): Promise<void>;
3
- export declare function createBarrelFile(cwd: string, config: InitConfig, projectInfo: ProjectInfo): Promise<void>;
1
+ import type { InitConfig, ProjectInfo } from "./types.js";
2
+ export declare function copyTemplateFiles(cwd: string, config: InitConfig, projectInfo: ProjectInfo, force: boolean): Promise<void>;
3
+ export declare function createBarrelFile(cwd: string, config: InitConfig, projectInfo: ProjectInfo): Promise<void>;
@@ -1,16 +1,16 @@
1
- import path from "node:path";
2
- import { copyFileSafe, writeFileSafe } from "../../lib/fs.js";
3
- import { getTemplatePath } from "../../lib/paths.js";
4
- export async function copyTemplateFiles(cwd, config, projectInfo, force) {
5
- const ext = projectInfo.typescript ? "ts" : "js";
6
- await copyFileSafe(getTemplatePath(`lib/utils.${ext}`), path.resolve(cwd, config.paths.utils), force);
7
- }
8
- export async function createBarrelFile(cwd, config, projectInfo) {
9
- const ext = projectInfo.typescript ? "ts" : "js";
10
- const barrelPath = path.resolve(cwd, config.paths.components, `index.${ext}`);
11
- const content = `// Auto-generated barrel file
12
- // This file exports all components from this directory
13
- `;
14
- await writeFileSafe(barrelPath, content, true);
15
- }
1
+ import path from "node:path";
2
+ import { copyFileSafe, writeFileSafe } from "../../lib/fs.js";
3
+ import { getTemplatePath } from "../../lib/paths.js";
4
+ export async function copyTemplateFiles(cwd, config, projectInfo, force) {
5
+ const ext = projectInfo.typescript ? "ts" : "js";
6
+ await copyFileSafe(getTemplatePath(`lib/utils.${ext}`), path.resolve(cwd, config.paths.utils), force);
7
+ }
8
+ export async function createBarrelFile(cwd, config, projectInfo) {
9
+ const ext = projectInfo.typescript ? "ts" : "js";
10
+ const barrelPath = path.resolve(cwd, config.paths.components, `index.${ext}`);
11
+ const content = `// Auto-generated barrel file
12
+ // This file exports all components from this directory
13
+ `;
14
+ await writeFileSafe(barrelPath, content, true);
15
+ }
16
16
  //# sourceMappingURL=templates.js.map
@@ -1,2 +1,2 @@
1
- import type { ProjectInfo } from "./types.js";
2
- export declare function setupTypeScriptPaths(cwd: string, projectInfo: ProjectInfo): Promise<void>;
1
+ import type { ProjectInfo } from "./types.js";
2
+ export declare function setupTypeScriptPaths(cwd: string, projectInfo: ProjectInfo): Promise<void>;
@@ -1,274 +1,274 @@
1
- import path from "node:path";
2
- import { directoryExists, fileExists, readFile, writeFile } from "../../lib/fs.js";
3
- function isRecord(value) {
4
- return typeof value === "object" && value !== null && !Array.isArray(value);
5
- }
6
- function normalizePathSegment(value) {
7
- const normalized = path.posix
8
- .normalize(value.replace(/\\/g, "/").trim())
9
- .replace(/\/+$/, "");
10
- return normalized.length > 0 ? normalized : ".";
11
- }
12
- function isEscaped(input, index) {
13
- let slashCount = 0;
14
- for (let i = index - 1; i >= 0 && input[i] === "\\"; i -= 1) {
15
- slashCount += 1;
16
- }
17
- return slashCount % 2 === 1;
18
- }
19
- function findNextMeaningfulChar(input, startIndex) {
20
- let index = startIndex;
21
- while (index < input.length) {
22
- const char = input[index];
23
- const next = input[index + 1];
24
- if (char === " " || char === "\t" || char === "\n" || char === "\r") {
25
- index += 1;
26
- continue;
27
- }
28
- if (char === "/" && next === "/") {
29
- index += 2;
30
- while (index < input.length &&
31
- input[index] !== "\n" &&
32
- input[index] !== "\r") {
33
- index += 1;
34
- }
35
- continue;
36
- }
37
- if (char === "/" && next === "*") {
38
- index += 2;
39
- while (index < input.length) {
40
- if (input[index] === "*" && input[index + 1] === "/") {
41
- index += 2;
42
- break;
43
- }
44
- index += 1;
45
- }
46
- continue;
47
- }
48
- return char;
49
- }
50
- return "";
51
- }
52
- function sanitizeJsonc(input) {
53
- let output = "";
54
- let index = 0;
55
- let inString = false;
56
- let inLineComment = false;
57
- let inBlockComment = false;
58
- while (index < input.length) {
59
- const char = input[index];
60
- const next = input[index + 1];
61
- if (inLineComment) {
62
- if (char === "\n" || char === "\r") {
63
- inLineComment = false;
64
- output += char;
65
- }
66
- index += 1;
67
- continue;
68
- }
69
- if (inBlockComment) {
70
- if (char === "*" && next === "/") {
71
- inBlockComment = false;
72
- index += 2;
73
- continue;
74
- }
75
- index += 1;
76
- continue;
77
- }
78
- if (inString) {
79
- output += char;
80
- if (char === "\"" && !isEscaped(input, index)) {
81
- inString = false;
82
- }
83
- index += 1;
84
- continue;
85
- }
86
- if (char === "\"") {
87
- inString = true;
88
- output += char;
89
- index += 1;
90
- continue;
91
- }
92
- if (char === "/" && next === "/") {
93
- inLineComment = true;
94
- index += 2;
95
- continue;
96
- }
97
- if (char === "/" && next === "*") {
98
- inBlockComment = true;
99
- index += 2;
100
- continue;
101
- }
102
- if (char === ",") {
103
- const nextMeaningful = findNextMeaningfulChar(input, index + 1);
104
- if (nextMeaningful === "}" || nextMeaningful === "]") {
105
- index += 1;
106
- continue;
107
- }
108
- }
109
- output += char;
110
- index += 1;
111
- }
112
- return output;
113
- }
114
- function parseJsonc(content, filePath) {
115
- try {
116
- const sanitized = sanitizeJsonc(content);
117
- const parsed = JSON.parse(sanitized);
118
- if (!isRecord(parsed)) {
119
- throw new Error("Root value must be an object");
120
- }
121
- return parsed;
122
- }
123
- catch (error) {
124
- const message = error instanceof Error ? error.message : "Unknown error";
125
- throw new Error(`Invalid JSON in ${path.basename(filePath)}: ${message}`);
126
- }
127
- }
128
- async function readTsConfig(filePath) {
129
- const content = await readFile(filePath);
130
- return parseJsonc(content, filePath);
131
- }
132
- function getCompilerOptions(tsconfig) {
133
- if (!tsconfig.compilerOptions) {
134
- tsconfig.compilerOptions = {};
135
- }
136
- if (!isRecord(tsconfig.compilerOptions)) {
137
- throw new Error("Invalid tsconfig: compilerOptions must be an object.");
138
- }
139
- return tsconfig.compilerOptions;
140
- }
141
- function getPaths(compilerOptions) {
142
- if (!compilerOptions.paths) {
143
- compilerOptions.paths = {};
144
- }
145
- if (!isRecord(compilerOptions.paths)) {
146
- throw new Error("Invalid tsconfig: compilerOptions.paths must be an object.");
147
- }
148
- return compilerOptions.paths;
149
- }
150
- function computeAliasTarget(baseUrl, projectInfo) {
151
- const normalizedBaseUrl = normalizePathSegment(baseUrl);
152
- const aliasRoot = projectInfo.srcDir ? "src" : ".";
153
- if (normalizedBaseUrl === ".") {
154
- return aliasRoot === "." ? "./*" : `${aliasRoot}/*`;
155
- }
156
- const targetRoot = aliasRoot === "." ? "." : aliasRoot;
157
- const relative = path.posix.relative(normalizedBaseUrl, targetRoot);
158
- if (relative === "" || relative === ".") {
159
- return "*";
160
- }
161
- return `${relative}/*`;
162
- }
163
- function isLikelyAppConfig(tsconfig) {
164
- if (Array.isArray(tsconfig.include)) {
165
- const hasSrc = tsconfig.include.some((value) => typeof value === "string" && value.includes("src"));
166
- if (hasSrc) {
167
- return true;
168
- }
169
- }
170
- if (Array.isArray(tsconfig.files)) {
171
- const hasSrc = tsconfig.files.some((value) => typeof value === "string" && value.includes("src"));
172
- if (hasSrc) {
173
- return true;
174
- }
175
- }
176
- return Boolean(tsconfig.compilerOptions &&
177
- typeof tsconfig.compilerOptions.jsx === "string");
178
- }
179
- async function resolveReferencePaths(cwd, references) {
180
- const resolved = [];
181
- for (const reference of references) {
182
- if (!reference.path) {
183
- continue;
184
- }
185
- const referencePath = path.resolve(cwd, reference.path);
186
- if (await fileExists(referencePath)) {
187
- resolved.push(referencePath);
188
- continue;
189
- }
190
- if (await directoryExists(referencePath)) {
191
- const configPath = path.join(referencePath, "tsconfig.json");
192
- if (await fileExists(configPath)) {
193
- resolved.push(configPath);
194
- }
195
- continue;
196
- }
197
- if (!referencePath.endsWith(".json")) {
198
- const jsonPath = `${referencePath}.json`;
199
- if (await fileExists(jsonPath)) {
200
- resolved.push(jsonPath);
201
- }
202
- }
203
- }
204
- return resolved;
205
- }
206
- async function resolveTsConfigTargets(cwd) {
207
- const rootPath = path.join(cwd, "tsconfig.json");
208
- if (!(await fileExists(rootPath))) {
209
- return [];
210
- }
211
- const rootConfig = await readTsConfig(rootPath);
212
- const references = Array.isArray(rootConfig.references)
213
- ? rootConfig.references
214
- : [];
215
- if (references.length === 0) {
216
- return [rootPath];
217
- }
218
- const referencePaths = await resolveReferencePaths(cwd, references);
219
- if (referencePaths.length === 0) {
220
- return [];
221
- }
222
- const appConfigPaths = [];
223
- for (const referencePath of referencePaths) {
224
- const referenceConfig = await readTsConfig(referencePath);
225
- if (isLikelyAppConfig(referenceConfig)) {
226
- appConfigPaths.push(referencePath);
227
- }
228
- }
229
- return appConfigPaths.length > 0 ? appConfigPaths : referencePaths;
230
- }
231
- async function updateTsConfigFile(filePath, projectInfo) {
232
- const content = await readFile(filePath);
233
- const tsconfig = parseJsonc(content, filePath);
234
- const compilerOptions = getCompilerOptions(tsconfig);
235
- const baseUrlValue = typeof compilerOptions.baseUrl === "string"
236
- ? compilerOptions.baseUrl.trim()
237
- : "";
238
- const effectiveBaseUrl = baseUrlValue.length > 0 ? baseUrlValue : ".";
239
- let didChange = false;
240
- if (!compilerOptions.baseUrl || baseUrlValue.length === 0) {
241
- compilerOptions.baseUrl = effectiveBaseUrl;
242
- didChange = true;
243
- }
244
- const paths = getPaths(compilerOptions);
245
- const existingAlias = paths["@/*"];
246
- if (existingAlias === undefined) {
247
- const aliasTarget = computeAliasTarget(effectiveBaseUrl, projectInfo);
248
- paths["@/*"] = [aliasTarget];
249
- didChange = true;
250
- }
251
- else if (!Array.isArray(existingAlias) ||
252
- existingAlias.some((value) => typeof value !== "string")) {
253
- throw new Error(`Invalid tsconfig: compilerOptions.paths["@/*"] must be an array of strings in ${path.basename(filePath)}`);
254
- }
255
- if (didChange) {
256
- const nextContent = JSON.stringify(tsconfig, null, 2) + "\n";
257
- await writeFile(filePath, nextContent);
258
- }
259
- return didChange;
260
- }
261
- export async function setupTypeScriptPaths(cwd, projectInfo) {
262
- if (!projectInfo.typescript) {
263
- return;
264
- }
265
- const targets = await resolveTsConfigTargets(cwd);
266
- if (targets.length === 0) {
267
- throw new Error("No tsconfig files found for TypeScript path alias setup.");
268
- }
269
- const uniqueTargets = Array.from(new Set(targets));
270
- for (const target of uniqueTargets) {
271
- await updateTsConfigFile(target, projectInfo);
272
- }
273
- }
1
+ import path from "node:path";
2
+ import { directoryExists, fileExists, readFile, writeFile } from "../../lib/fs.js";
3
+ function isRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ function normalizePathSegment(value) {
7
+ const normalized = path.posix
8
+ .normalize(value.replace(/\\/g, "/").trim())
9
+ .replace(/\/+$/, "");
10
+ return normalized.length > 0 ? normalized : ".";
11
+ }
12
+ function isEscaped(input, index) {
13
+ let slashCount = 0;
14
+ for (let i = index - 1; i >= 0 && input[i] === "\\"; i -= 1) {
15
+ slashCount += 1;
16
+ }
17
+ return slashCount % 2 === 1;
18
+ }
19
+ function findNextMeaningfulChar(input, startIndex) {
20
+ let index = startIndex;
21
+ while (index < input.length) {
22
+ const char = input[index];
23
+ const next = input[index + 1];
24
+ if (char === " " || char === "\t" || char === "\n" || char === "\r") {
25
+ index += 1;
26
+ continue;
27
+ }
28
+ if (char === "/" && next === "/") {
29
+ index += 2;
30
+ while (index < input.length &&
31
+ input[index] !== "\n" &&
32
+ input[index] !== "\r") {
33
+ index += 1;
34
+ }
35
+ continue;
36
+ }
37
+ if (char === "/" && next === "*") {
38
+ index += 2;
39
+ while (index < input.length) {
40
+ if (input[index] === "*" && input[index + 1] === "/") {
41
+ index += 2;
42
+ break;
43
+ }
44
+ index += 1;
45
+ }
46
+ continue;
47
+ }
48
+ return char;
49
+ }
50
+ return "";
51
+ }
52
+ function sanitizeJsonc(input) {
53
+ let output = "";
54
+ let index = 0;
55
+ let inString = false;
56
+ let inLineComment = false;
57
+ let inBlockComment = false;
58
+ while (index < input.length) {
59
+ const char = input[index];
60
+ const next = input[index + 1];
61
+ if (inLineComment) {
62
+ if (char === "\n" || char === "\r") {
63
+ inLineComment = false;
64
+ output += char;
65
+ }
66
+ index += 1;
67
+ continue;
68
+ }
69
+ if (inBlockComment) {
70
+ if (char === "*" && next === "/") {
71
+ inBlockComment = false;
72
+ index += 2;
73
+ continue;
74
+ }
75
+ index += 1;
76
+ continue;
77
+ }
78
+ if (inString) {
79
+ output += char;
80
+ if (char === "\"" && !isEscaped(input, index)) {
81
+ inString = false;
82
+ }
83
+ index += 1;
84
+ continue;
85
+ }
86
+ if (char === "\"") {
87
+ inString = true;
88
+ output += char;
89
+ index += 1;
90
+ continue;
91
+ }
92
+ if (char === "/" && next === "/") {
93
+ inLineComment = true;
94
+ index += 2;
95
+ continue;
96
+ }
97
+ if (char === "/" && next === "*") {
98
+ inBlockComment = true;
99
+ index += 2;
100
+ continue;
101
+ }
102
+ if (char === ",") {
103
+ const nextMeaningful = findNextMeaningfulChar(input, index + 1);
104
+ if (nextMeaningful === "}" || nextMeaningful === "]") {
105
+ index += 1;
106
+ continue;
107
+ }
108
+ }
109
+ output += char;
110
+ index += 1;
111
+ }
112
+ return output;
113
+ }
114
+ function parseJsonc(content, filePath) {
115
+ try {
116
+ const sanitized = sanitizeJsonc(content);
117
+ const parsed = JSON.parse(sanitized);
118
+ if (!isRecord(parsed)) {
119
+ throw new Error("Root value must be an object");
120
+ }
121
+ return parsed;
122
+ }
123
+ catch (error) {
124
+ const message = error instanceof Error ? error.message : "Unknown error";
125
+ throw new Error(`Invalid JSON in ${path.basename(filePath)}: ${message}`);
126
+ }
127
+ }
128
+ async function readTsConfig(filePath) {
129
+ const content = await readFile(filePath);
130
+ return parseJsonc(content, filePath);
131
+ }
132
+ function getCompilerOptions(tsconfig) {
133
+ if (!tsconfig.compilerOptions) {
134
+ tsconfig.compilerOptions = {};
135
+ }
136
+ if (!isRecord(tsconfig.compilerOptions)) {
137
+ throw new Error("Invalid tsconfig: compilerOptions must be an object.");
138
+ }
139
+ return tsconfig.compilerOptions;
140
+ }
141
+ function getPaths(compilerOptions) {
142
+ if (!compilerOptions.paths) {
143
+ compilerOptions.paths = {};
144
+ }
145
+ if (!isRecord(compilerOptions.paths)) {
146
+ throw new Error("Invalid tsconfig: compilerOptions.paths must be an object.");
147
+ }
148
+ return compilerOptions.paths;
149
+ }
150
+ function computeAliasTarget(baseUrl, projectInfo) {
151
+ const normalizedBaseUrl = normalizePathSegment(baseUrl);
152
+ const aliasRoot = projectInfo.srcDir ? "src" : ".";
153
+ if (normalizedBaseUrl === ".") {
154
+ return aliasRoot === "." ? "./*" : `${aliasRoot}/*`;
155
+ }
156
+ const targetRoot = aliasRoot === "." ? "." : aliasRoot;
157
+ const relative = path.posix.relative(normalizedBaseUrl, targetRoot);
158
+ if (relative === "" || relative === ".") {
159
+ return "*";
160
+ }
161
+ return `${relative}/*`;
162
+ }
163
+ function isLikelyAppConfig(tsconfig) {
164
+ if (Array.isArray(tsconfig.include)) {
165
+ const hasSrc = tsconfig.include.some((value) => typeof value === "string" && value.includes("src"));
166
+ if (hasSrc) {
167
+ return true;
168
+ }
169
+ }
170
+ if (Array.isArray(tsconfig.files)) {
171
+ const hasSrc = tsconfig.files.some((value) => typeof value === "string" && value.includes("src"));
172
+ if (hasSrc) {
173
+ return true;
174
+ }
175
+ }
176
+ return Boolean(tsconfig.compilerOptions &&
177
+ typeof tsconfig.compilerOptions.jsx === "string");
178
+ }
179
+ async function resolveReferencePaths(cwd, references) {
180
+ const resolved = [];
181
+ for (const reference of references) {
182
+ if (!reference.path) {
183
+ continue;
184
+ }
185
+ const referencePath = path.resolve(cwd, reference.path);
186
+ if (await fileExists(referencePath)) {
187
+ resolved.push(referencePath);
188
+ continue;
189
+ }
190
+ if (await directoryExists(referencePath)) {
191
+ const configPath = path.join(referencePath, "tsconfig.json");
192
+ if (await fileExists(configPath)) {
193
+ resolved.push(configPath);
194
+ }
195
+ continue;
196
+ }
197
+ if (!referencePath.endsWith(".json")) {
198
+ const jsonPath = `${referencePath}.json`;
199
+ if (await fileExists(jsonPath)) {
200
+ resolved.push(jsonPath);
201
+ }
202
+ }
203
+ }
204
+ return resolved;
205
+ }
206
+ async function resolveTsConfigTargets(cwd) {
207
+ const rootPath = path.join(cwd, "tsconfig.json");
208
+ if (!(await fileExists(rootPath))) {
209
+ return [];
210
+ }
211
+ const rootConfig = await readTsConfig(rootPath);
212
+ const references = Array.isArray(rootConfig.references)
213
+ ? rootConfig.references
214
+ : [];
215
+ if (references.length === 0) {
216
+ return [rootPath];
217
+ }
218
+ const referencePaths = await resolveReferencePaths(cwd, references);
219
+ if (referencePaths.length === 0) {
220
+ return [];
221
+ }
222
+ const appConfigPaths = [];
223
+ for (const referencePath of referencePaths) {
224
+ const referenceConfig = await readTsConfig(referencePath);
225
+ if (isLikelyAppConfig(referenceConfig)) {
226
+ appConfigPaths.push(referencePath);
227
+ }
228
+ }
229
+ return appConfigPaths.length > 0 ? appConfigPaths : referencePaths;
230
+ }
231
+ async function updateTsConfigFile(filePath, projectInfo) {
232
+ const content = await readFile(filePath);
233
+ const tsconfig = parseJsonc(content, filePath);
234
+ const compilerOptions = getCompilerOptions(tsconfig);
235
+ const baseUrlValue = typeof compilerOptions.baseUrl === "string"
236
+ ? compilerOptions.baseUrl.trim()
237
+ : "";
238
+ const effectiveBaseUrl = baseUrlValue.length > 0 ? baseUrlValue : ".";
239
+ let didChange = false;
240
+ if (!compilerOptions.baseUrl || baseUrlValue.length === 0) {
241
+ compilerOptions.baseUrl = effectiveBaseUrl;
242
+ didChange = true;
243
+ }
244
+ const paths = getPaths(compilerOptions);
245
+ const existingAlias = paths["@/*"];
246
+ if (existingAlias === undefined) {
247
+ const aliasTarget = computeAliasTarget(effectiveBaseUrl, projectInfo);
248
+ paths["@/*"] = [aliasTarget];
249
+ didChange = true;
250
+ }
251
+ else if (!Array.isArray(existingAlias) ||
252
+ existingAlias.some((value) => typeof value !== "string")) {
253
+ throw new Error(`Invalid tsconfig: compilerOptions.paths["@/*"] must be an array of strings in ${path.basename(filePath)}`);
254
+ }
255
+ if (didChange) {
256
+ const nextContent = JSON.stringify(tsconfig, null, 2) + "\n";
257
+ await writeFile(filePath, nextContent);
258
+ }
259
+ return didChange;
260
+ }
261
+ export async function setupTypeScriptPaths(cwd, projectInfo) {
262
+ if (!projectInfo.typescript) {
263
+ return;
264
+ }
265
+ const targets = await resolveTsConfigTargets(cwd);
266
+ if (targets.length === 0) {
267
+ throw new Error("No tsconfig files found for TypeScript path alias setup.");
268
+ }
269
+ const uniqueTargets = Array.from(new Set(targets));
270
+ for (const target of uniqueTargets) {
271
+ await updateTsConfigFile(target, projectInfo);
272
+ }
273
+ }
274
274
  //# sourceMappingURL=tsconfig.js.map