@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,80 @@
|
|
|
1
|
+
import * as esbuild from 'esbuild';
|
|
2
|
+
import type { Config as SvelteConfig } from '@sveltejs/kit';
|
|
3
|
+
import type { Result } from '@fuzdev/fuz_util/result.js';
|
|
4
|
+
import type { PathId } from '@fuzdev/fuz_util/path.js';
|
|
5
|
+
import type { Plugin } from './plugin.ts';
|
|
6
|
+
export declare const SERVER_SOURCE_ID: PathId;
|
|
7
|
+
export declare const has_server: (path?: PathId) => Promise<Result<object, {
|
|
8
|
+
message: string;
|
|
9
|
+
}>>;
|
|
10
|
+
export interface GroPluginServerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* same as esbuild's `entryPoints`
|
|
13
|
+
*/
|
|
14
|
+
entry_points?: Array<string>;
|
|
15
|
+
/**
|
|
16
|
+
* @default cwd
|
|
17
|
+
*/
|
|
18
|
+
dir?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the `Outpaths` given a `dev` param.
|
|
21
|
+
* Decoupling this from plugin creation allows it to be created generically,
|
|
22
|
+
* so the build and dev tasks can be the source of truth for `dev`.
|
|
23
|
+
*/
|
|
24
|
+
outpaths?: CreateOutpaths;
|
|
25
|
+
/**
|
|
26
|
+
* @default ```SvelteKit's `.env`, `.env.development`, and `.env.production````
|
|
27
|
+
*/
|
|
28
|
+
env_files?: Array<string>;
|
|
29
|
+
/**
|
|
30
|
+
* @default process.env
|
|
31
|
+
*/
|
|
32
|
+
ambient_env?: Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* @default ```loaded from `${cwd}/${SVELTE_CONFIG_FILENAME}````
|
|
35
|
+
*/
|
|
36
|
+
svelte_config?: SvelteConfig;
|
|
37
|
+
/**
|
|
38
|
+
* @default 'esnext'
|
|
39
|
+
*/
|
|
40
|
+
target?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Optionally map the esbuild options.
|
|
43
|
+
* @default identity
|
|
44
|
+
*/
|
|
45
|
+
esbuild_build_options?: (base_options: esbuild.BuildOptions) => esbuild.BuildOptions;
|
|
46
|
+
/**
|
|
47
|
+
* Milliseconds to throttle rebuilds.
|
|
48
|
+
* Should be longer than it takes to build to avoid backpressure.
|
|
49
|
+
* @default 1000
|
|
50
|
+
*/
|
|
51
|
+
rebuild_throttle_delay?: number;
|
|
52
|
+
/**
|
|
53
|
+
* The CLI command to run the server, like `'node'` or `'bun'` or `'deno'`.
|
|
54
|
+
* Receives the path to the server js file as its argument.
|
|
55
|
+
* @default 'node'
|
|
56
|
+
*/
|
|
57
|
+
cli_command?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Whether to run the server or not after building.
|
|
60
|
+
* @default dev
|
|
61
|
+
*/
|
|
62
|
+
run?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface Outpaths {
|
|
65
|
+
/**
|
|
66
|
+
* @default '.gro/dev' or 'dist_server'
|
|
67
|
+
*/
|
|
68
|
+
outdir: string;
|
|
69
|
+
/**
|
|
70
|
+
* @default 'src/lib'
|
|
71
|
+
*/
|
|
72
|
+
outbase: string;
|
|
73
|
+
/**
|
|
74
|
+
* @default 'server.js'
|
|
75
|
+
*/
|
|
76
|
+
outname: string;
|
|
77
|
+
}
|
|
78
|
+
export type CreateOutpaths = (dev: boolean) => Outpaths;
|
|
79
|
+
export declare const gro_plugin_server: ({ entry_points, dir, outpaths, env_files, ambient_env, svelte_config, target, esbuild_build_options, rebuild_throttle_delay, cli_command, run, }?: GroPluginServerOptions) => Plugin;
|
|
80
|
+
//# sourceMappingURL=gro_plugin_server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro_plugin_server.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAC,MAAM,IAAI,YAAY,EAAC,MAAM,eAAe,CAAC;AAI1D,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,4BAA4B,CAAC;AAGvD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,0BAA0B,CAAC;AAErD,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAcxC,eAAO,MAAM,gBAAgB,QAA0D,CAAC;AAExF,eAAO,MAAM,UAAU,GACtB,aAAuB,KACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAAC,CAK3C,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACtC;;OAEG;IACH,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC;;OAEG;IACH,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CAAC,YAAY,EAAE,OAAO,CAAC,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC;IACrF;;;;OAIG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACxB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,CAAC;AAExD,eAAO,MAAM,iBAAiB,GAAI,mJAgB/B,sBAA2B,KAAG,MAsJhC,CAAC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { spawn_restartable_process } from '@fuzdev/fuz_util/process.js';
|
|
2
|
+
import * as esbuild from 'esbuild';
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
|
+
import { identity } from '@fuzdev/fuz_util/function.js';
|
|
5
|
+
import { strip_before, strip_end } from '@fuzdev/fuz_util/string.js';
|
|
6
|
+
import { fs_exists } from '@fuzdev/fuz_util/fs.js';
|
|
7
|
+
import { throttle } from '@fuzdev/fuz_util/throttle.js';
|
|
8
|
+
import { base_path_to_path_id, LIB_DIRNAME, paths } from "./paths.js";
|
|
9
|
+
import { GRO_DEV_DIRNAME, SERVER_DIST_PATH } from "./constants.js";
|
|
10
|
+
import { parse_svelte_config, default_svelte_config } from "./svelte_config.js";
|
|
11
|
+
import { esbuild_plugin_sveltekit_shim_app } from "./esbuild_plugin_sveltekit_shim_app.js";
|
|
12
|
+
import { esbuild_plugin_sveltekit_shim_env } from "./esbuild_plugin_sveltekit_shim_env.js";
|
|
13
|
+
import { print_build_result, to_define_import_meta_env } from "./esbuild_helpers.js";
|
|
14
|
+
import { esbuild_plugin_sveltekit_shim_alias } from "./esbuild_plugin_sveltekit_shim_alias.js";
|
|
15
|
+
import { esbuild_plugin_external_worker } from "./esbuild_plugin_external_worker.js";
|
|
16
|
+
import { esbuild_plugin_sveltekit_local_imports } from "./esbuild_plugin_sveltekit_local_imports.js";
|
|
17
|
+
import { esbuild_plugin_svelte } from "./esbuild_plugin_svelte.js";
|
|
18
|
+
// TODO sourcemap as a hoisted option? disable for production by default - or like `outpaths`, passed a `dev` param
|
|
19
|
+
export const SERVER_SOURCE_ID = base_path_to_path_id(LIB_DIRNAME + '/server/server.ts');
|
|
20
|
+
export const has_server = async (path = SERVER_SOURCE_ID) => {
|
|
21
|
+
if (!(await fs_exists(path))) {
|
|
22
|
+
return { ok: false, message: `no server file found at ${path}` };
|
|
23
|
+
}
|
|
24
|
+
return { ok: true };
|
|
25
|
+
};
|
|
26
|
+
export const gro_plugin_server = ({ entry_points = [SERVER_SOURCE_ID], dir = process.cwd(), outpaths = (dev) => ({
|
|
27
|
+
outdir: join(dir, dev ? GRO_DEV_DIRNAME : SERVER_DIST_PATH),
|
|
28
|
+
outbase: paths.lib,
|
|
29
|
+
outname: 'server/server.js',
|
|
30
|
+
}), env_files, ambient_env, svelte_config, target = 'esnext', esbuild_build_options = identity, rebuild_throttle_delay = 1000, cli_command, run, // `dev` default is not available in this scope
|
|
31
|
+
} = {}) => {
|
|
32
|
+
let build_ctx;
|
|
33
|
+
let cleanup_watch;
|
|
34
|
+
let server_process;
|
|
35
|
+
let deps;
|
|
36
|
+
return {
|
|
37
|
+
name: 'gro_plugin_server',
|
|
38
|
+
setup: async ({ dev, watch, timings, log, config, filer }) => {
|
|
39
|
+
const parsed_svelte_config = !svelte_config && strip_end(dir, '/') === process.cwd()
|
|
40
|
+
? default_svelte_config
|
|
41
|
+
: await parse_svelte_config({
|
|
42
|
+
dir_or_config: svelte_config ?? dir,
|
|
43
|
+
config_filename: config.svelte_config_filename,
|
|
44
|
+
});
|
|
45
|
+
const { alias, base_url, assets_url, env_dir, private_prefix, public_prefix, svelte_compile_options, svelte_compile_module_options, svelte_preprocessors, } = parsed_svelte_config;
|
|
46
|
+
const { outbase, outdir, outname } = outpaths(dev);
|
|
47
|
+
const server_outpath = join(outdir, outname);
|
|
48
|
+
const timing_to_esbuild_create_context = timings.start('create build context');
|
|
49
|
+
const build_options = esbuild_build_options({
|
|
50
|
+
outdir,
|
|
51
|
+
outbase,
|
|
52
|
+
format: 'esm',
|
|
53
|
+
platform: 'node',
|
|
54
|
+
packages: 'external',
|
|
55
|
+
bundle: true,
|
|
56
|
+
target,
|
|
57
|
+
metafile: watch,
|
|
58
|
+
});
|
|
59
|
+
build_ctx = await esbuild.context({
|
|
60
|
+
entryPoints: entry_points.map((path) => resolve(dir, path)),
|
|
61
|
+
plugins: [
|
|
62
|
+
esbuild_plugin_sveltekit_shim_app({ dev, base_url, assets_url }),
|
|
63
|
+
esbuild_plugin_sveltekit_shim_env({
|
|
64
|
+
dev,
|
|
65
|
+
public_prefix,
|
|
66
|
+
private_prefix,
|
|
67
|
+
env_dir,
|
|
68
|
+
env_files,
|
|
69
|
+
ambient_env,
|
|
70
|
+
}),
|
|
71
|
+
esbuild_plugin_sveltekit_shim_alias({ dir, alias }),
|
|
72
|
+
esbuild_plugin_external_worker({
|
|
73
|
+
dev,
|
|
74
|
+
build_options,
|
|
75
|
+
dir,
|
|
76
|
+
svelte_compile_options,
|
|
77
|
+
svelte_compile_module_options,
|
|
78
|
+
svelte_preprocessors,
|
|
79
|
+
alias,
|
|
80
|
+
base_url,
|
|
81
|
+
public_prefix,
|
|
82
|
+
private_prefix,
|
|
83
|
+
env_dir,
|
|
84
|
+
env_files,
|
|
85
|
+
ambient_env,
|
|
86
|
+
log,
|
|
87
|
+
}),
|
|
88
|
+
esbuild_plugin_svelte({
|
|
89
|
+
dev,
|
|
90
|
+
base_url,
|
|
91
|
+
dir,
|
|
92
|
+
svelte_compile_options,
|
|
93
|
+
svelte_compile_module_options,
|
|
94
|
+
svelte_preprocessors,
|
|
95
|
+
}),
|
|
96
|
+
esbuild_plugin_sveltekit_local_imports(),
|
|
97
|
+
],
|
|
98
|
+
define: to_define_import_meta_env(dev, base_url),
|
|
99
|
+
...build_options,
|
|
100
|
+
});
|
|
101
|
+
timing_to_esbuild_create_context();
|
|
102
|
+
const rebuild = throttle(async () => {
|
|
103
|
+
let build_result;
|
|
104
|
+
try {
|
|
105
|
+
build_result = await build_ctx.rebuild();
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
log.error('[gro_plugin_server] build failed', error);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const { metafile } = build_result;
|
|
112
|
+
if (!metafile)
|
|
113
|
+
return;
|
|
114
|
+
print_build_result(log, build_result);
|
|
115
|
+
deps = parse_deps(metafile.inputs, dir);
|
|
116
|
+
void server_process?.restart();
|
|
117
|
+
}, { delay: rebuild_throttle_delay });
|
|
118
|
+
await rebuild();
|
|
119
|
+
if (watch) {
|
|
120
|
+
cleanup_watch = await filer.watch((change) => {
|
|
121
|
+
if (!deps?.has(change.path)) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
void rebuild();
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (!(await fs_exists(server_outpath))) {
|
|
128
|
+
throw Error(`Node server failed to start due to missing file: ${server_outpath}`);
|
|
129
|
+
}
|
|
130
|
+
if (run || dev) {
|
|
131
|
+
const cli_args = [];
|
|
132
|
+
if (dev) {
|
|
133
|
+
cli_args.push('-C', 'development'); // same as `--conditions`
|
|
134
|
+
}
|
|
135
|
+
cli_args.push(server_outpath);
|
|
136
|
+
server_process = spawn_restartable_process(cli_command ?? config.js_cli, cli_args);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
teardown: async () => {
|
|
140
|
+
if (cleanup_watch) {
|
|
141
|
+
cleanup_watch();
|
|
142
|
+
cleanup_watch = undefined;
|
|
143
|
+
}
|
|
144
|
+
if (server_process) {
|
|
145
|
+
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`
|
|
146
|
+
server_process = undefined;
|
|
147
|
+
await s.kill();
|
|
148
|
+
}
|
|
149
|
+
if (build_ctx) {
|
|
150
|
+
await build_ctx.dispose();
|
|
151
|
+
build_ctx = undefined;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* The esbuild metafile contains the paths in `entryPoints` relative to the `dir`
|
|
158
|
+
* even though we're resolving them to absolute paths before passing them to esbuild,
|
|
159
|
+
* so we resolve them here relative to the `dir`.
|
|
160
|
+
*/
|
|
161
|
+
const parse_deps = (metafile_inputs, dir) => {
|
|
162
|
+
const deps = new Set();
|
|
163
|
+
for (const key in metafile_inputs) {
|
|
164
|
+
deps.add(resolve(dir, strip_before(key, ':')));
|
|
165
|
+
}
|
|
166
|
+
return deps;
|
|
167
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from './plugin.ts';
|
|
2
|
+
export interface GroPluginSveltekitAppOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The Vite CLI to use.
|
|
5
|
+
*/
|
|
6
|
+
vite_cli?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const gro_plugin_sveltekit_app: ({ vite_cli, }?: GroPluginSveltekitAppOptions) => Plugin;
|
|
9
|
+
//# sourceMappingURL=gro_plugin_sveltekit_app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro_plugin_sveltekit_app.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_app.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAGxC,MAAM,WAAW,4BAA4B;IAC5C;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,wBAAwB,GAAI,gBAEtC,4BAAiC,KAAG,MAuCtC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { args_serialize } from '@fuzdev/fuz_util/args.js';
|
|
2
|
+
import { spawn_result_to_message } from '@fuzdev/fuz_util/process.js';
|
|
3
|
+
import { to_forwarded_args } from "./args.js";
|
|
4
|
+
import { find_cli, spawn_cli, spawn_cli_process } from "./cli.js";
|
|
5
|
+
import { VITE_CLI } from "./constants.js";
|
|
6
|
+
import { TaskError } from "./task.js";
|
|
7
|
+
export const gro_plugin_sveltekit_app = ({ vite_cli = VITE_CLI, } = {}) => {
|
|
8
|
+
let sveltekit_process = undefined;
|
|
9
|
+
return {
|
|
10
|
+
name: 'gro_plugin_sveltekit_app',
|
|
11
|
+
setup: async ({ dev, watch, log, config }) => {
|
|
12
|
+
const found_vite_cli = await find_cli(vite_cli);
|
|
13
|
+
if (!found_vite_cli)
|
|
14
|
+
throw Error(`Failed to find Vite CLI \`${vite_cli}\`, do you need to run \`${config.pm_cli} i\`?`);
|
|
15
|
+
if (dev) {
|
|
16
|
+
// `vite dev` in development mode
|
|
17
|
+
if (watch) {
|
|
18
|
+
const serialized_args = ['dev', ...args_serialize(to_forwarded_args(vite_cli))];
|
|
19
|
+
sveltekit_process = await spawn_cli_process(found_vite_cli, serialized_args, log);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
log.debug(`the SvelteKit app plugin is loaded but will not output anything` +
|
|
23
|
+
' because `dev` is true and `watch` is false');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// `vite build` in production mode
|
|
28
|
+
const serialized_args = ['build', ...args_serialize(to_forwarded_args(vite_cli))];
|
|
29
|
+
const spawned = await spawn_cli(found_vite_cli, serialized_args, log);
|
|
30
|
+
if (!spawned?.ok) {
|
|
31
|
+
throw new TaskError(`${vite_cli} build failed: ${spawned ? spawn_result_to_message(spawned) : 'unknown error'}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
teardown: async () => {
|
|
36
|
+
if (sveltekit_process) {
|
|
37
|
+
sveltekit_process.child.kill();
|
|
38
|
+
await sveltekit_process.closed;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Plugin } from './plugin.ts';
|
|
2
|
+
import { type SveltePackageOptions } from './sveltekit_helpers.ts';
|
|
3
|
+
export interface GroPluginSveltekitLibraryOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The options passed to the SvelteKit packaging CLI.
|
|
6
|
+
* @see https://kit.svelte.dev/docs/packaging#options
|
|
7
|
+
*/
|
|
8
|
+
svelte_package_options?: SveltePackageOptions;
|
|
9
|
+
/**
|
|
10
|
+
* The SvelteKit packaging CLI to use. Defaults to `svelte-package`.
|
|
11
|
+
* @see https://kit.svelte.dev/docs/packaging
|
|
12
|
+
*/
|
|
13
|
+
svelte_package_cli?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const gro_plugin_sveltekit_library: ({ svelte_package_options, svelte_package_cli, }?: GroPluginSveltekitLibraryOptions) => Plugin;
|
|
16
|
+
//# sourceMappingURL=gro_plugin_sveltekit_library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gro_plugin_sveltekit_library.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/gro_plugin_sveltekit_library.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAGxC,OAAO,EAAqB,KAAK,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAGrF,MAAM,WAAW,gCAAgC;IAChD;;;OAGG;IACH,sBAAsB,CAAC,EAAE,oBAAoB,CAAC;IAC9C;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,4BAA4B,GAAI,kDAG1C,gCAAqC,KAAG,MAsC1C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { print_spawn_result, spawn, spawn_result_to_message } from '@fuzdev/fuz_util/process.js';
|
|
2
|
+
import { TaskError } from "./task.js";
|
|
3
|
+
import { package_json_load } from "./package_json.js";
|
|
4
|
+
import { run_svelte_package } from "./sveltekit_helpers.js";
|
|
5
|
+
import { SVELTE_PACKAGE_CLI } from "./constants.js";
|
|
6
|
+
export const gro_plugin_sveltekit_library = ({ svelte_package_options, svelte_package_cli = SVELTE_PACKAGE_CLI, } = {}) => {
|
|
7
|
+
return {
|
|
8
|
+
name: 'gro_plugin_sveltekit_library',
|
|
9
|
+
setup: async ({ dev, log, config }) => {
|
|
10
|
+
if (!dev) {
|
|
11
|
+
const package_json = await package_json_load();
|
|
12
|
+
await run_svelte_package(package_json, svelte_package_options, svelte_package_cli, log, config.pm_cli);
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
adapt: async ({ log, timings, config }) => {
|
|
16
|
+
const package_json = await package_json_load();
|
|
17
|
+
// link the CLI binaries if they exist
|
|
18
|
+
if (package_json.bin) {
|
|
19
|
+
const timing_to_link = timings.start(`${config.pm_cli} link`);
|
|
20
|
+
await Promise.all(Object.values(package_json.bin).map(async (bin_path) => {
|
|
21
|
+
const chmod_result = await spawn('chmod', ['+x', bin_path]);
|
|
22
|
+
if (!chmod_result.ok)
|
|
23
|
+
log.error(`chmod on bin path ${bin_path} failed: ${spawn_result_to_message(chmod_result)}`);
|
|
24
|
+
}));
|
|
25
|
+
log.info(`linking`);
|
|
26
|
+
const link_result = await spawn(config.pm_cli, ['link', '-f']); // TODO don't use `-f` unless necessary or at all?
|
|
27
|
+
if (!link_result.ok) {
|
|
28
|
+
throw new TaskError(`Failed to link. ${print_spawn_result(link_result)}`);
|
|
29
|
+
}
|
|
30
|
+
timing_to_link();
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd,YAAY,EAAC,SAAS,EAAE,eAAe,EAAE,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC9E,cAAc;AACd,OAAO,EAAC,KAAK,MAAM,EAAE,cAAc,EAAC,MAAM,aAAa,CAAC;AACxD,cAAc;AACd,YAAY,EAAC,GAAG,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAC9C,cAAc;AACd,OAAO,EAAC,KAAK,IAAI,EAAE,KAAK,WAAW,EAAE,SAAS,EAAC,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { Flavored } from '@fuzdev/fuz_util/types.js';
|
|
3
|
+
import type { PathId, ResolvedPath } from '@fuzdev/fuz_util/path.js';
|
|
4
|
+
export declare const InputPath: z.ZodString;
|
|
5
|
+
export type InputPath = Flavored<z.infer<typeof InputPath>, 'InputPath'>;
|
|
6
|
+
export declare const RawInputPath: z.ZodString;
|
|
7
|
+
export type RawInputPath = Flavored<z.infer<typeof RawInputPath>, 'RawInputPath'>;
|
|
8
|
+
/**
|
|
9
|
+
* Raw input paths are paths that users provide to Gro to reference files for tasks and gen.
|
|
10
|
+
*
|
|
11
|
+
* A raw input path can be to a file or directory in the following forms:
|
|
12
|
+
*
|
|
13
|
+
* - an absolute path, preserved
|
|
14
|
+
* - an explicit relative path, e.g. `./src/foo`, resolved to `root_path` which defaults to the cwd
|
|
15
|
+
* - an implicit relative path, e.g. `src/foo`, preserved
|
|
16
|
+
* - an implicit relative path prefixed with `gro/`, transformed to absolute in the Gro directory
|
|
17
|
+
*
|
|
18
|
+
* Thus, input paths are either absolute or implicitly relative.
|
|
19
|
+
*/
|
|
20
|
+
export declare const to_input_path: (raw_input_path: RawInputPath, root_path?: string) => InputPath;
|
|
21
|
+
export declare const to_input_paths: (raw_input_paths: Array<RawInputPath>, root_path?: string) => Array<InputPath>;
|
|
22
|
+
export interface PossiblePath {
|
|
23
|
+
id: PathId;
|
|
24
|
+
input_path: InputPath;
|
|
25
|
+
root_dir: PathId;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Gets a list of possible source ids for each input path with `extensions`,
|
|
29
|
+
* duplicating each under `root_dirs`, without checking the filesystem.
|
|
30
|
+
*/
|
|
31
|
+
export declare const get_possible_paths: (input_path: InputPath, root_dirs: Array<PathId>, extensions: Array<string>) => Promise<Array<PossiblePath>>;
|
|
32
|
+
export interface ResolvedInputPath {
|
|
33
|
+
input_path: InputPath;
|
|
34
|
+
id: PathId;
|
|
35
|
+
is_directory: boolean;
|
|
36
|
+
root_dir: PathId;
|
|
37
|
+
}
|
|
38
|
+
export interface ResolvedInputFile {
|
|
39
|
+
id: PathId;
|
|
40
|
+
input_path: InputPath;
|
|
41
|
+
resolved_input_path: ResolvedInputPath;
|
|
42
|
+
}
|
|
43
|
+
export interface ResolvedInputPaths {
|
|
44
|
+
resolved_input_paths: Array<ResolvedInputPath>;
|
|
45
|
+
possible_paths_by_input_path: Map<InputPath, Array<PossiblePath>>;
|
|
46
|
+
unmapped_input_paths: Array<InputPath>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the path data for each input path, checking the filesystem for the possibilities
|
|
50
|
+
* and stopping at the first existing file or falling back to the first existing directory.
|
|
51
|
+
* If none is found for an input path, it's added to `unmapped_input_paths`.
|
|
52
|
+
*/
|
|
53
|
+
export declare const resolve_input_paths: (input_paths: Array<InputPath>, root_dirs: Array<PathId>, extensions: Array<string>) => Promise<ResolvedInputPaths>;
|
|
54
|
+
export interface ResolvedInputFiles {
|
|
55
|
+
resolved_input_files: Array<ResolvedInputFile>;
|
|
56
|
+
resolved_input_files_by_root_dir: Map<PathId, Array<ResolvedInputFile>>;
|
|
57
|
+
input_directories_with_no_files: Array<InputPath>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Finds all of the matching files for the given input paths.
|
|
61
|
+
* De-dupes source ids.
|
|
62
|
+
*/
|
|
63
|
+
export declare const resolve_input_files: (resolved_input_paths: Array<ResolvedInputPath>, search?: (dir: string) => Promise<Array<ResolvedPath>>) => Promise<ResolvedInputFiles>;
|
|
64
|
+
//# sourceMappingURL=input_path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input_path.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/input_path.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAW,MAAM,EAAE,YAAY,EAAC,MAAM,0BAA0B,CAAC;AAM7E,eAAO,MAAM,SAAS,aAAa,CAAC;AACpC,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,EAAE,WAAW,CAAC,CAAC;AAEzE,eAAO,MAAM,YAAY,aAAa,CAAC;AACvC,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC;AAElF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,GACzB,gBAAgB,YAAY,EAC5B,kBAAyB,KACvB,SAOF,CAAC;AAEF,eAAO,MAAM,cAAc,GAC1B,iBAAiB,KAAK,CAAC,YAAY,CAAC,EACpC,YAAY,MAAM,KAChB,KAAK,CAAC,SAAS,CAA4D,CAAC;AAE/E,MAAM,WAAW,YAAY;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,SAAS,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC9B,YAAY,SAAS,EACrB,WAAW,KAAK,CAAC,MAAM,CAAC,EACxB,YAAY,KAAK,CAAC,MAAM,CAAC,KACvB,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAiC7B,CAAC;AAEF,MAAM,WAAW,iBAAiB;IACjC,UAAU,EAAE,SAAS,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,SAAS,CAAC;IACtB,mBAAmB,EAAE,iBAAiB,CAAC;CACvC;AAED,MAAM,WAAW,kBAAkB;IAClC,oBAAoB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC/C,4BAA4B,EAAE,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC;IAClE,oBAAoB,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CACvC;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC/B,aAAa,KAAK,CAAC,SAAS,CAAC,EAC7B,WAAW,KAAK,CAAC,MAAM,CAAC,EACxB,YAAY,KAAK,CAAC,MAAM,CAAC,KACvB,OAAO,CAAC,kBAAkB,CAkD5B,CAAC;AAEF,MAAM,WAAW,kBAAkB;IAClC,oBAAoB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC/C,gCAAgC,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACxE,+BAA+B,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CAClD;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC/B,sBAAsB,KAAK,CAAC,iBAAiB,CAAC,EAC9C,SAAQ,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAa,KAC/D,OAAO,CAAC,kBAAkB,CAgE5B,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
2
|
+
import { stat } from 'node:fs/promises';
|
|
3
|
+
import { fs_exists, fs_search } from '@fuzdev/fuz_util/fs.js';
|
|
4
|
+
import { strip_start } from '@fuzdev/fuz_util/string.js';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { GRO_PACKAGE_DIR, GRO_DIST_DIR } from "./paths.js";
|
|
7
|
+
import { TASK_FILE_SUFFIX_JS } from "./task.js";
|
|
8
|
+
// TODO Flavored doesn't work when used in schemas, use Zod brand instead? problem is ergonomics
|
|
9
|
+
export const InputPath = z.string();
|
|
10
|
+
export const RawInputPath = z.string();
|
|
11
|
+
/**
|
|
12
|
+
* Raw input paths are paths that users provide to Gro to reference files for tasks and gen.
|
|
13
|
+
*
|
|
14
|
+
* A raw input path can be to a file or directory in the following forms:
|
|
15
|
+
*
|
|
16
|
+
* - an absolute path, preserved
|
|
17
|
+
* - an explicit relative path, e.g. `./src/foo`, resolved to `root_path` which defaults to the cwd
|
|
18
|
+
* - an implicit relative path, e.g. `src/foo`, preserved
|
|
19
|
+
* - an implicit relative path prefixed with `gro/`, transformed to absolute in the Gro directory
|
|
20
|
+
*
|
|
21
|
+
* Thus, input paths are either absolute or implicitly relative.
|
|
22
|
+
*/
|
|
23
|
+
export const to_input_path = (raw_input_path, root_path = process.cwd()) => {
|
|
24
|
+
if (raw_input_path.startsWith(GRO_PACKAGE_DIR)) {
|
|
25
|
+
return GRO_DIST_DIR + strip_start(raw_input_path, GRO_PACKAGE_DIR);
|
|
26
|
+
}
|
|
27
|
+
else if (raw_input_path[0] === '.') {
|
|
28
|
+
return resolve(root_path, raw_input_path);
|
|
29
|
+
}
|
|
30
|
+
return raw_input_path;
|
|
31
|
+
};
|
|
32
|
+
export const to_input_paths = (raw_input_paths, root_path) => raw_input_paths.map((p) => to_input_path(p, root_path));
|
|
33
|
+
/**
|
|
34
|
+
* Gets a list of possible source ids for each input path with `extensions`,
|
|
35
|
+
* duplicating each under `root_dirs`, without checking the filesystem.
|
|
36
|
+
*/
|
|
37
|
+
export const get_possible_paths = async (input_path, root_dirs, extensions) => {
|
|
38
|
+
const possible_paths = new Set();
|
|
39
|
+
const add_possible_paths = (path, root_dir) => {
|
|
40
|
+
// Specifically for paths to the Gro package dist, optimize by only looking for `.task.js`.
|
|
41
|
+
if (path.startsWith(GRO_DIST_DIR)) {
|
|
42
|
+
possible_paths.add({
|
|
43
|
+
id: (path.endsWith('/') || path.endsWith(TASK_FILE_SUFFIX_JS)
|
|
44
|
+
? path
|
|
45
|
+
: path + TASK_FILE_SUFFIX_JS),
|
|
46
|
+
input_path,
|
|
47
|
+
root_dir,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
possible_paths.add({ id: path, input_path, root_dir });
|
|
52
|
+
if (!path.endsWith('/') && !extensions.some((e) => path.endsWith(e))) {
|
|
53
|
+
for (const extension of extensions) {
|
|
54
|
+
possible_paths.add({ id: path + extension, input_path, root_dir });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
if (isAbsolute(input_path)) {
|
|
60
|
+
const exists = await fs_exists(input_path);
|
|
61
|
+
const is_directory = exists && (await stat(input_path)).isDirectory();
|
|
62
|
+
add_possible_paths(input_path, is_directory ? input_path : dirname(input_path));
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
for (const root_dir of root_dirs) {
|
|
66
|
+
add_possible_paths(join(root_dir, input_path), root_dir);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return Array.from(possible_paths);
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Gets the path data for each input path, checking the filesystem for the possibilities
|
|
73
|
+
* and stopping at the first existing file or falling back to the first existing directory.
|
|
74
|
+
* If none is found for an input path, it's added to `unmapped_input_paths`.
|
|
75
|
+
*/
|
|
76
|
+
export const resolve_input_paths = async (input_paths, root_dirs, extensions) => {
|
|
77
|
+
const resolved_input_paths = [];
|
|
78
|
+
const possible_paths_by_input_path = new Map();
|
|
79
|
+
const unmapped_input_paths = [];
|
|
80
|
+
for (const input_path of input_paths) {
|
|
81
|
+
let found_file = null;
|
|
82
|
+
let found_dirs = null;
|
|
83
|
+
// eslint-disable-next-line no-await-in-loop
|
|
84
|
+
const possible_paths = await get_possible_paths(input_path, root_dirs, extensions);
|
|
85
|
+
possible_paths_by_input_path.set(input_path, possible_paths);
|
|
86
|
+
// Find the first existing file path or fallback to the first directory path.
|
|
87
|
+
for (const possible_path of possible_paths) {
|
|
88
|
+
// eslint-disable-next-line no-await-in-loop
|
|
89
|
+
if (!(await fs_exists(possible_path.id)))
|
|
90
|
+
continue;
|
|
91
|
+
// eslint-disable-next-line no-await-in-loop
|
|
92
|
+
const stats = await stat(possible_path.id);
|
|
93
|
+
if (stats.isDirectory()) {
|
|
94
|
+
found_dirs ??= [];
|
|
95
|
+
found_dirs.push([{ id: possible_path.id, is_directory: stats.isDirectory() }, possible_path]);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
found_file = [{ id: possible_path.id, is_directory: stats.isDirectory() }, possible_path];
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (found_file) {
|
|
103
|
+
resolved_input_paths.push({
|
|
104
|
+
input_path,
|
|
105
|
+
id: found_file[0].id,
|
|
106
|
+
is_directory: found_file[0].is_directory,
|
|
107
|
+
root_dir: found_file[1].root_dir,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else if (found_dirs) {
|
|
111
|
+
for (const found_dir of found_dirs) {
|
|
112
|
+
resolved_input_paths.push({
|
|
113
|
+
input_path,
|
|
114
|
+
id: found_dir[0].id,
|
|
115
|
+
is_directory: found_dir[0].is_directory,
|
|
116
|
+
root_dir: found_dir[1].root_dir,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
unmapped_input_paths.push(input_path);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
resolved_input_paths,
|
|
126
|
+
possible_paths_by_input_path,
|
|
127
|
+
unmapped_input_paths,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Finds all of the matching files for the given input paths.
|
|
132
|
+
* De-dupes source ids.
|
|
133
|
+
*/
|
|
134
|
+
export const resolve_input_files = async (resolved_input_paths, search = fs_search) => {
|
|
135
|
+
const resolved_input_files = [];
|
|
136
|
+
// Add all input paths initially, and remove each when resolved to a file.
|
|
137
|
+
const existing_path_ids = new Set();
|
|
138
|
+
let remaining = resolved_input_paths.slice();
|
|
139
|
+
const handle_found = (input_path, id) => {
|
|
140
|
+
remaining = remaining.filter((r) => !(r.id === id || r.input_path === input_path || r.input_path === id));
|
|
141
|
+
};
|
|
142
|
+
// TODO parallelize but would need to de-dupe and retain order
|
|
143
|
+
for (const resolved_input_path of resolved_input_paths) {
|
|
144
|
+
const { input_path, id, is_directory } = resolved_input_path;
|
|
145
|
+
if (is_directory) {
|
|
146
|
+
// Handle input paths that resolve to directories.
|
|
147
|
+
// eslint-disable-next-line no-await-in-loop
|
|
148
|
+
const files = await search(id);
|
|
149
|
+
if (!files.length)
|
|
150
|
+
continue;
|
|
151
|
+
const path_ids = [];
|
|
152
|
+
for (const { path, is_directory } of files) {
|
|
153
|
+
if (is_directory)
|
|
154
|
+
continue;
|
|
155
|
+
const path_id = join(id, path);
|
|
156
|
+
if (!existing_path_ids.has(path_id)) {
|
|
157
|
+
existing_path_ids.add(path_id);
|
|
158
|
+
path_ids.push(path_id);
|
|
159
|
+
}
|
|
160
|
+
handle_found(input_path, path_id);
|
|
161
|
+
}
|
|
162
|
+
if (!path_ids.length)
|
|
163
|
+
continue;
|
|
164
|
+
const resolved_input_files_for_input_path = [];
|
|
165
|
+
for (const path_id of path_ids) {
|
|
166
|
+
const resolved_input_file = {
|
|
167
|
+
id: path_id,
|
|
168
|
+
input_path,
|
|
169
|
+
resolved_input_path,
|
|
170
|
+
};
|
|
171
|
+
resolved_input_files.push(resolved_input_file);
|
|
172
|
+
resolved_input_files_for_input_path.push(resolved_input_file);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (!existing_path_ids.has(id)) {
|
|
177
|
+
// Handle input paths that resolve to files.
|
|
178
|
+
existing_path_ids.add(id);
|
|
179
|
+
const resolved_input_file = { id, input_path, resolved_input_path };
|
|
180
|
+
resolved_input_files.push(resolved_input_file);
|
|
181
|
+
}
|
|
182
|
+
handle_found(input_path, id);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
resolved_input_files,
|
|
187
|
+
resolved_input_files_by_root_dir: resolved_input_files.reduce((map, resolved_input_file) => {
|
|
188
|
+
const { root_dir } = resolved_input_file.resolved_input_path;
|
|
189
|
+
if (map.has(root_dir)) {
|
|
190
|
+
map.get(root_dir).push(resolved_input_file);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
map.set(root_dir, [resolved_input_file]);
|
|
194
|
+
}
|
|
195
|
+
return map;
|
|
196
|
+
}, new Map()),
|
|
197
|
+
input_directories_with_no_files: remaining.map((r) => r.input_path),
|
|
198
|
+
};
|
|
199
|
+
};
|
package/dist/invoke.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/invoke.ts"],"names":[],"mappings":""}
|