@ryanatkn/gro 0.176.0 → 0.177.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/dist/args.d.ts +5 -5
- package/dist/args.d.ts.map +1 -1
- package/dist/build.task.d.ts.map +1 -1
- package/dist/build.task.js +2 -2
- package/dist/build_cache.d.ts +12 -12
- package/dist/build_cache.d.ts.map +1 -1
- package/dist/build_cache.js +4 -4
- package/dist/changelog.d.ts +2 -2
- package/dist/changelog.d.ts.map +1 -1
- package/dist/changelog.js +1 -1
- package/dist/changeset.task.d.ts.map +1 -1
- package/dist/changeset.task.js +9 -9
- package/dist/changeset_helpers.d.ts +4 -4
- package/dist/changeset_helpers.d.ts.map +1 -1
- package/dist/changeset_helpers.js +2 -2
- package/dist/check.task.d.ts.map +1 -1
- package/dist/check.task.js +3 -3
- package/dist/clean.task.js +2 -2
- package/dist/cli.d.ts +6 -6
- package/dist/cli.d.ts.map +1 -1
- package/dist/commit.task.js +2 -2
- package/dist/deploy.task.d.ts.map +1 -1
- package/dist/deploy.task.js +13 -13
- package/dist/dev.task.d.ts +2 -2
- package/dist/dev.task.d.ts.map +1 -1
- package/dist/disknode.d.ts +4 -4
- package/dist/disknode.d.ts.map +1 -1
- package/dist/esbuild_helpers.d.ts +2 -2
- package/dist/esbuild_helpers.d.ts.map +1 -1
- package/dist/esbuild_plugin_external_worker.d.ts +5 -5
- package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
- package/dist/esbuild_plugin_svelte.d.ts +4 -4
- package/dist/esbuild_plugin_svelte.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +2 -2
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +5 -5
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts.map +1 -1
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +2 -2
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts.map +1 -1
- package/dist/filer.d.ts +15 -15
- package/dist/filer.d.ts.map +1 -1
- package/dist/filer.js +2 -2
- package/dist/format.task.d.ts.map +1 -1
- package/dist/format.task.js +2 -2
- package/dist/format_directory.d.ts +2 -2
- package/dist/format_directory.d.ts.map +1 -1
- package/dist/gen.d.ts +73 -73
- package/dist/gen.d.ts.map +1 -1
- package/dist/gen.js +1 -1
- package/dist/gen.task.d.ts.map +1 -1
- package/dist/gen.task.js +8 -8
- package/dist/gen_helpers.d.ts +4 -4
- package/dist/gen_helpers.d.ts.map +1 -1
- package/dist/gen_helpers.js +1 -1
- package/dist/github.d.ts +4 -4
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +3 -3
- package/dist/gro.config.default.d.ts +2 -2
- package/dist/gro.config.default.d.ts.map +1 -1
- package/dist/gro_config.d.ts +25 -25
- package/dist/gro_config.d.ts.map +1 -1
- package/dist/gro_config.js +2 -2
- package/dist/gro_helpers.d.ts +2 -2
- package/dist/gro_helpers.d.ts.map +1 -1
- package/dist/gro_plugin_gen.d.ts +3 -3
- package/dist/gro_plugin_gen.d.ts.map +1 -1
- package/dist/gro_plugin_gen.js +2 -2
- package/dist/gro_plugin_server.d.ts +7 -7
- package/dist/gro_plugin_server.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.d.ts +10 -10
- package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.js +2 -2
- package/dist/gro_plugin_sveltekit_library.d.ts +4 -4
- package/dist/gro_plugin_sveltekit_library.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_library.js +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/input_path.d.ts +30 -30
- package/dist/input_path.d.ts.map +1 -1
- package/dist/input_path.js +2 -2
- package/dist/invoke.js +1 -1
- package/dist/invoke_task.d.ts +3 -3
- package/dist/invoke_task.d.ts.map +1 -1
- package/dist/invoke_task.js +4 -4
- package/dist/lint.task.d.ts.map +1 -1
- package/dist/lint.task.js +2 -2
- package/dist/modules.d.ts +20 -20
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +2 -2
- package/dist/package_json.d.ts +16 -16
- package/dist/package_json.d.ts.map +1 -1
- package/dist/package_json.js +6 -6
- package/dist/parse_exports.d.ts +7 -7
- package/dist/parse_exports.d.ts.map +1 -1
- package/dist/parse_exports.js +3 -3
- package/dist/parse_exports_context.d.ts +3 -3
- package/dist/parse_exports_context.d.ts.map +1 -1
- package/dist/parse_exports_context.js +1 -1
- package/dist/parse_imports.d.ts +3 -3
- package/dist/parse_imports.d.ts.map +1 -1
- package/dist/parse_imports.js +2 -2
- package/dist/paths.d.ts +6 -6
- package/dist/paths.d.ts.map +1 -1
- package/dist/plugin.d.ts +13 -13
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/publish.task.d.ts.map +1 -1
- package/dist/publish.task.js +12 -12
- package/dist/reinstall.task.d.ts.map +1 -1
- package/dist/reinstall.task.js +4 -4
- package/dist/resolve_specifier.d.ts +4 -4
- package/dist/resolve_specifier.d.ts.map +1 -1
- package/dist/run.task.d.ts.map +1 -1
- package/dist/run.task.js +3 -3
- package/dist/run_gen.d.ts +4 -4
- package/dist/run_gen.d.ts.map +1 -1
- package/dist/run_task.d.ts +4 -4
- package/dist/run_task.d.ts.map +1 -1
- package/dist/run_task.js +3 -3
- package/dist/search_fs.d.ts +6 -6
- package/dist/search_fs.d.ts.map +1 -1
- package/dist/src_json.d.ts +6 -6
- package/dist/src_json.d.ts.map +1 -1
- package/dist/src_json.js +3 -3
- package/dist/svelte_config.d.ts +3 -3
- package/dist/svelte_config.d.ts.map +1 -1
- package/dist/sveltekit_helpers.d.ts +5 -5
- package/dist/sveltekit_helpers.d.ts.map +1 -1
- package/dist/sveltekit_helpers.js +5 -5
- package/dist/sveltekit_shim_app.d.ts +2 -2
- package/dist/sveltekit_shim_app.d.ts.map +1 -1
- package/dist/sync.task.d.ts.map +1 -1
- package/dist/sync.task.js +2 -2
- package/dist/task.d.ts +54 -54
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +3 -3
- package/dist/task_logging.d.ts +3 -3
- package/dist/task_logging.d.ts.map +1 -1
- package/dist/test.task.d.ts.map +1 -1
- package/dist/test.task.js +4 -4
- package/dist/typecheck.task.d.ts.map +1 -1
- package/dist/typecheck.task.js +4 -4
- package/dist/upgrade.task.d.ts.map +1 -1
- package/dist/upgrade.task.js +5 -5
- package/dist/watch_dir.d.ts +10 -10
- package/dist/watch_dir.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/args.ts +9 -9
- package/src/lib/build.task.ts +2 -2
- package/src/lib/build_cache.ts +18 -18
- package/src/lib/changelog.ts +10 -10
- package/src/lib/changeset.task.ts +16 -16
- package/src/lib/changeset_helpers.ts +4 -4
- package/src/lib/check.task.ts +3 -3
- package/src/lib/clean.task.ts +2 -2
- package/src/lib/cli.ts +7 -7
- package/src/lib/commit.task.ts +2 -2
- package/src/lib/deploy.task.ts +15 -15
- package/src/lib/dev.task.ts +2 -2
- package/src/lib/disknode.ts +4 -4
- package/src/lib/esbuild_helpers.ts +2 -2
- package/src/lib/esbuild_plugin_external_worker.ts +7 -7
- package/src/lib/esbuild_plugin_svelte.ts +4 -4
- package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +2 -2
- package/src/lib/esbuild_plugin_sveltekit_shim_app.ts +5 -5
- package/src/lib/esbuild_plugin_sveltekit_shim_env.ts +2 -2
- package/src/lib/filer.ts +35 -35
- package/src/lib/format.task.ts +2 -2
- package/src/lib/format_directory.ts +2 -2
- package/src/lib/gen.task.ts +19 -19
- package/src/lib/gen.ts +85 -85
- package/src/lib/gen_helpers.ts +17 -17
- package/src/lib/github.ts +6 -6
- package/src/lib/gro.config.default.ts +2 -2
- package/src/lib/gro_config.ts +28 -28
- package/src/lib/gro_helpers.ts +2 -2
- package/src/lib/gro_plugin_gen.ts +5 -5
- package/src/lib/gro_plugin_server.ts +8 -8
- package/src/lib/gro_plugin_sveltekit_app.ts +15 -15
- package/src/lib/gro_plugin_sveltekit_library.ts +6 -6
- package/src/lib/index.ts +3 -3
- package/src/lib/input_path.ts +56 -56
- package/src/lib/invoke.ts +2 -2
- package/src/lib/invoke_task.ts +7 -7
- package/src/lib/lint.task.ts +2 -2
- package/src/lib/modules.ts +31 -31
- package/src/lib/package_json.ts +27 -27
- package/src/lib/parse_exports.ts +15 -15
- package/src/lib/parse_exports_context.ts +9 -9
- package/src/lib/parse_imports.ts +6 -6
- package/src/lib/paths.ts +6 -6
- package/src/lib/plugin.ts +17 -17
- package/src/lib/publish.task.ts +13 -13
- package/src/lib/reinstall.task.ts +4 -4
- package/src/lib/resolve_specifier.ts +5 -5
- package/src/lib/run.task.ts +3 -3
- package/src/lib/run_gen.ts +14 -14
- package/src/lib/run_task.ts +8 -8
- package/src/lib/search_fs.ts +13 -13
- package/src/lib/src_json.ts +13 -13
- package/src/lib/svelte_config.ts +2 -2
- package/src/lib/sveltekit_helpers.ts +12 -12
- package/src/lib/sveltekit_shim_app.ts +3 -3
- package/src/lib/sync.task.ts +2 -2
- package/src/lib/task.ts +63 -63
- package/src/lib/task_logging.ts +11 -11
- package/src/lib/test.task.ts +4 -4
- package/src/lib/typecheck.task.ts +4 -4
- package/src/lib/upgrade.task.ts +7 -7
- package/src/lib/watch_dir.ts +10 -10
package/src/lib/run_gen.ts
CHANGED
|
@@ -4,43 +4,43 @@ import type {Timings} from '@ryanatkn/belt/timings.js';
|
|
|
4
4
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
type
|
|
7
|
+
type GenResults,
|
|
8
|
+
type GenfileModuleResult,
|
|
9
|
+
type GenContext,
|
|
10
|
+
type GenfileModuleMeta,
|
|
11
11
|
to_gen_result,
|
|
12
|
-
type
|
|
12
|
+
type RawGenResult,
|
|
13
13
|
normalize_gen_config,
|
|
14
14
|
} from './gen.ts';
|
|
15
15
|
import {print_path, to_root_path} from './paths.ts';
|
|
16
16
|
import type {format_file as base_format_file} from './format_file.ts';
|
|
17
|
-
import type {
|
|
17
|
+
import type {GroConfig} from './gro_config.ts';
|
|
18
18
|
import {default_svelte_config} from './svelte_config.ts';
|
|
19
19
|
import type {Filer} from './filer.ts';
|
|
20
|
-
import type {
|
|
20
|
+
import type {InvokeTask} from './task.ts';
|
|
21
21
|
|
|
22
22
|
export const GEN_NO_PROD_MESSAGE = 'gen runs only during development';
|
|
23
23
|
|
|
24
24
|
export const run_gen = async (
|
|
25
|
-
gen_modules: Array<
|
|
26
|
-
config:
|
|
25
|
+
gen_modules: Array<GenfileModuleMeta>,
|
|
26
|
+
config: GroConfig,
|
|
27
27
|
filer: Filer,
|
|
28
28
|
log: Logger,
|
|
29
29
|
timings: Timings,
|
|
30
|
-
invoke_task:
|
|
30
|
+
invoke_task: InvokeTask,
|
|
31
31
|
format_file?: typeof base_format_file,
|
|
32
|
-
): Promise<
|
|
32
|
+
): Promise<GenResults> => {
|
|
33
33
|
let input_count = 0;
|
|
34
34
|
let output_count = 0;
|
|
35
35
|
const timing_for_run_gen = timings.start('run_gen');
|
|
36
36
|
const results = await Promise.all(
|
|
37
|
-
gen_modules.map(async (module_meta): Promise<
|
|
37
|
+
gen_modules.map(async (module_meta): Promise<GenfileModuleResult> => {
|
|
38
38
|
input_count++;
|
|
39
39
|
const {id} = module_meta;
|
|
40
40
|
const timing_for_module = timings.start(id);
|
|
41
41
|
|
|
42
42
|
const gen_config = normalize_gen_config(module_meta.mod.gen);
|
|
43
|
-
const gen_ctx:
|
|
43
|
+
const gen_ctx: GenContext = {
|
|
44
44
|
config,
|
|
45
45
|
svelte_config: default_svelte_config,
|
|
46
46
|
filer,
|
|
@@ -51,7 +51,7 @@ export const run_gen = async (
|
|
|
51
51
|
origin_path: to_root_path(id),
|
|
52
52
|
changed_file_id: undefined,
|
|
53
53
|
};
|
|
54
|
-
let raw_gen_result:
|
|
54
|
+
let raw_gen_result: RawGenResult;
|
|
55
55
|
try {
|
|
56
56
|
raw_gen_result = await gen_config.generate(gen_ctx);
|
|
57
57
|
} catch (err) {
|
package/src/lib/run_task.ts
CHANGED
|
@@ -6,12 +6,12 @@ import {z} from 'zod';
|
|
|
6
6
|
import {parse_args, type Args} from './args.ts';
|
|
7
7
|
import type {invoke_task as base_invoke_task} from './invoke_task.ts';
|
|
8
8
|
import {log_task_help} from './task_logging.ts';
|
|
9
|
-
import type {
|
|
10
|
-
import {
|
|
9
|
+
import type {GroConfig} from './gro_config.ts';
|
|
10
|
+
import {TaskError, type TaskModuleMeta} from './task.ts';
|
|
11
11
|
import {default_svelte_config} from './svelte_config.ts';
|
|
12
12
|
import type {Filer} from './filer.ts';
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type RunTaskResult =
|
|
15
15
|
| {
|
|
16
16
|
ok: true;
|
|
17
17
|
output: unknown;
|
|
@@ -23,14 +23,14 @@ export type Run_Task_Result =
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export const run_task = async (
|
|
26
|
-
task_meta:
|
|
26
|
+
task_meta: TaskModuleMeta,
|
|
27
27
|
unparsed_args: Args,
|
|
28
28
|
invoke_task: typeof base_invoke_task,
|
|
29
|
-
config:
|
|
29
|
+
config: GroConfig,
|
|
30
30
|
filer: Filer,
|
|
31
31
|
log: Logger,
|
|
32
32
|
timings: Timings,
|
|
33
|
-
): Promise<
|
|
33
|
+
): Promise<RunTaskResult> => {
|
|
34
34
|
const {task} = task_meta.mod;
|
|
35
35
|
|
|
36
36
|
if (unparsed_args.help) {
|
|
@@ -43,7 +43,7 @@ export const run_task = async (
|
|
|
43
43
|
if (task.Args) {
|
|
44
44
|
const parsed = parse_args(unparsed_args, task.Args);
|
|
45
45
|
if (!parsed.success) {
|
|
46
|
-
throw new
|
|
46
|
+
throw new TaskError(
|
|
47
47
|
`Failed task args validation for task '${task_meta.name}':\n${z.prettifyError(parsed.error)}`,
|
|
48
48
|
);
|
|
49
49
|
}
|
|
@@ -68,7 +68,7 @@ export const run_task = async (
|
|
|
68
68
|
ok: false,
|
|
69
69
|
reason: st(
|
|
70
70
|
'red',
|
|
71
|
-
err?.constructor?.name === '
|
|
71
|
+
err?.constructor?.name === 'TaskError'
|
|
72
72
|
? (err.message as string)
|
|
73
73
|
: `Unexpected error running task ${st(
|
|
74
74
|
'cyan',
|
package/src/lib/search_fs.ts
CHANGED
|
@@ -3,21 +3,21 @@ import {to_array} from '@ryanatkn/belt/array.js';
|
|
|
3
3
|
import {ensure_end} from '@ryanatkn/belt/string.js';
|
|
4
4
|
import {isAbsolute, join} from 'node:path';
|
|
5
5
|
import {existsSync, readdirSync} from 'node:fs';
|
|
6
|
-
import type {
|
|
6
|
+
import type {FileFilter, ResolvedPath, PathFilter} from '@ryanatkn/belt/path.js';
|
|
7
7
|
|
|
8
|
-
export interface
|
|
8
|
+
export interface SearchFsOptions {
|
|
9
9
|
/**
|
|
10
10
|
* One or more filter functions, any of which can short-circuit the search by returning `false`.
|
|
11
11
|
*/
|
|
12
|
-
filter?:
|
|
12
|
+
filter?: PathFilter | Array<PathFilter>;
|
|
13
13
|
/**
|
|
14
14
|
* One or more file filter functions. Every filter must pass for a file to be included.
|
|
15
15
|
*/
|
|
16
|
-
file_filter?:
|
|
16
|
+
file_filter?: FileFilter | Array<FileFilter>;
|
|
17
17
|
/**
|
|
18
18
|
* Pass `null` or `false` to speed things up at the cost of volatile ordering.
|
|
19
19
|
*/
|
|
20
|
-
sort?: boolean | null | ((a:
|
|
20
|
+
sort?: boolean | null | ((a: ResolvedPath, b: ResolvedPath) => number);
|
|
21
21
|
/**
|
|
22
22
|
* Set to `true` to include directories. Defaults to `false`.
|
|
23
23
|
*/
|
|
@@ -30,8 +30,8 @@ export interface Search_Fs_Options {
|
|
|
30
30
|
|
|
31
31
|
export const search_fs = (
|
|
32
32
|
dir: string,
|
|
33
|
-
options:
|
|
34
|
-
): Array<
|
|
33
|
+
options: SearchFsOptions = EMPTY_OBJECT,
|
|
34
|
+
): Array<ResolvedPath> => {
|
|
35
35
|
const {
|
|
36
36
|
filter,
|
|
37
37
|
file_filter,
|
|
@@ -51,22 +51,22 @@ export const search_fs = (
|
|
|
51
51
|
|
|
52
52
|
if (!existsSync(final_dir)) return [];
|
|
53
53
|
|
|
54
|
-
const paths: Array<
|
|
54
|
+
const paths: Array<ResolvedPath> = [];
|
|
55
55
|
crawl(final_dir, paths, filters, file_filters, include_directories, null);
|
|
56
56
|
|
|
57
57
|
return sort ? paths.sort(typeof sort === 'boolean' ? default_sort : sort) : paths;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
const default_sort = (a:
|
|
60
|
+
const default_sort = (a: ResolvedPath, b: ResolvedPath): number => a.path.localeCompare(b.path);
|
|
61
61
|
|
|
62
62
|
const crawl = (
|
|
63
63
|
dir: string,
|
|
64
|
-
paths: Array<
|
|
65
|
-
filters: Array<
|
|
66
|
-
file_filter: Array<
|
|
64
|
+
paths: Array<ResolvedPath>,
|
|
65
|
+
filters: Array<PathFilter> | undefined,
|
|
66
|
+
file_filter: Array<FileFilter> | undefined,
|
|
67
67
|
include_directories: boolean,
|
|
68
68
|
base_dir: string | null,
|
|
69
|
-
): Array<
|
|
69
|
+
): Array<ResolvedPath> => {
|
|
70
70
|
// This sync version is significantly faster than using the `fs/promises` version -
|
|
71
71
|
// it doesn't parallelize but that's not the common case in Gro.
|
|
72
72
|
const dirents = readdirSync(dir, {withFileTypes: true});
|
package/src/lib/src_json.ts
CHANGED
|
@@ -2,8 +2,8 @@ import {join} from 'node:path';
|
|
|
2
2
|
import {ensure_end, strip_start} from '@ryanatkn/belt/string.js';
|
|
3
3
|
import {existsSync} from 'node:fs';
|
|
4
4
|
import ts from 'typescript';
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
5
|
+
import type {PackageJson, PackageJsonExports} from '@ryanatkn/belt/package_json.js';
|
|
6
|
+
import {SrcJson, type ModuleJson, type IdentifierKind} from '@ryanatkn/belt/src_json.js';
|
|
7
7
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
8
8
|
|
|
9
9
|
import {paths, replace_extension} from './paths.ts';
|
|
@@ -11,29 +11,29 @@ import {parse_exports} from './parse_exports.ts';
|
|
|
11
11
|
import {TS_MATCHER, SVELTE_MATCHER, JSON_MATCHER, CSS_MATCHER} from './constants.ts';
|
|
12
12
|
import {search_fs} from './search_fs.ts';
|
|
13
13
|
|
|
14
|
-
export type
|
|
14
|
+
export type SrcJsonMapper = (src_json: SrcJson) => SrcJson | null | Promise<SrcJson | null>;
|
|
15
15
|
|
|
16
16
|
export const src_json_create = (
|
|
17
|
-
package_json:
|
|
17
|
+
package_json: PackageJson,
|
|
18
18
|
lib_path?: string,
|
|
19
19
|
log?: Logger,
|
|
20
|
-
):
|
|
21
|
-
|
|
20
|
+
): SrcJson =>
|
|
21
|
+
SrcJson.parse({
|
|
22
22
|
name: package_json.name,
|
|
23
23
|
version: package_json.version,
|
|
24
24
|
modules: src_modules_create(package_json.exports, lib_path, log),
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
export const src_json_serialize = (src_json:
|
|
28
|
-
const parsed =
|
|
27
|
+
export const src_json_serialize = (src_json: SrcJson): string => {
|
|
28
|
+
const parsed = SrcJson.parse(src_json);
|
|
29
29
|
return JSON.stringify(parsed, null, 2) + '\n';
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
export const src_modules_create = (
|
|
33
|
-
exports:
|
|
33
|
+
exports: PackageJsonExports | undefined,
|
|
34
34
|
lib_path = paths.lib,
|
|
35
35
|
log?: Logger,
|
|
36
|
-
): Array<
|
|
36
|
+
): Array<ModuleJson> | undefined => {
|
|
37
37
|
if (!exports) return;
|
|
38
38
|
|
|
39
39
|
const file_paths = collect_file_paths(exports, lib_path);
|
|
@@ -58,14 +58,14 @@ export const src_modules_create = (
|
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const result: Array<
|
|
61
|
+
const result: Array<ModuleJson> = [];
|
|
62
62
|
|
|
63
63
|
// Process each file
|
|
64
64
|
for (const {file_path} of file_paths) {
|
|
65
65
|
const relative_path = file_path.replace(ensure_end(lib_path, '/'), '');
|
|
66
66
|
|
|
67
67
|
const identifiers = parse_exports(file_path, program, undefined, log)
|
|
68
|
-
.filter((d): d is {name: string; kind:
|
|
68
|
+
.filter((d): d is {name: string; kind: IdentifierKind} => d.kind !== null) // TODO maybe dont filter out?
|
|
69
69
|
.map(({name, kind}) => ({name, kind}));
|
|
70
70
|
|
|
71
71
|
result.push(
|
|
@@ -84,7 +84,7 @@ export const src_modules_create = (
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
const collect_file_paths = (
|
|
87
|
-
exports:
|
|
87
|
+
exports: PackageJsonExports,
|
|
88
88
|
lib_path: string,
|
|
89
89
|
): Array<{export_key: string; file_path: string}> => {
|
|
90
90
|
const file_paths: Array<{export_key: string; file_path: string}> = [];
|
package/src/lib/svelte_config.ts
CHANGED
|
@@ -37,7 +37,7 @@ export const load_svelte_config = async ({
|
|
|
37
37
|
* The `base` and `assets` in particular are renamed for clarity with Gro's internal systems,
|
|
38
38
|
* so these properties become first-class vocabulary inside Gro.
|
|
39
39
|
*/
|
|
40
|
-
export interface
|
|
40
|
+
export interface ParsedSvelteConfig {
|
|
41
41
|
// TODO probably fill these out with defaults
|
|
42
42
|
svelte_config: SvelteConfig | null;
|
|
43
43
|
alias: Record<string, string>;
|
|
@@ -78,7 +78,7 @@ export const parse_svelte_config = async ({
|
|
|
78
78
|
}: {
|
|
79
79
|
dir_or_config?: string | SvelteConfig;
|
|
80
80
|
config_filename?: string;
|
|
81
|
-
} = EMPTY_OBJECT): Promise<
|
|
81
|
+
} = EMPTY_OBJECT): Promise<ParsedSvelteConfig> => {
|
|
82
82
|
const svelte_config =
|
|
83
83
|
typeof dir_or_config === 'string'
|
|
84
84
|
? await load_svelte_config({dir: dir_or_config, config_filename})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type {Result} from '@ryanatkn/belt/result.js';
|
|
2
2
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
3
3
|
import {join} from 'node:path';
|
|
4
|
-
import type {
|
|
4
|
+
import type {PackageJson} from '@ryanatkn/belt/package_json.js';
|
|
5
5
|
import {fs_exists} from '@ryanatkn/belt/fs.js';
|
|
6
6
|
|
|
7
7
|
import {has_dep} from './package_json.ts';
|
|
8
|
-
import {default_svelte_config, type
|
|
8
|
+
import {default_svelte_config, type ParsedSvelteConfig} from './svelte_config.ts';
|
|
9
9
|
import {
|
|
10
10
|
SVELTE_CONFIG_FILENAME,
|
|
11
11
|
SVELTEKIT_DEV_DIRNAME,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
SVELTEKIT_CLI,
|
|
15
15
|
} from './constants.ts';
|
|
16
16
|
import {find_cli, spawn_cli, to_cli_name, type Cli} from './cli.ts';
|
|
17
|
-
import {
|
|
17
|
+
import {TaskError} from './task.ts';
|
|
18
18
|
import {serialize_args, to_forwarded_args} from './args.ts';
|
|
19
19
|
|
|
20
20
|
export const has_sveltekit_app = async (
|
|
@@ -28,8 +28,8 @@ export const has_sveltekit_app = async (
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
export const has_sveltekit_library = async (
|
|
31
|
-
package_json:
|
|
32
|
-
svelte_config:
|
|
31
|
+
package_json: PackageJson,
|
|
32
|
+
svelte_config: ParsedSvelteConfig = default_svelte_config,
|
|
33
33
|
dep_name = SVELTE_PACKAGE_DEP_NAME,
|
|
34
34
|
): Promise<Result<object, {message: string}>> => {
|
|
35
35
|
const has_sveltekit_app_result = await has_sveltekit_app();
|
|
@@ -57,11 +57,11 @@ export const sveltekit_sync = async (
|
|
|
57
57
|
): Promise<void> => {
|
|
58
58
|
const result = await spawn_cli(sveltekit_cli, ['sync']);
|
|
59
59
|
if (!result) {
|
|
60
|
-
throw new
|
|
60
|
+
throw new TaskError(
|
|
61
61
|
`Failed to find SvelteKit CLI \`${to_cli_name(sveltekit_cli)}\`, do you need to run \`${pm_cli} install\`?`,
|
|
62
62
|
);
|
|
63
63
|
} else if (!result.ok) {
|
|
64
|
-
throw new
|
|
64
|
+
throw new TaskError(`Failed ${to_cli_name(sveltekit_cli)} sync`);
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
67
|
|
|
@@ -100,7 +100,7 @@ export const sveltekit_sync_if_obviously_needed = async (
|
|
|
100
100
|
* Options to the SvelteKit packaging CLI.
|
|
101
101
|
* @see https://kit.svelte.dev/docs/packaging#options
|
|
102
102
|
*/
|
|
103
|
-
export interface
|
|
103
|
+
export interface SveltePackageOptions {
|
|
104
104
|
/**
|
|
105
105
|
* Watch files in src/lib for changes and rebuild the package
|
|
106
106
|
*/
|
|
@@ -147,22 +147,22 @@ export interface Svelte_Package_Options {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
export const run_svelte_package = async (
|
|
150
|
-
package_json:
|
|
151
|
-
options:
|
|
150
|
+
package_json: PackageJson,
|
|
151
|
+
options: SveltePackageOptions | undefined,
|
|
152
152
|
cli: string | Cli,
|
|
153
153
|
log: Logger,
|
|
154
154
|
pm_cli: string,
|
|
155
155
|
): Promise<void> => {
|
|
156
156
|
const has_sveltekit_library_result = await has_sveltekit_library(package_json);
|
|
157
157
|
if (!has_sveltekit_library_result.ok) {
|
|
158
|
-
throw new
|
|
158
|
+
throw new TaskError(
|
|
159
159
|
'Failed to find SvelteKit library: ' + has_sveltekit_library_result.message,
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
162
|
const cli_name = typeof cli === 'string' ? cli : cli.name;
|
|
163
163
|
const found_svelte_package_cli = cli === cli_name ? find_cli(cli) : (cli as Cli);
|
|
164
164
|
if (found_svelte_package_cli?.kind !== 'local') {
|
|
165
|
-
throw new
|
|
165
|
+
throw new TaskError(
|
|
166
166
|
`Failed to find SvelteKit packaging CLI \`${cli_name}\`, do you need to run \`${pm_cli} install\`?`,
|
|
167
167
|
);
|
|
168
168
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
2
2
|
|
|
3
3
|
export const SVELTEKIT_SHIM_APP_PATHS_MATCHER = /\/util\/sveltekit_shim_app_paths\.js$/;
|
|
4
4
|
export const SVELTEKIT_SHIM_APP_ENVIRONMENT_MATCHER = /\/util\/sveltekit_shim_app_environment\.js$/;
|
|
@@ -16,8 +16,8 @@ export const sveltekit_shim_app_specifiers = new Map([
|
|
|
16
16
|
]);
|
|
17
17
|
|
|
18
18
|
export const render_sveltekit_shim_app_paths = (
|
|
19
|
-
base_url:
|
|
20
|
-
assets_url:
|
|
19
|
+
base_url: ParsedSvelteConfig['base_url'] = '',
|
|
20
|
+
assets_url: ParsedSvelteConfig['assets_url'] = '',
|
|
21
21
|
): string => `// shim for $app/paths
|
|
22
22
|
// @see https://github.com/sveltejs/kit/issues/1485
|
|
23
23
|
|
package/src/lib/sync.task.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {z} from 'zod';
|
|
2
2
|
import {spawn} from '@ryanatkn/belt/process.js';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {TaskError, type Task} from './task.ts';
|
|
5
5
|
import {sync_package_json} from './package_json.ts';
|
|
6
6
|
import {sveltekit_sync} from './sveltekit_helpers.ts';
|
|
7
7
|
|
|
@@ -27,7 +27,7 @@ export const task: Task<Args> = {
|
|
|
27
27
|
if (install) {
|
|
28
28
|
const result = await spawn(config.pm_cli, ['install']);
|
|
29
29
|
if (!result.ok) {
|
|
30
|
-
throw new
|
|
30
|
+
throw new TaskError(`Failed \`${config.pm_cli} install\``);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
package/src/lib/task.ts
CHANGED
|
@@ -5,57 +5,57 @@ import type {Timings} from '@ryanatkn/belt/timings.js';
|
|
|
5
5
|
import {styleText as st} from 'node:util';
|
|
6
6
|
import type {Result} from '@ryanatkn/belt/result.js';
|
|
7
7
|
import {isAbsolute, join, relative} from 'node:path';
|
|
8
|
-
import type {
|
|
8
|
+
import type {PathId} from '@ryanatkn/belt/path.js';
|
|
9
9
|
|
|
10
10
|
import type {Args} from './args.ts';
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
11
|
+
import type {GroConfig} from './gro_config.ts';
|
|
12
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
13
13
|
import {
|
|
14
14
|
resolve_input_files,
|
|
15
15
|
resolve_input_paths,
|
|
16
|
-
type
|
|
17
|
-
type
|
|
18
|
-
type
|
|
16
|
+
type InputPath,
|
|
17
|
+
type ResolvedInputFile,
|
|
18
|
+
type ResolvedInputPath,
|
|
19
19
|
} from './input_path.ts';
|
|
20
20
|
import {GRO_DIST_DIR, print_path} from './paths.ts';
|
|
21
21
|
import {search_fs} from './search_fs.ts';
|
|
22
|
-
import {load_modules, type
|
|
22
|
+
import {load_modules, type LoadModulesFailure, type ModuleMeta} from './modules.ts';
|
|
23
23
|
import type {Filer} from './filer.ts';
|
|
24
24
|
|
|
25
25
|
export interface Task<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
TArgs = Args,
|
|
27
|
+
TArgsSchema extends z.ZodType<Args, Args> = z.ZodType<Args, Args>, // TODO improve type? separate input/output?
|
|
28
|
+
TReturn = unknown,
|
|
29
29
|
> {
|
|
30
|
-
run: (ctx:
|
|
30
|
+
run: (ctx: TaskContext<TArgs>) => TReturn | Promise<TReturn>; // TODO unused return value
|
|
31
31
|
summary?: string;
|
|
32
|
-
Args?:
|
|
32
|
+
Args?: TArgsSchema;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export interface
|
|
36
|
-
args:
|
|
37
|
-
config:
|
|
38
|
-
svelte_config:
|
|
35
|
+
export interface TaskContext<TArgs = object> {
|
|
36
|
+
args: TArgs;
|
|
37
|
+
config: GroConfig;
|
|
38
|
+
svelte_config: ParsedSvelteConfig;
|
|
39
39
|
filer: Filer;
|
|
40
40
|
log: Logger;
|
|
41
41
|
timings: Timings;
|
|
42
|
-
invoke_task:
|
|
42
|
+
invoke_task: InvokeTask;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export type
|
|
45
|
+
export type InvokeTask = (task_name: string, args?: Args, config?: GroConfig) => Promise<void>;
|
|
46
46
|
|
|
47
47
|
export const TASK_FILE_SUFFIX_TS = '.task.ts';
|
|
48
48
|
export const TASK_FILE_SUFFIX_JS = '.task.js';
|
|
49
|
-
export const TASK_FILE_SUFFIXES = [TASK_FILE_SUFFIX_TS, TASK_FILE_SUFFIX_JS]; // TODO from `
|
|
49
|
+
export const TASK_FILE_SUFFIXES = [TASK_FILE_SUFFIX_TS, TASK_FILE_SUFFIX_JS]; // TODO from `GroConfig`, but needs to be used everywhere the constants are
|
|
50
50
|
|
|
51
51
|
export const is_task_path = (path: string): boolean =>
|
|
52
52
|
path.endsWith(TASK_FILE_SUFFIX_TS) || path.endsWith(TASK_FILE_SUFFIX_JS);
|
|
53
53
|
|
|
54
54
|
export const to_task_name = (
|
|
55
|
-
id:
|
|
56
|
-
task_root_dir:
|
|
57
|
-
input_path:
|
|
58
|
-
root_path:
|
|
55
|
+
id: PathId,
|
|
56
|
+
task_root_dir: PathId,
|
|
57
|
+
input_path: InputPath,
|
|
58
|
+
root_path: PathId,
|
|
59
59
|
): string => {
|
|
60
60
|
let task_name = id.startsWith(task_root_dir)
|
|
61
61
|
? strip_start(strip_start(id, task_root_dir), '/')
|
|
@@ -80,46 +80,46 @@ export const to_task_name = (
|
|
|
80
80
|
* It's useful for cleaning up logging because
|
|
81
81
|
* we usually don't need their stack trace.
|
|
82
82
|
*/
|
|
83
|
-
export class
|
|
83
|
+
export class TaskError extends Error {}
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
86
|
* This is used to tell Gro to exit silently, usually still with with a non-zero exit code.
|
|
87
87
|
* Using it means error logging is handled by the code that threw it.
|
|
88
88
|
*/
|
|
89
|
-
export class
|
|
89
|
+
export class SilentError extends Error {}
|
|
90
90
|
|
|
91
|
-
export interface
|
|
92
|
-
input_path:
|
|
93
|
-
id:
|
|
94
|
-
task_root_dir:
|
|
91
|
+
export interface FoundTask {
|
|
92
|
+
input_path: InputPath;
|
|
93
|
+
id: PathId;
|
|
94
|
+
task_root_dir: PathId;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export interface
|
|
98
|
-
resolved_input_files: Array<
|
|
99
|
-
resolved_input_files_by_root_dir: Map<
|
|
100
|
-
resolved_input_paths: Array<
|
|
101
|
-
input_paths: Array<
|
|
102
|
-
task_root_dirs: Array<
|
|
97
|
+
export interface FoundTasks {
|
|
98
|
+
resolved_input_files: Array<ResolvedInputFile>;
|
|
99
|
+
resolved_input_files_by_root_dir: Map<PathId, Array<ResolvedInputFile>>;
|
|
100
|
+
resolved_input_paths: Array<ResolvedInputPath>;
|
|
101
|
+
input_paths: Array<InputPath>;
|
|
102
|
+
task_root_dirs: Array<PathId>;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export type
|
|
106
|
-
export type
|
|
105
|
+
export type FindTasksResult = Result<{value: FoundTasks}, FindModulesFailure>;
|
|
106
|
+
export type FindModulesFailure =
|
|
107
107
|
| {
|
|
108
108
|
type: 'unmapped_input_paths';
|
|
109
|
-
unmapped_input_paths: Array<
|
|
110
|
-
resolved_input_paths: Array<
|
|
111
|
-
input_paths: Array<
|
|
112
|
-
task_root_dirs: Array<
|
|
109
|
+
unmapped_input_paths: Array<InputPath>;
|
|
110
|
+
resolved_input_paths: Array<ResolvedInputPath>;
|
|
111
|
+
input_paths: Array<InputPath>;
|
|
112
|
+
task_root_dirs: Array<PathId>;
|
|
113
113
|
reasons: Array<string>;
|
|
114
114
|
}
|
|
115
115
|
| {
|
|
116
116
|
type: 'input_directories_with_no_files';
|
|
117
|
-
input_directories_with_no_files: Array<
|
|
118
|
-
resolved_input_files: Array<
|
|
119
|
-
resolved_input_files_by_root_dir: Map<
|
|
120
|
-
resolved_input_paths: Array<
|
|
121
|
-
input_paths: Array<
|
|
122
|
-
task_root_dirs: Array<
|
|
117
|
+
input_directories_with_no_files: Array<InputPath>;
|
|
118
|
+
resolved_input_files: Array<ResolvedInputFile>;
|
|
119
|
+
resolved_input_files_by_root_dir: Map<PathId, Array<ResolvedInputFile>>;
|
|
120
|
+
resolved_input_paths: Array<ResolvedInputPath>;
|
|
121
|
+
input_paths: Array<InputPath>;
|
|
122
|
+
task_root_dirs: Array<PathId>;
|
|
123
123
|
reasons: Array<string>;
|
|
124
124
|
};
|
|
125
125
|
|
|
@@ -127,11 +127,11 @@ export type Find_Modules_Failure =
|
|
|
127
127
|
* Finds modules from input paths. (see `src/lib/input_path.ts` for more)
|
|
128
128
|
*/
|
|
129
129
|
export const find_tasks = (
|
|
130
|
-
input_paths: Array<
|
|
131
|
-
task_root_dirs: Array<
|
|
132
|
-
config:
|
|
130
|
+
input_paths: Array<InputPath>,
|
|
131
|
+
task_root_dirs: Array<PathId>,
|
|
132
|
+
config: GroConfig,
|
|
133
133
|
timings?: Timings,
|
|
134
|
-
):
|
|
134
|
+
): FindTasksResult => {
|
|
135
135
|
// Check which extension variation works - if it's a directory, prefer others first!
|
|
136
136
|
const timing_to_resolve_input_paths = timings?.start('resolve input paths');
|
|
137
137
|
const {resolved_input_paths, unmapped_input_paths} = resolve_input_paths(
|
|
@@ -196,30 +196,30 @@ export const find_tasks = (
|
|
|
196
196
|
};
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
export interface
|
|
200
|
-
modules: Array<
|
|
201
|
-
found_tasks:
|
|
199
|
+
export interface LoadedTasks {
|
|
200
|
+
modules: Array<TaskModuleMeta>;
|
|
201
|
+
found_tasks: FoundTasks;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
export interface
|
|
204
|
+
export interface TaskModule {
|
|
205
205
|
task: Task;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
export interface
|
|
208
|
+
export interface TaskModuleMeta extends ModuleMeta<TaskModule> {
|
|
209
209
|
name: string;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
export type
|
|
213
|
-
export type
|
|
212
|
+
export type LoadTasksResult = Result<{value: LoadedTasks}, LoadTasksFailure>;
|
|
213
|
+
export type LoadTasksFailure = LoadModulesFailure<TaskModuleMeta>;
|
|
214
214
|
|
|
215
215
|
export const load_tasks = async (
|
|
216
|
-
found_tasks:
|
|
217
|
-
root_path:
|
|
218
|
-
): Promise<
|
|
216
|
+
found_tasks: FoundTasks,
|
|
217
|
+
root_path: PathId = process.cwd(), // TODO @many isn't passed in anywhere, maybe hoist to `invoke_task` and others
|
|
218
|
+
): Promise<LoadTasksResult> => {
|
|
219
219
|
const loaded_modules = await load_modules(
|
|
220
220
|
found_tasks.resolved_input_files,
|
|
221
221
|
validate_task_module,
|
|
222
|
-
(resolved_input_file, mod):
|
|
222
|
+
(resolved_input_file, mod): TaskModuleMeta => ({
|
|
223
223
|
id: resolved_input_file.id,
|
|
224
224
|
mod,
|
|
225
225
|
name: to_task_name(
|
|
@@ -240,5 +240,5 @@ export const load_tasks = async (
|
|
|
240
240
|
};
|
|
241
241
|
};
|
|
242
242
|
|
|
243
|
-
export const validate_task_module = (mod: Record<string, any>): mod is
|
|
243
|
+
export const validate_task_module = (mod: Record<string, any>): mod is TaskModule =>
|
|
244
244
|
!!mod.task && typeof mod.task.run === 'function';
|