@fuzdev/gro 0.192.0

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 (323) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +283 -0
  3. package/dist/args.d.ts +37 -0
  4. package/dist/args.d.ts.map +1 -0
  5. package/dist/args.js +102 -0
  6. package/dist/build.task.d.ts +20 -0
  7. package/dist/build.task.d.ts.map +1 -0
  8. package/dist/build.task.js +119 -0
  9. package/dist/build_cache.d.ts +100 -0
  10. package/dist/build_cache.d.ts.map +1 -0
  11. package/dist/build_cache.js +299 -0
  12. package/dist/changelog.d.ts +11 -0
  13. package/dist/changelog.d.ts.map +1 -0
  14. package/dist/changelog.js +47 -0
  15. package/dist/changeset.task.d.ts +35 -0
  16. package/dist/changeset.task.d.ts.map +1 -0
  17. package/dist/changeset.task.js +151 -0
  18. package/dist/changeset_helpers.d.ts +17 -0
  19. package/dist/changeset_helpers.d.ts.map +1 -0
  20. package/dist/changeset_helpers.js +7 -0
  21. package/dist/check.task.d.ts +28 -0
  22. package/dist/check.task.d.ts.map +1 -0
  23. package/dist/check.task.js +104 -0
  24. package/dist/child_process_logging.d.ts +10 -0
  25. package/dist/child_process_logging.d.ts.map +1 -0
  26. package/dist/child_process_logging.js +26 -0
  27. package/dist/clean.task.d.ts +15 -0
  28. package/dist/clean.task.d.ts.map +1 -0
  29. package/dist/clean.task.js +40 -0
  30. package/dist/clean_fs.d.ts +9 -0
  31. package/dist/clean_fs.d.ts.map +1 -0
  32. package/dist/clean_fs.js +28 -0
  33. package/dist/cli.d.ts +34 -0
  34. package/dist/cli.d.ts.map +1 -0
  35. package/dist/cli.js +61 -0
  36. package/dist/commit.task.d.ts +11 -0
  37. package/dist/commit.task.d.ts.map +1 -0
  38. package/dist/commit.task.js +24 -0
  39. package/dist/constants.d.ts +46 -0
  40. package/dist/constants.d.ts.map +1 -0
  41. package/dist/constants.js +52 -0
  42. package/dist/deploy.task.d.ts +29 -0
  43. package/dist/deploy.task.d.ts.map +1 -0
  44. package/dist/deploy.task.js +217 -0
  45. package/dist/dev.task.d.ts +16 -0
  46. package/dist/dev.task.d.ts.map +1 -0
  47. package/dist/dev.task.js +44 -0
  48. package/dist/disknode.d.ts +23 -0
  49. package/dist/disknode.d.ts.map +1 -0
  50. package/dist/disknode.js +1 -0
  51. package/dist/env.d.ts +11 -0
  52. package/dist/env.d.ts.map +1 -0
  53. package/dist/env.js +49 -0
  54. package/dist/esbuild_helpers.d.ts +16 -0
  55. package/dist/esbuild_helpers.d.ts.map +1 -0
  56. package/dist/esbuild_helpers.js +36 -0
  57. package/dist/esbuild_plugin_external_worker.d.ts +23 -0
  58. package/dist/esbuild_plugin_external_worker.d.ts.map +1 -0
  59. package/dist/esbuild_plugin_external_worker.js +55 -0
  60. package/dist/esbuild_plugin_svelte.d.ts +15 -0
  61. package/dist/esbuild_plugin_svelte.d.ts.map +1 -0
  62. package/dist/esbuild_plugin_svelte.js +83 -0
  63. package/dist/esbuild_plugin_sveltekit_local_imports.d.ts +8 -0
  64. package/dist/esbuild_plugin_sveltekit_local_imports.d.ts.map +1 -0
  65. package/dist/esbuild_plugin_sveltekit_local_imports.js +30 -0
  66. package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +7 -0
  67. package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts.map +1 -0
  68. package/dist/esbuild_plugin_sveltekit_shim_alias.js +18 -0
  69. package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +9 -0
  70. package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -0
  71. package/dist/esbuild_plugin_sveltekit_shim_app.js +22 -0
  72. package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +11 -0
  73. package/dist/esbuild_plugin_sveltekit_shim_env.d.ts.map +1 -0
  74. package/dist/esbuild_plugin_sveltekit_shim_env.js +18 -0
  75. package/dist/filer.d.ts +33 -0
  76. package/dist/filer.d.ts.map +1 -0
  77. package/dist/filer.js +385 -0
  78. package/dist/format.task.d.ts +11 -0
  79. package/dist/format.task.d.ts.map +1 -0
  80. package/dist/format.task.js +27 -0
  81. package/dist/format_directory.d.ts +13 -0
  82. package/dist/format_directory.d.ts.map +1 -0
  83. package/dist/format_directory.js +40 -0
  84. package/dist/format_file.d.ts +9 -0
  85. package/dist/format_file.d.ts.map +1 -0
  86. package/dist/format_file.js +42 -0
  87. package/dist/gen.d.ts +142 -0
  88. package/dist/gen.d.ts.map +1 -0
  89. package/dist/gen.js +199 -0
  90. package/dist/gen.task.d.ts +12 -0
  91. package/dist/gen.task.d.ts.map +1 -0
  92. package/dist/gen.task.js +149 -0
  93. package/dist/gen_helpers.d.ts +11 -0
  94. package/dist/gen_helpers.d.ts.map +1 -0
  95. package/dist/gen_helpers.js +76 -0
  96. package/dist/github.d.ts +19 -0
  97. package/dist/github.d.ts.map +1 -0
  98. package/dist/github.js +33 -0
  99. package/dist/gro.config.default.d.ts +13 -0
  100. package/dist/gro.config.default.d.ts.map +1 -0
  101. package/dist/gro.config.default.js +33 -0
  102. package/dist/gro.d.ts +3 -0
  103. package/dist/gro.d.ts.map +1 -0
  104. package/dist/gro.js +21 -0
  105. package/dist/gro_config.d.ts +115 -0
  106. package/dist/gro_config.d.ts.map +1 -0
  107. package/dist/gro_config.js +114 -0
  108. package/dist/gro_helpers.d.ts +49 -0
  109. package/dist/gro_helpers.d.ts.map +1 -0
  110. package/dist/gro_helpers.js +97 -0
  111. package/dist/gro_plugin_gen.d.ts +12 -0
  112. package/dist/gro_plugin_gen.d.ts.map +1 -0
  113. package/dist/gro_plugin_gen.js +101 -0
  114. package/dist/gro_plugin_server.d.ts +80 -0
  115. package/dist/gro_plugin_server.d.ts.map +1 -0
  116. package/dist/gro_plugin_server.js +167 -0
  117. package/dist/gro_plugin_sveltekit_app.d.ts +9 -0
  118. package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -0
  119. package/dist/gro_plugin_sveltekit_app.js +42 -0
  120. package/dist/gro_plugin_sveltekit_library.d.ts +16 -0
  121. package/dist/gro_plugin_sveltekit_library.d.ts.map +1 -0
  122. package/dist/gro_plugin_sveltekit_library.js +34 -0
  123. package/dist/index.d.ts +9 -0
  124. package/dist/index.d.ts.map +1 -0
  125. package/dist/index.js +4 -0
  126. package/dist/input_path.d.ts +64 -0
  127. package/dist/input_path.d.ts.map +1 -0
  128. package/dist/input_path.js +199 -0
  129. package/dist/invoke.d.ts +2 -0
  130. package/dist/invoke.d.ts.map +1 -0
  131. package/dist/invoke.js +28 -0
  132. package/dist/invoke_task.d.ts +30 -0
  133. package/dist/invoke_task.d.ts.map +1 -0
  134. package/dist/invoke_task.js +104 -0
  135. package/dist/lint.task.d.ts +11 -0
  136. package/dist/lint.task.d.ts.map +1 -0
  137. package/dist/lint.task.js +32 -0
  138. package/dist/loader.d.ts +6 -0
  139. package/dist/loader.d.ts.map +1 -0
  140. package/dist/loader.js +192 -0
  141. package/dist/module.d.ts +4 -0
  142. package/dist/module.d.ts.map +1 -0
  143. package/dist/module.js +6 -0
  144. package/dist/modules.d.ts +36 -0
  145. package/dist/modules.d.ts.map +1 -0
  146. package/dist/modules.js +71 -0
  147. package/dist/package_json.d.ts +32 -0
  148. package/dist/package_json.d.ts.map +1 -0
  149. package/dist/package_json.js +178 -0
  150. package/dist/parse_exports.d.ts +20 -0
  151. package/dist/parse_exports.d.ts.map +1 -0
  152. package/dist/parse_exports.js +65 -0
  153. package/dist/parse_exports_context.d.ts +21 -0
  154. package/dist/parse_exports_context.d.ts.map +1 -0
  155. package/dist/parse_exports_context.js +332 -0
  156. package/dist/parse_imports.d.ts +5 -0
  157. package/dist/parse_imports.d.ts.map +1 -0
  158. package/dist/parse_imports.js +140 -0
  159. package/dist/paths.d.ts +41 -0
  160. package/dist/paths.d.ts.map +1 -0
  161. package/dist/paths.js +69 -0
  162. package/dist/plugin.d.ts +36 -0
  163. package/dist/plugin.d.ts.map +1 -0
  164. package/dist/plugin.js +78 -0
  165. package/dist/publish.task.d.ts +26 -0
  166. package/dist/publish.task.d.ts.map +1 -0
  167. package/dist/publish.task.js +176 -0
  168. package/dist/register.d.ts +2 -0
  169. package/dist/register.d.ts.map +1 -0
  170. package/dist/register.js +2 -0
  171. package/dist/reinstall.task.d.ts +8 -0
  172. package/dist/reinstall.task.d.ts.map +1 -0
  173. package/dist/reinstall.task.js +35 -0
  174. package/dist/release.task.d.ts +8 -0
  175. package/dist/release.task.d.ts.map +1 -0
  176. package/dist/release.task.js +20 -0
  177. package/dist/resolve.task.d.ts +11 -0
  178. package/dist/resolve.task.d.ts.map +1 -0
  179. package/dist/resolve.task.js +38 -0
  180. package/dist/resolve_specifier.d.ts +22 -0
  181. package/dist/resolve_specifier.d.ts.map +1 -0
  182. package/dist/resolve_specifier.js +57 -0
  183. package/dist/run.task.d.ts +16 -0
  184. package/dist/run.task.d.ts.map +1 -0
  185. package/dist/run.task.js +52 -0
  186. package/dist/run_gen.d.ts +10 -0
  187. package/dist/run_gen.d.ts.map +1 -0
  188. package/dist/run_gen.js +73 -0
  189. package/dist/run_task.d.ts +17 -0
  190. package/dist/run_task.d.ts.map +1 -0
  191. package/dist/run_task.js +45 -0
  192. package/dist/source_json.d.ts +7 -0
  193. package/dist/source_json.d.ts.map +1 -0
  194. package/dist/source_json.js +145 -0
  195. package/dist/svelte_config.d.ts +57 -0
  196. package/dist/svelte_config.d.ts.map +1 -0
  197. package/dist/svelte_config.js +81 -0
  198. package/dist/sveltekit_helpers.d.ts +75 -0
  199. package/dist/sveltekit_helpers.d.ts.map +1 -0
  200. package/dist/sveltekit_helpers.js +94 -0
  201. package/dist/sveltekit_shim_app.d.ts +11 -0
  202. package/dist/sveltekit_shim_app.d.ts.map +1 -0
  203. package/dist/sveltekit_shim_app.js +31 -0
  204. package/dist/sveltekit_shim_app_environment.d.ts +13 -0
  205. package/dist/sveltekit_shim_app_environment.d.ts.map +1 -0
  206. package/dist/sveltekit_shim_app_environment.js +14 -0
  207. package/dist/sveltekit_shim_app_forms.d.ts +5 -0
  208. package/dist/sveltekit_shim_app_forms.d.ts.map +1 -0
  209. package/dist/sveltekit_shim_app_forms.js +6 -0
  210. package/dist/sveltekit_shim_app_navigation.d.ts +10 -0
  211. package/dist/sveltekit_shim_app_navigation.d.ts.map +1 -0
  212. package/dist/sveltekit_shim_app_navigation.js +11 -0
  213. package/dist/sveltekit_shim_app_paths.d.ts +17 -0
  214. package/dist/sveltekit_shim_app_paths.d.ts.map +1 -0
  215. package/dist/sveltekit_shim_app_paths.js +10 -0
  216. package/dist/sveltekit_shim_app_state.d.ts +5 -0
  217. package/dist/sveltekit_shim_app_state.d.ts.map +1 -0
  218. package/dist/sveltekit_shim_app_state.js +26 -0
  219. package/dist/sveltekit_shim_env.d.ts +5 -0
  220. package/dist/sveltekit_shim_env.d.ts.map +1 -0
  221. package/dist/sveltekit_shim_env.js +23 -0
  222. package/dist/sync.task.d.ts +16 -0
  223. package/dist/sync.task.d.ts.map +1 -0
  224. package/dist/sync.task.js +39 -0
  225. package/dist/task.d.ts +98 -0
  226. package/dist/task.d.ts.map +1 -0
  227. package/dist/task.js +109 -0
  228. package/dist/task_logging.d.ts +6 -0
  229. package/dist/task_logging.d.ts.map +1 -0
  230. package/dist/task_logging.js +201 -0
  231. package/dist/test.task.d.ts +13 -0
  232. package/dist/test.task.d.ts.map +1 -0
  233. package/dist/test.task.js +53 -0
  234. package/dist/typecheck.task.d.ts +13 -0
  235. package/dist/typecheck.task.d.ts.map +1 -0
  236. package/dist/typecheck.task.js +68 -0
  237. package/dist/upgrade.task.d.ts +20 -0
  238. package/dist/upgrade.task.d.ts.map +1 -0
  239. package/dist/upgrade.task.js +111 -0
  240. package/dist/watch_dir.d.ts +36 -0
  241. package/dist/watch_dir.d.ts.map +1 -0
  242. package/dist/watch_dir.js +69 -0
  243. package/package.json +149 -0
  244. package/src/lib/args.ts +115 -0
  245. package/src/lib/build.task.ts +151 -0
  246. package/src/lib/build_cache.ts +378 -0
  247. package/src/lib/changelog.ts +69 -0
  248. package/src/lib/changeset.task.ts +228 -0
  249. package/src/lib/changeset_helpers.ts +14 -0
  250. package/src/lib/check.task.ts +132 -0
  251. package/src/lib/child_process_logging.ts +38 -0
  252. package/src/lib/clean.task.ts +48 -0
  253. package/src/lib/clean_fs.ts +54 -0
  254. package/src/lib/cli.ts +98 -0
  255. package/src/lib/commit.task.ts +34 -0
  256. package/src/lib/constants.ts +56 -0
  257. package/src/lib/deploy.task.ts +287 -0
  258. package/src/lib/dev.task.ts +52 -0
  259. package/src/lib/disknode.ts +26 -0
  260. package/src/lib/env.ts +78 -0
  261. package/src/lib/esbuild_helpers.ts +49 -0
  262. package/src/lib/esbuild_plugin_external_worker.ts +94 -0
  263. package/src/lib/esbuild_plugin_svelte.ts +134 -0
  264. package/src/lib/esbuild_plugin_sveltekit_local_imports.ts +38 -0
  265. package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +27 -0
  266. package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +42 -0
  267. package/src/lib/esbuild_plugin_sveltekit_shim_env.ts +47 -0
  268. package/src/lib/filer.ts +458 -0
  269. package/src/lib/format.task.ts +44 -0
  270. package/src/lib/format_directory.ts +65 -0
  271. package/src/lib/format_file.ts +49 -0
  272. package/src/lib/gen.task.ts +206 -0
  273. package/src/lib/gen.ts +406 -0
  274. package/src/lib/gen_helpers.ts +131 -0
  275. package/src/lib/github.ts +46 -0
  276. package/src/lib/gro.config.default.ts +42 -0
  277. package/src/lib/gro.ts +29 -0
  278. package/src/lib/gro_config.ts +254 -0
  279. package/src/lib/gro_helpers.ts +108 -0
  280. package/src/lib/gro_plugin_gen.ts +149 -0
  281. package/src/lib/gro_plugin_server.ts +288 -0
  282. package/src/lib/gro_plugin_sveltekit_app.ts +58 -0
  283. package/src/lib/gro_plugin_sveltekit_library.ts +63 -0
  284. package/src/lib/index.ts +8 -0
  285. package/src/lib/input_path.ts +254 -0
  286. package/src/lib/invoke.ts +34 -0
  287. package/src/lib/invoke_task.ts +139 -0
  288. package/src/lib/lint.task.ts +39 -0
  289. package/src/lib/loader.ts +229 -0
  290. package/src/lib/module.ts +13 -0
  291. package/src/lib/modules.ts +117 -0
  292. package/src/lib/package_json.ts +255 -0
  293. package/src/lib/parse_exports.ts +100 -0
  294. package/src/lib/parse_exports_context.ts +395 -0
  295. package/src/lib/parse_imports.ts +180 -0
  296. package/src/lib/paths.ts +111 -0
  297. package/src/lib/plugin.ts +106 -0
  298. package/src/lib/publish.task.ts +228 -0
  299. package/src/lib/register.ts +3 -0
  300. package/src/lib/reinstall.task.ts +45 -0
  301. package/src/lib/release.task.ts +26 -0
  302. package/src/lib/resolve.task.ts +43 -0
  303. package/src/lib/resolve_specifier.ts +81 -0
  304. package/src/lib/run.task.ts +65 -0
  305. package/src/lib/run_gen.ts +110 -0
  306. package/src/lib/run_task.ts +82 -0
  307. package/src/lib/source_json.ts +183 -0
  308. package/src/lib/svelte_config.ts +140 -0
  309. package/src/lib/sveltekit_helpers.ts +193 -0
  310. package/src/lib/sveltekit_shim_app.ts +41 -0
  311. package/src/lib/sveltekit_shim_app_environment.ts +16 -0
  312. package/src/lib/sveltekit_shim_app_forms.ts +13 -0
  313. package/src/lib/sveltekit_shim_app_navigation.ts +23 -0
  314. package/src/lib/sveltekit_shim_app_paths.ts +26 -0
  315. package/src/lib/sveltekit_shim_app_state.ts +35 -0
  316. package/src/lib/sveltekit_shim_env.ts +45 -0
  317. package/src/lib/sync.task.ts +47 -0
  318. package/src/lib/task.ts +245 -0
  319. package/src/lib/task_logging.ts +255 -0
  320. package/src/lib/test.task.ts +63 -0
  321. package/src/lib/typecheck.task.ts +81 -0
  322. package/src/lib/upgrade.task.ts +148 -0
  323. package/src/lib/watch_dir.ts +115 -0
