@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,149 @@
|
|
|
1
|
+
import type {Args} from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import {UnreachableError} from '@fuzdev/fuz_util/error.js';
|
|
3
|
+
import {EMPTY_OBJECT} from '@fuzdev/fuz_util/object.js';
|
|
4
|
+
import {throttle} from '@fuzdev/fuz_util/throttle.js';
|
|
5
|
+
|
|
6
|
+
import type {Plugin} from './plugin.ts';
|
|
7
|
+
import {paths} from './paths.ts';
|
|
8
|
+
import {find_genfiles, is_gen_path} from './gen.ts';
|
|
9
|
+
import {filter_dependents} from './filer.ts';
|
|
10
|
+
import {should_trigger_gen} from './gen_helpers.ts';
|
|
11
|
+
import {spawn_cli} from './cli.ts';
|
|
12
|
+
|
|
13
|
+
const FLUSH_DEBOUNCE_DELAY = 500;
|
|
14
|
+
|
|
15
|
+
// TODO is cache busting a good idea here to speed up and run in-process?
|
|
16
|
+
// await invoke_task('gen', {_: files, bust_cache: true});
|
|
17
|
+
const gen = (files: Array<string> = []) => spawn_cli('gro', ['gen', ...files]);
|
|
18
|
+
|
|
19
|
+
export interface TaskArgs extends Args {
|
|
20
|
+
watch?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface GroPluginGenOptions {
|
|
24
|
+
input_paths?: Array<string>;
|
|
25
|
+
root_dirs?: Array<string>;
|
|
26
|
+
flush_debounce_delay?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const gro_plugin_gen = ({
|
|
30
|
+
input_paths = [paths.source],
|
|
31
|
+
root_dirs = [paths.source],
|
|
32
|
+
flush_debounce_delay = FLUSH_DEBOUNCE_DELAY,
|
|
33
|
+
}: GroPluginGenOptions = EMPTY_OBJECT): Plugin => {
|
|
34
|
+
const queued_files: Set<string> = new Set();
|
|
35
|
+
|
|
36
|
+
let cleanup_watch: (() => void) | undefined;
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
name: 'gro_plugin_gen',
|
|
40
|
+
setup: async ({watch, dev, log, config, filer, invoke_task, timings}) => {
|
|
41
|
+
// For production builds, we assume `gen` is already fresh,
|
|
42
|
+
// which should be checked by CI via `gro check` which calls `gro gen --check`.
|
|
43
|
+
if (!dev) return;
|
|
44
|
+
|
|
45
|
+
// Do we need to just generate everything once and exit?
|
|
46
|
+
if (!watch) {
|
|
47
|
+
// Run `gen`, first checking if there are any modules to avoid a console error.
|
|
48
|
+
// Some parts of the build may have already happened,
|
|
49
|
+
// making us miss `build` events for gen dependencies,
|
|
50
|
+
// so we run a full `gen` here even if it's usually wasteful.
|
|
51
|
+
const found = await find_genfiles(input_paths, root_dirs, config);
|
|
52
|
+
if (found.ok && found.value.resolved_input_files.length > 0) {
|
|
53
|
+
await gen();
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const queue_gen = (gen_file_id: string) => {
|
|
59
|
+
queued_files.add(gen_file_id);
|
|
60
|
+
void flush_gen_queue();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const flush_gen_queue = throttle(
|
|
64
|
+
async () => {
|
|
65
|
+
const files = Array.from(queued_files);
|
|
66
|
+
log.info(
|
|
67
|
+
files.length === 0
|
|
68
|
+
? '[gen] generating all files'
|
|
69
|
+
: `[gen] generating ${files.length} file${files.length === 1 ? '' : 's'}`,
|
|
70
|
+
);
|
|
71
|
+
queued_files.clear();
|
|
72
|
+
await gen(files);
|
|
73
|
+
|
|
74
|
+
// run again?
|
|
75
|
+
if (queued_files.size > 0) {
|
|
76
|
+
log.info(
|
|
77
|
+
`[gen] re-running for ${queued_files.size} more queued file${queued_files.size === 1 ? '' : 's'}`,
|
|
78
|
+
);
|
|
79
|
+
setTimeout(flush_gen_queue); // setTimeout is needed bc of throttle behavior
|
|
80
|
+
} else {
|
|
81
|
+
log.info('[gen] queue empty, done');
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{delay: flush_debounce_delay, when: 'trailing'},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// When a file builds, check it and its tree of dependents
|
|
88
|
+
// for any `.gen.` files that need to run.
|
|
89
|
+
cleanup_watch = await filer.watch(async (change, source_file) => {
|
|
90
|
+
if (source_file.external) return;
|
|
91
|
+
switch (change.type) {
|
|
92
|
+
case 'add':
|
|
93
|
+
case 'update': {
|
|
94
|
+
// Queue the gen file itself if it changed
|
|
95
|
+
if (is_gen_path(source_file.id)) {
|
|
96
|
+
queue_gen(source_file.id);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Find all current gen files and check their dependencies
|
|
100
|
+
const gen_files = filer.filter((d) => !d.external && is_gen_path(d.id));
|
|
101
|
+
if (gen_files) {
|
|
102
|
+
for (const gen_file of gen_files) {
|
|
103
|
+
// eslint-disable-next-line no-await-in-loop
|
|
104
|
+
const should_trigger = await should_trigger_gen(
|
|
105
|
+
gen_file.id,
|
|
106
|
+
source_file.id,
|
|
107
|
+
config,
|
|
108
|
+
filer,
|
|
109
|
+
log,
|
|
110
|
+
timings,
|
|
111
|
+
invoke_task,
|
|
112
|
+
);
|
|
113
|
+
if (should_trigger) {
|
|
114
|
+
queue_gen(gen_file.id);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Check import-based dependents
|
|
120
|
+
const dependent_gen_file_ids = filter_dependents(
|
|
121
|
+
source_file,
|
|
122
|
+
filer.get_by_id,
|
|
123
|
+
is_gen_path,
|
|
124
|
+
undefined,
|
|
125
|
+
undefined,
|
|
126
|
+
log,
|
|
127
|
+
);
|
|
128
|
+
for (const dependent_gen_file_id of dependent_gen_file_ids) {
|
|
129
|
+
queue_gen(dependent_gen_file_id);
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
case 'delete': {
|
|
134
|
+
// I think for the gen plugin this is best as a no-op? avoids broken attempts
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
default:
|
|
138
|
+
throw new UnreachableError(change.type);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
teardown: () => {
|
|
143
|
+
if (cleanup_watch) {
|
|
144
|
+
cleanup_watch();
|
|
145
|
+
cleanup_watch = undefined;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {spawn_restartable_process, type RestartableProcess} from '@fuzdev/fuz_util/process.js';
|
|
2
|
+
import * as esbuild from 'esbuild';
|
|
3
|
+
import type {Config as SvelteConfig} from '@sveltejs/kit';
|
|
4
|
+
import {join, resolve} from 'node:path';
|
|
5
|
+
import {identity} from '@fuzdev/fuz_util/function.js';
|
|
6
|
+
import {strip_before, strip_end} from '@fuzdev/fuz_util/string.js';
|
|
7
|
+
import type {Result} from '@fuzdev/fuz_util/result.js';
|
|
8
|
+
import {fs_exists} from '@fuzdev/fuz_util/fs.js';
|
|
9
|
+
import {throttle} from '@fuzdev/fuz_util/throttle.js';
|
|
10
|
+
import type {PathId} from '@fuzdev/fuz_util/path.js';
|
|
11
|
+
|
|
12
|
+
import type {Plugin} from './plugin.ts';
|
|
13
|
+
import {base_path_to_path_id, LIB_DIRNAME, paths} from './paths.ts';
|
|
14
|
+
import {GRO_DEV_DIRNAME, SERVER_DIST_PATH} from './constants.ts';
|
|
15
|
+
import {parse_svelte_config, default_svelte_config} from './svelte_config.ts';
|
|
16
|
+
import {esbuild_plugin_sveltekit_shim_app} from './esbuild_plugin_sveltekit_shim_app.ts';
|
|
17
|
+
import {esbuild_plugin_sveltekit_shim_env} from './esbuild_plugin_sveltekit_shim_env.ts';
|
|
18
|
+
import {print_build_result, to_define_import_meta_env} from './esbuild_helpers.ts';
|
|
19
|
+
import {esbuild_plugin_sveltekit_shim_alias} from './esbuild_plugin_sveltekit_shim_alias.ts';
|
|
20
|
+
import {esbuild_plugin_external_worker} from './esbuild_plugin_external_worker.ts';
|
|
21
|
+
import {esbuild_plugin_sveltekit_local_imports} from './esbuild_plugin_sveltekit_local_imports.ts';
|
|
22
|
+
import {esbuild_plugin_svelte} from './esbuild_plugin_svelte.ts';
|
|
23
|
+
|
|
24
|
+
// TODO sourcemap as a hoisted option? disable for production by default - or like `outpaths`, passed a `dev` param
|
|
25
|
+
|
|
26
|
+
export const SERVER_SOURCE_ID = base_path_to_path_id(LIB_DIRNAME + '/server/server.ts');
|
|
27
|
+
|
|
28
|
+
export const has_server = async (
|
|
29
|
+
path = SERVER_SOURCE_ID,
|
|
30
|
+
): Promise<Result<object, {message: string}>> => {
|
|
31
|
+
if (!(await fs_exists(path))) {
|
|
32
|
+
return {ok: false, message: `no server file found at ${path}`};
|
|
33
|
+
}
|
|
34
|
+
return {ok: true};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export interface GroPluginServerOptions {
|
|
38
|
+
/**
|
|
39
|
+
* same as esbuild's `entryPoints`
|
|
40
|
+
*/
|
|
41
|
+
entry_points?: Array<string>;
|
|
42
|
+
/**
|
|
43
|
+
* @default cwd
|
|
44
|
+
*/
|
|
45
|
+
dir?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Returns the `Outpaths` given a `dev` param.
|
|
48
|
+
* Decoupling this from plugin creation allows it to be created generically,
|
|
49
|
+
* so the build and dev tasks can be the source of truth for `dev`.
|
|
50
|
+
*/
|
|
51
|
+
outpaths?: CreateOutpaths;
|
|
52
|
+
/**
|
|
53
|
+
* @default ```SvelteKit's `.env`, `.env.development`, and `.env.production````
|
|
54
|
+
*/
|
|
55
|
+
env_files?: Array<string>;
|
|
56
|
+
/**
|
|
57
|
+
* @default process.env
|
|
58
|
+
*/
|
|
59
|
+
ambient_env?: Record<string, string>;
|
|
60
|
+
/**
|
|
61
|
+
* @default ```loaded from `${cwd}/${SVELTE_CONFIG_FILENAME}````
|
|
62
|
+
*/
|
|
63
|
+
svelte_config?: SvelteConfig;
|
|
64
|
+
/**
|
|
65
|
+
* @default 'esnext'
|
|
66
|
+
*/
|
|
67
|
+
target?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Optionally map the esbuild options.
|
|
70
|
+
* @default identity
|
|
71
|
+
*/
|
|
72
|
+
esbuild_build_options?: (base_options: esbuild.BuildOptions) => esbuild.BuildOptions;
|
|
73
|
+
/**
|
|
74
|
+
* Milliseconds to throttle rebuilds.
|
|
75
|
+
* Should be longer than it takes to build to avoid backpressure.
|
|
76
|
+
* @default 1000
|
|
77
|
+
*/
|
|
78
|
+
rebuild_throttle_delay?: number; // TODO could detect the backpressure problem and at least warn, shouldn't be a big deal
|
|
79
|
+
/**
|
|
80
|
+
* The CLI command to run the server, like `'node'` or `'bun'` or `'deno'`.
|
|
81
|
+
* Receives the path to the server js file as its argument.
|
|
82
|
+
* @default 'node'
|
|
83
|
+
*/
|
|
84
|
+
cli_command?: string;
|
|
85
|
+
/**
|
|
86
|
+
* Whether to run the server or not after building.
|
|
87
|
+
* @default dev
|
|
88
|
+
*/
|
|
89
|
+
run?: boolean;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface Outpaths {
|
|
93
|
+
/**
|
|
94
|
+
* @default '.gro/dev' or 'dist_server'
|
|
95
|
+
*/
|
|
96
|
+
outdir: string;
|
|
97
|
+
/**
|
|
98
|
+
* @default 'src/lib'
|
|
99
|
+
*/
|
|
100
|
+
outbase: string;
|
|
101
|
+
/**
|
|
102
|
+
* @default 'server.js'
|
|
103
|
+
*/
|
|
104
|
+
outname: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type CreateOutpaths = (dev: boolean) => Outpaths;
|
|
108
|
+
|
|
109
|
+
export const gro_plugin_server = ({
|
|
110
|
+
entry_points = [SERVER_SOURCE_ID],
|
|
111
|
+
dir = process.cwd(),
|
|
112
|
+
outpaths = (dev) => ({
|
|
113
|
+
outdir: join(dir, dev ? GRO_DEV_DIRNAME : SERVER_DIST_PATH),
|
|
114
|
+
outbase: paths.lib,
|
|
115
|
+
outname: 'server/server.js',
|
|
116
|
+
}),
|
|
117
|
+
env_files,
|
|
118
|
+
ambient_env,
|
|
119
|
+
svelte_config,
|
|
120
|
+
target = 'esnext',
|
|
121
|
+
esbuild_build_options = identity,
|
|
122
|
+
rebuild_throttle_delay = 1000,
|
|
123
|
+
cli_command,
|
|
124
|
+
run, // `dev` default is not available in this scope
|
|
125
|
+
}: GroPluginServerOptions = {}): Plugin => {
|
|
126
|
+
let build_ctx: esbuild.BuildContext | undefined;
|
|
127
|
+
let cleanup_watch: (() => void) | undefined;
|
|
128
|
+
let server_process: RestartableProcess | undefined;
|
|
129
|
+
let deps: Set<PathId> | undefined;
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
name: 'gro_plugin_server',
|
|
133
|
+
setup: async ({dev, watch, timings, log, config, filer}) => {
|
|
134
|
+
const parsed_svelte_config =
|
|
135
|
+
!svelte_config && strip_end(dir, '/') === process.cwd()
|
|
136
|
+
? default_svelte_config
|
|
137
|
+
: await parse_svelte_config({
|
|
138
|
+
dir_or_config: svelte_config ?? dir,
|
|
139
|
+
config_filename: config.svelte_config_filename,
|
|
140
|
+
});
|
|
141
|
+
const {
|
|
142
|
+
alias,
|
|
143
|
+
base_url,
|
|
144
|
+
assets_url,
|
|
145
|
+
env_dir,
|
|
146
|
+
private_prefix,
|
|
147
|
+
public_prefix,
|
|
148
|
+
svelte_compile_options,
|
|
149
|
+
svelte_compile_module_options,
|
|
150
|
+
svelte_preprocessors,
|
|
151
|
+
} = parsed_svelte_config;
|
|
152
|
+
|
|
153
|
+
const {outbase, outdir, outname} = outpaths(dev);
|
|
154
|
+
|
|
155
|
+
const server_outpath = join(outdir, outname);
|
|
156
|
+
|
|
157
|
+
const timing_to_esbuild_create_context = timings.start('create build context');
|
|
158
|
+
|
|
159
|
+
const build_options = esbuild_build_options({
|
|
160
|
+
outdir,
|
|
161
|
+
outbase,
|
|
162
|
+
format: 'esm',
|
|
163
|
+
platform: 'node',
|
|
164
|
+
packages: 'external',
|
|
165
|
+
bundle: true,
|
|
166
|
+
target,
|
|
167
|
+
metafile: watch,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
build_ctx = await esbuild.context({
|
|
171
|
+
entryPoints: entry_points.map((path) => resolve(dir, path)),
|
|
172
|
+
plugins: [
|
|
173
|
+
esbuild_plugin_sveltekit_shim_app({dev, base_url, assets_url}),
|
|
174
|
+
esbuild_plugin_sveltekit_shim_env({
|
|
175
|
+
dev,
|
|
176
|
+
public_prefix,
|
|
177
|
+
private_prefix,
|
|
178
|
+
env_dir,
|
|
179
|
+
env_files,
|
|
180
|
+
ambient_env,
|
|
181
|
+
}),
|
|
182
|
+
esbuild_plugin_sveltekit_shim_alias({dir, alias}),
|
|
183
|
+
esbuild_plugin_external_worker({
|
|
184
|
+
dev,
|
|
185
|
+
build_options,
|
|
186
|
+
dir,
|
|
187
|
+
svelte_compile_options,
|
|
188
|
+
svelte_compile_module_options,
|
|
189
|
+
svelte_preprocessors,
|
|
190
|
+
alias,
|
|
191
|
+
base_url,
|
|
192
|
+
public_prefix,
|
|
193
|
+
private_prefix,
|
|
194
|
+
env_dir,
|
|
195
|
+
env_files,
|
|
196
|
+
ambient_env,
|
|
197
|
+
log,
|
|
198
|
+
}),
|
|
199
|
+
esbuild_plugin_svelte({
|
|
200
|
+
dev,
|
|
201
|
+
base_url,
|
|
202
|
+
dir,
|
|
203
|
+
svelte_compile_options,
|
|
204
|
+
svelte_compile_module_options,
|
|
205
|
+
svelte_preprocessors,
|
|
206
|
+
}),
|
|
207
|
+
esbuild_plugin_sveltekit_local_imports(),
|
|
208
|
+
],
|
|
209
|
+
define: to_define_import_meta_env(dev, base_url),
|
|
210
|
+
...build_options,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
timing_to_esbuild_create_context();
|
|
214
|
+
|
|
215
|
+
const rebuild = throttle(
|
|
216
|
+
async () => {
|
|
217
|
+
let build_result;
|
|
218
|
+
try {
|
|
219
|
+
build_result = await build_ctx!.rebuild();
|
|
220
|
+
} catch (error) {
|
|
221
|
+
log.error('[gro_plugin_server] build failed', error);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const {metafile} = build_result;
|
|
225
|
+
if (!metafile) return;
|
|
226
|
+
print_build_result(log, build_result);
|
|
227
|
+
deps = parse_deps(metafile.inputs, dir);
|
|
228
|
+
void server_process?.restart();
|
|
229
|
+
},
|
|
230
|
+
{delay: rebuild_throttle_delay},
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
await rebuild();
|
|
234
|
+
|
|
235
|
+
if (watch) {
|
|
236
|
+
cleanup_watch = await filer.watch((change) => {
|
|
237
|
+
if (!deps?.has(change.path)) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
void rebuild();
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!(await fs_exists(server_outpath))) {
|
|
245
|
+
throw Error(`Node server failed to start due to missing file: ${server_outpath}`);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (run || dev) {
|
|
249
|
+
const cli_args = [];
|
|
250
|
+
if (dev) {
|
|
251
|
+
cli_args.push('-C', 'development'); // same as `--conditions`
|
|
252
|
+
}
|
|
253
|
+
cli_args.push(server_outpath);
|
|
254
|
+
server_process = spawn_restartable_process(cli_command ?? config.js_cli, cli_args);
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
teardown: async () => {
|
|
258
|
+
if (cleanup_watch) {
|
|
259
|
+
cleanup_watch();
|
|
260
|
+
cleanup_watch = undefined;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (server_process) {
|
|
264
|
+
const s = server_process; // avoid possible issue where a build is in progress, don't want to issue a restart, could be fixed upstream in `spawn_restartable_process`
|
|
265
|
+
server_process = undefined;
|
|
266
|
+
await s.kill();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (build_ctx) {
|
|
270
|
+
await build_ctx.dispose();
|
|
271
|
+
build_ctx = undefined;
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The esbuild metafile contains the paths in `entryPoints` relative to the `dir`
|
|
279
|
+
* even though we're resolving them to absolute paths before passing them to esbuild,
|
|
280
|
+
* so we resolve them here relative to the `dir`.
|
|
281
|
+
*/
|
|
282
|
+
const parse_deps = (metafile_inputs: Record<string, unknown>, dir: string): Set<string> => {
|
|
283
|
+
const deps: Set<string> = new Set();
|
|
284
|
+
for (const key in metafile_inputs) {
|
|
285
|
+
deps.add(resolve(dir, strip_before(key, ':')));
|
|
286
|
+
}
|
|
287
|
+
return deps;
|
|
288
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {args_serialize} from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import {spawn_result_to_message, type SpawnedProcess} from '@fuzdev/fuz_util/process.js';
|
|
3
|
+
|
|
4
|
+
import {to_forwarded_args} from './args.ts';
|
|
5
|
+
import {find_cli, spawn_cli, spawn_cli_process} from './cli.ts';
|
|
6
|
+
import {VITE_CLI} from './constants.ts';
|
|
7
|
+
import type {Plugin} from './plugin.ts';
|
|
8
|
+
import {TaskError} from './task.ts';
|
|
9
|
+
|
|
10
|
+
export interface GroPluginSveltekitAppOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The Vite CLI to use.
|
|
13
|
+
*/
|
|
14
|
+
vite_cli?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const gro_plugin_sveltekit_app = ({
|
|
18
|
+
vite_cli = VITE_CLI,
|
|
19
|
+
}: GroPluginSveltekitAppOptions = {}): Plugin => {
|
|
20
|
+
let sveltekit_process: SpawnedProcess | undefined = undefined;
|
|
21
|
+
return {
|
|
22
|
+
name: 'gro_plugin_sveltekit_app',
|
|
23
|
+
setup: async ({dev, watch, log, config}) => {
|
|
24
|
+
const found_vite_cli = await find_cli(vite_cli);
|
|
25
|
+
if (!found_vite_cli)
|
|
26
|
+
throw Error(
|
|
27
|
+
`Failed to find Vite CLI \`${vite_cli}\`, do you need to run \`${config.pm_cli} i\`?`,
|
|
28
|
+
);
|
|
29
|
+
if (dev) {
|
|
30
|
+
// `vite dev` in development mode
|
|
31
|
+
if (watch) {
|
|
32
|
+
const serialized_args = ['dev', ...args_serialize(to_forwarded_args(vite_cli))];
|
|
33
|
+
sveltekit_process = await spawn_cli_process(found_vite_cli, serialized_args, log);
|
|
34
|
+
} else {
|
|
35
|
+
log.debug(
|
|
36
|
+
`the SvelteKit app plugin is loaded but will not output anything` +
|
|
37
|
+
' because `dev` is true and `watch` is false',
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
// `vite build` in production mode
|
|
42
|
+
const serialized_args = ['build', ...args_serialize(to_forwarded_args(vite_cli))];
|
|
43
|
+
const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
|
|
44
|
+
if (!spawned?.ok) {
|
|
45
|
+
throw new TaskError(
|
|
46
|
+
`${vite_cli} build failed: ${spawned ? spawn_result_to_message(spawned) : 'unknown error'}`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
teardown: async () => {
|
|
52
|
+
if (sveltekit_process) {
|
|
53
|
+
sveltekit_process.child.kill();
|
|
54
|
+
await sveltekit_process.closed;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {print_spawn_result, spawn, spawn_result_to_message} from '@fuzdev/fuz_util/process.js';
|
|
2
|
+
|
|
3
|
+
import type {Plugin} from './plugin.ts';
|
|
4
|
+
import {TaskError} from './task.ts';
|
|
5
|
+
import {package_json_load} from './package_json.ts';
|
|
6
|
+
import {run_svelte_package, type SveltePackageOptions} from './sveltekit_helpers.ts';
|
|
7
|
+
import {SVELTE_PACKAGE_CLI} from './constants.ts';
|
|
8
|
+
|
|
9
|
+
export interface GroPluginSveltekitLibraryOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The options passed to the SvelteKit packaging CLI.
|
|
12
|
+
* @see https://kit.svelte.dev/docs/packaging#options
|
|
13
|
+
*/
|
|
14
|
+
svelte_package_options?: SveltePackageOptions;
|
|
15
|
+
/**
|
|
16
|
+
* The SvelteKit packaging CLI to use. Defaults to `svelte-package`.
|
|
17
|
+
* @see https://kit.svelte.dev/docs/packaging
|
|
18
|
+
*/
|
|
19
|
+
svelte_package_cli?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const gro_plugin_sveltekit_library = ({
|
|
23
|
+
svelte_package_options,
|
|
24
|
+
svelte_package_cli = SVELTE_PACKAGE_CLI,
|
|
25
|
+
}: GroPluginSveltekitLibraryOptions = {}): Plugin => {
|
|
26
|
+
return {
|
|
27
|
+
name: 'gro_plugin_sveltekit_library',
|
|
28
|
+
setup: async ({dev, log, config}) => {
|
|
29
|
+
if (!dev) {
|
|
30
|
+
const package_json = await package_json_load();
|
|
31
|
+
await run_svelte_package(
|
|
32
|
+
package_json,
|
|
33
|
+
svelte_package_options,
|
|
34
|
+
svelte_package_cli,
|
|
35
|
+
log,
|
|
36
|
+
config.pm_cli,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
adapt: async ({log, timings, config}) => {
|
|
41
|
+
const package_json = await package_json_load();
|
|
42
|
+
// link the CLI binaries if they exist
|
|
43
|
+
if (package_json.bin) {
|
|
44
|
+
const timing_to_link = timings.start(`${config.pm_cli} link`);
|
|
45
|
+
await Promise.all(
|
|
46
|
+
Object.values(package_json.bin).map(async (bin_path) => {
|
|
47
|
+
const chmod_result = await spawn('chmod', ['+x', bin_path]);
|
|
48
|
+
if (!chmod_result.ok)
|
|
49
|
+
log.error(
|
|
50
|
+
`chmod on bin path ${bin_path} failed: ${spawn_result_to_message(chmod_result)}`,
|
|
51
|
+
);
|
|
52
|
+
}),
|
|
53
|
+
);
|
|
54
|
+
log.info(`linking`);
|
|
55
|
+
const link_result = await spawn(config.pm_cli, ['link', '-f']); // TODO don't use `-f` unless necessary or at all?
|
|
56
|
+
if (!link_result.ok) {
|
|
57
|
+
throw new TaskError(`Failed to link. ${print_spawn_result(link_result)}`);
|
|
58
|
+
}
|
|
59
|
+
timing_to_link();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
};
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @nodocs */
|
|
2
|
+
export type {GroConfig, CreateGroConfig, RawGroConfig} from './gro_config.ts';
|
|
3
|
+
/** @nodocs */
|
|
4
|
+
export {type Plugin, plugin_replace} from './plugin.ts';
|
|
5
|
+
/** @nodocs */
|
|
6
|
+
export type {Gen, GenContext} from './gen.ts';
|
|
7
|
+
/** @nodocs */
|
|
8
|
+
export {type Task, type TaskContext, TaskError} from './task.ts';
|