@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/gen.ts
CHANGED
|
@@ -5,73 +5,73 @@ import type {Result} from '@ryanatkn/belt/result.js';
|
|
|
5
5
|
import type {Timings} from '@ryanatkn/belt/timings.js';
|
|
6
6
|
import {styleText as st} from 'node:util';
|
|
7
7
|
import {existsSync} from 'node:fs';
|
|
8
|
-
import type {
|
|
8
|
+
import type {PathId} from '@ryanatkn/belt/path.js';
|
|
9
9
|
|
|
10
10
|
import {print_path} from './paths.ts';
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
import {load_modules, type
|
|
11
|
+
import type {GroConfig} from './gro_config.ts';
|
|
12
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
13
|
+
import {load_modules, type LoadModulesFailure, type ModuleMeta} from './modules.ts';
|
|
14
14
|
import {
|
|
15
|
-
|
|
15
|
+
InputPath,
|
|
16
16
|
resolve_input_files,
|
|
17
17
|
resolve_input_paths,
|
|
18
|
-
type
|
|
19
|
-
type
|
|
18
|
+
type ResolvedInputFile,
|
|
19
|
+
type ResolvedInputPath,
|
|
20
20
|
} from './input_path.ts';
|
|
21
21
|
import {search_fs} from './search_fs.ts';
|
|
22
22
|
import type {Filer} from './filer.ts';
|
|
23
|
-
import type {
|
|
23
|
+
import type {InvokeTask} from './task.ts';
|
|
24
24
|
|
|
25
25
|
export const GEN_FILE_PATTERN_TEXT = 'gen';
|
|
26
26
|
export const GEN_FILE_PATTERN = '.' + GEN_FILE_PATTERN_TEXT + '.';
|
|
27
27
|
|
|
28
28
|
export const is_gen_path = (path: string): boolean => path.includes(GEN_FILE_PATTERN);
|
|
29
29
|
|
|
30
|
-
export interface
|
|
31
|
-
origin_id:
|
|
32
|
-
files: Array<
|
|
30
|
+
export interface GenResult {
|
|
31
|
+
origin_id: PathId;
|
|
32
|
+
files: Array<GenFile>;
|
|
33
33
|
}
|
|
34
|
-
export interface
|
|
35
|
-
id:
|
|
34
|
+
export interface GenFile {
|
|
35
|
+
id: PathId;
|
|
36
36
|
content: string;
|
|
37
|
-
origin_id:
|
|
37
|
+
origin_id: PathId;
|
|
38
38
|
format: boolean;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export type
|
|
41
|
+
export type GenDependencies = 'all' | GenDependenciesConfig | GenDependenciesResolver;
|
|
42
42
|
|
|
43
|
-
export interface
|
|
43
|
+
export interface GenDependenciesConfig {
|
|
44
44
|
patterns?: Array<RegExp>;
|
|
45
|
-
files?: Array<
|
|
45
|
+
files?: Array<PathId>;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export type
|
|
49
|
-
ctx:
|
|
50
|
-
) =>
|
|
48
|
+
export type GenDependenciesResolver = (
|
|
49
|
+
ctx: GenContext,
|
|
50
|
+
) => GenDependenciesConfig | 'all' | null | Promise<GenDependenciesConfig | 'all' | null>;
|
|
51
51
|
|
|
52
|
-
export type Gen =
|
|
52
|
+
export type Gen = GenFunction | GenConfig;
|
|
53
53
|
|
|
54
|
-
export type
|
|
54
|
+
export type GenFunction = (ctx: GenContext) => RawGenResult | Promise<RawGenResult>;
|
|
55
55
|
|
|
56
|
-
// TODO add a
|
|
57
|
-
export interface
|
|
58
|
-
generate:
|
|
59
|
-
dependencies?:
|
|
56
|
+
// TODO add a GenConfigRaw variant and change `normalize_gen_config` to `gen_cook_config`
|
|
57
|
+
export interface GenConfig {
|
|
58
|
+
generate: GenFunction;
|
|
59
|
+
dependencies?: GenDependencies;
|
|
60
60
|
// TODO think about what could be added
|
|
61
61
|
// cache?: boolean;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export interface
|
|
65
|
-
config:
|
|
66
|
-
svelte_config:
|
|
64
|
+
export interface GenContext {
|
|
65
|
+
config: GroConfig;
|
|
66
|
+
svelte_config: ParsedSvelteConfig;
|
|
67
67
|
filer: Filer;
|
|
68
68
|
log: Logger;
|
|
69
69
|
timings: Timings;
|
|
70
|
-
invoke_task:
|
|
70
|
+
invoke_task: InvokeTask;
|
|
71
71
|
/**
|
|
72
72
|
* Same as `import.meta.url` but in path form.
|
|
73
73
|
*/
|
|
74
|
-
origin_id:
|
|
74
|
+
origin_id: PathId;
|
|
75
75
|
/**
|
|
76
76
|
* The `origin_id` relative to the root dir.
|
|
77
77
|
*/
|
|
@@ -81,12 +81,12 @@ export interface Gen_Context {
|
|
|
81
81
|
* Only available when resolving dependencies dynamically.
|
|
82
82
|
* `undefined` during actual generation.
|
|
83
83
|
*/
|
|
84
|
-
changed_file_id:
|
|
84
|
+
changed_file_id: PathId | undefined;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// TODO consider other return data - metadata? effects? non-file build artifacts?
|
|
88
|
-
export type
|
|
89
|
-
export interface
|
|
88
|
+
export type RawGenResult = string | RawGenFile | null | Array<RawGenResult>;
|
|
89
|
+
export interface RawGenFile {
|
|
90
90
|
content: string;
|
|
91
91
|
// Defaults to file name without the `.gen`, and can be a relative path.
|
|
92
92
|
// TODO maybe support a transform pattern or callback fn? like '[stem].thing.[ext]'
|
|
@@ -94,37 +94,37 @@ export interface Raw_Gen_File {
|
|
|
94
94
|
format?: boolean; // defaults to `true`
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
export interface
|
|
98
|
-
results: Array<
|
|
99
|
-
successes: Array<
|
|
100
|
-
failures: Array<
|
|
97
|
+
export interface GenResults {
|
|
98
|
+
results: Array<GenfileModuleResult>;
|
|
99
|
+
successes: Array<GenfileModuleResultSuccess>;
|
|
100
|
+
failures: Array<GenfileModuleResultFailure>;
|
|
101
101
|
input_count: number;
|
|
102
102
|
output_count: number;
|
|
103
103
|
elapsed: number;
|
|
104
104
|
}
|
|
105
|
-
export type
|
|
106
|
-
export interface
|
|
105
|
+
export type GenfileModuleResult = GenfileModuleResultSuccess | GenfileModuleResultFailure;
|
|
106
|
+
export interface GenfileModuleResultSuccess {
|
|
107
107
|
ok: true;
|
|
108
|
-
id:
|
|
109
|
-
files: Array<
|
|
108
|
+
id: PathId;
|
|
109
|
+
files: Array<GenFile>;
|
|
110
110
|
elapsed: number;
|
|
111
111
|
}
|
|
112
|
-
export interface
|
|
112
|
+
export interface GenfileModuleResultFailure {
|
|
113
113
|
ok: false;
|
|
114
|
-
id:
|
|
114
|
+
id: PathId;
|
|
115
115
|
reason: string;
|
|
116
116
|
error: Error;
|
|
117
117
|
elapsed: number;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export const to_gen_result = (origin_id:
|
|
120
|
+
export const to_gen_result = (origin_id: PathId, raw_result: RawGenResult): GenResult => {
|
|
121
121
|
return {
|
|
122
122
|
origin_id,
|
|
123
123
|
files: to_gen_files(origin_id, raw_result),
|
|
124
124
|
};
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
const to_gen_files = (origin_id:
|
|
127
|
+
const to_gen_files = (origin_id: PathId, raw_result: RawGenResult): Array<GenFile> => {
|
|
128
128
|
if (raw_result === null) {
|
|
129
129
|
return [];
|
|
130
130
|
} else if (typeof raw_result === 'string') {
|
|
@@ -137,13 +137,13 @@ const to_gen_files = (origin_id: Path_Id, raw_result: Raw_Gen_Result): Array<Gen
|
|
|
137
137
|
return [to_gen_file(origin_id, raw_result)];
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
const to_gen_file = (origin_id:
|
|
140
|
+
const to_gen_file = (origin_id: PathId, raw_gen_file: RawGenFile): GenFile => {
|
|
141
141
|
const {content, filename, format = true} = raw_gen_file;
|
|
142
142
|
const id = to_output_file_id(origin_id, filename);
|
|
143
143
|
return {id, content, origin_id, format};
|
|
144
144
|
};
|
|
145
145
|
|
|
146
|
-
const to_output_file_id = (origin_id:
|
|
146
|
+
const to_output_file_id = (origin_id: PathId, raw_file_name: string | undefined): string => {
|
|
147
147
|
if (raw_file_name === '') {
|
|
148
148
|
throw Error(`Output file name cannot be an empty string`);
|
|
149
149
|
}
|
|
@@ -186,7 +186,7 @@ export const to_output_file_name = (filename: string): string => {
|
|
|
186
186
|
return final_parts.join('.');
|
|
187
187
|
};
|
|
188
188
|
|
|
189
|
-
const validate_gen_files = (files: Array<
|
|
189
|
+
const validate_gen_files = (files: Array<GenFile>) => {
|
|
190
190
|
const ids = new Set();
|
|
191
191
|
for (const file of files) {
|
|
192
192
|
if (ids.has(file.id)) {
|
|
@@ -196,30 +196,30 @@ const validate_gen_files = (files: Array<Gen_File>) => {
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
export type
|
|
199
|
+
export type AnalyzedGenResult =
|
|
200
200
|
| {
|
|
201
|
-
file:
|
|
201
|
+
file: GenFile;
|
|
202
202
|
existing_content: string;
|
|
203
203
|
is_new: false;
|
|
204
204
|
has_changed: boolean;
|
|
205
205
|
}
|
|
206
206
|
| {
|
|
207
|
-
file:
|
|
207
|
+
file: GenFile;
|
|
208
208
|
existing_content: null;
|
|
209
209
|
is_new: true;
|
|
210
210
|
has_changed: true;
|
|
211
211
|
};
|
|
212
212
|
|
|
213
213
|
export const analyze_gen_results = (
|
|
214
|
-
gen_results:
|
|
215
|
-
): Promise<Array<
|
|
214
|
+
gen_results: GenResults,
|
|
215
|
+
): Promise<Array<AnalyzedGenResult>> =>
|
|
216
216
|
Promise.all(
|
|
217
217
|
gen_results.successes
|
|
218
218
|
.map((result) => result.files.map((file) => analyze_gen_result(file)))
|
|
219
219
|
.flat(),
|
|
220
220
|
);
|
|
221
221
|
|
|
222
|
-
export const analyze_gen_result = async (file:
|
|
222
|
+
export const analyze_gen_result = async (file: GenFile): Promise<AnalyzedGenResult> => {
|
|
223
223
|
if (!existsSync(file.id)) {
|
|
224
224
|
return {
|
|
225
225
|
file,
|
|
@@ -238,8 +238,8 @@ export const analyze_gen_result = async (file: Gen_File): Promise<Analyzed_Gen_R
|
|
|
238
238
|
};
|
|
239
239
|
|
|
240
240
|
export const write_gen_results = async (
|
|
241
|
-
gen_results:
|
|
242
|
-
analyzed_gen_results: Array<
|
|
241
|
+
gen_results: GenResults,
|
|
242
|
+
analyzed_gen_results: Array<AnalyzedGenResult>,
|
|
243
243
|
log: Logger,
|
|
244
244
|
): Promise<void> => {
|
|
245
245
|
await Promise.all(
|
|
@@ -265,26 +265,26 @@ export const write_gen_results = async (
|
|
|
265
265
|
);
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
-
export interface
|
|
269
|
-
resolved_input_files: Array<
|
|
270
|
-
resolved_input_files_by_root_dir: Map<
|
|
271
|
-
resolved_input_paths: Array<
|
|
268
|
+
export interface FoundGenfiles {
|
|
269
|
+
resolved_input_files: Array<ResolvedInputFile>;
|
|
270
|
+
resolved_input_files_by_root_dir: Map<PathId, Array<ResolvedInputFile>>;
|
|
271
|
+
resolved_input_paths: Array<ResolvedInputPath>;
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
export type
|
|
275
|
-
export type
|
|
274
|
+
export type FindGenfilesResult = Result<{value: FoundGenfiles}, FindGenfilesFailure>;
|
|
275
|
+
export type FindGenfilesFailure =
|
|
276
276
|
| {
|
|
277
277
|
type: 'unmapped_input_paths';
|
|
278
|
-
unmapped_input_paths: Array<
|
|
279
|
-
resolved_input_paths: Array<
|
|
278
|
+
unmapped_input_paths: Array<InputPath>;
|
|
279
|
+
resolved_input_paths: Array<ResolvedInputPath>;
|
|
280
280
|
reasons: Array<string>;
|
|
281
281
|
}
|
|
282
282
|
| {
|
|
283
283
|
type: 'input_directories_with_no_files';
|
|
284
|
-
input_directories_with_no_files: Array<
|
|
285
|
-
resolved_input_files: Array<
|
|
286
|
-
resolved_input_files_by_root_dir: Map<
|
|
287
|
-
resolved_input_paths: Array<
|
|
284
|
+
input_directories_with_no_files: Array<InputPath>;
|
|
285
|
+
resolved_input_files: Array<ResolvedInputFile>;
|
|
286
|
+
resolved_input_files_by_root_dir: Map<PathId, Array<ResolvedInputFile>>;
|
|
287
|
+
resolved_input_paths: Array<ResolvedInputPath>;
|
|
288
288
|
reasons: Array<string>;
|
|
289
289
|
};
|
|
290
290
|
|
|
@@ -292,11 +292,11 @@ export type Find_Genfiles_Failure =
|
|
|
292
292
|
* Finds modules from input paths. (see `src/lib/input_path.ts` for more)
|
|
293
293
|
*/
|
|
294
294
|
export const find_genfiles = (
|
|
295
|
-
input_paths: Array<
|
|
296
|
-
root_dirs: Array<
|
|
297
|
-
config:
|
|
295
|
+
input_paths: Array<InputPath>,
|
|
296
|
+
root_dirs: Array<PathId>,
|
|
297
|
+
config: GroConfig,
|
|
298
298
|
timings?: Timings,
|
|
299
|
-
):
|
|
299
|
+
): FindGenfilesResult => {
|
|
300
300
|
const extensions: Array<string> = [GEN_FILE_PATTERN];
|
|
301
301
|
|
|
302
302
|
// Check which extension variation works - if it's a directory, prefer others first!
|
|
@@ -357,28 +357,28 @@ export const find_genfiles = (
|
|
|
357
357
|
};
|
|
358
358
|
};
|
|
359
359
|
|
|
360
|
-
export interface
|
|
360
|
+
export interface GenfileModule {
|
|
361
361
|
gen: Gen;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
-
export type
|
|
364
|
+
export type GenfileModuleMeta = ModuleMeta<GenfileModule>;
|
|
365
365
|
|
|
366
|
-
export interface
|
|
367
|
-
modules: Array<
|
|
368
|
-
found_genfiles:
|
|
366
|
+
export interface LoadedGenfiles {
|
|
367
|
+
modules: Array<GenfileModuleMeta>;
|
|
368
|
+
found_genfiles: FoundGenfiles;
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
export type
|
|
372
|
-
export type
|
|
371
|
+
export type LoadGenfilesResult = Result<{value: LoadedGenfiles}, LoadGenfilesFailure>;
|
|
372
|
+
export type LoadGenfilesFailure = LoadModulesFailure<GenfileModuleMeta>;
|
|
373
373
|
|
|
374
374
|
export const load_genfiles = async (
|
|
375
|
-
found_genfiles:
|
|
375
|
+
found_genfiles: FoundGenfiles,
|
|
376
376
|
timings?: Timings,
|
|
377
|
-
): Promise<
|
|
377
|
+
): Promise<LoadGenfilesResult> => {
|
|
378
378
|
const loaded_modules = await load_modules(
|
|
379
379
|
found_genfiles.resolved_input_files,
|
|
380
380
|
validate_gen_module,
|
|
381
|
-
(resolved_input_file, mod):
|
|
381
|
+
(resolved_input_file, mod): GenfileModuleMeta => ({id: resolved_input_file.id, mod}),
|
|
382
382
|
timings,
|
|
383
383
|
);
|
|
384
384
|
if (!loaded_modules.ok) {
|
|
@@ -390,7 +390,7 @@ export const load_genfiles = async (
|
|
|
390
390
|
};
|
|
391
391
|
};
|
|
392
392
|
|
|
393
|
-
export const validate_gen_module = (mod: Record<string, any>): mod is
|
|
393
|
+
export const validate_gen_module = (mod: Record<string, any>): mod is GenfileModule => {
|
|
394
394
|
if (typeof mod.gen === 'function') return true;
|
|
395
395
|
if (typeof mod.gen === 'object' && mod.gen !== null && typeof mod.gen.generate === 'function') {
|
|
396
396
|
return true;
|
|
@@ -398,5 +398,5 @@ export const validate_gen_module = (mod: Record<string, any>): mod is Genfile_Mo
|
|
|
398
398
|
return false;
|
|
399
399
|
};
|
|
400
400
|
|
|
401
|
-
export const normalize_gen_config = (gen: Gen):
|
|
401
|
+
export const normalize_gen_config = (gen: Gen): GenConfig =>
|
|
402
402
|
typeof gen === 'function' ? {generate: gen} : gen;
|
package/src/lib/gen_helpers.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {resolve} from 'node:path';
|
|
2
2
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
3
3
|
import type {Timings} from '@ryanatkn/belt/timings.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type {PathId} from '@ryanatkn/belt/path.js';
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type {GroConfig} from './gro_config.ts';
|
|
7
7
|
import {filter_dependents, type Filer} from './filer.ts';
|
|
8
|
-
import type {
|
|
8
|
+
import type {InvokeTask} from './task.ts';
|
|
9
9
|
import {
|
|
10
10
|
normalize_gen_config,
|
|
11
11
|
validate_gen_module,
|
|
12
|
-
type
|
|
13
|
-
type
|
|
14
|
-
type
|
|
12
|
+
type GenContext,
|
|
13
|
+
type GenDependencies,
|
|
14
|
+
type GenDependenciesConfig,
|
|
15
15
|
} from './gen.ts';
|
|
16
16
|
import {default_svelte_config} from './svelte_config.ts';
|
|
17
17
|
import {to_root_path} from './paths.ts';
|
|
@@ -21,13 +21,13 @@ import {load_module} from './modules.ts';
|
|
|
21
21
|
* Check if a file change should trigger a gen file.
|
|
22
22
|
*/
|
|
23
23
|
export const should_trigger_gen = async (
|
|
24
|
-
gen_file_id:
|
|
25
|
-
changed_file_id:
|
|
26
|
-
config:
|
|
24
|
+
gen_file_id: PathId,
|
|
25
|
+
changed_file_id: PathId,
|
|
26
|
+
config: GroConfig,
|
|
27
27
|
filer: Filer,
|
|
28
28
|
log: Logger,
|
|
29
29
|
timings: Timings,
|
|
30
|
-
invoke_task:
|
|
30
|
+
invoke_task: InvokeTask,
|
|
31
31
|
): Promise<boolean> => {
|
|
32
32
|
// Always trigger if the gen file itself changed
|
|
33
33
|
const is_self_change = gen_file_id === changed_file_id;
|
|
@@ -74,14 +74,14 @@ export const should_trigger_gen = async (
|
|
|
74
74
|
*/
|
|
75
75
|
const resolve_gen_dependencies = async (
|
|
76
76
|
gen_file_id: string,
|
|
77
|
-
changed_file_id:
|
|
77
|
+
changed_file_id: PathId | undefined,
|
|
78
78
|
bust_cache: boolean,
|
|
79
|
-
config:
|
|
79
|
+
config: GroConfig,
|
|
80
80
|
filer: Filer,
|
|
81
81
|
log: Logger,
|
|
82
82
|
timings: Timings,
|
|
83
|
-
invoke_task:
|
|
84
|
-
): Promise<
|
|
83
|
+
invoke_task: InvokeTask,
|
|
84
|
+
): Promise<GenDependenciesConfig | 'all' | null> => {
|
|
85
85
|
const result = await load_module(gen_file_id, validate_gen_module, bust_cache);
|
|
86
86
|
|
|
87
87
|
if (!result.ok) {
|
|
@@ -96,9 +96,9 @@ const resolve_gen_dependencies = async (
|
|
|
96
96
|
return null;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
let dependencies:
|
|
99
|
+
let dependencies: GenDependencies | null = gen_config.dependencies;
|
|
100
100
|
if (typeof dependencies === 'function') {
|
|
101
|
-
const gen_ctx:
|
|
101
|
+
const gen_ctx: GenContext = {
|
|
102
102
|
config,
|
|
103
103
|
svelte_config: default_svelte_config,
|
|
104
104
|
filer,
|
|
@@ -116,7 +116,7 @@ const resolve_gen_dependencies = async (
|
|
|
116
116
|
return dependencies;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
// At this point, dependencies is either 'all' or
|
|
119
|
+
// At this point, dependencies is either 'all' or GenDependenciesConfig
|
|
120
120
|
// For static dependencies, also normalize empty objects
|
|
121
121
|
if (!dependencies.patterns?.length && !dependencies.files?.length) {
|
|
122
122
|
return null;
|
package/src/lib/github.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// for now it's just calling a single endpoint so we do it manually
|
|
3
3
|
// and we specify just the types we need
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {FetchValueCache, fetch_value} from '@ryanatkn/belt/fetch.js';
|
|
6
6
|
import type {Logger} from '@ryanatkn/belt/log.js';
|
|
7
7
|
import {z} from 'zod';
|
|
8
8
|
|
|
9
9
|
export const GITHUB_REPO_MATCHER = /.+github.com\/(.+)\/(.+)/;
|
|
10
10
|
|
|
11
|
-
export const
|
|
11
|
+
export const GithubPullRequest = z.looseObject({
|
|
12
12
|
url: z.string(),
|
|
13
13
|
id: z.number(),
|
|
14
14
|
html_url: z.string(),
|
|
@@ -17,7 +17,7 @@ export const Github_Pull_Request = z.looseObject({
|
|
|
17
17
|
login: z.string(),
|
|
18
18
|
}),
|
|
19
19
|
});
|
|
20
|
-
export type
|
|
20
|
+
export type GithubPullRequest = z.infer<typeof GithubPullRequest>;
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* @see https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-pull-requests-associated-with-a-commit
|
|
@@ -28,14 +28,14 @@ export const github_fetch_commit_prs = async (
|
|
|
28
28
|
commit_sha: string,
|
|
29
29
|
token?: string,
|
|
30
30
|
log?: Logger,
|
|
31
|
-
cache?:
|
|
31
|
+
cache?: FetchValueCache,
|
|
32
32
|
api_version?: string,
|
|
33
|
-
): Promise<Array<
|
|
33
|
+
): Promise<Array<GithubPullRequest> | null> => {
|
|
34
34
|
const headers = api_version ? new Headers({'x-github-api-version': api_version}) : undefined;
|
|
35
35
|
const url = `https://api.github.com/repos/${owner}/${repo}/commits/${commit_sha}/pulls`;
|
|
36
36
|
const fetched = await fetch_value(url, {
|
|
37
37
|
request: {headers},
|
|
38
|
-
parse: (v: Array<any>) => v.map((p) =>
|
|
38
|
+
parse: (v: Array<any>) => v.map((p) => GithubPullRequest.parse(p)),
|
|
39
39
|
token,
|
|
40
40
|
cache,
|
|
41
41
|
return_early_from_cache: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {CreateGroConfig} from './gro_config.ts';
|
|
2
2
|
import {gro_plugin_sveltekit_library} from './gro_plugin_sveltekit_library.ts';
|
|
3
3
|
import {has_server, gro_plugin_server} from './gro_plugin_server.ts';
|
|
4
4
|
import {gro_plugin_sveltekit_app} from './gro_plugin_sveltekit_app.ts';
|
|
@@ -17,7 +17,7 @@ import {load_package_json} from './package_json.ts';
|
|
|
17
17
|
* - if `src/lib`, assumes a Node library - respects `KitConfig.kit.files.lib`
|
|
18
18
|
* - if `src/lib/server/server.ts`, assumes a Node server - needs config
|
|
19
19
|
*/
|
|
20
|
-
const config:
|
|
20
|
+
const config: CreateGroConfig = async (cfg, svelte_config) => {
|
|
21
21
|
const package_json = load_package_json(); // TODO gets wastefully loaded by some plugins, maybe put in plugin/task context? how does that interact with `map_package_json`?
|
|
22
22
|
|
|
23
23
|
const [has_server_result, has_sveltekit_library_result, has_sveltekit_app_result] =
|
package/src/lib/gro_config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {join, resolve} from 'node:path';
|
|
2
2
|
import {existsSync} from 'node:fs';
|
|
3
3
|
import {identity} from '@ryanatkn/belt/function.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type {PathFilter, PathId} from '@ryanatkn/belt/path.js';
|
|
5
5
|
import {json_stringify_deterministic} from '@ryanatkn/belt/json.js';
|
|
6
6
|
|
|
7
7
|
import {GRO_DIST_DIR, IS_THIS_GRO, paths} from './paths.ts';
|
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
SVELTEKIT_DIST_DIRNAME,
|
|
16
16
|
} from './constants.ts';
|
|
17
17
|
import create_default_config from './gro.config.default.ts';
|
|
18
|
-
import type {
|
|
19
|
-
import type {
|
|
20
|
-
import type {
|
|
18
|
+
import type {CreateConfigPlugins} from './plugin.ts';
|
|
19
|
+
import type {PackageJsonMapper} from './package_json.ts';
|
|
20
|
+
import type {ParsedSvelteConfig} from './svelte_config.ts';
|
|
21
21
|
import {to_hash} from './hash.ts';
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -32,27 +32,27 @@ export const EMPTY_BUILD_CACHE_CONFIG_HASH =
|
|
|
32
32
|
* This is exposed to users in places like tasks and genfiles.
|
|
33
33
|
* @see https://github.com/ryanatkn/gro/blob/main/src/docs/config.md
|
|
34
34
|
*/
|
|
35
|
-
export interface
|
|
35
|
+
export interface GroConfig extends RawGroConfig {
|
|
36
36
|
/**
|
|
37
37
|
* @see https://github.com/ryanatkn/gro/blob/main/src/docs/plugin.md
|
|
38
38
|
*/
|
|
39
|
-
plugins:
|
|
39
|
+
plugins: CreateConfigPlugins;
|
|
40
40
|
/**
|
|
41
41
|
* Maps the project's `package.json` before writing it to the filesystem.
|
|
42
42
|
* The `package_json` argument may be mutated, but the return value is what's used by the caller.
|
|
43
43
|
* Returning `null` is a no-op for the caller.
|
|
44
44
|
*/
|
|
45
|
-
map_package_json:
|
|
45
|
+
map_package_json: PackageJsonMapper | null;
|
|
46
46
|
/**
|
|
47
47
|
* The root directories to search for tasks given implicit relative input paths.
|
|
48
48
|
* Defaults to `./src/lib`, then the cwd, then the Gro package dist.
|
|
49
49
|
*/
|
|
50
|
-
task_root_dirs: Array<
|
|
50
|
+
task_root_dirs: Array<PathId>;
|
|
51
51
|
/**
|
|
52
52
|
* When searching the filsystem for tasks and genfiles,
|
|
53
53
|
* directories and files are included if they pass all of these filters.
|
|
54
54
|
*/
|
|
55
|
-
search_filters: Array<
|
|
55
|
+
search_filters: Array<PathFilter>;
|
|
56
56
|
/**
|
|
57
57
|
* The CLI to use that's compatible with `node`.
|
|
58
58
|
*/
|
|
@@ -67,21 +67,21 @@ export interface Gro_Config extends Raw_Gro_Config {
|
|
|
67
67
|
* SHA-256 hash of the user's `build_cache_config` from `gro.config.ts`.
|
|
68
68
|
* This is computed during config normalization and the raw value is immediately deleted.
|
|
69
69
|
* If no `build_cache_config` was provided, this is the hash of an empty string.
|
|
70
|
-
* @see
|
|
70
|
+
* @see RawGroConfig.build_cache_config
|
|
71
71
|
*/
|
|
72
72
|
build_cache_config_hash: string;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* The relaxed variant of `
|
|
77
|
-
* Superset of `
|
|
76
|
+
* The relaxed variant of `GroConfig` that users can provide via `gro.config.ts`.
|
|
77
|
+
* Superset of `GroConfig`.
|
|
78
78
|
* @see https://github.com/ryanatkn/gro/blob/main/src/docs/config.md
|
|
79
79
|
*/
|
|
80
|
-
export interface
|
|
81
|
-
plugins?:
|
|
82
|
-
map_package_json?:
|
|
80
|
+
export interface RawGroConfig {
|
|
81
|
+
plugins?: CreateConfigPlugins;
|
|
82
|
+
map_package_json?: PackageJsonMapper | null;
|
|
83
83
|
task_root_dirs?: Array<string>;
|
|
84
|
-
search_filters?:
|
|
84
|
+
search_filters?: PathFilter | Array<PathFilter> | null;
|
|
85
85
|
js_cli?: string;
|
|
86
86
|
pm_cli?: string;
|
|
87
87
|
/**
|
|
@@ -104,12 +104,12 @@ export interface Raw_Gro_Config {
|
|
|
104
104
|
| (() => Record<string, unknown> | Promise<Record<string, unknown>>);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export type
|
|
108
|
-
base_config:
|
|
109
|
-
svelte_config?:
|
|
110
|
-
) =>
|
|
107
|
+
export type CreateGroConfig = (
|
|
108
|
+
base_config: GroConfig,
|
|
109
|
+
svelte_config?: ParsedSvelteConfig,
|
|
110
|
+
) => RawGroConfig | Promise<RawGroConfig>;
|
|
111
111
|
|
|
112
|
-
export const create_empty_gro_config = ():
|
|
112
|
+
export const create_empty_gro_config = (): GroConfig => ({
|
|
113
113
|
plugins: () => [],
|
|
114
114
|
map_package_json: identity,
|
|
115
115
|
task_root_dirs: [
|
|
@@ -127,7 +127,7 @@ export const create_empty_gro_config = (): Gro_Config => ({
|
|
|
127
127
|
/**
|
|
128
128
|
* The regexp used by default to exclude directories and files
|
|
129
129
|
* when searching the filesystem for tasks and genfiles.
|
|
130
|
-
* Customize via `search_filters` in the `
|
|
130
|
+
* Customize via `search_filters` in the `GroConfig`.
|
|
131
131
|
* See the test cases for the exact behavior.
|
|
132
132
|
*/
|
|
133
133
|
export const SEARCH_EXCLUDER_DEFAULT = new RegExp(
|
|
@@ -145,11 +145,11 @@ export const SEARCH_EXCLUDER_DEFAULT = new RegExp(
|
|
|
145
145
|
export const EXPORTS_EXCLUDER_DEFAULT = /(\.md|\.(test|ignore)\.|\/(test|ignore)\/)/;
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
* Transforms a `
|
|
148
|
+
* Transforms a `RawGroConfig` to the more strict `GroConfig`.
|
|
149
149
|
* This allows users to provide a more relaxed config.
|
|
150
150
|
* Hashes the `build_cache_config` and deletes the raw value for security.
|
|
151
151
|
*/
|
|
152
|
-
export const cook_gro_config = async (raw_config:
|
|
152
|
+
export const cook_gro_config = async (raw_config: RawGroConfig): Promise<GroConfig> => {
|
|
153
153
|
const empty_config = create_empty_gro_config();
|
|
154
154
|
|
|
155
155
|
// All of the raw config properties are optional,
|
|
@@ -198,11 +198,11 @@ export const cook_gro_config = async (raw_config: Raw_Gro_Config): Promise<Gro_C
|
|
|
198
198
|
};
|
|
199
199
|
};
|
|
200
200
|
|
|
201
|
-
export interface
|
|
202
|
-
readonly default:
|
|
201
|
+
export interface GroConfigModule {
|
|
202
|
+
readonly default: RawGroConfig | CreateGroConfig;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
export const load_gro_config = async (dir = paths.root): Promise<
|
|
205
|
+
export const load_gro_config = async (dir = paths.root): Promise<GroConfig> => {
|
|
206
206
|
const default_config = await cook_gro_config(
|
|
207
207
|
await create_default_config(create_empty_gro_config()),
|
|
208
208
|
);
|
|
@@ -228,7 +228,7 @@ export const load_gro_config = async (dir = paths.root): Promise<Gro_Config> =>
|
|
|
228
228
|
export const validate_gro_config_module: (
|
|
229
229
|
config_module: any,
|
|
230
230
|
config_path: string,
|
|
231
|
-
) => asserts config_module is
|
|
231
|
+
) => asserts config_module is GroConfigModule = (config_module, config_path) => {
|
|
232
232
|
const config = config_module.default;
|
|
233
233
|
if (!config) {
|
|
234
234
|
throw Error(`Invalid Gro config module at ${config_path}: expected a default export`);
|
package/src/lib/gro_helpers.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {realpathSync, existsSync} from 'node:fs';
|
|
2
2
|
import {join, resolve} from 'node:path';
|
|
3
3
|
import {fileURLToPath} from 'node:url';
|
|
4
|
-
import {spawn, type
|
|
4
|
+
import {spawn, type SpawnResult} from '@ryanatkn/belt/process.js';
|
|
5
5
|
|
|
6
6
|
import {JS_CLI_DEFAULT, NODE_MODULES_DIRNAME, SVELTEKIT_DIST_DIRNAME} from './constants.ts';
|
|
7
7
|
|
|
@@ -85,7 +85,7 @@ export const spawn_with_loader = (
|
|
|
85
85
|
invoke_path: string,
|
|
86
86
|
argv: Array<string>,
|
|
87
87
|
js_cli = JS_CLI_DEFAULT, // TODO source from config when possible
|
|
88
|
-
): Promise<
|
|
88
|
+
): Promise<SpawnResult> => {
|
|
89
89
|
const args = [
|
|
90
90
|
'--import',
|
|
91
91
|
// This does the same as `$lib/register.ts` but without the cost of importing another file.
|