@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,110 @@
|
|
|
1
|
+
import {styleText as st} from 'node:util';
|
|
2
|
+
import {print_error} from '@fuzdev/fuz_util/print.js';
|
|
3
|
+
import type {Timings} from '@fuzdev/fuz_util/timings.js';
|
|
4
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
5
|
+
import {map_concurrent} from '@fuzdev/fuz_util/async.js';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type GenResults,
|
|
9
|
+
type GenfileModuleResult,
|
|
10
|
+
type GenContext,
|
|
11
|
+
type GenfileModuleMeta,
|
|
12
|
+
to_gen_result,
|
|
13
|
+
type RawGenResult,
|
|
14
|
+
normalize_gen_config,
|
|
15
|
+
} from './gen.ts';
|
|
16
|
+
import {print_path, to_root_path} from './paths.ts';
|
|
17
|
+
import type {format_file as base_format_file} from './format_file.ts';
|
|
18
|
+
import type {GroConfig} from './gro_config.ts';
|
|
19
|
+
import {default_svelte_config} from './svelte_config.ts';
|
|
20
|
+
import type {Filer} from './filer.ts';
|
|
21
|
+
import type {InvokeTask} from './task.ts';
|
|
22
|
+
|
|
23
|
+
export const GEN_NO_PROD_MESSAGE = 'gen runs only during development';
|
|
24
|
+
|
|
25
|
+
export const run_gen = async (
|
|
26
|
+
gen_modules: Array<GenfileModuleMeta>,
|
|
27
|
+
config: GroConfig,
|
|
28
|
+
filer: Filer,
|
|
29
|
+
log: Logger,
|
|
30
|
+
timings: Timings,
|
|
31
|
+
invoke_task: InvokeTask,
|
|
32
|
+
format_file?: typeof base_format_file,
|
|
33
|
+
): Promise<GenResults> => {
|
|
34
|
+
let input_count = 0;
|
|
35
|
+
let output_count = 0;
|
|
36
|
+
const timing_for_run_gen = timings.start('run_gen');
|
|
37
|
+
const results = await map_concurrent(
|
|
38
|
+
gen_modules,
|
|
39
|
+
async (module_meta): Promise<GenfileModuleResult> => {
|
|
40
|
+
input_count++;
|
|
41
|
+
const {id} = module_meta;
|
|
42
|
+
const timing_for_module = timings.start(id);
|
|
43
|
+
|
|
44
|
+
const gen_config = normalize_gen_config(module_meta.mod.gen);
|
|
45
|
+
const gen_ctx: GenContext = {
|
|
46
|
+
config,
|
|
47
|
+
svelte_config: default_svelte_config,
|
|
48
|
+
filer,
|
|
49
|
+
log,
|
|
50
|
+
timings,
|
|
51
|
+
invoke_task,
|
|
52
|
+
origin_id: id,
|
|
53
|
+
origin_path: to_root_path(id),
|
|
54
|
+
changed_file_id: undefined,
|
|
55
|
+
};
|
|
56
|
+
let raw_gen_result: RawGenResult;
|
|
57
|
+
try {
|
|
58
|
+
raw_gen_result = await gen_config.generate(gen_ctx);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
id,
|
|
63
|
+
error,
|
|
64
|
+
reason: st('red', `Error generating ${print_path(id)}`),
|
|
65
|
+
elapsed: timing_for_module(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Convert the module's return value to a normalized form.
|
|
70
|
+
const gen_result = to_gen_result(id, raw_gen_result);
|
|
71
|
+
|
|
72
|
+
// Format the files if needed.
|
|
73
|
+
const files = format_file
|
|
74
|
+
? await map_concurrent(
|
|
75
|
+
gen_result.files,
|
|
76
|
+
async (file) => {
|
|
77
|
+
if (!file.format) return file;
|
|
78
|
+
try {
|
|
79
|
+
return {...file, content: await format_file(file.content, {filepath: file.id})};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
log.error(
|
|
82
|
+
st('red', `Error formatting ${print_path(file.id)} via ${print_path(id)}`),
|
|
83
|
+
print_error(error),
|
|
84
|
+
);
|
|
85
|
+
return file;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
10,
|
|
89
|
+
)
|
|
90
|
+
: gen_result.files;
|
|
91
|
+
|
|
92
|
+
output_count += files.length;
|
|
93
|
+
return {
|
|
94
|
+
ok: true,
|
|
95
|
+
id,
|
|
96
|
+
files,
|
|
97
|
+
elapsed: timing_for_module(),
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
10,
|
|
101
|
+
);
|
|
102
|
+
return {
|
|
103
|
+
results,
|
|
104
|
+
successes: results.filter((r) => r.ok),
|
|
105
|
+
failures: results.filter((r) => !r.ok),
|
|
106
|
+
input_count,
|
|
107
|
+
output_count,
|
|
108
|
+
elapsed: timing_for_run_gen(),
|
|
109
|
+
};
|
|
110
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {args_parse, type Args} from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
3
|
+
import type {Timings} from '@fuzdev/fuz_util/timings.js';
|
|
4
|
+
import {styleText as st} from 'node:util';
|
|
5
|
+
import {z} from 'zod';
|
|
6
|
+
|
|
7
|
+
import type {Filer} from './filer.ts';
|
|
8
|
+
import type {GroConfig} from './gro_config.ts';
|
|
9
|
+
import type {invoke_task as base_invoke_task} from './invoke_task.ts';
|
|
10
|
+
import {default_svelte_config} from './svelte_config.ts';
|
|
11
|
+
import {TaskError, type TaskModuleMeta} from './task.ts';
|
|
12
|
+
import {log_task_help} from './task_logging.ts';
|
|
13
|
+
|
|
14
|
+
export type RunTaskResult =
|
|
15
|
+
| {
|
|
16
|
+
ok: true;
|
|
17
|
+
output: unknown;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: string;
|
|
22
|
+
error: Error;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const run_task = async (
|
|
26
|
+
task_meta: TaskModuleMeta,
|
|
27
|
+
unparsed_args: Args,
|
|
28
|
+
invoke_task: typeof base_invoke_task,
|
|
29
|
+
config: GroConfig,
|
|
30
|
+
filer: Filer,
|
|
31
|
+
log: Logger,
|
|
32
|
+
timings: Timings,
|
|
33
|
+
): Promise<RunTaskResult> => {
|
|
34
|
+
const {task} = task_meta.mod;
|
|
35
|
+
|
|
36
|
+
if (unparsed_args.help) {
|
|
37
|
+
log_task_help(log, task_meta);
|
|
38
|
+
return {ok: true, output: null};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Parse and validate args.
|
|
42
|
+
let args = unparsed_args;
|
|
43
|
+
if (task.Args) {
|
|
44
|
+
const parsed = args_parse(unparsed_args, task.Args);
|
|
45
|
+
if (!parsed.success) {
|
|
46
|
+
throw new TaskError(
|
|
47
|
+
`Failed task args validation for task '${task_meta.name}':\n${z.prettifyError(parsed.error)}`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
args = parsed.data;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Run the task.
|
|
54
|
+
let output: unknown; // TODO generic
|
|
55
|
+
try {
|
|
56
|
+
output = await task.run({
|
|
57
|
+
args,
|
|
58
|
+
config,
|
|
59
|
+
svelte_config: default_svelte_config,
|
|
60
|
+
filer,
|
|
61
|
+
log,
|
|
62
|
+
timings,
|
|
63
|
+
invoke_task: (invoked_task_name, invoked_args, invoked_config) =>
|
|
64
|
+
invoke_task(invoked_task_name, invoked_args, invoked_config ?? config, filer, timings, log),
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
ok: false,
|
|
69
|
+
reason: st(
|
|
70
|
+
'red',
|
|
71
|
+
error?.constructor?.name === 'TaskError'
|
|
72
|
+
? (error.message as string)
|
|
73
|
+
: `Unexpected error running task ${st(
|
|
74
|
+
'cyan',
|
|
75
|
+
task_meta.name,
|
|
76
|
+
)}. If this is unexpected try running \`${config.pm_cli} install\` and \`gro clean\`.`,
|
|
77
|
+
),
|
|
78
|
+
error,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return {ok: true, output};
|
|
82
|
+
};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {join} from 'node:path';
|
|
2
|
+
import {ensure_end, strip_start} from '@fuzdev/fuz_util/string.js';
|
|
3
|
+
import {fs_exists, fs_search} from '@fuzdev/fuz_util/fs.js';
|
|
4
|
+
import ts from 'typescript';
|
|
5
|
+
import type {PackageJson, PackageJsonExports} from '@fuzdev/fuz_util/package_json.js';
|
|
6
|
+
import {SourceJson, type ModuleJson, type DeclarationKind} from '@fuzdev/fuz_util/source_json.js';
|
|
7
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
8
|
+
|
|
9
|
+
import {paths, replace_extension} from './paths.ts';
|
|
10
|
+
import {parse_exports} from './parse_exports.ts';
|
|
11
|
+
import {TS_MATCHER, SVELTE_MATCHER, JSON_MATCHER, CSS_MATCHER} from './constants.ts';
|
|
12
|
+
|
|
13
|
+
export type SourceJsonMapper = (
|
|
14
|
+
source_json: SourceJson,
|
|
15
|
+
) => SourceJson | null | Promise<SourceJson | null>;
|
|
16
|
+
|
|
17
|
+
export const source_json_create = async (
|
|
18
|
+
package_json: PackageJson,
|
|
19
|
+
lib_path?: string,
|
|
20
|
+
log?: Logger,
|
|
21
|
+
): Promise<SourceJson> =>
|
|
22
|
+
SourceJson.parse({
|
|
23
|
+
name: package_json.name,
|
|
24
|
+
version: package_json.version,
|
|
25
|
+
modules: await source_json_modules_create(package_json.exports, lib_path, log),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const source_json_modules_create = async (
|
|
29
|
+
exports: PackageJsonExports | undefined,
|
|
30
|
+
lib_path = paths.lib,
|
|
31
|
+
log?: Logger,
|
|
32
|
+
): Promise<Array<ModuleJson> | undefined> => {
|
|
33
|
+
if (!exports) return;
|
|
34
|
+
|
|
35
|
+
const file_paths = await collect_file_paths(exports, lib_path);
|
|
36
|
+
|
|
37
|
+
// Create a TypeScript program for all TypeScript files
|
|
38
|
+
const ts_files = file_paths
|
|
39
|
+
.filter(({file_path}) => TS_MATCHER.test(file_path))
|
|
40
|
+
.map(({file_path}) => file_path);
|
|
41
|
+
|
|
42
|
+
let program: ts.Program | undefined;
|
|
43
|
+
if (ts_files.length > 0) {
|
|
44
|
+
program = ts.createProgram(
|
|
45
|
+
ts_files,
|
|
46
|
+
// TODO get from tsconfig?
|
|
47
|
+
{
|
|
48
|
+
target: ts.ScriptTarget.ESNext,
|
|
49
|
+
module: ts.ModuleKind.ESNext,
|
|
50
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
51
|
+
verbatimModuleSyntax: true,
|
|
52
|
+
isolatedModules: true,
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const result: Array<ModuleJson> = [];
|
|
58
|
+
|
|
59
|
+
// Process each file
|
|
60
|
+
for (const {file_path} of file_paths) {
|
|
61
|
+
const relative_path = file_path.replace(ensure_end(lib_path, '/'), '');
|
|
62
|
+
|
|
63
|
+
const declarations = parse_exports(file_path, program, undefined, log)
|
|
64
|
+
.filter((d): d is {name: string; kind: DeclarationKind} => d.kind !== null) // TODO maybe dont filter out?
|
|
65
|
+
.map(({name, kind}) => ({name, kind}));
|
|
66
|
+
|
|
67
|
+
result.push(
|
|
68
|
+
declarations.length
|
|
69
|
+
? {
|
|
70
|
+
path: relative_path,
|
|
71
|
+
declarations,
|
|
72
|
+
}
|
|
73
|
+
: {
|
|
74
|
+
path: relative_path,
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return result;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const collect_file_paths = async (
|
|
83
|
+
exports: PackageJsonExports,
|
|
84
|
+
lib_path: string,
|
|
85
|
+
): Promise<Array<{export_key: string; file_path: string}>> => {
|
|
86
|
+
const file_paths: Array<{export_key: string; file_path: string}> = [];
|
|
87
|
+
|
|
88
|
+
// Handle string exports (single default export)
|
|
89
|
+
if (typeof exports === 'string') {
|
|
90
|
+
const source_file = await infer_source_from_export(exports, lib_path);
|
|
91
|
+
if (source_file) {
|
|
92
|
+
file_paths.push({export_key: '.', file_path: source_file});
|
|
93
|
+
} else {
|
|
94
|
+
throw Error(
|
|
95
|
+
`Failed to infer source file from package.json string export "${exports}" - no matching file found in ${lib_path}`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return file_paths;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Handle object exports
|
|
102
|
+
for (const k in exports) {
|
|
103
|
+
// Skip package.json
|
|
104
|
+
if (k === './package.json') continue;
|
|
105
|
+
|
|
106
|
+
// Check if this is a pattern export
|
|
107
|
+
if (k.includes('*')) {
|
|
108
|
+
// Handle pattern exports by finding matching files in lib
|
|
109
|
+
// eslint-disable-next-line no-await-in-loop
|
|
110
|
+
const matching_files = await fs_search(lib_path, {
|
|
111
|
+
file_filter: (path) => {
|
|
112
|
+
const p = path.replace(ensure_end(lib_path, '/'), '');
|
|
113
|
+
// Only match files in the root directory (no subdirectories)
|
|
114
|
+
if (p.includes('/')) return false;
|
|
115
|
+
|
|
116
|
+
// Match based on the export pattern
|
|
117
|
+
if (k === './*.js') {
|
|
118
|
+
return TS_MATCHER.test(p) && !p.endsWith('.d.ts') && !p.endsWith('.test.ts');
|
|
119
|
+
} else if (k === './*.svelte') {
|
|
120
|
+
return SVELTE_MATCHER.test(p);
|
|
121
|
+
} else if (k === './*.json') {
|
|
122
|
+
return JSON_MATCHER.test(p);
|
|
123
|
+
} else if (k === './*.css') {
|
|
124
|
+
return CSS_MATCHER.test(p);
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Add each matching file
|
|
131
|
+
for (const file of matching_files) {
|
|
132
|
+
let export_path: string;
|
|
133
|
+
if (file.path.endsWith('.ts')) {
|
|
134
|
+
export_path = './' + file.path.replace('.ts', '.js');
|
|
135
|
+
} else {
|
|
136
|
+
export_path = './' + file.path;
|
|
137
|
+
}
|
|
138
|
+
file_paths.push({export_key: export_path, file_path: file.id});
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
// Handle explicit exports (non-patterns)
|
|
142
|
+
// eslint-disable-next-line no-await-in-loop
|
|
143
|
+
const source_file = await infer_source_from_export(k, lib_path);
|
|
144
|
+
if (source_file) {
|
|
145
|
+
file_paths.push({export_key: k, file_path: source_file});
|
|
146
|
+
} else {
|
|
147
|
+
throw Error(
|
|
148
|
+
`Failed to infer source file from package.json export path ${k} - no matching file found in ${lib_path}`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return file_paths;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const infer_source_from_export = async (
|
|
158
|
+
export_path: string,
|
|
159
|
+
lib_path: string,
|
|
160
|
+
): Promise<string | null> => {
|
|
161
|
+
// Handle index specially
|
|
162
|
+
if (export_path === '.' || export_path === './') {
|
|
163
|
+
const index_ts = join(lib_path, 'index.ts');
|
|
164
|
+
if (await fs_exists(index_ts)) return index_ts;
|
|
165
|
+
const index_js = join(lib_path, 'index.js');
|
|
166
|
+
if (await fs_exists(index_js)) return index_js;
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const clean_path = strip_start(export_path, './');
|
|
171
|
+
|
|
172
|
+
// For .js exports, try .ts first
|
|
173
|
+
if (clean_path.endsWith('.js')) {
|
|
174
|
+
const ts_path = join(lib_path, replace_extension(clean_path, '.ts'));
|
|
175
|
+
if (await fs_exists(ts_path)) return ts_path;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Try the exact path
|
|
179
|
+
const exact_path = join(lib_path, clean_path);
|
|
180
|
+
if (await fs_exists(exact_path)) return exact_path;
|
|
181
|
+
|
|
182
|
+
return null;
|
|
183
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type {Config as SvelteConfig} from '@sveltejs/kit';
|
|
2
|
+
import type {CompileOptions, ModuleCompileOptions, PreprocessorGroup} from 'svelte/compiler';
|
|
3
|
+
import {join} from 'node:path';
|
|
4
|
+
import {EMPTY_OBJECT} from '@fuzdev/fuz_util/object.js';
|
|
5
|
+
|
|
6
|
+
import {SVELTE_CONFIG_FILENAME} from './constants.ts';
|
|
7
|
+
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
9
|
+
// see https://github.com/sveltejs/kit/discussions/14240
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
|
|
13
|
+
This module is intended to have minimal dependencies to avoid over-imports in the CLI.
|
|
14
|
+
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Loads a SvelteKit config at `dir`.
|
|
19
|
+
* @returns `null` if no config is found
|
|
20
|
+
*/
|
|
21
|
+
export const load_svelte_config = async ({
|
|
22
|
+
dir = process.cwd(),
|
|
23
|
+
config_filename = SVELTE_CONFIG_FILENAME,
|
|
24
|
+
}: {dir?: string; config_filename?: string} = EMPTY_OBJECT): Promise<SvelteConfig | null> => {
|
|
25
|
+
try {
|
|
26
|
+
return (await import(join(dir, config_filename))).default;
|
|
27
|
+
} catch (_err) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A subset of SvelteKit's config in a form that Gro uses
|
|
34
|
+
* because SvelteKit doesn't expose its config resolver.
|
|
35
|
+
* Flattens things out to keep them simple and easy to pass around,
|
|
36
|
+
* and doesn't deal with most properties, but includes the full `svelte_config`.
|
|
37
|
+
* The `base` and `assets` in particular are renamed for clarity with Gro's internal systems,
|
|
38
|
+
* so these properties become first-class vocabulary inside Gro.
|
|
39
|
+
*/
|
|
40
|
+
export interface ParsedSvelteConfig {
|
|
41
|
+
// TODO probably fill these out with defaults
|
|
42
|
+
svelte_config: SvelteConfig | null;
|
|
43
|
+
alias: Record<string, string>;
|
|
44
|
+
base_url: '' | `/${string}` | undefined;
|
|
45
|
+
assets_url: '' | `http://${string}` | `https://${string}` | undefined;
|
|
46
|
+
|
|
47
|
+
// TODO others, but maybe replace with a Zod schema? https://kit.svelte.dev/docs/configuration
|
|
48
|
+
/**
|
|
49
|
+
* Same as the SvelteKit `files.assets`.
|
|
50
|
+
*/
|
|
51
|
+
assets_path: string;
|
|
52
|
+
/**
|
|
53
|
+
* Same as the SvelteKit `files.lib`.
|
|
54
|
+
*/
|
|
55
|
+
lib_path: string;
|
|
56
|
+
/**
|
|
57
|
+
* Same as the SvelteKit `files.routes`.
|
|
58
|
+
*/
|
|
59
|
+
routes_path: string;
|
|
60
|
+
|
|
61
|
+
env_dir: string | undefined;
|
|
62
|
+
private_prefix: string | undefined;
|
|
63
|
+
public_prefix: string | undefined;
|
|
64
|
+
svelte_compile_options: CompileOptions;
|
|
65
|
+
svelte_compile_module_options: ModuleCompileOptions;
|
|
66
|
+
svelte_preprocessors: PreprocessorGroup | Array<PreprocessorGroup> | undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// TODO currently incomplete and hack - maybe rethink
|
|
70
|
+
/**
|
|
71
|
+
* Returns Gro-relevant properties of a SvelteKit config
|
|
72
|
+
* as a convenience wrapper around `load_svelte_config`.
|
|
73
|
+
* Needed because SvelteKit doesn't expose its config resolver.
|
|
74
|
+
*/
|
|
75
|
+
export const parse_svelte_config = async ({
|
|
76
|
+
dir_or_config = process.cwd(), // TODO maybe not the best API, maybe a type union? `({svelte_config} | {dir}) & {config_filename}`
|
|
77
|
+
config_filename = SVELTE_CONFIG_FILENAME,
|
|
78
|
+
}: {
|
|
79
|
+
dir_or_config?: string | SvelteConfig;
|
|
80
|
+
config_filename?: string;
|
|
81
|
+
} = EMPTY_OBJECT): Promise<ParsedSvelteConfig> => {
|
|
82
|
+
const svelte_config =
|
|
83
|
+
typeof dir_or_config === 'string'
|
|
84
|
+
? await load_svelte_config({dir: dir_or_config, config_filename})
|
|
85
|
+
: dir_or_config;
|
|
86
|
+
|
|
87
|
+
const kit = svelte_config?.kit;
|
|
88
|
+
|
|
89
|
+
const alias = {$lib: 'src/lib', ...kit?.alias};
|
|
90
|
+
|
|
91
|
+
const base_url = kit?.paths?.base;
|
|
92
|
+
const assets_url = kit?.paths?.assets;
|
|
93
|
+
|
|
94
|
+
// TODO probably a Zod schema instead
|
|
95
|
+
const assets_path = kit?.files?.assets ?? 'static';
|
|
96
|
+
const lib_path = kit?.files?.lib ?? 'src/lib';
|
|
97
|
+
const routes_path = kit?.files?.routes ?? 'src/routes';
|
|
98
|
+
|
|
99
|
+
const env_dir = kit?.env?.dir;
|
|
100
|
+
const private_prefix = kit?.env?.privatePrefix;
|
|
101
|
+
const public_prefix = kit?.env?.publicPrefix;
|
|
102
|
+
|
|
103
|
+
const svelte_compile_options: CompileOptions = svelte_config?.compilerOptions ?? {};
|
|
104
|
+
// Change the default to `generate: 'server'`,
|
|
105
|
+
// because SvelteKit handles the client in the normal cases.
|
|
106
|
+
if (svelte_compile_options.generate === undefined) {
|
|
107
|
+
svelte_compile_options.generate = 'server';
|
|
108
|
+
}
|
|
109
|
+
const svelte_compile_module_options = to_default_compile_module_options(svelte_compile_options); // TODO will kit have these separately?
|
|
110
|
+
const svelte_preprocessors = svelte_config?.preprocess;
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
svelte_config,
|
|
114
|
+
alias,
|
|
115
|
+
base_url,
|
|
116
|
+
assets_url,
|
|
117
|
+
assets_path,
|
|
118
|
+
lib_path,
|
|
119
|
+
routes_path,
|
|
120
|
+
env_dir,
|
|
121
|
+
private_prefix,
|
|
122
|
+
public_prefix,
|
|
123
|
+
svelte_compile_options,
|
|
124
|
+
svelte_compile_module_options,
|
|
125
|
+
svelte_preprocessors,
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export const to_default_compile_module_options = ({
|
|
130
|
+
dev,
|
|
131
|
+
generate,
|
|
132
|
+
filename,
|
|
133
|
+
rootDir,
|
|
134
|
+
warningFilter,
|
|
135
|
+
}: CompileOptions): ModuleCompileOptions => ({dev, generate, filename, rootDir, warningFilter});
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The parsed SvelteKit config for the cwd, cached globally at the module level.
|
|
139
|
+
*/
|
|
140
|
+
export const default_svelte_config = await parse_svelte_config(); // always load it to keep things simple ahead
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {args_serialize} from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import {fs_exists} from '@fuzdev/fuz_util/fs.js';
|
|
3
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
4
|
+
import type {PackageJson} from '@fuzdev/fuz_util/package_json.js';
|
|
5
|
+
import type {Result} from '@fuzdev/fuz_util/result.js';
|
|
6
|
+
import {join} from 'node:path';
|
|
7
|
+
|
|
8
|
+
import {to_forwarded_args} from './args.ts';
|
|
9
|
+
import {find_cli, spawn_cli, to_cli_name, type Cli} from './cli.ts';
|
|
10
|
+
import {
|
|
11
|
+
PM_CLI_DEFAULT,
|
|
12
|
+
SVELTE_CONFIG_FILENAME,
|
|
13
|
+
SVELTE_PACKAGE_DEP_NAME,
|
|
14
|
+
SVELTEKIT_CLI,
|
|
15
|
+
SVELTEKIT_DEV_DIRNAME,
|
|
16
|
+
} from './constants.ts';
|
|
17
|
+
import {package_json_has_dependency} from './package_json.ts';
|
|
18
|
+
import {default_svelte_config, type ParsedSvelteConfig} from './svelte_config.ts';
|
|
19
|
+
import {TaskError} from './task.ts';
|
|
20
|
+
|
|
21
|
+
export const has_sveltekit_app = async (
|
|
22
|
+
svelte_config_path: string = SVELTE_CONFIG_FILENAME,
|
|
23
|
+
): Promise<Result<object, {message: string}>> => {
|
|
24
|
+
if (!(await fs_exists(svelte_config_path))) {
|
|
25
|
+
return {ok: false, message: `no SvelteKit config found at ${SVELTE_CONFIG_FILENAME}`};
|
|
26
|
+
}
|
|
27
|
+
// TODO check for routes?
|
|
28
|
+
return {ok: true};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const has_sveltekit_library = async (
|
|
32
|
+
package_json: PackageJson,
|
|
33
|
+
svelte_config: ParsedSvelteConfig = default_svelte_config,
|
|
34
|
+
dep_name = SVELTE_PACKAGE_DEP_NAME,
|
|
35
|
+
): Promise<Result<object, {message: string}>> => {
|
|
36
|
+
const has_sveltekit_app_result = await has_sveltekit_app();
|
|
37
|
+
if (!has_sveltekit_app_result.ok) {
|
|
38
|
+
return has_sveltekit_app_result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!(await fs_exists(svelte_config.lib_path))) {
|
|
42
|
+
return {ok: false, message: `no SvelteKit lib directory found at ${svelte_config.lib_path}`};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!package_json_has_dependency(dep_name, package_json)) {
|
|
46
|
+
return {
|
|
47
|
+
ok: false,
|
|
48
|
+
message: `no dependency found in package.json for ${dep_name}`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {ok: true};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const sveltekit_sync = async (
|
|
56
|
+
sveltekit_cli: string | Cli = SVELTEKIT_CLI,
|
|
57
|
+
pm_cli = PM_CLI_DEFAULT, // TODO source from config when possible, is just needed for error messages
|
|
58
|
+
): Promise<void> => {
|
|
59
|
+
const result = await spawn_cli(sveltekit_cli, ['sync']);
|
|
60
|
+
if (!result) {
|
|
61
|
+
throw new TaskError(
|
|
62
|
+
`Failed to find SvelteKit CLI \`${to_cli_name(sveltekit_cli)}\`, do you need to run \`${pm_cli} install\`?`,
|
|
63
|
+
);
|
|
64
|
+
} else if (!result.ok) {
|
|
65
|
+
throw new TaskError(`Failed ${to_cli_name(sveltekit_cli)} sync`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// TODO maybe this shouldn't exist, instead error if `package.json` has SvelteKit but it's not found (with install message above)
|
|
70
|
+
/**
|
|
71
|
+
* If the SvelteKit CLI is found and its `.svelte-kit` directory is not, run `svelte-kit sync`.
|
|
72
|
+
*/
|
|
73
|
+
export const sveltekit_sync_if_available = async (
|
|
74
|
+
sveltekit_cli: string | Cli = SVELTEKIT_CLI,
|
|
75
|
+
): Promise<void> => {
|
|
76
|
+
const found_sveltekit_cli =
|
|
77
|
+
typeof sveltekit_cli === 'string' ? await find_cli(sveltekit_cli) : sveltekit_cli;
|
|
78
|
+
if (found_sveltekit_cli) {
|
|
79
|
+
return sveltekit_sync(found_sveltekit_cli);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* If the SvelteKit CLI is found and its `.svelte-kit` directory is not, run `svelte-kit sync`.
|
|
85
|
+
*/
|
|
86
|
+
export const sveltekit_sync_if_obviously_needed = async (
|
|
87
|
+
sveltekit_cli: string | Cli = SVELTEKIT_CLI,
|
|
88
|
+
): Promise<void> => {
|
|
89
|
+
if (await fs_exists(SVELTEKIT_DEV_DIRNAME)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const found_sveltekit_cli =
|
|
93
|
+
typeof sveltekit_cli === 'string' ? await find_cli(sveltekit_cli) : sveltekit_cli;
|
|
94
|
+
if (!found_sveltekit_cli) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
return sveltekit_sync(found_sveltekit_cli);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Options to the SvelteKit packaging CLI.
|
|
102
|
+
* @see https://kit.svelte.dev/docs/packaging#options
|
|
103
|
+
*/
|
|
104
|
+
export interface SveltePackageOptions {
|
|
105
|
+
/**
|
|
106
|
+
* Watch files in src/lib for changes and rebuild the package
|
|
107
|
+
*/
|
|
108
|
+
watch?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Alias for `watch`.
|
|
111
|
+
*/
|
|
112
|
+
w?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* The input directory which contains all the files of the package.
|
|
115
|
+
* Defaults to src/lib
|
|
116
|
+
*/
|
|
117
|
+
input?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Alias for `input`.
|
|
120
|
+
*/
|
|
121
|
+
i?: string;
|
|
122
|
+
/**
|
|
123
|
+
* The output directory where the processed files are written to.
|
|
124
|
+
* Your package.json's exports should point to files inside there,
|
|
125
|
+
* and the files array should include that folder.
|
|
126
|
+
* Defaults to dist
|
|
127
|
+
*/
|
|
128
|
+
output?: string;
|
|
129
|
+
/**
|
|
130
|
+
* Alias for `output`.
|
|
131
|
+
*/
|
|
132
|
+
o?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Whether or not to create type definitions (d.ts files).
|
|
135
|
+
* We strongly recommend doing this as it fosters ecosystem library quality.
|
|
136
|
+
* Defaults to true
|
|
137
|
+
*/
|
|
138
|
+
types?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Alias for `types`.
|
|
141
|
+
*/
|
|
142
|
+
t?: boolean;
|
|
143
|
+
/**
|
|
144
|
+
* The path to a tsconfig or jsconfig.
|
|
145
|
+
* When not provided, searches for the next upper tsconfig/jsconfig in the workspace path.
|
|
146
|
+
*/
|
|
147
|
+
tsconfig?: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const run_svelte_package = async (
|
|
151
|
+
package_json: PackageJson,
|
|
152
|
+
options: SveltePackageOptions | undefined,
|
|
153
|
+
cli: string | Cli,
|
|
154
|
+
log: Logger,
|
|
155
|
+
pm_cli: string,
|
|
156
|
+
): Promise<void> => {
|
|
157
|
+
const has_sveltekit_library_result = await has_sveltekit_library(package_json);
|
|
158
|
+
if (!has_sveltekit_library_result.ok) {
|
|
159
|
+
throw new TaskError(
|
|
160
|
+
'Failed to find SvelteKit library: ' + has_sveltekit_library_result.message,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
const cli_name = typeof cli === 'string' ? cli : cli.name;
|
|
164
|
+
const found_svelte_package_cli = cli === cli_name ? await find_cli(cli) : (cli as Cli);
|
|
165
|
+
if (found_svelte_package_cli?.kind !== 'local') {
|
|
166
|
+
throw new TaskError(
|
|
167
|
+
`Failed to find SvelteKit packaging CLI \`${cli_name}\`, do you need to run \`${pm_cli} install\`?`,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
const serialized_args = args_serialize({
|
|
171
|
+
...options,
|
|
172
|
+
...to_forwarded_args(cli_name),
|
|
173
|
+
});
|
|
174
|
+
await spawn_cli(found_svelte_package_cli, serialized_args, log);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
//
|
|
178
|
+
/**
|
|
179
|
+
* Map an import specifier with the SvelteKit aliases.
|
|
180
|
+
*/
|
|
181
|
+
export const map_sveltekit_aliases = (
|
|
182
|
+
specifier: string,
|
|
183
|
+
aliases: Array<[string, string]>,
|
|
184
|
+
): string => {
|
|
185
|
+
let path = specifier;
|
|
186
|
+
for (const [from, to] of aliases) {
|
|
187
|
+
if (path.startsWith(from)) {
|
|
188
|
+
path = join(process.cwd(), to, path.substring(from.length));
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return path;
|
|
193
|
+
};
|