@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,217 @@
1
+ import { spawn } from '@fuzdev/fuz_util/process.js';
2
+ import { print_error } from '@fuzdev/fuz_util/print.js';
3
+ import { styleText as st } from 'node:util';
4
+ import { z } from 'zod';
5
+ import { cp, mkdir, readdir, rm } from 'node:fs/promises';
6
+ import { join, resolve } from 'node:path';
7
+ import { fs_exists, fs_empty_dir } from '@fuzdev/fuz_util/fs.js';
8
+ import { git_check_clean_workspace, git_checkout, git_local_branch_exists, git_remote_branch_exists, GitOrigin, GitBranch, git_delete_local_branch, git_push_to_create, git_reset_branch_to_first_commit, git_pull, git_fetch, git_check_setting_pull_rebase, git_clone_locally, git_current_branch_name, } from '@fuzdev/fuz_util/git.js';
9
+ import { TaskError } from "./task.js";
10
+ import { print_path } from "./paths.js";
11
+ import { GRO_DIRNAME, GIT_DIRNAME, SVELTEKIT_BUILD_DIRNAME } from "./constants.js";
12
+ // docs at ../docs/deploy.md
13
+ // terminal command for testing:
14
+ // npm run bootstrap && rm -rf .gro && clear && gro deploy --source no-git-workspace --no-build --dry
15
+ // TODO customize
16
+ const dir = process.cwd();
17
+ const INITIAL_FILE_PATH = '.gitkeep';
18
+ const DEPLOY_DIR = GRO_DIRNAME + '/deploy';
19
+ const SOURCE_BRANCH = 'main';
20
+ const TARGET_BRANCH = 'deploy';
21
+ const DANGEROUS_BRANCHES = [SOURCE_BRANCH, 'master'];
22
+ /** @nodocs */
23
+ export const Args = z.strictObject({
24
+ source: GitBranch.describe('git source branch to build and deploy from').default(SOURCE_BRANCH),
25
+ target: GitBranch.describe('git target branch to deploy to').default(TARGET_BRANCH),
26
+ origin: GitOrigin.describe('git origin to deploy to').default('origin'),
27
+ deploy_dir: z.string().meta({ description: 'the deploy output directory' }).default(DEPLOY_DIR),
28
+ build_dir: z
29
+ .string()
30
+ .meta({ description: 'the SvelteKit build directory' })
31
+ .default(SVELTEKIT_BUILD_DIRNAME),
32
+ dry: z
33
+ .boolean()
34
+ .meta({
35
+ description: 'build and prepare to deploy without actually deploying',
36
+ })
37
+ .default(false),
38
+ force: z
39
+ .boolean()
40
+ .meta({ description: 'caution!! destroys the target branch both locally and remotely' })
41
+ .default(false),
42
+ dangerous: z
43
+ .boolean()
44
+ .meta({ description: 'caution!! enables destruction of branches like main and master' })
45
+ .default(false),
46
+ reset: z
47
+ .boolean()
48
+ .meta({
49
+ description: 'if true, resets the target branch back to the first commit before deploying',
50
+ })
51
+ .default(false),
52
+ build: z.boolean().meta({ description: 'dual of no-build' }).default(true),
53
+ 'no-build': z.boolean().meta({ description: 'opt out of building' }).default(false),
54
+ sync: z.boolean().meta({ description: 'dual of no-sync' }).default(true),
55
+ 'no-sync': z.boolean().meta({ description: 'opt out of gro sync in build' }).default(false),
56
+ gen: z.boolean().meta({ description: 'dual of no-gen' }).default(true),
57
+ 'no-gen': z.boolean().meta({ description: 'opt out of gro gen in build' }).default(false),
58
+ install: z.boolean().meta({ description: 'dual of no-install' }).default(true),
59
+ 'no-install': z
60
+ .boolean()
61
+ .meta({ description: 'opt out of installing packages before building' })
62
+ .default(false),
63
+ force_build: z
64
+ .boolean()
65
+ .meta({ description: 'force a fresh build, ignoring the cache' })
66
+ .default(false),
67
+ pull: z.boolean().meta({ description: 'dual of no-pull' }).default(true),
68
+ 'no-pull': z.boolean().meta({ description: 'opt out of git pull' }).default(false),
69
+ });
70
+ /** @nodocs */
71
+ export const task = {
72
+ summary: 'deploy to a branch',
73
+ Args,
74
+ run: async ({ args, log, invoke_task }) => {
75
+ const { source, target, origin, build_dir, deploy_dir, dry, force, dangerous, reset, build, sync, gen, install, force_build, pull, } = args;
76
+ // Checks
77
+ if (!force && target !== TARGET_BRANCH) {
78
+ throw new TaskError(`Warning! You are deploying to a custom target branch '${target}',` +
79
+ ` instead of the default '${TARGET_BRANCH}' branch.` +
80
+ ` This is destructive to your '${target}' branch!` +
81
+ ` If you understand and are OK with deleting your branch '${target}',` +
82
+ ` both locally and remotely, pass --force to suppress this error.`);
83
+ }
84
+ if (!dangerous && DANGEROUS_BRANCHES.includes(target)) {
85
+ throw new TaskError(`Warning! You are deploying to a custom target branch '${target}'` +
86
+ ` and that appears very dangerous: it is destructive to your '${target}' branch!` +
87
+ ` If you understand and are OK with deleting your branch '${target}',` +
88
+ ` both locally and remotely, pass --dangerous to suppress this error.`);
89
+ }
90
+ const clean_error_message = await git_check_clean_workspace();
91
+ if (clean_error_message) {
92
+ throw new TaskError('Deploy failed because the git workspace has uncommitted changes: ' + clean_error_message);
93
+ }
94
+ if (!(await git_check_setting_pull_rebase())) {
95
+ throw new TaskError('Deploying currently requires `git config --global pull.rebase true`,' +
96
+ ' but this restriction could be lifted with more work');
97
+ }
98
+ // Fetch the source branch in the cwd if it's not there
99
+ if (!(await git_local_branch_exists(source))) {
100
+ await git_fetch(origin, source);
101
+ }
102
+ // Prepare the source branch in the cwd
103
+ await git_checkout(source);
104
+ if (pull) {
105
+ await git_pull(origin, source);
106
+ }
107
+ if (await git_check_clean_workspace()) {
108
+ throw new TaskError('Deploy failed because the local source branch is out of sync with the remote one,' +
109
+ ' finish rebasing manually or reset with `git rebase --abort`');
110
+ }
111
+ // Prepare the target branch remotely and locally
112
+ const resolved_deploy_dir = resolve(deploy_dir);
113
+ const target_spawn_options = { cwd: resolved_deploy_dir };
114
+ const remote_target_exists = await git_remote_branch_exists(origin, target);
115
+ if (remote_target_exists) {
116
+ // Remote target branch already exists, so sync up efficiently
117
+ // First, check if the deploy dir exists, and if so, attempt to sync it.
118
+ // If anything goes wrong, delete the directory and we'll initialize it
119
+ // using the same code path as if it didn't exist in the first place.
120
+ if (await fs_exists(resolved_deploy_dir)) {
121
+ if (target !== (await git_current_branch_name(target_spawn_options))) {
122
+ // We're in a bad state because the target branch has changed,
123
+ // so delete the directory and continue as if it wasn't there.
124
+ await rm(resolved_deploy_dir, { recursive: true });
125
+ }
126
+ else {
127
+ await spawn('git', ['reset', '--hard'], target_spawn_options); // in case it's dirty
128
+ // Skip pulling target branch when resetting (optimization - we reset after anyway)
129
+ if (!reset) {
130
+ await git_pull(origin, target, target_spawn_options);
131
+ if (await git_check_clean_workspace(target_spawn_options)) {
132
+ // We're in a bad state because the local branch lost continuity with the remote,
133
+ // so delete the directory and continue as if it wasn't there.
134
+ await rm(resolved_deploy_dir, { recursive: true });
135
+ }
136
+ }
137
+ }
138
+ }
139
+ // Second, initialize the deploy dir if needed.
140
+ // It may not exist, or it may have been deleted after failing to sync above.
141
+ if (!(await fs_exists(resolved_deploy_dir))) {
142
+ const local_deploy_branch_exists = await git_local_branch_exists(target);
143
+ await git_fetch(origin, ('+' + target + ':' + target)); // fetch+merge and allow non-fastforward updates with the +
144
+ await git_clone_locally(origin, target, dir, resolved_deploy_dir);
145
+ // Clean up if we created the target branch in the cwd
146
+ if (!local_deploy_branch_exists) {
147
+ await git_delete_local_branch(target);
148
+ }
149
+ }
150
+ // Local target branch is now synced with remote, but do we need to reset?
151
+ if (reset) {
152
+ await git_reset_branch_to_first_commit(origin, target, target_spawn_options);
153
+ }
154
+ }
155
+ else {
156
+ // Remote target branch does not exist, so start from scratch
157
+ // Delete the deploy dir and recreate it
158
+ if (await fs_exists(resolved_deploy_dir)) {
159
+ await rm(resolved_deploy_dir, { recursive: true });
160
+ await mkdir(resolved_deploy_dir, { recursive: true });
161
+ }
162
+ // Delete the target branch locally in the cwd if it exists
163
+ if (await git_local_branch_exists(target)) {
164
+ await git_delete_local_branch(target);
165
+ }
166
+ // Create the target branch locally and remotely.
167
+ // This is more complex to avoid churning the cwd.
168
+ await git_clone_locally(origin, source, dir, resolved_deploy_dir);
169
+ await spawn('git', ['checkout', '--orphan', target], target_spawn_options);
170
+ // TODO there's definitely a better way to do this
171
+ await spawn('git', ['rm', '-rf', '.'], target_spawn_options);
172
+ await spawn('touch', [INITIAL_FILE_PATH], target_spawn_options);
173
+ await spawn('git', ['add', INITIAL_FILE_PATH], target_spawn_options);
174
+ await spawn('git', ['commit', '-m', 'init'], target_spawn_options);
175
+ await git_push_to_create(origin, target, target_spawn_options);
176
+ await git_delete_local_branch(source, target_spawn_options);
177
+ }
178
+ // Remove everything except .git from the deploy directory to avoid stale files
179
+ await fs_empty_dir(resolved_deploy_dir, (name) => name !== GIT_DIRNAME);
180
+ // Build
181
+ try {
182
+ if (build) {
183
+ await invoke_task('build', { sync, gen, install, force_build });
184
+ }
185
+ }
186
+ catch (error) {
187
+ log.error(st('red', 'build failed'), 'but', st('green', 'no changes were made to git'), print_error(error));
188
+ if (dry) {
189
+ log.info(st('red', 'dry deploy failed'));
190
+ }
191
+ throw new TaskError(`Deploy safely canceled due to build failure. See the error above.`);
192
+ }
193
+ // Verify build output exists
194
+ if (!(await fs_exists(build_dir))) {
195
+ throw new TaskError(`Directory to deploy does not exist after building: ${build_dir}`);
196
+ }
197
+ // Copy the build
198
+ const build_entries = await readdir(build_dir);
199
+ await Promise.all(build_entries.map((path) => cp(join(build_dir, path), join(resolved_deploy_dir, path), { recursive: true })));
200
+ // At this point, `dist/` is ready to be committed and deployed!
201
+ if (dry) {
202
+ log.info(st('green', 'dry deploy complete:'), 'files at', print_path(resolved_deploy_dir));
203
+ return;
204
+ }
205
+ // Commit and push
206
+ try {
207
+ await spawn('git', ['add', '.', '-f'], target_spawn_options);
208
+ await spawn('git', ['commit', '-m', 'deployment'], target_spawn_options);
209
+ await spawn('git', ['push', origin, target, '-f'], target_spawn_options); // force push because we may be resetting the branch, see the checks above to make this safer
210
+ }
211
+ catch (error) {
212
+ log.error(st('red', 'updating git failed:'), print_error(error));
213
+ throw new TaskError(`Deploy failed in a bad state: built but not pushed, see error above.`);
214
+ }
215
+ log.info(st('green', 'deployed')); // TODO log a different message if "Everything up-to-date"
216
+ },
217
+ };
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ import type { Task } from './task.ts';
3
+ import { type PluginContext } from './plugin.ts';
4
+ /** @nodocs */
5
+ export declare const Args: z.ZodObject<{
6
+ watch: z.ZodDefault<z.ZodBoolean>;
7
+ 'no-watch': z.ZodDefault<z.ZodBoolean>;
8
+ sync: z.ZodDefault<z.ZodBoolean>;
9
+ 'no-sync': z.ZodDefault<z.ZodBoolean>;
10
+ install: z.ZodDefault<z.ZodBoolean>;
11
+ }, z.core.$strict>;
12
+ export type Args = z.infer<typeof Args>;
13
+ export type DevTaskContext = PluginContext<Args>;
14
+ /** @nodocs */
15
+ export declare const task: Task<Args>;
16
+ //# sourceMappingURL=dev.task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/dev.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AACpC,OAAO,EAAU,KAAK,aAAa,EAAC,MAAM,aAAa,CAAC;AAGxD,cAAc;AACd,eAAO,MAAM,IAAI;;;;;;kBAWf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;AAEjD,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA2B3B,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { z } from 'zod';
2
+ import { Plugins } from "./plugin.js";
3
+ import { clean_fs } from "./clean_fs.js";
4
+ /** @nodocs */
5
+ export const Args = z.strictObject({
6
+ watch: z.boolean().meta({ description: 'dual of no-watch' }).default(true),
7
+ 'no-watch': z
8
+ .boolean()
9
+ .meta({
10
+ description: 'opt out of running a long-lived process to watch files and rebuild on changes',
11
+ })
12
+ .default(false),
13
+ sync: z.boolean().meta({ description: 'dual of no-sync' }).default(true),
14
+ 'no-sync': z.boolean().meta({ description: 'opt out of gro sync' }).default(false),
15
+ install: z.boolean().meta({ description: 'opt into installing packages' }).default(false),
16
+ });
17
+ /** @nodocs */
18
+ export const task = {
19
+ summary: 'start SvelteKit and other dev plugins',
20
+ Args,
21
+ run: async (ctx) => {
22
+ const { args, invoke_task, log } = ctx;
23
+ const { watch, sync, install } = args;
24
+ await clean_fs({ build_dev: true });
25
+ if (sync || install) {
26
+ if (!sync)
27
+ log.warn('sync is false but install is true, so ignoring the sync option');
28
+ await invoke_task('sync', { install, gen: !watch });
29
+ }
30
+ const plugins = await Plugins.create({ ...ctx, dev: true, watch });
31
+ await plugins.setup();
32
+ if (!watch) {
33
+ await plugins.teardown();
34
+ }
35
+ else {
36
+ // TODO maybe redesign for this API to be explicitly cancelable?
37
+ // Keep the task running indefinitely in watch mode.
38
+ // This prevents invoke_task from calling finish() and closing the filer.
39
+ await new Promise(() => {
40
+ // Never resolves - keeps filer and listeners alive.
41
+ });
42
+ }
43
+ },
44
+ };
@@ -0,0 +1,23 @@
1
+ import type { PathId } from '@fuzdev/fuz_util/path.js';
2
+ export interface Disknode {
3
+ id: PathId;
4
+ /**
5
+ * `null` contents means it doesn't exist.
6
+ * We create the file in memory to track its dependents regardless of its existence on disk.
7
+ */
8
+ contents: string | null;
9
+ /**
10
+ * Is the source file outside of the `root_dir` or excluded by `watch_dir_options.filter`?
11
+ */
12
+ external: boolean;
13
+ ctime: number | null;
14
+ mtime: number | null;
15
+ /**
16
+ * SHA-256 hash of `contents`. `null` iff `contents` is `null`.
17
+ * Used for content-based change detection and caching.
18
+ */
19
+ content_hash: string | null;
20
+ dependents: Map<PathId, Disknode>;
21
+ dependencies: Map<PathId, Disknode>;
22
+ }
23
+ //# sourceMappingURL=disknode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disknode.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/disknode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAIrD,MAAM,WAAW,QAAQ;IACxB,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;OAGG;IACH,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CACpC"}
@@ -0,0 +1 @@
1
+ export {};
package/dist/env.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export declare const load_env: (dev: boolean, visibility: "public" | "private", public_prefix: string, private_prefix: string, env_dir?: string, env_files?: string[], ambient_env?: NodeJS.ProcessEnv) => Record<string, string>;
2
+ /**
3
+ * Loads a single env value without merging it into `process.env`.
4
+ * By default searches process.env, then a local `.env` if one exists, then `../.env` if it exists.
5
+ * Empty strings are semantically the same as `undefined` for more ergonomic fallbacks.
6
+ */
7
+ export declare const load_from_env: (key: string, paths?: string[]) => string | undefined;
8
+ export declare const merge_envs: (envs: Array<Record<string, string | undefined>>, visibility: "public" | "private", public_prefix: string, private_prefix: string) => Record<string, string>;
9
+ export declare const is_private_env: (key: string, public_prefix: string, private_prefix: string) => boolean;
10
+ export declare const is_public_env: (key: string, public_prefix: string, private_prefix: string) => boolean;
11
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/env.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,QAAQ,GACpB,KAAK,OAAO,EACZ,YAAY,QAAQ,GAAG,SAAS,EAChC,eAAe,MAAM,EACrB,gBAAgB,MAAM,EACtB,UAAU,MAAM,EAChB,oBAAoE,EACpE,+BAAyB,KACvB,MAAM,CAAC,MAAM,EAAE,MAAM,CAMvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,gBAA2B,KAAG,MAAM,GAAG,SASjF,CAAC;AAQF,eAAO,MAAM,UAAU,GACtB,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EAC/C,YAAY,QAAQ,GAAG,SAAS,EAChC,eAAe,MAAM,EACrB,gBAAgB,MAAM,KACpB,MAAM,CAAC,MAAM,EAAE,MAAM,CAgBvB,CAAC;AAEF,eAAO,MAAM,cAAc,GAC1B,KAAK,MAAM,EACX,eAAe,MAAM,EACrB,gBAAgB,MAAM,KACpB,OACwF,CAAC;AAE5F,eAAO,MAAM,aAAa,GACzB,KAAK,MAAM,EACX,eAAe,MAAM,EACrB,gBAAgB,MAAM,KACpB,OACyF,CAAC"}
package/dist/env.js ADDED
@@ -0,0 +1,49 @@
1
+ import dotenv from 'dotenv';
2
+ import { resolve } from 'node:path';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ export const load_env = (dev, visibility, public_prefix, private_prefix, env_dir, env_files = ['.env', '.env.' + (dev ? 'development' : 'production')], ambient_env = process.env) => {
5
+ const envs = env_files
6
+ .map((path) => load(env_dir === undefined ? path : resolve(env_dir, path)))
7
+ .filter((v) => v !== undefined);
8
+ envs.push(ambient_env);
9
+ return merge_envs(envs, visibility, public_prefix, private_prefix);
10
+ };
11
+ /**
12
+ * Loads a single env value without merging it into `process.env`.
13
+ * By default searches process.env, then a local `.env` if one exists, then `../.env` if it exists.
14
+ * Empty strings are semantically the same as `undefined` for more ergonomic fallbacks.
15
+ */
16
+ export const load_from_env = (key, paths = ['.env', '../.env']) => {
17
+ let v = process.env[key];
18
+ if (v)
19
+ return v;
20
+ for (const path of paths) {
21
+ const env = load(path);
22
+ v = env?.[key];
23
+ if (v)
24
+ return v;
25
+ }
26
+ return undefined;
27
+ };
28
+ const load = (path) => {
29
+ if (!existsSync(path))
30
+ return;
31
+ const loaded = readFileSync(path, 'utf8');
32
+ return dotenv.parse(loaded);
33
+ };
34
+ export const merge_envs = (envs, visibility, public_prefix, private_prefix) => {
35
+ const env = {};
36
+ for (const e of envs) {
37
+ for (const key in e) {
38
+ if ((visibility === 'private' && is_private_env(key, public_prefix, private_prefix)) ||
39
+ (visibility === 'public' && is_public_env(key, public_prefix, private_prefix))) {
40
+ const value = e[key];
41
+ if (value !== undefined)
42
+ env[key] = value;
43
+ }
44
+ }
45
+ }
46
+ return env;
47
+ };
48
+ export const is_private_env = (key, public_prefix, private_prefix) => key.startsWith(private_prefix) && (public_prefix === '' || !key.startsWith(public_prefix));
49
+ export const is_public_env = (key, public_prefix, private_prefix) => key.startsWith(public_prefix) && (private_prefix === '' || !key.startsWith(private_prefix));
@@ -0,0 +1,16 @@
1
+ import type { Logger } from '@fuzdev/fuz_util/log.js';
2
+ import type * as esbuild from 'esbuild';
3
+ import type { ParsedSvelteConfig } from './svelte_config.ts';
4
+ export declare const print_build_result: (log: Logger, build_result: esbuild.BuildResult) => void;
5
+ /**
6
+ * Creates an esbuild `define` shim for Vite's `import.meta\.env`.
7
+ * @see https://esbuild.github.io/api/#define
8
+ * @param dev
9
+ * @param base_url - best-effort shim from SvelteKit's `base` to Vite's `import.meta\.env.BASE_URL`
10
+ * @param ssr
11
+ * @param mode
12
+ * @returns
13
+ */
14
+ export declare const to_define_import_meta_env: (dev: boolean, base_url: ParsedSvelteConfig["base_url"], ssr?: boolean, mode?: string) => Record<string, string>;
15
+ export declare const default_ts_transform_options: esbuild.TransformOptions;
16
+ //# sourceMappingURL=esbuild_helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/esbuild_helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAExC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAE3D,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,EAAE,cAAc,OAAO,CAAC,WAAW,KAAG,IAOnF,CAAC;AAMF;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,GACrC,KAAK,OAAO,EACZ,UAAU,kBAAkB,CAAC,UAAU,CAAC,EACxC,aAAU,EACV,aAAyC,KACvC,MAAM,CAAC,MAAM,EAAE,MAAM,CAQtB,CAAC;AAEH,eAAO,MAAM,4BAA4B,EAAE,OAAO,CAAC,gBAKlD,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { styleText as st } from 'node:util';
2
+ export const print_build_result = (log, build_result) => {
3
+ for (const error of build_result.errors) {
4
+ log.error(st('red', 'esbuild error'), error);
5
+ }
6
+ for (const warning of build_result.warnings) {
7
+ log.warn(st('yellow', 'esbuild warning'), warning);
8
+ }
9
+ };
10
+ // This concatenates weirdly to avoid a SvelteKit warning,
11
+ // because SvelteKit detects usage as a string and not the AST.
12
+ const import_meta_env = 'import.' + 'meta.env.'; // eslint-disable-line no-useless-concat
13
+ /**
14
+ * Creates an esbuild `define` shim for Vite's `import.meta\.env`.
15
+ * @see https://esbuild.github.io/api/#define
16
+ * @param dev
17
+ * @param base_url - best-effort shim from SvelteKit's `base` to Vite's `import.meta\.env.BASE_URL`
18
+ * @param ssr
19
+ * @param mode
20
+ * @returns
21
+ */
22
+ export const to_define_import_meta_env = (dev, base_url, ssr = true, mode = dev ? 'development' : 'production') => ({
23
+ // see `import_meta_env` for why this is defined weirdly instead of statically
24
+ [import_meta_env + 'DEV']: JSON.stringify(dev),
25
+ [import_meta_env + 'PROD']: JSON.stringify(!dev),
26
+ [import_meta_env + 'SSR']: JSON.stringify(ssr),
27
+ [import_meta_env + 'MODE']: JSON.stringify(mode),
28
+ // it appears SvelteKit's `''` translates to Vite's `'/'`, so this intentionally falls back for falsy values, not just undefined
29
+ [import_meta_env + 'BASE_URL']: JSON.stringify(base_url || '/'),
30
+ });
31
+ export const default_ts_transform_options = {
32
+ target: 'esnext', // TODO load local tsconfig
33
+ format: 'esm',
34
+ loader: 'ts',
35
+ charset: 'utf8',
36
+ };
@@ -0,0 +1,23 @@
1
+ import * as esbuild from 'esbuild';
2
+ import type { Logger } from '@fuzdev/fuz_util/log.js';
3
+ import type { CompileOptions, ModuleCompileOptions, PreprocessorGroup } from 'svelte/compiler';
4
+ import type { ParsedSvelteConfig } from './svelte_config.ts';
5
+ export interface EsbuildPluginExternalWorkerOptions {
6
+ dev: boolean;
7
+ build_options: esbuild.BuildOptions;
8
+ dir?: string;
9
+ svelte_compile_options?: CompileOptions;
10
+ svelte_compile_module_options?: ModuleCompileOptions;
11
+ svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
12
+ alias?: Record<string, string>;
13
+ base_url?: ParsedSvelteConfig['base_url'];
14
+ assets_url?: ParsedSvelteConfig['assets_url'];
15
+ public_prefix?: string;
16
+ private_prefix?: string;
17
+ env_dir?: string;
18
+ env_files?: Array<string>;
19
+ ambient_env?: Record<string, string>;
20
+ log?: Logger;
21
+ }
22
+ export declare const esbuild_plugin_external_worker: ({ dev, build_options, dir, svelte_compile_options, svelte_compile_module_options, svelte_preprocessors, alias, base_url, assets_url, public_prefix, private_prefix, env_dir, env_files, ambient_env, log, }: EsbuildPluginExternalWorkerOptions) => esbuild.Plugin;
23
+ //# sourceMappingURL=esbuild_plugin_external_worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild_plugin_external_worker.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/esbuild_plugin_external_worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAC,cAAc,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAU7F,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAE3D,MAAM,WAAW,kCAAkC;IAClD,GAAG,EAAE,OAAO,CAAC;IACb,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,6BAA6B,CAAC,EAAE,oBAAoB,CAAC;IACrD,oBAAoB,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,8BAA8B,GAAI,6MAgB5C,kCAAkC,KAAG,OAAO,CAAC,MA4C9C,CAAC"}
@@ -0,0 +1,55 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { basename } from 'node:path';
3
+ import { print_build_result, to_define_import_meta_env } from "./esbuild_helpers.js";
4
+ import { resolve_specifier } from "./resolve_specifier.js";
5
+ import { esbuild_plugin_sveltekit_shim_alias } from "./esbuild_plugin_sveltekit_shim_alias.js";
6
+ import { esbuild_plugin_sveltekit_shim_env } from "./esbuild_plugin_sveltekit_shim_env.js";
7
+ import { esbuild_plugin_sveltekit_shim_app } from "./esbuild_plugin_sveltekit_shim_app.js";
8
+ import { esbuild_plugin_sveltekit_local_imports } from "./esbuild_plugin_sveltekit_local_imports.js";
9
+ import { esbuild_plugin_svelte } from "./esbuild_plugin_svelte.js";
10
+ export const esbuild_plugin_external_worker = ({ dev, build_options, dir = process.cwd(), svelte_compile_options, svelte_compile_module_options, svelte_preprocessors, alias, base_url, assets_url, public_prefix, private_prefix, env_dir, env_files, ambient_env, log, }) => ({
11
+ name: 'external_worker',
12
+ setup: (build) => {
13
+ const builds = new Map();
14
+ const build_worker = async (path_id) => {
15
+ if (builds.has(path_id))
16
+ return builds.get(path_id);
17
+ const building = esbuild.build({
18
+ entryPoints: [path_id],
19
+ plugins: [
20
+ esbuild_plugin_sveltekit_shim_app({ dev, base_url, assets_url }),
21
+ esbuild_plugin_sveltekit_shim_env({
22
+ dev,
23
+ public_prefix,
24
+ private_prefix,
25
+ env_dir,
26
+ env_files,
27
+ ambient_env,
28
+ }),
29
+ esbuild_plugin_sveltekit_shim_alias({ dir, alias }),
30
+ esbuild_plugin_svelte({
31
+ dev,
32
+ base_url,
33
+ dir,
34
+ svelte_compile_options,
35
+ svelte_compile_module_options,
36
+ svelte_preprocessors,
37
+ }),
38
+ esbuild_plugin_sveltekit_local_imports(),
39
+ ],
40
+ define: to_define_import_meta_env(dev, base_url),
41
+ ...build_options,
42
+ });
43
+ builds.set(path_id, building);
44
+ return building;
45
+ };
46
+ build.onResolve({ filter: /\.worker(|\.js|\.ts)$/ }, async ({ path, resolveDir }) => {
47
+ const parsed = await resolve_specifier(path, resolveDir);
48
+ const { specifier, path_id, namespace } = parsed;
49
+ const build_result = await build_worker(path_id);
50
+ if (log)
51
+ print_build_result(log, build_result);
52
+ return { path: './' + basename(specifier), external: true, namespace };
53
+ });
54
+ },
55
+ });
@@ -0,0 +1,15 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { type CompileOptions, type ModuleCompileOptions, type PreprocessorGroup } from 'svelte/compiler';
3
+ import { type ParsedSvelteConfig } from './svelte_config.ts';
4
+ export interface EsbuildPluginSvelteOptions {
5
+ dev: boolean;
6
+ base_url: ParsedSvelteConfig['base_url'];
7
+ dir?: string;
8
+ svelte_compile_options?: CompileOptions;
9
+ svelte_compile_module_options?: ModuleCompileOptions;
10
+ svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
11
+ ts_transform_options?: esbuild.TransformOptions;
12
+ is_ts?: (filename: string) => boolean;
13
+ }
14
+ export declare const esbuild_plugin_svelte: (options: EsbuildPluginSvelteOptions) => esbuild.Plugin;
15
+ //# sourceMappingURL=esbuild_plugin_svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild_plugin_svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/esbuild_plugin_svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAIN,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACtB,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EAGN,KAAK,kBAAkB,EACvB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,WAAW,0BAA0B;IAC1C,GAAG,EAAE,OAAO,CAAC;IACb,QAAQ,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,6BAA6B,CAAC,EAAE,oBAAoB,CAAC;IACrD,oBAAoB,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACpE,oBAAoB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC;IAChD,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CACtC;AAED,eAAO,MAAM,qBAAqB,GAAI,SAAS,0BAA0B,KAAG,OAAO,CAAC,MAmEnF,CAAC"}
@@ -0,0 +1,83 @@
1
+ import * as esbuild from 'esbuild';
2
+ import { compile, compileModule, preprocess, } from 'svelte/compiler';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { relative } from 'node:path';
5
+ import { to_define_import_meta_env, default_ts_transform_options } from "./esbuild_helpers.js";
6
+ import { default_svelte_config, to_default_compile_module_options, } from "./svelte_config.js";
7
+ import { TS_MATCHER, SVELTE_MATCHER, SVELTE_RUNES_MATCHER } from "./constants.js";
8
+ export const esbuild_plugin_svelte = (options) => {
9
+ const { dev, base_url, dir = process.cwd(), svelte_compile_options = default_svelte_config.svelte_compile_options, svelte_compile_module_options = to_default_compile_module_options(svelte_compile_options), svelte_preprocessors, ts_transform_options = default_ts_transform_options, is_ts = (f) => TS_MATCHER.test(f), } = options;
10
+ const final_ts_transform_options = {
11
+ ...ts_transform_options,
12
+ define: to_define_import_meta_env(dev, base_url),
13
+ sourcemap: 'inline',
14
+ };
15
+ return {
16
+ name: 'svelte',
17
+ setup: (build) => {
18
+ build.onLoad({ filter: SVELTE_RUNES_MATCHER }, async ({ path }) => {
19
+ const source = await readFile(path, 'utf8');
20
+ try {
21
+ const filename = relative(dir, path);
22
+ const js_source = is_ts(filename)
23
+ ? (await esbuild.transform(source, {
24
+ ...final_ts_transform_options,
25
+ sourcefile: filename,
26
+ })).code // TODO @many use warnings? handle not-inline sourcemaps?
27
+ : source;
28
+ const { js, warnings } = compileModule(js_source, {
29
+ ...svelte_compile_module_options,
30
+ filename,
31
+ });
32
+ const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
33
+ return {
34
+ contents,
35
+ warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
36
+ };
37
+ }
38
+ catch (error) {
39
+ return { errors: [convert_svelte_message_to_esbuild(path, source, error)] };
40
+ }
41
+ });
42
+ build.onLoad({ filter: SVELTE_MATCHER }, async ({ path }) => {
43
+ let source = await readFile(path, 'utf8');
44
+ try {
45
+ const filename = relative(dir, path);
46
+ const preprocessed = svelte_preprocessors
47
+ ? await preprocess(source, svelte_preprocessors, { filename })
48
+ : null;
49
+ if (preprocessed?.code)
50
+ source = preprocessed.code;
51
+ const { js, warnings } = compile(source, { ...svelte_compile_options, filename });
52
+ const contents = js.code + '//# sourceMappingURL=' + js.map.toUrl();
53
+ return {
54
+ contents,
55
+ warnings: warnings.map((w) => convert_svelte_message_to_esbuild(filename, source, w)),
56
+ };
57
+ }
58
+ catch (error) {
59
+ return { errors: [convert_svelte_message_to_esbuild(path, source, error)] };
60
+ }
61
+ });
62
+ },
63
+ };
64
+ };
65
+ /**
66
+ * Following the example in the esbuild docs:
67
+ * https://esbuild.github.io/plugins/#svelte-plugin
68
+ */
69
+ const convert_svelte_message_to_esbuild = (path, source, { message, start, end }) => {
70
+ let location = null;
71
+ if (start && end) {
72
+ const lineText = source.split(/\r\n|\r|\n/g)[start.line - 1] ?? '';
73
+ const lineEnd = start.line === end.line ? end.column : lineText.length;
74
+ location = {
75
+ file: path,
76
+ line: start.line,
77
+ lineText,
78
+ column: start.column,
79
+ length: lineEnd - start.column,
80
+ };
81
+ }
82
+ return { text: message, location };
83
+ };
@@ -0,0 +1,8 @@
1
+ import type * as esbuild from 'esbuild';
2
+ /**
3
+ * Adds support for imports to both `.ts` and `.js`,
4
+ * as well as imports without extensions that resolve to `.js` or `.ts`.
5
+ * Prefers `.ts` over any `.js`, and falls back to `.ts` if no file is found.
6
+ */
7
+ export declare const esbuild_plugin_sveltekit_local_imports: () => esbuild.Plugin;
8
+ //# sourceMappingURL=esbuild_plugin_sveltekit_local_imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild_plugin_sveltekit_local_imports.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/esbuild_plugin_sveltekit_local_imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,CAAC;AAOxC;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,QAAO,OAAO,CAAC,MAyBhE,CAAC"}