@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,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { has_sveltekit_library, has_sveltekit_app } from "./sveltekit_helpers.js";
|
|
3
|
+
import { package_json_load } from "./package_json.js";
|
|
4
|
+
/** @nodocs */
|
|
5
|
+
export const Args = z.strictObject({});
|
|
6
|
+
/** @nodocs */
|
|
7
|
+
export const task = {
|
|
8
|
+
summary: 'publish and deploy',
|
|
9
|
+
Args,
|
|
10
|
+
run: async ({ invoke_task }) => {
|
|
11
|
+
const package_json = await package_json_load();
|
|
12
|
+
const publish = (await has_sveltekit_library(package_json)).ok;
|
|
13
|
+
if (publish) {
|
|
14
|
+
await invoke_task('publish', { optional: true });
|
|
15
|
+
}
|
|
16
|
+
if ((await has_sveltekit_app()).ok) {
|
|
17
|
+
await invoke_task('deploy', { build: !publish });
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Task } from './task.ts';
|
|
3
|
+
/** @nodocs */
|
|
4
|
+
export declare const Args: z.ZodObject<{
|
|
5
|
+
_: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
6
|
+
verbose: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
}, z.core.$strict>;
|
|
8
|
+
export type Args = z.infer<typeof Args>;
|
|
9
|
+
/** @nodocs */
|
|
10
|
+
export declare const task: Task<Args>;
|
|
11
|
+
//# sourceMappingURL=resolve.task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/resolve.task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,OAAO,EAAqB,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAGxD,cAAc;AACd,eAAO,MAAM,IAAI;;;kBAGf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA4B3B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { styleText as st } from 'node:util';
|
|
3
|
+
import { TASK_FILE_SUFFIXES } from "./task.js";
|
|
4
|
+
import { resolve_input_paths, to_input_paths } from "./input_path.js";
|
|
5
|
+
/** @nodocs */
|
|
6
|
+
export const Args = z.strictObject({
|
|
7
|
+
_: z.array(z.string()).meta({ description: 'the input paths to resolve' }).default(['']),
|
|
8
|
+
verbose: z.boolean().meta({ description: 'log diagnostics' }).default(false),
|
|
9
|
+
});
|
|
10
|
+
/** @nodocs */
|
|
11
|
+
export const task = {
|
|
12
|
+
summary: 'diagnostic that logs resolved filesystem info for the given input paths',
|
|
13
|
+
Args,
|
|
14
|
+
run: async ({ args, config, log }) => {
|
|
15
|
+
const { _, verbose } = args;
|
|
16
|
+
if (verbose)
|
|
17
|
+
log.info('raw input paths:', _);
|
|
18
|
+
const input_paths = to_input_paths(_);
|
|
19
|
+
if (verbose)
|
|
20
|
+
log.info('input paths:', input_paths);
|
|
21
|
+
const { task_root_dirs } = config;
|
|
22
|
+
if (verbose)
|
|
23
|
+
log.info('task root paths:', task_root_dirs);
|
|
24
|
+
const { resolved_input_paths, possible_paths_by_input_path, unmapped_input_paths } = await resolve_input_paths(input_paths, task_root_dirs, TASK_FILE_SUFFIXES);
|
|
25
|
+
if (verbose)
|
|
26
|
+
log.info('resolved_input_paths:', resolved_input_paths);
|
|
27
|
+
if (verbose)
|
|
28
|
+
log.info('possible_paths_by_input_path:', possible_paths_by_input_path);
|
|
29
|
+
if (verbose)
|
|
30
|
+
log.info('unmapped_input_paths:', unmapped_input_paths);
|
|
31
|
+
for (const p of resolved_input_paths) {
|
|
32
|
+
log.info('resolved:', st('green', p.id));
|
|
33
|
+
}
|
|
34
|
+
if (!resolved_input_paths.length) {
|
|
35
|
+
log.warn(st('yellow', 'no input paths were resolved'));
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PathId } from '@fuzdev/fuz_util/path.js';
|
|
2
|
+
export interface ResolvedSpecifier {
|
|
3
|
+
/**
|
|
4
|
+
* The resolved filesystem path for the specifier.
|
|
5
|
+
*/
|
|
6
|
+
path_id: PathId;
|
|
7
|
+
/**
|
|
8
|
+
* Same as `path_id` but includes `?raw` and other querystrings. (currently none)
|
|
9
|
+
*/
|
|
10
|
+
path_id_with_querystring: string;
|
|
11
|
+
specifier: string;
|
|
12
|
+
mapped_specifier: string;
|
|
13
|
+
namespace: undefined | 'sveltekit_local_imports_ts' | 'sveltekit_local_imports_js';
|
|
14
|
+
raw: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Maps an import `specifier` relative to `dir`,
|
|
18
|
+
* and infer the correct extension following Vite conventions.
|
|
19
|
+
* If no `.js` file is found for the specifier on the filesystem, it assumes `.ts`.
|
|
20
|
+
*/
|
|
21
|
+
export declare const resolve_specifier: (specifier: string, dir: string) => Promise<ResolvedSpecifier>;
|
|
22
|
+
//# sourceMappingURL=resolve_specifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve_specifier.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/resolve_specifier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAMrD,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,wBAAwB,EAAE,MAAM,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,SAAS,GAAG,4BAA4B,GAAG,4BAA4B,CAAC;IACnF,GAAG,EAAE,OAAO,CAAC;CACb;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC7B,WAAW,MAAM,EACjB,KAAK,MAAM,KACT,OAAO,CAAC,iBAAiB,CAiD3B,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { extname, isAbsolute, join, relative } from 'node:path';
|
|
2
|
+
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
3
|
+
import { replace_extension } from "./paths.js";
|
|
4
|
+
/**
|
|
5
|
+
* Maps an import `specifier` relative to `dir`,
|
|
6
|
+
* and infer the correct extension following Vite conventions.
|
|
7
|
+
* If no `.js` file is found for the specifier on the filesystem, it assumes `.ts`.
|
|
8
|
+
*/
|
|
9
|
+
export const resolve_specifier = async (specifier, dir) => {
|
|
10
|
+
const raw = specifier.endsWith('?raw'); // TODO more robust detection? other values?
|
|
11
|
+
const final_specifier = raw ? specifier.substring(0, specifier.length - 4) : specifier;
|
|
12
|
+
const absolute_path = isAbsolute(final_specifier) ? final_specifier : join(dir, final_specifier);
|
|
13
|
+
let mapped_path;
|
|
14
|
+
let path_id;
|
|
15
|
+
let namespace;
|
|
16
|
+
const ext = extname(absolute_path);
|
|
17
|
+
const is_js = ext === '.js';
|
|
18
|
+
const is_ts = ext === '.ts';
|
|
19
|
+
if (!is_js && !is_ts && (await fs_exists(absolute_path))) {
|
|
20
|
+
// unrecognized extension and the file exists
|
|
21
|
+
mapped_path = absolute_path;
|
|
22
|
+
path_id = absolute_path;
|
|
23
|
+
}
|
|
24
|
+
else if (is_ts) {
|
|
25
|
+
// explicitly ts
|
|
26
|
+
mapped_path = replace_extension(absolute_path, '.js');
|
|
27
|
+
path_id = absolute_path;
|
|
28
|
+
namespace = 'sveltekit_local_imports_ts';
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
// extensionless, or js that points to ts, or just js
|
|
32
|
+
const js_id = is_js ? absolute_path : absolute_path + '.js';
|
|
33
|
+
const ts_id = is_js ? replace_extension(absolute_path, '.ts') : absolute_path + '.ts';
|
|
34
|
+
const [ts_exists, js_exists] = await Promise.all([fs_exists(ts_id), fs_exists(js_id)]);
|
|
35
|
+
if (!ts_exists && js_exists) {
|
|
36
|
+
mapped_path = js_id;
|
|
37
|
+
path_id = js_id;
|
|
38
|
+
namespace = 'sveltekit_local_imports_js';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
mapped_path = js_id;
|
|
42
|
+
path_id = ts_id;
|
|
43
|
+
namespace = 'sveltekit_local_imports_ts';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
let mapped_specifier = relative(dir, mapped_path);
|
|
47
|
+
if (mapped_specifier[0] !== '.')
|
|
48
|
+
mapped_specifier = './' + mapped_specifier;
|
|
49
|
+
return {
|
|
50
|
+
path_id,
|
|
51
|
+
path_id_with_querystring: raw ? path_id + '?raw' : path_id,
|
|
52
|
+
raw,
|
|
53
|
+
specifier,
|
|
54
|
+
mapped_specifier,
|
|
55
|
+
namespace,
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Task } from './task.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Runs a TypeScript file with Gro's loader, forwarding all args to the script.
|
|
5
|
+
* Useful for scripts that need SvelteKit shims ($lib, $env, etc).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** @nodocs */
|
|
10
|
+
export declare const Args: z.ZodObject<{
|
|
11
|
+
_: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
}, z.core.$catchall<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>]>>>;
|
|
13
|
+
export type Args = z.infer<typeof Args>;
|
|
14
|
+
/** @nodocs */
|
|
15
|
+
export declare const task: Task<Args>;
|
|
16
|
+
//# sourceMappingURL=run.task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/run.task.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAItB,OAAO,EAAY,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAE/C;;;;;GAKG;AAEH,cAAc;AACd,eAAO,MAAM,IAAI;;8JAWf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,cAAc;AACd,eAAO,MAAM,IAAI,EAAE,IAAI,CAAC,IAAI,CA+B3B,CAAC"}
|
package/dist/run.task.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { args_serialize } from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
3
|
+
import { spawn_result_to_message } from '@fuzdev/fuz_util/process.js';
|
|
4
|
+
import { styleText as st } from 'node:util';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { to_implicit_forwarded_args } from "./args.js";
|
|
7
|
+
import { resolve_gro_module_path, spawn_with_loader } from "./gro_helpers.js";
|
|
8
|
+
import { TaskError } from "./task.js";
|
|
9
|
+
/**
|
|
10
|
+
* Runs a TypeScript file with Gro's loader, forwarding all args to the script.
|
|
11
|
+
* Useful for scripts that need SvelteKit shims ($lib, $env, etc).
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
/** @nodocs */
|
|
16
|
+
export const Args = z
|
|
17
|
+
.object({
|
|
18
|
+
_: z.array(z.string()).meta({ description: 'the file path to run' }).default([]),
|
|
19
|
+
})
|
|
20
|
+
.catchall(z.union([
|
|
21
|
+
z.string(),
|
|
22
|
+
z.number(),
|
|
23
|
+
z.boolean(),
|
|
24
|
+
z.array(z.union([z.string(), z.number(), z.boolean()])),
|
|
25
|
+
]));
|
|
26
|
+
/** @nodocs */
|
|
27
|
+
export const task = {
|
|
28
|
+
summary: 'execute a file with the loader, like `node` but works for TypeScript',
|
|
29
|
+
Args,
|
|
30
|
+
run: async ({ args, log }) => {
|
|
31
|
+
const { _, ...forwarded_args } = args;
|
|
32
|
+
const [path, ...positional_argv] = _;
|
|
33
|
+
if (!path) {
|
|
34
|
+
log.info(st('green', '\n\nUsage: ') + st('cyan', 'gro run path/to/file.ts [...args]\n'));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!(await fs_exists(path))) {
|
|
38
|
+
throw new TaskError('Cannot find file to run at path: ' + path);
|
|
39
|
+
}
|
|
40
|
+
// Get args after `--` without requiring a command name.
|
|
41
|
+
// This allows `gro run script.ts -- --help` to pass --help to the script.
|
|
42
|
+
const implicit_args = to_implicit_forwarded_args();
|
|
43
|
+
// Reconstruct argv: positional args + explicit named args + implicit args after --
|
|
44
|
+
const named_argv = args_serialize({ ...forwarded_args, ...implicit_args });
|
|
45
|
+
const full_argv = [...positional_argv, ...named_argv];
|
|
46
|
+
const loader_path = resolve_gro_module_path('loader.js');
|
|
47
|
+
const spawned = await spawn_with_loader(loader_path, path, full_argv);
|
|
48
|
+
if (!spawned.ok) {
|
|
49
|
+
throw new TaskError(`\`gro run ${path}\` failed: ${spawn_result_to_message(spawned)}`);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Timings } from '@fuzdev/fuz_util/timings.js';
|
|
2
|
+
import type { Logger } from '@fuzdev/fuz_util/log.js';
|
|
3
|
+
import { type GenResults, type GenfileModuleMeta } from './gen.ts';
|
|
4
|
+
import type { format_file as base_format_file } from './format_file.ts';
|
|
5
|
+
import type { GroConfig } from './gro_config.ts';
|
|
6
|
+
import type { Filer } from './filer.ts';
|
|
7
|
+
import type { InvokeTask } from './task.ts';
|
|
8
|
+
export declare const GEN_NO_PROD_MESSAGE = "gen runs only during development";
|
|
9
|
+
export declare const run_gen: (gen_modules: Array<GenfileModuleMeta>, config: GroConfig, filer: Filer, log: Logger, timings: Timings, invoke_task: InvokeTask, format_file?: typeof base_format_file) => Promise<GenResults>;
|
|
10
|
+
//# sourceMappingURL=run_gen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run_gen.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/run_gen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,6BAA6B,CAAC;AACzD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAGpD,OAAO,EACN,KAAK,UAAU,EAGf,KAAK,iBAAiB,EAItB,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAC,WAAW,IAAI,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAE/C,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,WAAW,CAAC;AAE1C,eAAO,MAAM,mBAAmB,qCAAqC,CAAC;AAEtE,eAAO,MAAM,OAAO,GACnB,aAAa,KAAK,CAAC,iBAAiB,CAAC,EACrC,QAAQ,SAAS,EACjB,OAAO,KAAK,EACZ,KAAK,MAAM,EACX,SAAS,OAAO,EAChB,aAAa,UAAU,EACvB,cAAc,OAAO,gBAAgB,KACnC,OAAO,CAAC,UAAU,CA6EpB,CAAC"}
|
package/dist/run_gen.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { styleText as st } from 'node:util';
|
|
2
|
+
import { print_error } from '@fuzdev/fuz_util/print.js';
|
|
3
|
+
import { map_concurrent } from '@fuzdev/fuz_util/async.js';
|
|
4
|
+
import { to_gen_result, normalize_gen_config, } from "./gen.js";
|
|
5
|
+
import { print_path, to_root_path } from "./paths.js";
|
|
6
|
+
import { default_svelte_config } from "./svelte_config.js";
|
|
7
|
+
export const GEN_NO_PROD_MESSAGE = 'gen runs only during development';
|
|
8
|
+
export const run_gen = async (gen_modules, config, filer, log, timings, invoke_task, format_file) => {
|
|
9
|
+
let input_count = 0;
|
|
10
|
+
let output_count = 0;
|
|
11
|
+
const timing_for_run_gen = timings.start('run_gen');
|
|
12
|
+
const results = await map_concurrent(gen_modules, async (module_meta) => {
|
|
13
|
+
input_count++;
|
|
14
|
+
const { id } = module_meta;
|
|
15
|
+
const timing_for_module = timings.start(id);
|
|
16
|
+
const gen_config = normalize_gen_config(module_meta.mod.gen);
|
|
17
|
+
const gen_ctx = {
|
|
18
|
+
config,
|
|
19
|
+
svelte_config: default_svelte_config,
|
|
20
|
+
filer,
|
|
21
|
+
log,
|
|
22
|
+
timings,
|
|
23
|
+
invoke_task,
|
|
24
|
+
origin_id: id,
|
|
25
|
+
origin_path: to_root_path(id),
|
|
26
|
+
changed_file_id: undefined,
|
|
27
|
+
};
|
|
28
|
+
let raw_gen_result;
|
|
29
|
+
try {
|
|
30
|
+
raw_gen_result = await gen_config.generate(gen_ctx);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
return {
|
|
34
|
+
ok: false,
|
|
35
|
+
id,
|
|
36
|
+
error,
|
|
37
|
+
reason: st('red', `Error generating ${print_path(id)}`),
|
|
38
|
+
elapsed: timing_for_module(),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Convert the module's return value to a normalized form.
|
|
42
|
+
const gen_result = to_gen_result(id, raw_gen_result);
|
|
43
|
+
// Format the files if needed.
|
|
44
|
+
const files = format_file
|
|
45
|
+
? await map_concurrent(gen_result.files, async (file) => {
|
|
46
|
+
if (!file.format)
|
|
47
|
+
return file;
|
|
48
|
+
try {
|
|
49
|
+
return { ...file, content: await format_file(file.content, { filepath: file.id }) };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
log.error(st('red', `Error formatting ${print_path(file.id)} via ${print_path(id)}`), print_error(error));
|
|
53
|
+
return file;
|
|
54
|
+
}
|
|
55
|
+
}, 10)
|
|
56
|
+
: gen_result.files;
|
|
57
|
+
output_count += files.length;
|
|
58
|
+
return {
|
|
59
|
+
ok: true,
|
|
60
|
+
id,
|
|
61
|
+
files,
|
|
62
|
+
elapsed: timing_for_module(),
|
|
63
|
+
};
|
|
64
|
+
}, 10);
|
|
65
|
+
return {
|
|
66
|
+
results,
|
|
67
|
+
successes: results.filter((r) => r.ok),
|
|
68
|
+
failures: results.filter((r) => !r.ok),
|
|
69
|
+
input_count,
|
|
70
|
+
output_count,
|
|
71
|
+
elapsed: timing_for_run_gen(),
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { 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 type { Filer } from './filer.ts';
|
|
5
|
+
import type { GroConfig } from './gro_config.ts';
|
|
6
|
+
import type { invoke_task as base_invoke_task } from './invoke_task.ts';
|
|
7
|
+
import { type TaskModuleMeta } from './task.ts';
|
|
8
|
+
export type RunTaskResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
output: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
reason: string;
|
|
14
|
+
error: Error;
|
|
15
|
+
};
|
|
16
|
+
export declare const run_task: (task_meta: TaskModuleMeta, unparsed_args: Args, invoke_task: typeof base_invoke_task, config: GroConfig, filer: Filer, log: Logger, timings: Timings) => Promise<RunTaskResult>;
|
|
17
|
+
//# sourceMappingURL=run_task.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run_task.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/run_task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,IAAI,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,6BAA6B,CAAC;AAIzD,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAC,WAAW,IAAI,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAY,KAAK,cAAc,EAAC,MAAM,WAAW,CAAC;AAGzD,MAAM,MAAM,aAAa,GACtB;IACA,EAAE,EAAE,IAAI,CAAC;IACT,MAAM,EAAE,OAAO,CAAC;CACf,GACD;IACA,EAAE,EAAE,KAAK,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;CACZ,CAAC;AAEL,eAAO,MAAM,QAAQ,GACpB,WAAW,cAAc,EACzB,eAAe,IAAI,EACnB,aAAa,OAAO,gBAAgB,EACpC,QAAQ,SAAS,EACjB,OAAO,KAAK,EACZ,KAAK,MAAM,EACX,SAAS,OAAO,KACd,OAAO,CAAC,aAAa,CAiDvB,CAAC"}
|
package/dist/run_task.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { args_parse } from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import { styleText as st } from 'node:util';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { default_svelte_config } from "./svelte_config.js";
|
|
5
|
+
import { TaskError } from "./task.js";
|
|
6
|
+
import { log_task_help } from "./task_logging.js";
|
|
7
|
+
export const run_task = async (task_meta, unparsed_args, invoke_task, config, filer, log, timings) => {
|
|
8
|
+
const { task } = task_meta.mod;
|
|
9
|
+
if (unparsed_args.help) {
|
|
10
|
+
log_task_help(log, task_meta);
|
|
11
|
+
return { ok: true, output: null };
|
|
12
|
+
}
|
|
13
|
+
// Parse and validate args.
|
|
14
|
+
let args = unparsed_args;
|
|
15
|
+
if (task.Args) {
|
|
16
|
+
const parsed = args_parse(unparsed_args, task.Args);
|
|
17
|
+
if (!parsed.success) {
|
|
18
|
+
throw new TaskError(`Failed task args validation for task '${task_meta.name}':\n${z.prettifyError(parsed.error)}`);
|
|
19
|
+
}
|
|
20
|
+
args = parsed.data;
|
|
21
|
+
}
|
|
22
|
+
// Run the task.
|
|
23
|
+
let output; // TODO generic
|
|
24
|
+
try {
|
|
25
|
+
output = await task.run({
|
|
26
|
+
args,
|
|
27
|
+
config,
|
|
28
|
+
svelte_config: default_svelte_config,
|
|
29
|
+
filer,
|
|
30
|
+
log,
|
|
31
|
+
timings,
|
|
32
|
+
invoke_task: (invoked_task_name, invoked_args, invoked_config) => invoke_task(invoked_task_name, invoked_args, invoked_config ?? config, filer, timings, log),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
reason: st('red', error?.constructor?.name === 'TaskError'
|
|
39
|
+
? error.message
|
|
40
|
+
: `Unexpected error running task ${st('cyan', task_meta.name)}. If this is unexpected try running \`${config.pm_cli} install\` and \`gro clean\`.`),
|
|
41
|
+
error,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return { ok: true, output };
|
|
45
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PackageJson, PackageJsonExports } from '@fuzdev/fuz_util/package_json.js';
|
|
2
|
+
import { SourceJson, type ModuleJson } from '@fuzdev/fuz_util/source_json.js';
|
|
3
|
+
import type { Logger } from '@fuzdev/fuz_util/log.js';
|
|
4
|
+
export type SourceJsonMapper = (source_json: SourceJson) => SourceJson | null | Promise<SourceJson | null>;
|
|
5
|
+
export declare const source_json_create: (package_json: PackageJson, lib_path?: string, log?: Logger) => Promise<SourceJson>;
|
|
6
|
+
export declare const source_json_modules_create: (exports: PackageJsonExports | undefined, lib_path?: string, log?: Logger) => Promise<Array<ModuleJson> | undefined>;
|
|
7
|
+
//# sourceMappingURL=source_json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/source_json.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,kCAAkC,CAAC;AACtF,OAAO,EAAC,UAAU,EAAE,KAAK,UAAU,EAAuB,MAAM,iCAAiC,CAAC;AAClG,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAMpD,MAAM,MAAM,gBAAgB,GAAG,CAC9B,WAAW,EAAE,UAAU,KACnB,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;AAEpD,eAAO,MAAM,kBAAkB,GAC9B,cAAc,WAAW,EACzB,WAAW,MAAM,EACjB,MAAM,MAAM,KACV,OAAO,CAAC,UAAU,CAKlB,CAAC;AAEJ,eAAO,MAAM,0BAA0B,GACtC,SAAS,kBAAkB,GAAG,SAAS,EACvC,iBAAoB,EACpB,MAAM,MAAM,KACV,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,SAAS,CAgDvC,CAAC"}
|
|
@@ -0,0 +1,145 @@
|
|
|
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 { SourceJson } from '@fuzdev/fuz_util/source_json.js';
|
|
6
|
+
import { paths, replace_extension } from "./paths.js";
|
|
7
|
+
import { parse_exports } from "./parse_exports.js";
|
|
8
|
+
import { TS_MATCHER, SVELTE_MATCHER, JSON_MATCHER, CSS_MATCHER } from "./constants.js";
|
|
9
|
+
export const source_json_create = async (package_json, lib_path, log) => SourceJson.parse({
|
|
10
|
+
name: package_json.name,
|
|
11
|
+
version: package_json.version,
|
|
12
|
+
modules: await source_json_modules_create(package_json.exports, lib_path, log),
|
|
13
|
+
});
|
|
14
|
+
export const source_json_modules_create = async (exports, lib_path = paths.lib, log) => {
|
|
15
|
+
if (!exports)
|
|
16
|
+
return;
|
|
17
|
+
const file_paths = await collect_file_paths(exports, lib_path);
|
|
18
|
+
// Create a TypeScript program for all TypeScript files
|
|
19
|
+
const ts_files = file_paths
|
|
20
|
+
.filter(({ file_path }) => TS_MATCHER.test(file_path))
|
|
21
|
+
.map(({ file_path }) => file_path);
|
|
22
|
+
let program;
|
|
23
|
+
if (ts_files.length > 0) {
|
|
24
|
+
program = ts.createProgram(ts_files,
|
|
25
|
+
// TODO get from tsconfig?
|
|
26
|
+
{
|
|
27
|
+
target: ts.ScriptTarget.ESNext,
|
|
28
|
+
module: ts.ModuleKind.ESNext,
|
|
29
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
30
|
+
verbatimModuleSyntax: true,
|
|
31
|
+
isolatedModules: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
const result = [];
|
|
35
|
+
// Process each file
|
|
36
|
+
for (const { file_path } of file_paths) {
|
|
37
|
+
const relative_path = file_path.replace(ensure_end(lib_path, '/'), '');
|
|
38
|
+
const declarations = parse_exports(file_path, program, undefined, log)
|
|
39
|
+
.filter((d) => d.kind !== null) // TODO maybe dont filter out?
|
|
40
|
+
.map(({ name, kind }) => ({ name, kind }));
|
|
41
|
+
result.push(declarations.length
|
|
42
|
+
? {
|
|
43
|
+
path: relative_path,
|
|
44
|
+
declarations,
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
path: relative_path,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
const collect_file_paths = async (exports, lib_path) => {
|
|
53
|
+
const file_paths = [];
|
|
54
|
+
// Handle string exports (single default export)
|
|
55
|
+
if (typeof exports === 'string') {
|
|
56
|
+
const source_file = await infer_source_from_export(exports, lib_path);
|
|
57
|
+
if (source_file) {
|
|
58
|
+
file_paths.push({ export_key: '.', file_path: source_file });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw Error(`Failed to infer source file from package.json string export "${exports}" - no matching file found in ${lib_path}`);
|
|
62
|
+
}
|
|
63
|
+
return file_paths;
|
|
64
|
+
}
|
|
65
|
+
// Handle object exports
|
|
66
|
+
for (const k in exports) {
|
|
67
|
+
// Skip package.json
|
|
68
|
+
if (k === './package.json')
|
|
69
|
+
continue;
|
|
70
|
+
// Check if this is a pattern export
|
|
71
|
+
if (k.includes('*')) {
|
|
72
|
+
// Handle pattern exports by finding matching files in lib
|
|
73
|
+
// eslint-disable-next-line no-await-in-loop
|
|
74
|
+
const matching_files = await fs_search(lib_path, {
|
|
75
|
+
file_filter: (path) => {
|
|
76
|
+
const p = path.replace(ensure_end(lib_path, '/'), '');
|
|
77
|
+
// Only match files in the root directory (no subdirectories)
|
|
78
|
+
if (p.includes('/'))
|
|
79
|
+
return false;
|
|
80
|
+
// Match based on the export pattern
|
|
81
|
+
if (k === './*.js') {
|
|
82
|
+
return TS_MATCHER.test(p) && !p.endsWith('.d.ts') && !p.endsWith('.test.ts');
|
|
83
|
+
}
|
|
84
|
+
else if (k === './*.svelte') {
|
|
85
|
+
return SVELTE_MATCHER.test(p);
|
|
86
|
+
}
|
|
87
|
+
else if (k === './*.json') {
|
|
88
|
+
return JSON_MATCHER.test(p);
|
|
89
|
+
}
|
|
90
|
+
else if (k === './*.css') {
|
|
91
|
+
return CSS_MATCHER.test(p);
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
// Add each matching file
|
|
97
|
+
for (const file of matching_files) {
|
|
98
|
+
let export_path;
|
|
99
|
+
if (file.path.endsWith('.ts')) {
|
|
100
|
+
export_path = './' + file.path.replace('.ts', '.js');
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
export_path = './' + file.path;
|
|
104
|
+
}
|
|
105
|
+
file_paths.push({ export_key: export_path, file_path: file.id });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Handle explicit exports (non-patterns)
|
|
110
|
+
// eslint-disable-next-line no-await-in-loop
|
|
111
|
+
const source_file = await infer_source_from_export(k, lib_path);
|
|
112
|
+
if (source_file) {
|
|
113
|
+
file_paths.push({ export_key: k, file_path: source_file });
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
throw Error(`Failed to infer source file from package.json export path ${k} - no matching file found in ${lib_path}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return file_paths;
|
|
121
|
+
};
|
|
122
|
+
const infer_source_from_export = async (export_path, lib_path) => {
|
|
123
|
+
// Handle index specially
|
|
124
|
+
if (export_path === '.' || export_path === './') {
|
|
125
|
+
const index_ts = join(lib_path, 'index.ts');
|
|
126
|
+
if (await fs_exists(index_ts))
|
|
127
|
+
return index_ts;
|
|
128
|
+
const index_js = join(lib_path, 'index.js');
|
|
129
|
+
if (await fs_exists(index_js))
|
|
130
|
+
return index_js;
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const clean_path = strip_start(export_path, './');
|
|
134
|
+
// For .js exports, try .ts first
|
|
135
|
+
if (clean_path.endsWith('.js')) {
|
|
136
|
+
const ts_path = join(lib_path, replace_extension(clean_path, '.ts'));
|
|
137
|
+
if (await fs_exists(ts_path))
|
|
138
|
+
return ts_path;
|
|
139
|
+
}
|
|
140
|
+
// Try the exact path
|
|
141
|
+
const exact_path = join(lib_path, clean_path);
|
|
142
|
+
if (await fs_exists(exact_path))
|
|
143
|
+
return exact_path;
|
|
144
|
+
return null;
|
|
145
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Config as SvelteConfig } from '@sveltejs/kit';
|
|
2
|
+
import type { CompileOptions, ModuleCompileOptions, PreprocessorGroup } from 'svelte/compiler';
|
|
3
|
+
/**
|
|
4
|
+
* Loads a SvelteKit config at `dir`.
|
|
5
|
+
* @returns `null` if no config is found
|
|
6
|
+
*/
|
|
7
|
+
export declare const load_svelte_config: ({ dir, config_filename, }?: {
|
|
8
|
+
dir?: string;
|
|
9
|
+
config_filename?: string;
|
|
10
|
+
}) => Promise<SvelteConfig | null>;
|
|
11
|
+
/**
|
|
12
|
+
* A subset of SvelteKit's config in a form that Gro uses
|
|
13
|
+
* because SvelteKit doesn't expose its config resolver.
|
|
14
|
+
* Flattens things out to keep them simple and easy to pass around,
|
|
15
|
+
* and doesn't deal with most properties, but includes the full `svelte_config`.
|
|
16
|
+
* The `base` and `assets` in particular are renamed for clarity with Gro's internal systems,
|
|
17
|
+
* so these properties become first-class vocabulary inside Gro.
|
|
18
|
+
*/
|
|
19
|
+
export interface ParsedSvelteConfig {
|
|
20
|
+
svelte_config: SvelteConfig | null;
|
|
21
|
+
alias: Record<string, string>;
|
|
22
|
+
base_url: '' | `/${string}` | undefined;
|
|
23
|
+
assets_url: '' | `http://${string}` | `https://${string}` | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Same as the SvelteKit `files.assets`.
|
|
26
|
+
*/
|
|
27
|
+
assets_path: string;
|
|
28
|
+
/**
|
|
29
|
+
* Same as the SvelteKit `files.lib`.
|
|
30
|
+
*/
|
|
31
|
+
lib_path: string;
|
|
32
|
+
/**
|
|
33
|
+
* Same as the SvelteKit `files.routes`.
|
|
34
|
+
*/
|
|
35
|
+
routes_path: string;
|
|
36
|
+
env_dir: string | undefined;
|
|
37
|
+
private_prefix: string | undefined;
|
|
38
|
+
public_prefix: string | undefined;
|
|
39
|
+
svelte_compile_options: CompileOptions;
|
|
40
|
+
svelte_compile_module_options: ModuleCompileOptions;
|
|
41
|
+
svelte_preprocessors: PreprocessorGroup | Array<PreprocessorGroup> | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns Gro-relevant properties of a SvelteKit config
|
|
45
|
+
* as a convenience wrapper around `load_svelte_config`.
|
|
46
|
+
* Needed because SvelteKit doesn't expose its config resolver.
|
|
47
|
+
*/
|
|
48
|
+
export declare const parse_svelte_config: ({ dir_or_config, config_filename, }?: {
|
|
49
|
+
dir_or_config?: string | SvelteConfig;
|
|
50
|
+
config_filename?: string;
|
|
51
|
+
}) => Promise<ParsedSvelteConfig>;
|
|
52
|
+
export declare const to_default_compile_module_options: ({ dev, generate, filename, rootDir, warningFilter, }: CompileOptions) => ModuleCompileOptions;
|
|
53
|
+
/**
|
|
54
|
+
* The parsed SvelteKit config for the cwd, cached globally at the module level.
|
|
55
|
+
*/
|
|
56
|
+
export declare const default_svelte_config: ParsedSvelteConfig;
|
|
57
|
+
//# sourceMappingURL=svelte_config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"svelte_config.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte_config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,EAAC,cAAc,EAAE,oBAAoB,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAe7F;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAU,4BAGtC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAgB,KAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAMvF,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAkB;IAElC,aAAa,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,EAAE,EAAE,GAAG,IAAI,MAAM,EAAE,GAAG,SAAS,CAAC;IACxC,UAAU,EAAE,EAAE,GAAG,UAAU,MAAM,EAAE,GAAG,WAAW,MAAM,EAAE,GAAG,SAAS,CAAC;IAGtE;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,sBAAsB,EAAE,cAAc,CAAC;IACvC,6BAA6B,EAAE,oBAAoB,CAAC;IACpD,oBAAoB,EAAE,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC;CAC/E;AAGD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAU,sCAGvC;IACF,aAAa,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;CACV,KAAG,OAAO,CAAC,kBAAkB,CA8C5C,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAAI,sDAM/C,cAAc,KAAG,oBAA2E,CAAC;AAEhG;;GAEG;AACH,eAAO,MAAM,qBAAqB,oBAA8B,CAAC"}
|