@@ -0,0 +1,395 @@
1
+ import ts from 'typescript';
2
+ import type {Logger} from '@fuzdev/fuz_util/log.js';
3
+ import type {DeclarationKind} from '@fuzdev/fuz_util/source_json.js';
4
+
5
+ import type {ExportDeclaration} from './parse_exports.ts';
6
+
7
+ /**
8
+ * A class to track export context and determine export kinds.
9
+ */
10
+ export class ParseExportsContext {
11
+ readonly #checker: ts.TypeChecker;
12
+
13
+ // Map of source file paths to their symbols
14
+ readonly #file_symbols: Map<string, ts.Symbol> = new Map();
15
+ // Cache for resolved symbols to avoid repeated resolution
16
+ readonly #symbol_kind_cache: Map<ts.Symbol, DeclarationKind> = new Map();
17
+
18
+ readonly log: Logger | undefined;
19
+ debug = process.env.DEBUG_EXPORTS === 'true';
20
+
21
+ constructor(program: ts.Program, log?: Logger) {
22
+ this.log = log;
23
+ this.#checker = program.getTypeChecker();
24
+ }
25
+
26
+ /**
27
+ * Log a debug message if debug mode is enabled.
28
+ */
29
+ #log(...args: Array<unknown>): void {
30
+ if (this.debug && this.log) {
31
+ this.log.info(...args);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Analyze a source file to prepare for export processing.
37
+ */
38
+ analyze_source_file(source_file: ts.SourceFile): void {
39
+ const file_path = source_file.fileName;
40
+
41
+ // Skip if we've already analyzed this file
42
+ if (this.#file_symbols.has(file_path)) {
43
+ return;
44
+ }
45
+
46
+ // Get the source file symbol and cache it
47
+ const symbol = this.#checker.getSymbolAtLocation(source_file);
48
+ if (symbol) {
49
+ this.#file_symbols.set(file_path, symbol);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Process a list of exported symbols and identify their kinds.
55
+ */
56
+ process_exports(
57
+ source_file: ts.SourceFile,
58
+ exports: Array<ts.Symbol>,
59
+ declarations: Array<ExportDeclaration> = [],
60
+ ): Array<ExportDeclaration> {
61
+ for (const export_symbol of exports) {
62
+ const name = export_symbol.name;
63
+ this.#log(`Determining kind for export: ${name}`);
64
+
65
+ const kind = this.#determine_export_kind(source_file, export_symbol);
66
+ declarations.push({
67
+ name,
68
+ kind,
69
+ });
70
+ }
71
+
72
+ return declarations;
73
+ }
74
+
75
+ /**
76
+ * Determine the kind of an export based on its symbol.
77
+ */
78
+ #determine_export_kind(source_file: ts.SourceFile, symbol: ts.Symbol): DeclarationKind {
79
+ // Check if this is a type-only export (no value export)
80
+ if (this.#is_type_only_export(source_file, symbol)) {
81
+ return 'type';
82
+ }
83
+
84
+ // Get the true symbol by resolving aliases
85
+ const resolved_symbol = this.#resolve_symbol(symbol);
86
+
87
+ // Check if we've already determined this symbol's kind
88
+ if (this.#symbol_kind_cache.has(resolved_symbol)) {
89
+ return this.#symbol_kind_cache.get(resolved_symbol)!;
90
+ }
91
+
92
+ // Determine the kind based on declaration and type information
93
+ const kind = this.#infer_declaration_kind(resolved_symbol);
94
+
95
+ // Cache the result for future lookups
96
+ this.#symbol_kind_cache.set(resolved_symbol, kind);
97
+
98
+ return kind;
99
+ }
100
+
101
+ /**
102
+ * Resolve a symbol through aliases to its original declaration.
103
+ */
104
+ #resolve_symbol(symbol: ts.Symbol): ts.Symbol {
105
+ try {
106
+ if (symbol.flags & ts.SymbolFlags.Alias) {
107
+ return this.#checker.getAliasedSymbol(symbol);
108
+ }
109
+ } catch {
110
+ // If resolution fails, return the original symbol
111
+ }
112
+ return symbol;
113
+ }
114
+
115
+ /**
116
+ * Infer the declaration kind from a symbol's declaration and type information.
117
+ */
118
+ #infer_declaration_kind(symbol: ts.Symbol): DeclarationKind {
119
+ // Check symbol flags first for direct type matching
120
+ if (this.#is_class_symbol(symbol)) {
121
+ return 'class';
122
+ }
123
+
124
+ if (this.#is_function_symbol(symbol)) {
125
+ return 'function';
126
+ }
127
+
128
+ // If no direct match from flags, look at declarations
129
+ if (symbol.declarations && symbol.declarations.length > 0) {
130
+ const decl = symbol.declarations[0]!;
131
+ const kind_from_decl = this.#infer_kind_from_declaration(decl);
132
+ if (kind_from_decl) {
133
+ return kind_from_decl;
134
+ }
135
+ }
136
+
137
+ // Check for callable type as a fallback for functions
138
+ if (this.#is_callable(symbol)) {
139
+ return 'function';
140
+ }
141
+
142
+ // Default to variable if no other type can be determined
143
+ return 'variable';
144
+ }
145
+
146
+ /**
147
+ * Check if a symbol represents a callable type (function-like).
148
+ */
149
+ #is_callable(symbol: ts.Symbol): boolean {
150
+ try {
151
+ // Try to get valid declaration node
152
+ const declaration = this.#get_valid_declaration(symbol);
153
+ if (!declaration) {
154
+ return false;
155
+ }
156
+
157
+ // Get the type at the declaration location
158
+ const type = this.#checker.getTypeOfSymbolAtLocation(symbol, declaration);
159
+
160
+ // Check if the type has call signatures (making it function-like)
161
+ return type.getCallSignatures().length > 0;
162
+ } catch {
163
+ return false;
164
+ }
165
+ }
166
+
167
+ /**
168
+ * Get a valid declaration for a symbol, preferring valueDeclaration.
169
+ */
170
+ #get_valid_declaration(symbol: ts.Symbol): ts.Node | undefined {
171
+ if (symbol.valueDeclaration) {
172
+ return symbol.valueDeclaration;
173
+ }
174
+
175
+ if (symbol.declarations && symbol.declarations.length > 0) {
176
+ return symbol.declarations[0];
177
+ }
178
+
179
+ return undefined;
180
+ }
181
+
182
+ /**
183
+ * Infer the declaration kind from a specific declaration node.
184
+ */
185
+ #infer_kind_from_declaration(decl: ts.Declaration): DeclarationKind | null {
186
+ if (ts.isFunctionDeclaration(decl)) {
187
+ return 'function';
188
+ }
189
+
190
+ if (ts.isClassDeclaration(decl)) {
191
+ return 'class';
192
+ }
193
+
194
+ if (ts.isInterfaceDeclaration(decl) || ts.isTypeAliasDeclaration(decl)) {
195
+ return 'type';
196
+ }
197
+
198
+ if (ts.isVariableDeclaration(decl)) {
199
+ // Handle initializers for variable declarations
200
+ if (decl.initializer) {
201
+ if (ts.isFunctionExpression(decl.initializer) || ts.isArrowFunction(decl.initializer)) {
202
+ return 'function';
203
+ }
204
+
205
+ if (ts.isClassExpression(decl.initializer)) {
206
+ return 'class';
207
+ }
208
+
209
+ // Handle identifiers pointing to other declarations
210
+ if (ts.isIdentifier(decl.initializer)) {
211
+ try {
212
+ const referred_symbol = this.#checker.getSymbolAtLocation(decl.initializer);
213
+ if (referred_symbol) {
214
+ // Avoid infinite recursion by not resolving symbols here
215
+ if (this.#is_function_symbol(referred_symbol)) {
216
+ return 'function';
217
+ }
218
+ if (this.#is_class_symbol(referred_symbol)) {
219
+ return 'class';
220
+ }
221
+ }
222
+ } catch {
223
+ // Ignore failures to resolve identifiers
224
+ }
225
+ }
226
+ }
227
+
228
+ // As a fallback, check if the variable's type is callable
229
+ try {
230
+ const symbol = this.#checker.getSymbolAtLocation(decl.name);
231
+ if (symbol && this.#is_callable(symbol)) {
232
+ return 'function';
233
+ }
234
+ } catch {
235
+ // Ignore errors in type checking
236
+ }
237
+ }
238
+
239
+ return null;
240
+ }
241
+
242
+ /**
243
+ * Check if a symbol is exported as a type-only export.
244
+ * A type-only export means it's ONLY exported as a type with no value export.
245
+ */
246
+ #is_type_only_export(source_file: ts.SourceFile, symbol: ts.Symbol): boolean {
247
+ // First, check if the symbol has an explicit type-only export
248
+ let has_type_only_export = false;
249
+
250
+ // Check if it has a corresponding value export
251
+ const has_value_export = this.#has_value_export(source_file, symbol);
252
+
253
+ // If it has both type and value exports (dual purpose), it's not type-only
254
+ if (has_value_export) {
255
+ return false;
256
+ }
257
+
258
+ // Check export declarations for explicit type-only exports
259
+ ts.forEachChild(source_file, (node) => {
260
+ if (
261
+ ts.isExportDeclaration(node) &&
262
+ node.exportClause &&
263
+ ts.isNamedExports(node.exportClause)
264
+ ) {
265
+ // Check if it's a type-only export declaration (export type {...})
266
+ if (node.isTypeOnly) {
267
+ for (const specifier of node.exportClause.elements) {
268
+ if (specifier.name.text === symbol.name) {
269
+ has_type_only_export = true;
270
+ }
271
+ }
272
+ } else {
273
+ // Check if it's a specific type export (export {type X})
274
+ for (const specifier of node.exportClause.elements) {
275
+ if (specifier.name.text === symbol.name && specifier.isTypeOnly) {
276
+ has_type_only_export = true;
277
+ }
278
+ }
279
+ }
280
+ }
281
+ });
282
+
283
+ // If explicitly marked as a type-only export, use that
284
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
285
+ if (has_type_only_export) {
286
+ return true;
287
+ }
288
+
289
+ // If not explicitly marked as type-only, check if the symbol itself is a type
290
+ // AND there's no value export for it
291
+ const resolved_symbol = this.#resolve_symbol(symbol);
292
+ return this.#is_type_symbol(resolved_symbol) && !has_value_export;
293
+ }
294
+
295
+ /**
296
+ * Check if a symbol has a value export in the source file.
297
+ */
298
+ #has_value_export(source_file: ts.SourceFile, symbol: ts.Symbol): boolean {
299
+ let has_value_export = false;
300
+
301
+ // Check export declarations
302
+ ts.forEachChild(source_file, (node) => {
303
+ if (
304
+ ts.isExportDeclaration(node) &&
305
+ node.exportClause &&
306
+ ts.isNamedExports(node.exportClause)
307
+ ) {
308
+ // Skip type-only exports
309
+ if (node.isTypeOnly) return;
310
+
311
+ // Check if it's a regular export (not type-only)
312
+ for (const specifier of node.exportClause.elements) {
313
+ if (specifier.name.text === symbol.name && !specifier.isTypeOnly) {
314
+ has_value_export = true;
315
+ }
316
+ }
317
+ }
318
+ // Check for default export
319
+ else if (ts.isExportAssignment(node) && symbol.name === 'default') {
320
+ has_value_export = true;
321
+ }
322
+ // Check for direct exports (export const x = ...)
323
+ else if (this.#is_direct_export(node) && this.#get_export_name(node) === symbol.name) {
324
+ has_value_export = true;
325
+ }
326
+ });
327
+
328
+ return has_value_export;
329
+ }
330
+
331
+ /**
332
+ * Check if a node is a direct export (export const/function/class).
333
+ */
334
+ #is_direct_export(node: ts.Node): boolean {
335
+ return (
336
+ (ts.isVariableStatement(node) ||
337
+ ts.isFunctionDeclaration(node) ||
338
+ ts.isClassDeclaration(node)) &&
339
+ this.#has_export_modifier(node)
340
+ );
341
+ }
342
+
343
+ /**
344
+ * Get the export name from a direct export node.
345
+ */
346
+ #get_export_name(node: ts.Node): string | undefined {
347
+ if (ts.isVariableStatement(node) && node.declarationList.declarations.length > 0) {
348
+ const decl = node.declarationList.declarations[0]!;
349
+ if (ts.isIdentifier(decl.name)) {
350
+ return decl.name.text;
351
+ }
352
+ } else if (ts.isFunctionDeclaration(node) && node.name) {
353
+ return node.name.text;
354
+ } else if (ts.isClassDeclaration(node) && node.name) {
355
+ return node.name.text;
356
+ }
357
+ return undefined;
358
+ }
359
+
360
+ /**
361
+ * Check if a node has an export modifier.
362
+ */
363
+ #has_export_modifier(node: ts.Node): boolean {
364
+ return (
365
+ (ts.canHaveModifiers(node) &&
366
+ ts.getModifiers(node)?.some((mod) => mod.kind === ts.SyntaxKind.ExportKeyword)) ||
367
+ false
368
+ );
369
+ }
370
+
371
+ /**
372
+ * Check if a symbol is a function symbol.
373
+ */
374
+ #is_function_symbol(symbol: ts.Symbol): boolean {
375
+ return !!(symbol.flags & ts.SymbolFlags.Function || symbol.flags & ts.SymbolFlags.Method);
376
+ }
377
+
378
+ /**
379
+ * Check if a symbol is a class symbol.
380
+ */
381
+ #is_class_symbol(symbol: ts.Symbol): boolean {
382
+ return !!(symbol.flags & ts.SymbolFlags.Class);
383
+ }
384
+
385
+ /**
386
+ * Check if a symbol is a type-only symbol (interface, type alias, etc.).
387
+ */
388
+ #is_type_symbol(symbol: ts.Symbol): boolean {
389
+ return !!(
390
+ symbol.flags & ts.SymbolFlags.Interface ||
391
+ symbol.flags & ts.SymbolFlags.TypeAlias ||
392
+ symbol.flags & ts.SymbolFlags.TypeParameter
393
+ );
394
+ }
395
+ }
@@ -0,0 +1,180 @@
1
+ import {parseSync, type ImportDeclaration} from 'oxc-parser';
2
+ import type {Flavored} from '@fuzdev/fuz_util/types.js';
3
+ import {UnreachableError} from '@fuzdev/fuz_util/error.js';
4
+ import type {PathId} from '@fuzdev/fuz_util/path.js';
5
+
6
+ import {JS_MATCHER, TS_MATCHER, SVELTE_MATCHER, SVELTE_SCRIPT_MATCHER} from './constants.ts';
7
+
8
+ export type ImportSpecifier = Flavored<string, 'ImportSpecifier'>;
9
+
10
+ // TODO this is probably way more complicated that it should be, maybe report the issues upstream unless I made a mistake here
11
+
12
+ /**
13
+ * Extracts the string value from a module request, handling different quote styles.
14
+ * Returns null if the value is not a valid string literal.
15
+ */
16
+ const extract_string_literal = (content: string, start: number, end: number): string | null => {
17
+ const value = content.substring(start, end);
18
+
19
+ // Check if it's a string literal (starts and ends with quotes)
20
+ if (
21
+ (value.startsWith("'") && value.endsWith("'")) ||
22
+ (value.startsWith('"') && value.endsWith('"')) ||
23
+ (value.startsWith('`') && value.endsWith('`'))
24
+ ) {
25
+ // Remove the quotes
26
+ return value.slice(1, -1);
27
+ }
28
+
29
+ // Not a valid string literal
30
+ return null;
31
+ };
32
+
33
+ export const parse_imports = (
34
+ id: PathId,
35
+ contents: string,
36
+ ignore_types = true,
37
+ ): Array<ImportSpecifier> => {
38
+ const specifiers: Array<string> = [];
39
+ const is_svelte = SVELTE_MATCHER.test(id);
40
+
41
+ const parse_from = (s: string): void => {
42
+ const parsed = parseSync(is_svelte ? id + '.ts' : id, s, {});
43
+
44
+ // Process static imports
45
+ for (const static_import of parsed.module.staticImports) {
46
+ // Get the module source node
47
+ const import_decl = parsed.program.body.find(
48
+ (node) => node.type === 'ImportDeclaration' && node.start === static_import.start,
49
+ ) as ImportDeclaration | undefined;
50
+
51
+ if (!import_decl?.source) continue;
52
+
53
+ // Extract the module request string value
54
+ const value = extract_string_literal(s, import_decl.source.start, import_decl.source.end);
55
+
56
+ if (!value) continue;
57
+
58
+ // Skip type-only imports if ignore_types is true
59
+ if (ignore_types) {
60
+ // Handle import type {...} (type-only imports)
61
+ if (import_decl.importKind === 'type') {
62
+ continue;
63
+ }
64
+
65
+ // Handle inline type imports ({type foo})
66
+ if (static_import.entries.length > 0) {
67
+ // If all imports are type imports, skip this import
68
+ const has_non_type_specifier = static_import.entries.some((entry) => !entry.isType);
69
+ if (!has_non_type_specifier) {
70
+ continue;
71
+ }
72
+ }
73
+ }
74
+
75
+ specifiers.push(value);
76
+ }
77
+
78
+ // Process dynamic imports
79
+ for (const dynamic_import of parsed.module.dynamicImports) {
80
+ // Find the corresponding AST node
81
+ let found = false;
82
+ for (const node of parsed.program.body) {
83
+ if (
84
+ node.type === 'ExpressionStatement' &&
85
+ node.expression.type === 'AwaitExpression' &&
86
+ node.expression.argument.type === 'ImportExpression'
87
+ ) {
88
+ const import_expr = node.expression.argument;
89
+ if (import_expr.start === dynamic_import.start) {
90
+ // Only process string literals (not expressions or variables)
91
+ if (import_expr.source.type === 'Literal') {
92
+ const value = String(import_expr.source.value);
93
+ if (value) {
94
+ specifiers.push(value);
95
+ }
96
+ }
97
+ found = true;
98
+ break;
99
+ }
100
+ }
101
+ }
102
+
103
+ // If we didn't find a match through AST, fall back to the original approach
104
+ // but only for simple string literals
105
+ if (!found) {
106
+ const value = extract_string_literal(
107
+ s,
108
+ dynamic_import.moduleRequest.start,
109
+ dynamic_import.moduleRequest.end,
110
+ );
111
+ if (value) {
112
+ specifiers.push(value);
113
+ }
114
+ }
115
+ }
116
+
117
+ // Process re-exports
118
+ for (const node of parsed.program.body) {
119
+ if (node.type === 'ExportNamedDeclaration' && node.source) {
120
+ // Skip type-only exports if ignore_types is true
121
+ if (ignore_types && node.exportKind === 'type') {
122
+ continue;
123
+ }
124
+
125
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
126
+ if (node.source.type === 'Literal') {
127
+ const value = node.source.value;
128
+ if (value) {
129
+ specifiers.push(value);
130
+ }
131
+ } else {
132
+ throw new UnreachableError(node.source.type);
133
+ }
134
+ }
135
+ }
136
+ };
137
+
138
+ if (is_svelte) {
139
+ // Reset the regexp state between calls
140
+ SVELTE_SCRIPT_MATCHER.lastIndex = 0;
141
+
142
+ // Capture script tags at the top level (not nested in HTML)
143
+ let last_index = 0;
144
+ const script_blocks: Array<{content: string; start: number; end: number}> = [];
145
+
146
+ // First collect all script blocks
147
+ let match;
148
+ while ((match = SVELTE_SCRIPT_MATCHER.exec(contents)) !== null) {
149
+ // Save position of the script tag
150
+ const start = match.index;
151
+ const end = SVELTE_SCRIPT_MATCHER.lastIndex;
152
+
153
+ // Only process top-level script tags (skip nested ones)
154
+ // A nested script would be inside another HTML tag between lastIndex and start
155
+ const text_between = contents.substring(last_index, start);
156
+ const contains_opening_tag = /<[a-z][^>]*>/i.test(text_between);
157
+ const contains_closing_tag = /<\/[a-z][^>]*>/i.test(text_between);
158
+
159
+ // If we're not nested (no HTML tag nesting), process this script
160
+ if (!(contains_opening_tag && !contains_closing_tag)) {
161
+ script_blocks.push({
162
+ content: match[1]!,
163
+ start,
164
+ end,
165
+ });
166
+ }
167
+
168
+ last_index = end;
169
+ }
170
+
171
+ // Process all the collected script blocks
172
+ for (const script_block of script_blocks) {
173
+ parse_from(script_block.content);
174
+ }
175
+ } else if (TS_MATCHER.test(id) || JS_MATCHER.test(id)) {
176
+ parse_from(contents);
177
+ }
178
+
179
+ return specifiers;
180
+ };
@@ -0,0 +1,111 @@
1
+ import {join, extname, relative, basename} from 'node:path';
2
+ import {fileURLToPath} from 'node:url';
3
+ import {ensure_end, strip_end} from '@fuzdev/fuz_util/string.js';
4
+ import {styleText as st} from 'node:util';
5
+ import type {PathId} from '@fuzdev/fuz_util/path.js';
6
+
7
+ import {
8
+ GRO_CONFIG_FILENAME,
9
+ GRO_DEV_DIR,
10
+ GRO_DIR,
11
+ SOURCE_DIR,
12
+ SVELTEKIT_DIST_DIRNAME,
13
+ } from './constants.ts';
14
+ import {default_svelte_config} from './svelte_config.ts';
15
+
16
+ /*
17
+
18
+ A path `id` is an absolute path to the source/.gro/dist directory.
19
+ It's the same name that Rollup uses.
20
+
21
+ */
22
+
23
+ export const LIB_DIRNAME = basename(default_svelte_config.lib_path);
24
+ export const LIB_PATH = SOURCE_DIR + LIB_DIRNAME;
25
+ /** @trailing_slash */
26
+ export const LIB_DIR = LIB_PATH + '/';
27
+ export const ROUTES_DIRNAME = basename(default_svelte_config.routes_path);
28
+
29
+ export interface Paths {
30
+ /** @trailing_slash */
31
+ root: string;
32
+ /** @trailing_slash */
33
+ source: string;
34
+ /** @trailing_slash */
35
+ lib: string;
36
+ /** @trailing_slash */
37
+ build: string;
38
+ /** @trailing_slash */
39
+ build_dev: string;
40
+ config: string;
41
+ }
42
+
43
+ export const create_paths = (root_dir: string): Paths => {
44
+ // TODO remove reliance on trailing slash towards windows support
45
+ const root = ensure_end(root_dir, '/');
46
+ return {
47
+ root,
48
+ source: root + SOURCE_DIR,
49
+ lib: root + LIB_DIR,
50
+ build: root + GRO_DIR,
51
+ build_dev: root + GRO_DEV_DIR,
52
+ config: root + GRO_CONFIG_FILENAME,
53
+ };
54
+ };
55
+
56
+ export const infer_paths = (id: PathId): Paths => (is_gro_id(id) ? gro_paths : paths);
57
+
58
+ export const is_gro_id = (id: PathId): boolean =>
59
+ id.startsWith(gro_paths.root) || gro_paths.root === ensure_end(id, '/');
60
+
61
+ // '/home/me/app/src/foo/bar/baz.ts' → 'src/foo/bar/baz.ts'
62
+ export const to_root_path = (id: PathId, p = infer_paths(id)): string =>
63
+ relative(p.root, id) || './';
64
+
65
+ // '/home/me/app/src/foo/bar/baz.ts' → 'foo/bar/baz.ts'
66
+ export const path_id_to_base_path = (path_id: PathId, p = infer_paths(path_id)): string =>
67
+ relative(p.source, path_id);
68
+
69
+ // TODO base_path is an obsolete concept, it was a remnant from forcing `src/`
70
+ // 'foo/bar/baz.ts' → '/home/me/app/src/foo/bar/baz.ts'
71
+ export const base_path_to_path_id = (base_path: string, p = infer_paths(base_path)): PathId =>
72
+ join(p.source, base_path);
73
+
74
+ export const print_path = (path: string, p = infer_paths(path)): string => {
75
+ let final_path =
76
+ strip_end(path, '/') === strip_end(GRO_DIST_DIR, '/') ? 'gro' : to_root_path(path, p);
77
+ final_path =
78
+ final_path === 'gro' ? final_path : final_path[0] === '.' ? final_path : './' + final_path;
79
+ return st('gray', final_path);
80
+ };
81
+
82
+ export const replace_extension = (path: string, new_extension: string): string => {
83
+ const {length} = extname(path);
84
+ return (length === 0 ? path : path.substring(0, path.length - length)) + new_extension;
85
+ };
86
+
87
+ /**
88
+ * Paths for the user repo.
89
+ */
90
+ export const paths = create_paths(process.cwd());
91
+
92
+ /** @trailing_slash */
93
+ export const GRO_PACKAGE_DIR = 'gro/';
94
+ // TODO document these conditions with comments
95
+ // TODO there's probably a more robust way to do this
96
+ const filename = fileURLToPath(import.meta.url);
97
+ const gro_package_dir_path = join(
98
+ filename,
99
+ filename.includes('/gro/src/lib/')
100
+ ? '../../../'
101
+ : filename.includes('/gro/dist/')
102
+ ? '../../'
103
+ : '../',
104
+ );
105
+ export const IS_THIS_GRO = gro_package_dir_path === paths.root;
106
+ /**
107
+ * Paths for the Gro package being used by the user repo.
108
+ */
109
+ export const gro_paths = IS_THIS_GRO ? paths : create_paths(gro_package_dir_path);
110
+ /** @trailing_slash */
111
+ export const GRO_DIST_DIR = gro_paths.root + SVELTEKIT_DIST_DIRNAME + '/';