@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.
- package/LICENSE +21 -0
- package/README.md +283 -0
- package/dist/args.d.ts +37 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +102 -0
- package/dist/build.task.d.ts +20 -0
- package/dist/build.task.d.ts.map +1 -0
- package/dist/build.task.js +119 -0
- package/dist/build_cache.d.ts +100 -0
- package/dist/build_cache.d.ts.map +1 -0
- package/dist/build_cache.js +299 -0
- package/dist/changelog.d.ts +11 -0
- package/dist/changelog.d.ts.map +1 -0
- package/dist/changelog.js +47 -0
- package/dist/changeset.task.d.ts +35 -0
- package/dist/changeset.task.d.ts.map +1 -0
- package/dist/changeset.task.js +151 -0
- package/dist/changeset_helpers.d.ts +17 -0
- package/dist/changeset_helpers.d.ts.map +1 -0
- package/dist/changeset_helpers.js +7 -0
- package/dist/check.task.d.ts +28 -0
- package/dist/check.task.d.ts.map +1 -0
- package/dist/check.task.js +104 -0
- package/dist/child_process_logging.d.ts +10 -0
- package/dist/child_process_logging.d.ts.map +1 -0
- package/dist/child_process_logging.js +26 -0
- package/dist/clean.task.d.ts +15 -0
- package/dist/clean.task.d.ts.map +1 -0
- package/dist/clean.task.js +40 -0
- package/dist/clean_fs.d.ts +9 -0
- package/dist/clean_fs.d.ts.map +1 -0
- package/dist/clean_fs.js +28 -0
- package/dist/cli.d.ts +34 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +61 -0
- package/dist/commit.task.d.ts +11 -0
- package/dist/commit.task.d.ts.map +1 -0
- package/dist/commit.task.js +24 -0
- package/dist/constants.d.ts +46 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +52 -0
- package/dist/deploy.task.d.ts +29 -0
- package/dist/deploy.task.d.ts.map +1 -0
- package/dist/deploy.task.js +217 -0
- package/dist/dev.task.d.ts +16 -0
- package/dist/dev.task.d.ts.map +1 -0
- package/dist/dev.task.js +44 -0
- package/dist/disknode.d.ts +23 -0
- package/dist/disknode.d.ts.map +1 -0
- package/dist/disknode.js +1 -0
- package/dist/env.d.ts +11 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +49 -0
- package/dist/esbuild_helpers.d.ts +16 -0
- package/dist/esbuild_helpers.d.ts.map +1 -0
- package/dist/esbuild_helpers.js +36 -0
- package/dist/esbuild_plugin_external_worker.d.ts +23 -0
- package/dist/esbuild_plugin_external_worker.d.ts.map +1 -0
- package/dist/esbuild_plugin_external_worker.js +55 -0
- package/dist/esbuild_plugin_svelte.d.ts +15 -0
- package/dist/esbuild_plugin_svelte.d.ts.map +1 -0
- package/dist/esbuild_plugin_svelte.js +83 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.d.ts +8 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.js +30 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +7 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.js +18 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +9 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.js +22 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +11 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts.map +1 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.js +18 -0
- package/dist/filer.d.ts +33 -0
- package/dist/filer.d.ts.map +1 -0
- package/dist/filer.js +385 -0
- package/dist/format.task.d.ts +11 -0
- package/dist/format.task.d.ts.map +1 -0
- package/dist/format.task.js +27 -0
- package/dist/format_directory.d.ts +13 -0
- package/dist/format_directory.d.ts.map +1 -0
- package/dist/format_directory.js +40 -0
- package/dist/format_file.d.ts +9 -0
- package/dist/format_file.d.ts.map +1 -0
- package/dist/format_file.js +42 -0
- package/dist/gen.d.ts +142 -0
- package/dist/gen.d.ts.map +1 -0
- package/dist/gen.js +199 -0
- package/dist/gen.task.d.ts +12 -0
- package/dist/gen.task.d.ts.map +1 -0
- package/dist/gen.task.js +149 -0
- package/dist/gen_helpers.d.ts +11 -0
- package/dist/gen_helpers.d.ts.map +1 -0
- package/dist/gen_helpers.js +76 -0
- package/dist/github.d.ts +19 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/github.js +33 -0
- package/dist/gro.config.default.d.ts +13 -0
- package/dist/gro.config.default.d.ts.map +1 -0
- package/dist/gro.config.default.js +33 -0
- package/dist/gro.d.ts +3 -0
- package/dist/gro.d.ts.map +1 -0
- package/dist/gro.js +21 -0
- package/dist/gro_config.d.ts +115 -0
- package/dist/gro_config.d.ts.map +1 -0
- package/dist/gro_config.js +114 -0
- package/dist/gro_helpers.d.ts +49 -0
- package/dist/gro_helpers.d.ts.map +1 -0
- package/dist/gro_helpers.js +97 -0
- package/dist/gro_plugin_gen.d.ts +12 -0
- package/dist/gro_plugin_gen.d.ts.map +1 -0
- package/dist/gro_plugin_gen.js +101 -0
- package/dist/gro_plugin_server.d.ts +80 -0
- package/dist/gro_plugin_server.d.ts.map +1 -0
- package/dist/gro_plugin_server.js +167 -0
- package/dist/gro_plugin_sveltekit_app.d.ts +9 -0
- package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -0
- package/dist/gro_plugin_sveltekit_app.js +42 -0
- package/dist/gro_plugin_sveltekit_library.d.ts +16 -0
- package/dist/gro_plugin_sveltekit_library.d.ts.map +1 -0
- package/dist/gro_plugin_sveltekit_library.js +34 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/input_path.d.ts +64 -0
- package/dist/input_path.d.ts.map +1 -0
- package/dist/input_path.js +199 -0
- package/dist/invoke.d.ts +2 -0
- package/dist/invoke.d.ts.map +1 -0
- package/dist/invoke.js +28 -0
- package/dist/invoke_task.d.ts +30 -0
- package/dist/invoke_task.d.ts.map +1 -0
- package/dist/invoke_task.js +104 -0
- package/dist/lint.task.d.ts +11 -0
- package/dist/lint.task.d.ts.map +1 -0
- package/dist/lint.task.js +32 -0
- package/dist/loader.d.ts +6 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +192 -0
- package/dist/module.d.ts +4 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +6 -0
- package/dist/modules.d.ts +36 -0
- package/dist/modules.d.ts.map +1 -0
- package/dist/modules.js +71 -0
- package/dist/package_json.d.ts +32 -0
- package/dist/package_json.d.ts.map +1 -0
- package/dist/package_json.js +178 -0
- package/dist/parse_exports.d.ts +20 -0
- package/dist/parse_exports.d.ts.map +1 -0
- package/dist/parse_exports.js +65 -0
- package/dist/parse_exports_context.d.ts +21 -0
- package/dist/parse_exports_context.d.ts.map +1 -0
- package/dist/parse_exports_context.js +332 -0
- package/dist/parse_imports.d.ts +5 -0
- package/dist/parse_imports.d.ts.map +1 -0
- package/dist/parse_imports.js +140 -0
- package/dist/paths.d.ts +41 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +69 -0
- package/dist/plugin.d.ts +36 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +78 -0
- package/dist/publish.task.d.ts +26 -0
- package/dist/publish.task.d.ts.map +1 -0
- package/dist/publish.task.js +176 -0
- package/dist/register.d.ts +2 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/register.js +2 -0
- package/dist/reinstall.task.d.ts +8 -0
- package/dist/reinstall.task.d.ts.map +1 -0
- package/dist/reinstall.task.js +35 -0
- package/dist/release.task.d.ts +8 -0
- package/dist/release.task.d.ts.map +1 -0
- package/dist/release.task.js +20 -0
- package/dist/resolve.task.d.ts +11 -0
- package/dist/resolve.task.d.ts.map +1 -0
- package/dist/resolve.task.js +38 -0
- package/dist/resolve_specifier.d.ts +22 -0
- package/dist/resolve_specifier.d.ts.map +1 -0
- package/dist/resolve_specifier.js +57 -0
- package/dist/run.task.d.ts +16 -0
- package/dist/run.task.d.ts.map +1 -0
- package/dist/run.task.js +52 -0
- package/dist/run_gen.d.ts +10 -0
- package/dist/run_gen.d.ts.map +1 -0
- package/dist/run_gen.js +73 -0
- package/dist/run_task.d.ts +17 -0
- package/dist/run_task.d.ts.map +1 -0
- package/dist/run_task.js +45 -0
- package/dist/source_json.d.ts +7 -0
- package/dist/source_json.d.ts.map +1 -0
- package/dist/source_json.js +145 -0
- package/dist/svelte_config.d.ts +57 -0
- package/dist/svelte_config.d.ts.map +1 -0
- package/dist/svelte_config.js +81 -0
- package/dist/sveltekit_helpers.d.ts +75 -0
- package/dist/sveltekit_helpers.d.ts.map +1 -0
- package/dist/sveltekit_helpers.js +94 -0
- package/dist/sveltekit_shim_app.d.ts +11 -0
- package/dist/sveltekit_shim_app.d.ts.map +1 -0
- package/dist/sveltekit_shim_app.js +31 -0
- package/dist/sveltekit_shim_app_environment.d.ts +13 -0
- package/dist/sveltekit_shim_app_environment.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_environment.js +14 -0
- package/dist/sveltekit_shim_app_forms.d.ts +5 -0
- package/dist/sveltekit_shim_app_forms.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_forms.js +6 -0
- package/dist/sveltekit_shim_app_navigation.d.ts +10 -0
- package/dist/sveltekit_shim_app_navigation.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_navigation.js +11 -0
- package/dist/sveltekit_shim_app_paths.d.ts +17 -0
- package/dist/sveltekit_shim_app_paths.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_paths.js +10 -0
- package/dist/sveltekit_shim_app_state.d.ts +5 -0
- package/dist/sveltekit_shim_app_state.d.ts.map +1 -0
- package/dist/sveltekit_shim_app_state.js +26 -0
- package/dist/sveltekit_shim_env.d.ts +5 -0
- package/dist/sveltekit_shim_env.d.ts.map +1 -0
- package/dist/sveltekit_shim_env.js +23 -0
- package/dist/sync.task.d.ts +16 -0
- package/dist/sync.task.d.ts.map +1 -0
- package/dist/sync.task.js +39 -0
- package/dist/task.d.ts +98 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +109 -0
- package/dist/task_logging.d.ts +6 -0
- package/dist/task_logging.d.ts.map +1 -0
- package/dist/task_logging.js +201 -0
- package/dist/test.task.d.ts +13 -0
- package/dist/test.task.d.ts.map +1 -0
- package/dist/test.task.js +53 -0
- package/dist/typecheck.task.d.ts +13 -0
- package/dist/typecheck.task.d.ts.map +1 -0
- package/dist/typecheck.task.js +68 -0
- package/dist/upgrade.task.d.ts +20 -0
- package/dist/upgrade.task.d.ts.map +1 -0
- package/dist/upgrade.task.js +111 -0
- package/dist/watch_dir.d.ts +36 -0
- package/dist/watch_dir.d.ts.map +1 -0
- package/dist/watch_dir.js +69 -0
- package/package.json +149 -0
- package/src/lib/args.ts +115 -0
- package/src/lib/build.task.ts +151 -0
- package/src/lib/build_cache.ts +378 -0
- package/src/lib/changelog.ts +69 -0
- package/src/lib/changeset.task.ts +228 -0
- package/src/lib/changeset_helpers.ts +14 -0
- package/src/lib/check.task.ts +132 -0
- package/src/lib/child_process_logging.ts +38 -0
- package/src/lib/clean.task.ts +48 -0
- package/src/lib/clean_fs.ts +54 -0
- package/src/lib/cli.ts +98 -0
- package/src/lib/commit.task.ts +34 -0
- package/src/lib/constants.ts +56 -0
- package/src/lib/deploy.task.ts +287 -0
- package/src/lib/dev.task.ts +52 -0
- package/src/lib/disknode.ts +26 -0
- package/src/lib/env.ts +78 -0
- package/src/lib/esbuild_helpers.ts +49 -0
- package/src/lib/esbuild_plugin_external_worker.ts +94 -0
- package/src/lib/esbuild_plugin_svelte.ts +134 -0
- package/src/lib/esbuild_plugin_sveltekit_local_imports.ts +38 -0
- package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +27 -0
- package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +42 -0
- package/src/lib/esbuild_plugin_sveltekit_shim_env.ts +47 -0
- package/src/lib/filer.ts +458 -0
- package/src/lib/format.task.ts +44 -0
- package/src/lib/format_directory.ts +65 -0
- package/src/lib/format_file.ts +49 -0
- package/src/lib/gen.task.ts +206 -0
- package/src/lib/gen.ts +406 -0
- package/src/lib/gen_helpers.ts +131 -0
- package/src/lib/github.ts +46 -0
- package/src/lib/gro.config.default.ts +42 -0
- package/src/lib/gro.ts +29 -0
- package/src/lib/gro_config.ts +254 -0
- package/src/lib/gro_helpers.ts +108 -0
- package/src/lib/gro_plugin_gen.ts +149 -0
- package/src/lib/gro_plugin_server.ts +288 -0
- package/src/lib/gro_plugin_sveltekit_app.ts +58 -0
- package/src/lib/gro_plugin_sveltekit_library.ts +63 -0
- package/src/lib/index.ts +8 -0
- package/src/lib/input_path.ts +254 -0
- package/src/lib/invoke.ts +34 -0
- package/src/lib/invoke_task.ts +139 -0
- package/src/lib/lint.task.ts +39 -0
- package/src/lib/loader.ts +229 -0
- package/src/lib/module.ts +13 -0
- package/src/lib/modules.ts +117 -0
- package/src/lib/package_json.ts +255 -0
- package/src/lib/parse_exports.ts +100 -0
- package/src/lib/parse_exports_context.ts +395 -0
- package/src/lib/parse_imports.ts +180 -0
- package/src/lib/paths.ts +111 -0
- package/src/lib/plugin.ts +106 -0
- package/src/lib/publish.task.ts +228 -0
- package/src/lib/register.ts +3 -0
- package/src/lib/reinstall.task.ts +45 -0
- package/src/lib/release.task.ts +26 -0
- package/src/lib/resolve.task.ts +43 -0
- package/src/lib/resolve_specifier.ts +81 -0
- package/src/lib/run.task.ts +65 -0
- package/src/lib/run_gen.ts +110 -0
- package/src/lib/run_task.ts +82 -0
- package/src/lib/source_json.ts +183 -0
- package/src/lib/svelte_config.ts +140 -0
- package/src/lib/sveltekit_helpers.ts +193 -0
- package/src/lib/sveltekit_shim_app.ts +41 -0
- package/src/lib/sveltekit_shim_app_environment.ts +16 -0
- package/src/lib/sveltekit_shim_app_forms.ts +13 -0
- package/src/lib/sveltekit_shim_app_navigation.ts +23 -0
- package/src/lib/sveltekit_shim_app_paths.ts +26 -0
- package/src/lib/sveltekit_shim_app_state.ts +35 -0
- package/src/lib/sveltekit_shim_env.ts +45 -0
- package/src/lib/sync.task.ts +47 -0
- package/src/lib/task.ts +245 -0
- package/src/lib/task_logging.ts +255 -0
- package/src/lib/test.task.ts +63 -0
- package/src/lib/typecheck.task.ts +81 -0
- package/src/lib/upgrade.task.ts +148 -0
- package/src/lib/watch_dir.ts +115 -0
|
@@ -0,0 +1,287 @@
|
|
|
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 {
|
|
9
|
+
git_check_clean_workspace,
|
|
10
|
+
git_checkout,
|
|
11
|
+
git_local_branch_exists,
|
|
12
|
+
git_remote_branch_exists,
|
|
13
|
+
GitOrigin,
|
|
14
|
+
GitBranch,
|
|
15
|
+
git_delete_local_branch,
|
|
16
|
+
git_push_to_create,
|
|
17
|
+
git_reset_branch_to_first_commit,
|
|
18
|
+
git_pull,
|
|
19
|
+
git_fetch,
|
|
20
|
+
git_check_setting_pull_rebase,
|
|
21
|
+
git_clone_locally,
|
|
22
|
+
git_current_branch_name,
|
|
23
|
+
} from '@fuzdev/fuz_util/git.js';
|
|
24
|
+
|
|
25
|
+
import {TaskError, type Task} from './task.ts';
|
|
26
|
+
import {print_path} from './paths.ts';
|
|
27
|
+
import {GRO_DIRNAME, GIT_DIRNAME, SVELTEKIT_BUILD_DIRNAME} from './constants.ts';
|
|
28
|
+
|
|
29
|
+
// docs at ../docs/deploy.md
|
|
30
|
+
|
|
31
|
+
// terminal command for testing:
|
|
32
|
+
// npm run bootstrap && rm -rf .gro && clear && gro deploy --source no-git-workspace --no-build --dry
|
|
33
|
+
|
|
34
|
+
// TODO customize
|
|
35
|
+
const dir = process.cwd();
|
|
36
|
+
const INITIAL_FILE_PATH = '.gitkeep';
|
|
37
|
+
const DEPLOY_DIR = GRO_DIRNAME + '/deploy';
|
|
38
|
+
const SOURCE_BRANCH = 'main';
|
|
39
|
+
const TARGET_BRANCH = 'deploy';
|
|
40
|
+
const DANGEROUS_BRANCHES = [SOURCE_BRANCH, 'master'];
|
|
41
|
+
|
|
42
|
+
/** @nodocs */
|
|
43
|
+
export const Args = z.strictObject({
|
|
44
|
+
source: GitBranch.describe('git source branch to build and deploy from').default(SOURCE_BRANCH),
|
|
45
|
+
target: GitBranch.describe('git target branch to deploy to').default(TARGET_BRANCH),
|
|
46
|
+
origin: GitOrigin.describe('git origin to deploy to').default('origin'),
|
|
47
|
+
deploy_dir: z.string().meta({description: 'the deploy output directory'}).default(DEPLOY_DIR),
|
|
48
|
+
build_dir: z
|
|
49
|
+
.string()
|
|
50
|
+
.meta({description: 'the SvelteKit build directory'})
|
|
51
|
+
.default(SVELTEKIT_BUILD_DIRNAME),
|
|
52
|
+
dry: z
|
|
53
|
+
.boolean()
|
|
54
|
+
.meta({
|
|
55
|
+
description: 'build and prepare to deploy without actually deploying',
|
|
56
|
+
})
|
|
57
|
+
.default(false),
|
|
58
|
+
force: z
|
|
59
|
+
.boolean()
|
|
60
|
+
.meta({description: 'caution!! destroys the target branch both locally and remotely'})
|
|
61
|
+
.default(false),
|
|
62
|
+
dangerous: z
|
|
63
|
+
.boolean()
|
|
64
|
+
.meta({description: 'caution!! enables destruction of branches like main and master'})
|
|
65
|
+
.default(false),
|
|
66
|
+
reset: z
|
|
67
|
+
.boolean()
|
|
68
|
+
.meta({
|
|
69
|
+
description: 'if true, resets the target branch back to the first commit before deploying',
|
|
70
|
+
})
|
|
71
|
+
.default(false),
|
|
72
|
+
build: z.boolean().meta({description: 'dual of no-build'}).default(true),
|
|
73
|
+
'no-build': z.boolean().meta({description: 'opt out of building'}).default(false),
|
|
74
|
+
sync: z.boolean().meta({description: 'dual of no-sync'}).default(true),
|
|
75
|
+
'no-sync': z.boolean().meta({description: 'opt out of gro sync in build'}).default(false),
|
|
76
|
+
gen: z.boolean().meta({description: 'dual of no-gen'}).default(true),
|
|
77
|
+
'no-gen': z.boolean().meta({description: 'opt out of gro gen in build'}).default(false),
|
|
78
|
+
install: z.boolean().meta({description: 'dual of no-install'}).default(true),
|
|
79
|
+
'no-install': z
|
|
80
|
+
.boolean()
|
|
81
|
+
.meta({description: 'opt out of installing packages before building'})
|
|
82
|
+
.default(false),
|
|
83
|
+
force_build: z
|
|
84
|
+
.boolean()
|
|
85
|
+
.meta({description: 'force a fresh build, ignoring the cache'})
|
|
86
|
+
.default(false),
|
|
87
|
+
pull: z.boolean().meta({description: 'dual of no-pull'}).default(true),
|
|
88
|
+
'no-pull': z.boolean().meta({description: 'opt out of git pull'}).default(false),
|
|
89
|
+
});
|
|
90
|
+
export type Args = z.infer<typeof Args>;
|
|
91
|
+
|
|
92
|
+
/** @nodocs */
|
|
93
|
+
export const task: Task<Args> = {
|
|
94
|
+
summary: 'deploy to a branch',
|
|
95
|
+
Args,
|
|
96
|
+
run: async ({args, log, invoke_task}): Promise<void> => {
|
|
97
|
+
const {
|
|
98
|
+
source,
|
|
99
|
+
target,
|
|
100
|
+
origin,
|
|
101
|
+
build_dir,
|
|
102
|
+
deploy_dir,
|
|
103
|
+
dry,
|
|
104
|
+
force,
|
|
105
|
+
dangerous,
|
|
106
|
+
reset,
|
|
107
|
+
build,
|
|
108
|
+
sync,
|
|
109
|
+
gen,
|
|
110
|
+
install,
|
|
111
|
+
force_build,
|
|
112
|
+
pull,
|
|
113
|
+
} = args;
|
|
114
|
+
|
|
115
|
+
// Checks
|
|
116
|
+
if (!force && target !== TARGET_BRANCH) {
|
|
117
|
+
throw new TaskError(
|
|
118
|
+
`Warning! You are deploying to a custom target branch '${target}',` +
|
|
119
|
+
` instead of the default '${TARGET_BRANCH}' branch.` +
|
|
120
|
+
` This is destructive to your '${target}' branch!` +
|
|
121
|
+
` If you understand and are OK with deleting your branch '${target}',` +
|
|
122
|
+
` both locally and remotely, pass --force to suppress this error.`,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (!dangerous && DANGEROUS_BRANCHES.includes(target)) {
|
|
126
|
+
throw new TaskError(
|
|
127
|
+
`Warning! You are deploying to a custom target branch '${target}'` +
|
|
128
|
+
` and that appears very dangerous: it is destructive to your '${target}' branch!` +
|
|
129
|
+
` If you understand and are OK with deleting your branch '${target}',` +
|
|
130
|
+
` both locally and remotely, pass --dangerous to suppress this error.`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
const clean_error_message = await git_check_clean_workspace();
|
|
134
|
+
if (clean_error_message) {
|
|
135
|
+
throw new TaskError(
|
|
136
|
+
'Deploy failed because the git workspace has uncommitted changes: ' + clean_error_message,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (!(await git_check_setting_pull_rebase())) {
|
|
140
|
+
throw new TaskError(
|
|
141
|
+
'Deploying currently requires `git config --global pull.rebase true`,' +
|
|
142
|
+
' but this restriction could be lifted with more work',
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Fetch the source branch in the cwd if it's not there
|
|
147
|
+
if (!(await git_local_branch_exists(source))) {
|
|
148
|
+
await git_fetch(origin, source);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Prepare the source branch in the cwd
|
|
152
|
+
await git_checkout(source);
|
|
153
|
+
if (pull) {
|
|
154
|
+
await git_pull(origin, source);
|
|
155
|
+
}
|
|
156
|
+
if (await git_check_clean_workspace()) {
|
|
157
|
+
throw new TaskError(
|
|
158
|
+
'Deploy failed because the local source branch is out of sync with the remote one,' +
|
|
159
|
+
' finish rebasing manually or reset with `git rebase --abort`',
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Prepare the target branch remotely and locally
|
|
164
|
+
const resolved_deploy_dir = resolve(deploy_dir);
|
|
165
|
+
const target_spawn_options = {cwd: resolved_deploy_dir};
|
|
166
|
+
const remote_target_exists = await git_remote_branch_exists(origin, target);
|
|
167
|
+
if (remote_target_exists) {
|
|
168
|
+
// Remote target branch already exists, so sync up efficiently
|
|
169
|
+
|
|
170
|
+
// First, check if the deploy dir exists, and if so, attempt to sync it.
|
|
171
|
+
// If anything goes wrong, delete the directory and we'll initialize it
|
|
172
|
+
// using the same code path as if it didn't exist in the first place.
|
|
173
|
+
if (await fs_exists(resolved_deploy_dir)) {
|
|
174
|
+
if (target !== (await git_current_branch_name(target_spawn_options))) {
|
|
175
|
+
// We're in a bad state because the target branch has changed,
|
|
176
|
+
// so delete the directory and continue as if it wasn't there.
|
|
177
|
+
await rm(resolved_deploy_dir, {recursive: true});
|
|
178
|
+
} else {
|
|
179
|
+
await spawn('git', ['reset', '--hard'], target_spawn_options); // in case it's dirty
|
|
180
|
+
// Skip pulling target branch when resetting (optimization - we reset after anyway)
|
|
181
|
+
if (!reset) {
|
|
182
|
+
await git_pull(origin, target, target_spawn_options);
|
|
183
|
+
if (await git_check_clean_workspace(target_spawn_options)) {
|
|
184
|
+
// We're in a bad state because the local branch lost continuity with the remote,
|
|
185
|
+
// so delete the directory and continue as if it wasn't there.
|
|
186
|
+
await rm(resolved_deploy_dir, {recursive: true});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Second, initialize the deploy dir if needed.
|
|
193
|
+
// It may not exist, or it may have been deleted after failing to sync above.
|
|
194
|
+
if (!(await fs_exists(resolved_deploy_dir))) {
|
|
195
|
+
const local_deploy_branch_exists = await git_local_branch_exists(target);
|
|
196
|
+
await git_fetch(origin, ('+' + target + ':' + target) as GitBranch); // fetch+merge and allow non-fastforward updates with the +
|
|
197
|
+
await git_clone_locally(origin, target, dir, resolved_deploy_dir);
|
|
198
|
+
// Clean up if we created the target branch in the cwd
|
|
199
|
+
if (!local_deploy_branch_exists) {
|
|
200
|
+
await git_delete_local_branch(target);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Local target branch is now synced with remote, but do we need to reset?
|
|
205
|
+
if (reset) {
|
|
206
|
+
await git_reset_branch_to_first_commit(origin, target, target_spawn_options);
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
// Remote target branch does not exist, so start from scratch
|
|
210
|
+
|
|
211
|
+
// Delete the deploy dir and recreate it
|
|
212
|
+
if (await fs_exists(resolved_deploy_dir)) {
|
|
213
|
+
await rm(resolved_deploy_dir, {recursive: true});
|
|
214
|
+
await mkdir(resolved_deploy_dir, {recursive: true});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Delete the target branch locally in the cwd if it exists
|
|
218
|
+
if (await git_local_branch_exists(target)) {
|
|
219
|
+
await git_delete_local_branch(target);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Create the target branch locally and remotely.
|
|
223
|
+
// This is more complex to avoid churning the cwd.
|
|
224
|
+
await git_clone_locally(origin, source, dir, resolved_deploy_dir);
|
|
225
|
+
await spawn('git', ['checkout', '--orphan', target], target_spawn_options);
|
|
226
|
+
// TODO there's definitely a better way to do this
|
|
227
|
+
await spawn('git', ['rm', '-rf', '.'], target_spawn_options);
|
|
228
|
+
await spawn('touch', [INITIAL_FILE_PATH], target_spawn_options);
|
|
229
|
+
await spawn('git', ['add', INITIAL_FILE_PATH], target_spawn_options);
|
|
230
|
+
await spawn('git', ['commit', '-m', 'init'], target_spawn_options);
|
|
231
|
+
await git_push_to_create(origin, target, target_spawn_options);
|
|
232
|
+
await git_delete_local_branch(source, target_spawn_options);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Remove everything except .git from the deploy directory to avoid stale files
|
|
236
|
+
await fs_empty_dir(resolved_deploy_dir, (name) => name !== GIT_DIRNAME);
|
|
237
|
+
|
|
238
|
+
// Build
|
|
239
|
+
try {
|
|
240
|
+
if (build) {
|
|
241
|
+
await invoke_task('build', {sync, gen, install, force_build});
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
log.error(
|
|
245
|
+
st('red', 'build failed'),
|
|
246
|
+
'but',
|
|
247
|
+
st('green', 'no changes were made to git'),
|
|
248
|
+
print_error(error),
|
|
249
|
+
);
|
|
250
|
+
if (dry) {
|
|
251
|
+
log.info(st('red', 'dry deploy failed'));
|
|
252
|
+
}
|
|
253
|
+
throw new TaskError(`Deploy safely canceled due to build failure. See the error above.`);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Verify build output exists
|
|
257
|
+
if (!(await fs_exists(build_dir))) {
|
|
258
|
+
throw new TaskError(`Directory to deploy does not exist after building: ${build_dir}`);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Copy the build
|
|
262
|
+
const build_entries = await readdir(build_dir);
|
|
263
|
+
await Promise.all(
|
|
264
|
+
build_entries.map((path) =>
|
|
265
|
+
cp(join(build_dir, path), join(resolved_deploy_dir, path), {recursive: true}),
|
|
266
|
+
),
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// At this point, `dist/` is ready to be committed and deployed!
|
|
270
|
+
if (dry) {
|
|
271
|
+
log.info(st('green', 'dry deploy complete:'), 'files at', print_path(resolved_deploy_dir));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Commit and push
|
|
276
|
+
try {
|
|
277
|
+
await spawn('git', ['add', '.', '-f'], target_spawn_options);
|
|
278
|
+
await spawn('git', ['commit', '-m', 'deployment'], target_spawn_options);
|
|
279
|
+
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
|
|
280
|
+
} catch (error) {
|
|
281
|
+
log.error(st('red', 'updating git failed:'), print_error(error));
|
|
282
|
+
throw new TaskError(`Deploy failed in a bad state: built but not pushed, see error above.`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
log.info(st('green', 'deployed')); // TODO log a different message if "Everything up-to-date"
|
|
286
|
+
},
|
|
287
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {z} from 'zod';
|
|
2
|
+
|
|
3
|
+
import type {Task} from './task.ts';
|
|
4
|
+
import {Plugins, type PluginContext} from './plugin.ts';
|
|
5
|
+
import {clean_fs} from './clean_fs.ts';
|
|
6
|
+
|
|
7
|
+
/** @nodocs */
|
|
8
|
+
export const Args = z.strictObject({
|
|
9
|
+
watch: z.boolean().meta({description: 'dual of no-watch'}).default(true),
|
|
10
|
+
'no-watch': z
|
|
11
|
+
.boolean()
|
|
12
|
+
.meta({
|
|
13
|
+
description: 'opt out of running a long-lived process to watch files and rebuild on changes',
|
|
14
|
+
})
|
|
15
|
+
.default(false),
|
|
16
|
+
sync: z.boolean().meta({description: 'dual of no-sync'}).default(true),
|
|
17
|
+
'no-sync': z.boolean().meta({description: 'opt out of gro sync'}).default(false),
|
|
18
|
+
install: z.boolean().meta({description: 'opt into installing packages'}).default(false),
|
|
19
|
+
});
|
|
20
|
+
export type Args = z.infer<typeof Args>;
|
|
21
|
+
|
|
22
|
+
export type DevTaskContext = PluginContext<Args>;
|
|
23
|
+
|
|
24
|
+
/** @nodocs */
|
|
25
|
+
export const task: Task<Args> = {
|
|
26
|
+
summary: 'start SvelteKit and other dev plugins',
|
|
27
|
+
Args,
|
|
28
|
+
run: async (ctx) => {
|
|
29
|
+
const {args, invoke_task, log} = ctx;
|
|
30
|
+
const {watch, sync, install} = args;
|
|
31
|
+
|
|
32
|
+
await clean_fs({build_dev: true});
|
|
33
|
+
|
|
34
|
+
if (sync || install) {
|
|
35
|
+
if (!sync) log.warn('sync is false but install is true, so ignoring the sync option');
|
|
36
|
+
await invoke_task('sync', {install, gen: !watch});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const plugins = await Plugins.create({...ctx, dev: true, watch});
|
|
40
|
+
await plugins.setup();
|
|
41
|
+
if (!watch) {
|
|
42
|
+
await plugins.teardown();
|
|
43
|
+
} else {
|
|
44
|
+
// TODO maybe redesign for this API to be explicitly cancelable?
|
|
45
|
+
// Keep the task running indefinitely in watch mode.
|
|
46
|
+
// This prevents invoke_task from calling finish() and closing the filer.
|
|
47
|
+
await new Promise(() => {
|
|
48
|
+
// Never resolves - keeps filer and listeners alive.
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type {PathId} from '@fuzdev/fuz_util/path.js';
|
|
2
|
+
|
|
3
|
+
// TODO extract more here from Filer
|
|
4
|
+
|
|
5
|
+
export interface Disknode {
|
|
6
|
+
id: PathId;
|
|
7
|
+
// TODO figure out the best API that makes this lazy
|
|
8
|
+
/**
|
|
9
|
+
* `null` contents means it doesn't exist.
|
|
10
|
+
* We create the file in memory to track its dependents regardless of its existence on disk.
|
|
11
|
+
*/
|
|
12
|
+
contents: string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Is the source file outside of the `root_dir` or excluded by `watch_dir_options.filter`?
|
|
15
|
+
*/
|
|
16
|
+
external: boolean;
|
|
17
|
+
ctime: number | null;
|
|
18
|
+
mtime: number | null;
|
|
19
|
+
/**
|
|
20
|
+
* SHA-256 hash of `contents`. `null` iff `contents` is `null`.
|
|
21
|
+
* Used for content-based change detection and caching.
|
|
22
|
+
*/
|
|
23
|
+
content_hash: string | null;
|
|
24
|
+
dependents: Map<PathId, Disknode>;
|
|
25
|
+
dependencies: Map<PathId, Disknode>;
|
|
26
|
+
}
|
package/src/lib/env.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import dotenv from 'dotenv';
|
|
2
|
+
import {resolve} from 'node:path';
|
|
3
|
+
import {existsSync, readFileSync} from 'node:fs';
|
|
4
|
+
|
|
5
|
+
export const load_env = (
|
|
6
|
+
dev: boolean,
|
|
7
|
+
visibility: 'public' | 'private',
|
|
8
|
+
public_prefix: string,
|
|
9
|
+
private_prefix: string,
|
|
10
|
+
env_dir?: string,
|
|
11
|
+
env_files = ['.env', '.env.' + (dev ? 'development' : 'production')],
|
|
12
|
+
ambient_env = process.env,
|
|
13
|
+
): Record<string, string> => {
|
|
14
|
+
const envs: Array<Record<string, string | undefined>> = env_files
|
|
15
|
+
.map((path) => load(env_dir === undefined ? path : resolve(env_dir, path)))
|
|
16
|
+
.filter((v) => v !== undefined);
|
|
17
|
+
envs.push(ambient_env);
|
|
18
|
+
return merge_envs(envs, visibility, public_prefix, private_prefix);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Loads a single env value without merging it into `process.env`.
|
|
23
|
+
* By default searches process.env, then a local `.env` if one exists, then `../.env` if it exists.
|
|
24
|
+
* Empty strings are semantically the same as `undefined` for more ergonomic fallbacks.
|
|
25
|
+
*/
|
|
26
|
+
export const load_from_env = (key: string, paths = ['.env', '../.env']): string | undefined => {
|
|
27
|
+
let v = process.env[key];
|
|
28
|
+
if (v) return v;
|
|
29
|
+
for (const path of paths) {
|
|
30
|
+
const env = load(path);
|
|
31
|
+
v = env?.[key];
|
|
32
|
+
if (v) return v;
|
|
33
|
+
}
|
|
34
|
+
return undefined;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const load = (path: string): Record<string, string> | undefined => {
|
|
38
|
+
if (!existsSync(path)) return;
|
|
39
|
+
const loaded = readFileSync(path, 'utf8');
|
|
40
|
+
return dotenv.parse(loaded);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const merge_envs = (
|
|
44
|
+
envs: Array<Record<string, string | undefined>>,
|
|
45
|
+
visibility: 'public' | 'private',
|
|
46
|
+
public_prefix: string,
|
|
47
|
+
private_prefix: string,
|
|
48
|
+
): Record<string, string> => {
|
|
49
|
+
const env: Record<string, string> = {};
|
|
50
|
+
|
|
51
|
+
for (const e of envs) {
|
|
52
|
+
for (const key in e) {
|
|
53
|
+
if (
|
|
54
|
+
(visibility === 'private' && is_private_env(key, public_prefix, private_prefix)) ||
|
|
55
|
+
(visibility === 'public' && is_public_env(key, public_prefix, private_prefix))
|
|
56
|
+
) {
|
|
57
|
+
const value = e[key];
|
|
58
|
+
if (value !== undefined) env[key] = value;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return env;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const is_private_env = (
|
|
67
|
+
key: string,
|
|
68
|
+
public_prefix: string,
|
|
69
|
+
private_prefix: string,
|
|
70
|
+
): boolean =>
|
|
71
|
+
key.startsWith(private_prefix) && (public_prefix === '' || !key.startsWith(public_prefix));
|
|
72
|
+
|
|
73
|
+
export const is_public_env = (
|
|
74
|
+
key: string,
|
|
75
|
+
public_prefix: string,
|
|
76
|
+
private_prefix: string,
|
|
77
|
+
): boolean =>
|
|
78
|
+
key.startsWith(public_prefix) && (private_prefix === '' || !key.startsWith(private_prefix));
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {styleText as st} from 'node:util';
|
|
2
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
3
|
+
import type * as esbuild from 'esbuild';
|
|
4
|
+
|
|
5
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
6
|
+
|
|
7
|
+
export const print_build_result = (log: Logger, build_result: esbuild.BuildResult): void => {
|
|
8
|
+
for (const error of build_result.errors) {
|
|
9
|
+
log.error(st('red', 'esbuild error'), error);
|
|
10
|
+
}
|
|
11
|
+
for (const warning of build_result.warnings) {
|
|
12
|
+
log.warn(st('yellow', 'esbuild warning'), warning);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// This concatenates weirdly to avoid a SvelteKit warning,
|
|
17
|
+
// because SvelteKit detects usage as a string and not the AST.
|
|
18
|
+
const import_meta_env = 'import.' + 'meta.env.'; // eslint-disable-line no-useless-concat
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an esbuild `define` shim for Vite's `import.meta\.env`.
|
|
22
|
+
* @see https://esbuild.github.io/api/#define
|
|
23
|
+
* @param dev
|
|
24
|
+
* @param base_url - best-effort shim from SvelteKit's `base` to Vite's `import.meta\.env.BASE_URL`
|
|
25
|
+
* @param ssr
|
|
26
|
+
* @param mode
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
export const to_define_import_meta_env = (
|
|
30
|
+
dev: boolean,
|
|
31
|
+
base_url: ParsedSvelteConfig['base_url'],
|
|
32
|
+
ssr = true,
|
|
33
|
+
mode = dev ? 'development' : 'production',
|
|
34
|
+
): Record<string, string> => ({
|
|
35
|
+
// see `import_meta_env` for why this is defined weirdly instead of statically
|
|
36
|
+
[import_meta_env + 'DEV']: JSON.stringify(dev),
|
|
37
|
+
[import_meta_env + 'PROD']: JSON.stringify(!dev),
|
|
38
|
+
[import_meta_env + 'SSR']: JSON.stringify(ssr),
|
|
39
|
+
[import_meta_env + 'MODE']: JSON.stringify(mode),
|
|
40
|
+
// it appears SvelteKit's `''` translates to Vite's `'/'`, so this intentionally falls back for falsy values, not just undefined
|
|
41
|
+
[import_meta_env + 'BASE_URL']: JSON.stringify(base_url || '/'),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const default_ts_transform_options: esbuild.TransformOptions = {
|
|
45
|
+
target: 'esnext', // TODO load local tsconfig
|
|
46
|
+
format: 'esm',
|
|
47
|
+
loader: 'ts',
|
|
48
|
+
charset: 'utf8',
|
|
49
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
3
|
+
import {basename} from 'node:path';
|
|
4
|
+
import type {CompileOptions, ModuleCompileOptions, PreprocessorGroup} from 'svelte/compiler';
|
|
5
|
+
import type {PathId} from '@fuzdev/fuz_util/path.js';
|
|
6
|
+
|
|
7
|
+
import {print_build_result, to_define_import_meta_env} from './esbuild_helpers.ts';
|
|
8
|
+
import {resolve_specifier} from './resolve_specifier.ts';
|
|
9
|
+
import {esbuild_plugin_sveltekit_shim_alias} from './esbuild_plugin_sveltekit_shim_alias.ts';
|
|
10
|
+
import {esbuild_plugin_sveltekit_shim_env} from './esbuild_plugin_sveltekit_shim_env.ts';
|
|
11
|
+
import {esbuild_plugin_sveltekit_shim_app} from './esbuild_plugin_sveltekit_shim_app.ts';
|
|
12
|
+
import {esbuild_plugin_sveltekit_local_imports} from './esbuild_plugin_sveltekit_local_imports.ts';
|
|
13
|
+
import {esbuild_plugin_svelte} from './esbuild_plugin_svelte.ts';
|
|
14
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
15
|
+
|
|
16
|
+
export interface EsbuildPluginExternalWorkerOptions {
|
|
17
|
+
dev: boolean;
|
|
18
|
+
build_options: esbuild.BuildOptions;
|
|
19
|
+
dir?: string;
|
|
20
|
+
svelte_compile_options?: CompileOptions;
|
|
21
|
+
svelte_compile_module_options?: ModuleCompileOptions;
|
|
22
|
+
svelte_preprocessors?: PreprocessorGroup | Array<PreprocessorGroup>;
|
|
23
|
+
alias?: Record<string, string>;
|
|
24
|
+
base_url?: ParsedSvelteConfig['base_url'];
|
|
25
|
+
assets_url?: ParsedSvelteConfig['assets_url'];
|
|
26
|
+
public_prefix?: string;
|
|
27
|
+
private_prefix?: string;
|
|
28
|
+
env_dir?: string;
|
|
29
|
+
env_files?: Array<string>;
|
|
30
|
+
ambient_env?: Record<string, string>;
|
|
31
|
+
log?: Logger;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const esbuild_plugin_external_worker = ({
|
|
35
|
+
dev,
|
|
36
|
+
build_options,
|
|
37
|
+
dir = process.cwd(),
|
|
38
|
+
svelte_compile_options,
|
|
39
|
+
svelte_compile_module_options,
|
|
40
|
+
svelte_preprocessors,
|
|
41
|
+
alias,
|
|
42
|
+
base_url,
|
|
43
|
+
assets_url,
|
|
44
|
+
public_prefix,
|
|
45
|
+
private_prefix,
|
|
46
|
+
env_dir,
|
|
47
|
+
env_files,
|
|
48
|
+
ambient_env,
|
|
49
|
+
log,
|
|
50
|
+
}: EsbuildPluginExternalWorkerOptions): esbuild.Plugin => ({
|
|
51
|
+
name: 'external_worker',
|
|
52
|
+
setup: (build) => {
|
|
53
|
+
const builds: Map<string, Promise<esbuild.BuildResult>> = new Map();
|
|
54
|
+
const build_worker = async (path_id: PathId): Promise<esbuild.BuildResult> => {
|
|
55
|
+
if (builds.has(path_id)) return builds.get(path_id)!;
|
|
56
|
+
const building = esbuild.build({
|
|
57
|
+
entryPoints: [path_id],
|
|
58
|
+
plugins: [
|
|
59
|
+
esbuild_plugin_sveltekit_shim_app({dev, base_url, assets_url}),
|
|
60
|
+
esbuild_plugin_sveltekit_shim_env({
|
|
61
|
+
dev,
|
|
62
|
+
public_prefix,
|
|
63
|
+
private_prefix,
|
|
64
|
+
env_dir,
|
|
65
|
+
env_files,
|
|
66
|
+
ambient_env,
|
|
67
|
+
}),
|
|
68
|
+
esbuild_plugin_sveltekit_shim_alias({dir, alias}),
|
|
69
|
+
esbuild_plugin_svelte({
|
|
70
|
+
dev,
|
|
71
|
+
base_url,
|
|
72
|
+
dir,
|
|
73
|
+
svelte_compile_options,
|
|
74
|
+
svelte_compile_module_options,
|
|
75
|
+
svelte_preprocessors,
|
|
76
|
+
}),
|
|
77
|
+
esbuild_plugin_sveltekit_local_imports(),
|
|
78
|
+
],
|
|
79
|
+
define: to_define_import_meta_env(dev, base_url),
|
|
80
|
+
...build_options,
|
|
81
|
+
});
|
|
82
|
+
builds.set(path_id, building);
|
|
83
|
+
return building;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
build.onResolve({filter: /\.worker(|\.js|\.ts)$/}, async ({path, resolveDir}) => {
|
|
87
|
+
const parsed = await resolve_specifier(path, resolveDir);
|
|
88
|
+
const {specifier, path_id, namespace} = parsed;
|
|
89
|
+
const build_result = await build_worker(path_id);
|
|
90
|
+
if (log) print_build_result(log, build_result);
|
|
91
|
+
return {path: './' + basename(specifier), external: true, namespace};
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
});
|