@codefast/cli 0.5.0-canary.5 → 0.5.0-canary.7

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 (274) hide show
  1. package/README.md +106 -480
  2. package/dist/arrange/analyze.js +25 -0
  3. package/dist/arrange/analyze.js.map +1 -0
  4. package/dist/arrange/cli-schema.js +29 -0
  5. package/dist/arrange/cli-schema.js.map +1 -0
  6. package/dist/arrange/command.js +170 -0
  7. package/dist/arrange/command.js.map +1 -0
  8. package/dist/arrange/domain/analyze-service.js +122 -0
  9. package/dist/arrange/domain/analyze-service.js.map +1 -0
  10. package/dist/arrange/domain/ast/ast-node.js +240 -0
  11. package/dist/arrange/domain/ast/ast-node.js.map +1 -0
  12. package/dist/arrange/domain/ast/collectors-cn.js +81 -0
  13. package/dist/arrange/domain/ast/collectors-cn.js.map +1 -0
  14. package/dist/arrange/domain/ast/collectors-jsx.js +24 -0
  15. package/dist/arrange/domain/ast/collectors-jsx.js.map +1 -0
  16. package/dist/arrange/domain/ast/collectors-tv.js +319 -0
  17. package/dist/arrange/domain/ast/collectors-tv.js.map +1 -0
  18. package/dist/arrange/domain/ast/helpers.js +151 -0
  19. package/dist/arrange/domain/ast/helpers.js.map +1 -0
  20. package/dist/arrange/domain/ast/simplify-targets.js +161 -0
  21. package/dist/arrange/domain/ast/simplify-targets.js.map +1 -0
  22. package/dist/arrange/domain/ast/targets.js +182 -0
  23. package/dist/arrange/domain/ast/targets.js.map +1 -0
  24. package/dist/arrange/domain/constants.js +225 -0
  25. package/dist/arrange/domain/constants.js.map +1 -0
  26. package/dist/arrange/domain/grouping-service.js +128 -0
  27. package/dist/arrange/domain/grouping-service.js.map +1 -0
  28. package/dist/arrange/domain/grouping.js +435 -0
  29. package/dist/arrange/domain/grouping.js.map +1 -0
  30. package/dist/arrange/domain/imports.js +160 -0
  31. package/dist/arrange/domain/imports.js.map +1 -0
  32. package/dist/arrange/domain/source-text-formatters.js +100 -0
  33. package/dist/arrange/domain/source-text-formatters.js.map +1 -0
  34. package/dist/arrange/domain/tailwind-token.js +50 -0
  35. package/dist/arrange/domain/tailwind-token.js.map +1 -0
  36. package/dist/arrange/domain/token-classifier.js +448 -0
  37. package/dist/arrange/domain/token-classifier.js.map +1 -0
  38. package/dist/arrange/domain/types.js +11 -0
  39. package/dist/arrange/domain/types.js.map +1 -0
  40. package/dist/arrange/output.js +120 -0
  41. package/dist/arrange/output.js.map +1 -0
  42. package/dist/arrange/process-file.js +44 -0
  43. package/dist/arrange/process-file.js.map +1 -0
  44. package/dist/arrange/resolve-target.js +33 -0
  45. package/dist/arrange/resolve-target.js.map +1 -0
  46. package/dist/arrange/scan-target.js +30 -0
  47. package/dist/arrange/scan-target.js.map +1 -0
  48. package/dist/arrange/simplify-process-file.js +29 -0
  49. package/dist/arrange/simplify-process-file.js.map +1 -0
  50. package/dist/arrange/simplify-sync.js +29 -0
  51. package/dist/arrange/simplify-sync.js.map +1 -0
  52. package/dist/arrange/source-parse.js +17 -0
  53. package/dist/arrange/source-parse.js.map +1 -0
  54. package/dist/arrange/suggest.js +14 -0
  55. package/dist/arrange/suggest.js.map +1 -0
  56. package/dist/arrange/sync.js +48 -0
  57. package/dist/arrange/sync.js.map +1 -0
  58. package/dist/arrange/typescript-ast-translator.js +455 -0
  59. package/dist/arrange/typescript-ast-translator.js.map +1 -0
  60. package/dist/arrange/workspace.js +31 -0
  61. package/dist/arrange/workspace.js.map +1 -0
  62. package/dist/audit/cli-schema.js +22 -0
  63. package/dist/audit/cli-schema.js.map +1 -0
  64. package/dist/audit/command.js +60 -0
  65. package/dist/audit/command.js.map +1 -0
  66. package/dist/audit/domain/audit-file.js +101 -0
  67. package/dist/audit/domain/audit-file.js.map +1 -0
  68. package/dist/audit/domain/mappings.js +103 -0
  69. package/dist/audit/domain/mappings.js.map +1 -0
  70. package/dist/audit/domain/tokenize.js +83 -0
  71. package/dist/audit/domain/tokenize.js.map +1 -0
  72. package/dist/audit/domain/types.js +2 -0
  73. package/dist/audit/domain/types.js.map +1 -0
  74. package/dist/audit/output.js +44 -0
  75. package/dist/audit/output.js.map +1 -0
  76. package/dist/audit/prepare.js +42 -0
  77. package/dist/audit/prepare.js.map +1 -0
  78. package/dist/audit/run.js +57 -0
  79. package/dist/audit/run.js.map +1 -0
  80. package/dist/{bin.mjs → bin.js} +2 -4
  81. package/dist/bin.js.map +1 -0
  82. package/dist/cli.js +45 -0
  83. package/dist/cli.js.map +1 -0
  84. package/dist/core/cli/format-error.js +19 -0
  85. package/dist/core/cli/format-error.js.map +1 -0
  86. package/dist/core/cli/global-options.js +10 -0
  87. package/dist/core/cli/global-options.js.map +1 -0
  88. package/dist/core/cli/positional.js +9 -0
  89. package/dist/core/cli/positional.js.map +1 -0
  90. package/dist/core/cli/result-handle.js +69 -0
  91. package/dist/core/cli/result-handle.js.map +1 -0
  92. package/dist/core/config/loader.js +88 -0
  93. package/dist/core/config/loader.js.map +1 -0
  94. package/dist/core/config/schema.js +97 -0
  95. package/dist/core/config/schema.js.map +1 -0
  96. package/dist/core/config/warnings.js +12 -0
  97. package/dist/core/config/warnings.js.map +1 -0
  98. package/dist/core/config.js +18 -0
  99. package/dist/core/config.js.map +1 -0
  100. package/dist/core/errors.js +58 -0
  101. package/dist/core/errors.js.map +1 -0
  102. package/dist/core/exit-codes.js +15 -0
  103. package/dist/core/exit-codes.js.map +1 -0
  104. package/dist/core/filesystem/node.js +33 -0
  105. package/dist/core/filesystem/node.js.map +1 -0
  106. package/dist/core/filesystem/port.js +2 -0
  107. package/dist/core/filesystem/port.js.map +1 -0
  108. package/dist/core/glob.js +20 -0
  109. package/dist/core/glob.js.map +1 -0
  110. package/dist/core/logger.js +13 -0
  111. package/dist/core/logger.js.map +1 -0
  112. package/dist/core/result.js +16 -0
  113. package/dist/core/result.js.map +1 -0
  114. package/dist/core/schema-parse.js +21 -0
  115. package/dist/core/schema-parse.js.map +1 -0
  116. package/dist/core/source-text-edit.js +62 -0
  117. package/dist/core/source-text-edit.js.map +1 -0
  118. package/dist/core/verbose-diagnostics.js +9 -0
  119. package/dist/core/verbose-diagnostics.js.map +1 -0
  120. package/dist/core/workspace/resolver.js +208 -0
  121. package/dist/core/workspace/resolver.js.map +1 -0
  122. package/dist/core/workspace/typescript-walk.js +41 -0
  123. package/dist/core/workspace/typescript-walk.js.map +1 -0
  124. package/dist/mirror/cli-result.js +20 -0
  125. package/dist/mirror/cli-result.js.map +1 -0
  126. package/dist/mirror/cli-schema.js +11 -0
  127. package/dist/mirror/cli-schema.js.map +1 -0
  128. package/dist/mirror/command.js +73 -0
  129. package/dist/mirror/command.js.map +1 -0
  130. package/dist/mirror/dist-filesystem-impl.js +53 -0
  131. package/dist/mirror/dist-filesystem-impl.js.map +1 -0
  132. package/dist/mirror/domain/constants.js +21 -0
  133. package/dist/mirror/domain/constants.js.map +1 -0
  134. package/dist/mirror/domain/dirent-guard.js +16 -0
  135. package/dist/mirror/domain/dirent-guard.js.map +1 -0
  136. package/dist/mirror/domain/dist-filesystem.js +2 -0
  137. package/dist/mirror/domain/dist-filesystem.js.map +1 -0
  138. package/dist/mirror/domain/errors.js +19 -0
  139. package/dist/mirror/domain/errors.js.map +1 -0
  140. package/dist/mirror/domain/exports.js +284 -0
  141. package/dist/mirror/domain/exports.js.map +1 -0
  142. package/dist/mirror/domain/package-display-name.js +10 -0
  143. package/dist/mirror/domain/package-display-name.js.map +1 -0
  144. package/dist/mirror/domain/path-normalizer.js +8 -0
  145. package/dist/mirror/domain/path-normalizer.js.map +1 -0
  146. package/dist/mirror/domain/types.js +2 -0
  147. package/dist/mirror/domain/types.js.map +1 -0
  148. package/dist/mirror/output.js +47 -0
  149. package/dist/mirror/output.js.map +1 -0
  150. package/dist/mirror/package-path.js +40 -0
  151. package/dist/mirror/package-path.js.map +1 -0
  152. package/dist/mirror/prepare.js +37 -0
  153. package/dist/mirror/prepare.js.map +1 -0
  154. package/dist/mirror/supplement-exports.js +157 -0
  155. package/dist/mirror/supplement-exports.js.map +1 -0
  156. package/dist/mirror/sync-reporter.js +125 -0
  157. package/dist/mirror/sync-reporter.js.map +1 -0
  158. package/dist/mirror/sync-types.js +2 -0
  159. package/dist/mirror/sync-types.js.map +1 -0
  160. package/dist/mirror/sync-workspace-package.js +117 -0
  161. package/dist/mirror/sync-workspace-package.js.map +1 -0
  162. package/dist/mirror/sync.js +90 -0
  163. package/dist/mirror/sync.js.map +1 -0
  164. package/dist/mirror/write-exports.js +145 -0
  165. package/dist/mirror/write-exports.js.map +1 -0
  166. package/dist/tag/cli-result.js +12 -0
  167. package/dist/tag/cli-result.js.map +1 -0
  168. package/dist/tag/cli-schema.js +13 -0
  169. package/dist/tag/cli-schema.js.map +1 -0
  170. package/dist/tag/command.js +69 -0
  171. package/dist/tag/command.js.map +1 -0
  172. package/dist/tag/domain/types.js +2 -0
  173. package/dist/tag/domain/types.js.map +1 -0
  174. package/dist/tag/output.js +101 -0
  175. package/dist/tag/output.js.map +1 -0
  176. package/dist/tag/prepare.js +30 -0
  177. package/dist/tag/prepare.js.map +1 -0
  178. package/dist/tag/resolve-target-path.js +14 -0
  179. package/dist/tag/resolve-target-path.js.map +1 -0
  180. package/dist/tag/since-writer.js +231 -0
  181. package/dist/tag/since-writer.js.map +1 -0
  182. package/dist/tag/sync.js +166 -0
  183. package/dist/tag/sync.js.map +1 -0
  184. package/dist/tag/target-candidates.js +79 -0
  185. package/dist/tag/target-candidates.js.map +1 -0
  186. package/dist/tag/target-runner.js +25 -0
  187. package/dist/tag/target-runner.js.map +1 -0
  188. package/dist/tag/version-resolver.js +28 -0
  189. package/dist/tag/version-resolver.js.map +1 -0
  190. package/package.json +25 -20
  191. package/dist/arrange/analyze.mjs +0 -24
  192. package/dist/arrange/cli-schema.mjs +0 -27
  193. package/dist/arrange/command.mjs +0 -130
  194. package/dist/arrange/domain/analyze-service.mjs +0 -102
  195. package/dist/arrange/domain/ast/ast-node.mjs +0 -215
  196. package/dist/arrange/domain/ast/collectors-cn.mjs +0 -64
  197. package/dist/arrange/domain/ast/collectors-jsx.mjs +0 -23
  198. package/dist/arrange/domain/ast/collectors-tv.mjs +0 -189
  199. package/dist/arrange/domain/ast/helpers.mjs +0 -108
  200. package/dist/arrange/domain/ast/simplify-targets.mjs +0 -109
  201. package/dist/arrange/domain/ast/targets.mjs +0 -134
  202. package/dist/arrange/domain/constants.mjs +0 -213
  203. package/dist/arrange/domain/grouping-service.mjs +0 -121
  204. package/dist/arrange/domain/grouping.mjs +0 -338
  205. package/dist/arrange/domain/imports.mjs +0 -107
  206. package/dist/arrange/domain/source-text-formatters.mjs +0 -88
  207. package/dist/arrange/domain/tailwind-token.mjs +0 -40
  208. package/dist/arrange/domain/token-classifier.mjs +0 -218
  209. package/dist/arrange/domain/types.mjs +0 -1
  210. package/dist/arrange/output.mjs +0 -87
  211. package/dist/arrange/process-file.mjs +0 -42
  212. package/dist/arrange/resolve-target.mjs +0 -24
  213. package/dist/arrange/scan-target.mjs +0 -29
  214. package/dist/arrange/simplify-process-file.mjs +0 -35
  215. package/dist/arrange/simplify-sync.mjs +0 -32
  216. package/dist/arrange/source-parse.mjs +0 -18
  217. package/dist/arrange/suggest.mjs +0 -15
  218. package/dist/arrange/sync.mjs +0 -51
  219. package/dist/arrange/typescript-ast-translator.mjs +0 -354
  220. package/dist/arrange/workspace.mjs +0 -31
  221. package/dist/cli.mjs +0 -34
  222. package/dist/core/cli/format-error.mjs +0 -15
  223. package/dist/core/cli/global-options.mjs +0 -10
  224. package/dist/core/cli/positional.mjs +0 -11
  225. package/dist/core/cli/result-handle.mjs +0 -51
  226. package/dist/core/config/loader.mjs +0 -79
  227. package/dist/core/config/schema.mjs +0 -60
  228. package/dist/core/config/warnings.mjs +0 -12
  229. package/dist/core/config.mjs +0 -19
  230. package/dist/core/errors.mjs +0 -35
  231. package/dist/core/exit-codes.mjs +0 -17
  232. package/dist/core/filesystem/node.mjs +0 -32
  233. package/dist/core/filesystem/port.mjs +0 -1
  234. package/dist/core/glob.mjs +0 -20
  235. package/dist/core/logger.mjs +0 -15
  236. package/dist/core/result.mjs +0 -21
  237. package/dist/core/schema-parse.mjs +0 -18
  238. package/dist/core/source-text-edit.mjs +0 -56
  239. package/dist/core/verbose-diagnostics.mjs +0 -11
  240. package/dist/core/workspace/resolver.mjs +0 -177
  241. package/dist/core/workspace/typescript-walk.mjs +0 -36
  242. package/dist/mirror/cli-result.mjs +0 -22
  243. package/dist/mirror/cli-schema.mjs +0 -13
  244. package/dist/mirror/command.mjs +0 -58
  245. package/dist/mirror/dist-filesystem-impl.mjs +0 -42
  246. package/dist/mirror/domain/constants.mjs +0 -31
  247. package/dist/mirror/domain/dirent-guard.mjs +0 -16
  248. package/dist/mirror/domain/dist-filesystem.mjs +0 -1
  249. package/dist/mirror/domain/errors.mjs +0 -21
  250. package/dist/mirror/domain/exports.mjs +0 -226
  251. package/dist/mirror/domain/package-display-name.mjs +0 -12
  252. package/dist/mirror/domain/path-normalizer.mjs +0 -10
  253. package/dist/mirror/domain/types.mjs +0 -1
  254. package/dist/mirror/output.mjs +0 -48
  255. package/dist/mirror/package-path.mjs +0 -32
  256. package/dist/mirror/prepare.mjs +0 -33
  257. package/dist/mirror/supplement-exports.mjs +0 -114
  258. package/dist/mirror/sync-reporter.mjs +0 -107
  259. package/dist/mirror/sync-types.mjs +0 -1
  260. package/dist/mirror/sync-workspace-package.mjs +0 -109
  261. package/dist/mirror/sync.mjs +0 -88
  262. package/dist/mirror/write-exports.mjs +0 -94
  263. package/dist/tag/cli-result.mjs +0 -11
  264. package/dist/tag/cli-schema.mjs +0 -15
  265. package/dist/tag/command.mjs +0 -56
  266. package/dist/tag/domain/types.mjs +0 -1
  267. package/dist/tag/output.mjs +0 -87
  268. package/dist/tag/prepare.mjs +0 -29
  269. package/dist/tag/resolve-target-path.mjs +0 -12
  270. package/dist/tag/since-writer.mjs +0 -131
  271. package/dist/tag/sync.mjs +0 -149
  272. package/dist/tag/target-candidates.mjs +0 -68
  273. package/dist/tag/target-runner.mjs +0 -26
  274. package/dist/tag/version-resolver.mjs +0 -25
