@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
package/dist/invoke.js ADDED
@@ -0,0 +1,28 @@
1
+ import { attach_process_error_handler } from '@fuzdev/fuz_util/process.js';
2
+ import { configure_print_colors } from '@fuzdev/fuz_util/print.js';
3
+ import { invoke_task } from "./invoke_task.js";
4
+ import { to_task_args } from "./args.js";
5
+ import { load_gro_config } from "./gro_config.js";
6
+ import { sveltekit_sync_if_obviously_needed } from "./sveltekit_helpers.js";
7
+ /*
8
+
9
+ This module invokes the Gro CLI which in turn invokes tasks.
10
+ Tasks are the CLI's primary concept.
11
+ To learn more about them, see `src/docs/task.md`.
12
+
13
+ When the CLI is invoked it passes the first CLI arg as `task_name` to `invoke_task`,
14
+ and the rest of the args are forwarded to the task's `run` function.
15
+
16
+ */
17
+ // handle uncaught errors
18
+ attach_process_error_handler({
19
+ to_error_label: (err) => (err.constructor.name === 'TaskError' ? 'TaskError' : null),
20
+ map_error_text: (err) => (err.constructor.name === 'SilentError' ? '' : null),
21
+ });
22
+ if (!process.env.NO_COLOR) {
23
+ const { styleText } = await import('node:util');
24
+ configure_print_colors(styleText);
25
+ }
26
+ await sveltekit_sync_if_obviously_needed();
27
+ const { task_name, args } = to_task_args();
28
+ await invoke_task(task_name, args, await load_gro_config());
@@ -0,0 +1,30 @@
1
+ import type { Args } from '@fuzdev/fuz_util/args.js';
2
+ import { Logger } from '@fuzdev/fuz_util/log.js';
3
+ import { Timings } from '@fuzdev/fuz_util/timings.js';
4
+ import { RawInputPath } from './input_path.ts';
5
+ import type { GroConfig } from './gro_config.ts';
6
+ import { Filer } from './filer.ts';
7
+ /**
8
+ * Invokes Gro tasks by name using the filesystem as the source.
9
+ *
10
+ * When a task is invoked,
11
+ * Gro first searches for tasks in the current working directory.
12
+ * and falls back to searching Gro's directory, if the two are different.
13
+ * See `src/lib/input_path.ts` for info about what "task_name" can refer to.
14
+ * If it matches a directory, all of the tasks within it are logged,
15
+ * both in the current working directory and Gro.
16
+ *
17
+ * This code is particularly hairy because
18
+ * we're accepting a wide range of user input
19
+ * and trying to do the right thing.
20
+ * Precise error messages are especially difficult and
21
+ * there are some subtle differences in the complex logical branches.
22
+ * The comments describe each condition.
23
+ *
24
+ * @param task_name - The name of the task to invoke.
25
+ * @param args - The CLI args to pass to the task.
26
+ * @param config - The Gro configuration.
27
+ * @param initial_timings - The timings to use for the top-level task, `null` for composed tasks.
28
+ */
29
+ export declare const invoke_task: (task_name: RawInputPath, args: Args | undefined, config: GroConfig, initial_filer?: Filer, initial_timings?: Timings | null, parent_log?: Logger) => Promise<void>;
30
+ //# sourceMappingURL=invoke_task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke_task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/invoke_task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAE/C,OAAO,EAAmB,OAAO,EAAC,MAAM,6BAA6B,CAAC;AAKtE,OAAO,EAAgB,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAI5D,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,WAAW,GACvB,WAAW,YAAY,EACvB,MAAM,IAAI,GAAG,SAAS,EACtB,QAAQ,SAAS,EACjB,gBAAgB,KAAK,EACrB,kBAAkB,OAAO,GAAG,IAAI,EAChC,aAAa,MAAM,KACjB,OAAO,CAAC,IAAI,CA8Fd,CAAC"}
@@ -0,0 +1,104 @@
1
+ import { Logger } from '@fuzdev/fuz_util/log.js';
2
+ import { print_ms, print_timings } from '@fuzdev/fuz_util/print.js';
3
+ import { create_stopwatch, Timings } from '@fuzdev/fuz_util/timings.js';
4
+ import { styleText as st } from 'node:util';
5
+ import { to_forwarded_args } from "./args.js";
6
+ import { run_task } from "./run_task.js";
7
+ import { to_input_path, RawInputPath } from "./input_path.js";
8
+ import { find_tasks, load_tasks, SilentError } from "./task.js";
9
+ import { package_json_load_for_gro } from "./package_json.js";
10
+ import { log_tasks, log_error_reasons } from "./task_logging.js";
11
+ import { Filer } from "./filer.js";
12
+ /**
13
+ * Invokes Gro tasks by name using the filesystem as the source.
14
+ *
15
+ * When a task is invoked,
16
+ * Gro first searches for tasks in the current working directory.
17
+ * and falls back to searching Gro's directory, if the two are different.
18
+ * See `src/lib/input_path.ts` for info about what "task_name" can refer to.
19
+ * If it matches a directory, all of the tasks within it are logged,
20
+ * both in the current working directory and Gro.
21
+ *
22
+ * This code is particularly hairy because
23
+ * we're accepting a wide range of user input
24
+ * and trying to do the right thing.
25
+ * Precise error messages are especially difficult and
26
+ * there are some subtle differences in the complex logical branches.
27
+ * The comments describe each condition.
28
+ *
29
+ * @param task_name - The name of the task to invoke.
30
+ * @param args - The CLI args to pass to the task.
31
+ * @param config - The Gro configuration.
32
+ * @param initial_timings - The timings to use for the top-level task, `null` for composed tasks.
33
+ */
34
+ export const invoke_task = async (task_name, args, config, initial_filer, initial_timings, parent_log) => {
35
+ // Create child logger if parent exists, otherwise root logger
36
+ const log_label = task_name || 'gro';
37
+ const log = parent_log ? parent_log.child(log_label) : new Logger(log_label);
38
+ log.info('invoking', task_name ? st('cyan', task_name) : 'gro');
39
+ // track if we created the filer
40
+ const owns_filer = !initial_filer;
41
+ const filer = initial_filer ?? new Filer({ log: log.child('filer'), ...config.filer_options });
42
+ const owns_timings = !initial_timings;
43
+ const timings = initial_timings ?? new Timings();
44
+ const total_timing = create_stopwatch();
45
+ const finish = async () => {
46
+ // cleanup filer only if we created it and it was initialized
47
+ if (owns_filer && filer.inited) {
48
+ await filer.close();
49
+ }
50
+ if (owns_timings)
51
+ return; // kinda weird, print timings only for the top-level task
52
+ print_timings(timings, log);
53
+ log.info(`🕒 ${print_ms(total_timing())}`);
54
+ };
55
+ // Check if the caller just wants to see the version.
56
+ if (!task_name && (args?.version || args?.v)) {
57
+ const gro_package_json = await package_json_load_for_gro();
58
+ log.info(`${st('gray', 'v')}${st('cyan', gro_package_json.version)}`);
59
+ await finish();
60
+ return;
61
+ }
62
+ // Resolve the input path for the provided task name.
63
+ const input_path = to_input_path(task_name);
64
+ const { task_root_dirs } = config;
65
+ // Find the task or directory specified by the `input_path`.
66
+ // Fall back to searching the Gro directory as well.
67
+ const found = await find_tasks([input_path], task_root_dirs, config);
68
+ if (!found.ok) {
69
+ log_error_reasons(log, found.reasons);
70
+ throw new SilentError();
71
+ }
72
+ // Found a match either in the current working directory or Gro's directory.
73
+ const found_tasks = found.value;
74
+ const { resolved_input_files } = found_tasks;
75
+ // Load the task module.
76
+ const loaded = await load_tasks(found_tasks);
77
+ if (!loaded.ok) {
78
+ log_error_reasons(log, loaded.reasons);
79
+ throw new SilentError();
80
+ }
81
+ const loaded_tasks = loaded.value;
82
+ if (resolved_input_files.length > 1 ||
83
+ resolved_input_files[0].resolved_input_path.is_directory) {
84
+ // The input path matches a directory. Log the tasks but don't run them.
85
+ log_tasks(log, loaded_tasks);
86
+ await finish();
87
+ return;
88
+ }
89
+ // The input path matches a file that's presumable a task, so load and run it.
90
+ if (loaded_tasks.modules.length !== 1)
91
+ throw Error('expected one loaded task'); // run only one task at a time
92
+ const task = loaded_tasks.modules[0];
93
+ log.info(`→ ${st('cyan', task.name)} ${(task.mod.task.summary && st('gray', task.mod.task.summary)) ?? ''}`);
94
+ const timing_to_run_task = timings.start('run task ' + task_name);
95
+ const result = await run_task(task, { ...args, ...to_forwarded_args(`gro ${task.name}`) }, invoke_task, config, filer, log, timings);
96
+ timing_to_run_task();
97
+ if (!result.ok) {
98
+ log.info(`${st('red', '🞩')} ${st('cyan', task.name)}`);
99
+ log_error_reasons(log, [result.reason]);
100
+ throw result.error;
101
+ }
102
+ log.info(`✓ ${st('cyan', task.name)}`);
103
+ await finish();
104
+ };
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ import { type Task } from './task.ts';
3
+ /** @nodocs */
4
+ export declare const Args: z.ZodObject<{
5
+ _: z.ZodDefault<z.ZodArray<z.ZodString>>;
6
+ eslint_cli: z.ZodDefault<z.ZodString>;
7
+ }, z.core.$strict>;
8
+ export type Args = z.infer<typeof Args>;
9
+ /** @nodocs */
10
+ export declare const task: Task<Args>;
11
+ //# sourceMappingURL=lint.task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lint.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/lint.task.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAI/C,cAAc;AACd,eAAO,MAAM,IAAI;;;kBAGf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CAoB3B,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { args_serialize } from '@fuzdev/fuz_util/args.js';
2
+ import { print_spawn_result } from '@fuzdev/fuz_util/process.js';
3
+ import { z } from 'zod';
4
+ import { to_forwarded_args } from "./args.js";
5
+ import { find_cli, spawn_cli } from "./cli.js";
6
+ import { TaskError } from "./task.js";
7
+ const ESLINT_CLI = 'eslint';
8
+ /** @nodocs */
9
+ export const Args = z.strictObject({
10
+ _: z.array(z.string()).meta({ description: 'paths to serve' }).default([]),
11
+ eslint_cli: z.string().meta({ description: 'the ESLint CLI to use' }).default(ESLINT_CLI),
12
+ });
13
+ /** @nodocs */
14
+ export const task = {
15
+ summary: 'run eslint',
16
+ Args,
17
+ run: async ({ log, args }) => {
18
+ const { _, eslint_cli } = args;
19
+ const found_eslint_cli = await find_cli(eslint_cli);
20
+ if (!found_eslint_cli) {
21
+ // TODO maybe make this an option?
22
+ log.info('ESLint is not installed; skipping linting');
23
+ return;
24
+ }
25
+ const forwarded_args = { _, 'max-warnings': 0, ...to_forwarded_args(eslint_cli) };
26
+ const serialized_args = args_serialize(forwarded_args);
27
+ const eslintResult = await spawn_cli(found_eslint_cli, serialized_args, log);
28
+ if (!eslintResult?.ok) {
29
+ throw new TaskError(`ESLint found some problems. ${print_spawn_result(eslintResult)}`);
30
+ }
31
+ },
32
+ };
@@ -0,0 +1,6 @@
1
+ import type { LoadHook, ResolveHook } from 'node:module';
2
+ /** @nodocs */
3
+ export declare const load: LoadHook;
4
+ /** @nodocs */
5
+ export declare const resolve: ResolveHook;
6
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/loader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,QAAQ,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AAoEvD,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,QA0GlB,CAAC;AAEF,cAAc;AACd,eAAO,MAAM,OAAO,EAAE,WA+CrB,CAAC"}
package/dist/loader.js ADDED
@@ -0,0 +1,192 @@
1
+ import { compile, compileModule, preprocess } from 'svelte/compiler';
2
+ import { fileURLToPath, pathToFileURL } from 'node:url';
3
+ import { dirname, join } from 'node:path';
4
+ import { readFileSync } from 'node:fs';
5
+ import ts_blank_space from 'ts-blank-space';
6
+ import { render_env_shim_module } from "./sveltekit_shim_env.js";
7
+ import { render_sveltekit_shim_app_environment, render_sveltekit_shim_app_paths, SVELTEKIT_SHIM_APP_ENVIRONMENT_MATCHER, SVELTEKIT_SHIM_APP_PATHS_MATCHER, sveltekit_shim_app_specifiers, } from "./sveltekit_shim_app.js";
8
+ import { default_svelte_config } from "./svelte_config.js";
9
+ import { paths } from "./paths.js";
10
+ import { TS_MATCHER, SVELTE_MATCHER, SVELTE_RUNES_MATCHER } from "./constants.js";
11
+ import { resolve_specifier } from "./resolve_specifier.js";
12
+ import { map_sveltekit_aliases } from "./sveltekit_helpers.js";
13
+ // TODO get out of the loader business, starting with https://nodejs.org/api/typescript.html#type-stripping
14
+ /*
15
+
16
+ Usage via `$lib/register.ts`:
17
+
18
+ ```bash
19
+ node --import @fuzdev/gro/register.js foo.ts
20
+ ```
21
+
22
+ Usage via `$lib/run.task.ts`:
23
+
24
+ ```bash
25
+ gro run foo.ts
26
+ ```
27
+
28
+ Direct usage without register (see also `$lib/gro.ts`):
29
+
30
+ ```bash
31
+ node --import 'data:text/javascript,import {register} from "node:module"; import {pathToFileURL} from "node:url"; register("@fuzdev/gro/loader.js", pathToFileURL("./"));' --experimental-import-meta-resolve --experimental-strip-types' foo.ts
32
+ ```
33
+
34
+ TODO how to improve that gnarly import line? was originally designed for the now-deprecated `--loader`
35
+
36
+ */
37
+ // TODO sourcemaps for the svelte preprocessors
38
+ // TODO `import.meta.resolve` wasn't available in loaders when this was first implemented, but might be now
39
+ // dev is always true in the loader
40
+ const dev = true;
41
+ const dir = paths.root;
42
+ const { alias, base_url, assets_url, env_dir, private_prefix, public_prefix, svelte_compile_options, svelte_compile_module_options, svelte_preprocessors, } = default_svelte_config;
43
+ const aliases = Object.entries(alias);
44
+ const RAW_MATCHER = /(%3Fraw|\.css|\.svg)$/; // TODO others? configurable?
45
+ /** @nodocs */
46
+ export const load = async (url, context, nextLoad) => {
47
+ // console.log(`url`, url);
48
+ if (SVELTEKIT_SHIM_APP_PATHS_MATCHER.test(url)) {
49
+ // SvelteKit `$app/paths` shim
50
+ return {
51
+ format: 'module',
52
+ shortCircuit: true,
53
+ source: render_sveltekit_shim_app_paths(base_url, assets_url),
54
+ };
55
+ }
56
+ else if (SVELTEKIT_SHIM_APP_ENVIRONMENT_MATCHER.test(url)) {
57
+ // SvelteKit `$app/environment` shim
58
+ return {
59
+ format: 'module',
60
+ shortCircuit: true,
61
+ source: render_sveltekit_shim_app_environment(dev),
62
+ };
63
+ }
64
+ else if (SVELTE_RUNES_MATCHER.test(url)) {
65
+ // Svelte runes in js/ts, `.svelte.ts`
66
+ const filename = fileURLToPath(url);
67
+ const loaded = await nextLoad(url, { ...context, format: 'module-typescript' });
68
+ const raw_source = loaded.source?.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
69
+ if (raw_source == null)
70
+ throw Error(`Failed to load ${url}`);
71
+ // TODO should be nice if we could use Node's builtin amaro transform, but I couldn't find a way after digging into the source, AFAICT it's internal and not exposed
72
+ const source = ts_blank_space(raw_source); // TODO was using oxc-transform and probably should, but this doesn't require sourcemaps, and it's still alpha as of May 2025
73
+ const transformed = compileModule(source, {
74
+ ...svelte_compile_module_options,
75
+ dev,
76
+ filename,
77
+ });
78
+ return { format: 'module', shortCircuit: true, source: transformed.js.code };
79
+ }
80
+ else if (TS_MATCHER.test(url)) {
81
+ // ts but not `.svelte.ts`
82
+ return nextLoad(url, { ...context, format: 'module-typescript' });
83
+ }
84
+ else if (SVELTE_MATCHER.test(url)) {
85
+ // Svelte, `.svelte`
86
+ const loaded = await nextLoad(url, { ...context, format: 'module' });
87
+ const raw_source = loaded.source.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
88
+ const filename = fileURLToPath(url);
89
+ const preprocessed = svelte_preprocessors // TODO @many use sourcemaps (and diagnostics?)
90
+ ? await preprocess(raw_source, svelte_preprocessors, { filename })
91
+ : null;
92
+ const source = preprocessed?.code ?? raw_source;
93
+ const transformed = compile(source, { ...svelte_compile_options, dev, filename });
94
+ return { format: 'module', shortCircuit: true, source: transformed.js.code };
95
+ }
96
+ else if (context.importAttributes.type === 'json') {
97
+ // json - any file extension
98
+ // TODO probably follow esbuild and also export every top-level property for objects from the module for good treeshaking - https://esbuild.github.io/content-types/#json (type generation?)
99
+ // TODO why is removing the importAttributes needed? can't pass no context either -
100
+ // error: `Module "file:///home/user/dev/repo/foo.json" is not of type "json"`
101
+ const loaded = await nextLoad(url, { ...context, importAttributes: undefined });
102
+ const raw_source = loaded.source?.toString(); // eslint-disable-line @typescript-eslint/no-base-to-string
103
+ if (raw_source == null)
104
+ throw Error(`Failed to load ${url}`);
105
+ const source = `export default ` + raw_source;
106
+ return { format: 'module', shortCircuit: true, source };
107
+ }
108
+ else if (RAW_MATCHER.test(url)) {
109
+ // raw text imports like `?raw`, `.css`, `.svg`
110
+ const filename = fileURLToPath(url.endsWith('%3Fraw') ? url.substring(0, url.length - 6) : url);
111
+ const raw_source = readFileSync(filename, 'utf8');
112
+ const source = 'export default `' + raw_source.replaceAll('\\', '\\\\').replaceAll('`', '\\`') + '`;';
113
+ return { format: 'module', shortCircuit: true, source };
114
+ }
115
+ else {
116
+ // SvelteKit `$env`
117
+ // TODO use `format` from the resolve hook to speed this up and make it simpler
118
+ if (context.format === 'sveltekit-env') {
119
+ let mode;
120
+ let visibility;
121
+ switch (context.importAttributes.virtual) {
122
+ case '$env/static/public': {
123
+ mode = 'static';
124
+ visibility = 'public';
125
+ break;
126
+ }
127
+ case '$env/static/private': {
128
+ mode = 'static';
129
+ visibility = 'private';
130
+ break;
131
+ }
132
+ case '$env/dynamic/public': {
133
+ mode = 'dynamic';
134
+ visibility = 'public';
135
+ break;
136
+ }
137
+ case '$env/dynamic/private': {
138
+ mode = 'dynamic';
139
+ visibility = 'private';
140
+ break;
141
+ }
142
+ default: {
143
+ throw Error(`Unknown $env import: ${context.importAttributes.virtual}`);
144
+ }
145
+ }
146
+ const source = render_env_shim_module(dev, mode, visibility, public_prefix, private_prefix, env_dir);
147
+ return { format: 'module', shortCircuit: true, source };
148
+ }
149
+ }
150
+ // fallback to default behavior
151
+ return nextLoad(url, context);
152
+ };
153
+ /** @nodocs */
154
+ export const resolve = async (specifier, context, nextResolve) => {
155
+ let s = specifier;
156
+ // Support SvelteKit `$env` imports
157
+ if (s === '$env/static/public' ||
158
+ s === '$env/static/private' ||
159
+ s === '$env/dynamic/public' ||
160
+ s === '$env/dynamic/private') {
161
+ // The returned `url` is validated before `load` is called,
162
+ // so we need a slightly roundabout strategy to pass through the specifier for virtual files.
163
+ return {
164
+ url: pathToFileURL(join(dir, 'src/lib', s)).href,
165
+ format: 'sveltekit-env',
166
+ importAttributes: { virtual: s }, // TODO idk I'm just making this up
167
+ shortCircuit: true,
168
+ };
169
+ }
170
+ // Support SvelteKit `$app` imports, including from node_modules
171
+ const shimmed = sveltekit_shim_app_specifiers.get(s);
172
+ if (shimmed !== undefined) {
173
+ return nextResolve(shimmed, context);
174
+ }
175
+ // Apply SvelteKit aliases (handles self-referencing packages like @fuzdev/fuz_util -> src/lib)
176
+ s = map_sveltekit_aliases(s, aliases);
177
+ // Bare specifiers (not starting with . or /) use Node's default resolution
178
+ if (s[0] !== '.' && s[0] !== '/') {
179
+ return nextResolve(s, context);
180
+ }
181
+ // Resolve paths using Vite conventions
182
+ const parent_url = context.parentURL;
183
+ if (!parent_url) {
184
+ return nextResolve(s, context);
185
+ }
186
+ const resolved = await resolve_specifier(s, dirname(fileURLToPath(parent_url)));
187
+ return {
188
+ url: pathToFileURL(resolved.path_id_with_querystring).href,
189
+ format: 'module',
190
+ shortCircuit: true,
191
+ };
192
+ };
@@ -0,0 +1,4 @@
1
+ export declare const MODULE_PATH_SRC_PREFIX: string;
2
+ export declare const MODULE_PATH_LIB_PREFIX: string;
3
+ export declare const is_external_module: (module_name: string) => boolean;
4
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/module.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,QAAa,CAAC;AACjD,eAAO,MAAM,sBAAsB,QAAqB,CAAC;AAOzD,eAAO,MAAM,kBAAkB,GAAI,aAAa,MAAM,KAAG,OACd,CAAC"}
package/dist/module.js ADDED
@@ -0,0 +1,6 @@
1
+ import { LIB_DIRNAME } from "./paths.js";
2
+ import { SOURCE_DIR, SOURCE_DIRNAME } from "./constants.js";
3
+ export const MODULE_PATH_SRC_PREFIX = SOURCE_DIR;
4
+ export const MODULE_PATH_LIB_PREFIX = `$${LIB_DIRNAME}/`;
5
+ const INTERNAL_MODULE_MATCHER = new RegExp(`^(\\.?\\.?|${SOURCE_DIRNAME}|\\$${LIB_DIRNAME})\\/`, 'u');
6
+ export const is_external_module = (module_name) => !INTERNAL_MODULE_MATCHER.test(module_name);
@@ -0,0 +1,36 @@
1
+ import type { Timings } from '@fuzdev/fuz_util/timings.js';
2
+ import type { Result } from '@fuzdev/fuz_util/result.js';
3
+ import type { PathId } from '@fuzdev/fuz_util/path.js';
4
+ import type { ResolvedInputFile } from './input_path.ts';
5
+ export interface ModuleMeta<TModule extends Record<string, any> = Record<string, any>> {
6
+ id: PathId;
7
+ mod: TModule;
8
+ }
9
+ export type LoadModuleResult<TModule> = Result<{
10
+ id: PathId;
11
+ mod: TModule;
12
+ }, LoadModuleFailure>;
13
+ export type LoadModuleFailure = {
14
+ ok: false;
15
+ type: 'failed_import';
16
+ id: PathId;
17
+ error: Error;
18
+ } | {
19
+ ok: false;
20
+ type: 'failed_validation';
21
+ id: PathId;
22
+ mod: Record<string, any>;
23
+ validation: string;
24
+ };
25
+ export declare const load_module: <TModule extends Record<string, any>>(id: PathId, validate?: (mod: Record<string, any>) => mod is TModule, bust_cache?: boolean) => Promise<LoadModuleResult<TModule>>;
26
+ export interface LoadModulesFailure<TModuleMeta extends ModuleMeta> {
27
+ type: 'load_module_failures';
28
+ load_module_failures: Array<LoadModuleFailure>;
29
+ reasons: Array<string>;
30
+ modules: Array<TModuleMeta>;
31
+ }
32
+ export type LoadModulesResult<TModuleMeta extends ModuleMeta> = Result<{
33
+ modules: Array<TModuleMeta>;
34
+ }, LoadModulesFailure<TModuleMeta>>;
35
+ export declare const load_modules: <TModule extends Record<string, any>, TModuleMeta extends ModuleMeta<TModule>>(resolved_input_files: Array<ResolvedInputFile>, validate: (mod: any) => mod is TModule, map_module_meta: (resolved_input_file: ResolvedInputFile, mod: TModule) => TModuleMeta, timings?: Timings) => Promise<LoadModulesResult<TModuleMeta>>;
36
+ //# sourceMappingURL=modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/modules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,6BAA6B,CAAC;AAEzD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAGvD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAErD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAGvD,MAAM,WAAW,UAAU,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IACpF,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,OAAO,CAAC;CACb;AAED,MAAM,MAAM,gBAAgB,CAAC,OAAO,IAAI,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,OAAO,CAAA;CAAC,EAAE,iBAAiB,CAAC,CAAC;AAC9F,MAAM,MAAM,iBAAiB,GAC1B;IAAC,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,eAAe,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAC,GAC5D;IACA,EAAE,EAAE,KAAK,CAAC;IACV,IAAI,EAAE,mBAAmB,CAAC;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;CAClB,CAAC;AAEL,eAAO,MAAM,WAAW,GAAU,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACpE,IAAI,MAAM,EACV,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,OAAO,EACvD,aAAa,OAAO,KAClB,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAiBnC,CAAC;AAEF,MAAM,WAAW,kBAAkB,CAAC,WAAW,SAAS,UAAU;IACjE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,oBAAoB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC/C,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAEvB,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;CAC5B;AAED,MAAM,MAAM,iBAAiB,CAAC,WAAW,SAAS,UAAU,IAAI,MAAM,CACrE;IACC,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;CAC5B,EACD,kBAAkB,CAAC,WAAW,CAAC,CAC/B,CAAC;AAGF,eAAO,MAAM,YAAY,GACxB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnC,WAAW,SAAS,UAAU,CAAC,OAAO,CAAC,EAEvC,sBAAsB,KAAK,CAAC,iBAAiB,CAAC,EAC9C,UAAU,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,IAAI,OAAO,EACtC,iBAAiB,CAAC,mBAAmB,EAAE,iBAAiB,EAAE,GAAG,EAAE,OAAO,KAAK,WAAW,EACtF,UAAU,OAAO,KACf,OAAO,CAAC,iBAAiB,CAAC,WAAW,CAAC,CA2CxC,CAAC"}
@@ -0,0 +1,71 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { UnreachableError } from '@fuzdev/fuz_util/error.js';
10
+ import { print_error } from '@fuzdev/fuz_util/print.js';
11
+ import { pathToFileURL } from 'node:url';
12
+ import { print_path } from "./paths.js";
13
+ export const load_module = async (id, validate, bust_cache) => {
14
+ let mod;
15
+ try {
16
+ let import_path = id;
17
+ if (bust_cache) {
18
+ const url = pathToFileURL(id);
19
+ url.searchParams.set('t', Date.now().toString());
20
+ import_path = url.href;
21
+ }
22
+ mod = await import(__rewriteRelativeImportExtension(import_path, true));
23
+ }
24
+ catch (error) {
25
+ return { ok: false, type: 'failed_import', id, error };
26
+ }
27
+ if (validate && !validate(mod)) {
28
+ return { ok: false, type: 'failed_validation', id, mod, validation: validate.name };
29
+ }
30
+ return { ok: true, id, mod };
31
+ };
32
+ // TODO parallelize and sort afterwards
33
+ export const load_modules = async (resolved_input_files, validate, map_module_meta, timings) => {
34
+ const timing_to_load_modules = timings?.start('load modules');
35
+ const modules = [];
36
+ const load_module_failures = [];
37
+ const reasons = [];
38
+ for (const resolved_input_file of resolved_input_files.values()) {
39
+ const { id, input_path } = resolved_input_file;
40
+ const result = await load_module(id, validate); // eslint-disable-line no-await-in-loop
41
+ if (result.ok) {
42
+ modules.push(map_module_meta(resolved_input_file, result.mod));
43
+ }
44
+ else {
45
+ load_module_failures.push(result);
46
+ switch (result.type) {
47
+ case 'failed_import': {
48
+ reasons.push(`Module import ${print_path(id)} failed from input ${print_path(input_path)}: ${print_error(result.error)}`);
49
+ break;
50
+ }
51
+ case 'failed_validation': {
52
+ reasons.push(`Module ${print_path(id)} failed validation '${result.validation}'.`);
53
+ break;
54
+ }
55
+ default:
56
+ throw new UnreachableError(result);
57
+ }
58
+ }
59
+ }
60
+ timing_to_load_modules?.();
61
+ if (load_module_failures.length) {
62
+ return {
63
+ ok: false,
64
+ type: 'load_module_failures',
65
+ load_module_failures,
66
+ reasons,
67
+ modules,
68
+ };
69
+ }
70
+ return { ok: true, modules };
71
+ };
@@ -0,0 +1,32 @@
1
+ import type { Logger } from '@fuzdev/fuz_util/log.js';
2
+ import { PackageJson, PackageJsonExports } from '@fuzdev/fuz_util/package_json.js';
3
+ export type PackageJsonMapper = (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>;
4
+ export declare const PACKAGE_JSON_EMPTY: PackageJson;
5
+ export declare const package_json_load: (dir?: string, cache?: Record<string, PackageJson>, parse?: boolean, // TODO pass `false` here in more places, especially anything perf-sensitive like work on startup
6
+ log?: Logger) => Promise<PackageJson>;
7
+ export declare const package_json_sync: (map_package_json: PackageJsonMapper, log: Logger, write?: boolean, dir?: string, exports_dir?: string) => Promise<{
8
+ package_json: PackageJson | null;
9
+ changed: boolean;
10
+ }>;
11
+ export declare const package_json_load_for_gro: () => Promise<PackageJson>;
12
+ export declare const package_json_write: (serialized_package_json: string) => Promise<void>;
13
+ export declare const package_json_serialize: (package_json: PackageJson) => string;
14
+ /**
15
+ * Updates package.json. Writes to the filesystem only when contents change.
16
+ */
17
+ export declare const package_json_update: (update: (package_json: PackageJson) => PackageJson | null | Promise<PackageJson | null>, dir?: string, write?: boolean) => Promise<{
18
+ package_json: PackageJson | null;
19
+ changed: boolean;
20
+ }>;
21
+ export declare const package_json_to_exports: (paths: Array<string>) => PackageJsonExports;
22
+ export declare const package_json_parse_repo_url: (package_json: PackageJson) => {
23
+ owner: string;
24
+ repo: string;
25
+ } | undefined;
26
+ export declare const package_json_has_dependency: (dep_name: string, package_json: PackageJson) => boolean;
27
+ export interface PackageJsonDep {
28
+ name: string;
29
+ version: string;
30
+ }
31
+ export declare const package_json_extract_dependencies: (package_json: PackageJson) => Array<PackageJsonDep>;
32
+ //# sourceMappingURL=package_json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AAgBjF,MAAM,MAAM,iBAAiB,GAAG,CAC/B,YAAY,EAAE,WAAW,KACrB,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AAEtD,eAAO,MAAM,kBAAkB,EAAE,WAAqC,CAAC;AAEvE,eAAO,MAAM,iBAAiB,GAC7B,YAA+C,EAC/C,QAAQ,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,EACnC,eAAY,EAAE,iGAAiG;AAC/G,MAAM,MAAM,KACV,OAAO,CAAC,WAAW,CAkBrB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC7B,kBAAkB,iBAAiB,EACnC,KAAK,MAAM,EACX,eAAY,EACZ,YAAgB,EAChB,oBAAuB,KACrB,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CA0B9D,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAAO,OAAO,CAAC,WAAW,CAC9B,CAAC;AAMnC,eAAO,MAAM,kBAAkB,GAAI,yBAAyB,MAAM,KAAG,OAAO,CAAC,IAAI,CACL,CAAC;AAE7E,eAAO,MAAM,sBAAsB,GAAI,cAAc,WAAW,KAAG,MACW,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC/B,QAAQ,CAAC,YAAY,EAAE,WAAW,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,EACvF,YAAgB,EAChB,eAAY,KACV,OAAO,CAAC;IAAC,YAAY,EAAE,WAAW,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAC,CAa9D,CAAC;AAIF,eAAO,MAAM,uBAAuB,GAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAG,kBAmD9D,CAAC;AAIF,eAAO,MAAM,2BAA2B,GACvC,cAAc,WAAW,KACvB;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG,SAgBlC,CAAC;AA8BF,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,EAAE,cAAc,WAAW,KAAG,OAG9C,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,iCAAiC,GAC7C,cAAc,WAAW,KACvB,KAAK,CAAC,cAAc,CAetB,CAAC"}