@ryanatkn/gro 0.112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +257 -0
- package/dist/args.d.ts +59 -0
- package/dist/args.js +132 -0
- package/dist/args.test.d.ts +1 -0
- package/dist/args.test.js +43 -0
- package/dist/build.task.d.ts +11 -0
- package/dist/build.task.js +24 -0
- package/dist/changelog.d.ts +8 -0
- package/dist/changelog.js +47 -0
- package/dist/changelog.test.d.ts +1 -0
- package/dist/changelog.test.js +118 -0
- package/dist/changeset.task.d.ts +49 -0
- package/dist/changeset.task.js +141 -0
- package/dist/check.task.d.ts +47 -0
- package/dist/check.task.js +77 -0
- package/dist/clean.task.d.ts +26 -0
- package/dist/clean.task.js +41 -0
- package/dist/clean_fs.d.ts +9 -0
- package/dist/clean_fs.js +27 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +25 -0
- package/dist/commit.task.d.ts +11 -0
- package/dist/commit.task.js +22 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +42 -0
- package/dist/config.test.d.ts +1 -0
- package/dist/config.test.js +8 -0
- package/dist/deploy.task.d.ts +47 -0
- package/dist/deploy.task.js +198 -0
- package/dist/dev.task.d.ts +22 -0
- package/dist/dev.task.js +32 -0
- package/dist/docs/README.gen.md.d.ts +5 -0
- package/dist/docs/README.gen.md.js +53 -0
- package/dist/docs/README.md +20 -0
- package/dist/docs/build.md +41 -0
- package/dist/docs/config.md +162 -0
- package/dist/docs/deploy.md +32 -0
- package/dist/docs/dev.md +40 -0
- package/dist/docs/gen.md +241 -0
- package/dist/docs/gro_plugin_sveltekit_frontend.md +97 -0
- package/dist/docs/package_json.md +29 -0
- package/dist/docs/plugin.md +50 -0
- package/dist/docs/publish.md +144 -0
- package/dist/docs/task.md +377 -0
- package/dist/docs/tasks.gen.md.d.ts +2 -0
- package/dist/docs/tasks.gen.md.js +60 -0
- package/dist/docs/tasks.md +35 -0
- package/dist/docs/test.md +52 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +47 -0
- package/dist/esbuild_helpers.d.ts +14 -0
- package/dist/esbuild_helpers.js +36 -0
- package/dist/esbuild_plugin_external_worker.d.ts +22 -0
- package/dist/esbuild_plugin_external_worker.js +49 -0
- package/dist/esbuild_plugin_svelte.d.ts +9 -0
- package/dist/esbuild_plugin_svelte.js +49 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.d.ts +7 -0
- package/dist/esbuild_plugin_sveltekit_local_imports.js +30 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.d.ts +6 -0
- package/dist/esbuild_plugin_sveltekit_shim_alias.js +16 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.d.ts +8 -0
- package/dist/esbuild_plugin_sveltekit_shim_app.js +23 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.d.ts +10 -0
- package/dist/esbuild_plugin_sveltekit_shim_env.js +18 -0
- package/dist/format.task.d.ts +11 -0
- package/dist/format.task.js +24 -0
- package/dist/format_directory.d.ts +2 -0
- package/dist/format_directory.js +27 -0
- package/dist/format_file.d.ts +8 -0
- package/dist/format_file.js +42 -0
- package/dist/format_file.test.d.ts +1 -0
- package/dist/format_file.test.js +16 -0
- package/dist/fs.d.ts +7 -0
- package/dist/fs.js +19 -0
- package/dist/fs.test.d.ts +1 -0
- package/dist/fs.test.js +16 -0
- package/dist/gen.d.ts +57 -0
- package/dist/gen.js +81 -0
- package/dist/gen.task.d.ts +14 -0
- package/dist/gen.task.js +103 -0
- package/dist/gen.test.d.ts +1 -0
- package/dist/gen.test.js +239 -0
- package/dist/gen_module.d.ts +46 -0
- package/dist/gen_module.js +54 -0
- package/dist/gen_module.test.d.ts +1 -0
- package/dist/gen_module.test.js +30 -0
- package/dist/git.d.ts +76 -0
- package/dist/git.js +200 -0
- package/dist/git.test.d.ts +1 -0
- package/dist/git.test.js +18 -0
- package/dist/github.d.ts +35 -0
- package/dist/github.js +32 -0
- package/dist/gro.config.default.d.ts +12 -0
- package/dist/gro.config.default.js +31 -0
- package/dist/gro.d.ts +2 -0
- package/dist/gro.js +19 -0
- package/dist/gro_helpers.d.ts +43 -0
- package/dist/gro_helpers.js +79 -0
- package/dist/gro_plugin_gen.d.ts +6 -0
- package/dist/gro_plugin_gen.js +80 -0
- package/dist/gro_plugin_server.d.ts +77 -0
- package/dist/gro_plugin_server.js +152 -0
- package/dist/gro_plugin_sveltekit_app.d.ts +27 -0
- package/dist/gro_plugin_sveltekit_app.js +180 -0
- package/dist/gro_plugin_sveltekit_library.d.ts +4 -0
- package/dist/gro_plugin_sveltekit_library.js +42 -0
- package/dist/hash.d.ts +5 -0
- package/dist/hash.js +14 -0
- package/dist/hash.test.d.ts +1 -0
- package/dist/hash.test.js +25 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/input_path.d.ts +48 -0
- package/dist/input_path.js +161 -0
- package/dist/input_path.test.d.ts +1 -0
- package/dist/input_path.test.js +106 -0
- package/dist/invoke.d.ts +1 -0
- package/dist/invoke.js +18 -0
- package/dist/invoke_task.d.ts +20 -0
- package/dist/invoke_task.js +140 -0
- package/dist/lint.task.d.ts +11 -0
- package/dist/lint.task.js +29 -0
- package/dist/loader.d.ts +4 -0
- package/dist/loader.js +153 -0
- package/dist/module.d.ts +3 -0
- package/dist/module.js +6 -0
- package/dist/module.test.d.ts +1 -0
- package/dist/module.test.js +41 -0
- package/dist/modules.d.ts +60 -0
- package/dist/modules.js +103 -0
- package/dist/modules.test.d.ts +1 -0
- package/dist/modules.test.js +182 -0
- package/dist/package.d.ts +939 -0
- package/dist/package.gen.d.ts +7 -0
- package/dist/package.gen.js +26 -0
- package/dist/package.js +887 -0
- package/dist/package_json.d.ts +342 -0
- package/dist/package_json.js +212 -0
- package/dist/package_json.test.d.ts +1 -0
- package/dist/package_json.test.js +77 -0
- package/dist/path.d.ts +12 -0
- package/dist/path.js +8 -0
- package/dist/paths.d.ts +60 -0
- package/dist/paths.js +128 -0
- package/dist/paths.test.d.ts +1 -0
- package/dist/paths.test.js +49 -0
- package/dist/plugin.d.ts +36 -0
- package/dist/plugin.js +80 -0
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.js +54 -0
- package/dist/print_task.d.ts +4 -0
- package/dist/print_task.js +124 -0
- package/dist/publish.task.d.ts +32 -0
- package/dist/publish.task.js +125 -0
- package/dist/release.task.d.ts +5 -0
- package/dist/release.task.js +18 -0
- package/dist/resolve_node_specifier.d.ts +8 -0
- package/dist/resolve_node_specifier.js +39 -0
- package/dist/resolve_node_specifier.test.d.ts +1 -0
- package/dist/resolve_node_specifier.test.js +21 -0
- package/dist/resolve_specifier.d.ts +15 -0
- package/dist/resolve_specifier.js +51 -0
- package/dist/resolve_specifier.test.d.ts +1 -0
- package/dist/resolve_specifier.test.js +66 -0
- package/dist/run.task.d.ts +11 -0
- package/dist/run.task.js +31 -0
- package/dist/run_gen.d.ts +6 -0
- package/dist/run_gen.js +74 -0
- package/dist/run_gen.test.d.ts +1 -0
- package/dist/run_gen.test.js +182 -0
- package/dist/run_task.d.ts +13 -0
- package/dist/run_task.js +44 -0
- package/dist/run_task.test.d.ts +1 -0
- package/dist/run_task.test.js +63 -0
- package/dist/search_fs.d.ts +11 -0
- package/dist/search_fs.js +22 -0
- package/dist/search_fs.test.d.ts +1 -0
- package/dist/search_fs.test.js +46 -0
- package/dist/src_json.d.ts +256 -0
- package/dist/src_json.js +110 -0
- package/dist/src_json.test.d.ts +1 -0
- package/dist/src_json.test.js +52 -0
- package/dist/sveltekit_config.d.ts +36 -0
- package/dist/sveltekit_config.js +51 -0
- package/dist/sveltekit_shim_app.d.ts +10 -0
- package/dist/sveltekit_shim_app.js +31 -0
- package/dist/sveltekit_shim_app_environment.d.ts +10 -0
- package/dist/sveltekit_shim_app_environment.js +12 -0
- package/dist/sveltekit_shim_app_forms.d.ts +5 -0
- package/dist/sveltekit_shim_app_forms.js +13 -0
- package/dist/sveltekit_shim_app_navigation.d.ts +10 -0
- package/dist/sveltekit_shim_app_navigation.js +11 -0
- package/dist/sveltekit_shim_app_paths.d.ts +11 -0
- package/dist/sveltekit_shim_app_paths.js +6 -0
- package/dist/sveltekit_shim_app_stores.d.ts +6 -0
- package/dist/sveltekit_shim_app_stores.js +17 -0
- package/dist/sveltekit_shim_env.d.ts +4 -0
- package/dist/sveltekit_shim_env.js +23 -0
- package/dist/sync.task.d.ts +30 -0
- package/dist/sync.task.js +45 -0
- package/dist/task.d.ts +29 -0
- package/dist/task.js +17 -0
- package/dist/task.test.d.ts +1 -0
- package/dist/task.test.js +22 -0
- package/dist/task_module.d.ts +14 -0
- package/dist/task_module.js +19 -0
- package/dist/task_module.test.d.ts +1 -0
- package/dist/task_module.test.js +70 -0
- package/dist/test.task.d.ts +20 -0
- package/dist/test.task.js +43 -0
- package/dist/throttle.d.ts +16 -0
- package/dist/throttle.js +59 -0
- package/dist/throttle.test.d.ts +1 -0
- package/dist/throttle.test.js +49 -0
- package/dist/typecheck.task.d.ts +5 -0
- package/dist/typecheck.task.js +38 -0
- package/dist/upgrade.task.d.ts +14 -0
- package/dist/upgrade.task.js +37 -0
- package/dist/watch_dir.d.ts +30 -0
- package/dist/watch_dir.js +59 -0
- package/package.json +422 -0
package/dist/src_json.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { strip_start } from '@ryanatkn/belt/string.js';
|
|
4
|
+
import { Project } from 'ts-morph';
|
|
5
|
+
import { paths, replace_extension } from './paths.js';
|
|
6
|
+
import { exists } from './fs.js';
|
|
7
|
+
import { transform_empty_object_to_undefined, } from './package_json.js';
|
|
8
|
+
export const Src_Module_Declaration = z
|
|
9
|
+
.object({
|
|
10
|
+
name: z.string(), // the export identifier
|
|
11
|
+
// TODO these are poorly named, and they're somewhat redundant with `kind`,
|
|
12
|
+
// they were added to distinguish `VariableDeclaration` functions and non-functions
|
|
13
|
+
kind: z.enum(['type', 'function', 'variable', 'class']).nullable(),
|
|
14
|
+
// code: z.string(), // TODO experiment with `getType().getText()`, some of them return the same as `name`
|
|
15
|
+
})
|
|
16
|
+
.passthrough();
|
|
17
|
+
export const Src_Module = z
|
|
18
|
+
.object({
|
|
19
|
+
path: z.string(),
|
|
20
|
+
declarations: z.array(Src_Module_Declaration),
|
|
21
|
+
})
|
|
22
|
+
.passthrough();
|
|
23
|
+
export const Src_Modules = z.record(Src_Module);
|
|
24
|
+
/**
|
|
25
|
+
* @see https://github.com/ryanatkn/gro/blob/main/src/lib/docs/gro_plugin_sveltekit_app.md#well-known-src
|
|
26
|
+
*/
|
|
27
|
+
export const Src_Json = z.intersection(z.record(z.unknown()), // TODO is this what we want?
|
|
28
|
+
z
|
|
29
|
+
.object({
|
|
30
|
+
name: z.string(), // same as Package_Json
|
|
31
|
+
version: z.string(), // same as Package_Json
|
|
32
|
+
modules: Src_Modules.transform(transform_empty_object_to_undefined).optional(),
|
|
33
|
+
})
|
|
34
|
+
.passthrough());
|
|
35
|
+
export const create_src_json = async (package_json, log, lib_path) => {
|
|
36
|
+
return Src_Json.parse({
|
|
37
|
+
name: package_json.name,
|
|
38
|
+
version: package_json.version,
|
|
39
|
+
modules: await to_src_modules(package_json.exports, log, lib_path),
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
export const serialize_src_json = (src_json) => {
|
|
43
|
+
const parsed = Src_Json.parse(src_json); // TODO can parse do the logic that normalize does? see `.transform`
|
|
44
|
+
return JSON.stringify(parsed, null, 2) + '\n';
|
|
45
|
+
};
|
|
46
|
+
export const to_src_modules = async (exports, log, lib_path = paths.lib) => {
|
|
47
|
+
if (!exports)
|
|
48
|
+
return undefined;
|
|
49
|
+
const project = new Project();
|
|
50
|
+
project.addSourceFilesAtPaths('src/**/*.ts'); // TODO dir? maybe rewrite with `lib_path`?
|
|
51
|
+
return Object.fromEntries((await Promise.all(Object.entries(exports).map(async ([k, _v]) => {
|
|
52
|
+
// TODO hacky - doesn't handle any but the normal mappings, also add a helper?
|
|
53
|
+
const source_file_path = k === '.' || k === './'
|
|
54
|
+
? 'index.ts'
|
|
55
|
+
: strip_start(k.endsWith('.js') ? replace_extension(k, '.ts') : k, './');
|
|
56
|
+
if (!source_file_path.endsWith('.ts')) {
|
|
57
|
+
// TODO support more than just TypeScript - maybe use @sveltejs/language-tools,
|
|
58
|
+
// see how @sveltejs/package generates types, or maybe use its generated declaration files with ts-morph
|
|
59
|
+
const src_module = { path: source_file_path, declarations: [] };
|
|
60
|
+
return [k, src_module];
|
|
61
|
+
}
|
|
62
|
+
const source_file_id = join(lib_path, source_file_path);
|
|
63
|
+
if (!(await exists(source_file_id))) {
|
|
64
|
+
log?.warn('failed to infer source file from export path', k, '- the inferred file', source_file_id, 'does not exist');
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const declarations = [];
|
|
68
|
+
const source_file = project.getSourceFile((f) => f.getFilePath().endsWith(source_file_path)); // TODO expected this to work without the callback, according to my read of the docs it is, but `project.getSourceFile(source_file_path)` fails
|
|
69
|
+
if (source_file) {
|
|
70
|
+
for (const [name, decls] of source_file.getExportedDeclarations()) {
|
|
71
|
+
if (!decls)
|
|
72
|
+
continue;
|
|
73
|
+
// TODO how to correctly handle multiples?
|
|
74
|
+
for (const decl of decls) {
|
|
75
|
+
// TODO helper
|
|
76
|
+
const decl_type = decl.getType();
|
|
77
|
+
const k = decl.getKindName();
|
|
78
|
+
const kind = k === 'InterfaceDeclaration' || k === 'TypeAliasDeclaration'
|
|
79
|
+
? 'type'
|
|
80
|
+
: k === 'ClassDeclaration'
|
|
81
|
+
? 'class'
|
|
82
|
+
: k === 'VariableDeclaration'
|
|
83
|
+
? decl_type.getCallSignatures().length
|
|
84
|
+
? 'function'
|
|
85
|
+
: 'variable' // TODO name?
|
|
86
|
+
: null;
|
|
87
|
+
// TODO
|
|
88
|
+
// const code =
|
|
89
|
+
// k === 'InterfaceDeclaration' || k === 'TypeAliasDeclaration'
|
|
90
|
+
// ? decl_type.getText(source_file) // TODO
|
|
91
|
+
// : decl_type.getText(source_file);
|
|
92
|
+
const found = declarations.find((d) => d.name === name);
|
|
93
|
+
if (found) {
|
|
94
|
+
// TODO hacky, this only was added to prevent `TypeAliasDeclaration` from overriding `VariableDeclaration`
|
|
95
|
+
if (found.kind === 'type') {
|
|
96
|
+
found.kind = kind;
|
|
97
|
+
// found.code = code;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// TODO more
|
|
102
|
+
declarations.push({ name, kind }); // code
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const src_module = { path: source_file_path, declarations };
|
|
108
|
+
return [k, src_module];
|
|
109
|
+
}))).filter(Boolean));
|
|
110
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { test } from 'uvu';
|
|
2
|
+
import * as assert from 'uvu/assert';
|
|
3
|
+
import { to_src_modules } from './src_json.js';
|
|
4
|
+
import { to_package_exports } from './package_json.js';
|
|
5
|
+
import { paths } from './paths.js';
|
|
6
|
+
test('to_package_modules', async () => {
|
|
7
|
+
assert.equal(await to_src_modules(to_package_exports([
|
|
8
|
+
'fixtures/modules/some_test_css.css',
|
|
9
|
+
'fixtures/modules/Some_Test_Svelte.svelte',
|
|
10
|
+
'fixtures/modules/some_test_ts.ts',
|
|
11
|
+
'fixtures/modules/some_test_json.json',
|
|
12
|
+
]), undefined, paths.source), {
|
|
13
|
+
'./fixtures/modules/some_test_css.css': {
|
|
14
|
+
path: 'fixtures/modules/some_test_css.css',
|
|
15
|
+
declarations: [],
|
|
16
|
+
},
|
|
17
|
+
'./fixtures/modules/some_test_json.json': {
|
|
18
|
+
path: 'fixtures/modules/some_test_json.json',
|
|
19
|
+
declarations: [],
|
|
20
|
+
},
|
|
21
|
+
'./fixtures/modules/Some_Test_Svelte.svelte': {
|
|
22
|
+
path: 'fixtures/modules/Some_Test_Svelte.svelte',
|
|
23
|
+
declarations: [],
|
|
24
|
+
},
|
|
25
|
+
'./fixtures/modules/some_test_ts.js': {
|
|
26
|
+
path: 'fixtures/modules/some_test_ts.ts',
|
|
27
|
+
declarations: [
|
|
28
|
+
{
|
|
29
|
+
name: 'some_test_ts',
|
|
30
|
+
kind: 'variable',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'some_test_fn',
|
|
34
|
+
kind: 'function',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'Some_Test_Type',
|
|
38
|
+
kind: 'type',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'Some_Test_Interface',
|
|
42
|
+
kind: 'type',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'Some_Test_Class',
|
|
46
|
+
kind: 'class',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
test.run();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="svelte" />
|
|
2
|
+
import type { Config as SveltekitConfig } from '@sveltejs/kit';
|
|
3
|
+
import type { CompileOptions, PreprocessorGroup } from 'svelte/compiler';
|
|
4
|
+
/**
|
|
5
|
+
* Loads a SvelteKit config at `dir`.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const load_sveltekit_config: (dir?: string) => Promise<SveltekitConfig | null>;
|
|
9
|
+
/**
|
|
10
|
+
* A subset of SvelteKit's config in a form that Gro uses
|
|
11
|
+
* because SvelteKit doesn't expose its config resolver.
|
|
12
|
+
* Flattens things out to keep them simple and easy to pass around,
|
|
13
|
+
* and doesn't deal with most properties.
|
|
14
|
+
* The `base` and `assets` in particular are renamed for clarity with Gro's internal systems,
|
|
15
|
+
* so these properties become first-class vocabulary inside Gro.
|
|
16
|
+
*/
|
|
17
|
+
export interface Parsed_Sveltekit_Config {
|
|
18
|
+
sveltekit_config: SveltekitConfig | null;
|
|
19
|
+
alias: Record<string, string> | undefined;
|
|
20
|
+
base_url: '' | `/${string}` | undefined;
|
|
21
|
+
assets_url: '' | `http://${string}` | `https://${string}` | undefined;
|
|
22
|
+
assets_path: string;
|
|
23
|
+
lib_path: string;
|
|
24
|
+
routes_path: string;
|
|
25
|
+
env_dir: string | undefined;
|
|
26
|
+
private_prefix: string | undefined;
|
|
27
|
+
public_prefix: string | undefined;
|
|
28
|
+
svelte_compile_options: CompileOptions | undefined;
|
|
29
|
+
svelte_preprocessors: PreprocessorGroup | PreprocessorGroup[] | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns Gro-relevant properties of a SvelteKit config
|
|
33
|
+
* as a convenience wrapper around `load_sveltekit_config`.
|
|
34
|
+
* Needed because SvelteKit doesn't expose its config resolver.
|
|
35
|
+
*/
|
|
36
|
+
export declare const init_sveltekit_config: (dir_or_config?: string | SveltekitConfig) => Promise<Parsed_Sveltekit_Config>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { cwd } from 'node:process';
|
|
3
|
+
import { SVELTEKIT_CONFIG_FILENAME } from './paths.js';
|
|
4
|
+
/**
|
|
5
|
+
* Loads a SvelteKit config at `dir`.
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export const load_sveltekit_config = async (dir = cwd()) => {
|
|
9
|
+
try {
|
|
10
|
+
return (await import(join(dir, SVELTEKIT_CONFIG_FILENAME))).default;
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
// TODO currently incomplete and hack - maybe rethink
|
|
17
|
+
/**
|
|
18
|
+
* Returns Gro-relevant properties of a SvelteKit config
|
|
19
|
+
* as a convenience wrapper around `load_sveltekit_config`.
|
|
20
|
+
* Needed because SvelteKit doesn't expose its config resolver.
|
|
21
|
+
*/
|
|
22
|
+
export const init_sveltekit_config = async (dir_or_config = cwd()) => {
|
|
23
|
+
const sveltekit_config = typeof dir_or_config === 'string' ? await load_sveltekit_config(dir_or_config) : dir_or_config;
|
|
24
|
+
const kit = sveltekit_config?.kit;
|
|
25
|
+
const alias = kit?.alias;
|
|
26
|
+
const base_url = kit?.paths?.base;
|
|
27
|
+
const assets_url = kit?.paths?.assets;
|
|
28
|
+
// TODO probably a Zod schema instead
|
|
29
|
+
const assets_path = kit?.files?.assets ?? 'static';
|
|
30
|
+
const lib_path = kit?.files?.lib ?? 'src/lib';
|
|
31
|
+
const routes_path = kit?.files?.routes ?? 'src/routes';
|
|
32
|
+
const env_dir = kit?.env?.dir;
|
|
33
|
+
const private_prefix = kit?.env?.privatePrefix;
|
|
34
|
+
const public_prefix = kit?.env?.publicPrefix;
|
|
35
|
+
const svelte_compile_options = sveltekit_config?.compilerOptions;
|
|
36
|
+
const svelte_preprocessors = sveltekit_config?.preprocess;
|
|
37
|
+
return {
|
|
38
|
+
sveltekit_config,
|
|
39
|
+
alias,
|
|
40
|
+
base_url,
|
|
41
|
+
assets_url,
|
|
42
|
+
assets_path,
|
|
43
|
+
lib_path,
|
|
44
|
+
routes_path,
|
|
45
|
+
env_dir,
|
|
46
|
+
private_prefix,
|
|
47
|
+
public_prefix,
|
|
48
|
+
svelte_compile_options,
|
|
49
|
+
svelte_preprocessors,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Parsed_Sveltekit_Config } from './sveltekit_config.js';
|
|
2
|
+
export declare const sveltekit_shim_app_paths_matcher: RegExp;
|
|
3
|
+
export declare const sveltekit_shim_app_environment_matcher: RegExp;
|
|
4
|
+
/**
|
|
5
|
+
* Maps SvelteKit `$app` specifiers to their Gro shims.
|
|
6
|
+
* @see https://kit.svelte.dev/docs/modules
|
|
7
|
+
*/
|
|
8
|
+
export declare const sveltekit_shim_app_specifiers: Map<string, string>;
|
|
9
|
+
export declare const render_sveltekit_shim_app_paths: (base_url?: Parsed_Sveltekit_Config['base_url'], assets_url?: Parsed_Sveltekit_Config['assets_url']) => string;
|
|
10
|
+
export declare const render_sveltekit_shim_app_environment: (dev: boolean) => string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const sveltekit_shim_app_paths_matcher = /\/util\/sveltekit_shim_app_paths\.js$/u;
|
|
2
|
+
export const sveltekit_shim_app_environment_matcher = /\/util\/sveltekit_shim_app_environment\.js$/u;
|
|
3
|
+
/**
|
|
4
|
+
* Maps SvelteKit `$app` specifiers to their Gro shims.
|
|
5
|
+
* @see https://kit.svelte.dev/docs/modules
|
|
6
|
+
*/
|
|
7
|
+
export const sveltekit_shim_app_specifiers = new Map([
|
|
8
|
+
['$app/environment', '@ryanatkn/gro/sveltekit_shim_app_environment.js'],
|
|
9
|
+
['$app/forms', '@ryanatkn/gro/sveltekit_shim_app_forms.js'],
|
|
10
|
+
['$app/navigation', '@ryanatkn/gro/sveltekit_shim_app_navigation.js'],
|
|
11
|
+
['$app/paths', '@ryanatkn/gro/sveltekit_shim_app_paths.js'],
|
|
12
|
+
['$app/stores', '@ryanatkn/gro/sveltekit_shim_app_stores.js'],
|
|
13
|
+
]);
|
|
14
|
+
export const render_sveltekit_shim_app_paths = (base_url = '', assets_url = '') => `// shim for $app/paths
|
|
15
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
16
|
+
|
|
17
|
+
export const assets = ${JSON.stringify(assets_url)};
|
|
18
|
+
export const base = ${JSON.stringify(base_url)};
|
|
19
|
+
`;
|
|
20
|
+
// TODO improve support
|
|
21
|
+
// `dev` is not guaranteed to be the same as `MODE` - https://kit.svelte.dev/docs/modules#$app-environment-dev
|
|
22
|
+
// `version` is `config.kit.version.name` but I couldn't see how to load a SvelteKit `ValidatedConfig`
|
|
23
|
+
// `building` is just being hardcoded, might be better (but still not correct) to be `!dev`
|
|
24
|
+
export const render_sveltekit_shim_app_environment = (dev) => `// shim for $app/environment
|
|
25
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
26
|
+
|
|
27
|
+
export const browser = false;
|
|
28
|
+
export const building = false;
|
|
29
|
+
export const dev = ${JSON.stringify(dev)};
|
|
30
|
+
export const version = 'TODO';
|
|
31
|
+
`;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is created dynamically by `render_sveltekit_shim_app_environment`
|
|
3
|
+
* but exists here for the sake of the Node loader.
|
|
4
|
+
* There may be a cleaner workaround but I couldn't find it.
|
|
5
|
+
* @see https://github.com/nodejs/loaders for details about the forthcoming virtual file support
|
|
6
|
+
*/
|
|
7
|
+
export declare const browser = false;
|
|
8
|
+
export declare const building = false;
|
|
9
|
+
export declare const dev = true;
|
|
10
|
+
export declare const version = "TODO";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// shim for $app/environment
|
|
2
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
3
|
+
/**
|
|
4
|
+
* This file is created dynamically by `render_sveltekit_shim_app_environment`
|
|
5
|
+
* but exists here for the sake of the Node loader.
|
|
6
|
+
* There may be a cleaner workaround but I couldn't find it.
|
|
7
|
+
* @see https://github.com/nodejs/loaders for details about the forthcoming virtual file support
|
|
8
|
+
*/
|
|
9
|
+
export const browser = false;
|
|
10
|
+
export const building = false;
|
|
11
|
+
export const dev = true;
|
|
12
|
+
export const version = 'TODO';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="@sveltejs/kit" />
|
|
2
|
+
import type { applyAction as base_applyAction, deserialize as base_deserialize, enhance as base_enhance } from '$app/forms';
|
|
3
|
+
export declare const applyAction: typeof base_applyAction;
|
|
4
|
+
export declare const deserialize: typeof base_deserialize;
|
|
5
|
+
export declare const enhance: typeof base_enhance;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// shim for $app/forms
|
|
2
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
3
|
+
import { noop, noop_async } from '@ryanatkn/belt/function.js';
|
|
4
|
+
import * as devalue from 'devalue';
|
|
5
|
+
export const applyAction = noop_async;
|
|
6
|
+
export const deserialize = (result) => {
|
|
7
|
+
const parsed = JSON.parse(result);
|
|
8
|
+
if (parsed.data) {
|
|
9
|
+
parsed.data = devalue.parse(parsed.data);
|
|
10
|
+
}
|
|
11
|
+
return parsed;
|
|
12
|
+
};
|
|
13
|
+
export const enhance = () => ({ destroy: noop });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="@sveltejs/kit" />
|
|
2
|
+
import type { afterNavigate as base_afterNavigate, beforeNavigate as base_beforeNavigate, disableScrollHandling as base_disableScrollHandling, goto as base_goto, invalidate as base_invalidate, invalidateAll as base_invalidateAll, preloadCode as base_preloadCode, preloadData as base_preloadData } from '$app/navigation';
|
|
3
|
+
export declare const afterNavigate: typeof base_afterNavigate;
|
|
4
|
+
export declare const beforeNavigate: typeof base_beforeNavigate;
|
|
5
|
+
export declare const disableScrollHandling: typeof base_disableScrollHandling;
|
|
6
|
+
export declare const goto: typeof base_goto;
|
|
7
|
+
export declare const invalidate: typeof base_invalidate;
|
|
8
|
+
export declare const invalidateAll: typeof base_invalidateAll;
|
|
9
|
+
export declare const preloadCode: typeof base_preloadCode;
|
|
10
|
+
export declare const preloadData: typeof base_preloadData;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// shim for $app/navigation
|
|
2
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
3
|
+
import { noop, noop_async } from '@ryanatkn/belt/function.js';
|
|
4
|
+
export const afterNavigate = noop;
|
|
5
|
+
export const beforeNavigate = noop;
|
|
6
|
+
export const disableScrollHandling = noop;
|
|
7
|
+
export const goto = noop_async;
|
|
8
|
+
export const invalidate = noop_async;
|
|
9
|
+
export const invalidateAll = noop_async;
|
|
10
|
+
export const preloadCode = noop_async;
|
|
11
|
+
export const preloadData = noop_async;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="@sveltejs/kit" />
|
|
2
|
+
/**
|
|
3
|
+
* This file is created dynamically by `render_sveltekit_shim_app_paths`
|
|
4
|
+
* but exists here for the sake of the Node loader.
|
|
5
|
+
* There may be a cleaner workaround but I couldn't find it.
|
|
6
|
+
* @see https://github.com/nodejs/loaders for details about the forthcoming virtual file support
|
|
7
|
+
*/
|
|
8
|
+
import type { resolveRoute as base_resolveRoute } from '$app/paths';
|
|
9
|
+
export declare const assets = "";
|
|
10
|
+
export declare const base = "";
|
|
11
|
+
export declare const resolveRoute: typeof base_resolveRoute;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="@sveltejs/kit" />
|
|
2
|
+
import type { getStores as base_getStores, navigating as base_navigating, page as base_page, updated as base_updated } from '$app/stores';
|
|
3
|
+
export declare const getStores: typeof base_getStores;
|
|
4
|
+
export declare const navigating: typeof base_navigating;
|
|
5
|
+
export declare const page: typeof base_page;
|
|
6
|
+
export declare const updated: typeof base_updated;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// shim for $app/stores
|
|
2
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
3
|
+
import { readable } from 'svelte/store';
|
|
4
|
+
export const getStores = () => ({ navigating, page, updated });
|
|
5
|
+
export const navigating = readable(null);
|
|
6
|
+
export const page = readable({
|
|
7
|
+
url: new URL('https://gro.ryanatkn.com/TODO'),
|
|
8
|
+
params: {},
|
|
9
|
+
route: { id: 'RouteId' },
|
|
10
|
+
status: 200,
|
|
11
|
+
error: null,
|
|
12
|
+
data: {},
|
|
13
|
+
state: {},
|
|
14
|
+
form: {},
|
|
15
|
+
});
|
|
16
|
+
export const updated = readable(true);
|
|
17
|
+
updated.check = () => Promise.resolve(true);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a module shim for SvelteKit's `$env` imports.
|
|
3
|
+
*/
|
|
4
|
+
export declare const render_env_shim_module: (dev: boolean, mode: 'static' | 'dynamic', visibility: 'public' | 'private', public_prefix?: string, private_prefix?: string, env_dir?: string, env_files?: string[], ambient_env?: Record<string, string | undefined>) => Promise<string>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { load_env } from './env.js';
|
|
2
|
+
// TODO might want to do more escaping and validation
|
|
3
|
+
/**
|
|
4
|
+
* Generates a module shim for SvelteKit's `$env` imports.
|
|
5
|
+
*/
|
|
6
|
+
export const render_env_shim_module = async (dev, mode, visibility, public_prefix = 'PUBLIC_', private_prefix = '', env_dir, env_files, ambient_env) => {
|
|
7
|
+
const env = await load_env(dev, visibility, public_prefix, private_prefix, env_dir, env_files, ambient_env);
|
|
8
|
+
if (mode === 'static') {
|
|
9
|
+
return `// shim for $env/static/${visibility}
|
|
10
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
11
|
+
${Object.entries(env)
|
|
12
|
+
.map(([k, v]) => `export let ${k} = ${JSON.stringify(v)};`)
|
|
13
|
+
.join('\n')}
|
|
14
|
+
`;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return `// shim for $env/dynamic/${visibility}
|
|
18
|
+
// @see https://github.com/sveltejs/kit/issues/1485
|
|
19
|
+
import {load_env} from '@ryanatkn/gro/env.js';
|
|
20
|
+
export const env = load_env(${dev}, ${JSON.stringify(visibility)}, ${JSON.stringify(public_prefix)}, ${JSON.stringify(private_prefix)}, ${JSON.stringify(env_dir)}, ${JSON.stringify(env_files)}, ${JSON.stringify(ambient_env)});
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Task } from './task.js';
|
|
3
|
+
export declare const Args: z.ZodObject<{
|
|
4
|
+
sveltekit: z.ZodDefault<z.ZodBoolean>;
|
|
5
|
+
'no-sveltekit': z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
package_json: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
'no-package_json': z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
gen: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
'no-gen': z.ZodDefault<z.ZodBoolean>;
|
|
10
|
+
install: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
}, "strict", z.ZodTypeAny, {
|
|
12
|
+
package_json: boolean;
|
|
13
|
+
sveltekit: boolean;
|
|
14
|
+
install: boolean;
|
|
15
|
+
gen: boolean;
|
|
16
|
+
'no-gen': boolean;
|
|
17
|
+
'no-package_json': boolean;
|
|
18
|
+
'no-sveltekit': boolean;
|
|
19
|
+
}, {
|
|
20
|
+
sveltekit?: boolean | undefined;
|
|
21
|
+
'no-sveltekit'?: boolean | undefined;
|
|
22
|
+
package_json?: boolean | undefined;
|
|
23
|
+
'no-package_json'?: boolean | undefined;
|
|
24
|
+
gen?: boolean | undefined;
|
|
25
|
+
'no-gen'?: boolean | undefined;
|
|
26
|
+
install?: boolean | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export type Args = z.infer<typeof Args>;
|
|
29
|
+
export declare const task: Task<Args>;
|
|
30
|
+
export declare const sveltekit_sync: () => Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { spawn } from '@ryanatkn/belt/process.js';
|
|
3
|
+
import { Task_Error } from './task.js';
|
|
4
|
+
import { sync_package_json } from './package_json.js';
|
|
5
|
+
import { find_cli, spawn_cli } from './cli.js';
|
|
6
|
+
export const Args = z
|
|
7
|
+
.object({
|
|
8
|
+
sveltekit: z.boolean({ description: 'dual of no-sveltekit' }).default(true),
|
|
9
|
+
'no-sveltekit': z.boolean({ description: 'opt out of svelte-kit sync' }).default(false),
|
|
10
|
+
package_json: z.boolean({ description: 'dual of no-package_json' }).default(true),
|
|
11
|
+
'no-package_json': z.boolean({ description: 'opt out of package.json sync' }).default(false),
|
|
12
|
+
gen: z.boolean({ description: 'dual of no-gen' }).default(true),
|
|
13
|
+
'no-gen': z.boolean({ description: 'opt out of gen sync' }).default(false),
|
|
14
|
+
install: z.boolean({ description: 'run npm install' }).default(false),
|
|
15
|
+
})
|
|
16
|
+
.strict();
|
|
17
|
+
export const task = {
|
|
18
|
+
summary: 'run `gro gen`, update `package.json`, and optionally `npm i` to sync up',
|
|
19
|
+
Args,
|
|
20
|
+
run: async ({ args, invoke_task, config, log }) => {
|
|
21
|
+
const { sveltekit, package_json, gen, install } = args;
|
|
22
|
+
if (install) {
|
|
23
|
+
await spawn('npm', ['i']);
|
|
24
|
+
}
|
|
25
|
+
if (sveltekit) {
|
|
26
|
+
await sveltekit_sync();
|
|
27
|
+
log.info('synced SvelteKit');
|
|
28
|
+
}
|
|
29
|
+
if (package_json && config.map_package_json) {
|
|
30
|
+
await sync_package_json(config.map_package_json, log);
|
|
31
|
+
}
|
|
32
|
+
if (gen) {
|
|
33
|
+
await invoke_task('gen');
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export const sveltekit_sync = async () => {
|
|
38
|
+
if (!(await find_cli('svelte-kit'))) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const result = await spawn_cli('svelte-kit', ['sync']);
|
|
42
|
+
if (!result?.ok) {
|
|
43
|
+
throw new Task_Error(`failed svelte-kit sync`);
|
|
44
|
+
}
|
|
45
|
+
};
|
package/dist/task.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Logger } from '@ryanatkn/belt/log.js';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { Timings } from '@ryanatkn/belt/timings.js';
|
|
4
|
+
import type { Args } from './args.js';
|
|
5
|
+
import type { Gro_Config } from './config.js';
|
|
6
|
+
export interface Task<T_Args = Args, // same as `z.infer<typeof Args>`
|
|
7
|
+
T_Args_Schema extends z.ZodType = z.ZodType, T_Return = unknown> {
|
|
8
|
+
run: (ctx: Task_Context<T_Args>) => Promise<T_Return>;
|
|
9
|
+
summary?: string;
|
|
10
|
+
Args?: T_Args_Schema;
|
|
11
|
+
}
|
|
12
|
+
export interface Task_Context<T_Args = object> {
|
|
13
|
+
args: T_Args;
|
|
14
|
+
config: Gro_Config;
|
|
15
|
+
log: Logger;
|
|
16
|
+
timings: Timings;
|
|
17
|
+
invoke_task: (task_name: string, args?: Args, config?: Gro_Config) => Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export declare const TASK_FILE_SUFFIX_TS = ".task.ts";
|
|
20
|
+
export declare const TASK_FILE_SUFFIX_JS = ".task.js";
|
|
21
|
+
export declare const is_task_path: (path: string) => boolean;
|
|
22
|
+
export declare const to_task_name: (id: Flavored<string, "Source_Id">) => string;
|
|
23
|
+
/**
|
|
24
|
+
* This is used by tasks to signal a known failure.
|
|
25
|
+
* It's useful for cleaning up logging because
|
|
26
|
+
* we usually don't need their stack trace.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Task_Error extends Error {
|
|
29
|
+
}
|
package/dist/task.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { strip_end } from '@ryanatkn/belt/string.js';
|
|
2
|
+
import { import_id_to_lib_path } from './paths.js';
|
|
3
|
+
export const TASK_FILE_SUFFIX_TS = '.task.ts';
|
|
4
|
+
export const TASK_FILE_SUFFIX_JS = '.task.js';
|
|
5
|
+
export const is_task_path = (path) => path.endsWith(TASK_FILE_SUFFIX_TS) || path.endsWith(TASK_FILE_SUFFIX_JS);
|
|
6
|
+
export const to_task_name = (id) => {
|
|
7
|
+
const lib_path = import_id_to_lib_path(id);
|
|
8
|
+
const name = strip_end(strip_end(lib_path, TASK_FILE_SUFFIX_TS), TASK_FILE_SUFFIX_JS);
|
|
9
|
+
return name;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* This is used by tasks to signal a known failure.
|
|
13
|
+
* It's useful for cleaning up logging because
|
|
14
|
+
* we usually don't need their stack trace.
|
|
15
|
+
*/
|
|
16
|
+
export class Task_Error extends Error {
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { suite } from 'uvu';
|
|
2
|
+
import * as assert from 'uvu/assert';
|
|
3
|
+
import { is_task_path, to_task_name } from './task.js';
|
|
4
|
+
/* test__is_task_path */
|
|
5
|
+
const test__is_task_path = suite('is_task_path');
|
|
6
|
+
test__is_task_path('basic behavior', () => {
|
|
7
|
+
assert.ok(is_task_path('foo.task.ts'));
|
|
8
|
+
assert.ok(is_task_path('foo.task.js'));
|
|
9
|
+
assert.ok(!is_task_path('foo.ts'));
|
|
10
|
+
assert.ok(is_task_path('bar/baz/foo.task.ts'));
|
|
11
|
+
assert.ok(!is_task_path('bar/baz/foo.ts'));
|
|
12
|
+
});
|
|
13
|
+
test__is_task_path.run();
|
|
14
|
+
/* test__is_task_path */
|
|
15
|
+
/* test__to_task_name */
|
|
16
|
+
const test__to_task_name = suite('to_task_name');
|
|
17
|
+
test__to_task_name('basic behavior', () => {
|
|
18
|
+
assert.is(to_task_name('foo.task.ts'), 'foo');
|
|
19
|
+
assert.is(to_task_name('bar/baz/foo.task.ts'), 'bar/baz/foo');
|
|
20
|
+
});
|
|
21
|
+
test__to_task_name.run();
|
|
22
|
+
/* test__to_task_name */
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { load_modules, find_modules, type Module_Meta, type Load_Module_Result, type Find_Modules_Failure } from './modules.js';
|
|
2
|
+
import { type Task } from './task.js';
|
|
3
|
+
export interface Task_Module {
|
|
4
|
+
task: Task;
|
|
5
|
+
}
|
|
6
|
+
export interface Task_Module_Meta extends Module_Meta<Task_Module> {
|
|
7
|
+
name: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const validate_task_module: (mod: Record<string, any>) => mod is Task_Module;
|
|
10
|
+
export declare const load_task_module: (id: string) => Promise<Load_Module_Result<Task_Module_Meta>>;
|
|
11
|
+
export declare const find_task_modules: (input_paths?: string[], extensions?: string[], root_dirs?: string[]) => Promise<ReturnType<typeof find_modules>>;
|
|
12
|
+
export declare const load_task_modules: (input_paths?: string[], extensions?: string[], root_dirs?: string[]) => Promise<ReturnType<typeof load_modules<Task_Module, Task_Module_Meta>> | ({
|
|
13
|
+
ok: false;
|
|
14
|
+
} & Find_Modules_Failure)>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { paths } from './paths.js';
|
|
2
|
+
import { load_module, load_modules, find_modules, } from './modules.js';
|
|
3
|
+
import { to_task_name, is_task_path, TASK_FILE_SUFFIX_TS, TASK_FILE_SUFFIX_JS, } from './task.js';
|
|
4
|
+
import { get_possible_source_ids } from './input_path.js';
|
|
5
|
+
import { search_fs } from './search_fs.js';
|
|
6
|
+
export const validate_task_module = (mod) => !!mod.task && typeof mod.task.run === 'function';
|
|
7
|
+
export const load_task_module = async (id) => {
|
|
8
|
+
const result = await load_module(id, validate_task_module);
|
|
9
|
+
if (!result.ok)
|
|
10
|
+
return result;
|
|
11
|
+
return { ...result, mod: { ...result.mod, name: to_task_name(id) } };
|
|
12
|
+
};
|
|
13
|
+
export const find_task_modules = async (input_paths = [paths.lib], extensions = [TASK_FILE_SUFFIX_TS, TASK_FILE_SUFFIX_JS], root_dirs) => find_modules(input_paths, (id) => search_fs(id, { filter: (path) => is_task_path(path) }), (input_path) => get_possible_source_ids(input_path, extensions, root_dirs));
|
|
14
|
+
export const load_task_modules = async (input_paths, extensions, root_dirs) => {
|
|
15
|
+
const find_modules_result = await find_task_modules(input_paths, extensions, root_dirs);
|
|
16
|
+
if (!find_modules_result.ok)
|
|
17
|
+
return find_modules_result;
|
|
18
|
+
return load_modules(find_modules_result.source_ids_by_input_path, load_task_module);
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|