@ryanatkn/gro 0.175.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 +5 -1
- package/dist/run.task.d.ts.map +1 -1
- package/dist/run.task.js +25 -15
- 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 +28 -17
- 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/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';
|
package/src/lib/task_logging.ts
CHANGED
|
@@ -4,11 +4,11 @@ import {plural} from '@ryanatkn/belt/string.js';
|
|
|
4
4
|
import {print_value} from '@ryanatkn/belt/print.js';
|
|
5
5
|
import {z} from 'zod';
|
|
6
6
|
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type {ArgSchema} from './args.ts';
|
|
8
|
+
import type {LoadedTasks, TaskModuleMeta} from './task.ts';
|
|
9
9
|
import {print_path} from './paths.ts';
|
|
10
10
|
|
|
11
|
-
export const log_tasks = (log: Logger, loaded_tasks:
|
|
11
|
+
export const log_tasks = (log: Logger, loaded_tasks: LoadedTasks, log_intro = true): void => {
|
|
12
12
|
const {modules, found_tasks} = loaded_tasks;
|
|
13
13
|
const {resolved_input_files_by_root_dir} = found_tasks;
|
|
14
14
|
|
|
@@ -52,7 +52,7 @@ export const log_error_reasons = (log: Logger, reasons: Array<string>): void =>
|
|
|
52
52
|
|
|
53
53
|
const ARGS_PROPERTY_NAME = '[...args]';
|
|
54
54
|
|
|
55
|
-
export const log_task_help = (log: Logger, meta:
|
|
55
|
+
export const log_task_help = (log: Logger, meta: TaskModuleMeta): void => {
|
|
56
56
|
const {
|
|
57
57
|
name,
|
|
58
58
|
mod: {task},
|
|
@@ -92,17 +92,17 @@ export const log_task_help = (log: Logger, meta: Task_Module_Meta): void => {
|
|
|
92
92
|
// The following Zod helpers only need to support single-depth schemas for CLI args,
|
|
93
93
|
// but there's generic recursion to handle things like `ZodOptional` and `ZodDefault`.
|
|
94
94
|
|
|
95
|
-
interface
|
|
95
|
+
interface ArgSchemaProperty {
|
|
96
96
|
name: string;
|
|
97
|
-
schema:
|
|
97
|
+
schema: ArgSchema;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
// TODO this blocks many usecases like unions, and it's only implemented for CLI arg types, need better support for arbitrary schemas
|
|
101
101
|
const to_arg_properties = (
|
|
102
102
|
schema: z.ZodType,
|
|
103
|
-
meta:
|
|
103
|
+
meta: TaskModuleMeta,
|
|
104
104
|
log: Logger,
|
|
105
|
-
): Array<
|
|
105
|
+
): Array<ArgSchemaProperty> => {
|
|
106
106
|
const {def} = schema;
|
|
107
107
|
|
|
108
108
|
// TODO overly restrictive, support optional objects and/or unions?
|
|
@@ -112,11 +112,11 @@ const to_arg_properties = (
|
|
|
112
112
|
}
|
|
113
113
|
const shape = (def as z.core.$ZodObjectDef).shape;
|
|
114
114
|
|
|
115
|
-
const properties: Array<
|
|
115
|
+
const properties: Array<ArgSchemaProperty> = [];
|
|
116
116
|
for (const name in shape) {
|
|
117
117
|
if ('no-' + name in shape) continue;
|
|
118
118
|
const s = shape[name] as z.ZodType;
|
|
119
|
-
const schema:
|
|
119
|
+
const schema: ArgSchema = {
|
|
120
120
|
type: to_args_schema_type(s),
|
|
121
121
|
description: to_args_schema_description(s) || '',
|
|
122
122
|
default: to_args_schema_default(s),
|
|
@@ -129,7 +129,7 @@ const to_arg_properties = (
|
|
|
129
129
|
const to_max_length = <T>(items: Array<T>, toString: (item: T) => string) =>
|
|
130
130
|
items.reduce((max, m) => Math.max(toString(m).length, max), 0);
|
|
131
131
|
|
|
132
|
-
const to_args_schema_type = (schema: z.ZodType):
|
|
132
|
+
const to_args_schema_type = (schema: z.ZodType): ArgSchema['type'] => {
|
|
133
133
|
const {def} = schema._zod;
|
|
134
134
|
switch (def.type) {
|
|
135
135
|
case 'string':
|
package/src/lib/test.task.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {z} from 'zod';
|
|
2
2
|
import {spawn_cli} from '@ryanatkn/gro/cli.js';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {TaskError, type Task} from './task.ts';
|
|
5
5
|
import {find_cli} from './cli.ts';
|
|
6
6
|
import {has_dep} from './package_json.ts';
|
|
7
7
|
import {serialize_args, to_implicit_forwarded_args} from './args.ts';
|
|
@@ -31,11 +31,11 @@ export const task: Task<Args> = {
|
|
|
31
31
|
const {_: patterns, dir, fail_without_tests, t} = args;
|
|
32
32
|
|
|
33
33
|
if (!has_dep(VITEST_CLI)) {
|
|
34
|
-
throw new
|
|
34
|
+
throw new TaskError('no test runner found, install vitest');
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (!find_cli(VITEST_CLI)) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new TaskError('vitest is a dependency but not installed; run `npm i`?');
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
const vitest_args = ['run', ...patterns];
|
|
@@ -52,7 +52,7 @@ export const task: Task<Args> = {
|
|
|
52
52
|
|
|
53
53
|
const spawned = await spawn_cli(VITEST_CLI, vitest_args);
|
|
54
54
|
if (!spawned?.ok) {
|
|
55
|
-
throw new
|
|
55
|
+
throw new TaskError(`vitest failed with exit code ${spawned?.code}`);
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
58
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {print_spawn_result} from '@ryanatkn/belt/process.js';
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {TaskError, type Task} from './task.ts';
|
|
5
5
|
import {serialize_args, to_forwarded_args} from './args.ts';
|
|
6
6
|
import {find_cli, spawn_cli, spawn_cli_process} from './cli.ts';
|
|
7
7
|
import {sveltekit_sync_if_available} from './sveltekit_helpers.ts';
|
|
@@ -53,7 +53,7 @@ export const task: Task<Args> = {
|
|
|
53
53
|
const svelte_check_result = await spawned.closed;
|
|
54
54
|
|
|
55
55
|
if (!svelte_check_result.ok) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new TaskError(`Failed to typecheck. ${print_spawn_result(svelte_check_result)}`);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -68,12 +68,12 @@ export const task: Task<Args> = {
|
|
|
68
68
|
const serialized = serialize_args(forwarded);
|
|
69
69
|
const svelte_check_result = await spawn_cli(found_typescript_cli, serialized, log);
|
|
70
70
|
if (!svelte_check_result?.ok) {
|
|
71
|
-
throw new
|
|
71
|
+
throw new TaskError(`Failed to typecheck. ${print_spawn_result(svelte_check_result!)}`);
|
|
72
72
|
}
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
throw new
|
|
76
|
+
throw new TaskError(
|
|
77
77
|
`Failed to typecheck because neither \`${svelte_check_cli}\` nor \`${typescript_cli}\` was found`,
|
|
78
78
|
);
|
|
79
79
|
},
|
package/src/lib/upgrade.task.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {spawn} from '@ryanatkn/belt/process.js';
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
import {rmSync} from 'node:fs';
|
|
4
|
-
import {
|
|
4
|
+
import {GitOrigin, git_pull} from '@ryanatkn/belt/git.js';
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {extract_deps, load_package_json, type
|
|
6
|
+
import {TaskError, type Task} from './task.ts';
|
|
7
|
+
import {extract_deps, load_package_json, type PackageJsonDep} from './package_json.ts';
|
|
8
8
|
import {spawn_cli} from './cli.ts';
|
|
9
9
|
import {serialize_args, to_forwarded_args} from './args.ts';
|
|
10
10
|
import {NODE_MODULES_DIRNAME} from './constants.ts';
|
|
@@ -22,7 +22,7 @@ export const Args = z.strictObject({
|
|
|
22
22
|
})
|
|
23
23
|
.default([])
|
|
24
24
|
.transform((v) => (Array.isArray(v) ? v : [v])),
|
|
25
|
-
origin:
|
|
25
|
+
origin: GitOrigin.describe('git origin to deploy to').default('origin'),
|
|
26
26
|
force: z.boolean().meta({description: 'if true, print out the planned upgrades'}).default(false),
|
|
27
27
|
pull: z.boolean().meta({description: 'dual of no-pull'}).default(true),
|
|
28
28
|
'no-pull': z.boolean().meta({description: 'opt out of git pull'}).default(false),
|
|
@@ -65,7 +65,7 @@ export const task: Task<Args> = {
|
|
|
65
65
|
} = args;
|
|
66
66
|
|
|
67
67
|
if (_.length && only.length) {
|
|
68
|
-
throw new
|
|
68
|
+
throw new TaskError('Cannot call `gro upgrade` with both rest args and --only.');
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
// TODO maybe a different task that pulls and does other things, like `gro ready`
|
|
@@ -92,7 +92,7 @@ export const task: Task<Args> = {
|
|
|
92
92
|
: all_deps.filter((d) => !_.includes(d.name));
|
|
93
93
|
|
|
94
94
|
if (only.length && only.length !== deps.length) {
|
|
95
|
-
throw new
|
|
95
|
+
throw new TaskError(
|
|
96
96
|
`Some deps to upgrade were not found: ${only.filter((o) => !deps.find((d) => d.name === o)).join(', ')}`,
|
|
97
97
|
);
|
|
98
98
|
}
|
|
@@ -130,7 +130,7 @@ const CUSTOM_TAG_MATCHER = /^[\^~><=]*.+-(.+)/;
|
|
|
130
130
|
|
|
131
131
|
// TODO hacky and limited
|
|
132
132
|
// TODO probably want to pass through exact deps as well, e.g. @foo/bar@1
|
|
133
|
-
const to_upgrade_items = (deps: Array<
|
|
133
|
+
const to_upgrade_items = (deps: Array<PackageJsonDep>): Array<string> =>
|
|
134
134
|
deps.map((dep) => {
|
|
135
135
|
if (EXACT_VERSION_MATCHER.test(dep.name)) {
|
|
136
136
|
return dep.name;
|
package/src/lib/watch_dir.ts
CHANGED
|
@@ -2,30 +2,30 @@ import {watch, type ChokidarOptions, type FSWatcher, type Matcher} from 'chokida
|
|
|
2
2
|
import {relative} from 'node:path';
|
|
3
3
|
import {statSync} from 'node:fs';
|
|
4
4
|
import {create_deferred, type Deferred} from '@ryanatkn/belt/async.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type {PathFilter} from '@ryanatkn/belt/path.js';
|
|
6
6
|
import {EMPTY_OBJECT} from '@ryanatkn/belt/object.js';
|
|
7
7
|
|
|
8
8
|
const TMP_FILE_PATTERN = /\.tmp\./;
|
|
9
9
|
|
|
10
10
|
// TODO pretty hacky
|
|
11
11
|
|
|
12
|
-
export interface
|
|
12
|
+
export interface WatchNodeFs {
|
|
13
13
|
init: () => Promise<void>;
|
|
14
14
|
close: () => Promise<void>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface
|
|
18
|
-
type:
|
|
17
|
+
export interface WatcherChange {
|
|
18
|
+
type: WatcherChangeType;
|
|
19
19
|
path: string;
|
|
20
20
|
is_directory: boolean;
|
|
21
21
|
}
|
|
22
|
-
export type
|
|
23
|
-
export type
|
|
22
|
+
export type WatcherChangeType = 'add' | 'update' | 'delete';
|
|
23
|
+
export type WatcherChangeCallback = (change: WatcherChange) => void;
|
|
24
24
|
|
|
25
|
-
export interface
|
|
25
|
+
export interface WatchDirOptions {
|
|
26
26
|
dir: string;
|
|
27
|
-
on_change:
|
|
28
|
-
filter?:
|
|
27
|
+
on_change: WatcherChangeCallback;
|
|
28
|
+
filter?: PathFilter | null | undefined;
|
|
29
29
|
chokidar?: ChokidarOptions;
|
|
30
30
|
/**
|
|
31
31
|
* When `false`, returns the `path` relative to `dir`.
|
|
@@ -51,7 +51,7 @@ export const watch_dir = ({
|
|
|
51
51
|
absolute = true,
|
|
52
52
|
chokidar,
|
|
53
53
|
ignored = TMP_FILE_PATTERN,
|
|
54
|
-
}:
|
|
54
|
+
}: WatchDirOptions): WatchNodeFs => {
|
|
55
55
|
let watcher: FSWatcher | undefined;
|
|
56
56
|
let initing: Deferred<void> | undefined;
|
|
57
57
|
|