@@ -1,35 +0,0 @@
1
- //#region src/core/errors.ts
2
- /**
3
- * @since 0.3.16-canary.0
4
- */
5
- var AppError = class {
6
- name = "AppError";
7
- code;
8
- message;
9
- cause;
10
- constructor(code, message, cause) {
11
- this.code = code;
12
- this.message = message;
13
- if (cause !== void 0) this.cause = cause;
14
- }
15
- };
16
- /**
17
- * Stable, user-facing text for values caught as `unknown`.
18
- *
19
- * @since 0.3.16-canary.0
20
- */
21
- function messageFrom(value) {
22
- if (value instanceof Error) return value.message;
23
- if (typeof value === "string") return value;
24
- if (typeof value === "number" || typeof value === "bigint" || typeof value === "boolean") return String(value);
25
- if (typeof value === "symbol") return String(value);
26
- if (value === null) return "null";
27
- if (value === void 0) return "undefined";
28
- try {
29
- const serialized = JSON.stringify(value);
30
- if (typeof serialized === "string") return serialized;
31
- } catch {}
32
- return "[unserializable non-Error value]";
33
- }
34
- //#endregion
35
- export { AppError, messageFrom };
@@ -1,17 +0,0 @@
1
- //#region src/core/exit-codes.ts
2
- /**
3
- * Process exit codes for the `codefast` CLI.
4
- *
5
- * @since 0.3.16-canary.0
6
- */
7
- const CLI_EXIT_SUCCESS = 0;
8
- /**
9
- * @since 0.3.16-canary.0
10
- */
11
- const CLI_EXIT_GENERAL_ERROR = 1;
12
- /**
13
- * @since 0.3.16-canary.0
14
- */
15
- const CLI_EXIT_USAGE = 2;
16
- //#endregion
17
- export { CLI_EXIT_GENERAL_ERROR, CLI_EXIT_SUCCESS, CLI_EXIT_USAGE };
@@ -1,32 +0,0 @@
1
- import fsSync from "node:fs";
2
- import path from "node:path";
3
- import fsPromises from "node:fs/promises";
4
- //#region src/core/filesystem/node.ts
5
- /**
6
- * @since 0.3.16-canary.0
7
- */
8
- const nodeFilesystem = {
9
- existsSync: fsSync.existsSync,
10
- statSync: fsSync.statSync,
11
- readFileSync: fsSync.readFileSync,
12
- writeFileSync: fsSync.writeFileSync,
13
- readdirSync: fsSync.readdirSync,
14
- canonicalPathSync(inputPath) {
15
- try {
16
- return fsSync.realpathSync.native(inputPath);
17
- } catch {
18
- return path.resolve(inputPath);
19
- }
20
- },
21
- readFile: (filePath, enc) => fsPromises.readFile(filePath, enc),
22
- writeFile: (filePath, data, enc) => fsPromises.writeFile(filePath, data, enc),
23
- readdir: async (filePath, opts) => {
24
- const raw = await fsPromises.readdir(filePath, opts);
25
- if (!opts?.withFileTypes) return raw;
26
- return raw;
27
- },
28
- rename: (oldPath, newPath) => fsPromises.rename(oldPath, newPath),
29
- unlink: (filePath) => fsPromises.unlink(filePath)
30
- };
31
- //#endregion
32
- export { nodeFilesystem };
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- import picomatch from "picomatch";
2
- //#region src/core/glob.ts
3
- /**
4
- * Compile a list of glob patterns into a predicate that returns `true` when its
5
- * argument matches **any** of them (picomatch semantics). Returns a never-match
6
- * predicate when no patterns are supplied.
7
- *
8
- * Shared by every "match a name/path against a configured pattern list" use
9
- * (workspace excludes, `tag.skipPackages`, …) so the compile-then-`some` logic
10
- * lives in one place.
11
- *
12
- * @since 0.5.0-canary.0
13
- */
14
- function createAnyGlobMatcher(patterns, options) {
15
- if (!patterns || patterns.length === 0) return () => false;
16
- const matchers = patterns.map((pattern) => picomatch(pattern, options));
17
- return (value) => matchers.some((isMatch) => isMatch(value));
18
- }
19
- //#endregion
20
- export { createAnyGlobMatcher };
@@ -1,15 +0,0 @@
1
- import process from "node:process";
2
- //#region src/core/logger.ts
3
- /**
4
- * @since 0.3.16-canary.0
5
- */
6
- const logger = {
7
- out(line) {
8
- process.stdout.write(`${line}\n`);
9
- },
10
- err(line) {
11
- process.stderr.write(`${line}\n`);
12
- }
13
- };
14
- //#endregion
15
- export { logger };
@@ -1,21 +0,0 @@
1
- //#region src/core/result.ts
2
- /**
3
- * @since 0.3.16-canary.0
4
- */
5
- function ok(value) {
6
- return {
7
- ok: true,
8
- value
9
- };
10
- }
11
- /**
12
- * @since 0.3.16-canary.0
13
- */
14
- function err(error) {
15
- return {
16
- ok: false,
17
- error
18
- };
19
- }
20
- //#endregion
21
- export { err, ok };
@@ -1,18 +0,0 @@
1
- import { AppError } from "./errors.mjs";
2
- import { err, ok } from "./result.mjs";
3
- //#region src/core/schema-parse.ts
4
- function formatSchemaIssues(issues) {
5
- return issues.map((issue) => {
6
- return `${issue.path.length > 0 ? `${issue.path.join(".")}: ` : ""}${issue.message}`;
7
- }).join("; ");
8
- }
9
- /**
10
- * @since 0.3.16-canary.0
11
- */
12
- function parseWithSchema(schema, input) {
13
- const parsed = schema.safeParse(input);
14
- if (!parsed.success) return err(new AppError("VALIDATION_ERROR", formatSchemaIssues(parsed.error.issues)));
15
- return ok(parsed.data);
16
- }
17
- //#endregion
18
- export { parseWithSchema };
@@ -1,56 +0,0 @@
1
- //#region src/core/source-text-edit.ts
2
- function lineStartIndexContaining(source, pos) {
3
- const searchPos = Math.max(0, Math.min(pos, source.length));
4
- const prevLineBreak = Math.max(source.lastIndexOf("\n", searchPos - 1), source.lastIndexOf("\r", searchPos - 1));
5
- return prevLineBreak === -1 ? 0 : prevLineBreak + 1;
6
- }
7
- /**
8
- * @since 0.3.16-canary.0
9
- */
10
- function indentOfLineContaining(source, pos) {
11
- const lineStart = lineStartIndexContaining(source, pos);
12
- let lineEnd = source.length;
13
- for (let i = lineStart; i < source.length; i++) {
14
- const ch = source[i];
15
- if (ch === "\n" || ch === "\r") {
16
- lineEnd = i;
17
- break;
18
- }
19
- }
20
- const line = source.slice(lineStart, lineEnd);
21
- return /^[\t ]*/.exec(line)?.[0] ?? "";
22
- }
23
- /**
24
- * @since 0.3.16-canary.0
25
- */
26
- function textPrefixFromLineStartToPosition(source, pos) {
27
- const searchPos = Math.max(0, Math.min(pos, source.length));
28
- return source.slice(lineStartIndexContaining(source, searchPos), searchPos);
29
- }
30
- /**
31
- * @since 0.3.16-canary.0
32
- */
33
- function endAfterOptionalCommaFollowingInSource(source, tokenEnd) {
34
- let index = tokenEnd;
35
- while (index < source.length) {
36
- const ch = source[index];
37
- if (ch === " " || ch === " " || ch === "\n" || ch === "\r") {
38
- index += 1;
39
- continue;
40
- }
41
- if (ch === ",") return index + 1;
42
- break;
43
- }
44
- return tokenEnd;
45
- }
46
- /**
47
- * @since 0.3.16-canary.0
48
- */
49
- function applyEditsDescending(sourceText, edits) {
50
- const sorted = [...edits].toSorted((editA, editB) => editB.start - editA.start);
51
- let out = sourceText;
52
- for (const edit of sorted) out = out.slice(0, edit.start) + edit.replacement + out.slice(edit.end);
53
- return out;
54
- }
55
- //#endregion
56
- export { applyEditsDescending, endAfterOptionalCommaFollowingInSource, indentOfLineContaining, textPrefixFromLineStartToPosition };
@@ -1,11 +0,0 @@
1
- import process from "node:process";
2
- //#region src/core/verbose-diagnostics.ts
3
- /**
4
- * @since 0.3.16-canary.0
5
- */
6
- function isVerboseCliDiagnostics() {
7
- const raw = process.env.CODEFAST_VERBOSE;
8
- return raw === "1" || raw === "true";
9
- }
10
- //#endregion
11
- export { isVerboseCliDiagnostics };
@@ -1,177 +0,0 @@
1
- import { messageFrom } from "../errors.mjs";
2
- import { logger } from "../logger.mjs";
3
- import { createAnyGlobMatcher } from "../glob.mjs";
4
- import { globSync } from "node:fs";
5
- import path from "node:path";
6
- import { fileURLToPath } from "node:url";
7
- import { parse } from "yaml";
8
- //#region src/core/workspace/resolver.ts
9
- /**
10
- * Resolve the monorepo root (directory containing `pnpm-workspace.yaml`).
11
- *
12
- * @since 0.3.16-canary.0
13
- */
14
- function findRepoRoot(fromDirectory, fs) {
15
- const candidates = [path.dirname(fileURLToPath(import.meta.url)), fromDirectory];
16
- for (const start of candidates) {
17
- let dir = path.resolve(start);
18
- for (;;) {
19
- if (fs.existsSync(path.join(dir, "pnpm-workspace.yaml"))) return dir;
20
- const parent = path.dirname(dir);
21
- if (parent === dir) break;
22
- dir = parent;
23
- }
24
- }
25
- throw new Error(`Could not locate monorepo root (missing pnpm-workspace.yaml). Searched from: ${candidates.join(", ")}`);
26
- }
27
- const workspaceYamlFileName = "pnpm-workspace.yaml";
28
- const defaultIncludePatterns = ["packages/*"];
29
- const packageJsonFileName = "package.json";
30
- function toPosix(filePath) {
31
- return filePath.split(path.sep).join("/");
32
- }
33
- function isGlobPermissionError(caughtError) {
34
- if (typeof caughtError !== "object" || caughtError === null || !("code" in caughtError)) return false;
35
- const code = caughtError.code;
36
- return code === "EACCES" || code === "EPERM";
37
- }
38
- function workspacePatternToPackageJsonGlob(pattern) {
39
- const normalizedPattern = toPosix(pattern.trim()).replace(/\/+$/, "");
40
- if (!normalizedPattern) return `**/${packageJsonFileName}`;
41
- return `${normalizedPattern}/${packageJsonFileName}`;
42
- }
43
- function splitPnpmWorkspacePackagesArray(raw) {
44
- const include = [];
45
- const exclude = [];
46
- if (!Array.isArray(raw)) return {
47
- include,
48
- exclude
49
- };
50
- for (const entry of raw) {
51
- if (typeof entry !== "string") continue;
52
- const trimmed = entry.trim();
53
- if (!trimmed) continue;
54
- if (trimmed.startsWith("!")) exclude.push(trimmed.slice(1).trim());
55
- else include.push(trimmed);
56
- }
57
- return {
58
- include,
59
- exclude
60
- };
61
- }
62
- function parsePnpmWorkspaceDocument(doc) {
63
- const wf = workspaceYamlFileName;
64
- if (doc === null || doc === void 0) throw new Error(`${wf} root document must be an object (got empty or null)`);
65
- if (typeof doc !== "object" || Array.isArray(doc)) throw new Error(`${wf} root must be a mapping, not an array or scalar`);
66
- const parsedDoc = doc;
67
- if (!Object.prototype.hasOwnProperty.call(parsedDoc, "packages")) return {
68
- include: [],
69
- exclude: [],
70
- hasPackagesKey: false,
71
- isEmptyPackagesArray: false
72
- };
73
- const pkgs = parsedDoc.packages;
74
- if (!Array.isArray(pkgs)) throw new Error(`${wf} field "packages" must be an array`);
75
- if (pkgs.length === 0) return {
76
- include: [],
77
- exclude: [],
78
- hasPackagesKey: true,
79
- isEmptyPackagesArray: true
80
- };
81
- return {
82
- ...splitPnpmWorkspacePackagesArray(pkgs),
83
- hasPackagesKey: true,
84
- isEmptyPackagesArray: false
85
- };
86
- }
87
- async function readWorkspaceYaml(rootDir, fs) {
88
- const wf = workspaceYamlFileName;
89
- const workspaceYamlPath = path.join(rootDir, wf);
90
- if (!fs.existsSync(workspaceYamlPath)) return { exists: false };
91
- let raw;
92
- try {
93
- raw = await fs.readFile(workspaceYamlPath, "utf8");
94
- } catch (caughtReadError) {
95
- throw new Error(`Failed to read ${wf}: ${messageFrom(caughtReadError)}`, { cause: caughtReadError });
96
- }
97
- let doc;
98
- try {
99
- doc = parse(raw);
100
- } catch (caughtYamlParseError) {
101
- throw new Error(`Failed to parse ${wf}: ${messageFrom(caughtYamlParseError)}`, { cause: caughtYamlParseError });
102
- }
103
- if (doc === null || doc === void 0) throw new Error(`${wf} must define a mapping at the document root`);
104
- return {
105
- exists: true,
106
- doc
107
- };
108
- }
109
- /**
110
- * @since 0.3.16-canary.0
111
- */
112
- async function listWorkspacePackageDirectories(rootDirectoryPathAbsolute, fs, suppressGlobPermissionDiagnostics) {
113
- const workspaceYaml = await readWorkspaceYaml(rootDirectoryPathAbsolute, fs);
114
- const defInc = defaultIncludePatterns;
115
- let include;
116
- let exclude;
117
- let layoutSource;
118
- const hasPnpmWorkspaceYamlFile = workspaceYaml.exists;
119
- if (!workspaceYaml.exists) {
120
- include = [...defInc];
121
- exclude = [];
122
- layoutSource = "default-patterns";
123
- } else {
124
- const parsed = parsePnpmWorkspaceDocument(workspaceYaml.doc);
125
- if (!parsed.hasPackagesKey) {
126
- include = [...defInc];
127
- exclude = [];
128
- layoutSource = "default-patterns";
129
- } else if (parsed.isEmptyPackagesArray) return {
130
- packageDirectoryPathsAbsolute: [],
131
- layoutSource: "declared-empty",
132
- hasPnpmWorkspaceYamlFile: true
133
- };
134
- else {
135
- include = parsed.include;
136
- exclude = parsed.exclude;
137
- layoutSource = "pnpm-workspace-yaml";
138
- }
139
- }
140
- const foundRelativePosixPackageRoots = /* @__PURE__ */ new Set();
141
- const globOpts = {
142
- cwd: rootDirectoryPathAbsolute,
143
- posix: true,
144
- ...path.sep === "\\" ? { windowsPathsNoEscape: true } : {}
145
- };
146
- for (const pattern of include) {
147
- const globPat = workspacePatternToPackageJsonGlob(pattern);
148
- let matches;
149
- try {
150
- matches = globSync(globPat, globOpts);
151
- } catch (caughtGlobError) {
152
- if (isGlobPermissionError(caughtGlobError)) {
153
- if (!suppressGlobPermissionDiagnostics) logger.out(`⚠ Skipping workspace glob "${pattern}" (${messageFrom(caughtGlobError)})`);
154
- continue;
155
- }
156
- throw new Error(`Invalid workspace glob "${pattern}": ${messageFrom(caughtGlobError)}`, { cause: caughtGlobError });
157
- }
158
- for (const matchedPath of matches) {
159
- const posix = toPosix(matchedPath);
160
- const suffix = `/${packageJsonFileName}`;
161
- if (!posix.endsWith(suffix)) continue;
162
- const rel = posix.slice(0, -suffix.length);
163
- if (!rel) continue;
164
- foundRelativePosixPackageRoots.add(rel);
165
- }
166
- }
167
- const isExcluded = createAnyGlobMatcher(exclude, { dot: true });
168
- const filteredRelative = [...foundRelativePosixPackageRoots].filter((rel) => !isExcluded(rel));
169
- filteredRelative.sort((a, b) => a.localeCompare(b));
170
- return {
171
- packageDirectoryPathsAbsolute: filteredRelative.map((rel) => path.resolve(rootDirectoryPathAbsolute, rel.split("/").join(path.sep))),
172
- layoutSource,
173
- hasPnpmWorkspaceYamlFile
174
- };
175
- }
176
- //#endregion
177
- export { findRepoRoot, listWorkspacePackageDirectories };
@@ -1,36 +0,0 @@
1
- import path from "node:path";
2
- //#region src/core/workspace/typescript-walk.ts
3
- const defaultSkipDirectoryNames = /* @__PURE__ */ new Set([
4
- "node_modules",
5
- "dist",
6
- ".git",
7
- ".turbo",
8
- ".next",
9
- ".cache",
10
- "out",
11
- "build",
12
- "coverage",
13
- ".vercel",
14
- ".output"
15
- ]);
16
- /**
17
- * @since 0.3.16-canary.0
18
- */
19
- function walkTsxFiles(rootDirectoryPath, fs) {
20
- const result = [];
21
- visitTsxPaths(result, rootDirectoryPath, fs);
22
- return result;
23
- }
24
- function visitTsxPaths(result, entryPath, fs) {
25
- if (fs.statSync(entryPath).isDirectory()) {
26
- for (const childName of fs.readdirSync(entryPath)) {
27
- if (defaultSkipDirectoryNames.has(childName)) continue;
28
- visitTsxPaths(result, path.join(entryPath, childName), fs);
29
- }
30
- return;
31
- }
32
- if (entryPath.endsWith(".d.ts")) return;
33
- if (entryPath.endsWith(".tsx") || entryPath.endsWith(".ts")) result.push(entryPath);
34
- }
35
- //#endregion
36
- export { walkTsxFiles };
@@ -1,22 +0,0 @@
1
- import "../core/exit-codes.mjs";
2
- //#region src/mirror/cli-result.ts
3
- /**
4
- * @since 0.3.16-canary.0
5
- */
6
- function exitCodeForMirrorSyncResult(stats) {
7
- return stats.packagesErrored > 0 ? 1 : 0;
8
- }
9
- /**
10
- * @since 0.3.16-canary.0
11
- */
12
- function formatMirrorSyncJsonOutput(stats, elapsedSeconds, write = true) {
13
- return JSON.stringify({
14
- schemaVersion: 1,
15
- ok: stats.packagesErrored === 0,
16
- write,
17
- elapsedSeconds,
18
- stats
19
- });
20
- }
21
- //#endregion
22
- export { exitCodeForMirrorSyncResult, formatMirrorSyncJsonOutput };
@@ -1,13 +0,0 @@
1
- import { z } from "zod";
2
- //#region src/mirror/cli-schema.ts
3
- /**
4
- * @since 0.3.16-canary.0
5
- */
6
- const mirrorSyncRunRequestSchema = z.object({
7
- rootDir: z.string().min(1),
8
- packageFilter: z.string().optional(),
9
- config: z.unknown().optional(),
10
- write: z.boolean().optional()
11
- });
12
- //#endregion
13
- export { mirrorSyncRunRequestSchema };
@@ -1,58 +0,0 @@
1
- import { logger } from "../core/logger.mjs";
2
- import { readOptionalPositionalArg } from "../core/cli/positional.mjs";
3
- import { consumeCliAppError } from "../core/cli/result-handle.mjs";
4
- import { nodeFilesystem } from "../core/filesystem/node.mjs";
5
- import { parseWithSchema } from "../core/schema-parse.mjs";
6
- import { globalCliCommanderOptionsSchema } from "../core/cli/global-options.mjs";
7
- import { exitCodeForMirrorSyncResult, formatMirrorSyncJsonOutput } from "./cli-result.mjs";
8
- import { mirrorSyncRunRequestSchema } from "./cli-schema.mjs";
9
- import { MirrorSyncProgressPresenter } from "./output.mjs";
10
- import { prepareMirrorSync } from "./prepare.mjs";
11
- import { runMirrorSync } from "./sync.mjs";
12
- import process from "node:process";
13
- import { Command } from "commander";
14
- //#region src/mirror/command.ts
15
- /**
16
- * @since 0.3.16-canary.0
17
- */
18
- function createMirrorCommand() {
19
- return new Command("mirror").description("Write package.json exports from dist/ for workspace packages").argument("[package]", "Optional package path relative to repo root (e.g. packages/ui)").option("--dry-run", "Report what would change without writing package.json", false).option("-v, --verbose", "Print extra diagnostics", false).option("--json", "Print one JSON summary on stdout (suppresses human progress)", false).action(async (packageArg, opts, command) => {
20
- const globalOptionsOutcome = parseWithSchema(globalCliCommanderOptionsSchema, command.optsWithGlobals?.() ?? command.opts());
21
- if (!consumeCliAppError(globalOptionsOutcome)) return;
22
- const prelude = await prepareMirrorSync(nodeFilesystem, {
23
- currentWorkingDirectory: process.cwd(),
24
- packageArg: readOptionalPositionalArg(packageArg),
25
- globals: globalOptionsOutcome.value
26
- });
27
- if (!consumeCliAppError(prelude)) return;
28
- const write = !opts.dryRun;
29
- const { rootDir, config, packageFilter } = prelude.value;
30
- const parsed = parseWithSchema(mirrorSyncRunRequestSchema, {
31
- rootDir,
32
- config: config.mirror ?? {},
33
- packageFilter,
34
- write
35
- });
36
- if (!consumeCliAppError(parsed)) return;
37
- const json = !!opts.json;
38
- const noColor = globalOptionsOutcome.value.color === false;
39
- const verbose = !!opts.verbose;
40
- const progressPresenter = new MirrorSyncProgressPresenter();
41
- const listener = json ? void 0 : progressPresenter;
42
- if (!json) progressPresenter.configure({
43
- noColor,
44
- verbose,
45
- dryRun: !write
46
- });
47
- const startTime = performance.now();
48
- const outcome = await runMirrorSync(nodeFilesystem, {
49
- ...parsed.value,
50
- listener
51
- });
52
- if (!consumeCliAppError(outcome)) return;
53
- if (json) logger.out(formatMirrorSyncJsonOutput(outcome.value, (performance.now() - startTime) / 1e3, write));
54
- process.exitCode = exitCodeForMirrorSyncResult(outcome.value);
55
- });
56
- }
57
- //#endregion
58
- export { createMirrorCommand };
@@ -1,42 +0,0 @@
1
- import { normalizePath } from "./domain/path-normalizer.mjs";
2
- import { isDirentList } from "./domain/dirent-guard.mjs";
3
- import path from "node:path";
4
- //#region src/mirror/dist-filesystem-impl.ts
5
- /**
6
- * @since 0.3.16-canary.0
7
- */
8
- function createMirrorDistFilesystem(fs) {
9
- return {
10
- async listRelativeFilesRecursively(dirPath) {
11
- try {
12
- const raw = await fs.readdir(dirPath, {
13
- recursive: true,
14
- withFileTypes: true
15
- });
16
- if (!isDirentList(raw)) return [];
17
- return raw.filter((dirent) => dirent.isFile()).map((dirent) => {
18
- const fullPath = path.join(dirent.parentPath, dirent.name);
19
- return normalizePath(path.relative(dirPath, fullPath));
20
- });
21
- } catch (caughtError) {
22
- if (isKnownReadDirError(caughtError)) return [];
23
- throw caughtError;
24
- }
25
- },
26
- async isDirectoryCssOnly(distDir, dirPath) {
27
- try {
28
- const raw = await fs.readdir(path.join(distDir, dirPath), { withFileTypes: true });
29
- if (!isDirentList(raw)) return false;
30
- if (raw.length === 0) return true;
31
- return raw.every((dirent) => dirent.isFile() && dirent.name.endsWith(".css"));
32
- } catch {
33
- return false;
34
- }
35
- }
36
- };
37
- }
38
- function isKnownReadDirError(caughtError) {
39
- return typeof caughtError === "object" && caughtError !== null && "code" in caughtError && (caughtError.code === "ENOENT" || caughtError.code === "EACCES");
40
- }
41
- //#endregion
42
- export { createMirrorDistFilesystem };
@@ -1,31 +0,0 @@
1
- //#region src/mirror/domain/constants.ts
2
- /**
3
- * @since 0.3.16-canary.0
4
- */
5
- const DIST_DIR = "dist";
6
- /**
7
- * @since 0.3.16-canary.0
8
- */
9
- const PACKAGE_JSON = "package.json";
10
- /**
11
- * @since 0.3.16-canary.0
12
- */
13
- const VALID_JS_EXTENSIONS = /* @__PURE__ */ new Set([
14
- ".js",
15
- ".mjs",
16
- ".cjs"
17
- ]);
18
- /**
19
- * @since 0.3.16-canary.0
20
- */
21
- const VALID_DTS_EXTENSIONS = /* @__PURE__ */ new Set([
22
- ".d.ts",
23
- ".d.mts",
24
- ".d.cts"
25
- ]);
26
- /**
27
- * @since 0.3.16-canary.0
28
- */
29
- const PACKAGE_JSON_EXPORT = "./package.json";
30
- //#endregion
31
- export { DIST_DIR, PACKAGE_JSON, PACKAGE_JSON_EXPORT, VALID_DTS_EXTENSIONS, VALID_JS_EXTENSIONS };
@@ -1,16 +0,0 @@
1
- //#region src/mirror/domain/dirent-guard.ts
2
- /**
3
- * Narrow `fs.promises.readdir` overload result to `Dirent[]` when `withFileTypes: true`.
4
- * Accepts both historical checks (`isFile` / `isDirectory`) in one guard.
5
- * Returning `true` for an empty array is intentional: callers treat empty lists
6
- * the same regardless of the element type, so `[]` is safely accepted as `Dirent[]`.
7
- *
8
- * @since 0.3.16-canary.0
9
- */
10
- function isDirentList(x) {
11
- if (x.length === 0) return true;
12
- const first = x[0];
13
- return typeof first === "object" && first !== null && "isFile" in first && "isDirectory" in first;
14
- }
15
- //#endregion
16
- export { isDirentList };
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- //#region src/mirror/domain/errors.ts
2
- /**
3
- * @since 0.3.16-canary.0
4
- */
5
- const MirrorErrorCode = {
6
- FATAL: "FATAL",
7
- PACKAGE_WRITE: "PACKAGE_WRITE"
8
- };
9
- /**
10
- * @since 0.3.16-canary.0
11
- */
12
- var MirrorError = class extends Error {
13
- code;
14
- constructor(code, message, options) {
15
- super(message, options);
16
- this.name = "MirrorError";
17
- this.code = code;
18
- }
19
- };
20
- //#endregion
21
- export { MirrorError, MirrorErrorCode };