@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/module.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// TODO refactor to be configurable, probably following Rollup's patterns
|
|
2
|
+
import { SOURCE_DIR, SOURCE_DIRNAME, LIB_DIRNAME } from './paths.js';
|
|
3
|
+
export const MODULE_PATH_SRC_PREFIX = SOURCE_DIR;
|
|
4
|
+
export const MODULE_PATH_LIB_PREFIX = `$${LIB_DIRNAME}/`;
|
|
5
|
+
const INTERNAL_MODULE_MATCHER = new RegExp(`^(\\.?\\.?|${SOURCE_DIRNAME}|\\$${LIB_DIRNAME})\\/`, 'u');
|
|
6
|
+
export const is_external_module = (module_name) => !INTERNAL_MODULE_MATCHER.test(module_name);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { suite } from 'uvu';
|
|
2
|
+
import * as assert from 'uvu/assert';
|
|
3
|
+
import { is_external_module } from './module.js';
|
|
4
|
+
/* test__is_external_module */
|
|
5
|
+
const test__is_external_module = suite('is_external_module');
|
|
6
|
+
test__is_external_module('internal browser module patterns', () => {
|
|
7
|
+
assert.is(is_external_module('./foo'), false);
|
|
8
|
+
assert.is(is_external_module('./foo.js'), false);
|
|
9
|
+
assert.is(is_external_module('../foo'), false);
|
|
10
|
+
assert.is(is_external_module('../foo.js'), false);
|
|
11
|
+
assert.is(is_external_module('../../../foo'), false);
|
|
12
|
+
assert.is(is_external_module('../../../foo.js'), false);
|
|
13
|
+
assert.is(is_external_module('/foo'), false);
|
|
14
|
+
assert.is(is_external_module('/foo.js'), false);
|
|
15
|
+
assert.is(is_external_module('src/foo'), false);
|
|
16
|
+
assert.is(is_external_module('src/foo.js'), false);
|
|
17
|
+
assert.is(is_external_module('$lib/foo'), false);
|
|
18
|
+
assert.is(is_external_module('$lib/foo.js'), false);
|
|
19
|
+
assert.is(is_external_module('./foo/bar/baz'), false);
|
|
20
|
+
assert.is(is_external_module('./foo/bar/baz.js'), false);
|
|
21
|
+
assert.is(is_external_module('../foo/bar/baz'), false);
|
|
22
|
+
assert.is(is_external_module('../foo/bar/baz.js'), false);
|
|
23
|
+
assert.is(is_external_module('../../../foo/bar/baz'), false);
|
|
24
|
+
assert.is(is_external_module('../../../foo/bar/baz.js'), false);
|
|
25
|
+
assert.is(is_external_module('/foo/bar/baz'), false);
|
|
26
|
+
assert.is(is_external_module('/foo/bar/baz.js'), false);
|
|
27
|
+
assert.is(is_external_module('src/foo/bar/baz'), false);
|
|
28
|
+
assert.is(is_external_module('src/foo/bar/baz.js'), false);
|
|
29
|
+
assert.is(is_external_module('$lib/foo/bar/baz'), false);
|
|
30
|
+
assert.is(is_external_module('$lib/foo/bar/baz.js'), false);
|
|
31
|
+
});
|
|
32
|
+
test__is_external_module('external browser module patterns', () => {
|
|
33
|
+
assert.is(is_external_module('foo'), true);
|
|
34
|
+
assert.is(is_external_module('foo.js'), true);
|
|
35
|
+
assert.is(is_external_module('foo/bar/baz'), true);
|
|
36
|
+
assert.is(is_external_module('foo/bar/baz.js'), true);
|
|
37
|
+
assert.is(is_external_module('@foo/bar/baz'), true);
|
|
38
|
+
assert.is(is_external_module('@foo/bar/baz.js'), true);
|
|
39
|
+
});
|
|
40
|
+
test__is_external_module.run();
|
|
41
|
+
/* test__is_external_module */
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Result } from '@ryanatkn/belt/result.js';
|
|
2
|
+
import type { Path_Data } from './path.js';
|
|
3
|
+
import { type Source_Id } from './paths.js';
|
|
4
|
+
export interface Module_Meta<T_Module extends Record<string, any> = Record<string, any>> {
|
|
5
|
+
id: string;
|
|
6
|
+
mod: T_Module;
|
|
7
|
+
}
|
|
8
|
+
export type Load_Module_Result<T> = Result<{
|
|
9
|
+
mod: T;
|
|
10
|
+
}, Load_Module_Failure>;
|
|
11
|
+
export type Load_Module_Failure = {
|
|
12
|
+
ok: false;
|
|
13
|
+
type: 'importFailed';
|
|
14
|
+
id: string;
|
|
15
|
+
error: Error;
|
|
16
|
+
} | {
|
|
17
|
+
ok: false;
|
|
18
|
+
type: 'invalid';
|
|
19
|
+
id: string;
|
|
20
|
+
mod: Record<string, any>;
|
|
21
|
+
validation: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const load_module: <T extends Record<string, any>>(id: string, validate?: ((mod: Record<string, any>) => mod is T) | undefined) => Promise<Result<{
|
|
24
|
+
mod: T_1;
|
|
25
|
+
}, Load_Module_Failure>>;
|
|
26
|
+
export type Find_Modules_Result = Result<{
|
|
27
|
+
source_ids_by_input_path: Map<string, string[]>;
|
|
28
|
+
source_id_path_data_by_input_path: Map<string, Path_Data>;
|
|
29
|
+
}, Find_Modules_Failure>;
|
|
30
|
+
export type Find_Modules_Failure = {
|
|
31
|
+
type: 'unmapped_input_paths';
|
|
32
|
+
source_id_path_data_by_input_path: Map<string, Path_Data>;
|
|
33
|
+
unmapped_input_paths: string[];
|
|
34
|
+
reasons: string[];
|
|
35
|
+
} | {
|
|
36
|
+
type: 'input_directories_with_no_files';
|
|
37
|
+
source_ids_by_input_path: Map<string, string[]>;
|
|
38
|
+
source_id_path_data_by_input_path: Map<string, Path_Data>;
|
|
39
|
+
input_directories_with_no_files: string[];
|
|
40
|
+
reasons: string[];
|
|
41
|
+
};
|
|
42
|
+
export type Load_Modules_Result<T_Module_Meta extends Module_Meta> = Result<{
|
|
43
|
+
modules: T_Module_Meta[];
|
|
44
|
+
}, {
|
|
45
|
+
type: 'load_module_failures';
|
|
46
|
+
load_module_failures: Load_Module_Failure[];
|
|
47
|
+
reasons: string[];
|
|
48
|
+
modules: T_Module_Meta[];
|
|
49
|
+
}>;
|
|
50
|
+
export declare const find_modules: (input_paths: string[], custom_search_fs?: (dir: string, options?: import("./search_fs.js").Search_Fs_Options) => Promise<Map<string, import("./path.js").Path_Stats>>, get_possible_source_ids?: ((input_path: string) => string[]) | undefined, timings?: any) => Promise<Find_Modules_Result>;
|
|
51
|
+
export declare const load_modules: <Module_Type extends Record<string, any>, T_Module_Meta extends Module_Meta<Module_Type>>(source_ids_by_input_path: Map<string, string[]>, load_module_by_id: (source_id: Flavored<string, "Source_Id">) => Promise<Result<{
|
|
52
|
+
mod: T;
|
|
53
|
+
}, Load_Module_Failure>>, timings?: any) => Promise<Result<{
|
|
54
|
+
modules: T_Module_Meta_1[];
|
|
55
|
+
}, {
|
|
56
|
+
type: 'load_module_failures';
|
|
57
|
+
load_module_failures: Load_Module_Failure[];
|
|
58
|
+
reasons: string[];
|
|
59
|
+
modules: T_Module_Meta_1[];
|
|
60
|
+
}>>;
|
package/dist/modules.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { red } from 'kleur/colors';
|
|
2
|
+
import { Unreachable_Error } from '@ryanatkn/belt/error.js';
|
|
3
|
+
import { print_error } from '@ryanatkn/belt/print.js';
|
|
4
|
+
import { load_source_path_data_by_input_path, load_source_ids_by_input_path } from './input_path.js';
|
|
5
|
+
import { paths_from_id, print_path, print_path_or_gro_path } from './paths.js';
|
|
6
|
+
import { search_fs } from './search_fs.js';
|
|
7
|
+
export const load_module = async (id, validate) => {
|
|
8
|
+
let mod;
|
|
9
|
+
try {
|
|
10
|
+
mod = await import(id);
|
|
11
|
+
}
|
|
12
|
+
catch (err) {
|
|
13
|
+
return { ok: false, type: 'importFailed', id, error: err };
|
|
14
|
+
}
|
|
15
|
+
if (validate && !validate(mod)) {
|
|
16
|
+
return { ok: false, type: 'invalid', id, mod, validation: validate.name };
|
|
17
|
+
}
|
|
18
|
+
return { ok: true, mod: { id, mod } };
|
|
19
|
+
};
|
|
20
|
+
/*
|
|
21
|
+
|
|
22
|
+
Finds modules from input paths. (see `src/lib/input_path.ts` for more)
|
|
23
|
+
|
|
24
|
+
*/
|
|
25
|
+
export const find_modules = async (input_paths, custom_search_fs = search_fs, get_possible_source_ids, timings) => {
|
|
26
|
+
// Check which extension variation works - if it's a directory, prefer others first!
|
|
27
|
+
const timing_to_map_input_paths = timings?.start('map input paths');
|
|
28
|
+
const { source_id_path_data_by_input_path, unmapped_input_paths } = await load_source_path_data_by_input_path(input_paths, get_possible_source_ids);
|
|
29
|
+
timing_to_map_input_paths?.();
|
|
30
|
+
// Error if any input path could not be mapped.
|
|
31
|
+
if (unmapped_input_paths.length) {
|
|
32
|
+
return {
|
|
33
|
+
ok: false,
|
|
34
|
+
type: 'unmapped_input_paths',
|
|
35
|
+
source_id_path_data_by_input_path,
|
|
36
|
+
unmapped_input_paths,
|
|
37
|
+
reasons: unmapped_input_paths.map((input_path) => red(`Input path ${print_path_or_gro_path(input_path, paths_from_id(input_path))} cannot be mapped to a file or directory.`)),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// Find all of the files for any directories.
|
|
41
|
+
const timing_to_search_fs = timings?.start('find files');
|
|
42
|
+
const { source_ids_by_input_path, input_directories_with_no_files } = await load_source_ids_by_input_path(source_id_path_data_by_input_path, custom_search_fs);
|
|
43
|
+
timing_to_search_fs?.();
|
|
44
|
+
// Error if any input path has no files. (means we have an empty directory)
|
|
45
|
+
return input_directories_with_no_files.length
|
|
46
|
+
? {
|
|
47
|
+
ok: false,
|
|
48
|
+
type: 'input_directories_with_no_files',
|
|
49
|
+
source_id_path_data_by_input_path,
|
|
50
|
+
source_ids_by_input_path,
|
|
51
|
+
input_directories_with_no_files,
|
|
52
|
+
reasons: input_directories_with_no_files.map((input_path) => red(`Input directory ${print_path_or_gro_path(source_id_path_data_by_input_path.get(input_path).id, paths_from_id(input_path))} contains no matching files.`)),
|
|
53
|
+
}
|
|
54
|
+
: { ok: true, source_ids_by_input_path, source_id_path_data_by_input_path };
|
|
55
|
+
};
|
|
56
|
+
/*
|
|
57
|
+
|
|
58
|
+
Load modules by source id.
|
|
59
|
+
|
|
60
|
+
TODO parallelize, originally it needed to be serial for a specific usecase we no longer have
|
|
61
|
+
|
|
62
|
+
*/
|
|
63
|
+
export const load_modules = async (source_ids_by_input_path, // TODO maybe make this a flat array and remove `input_path`?
|
|
64
|
+
load_module_by_id, timings) => {
|
|
65
|
+
const timing_to_load_modules = timings?.start('load modules');
|
|
66
|
+
const modules = [];
|
|
67
|
+
const load_module_failures = [];
|
|
68
|
+
const reasons = [];
|
|
69
|
+
for (const [input_path, source_ids] of source_ids_by_input_path) {
|
|
70
|
+
for (const id of source_ids) {
|
|
71
|
+
const result = await load_module_by_id(id); // eslint-disable-line no-await-in-loop
|
|
72
|
+
if (result.ok) {
|
|
73
|
+
modules.push(result.mod);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
load_module_failures.push(result);
|
|
77
|
+
switch (result.type) {
|
|
78
|
+
case 'importFailed': {
|
|
79
|
+
reasons.push(`Module import ${print_path(id, paths_from_id(id))} failed from input ${print_path(input_path, paths_from_id(input_path))}: ${print_error(result.error)}`);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
case 'invalid': {
|
|
83
|
+
// TODO try to make this a good error message for the task case
|
|
84
|
+
reasons.push(`Module ${print_path(id, paths_from_id(id))} failed validation '${result.validation}'.`);
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
throw new Unreachable_Error(result);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
timing_to_load_modules?.();
|
|
94
|
+
return load_module_failures.length
|
|
95
|
+
? {
|
|
96
|
+
ok: false,
|
|
97
|
+
type: 'load_module_failures',
|
|
98
|
+
load_module_failures,
|
|
99
|
+
reasons,
|
|
100
|
+
modules,
|
|
101
|
+
}
|
|
102
|
+
: { ok: true, modules };
|
|
103
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { suite } from 'uvu';
|
|
2
|
+
import * as assert from 'uvu/assert';
|
|
3
|
+
import { resolve, join } from 'node:path';
|
|
4
|
+
import { find_modules, load_modules, load_module } from './modules.js';
|
|
5
|
+
import { get_possible_source_ids } from './input_path.js';
|
|
6
|
+
import { search_fs } from './search_fs.js';
|
|
7
|
+
// TODO if we import directly, svelte-package generates types in `src/fixtures`
|
|
8
|
+
/* eslint-disable no-useless-concat */
|
|
9
|
+
const modTest1 = await import('../fixtures/' + 'test1.foo.js');
|
|
10
|
+
const modTestBaz1 = await import('../fixtures/' + 'baz1/test1.baz.js');
|
|
11
|
+
const modTestBaz2 = await import('../fixtures/' + 'baz2/test2.baz.js');
|
|
12
|
+
/* test__load_module */
|
|
13
|
+
const test__load_module = suite('load_module');
|
|
14
|
+
test__load_module('basic behavior', async () => {
|
|
15
|
+
const id = resolve('src/fixtures/test1.foo.js');
|
|
16
|
+
let validated_mod;
|
|
17
|
+
const result = await load_module(id, ((mod) => {
|
|
18
|
+
validated_mod = mod;
|
|
19
|
+
return true;
|
|
20
|
+
}));
|
|
21
|
+
assert.ok(result.ok);
|
|
22
|
+
assert.is(result.mod.id, id);
|
|
23
|
+
assert.is(result.mod.mod, validated_mod);
|
|
24
|
+
assert.is(result.mod.mod, modTest1);
|
|
25
|
+
});
|
|
26
|
+
test__load_module('without validation', async () => {
|
|
27
|
+
const id = resolve('src/fixtures/test1.foo.js');
|
|
28
|
+
const result = await load_module(id);
|
|
29
|
+
assert.ok(result.ok);
|
|
30
|
+
assert.is(result.mod.id, id);
|
|
31
|
+
assert.is(result.mod.mod, modTest1);
|
|
32
|
+
});
|
|
33
|
+
test__load_module('fails validation', async () => {
|
|
34
|
+
const id = resolve('src/fixtures/test1.foo.js');
|
|
35
|
+
let validated_mod;
|
|
36
|
+
const test_validation = (mod) => {
|
|
37
|
+
validated_mod = mod;
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
const result = await load_module(id, test_validation);
|
|
41
|
+
assert.ok(!result.ok);
|
|
42
|
+
if (result.type === 'invalid') {
|
|
43
|
+
assert.is(result.validation, test_validation.name);
|
|
44
|
+
assert.is(result.id, id);
|
|
45
|
+
assert.is(result.mod, validated_mod);
|
|
46
|
+
assert.is(result.mod, modTest1);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
throw Error('Should be invalid');
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
test__load_module('fails to import', async () => {
|
|
53
|
+
const id = resolve('foo/test/failure');
|
|
54
|
+
const result = await load_module(id);
|
|
55
|
+
assert.ok(!result.ok);
|
|
56
|
+
if (result.type === 'importFailed') {
|
|
57
|
+
assert.is(result.id, id);
|
|
58
|
+
assert.ok(result.error instanceof Error);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw Error('Should fail to import');
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
test__load_module.run();
|
|
65
|
+
/* test__load_module */
|
|
66
|
+
/* test__find_modules */
|
|
67
|
+
const test__find_modules = suite('find_modules');
|
|
68
|
+
test__find_modules('with and without extension', async () => {
|
|
69
|
+
const path1 = resolve('src/fixtures/test1');
|
|
70
|
+
const id1 = resolve('src/fixtures/test1.foo.ts');
|
|
71
|
+
const id2 = resolve('src/fixtures/test2.foo.ts');
|
|
72
|
+
const result = await find_modules([path1, id2], (id) => search_fs(id, { files_only: false }), (input_path) => get_possible_source_ids(input_path, ['.foo.ts']));
|
|
73
|
+
assert.ok(result.ok);
|
|
74
|
+
assert.equal(result.source_ids_by_input_path, new Map([
|
|
75
|
+
[path1, [id1]],
|
|
76
|
+
[id2, [id2]],
|
|
77
|
+
]));
|
|
78
|
+
assert.equal(result.source_id_path_data_by_input_path, new Map([
|
|
79
|
+
[path1, { id: id1, isDirectory: false }],
|
|
80
|
+
[id2, { id: id2, isDirectory: false }],
|
|
81
|
+
]));
|
|
82
|
+
});
|
|
83
|
+
test__find_modules('directory', async () => {
|
|
84
|
+
const id = resolve('src/fixtures/');
|
|
85
|
+
const result = await find_modules([id], (id) => search_fs(id, { filter: (path) => path.includes('.foo.') }));
|
|
86
|
+
assert.ok(result.ok);
|
|
87
|
+
assert.equal(result.source_ids_by_input_path, new Map([[id, [join(id, 'test1.foo.ts'), join(id, 'test2.foo.ts')]]]));
|
|
88
|
+
assert.equal(result.source_id_path_data_by_input_path, new Map([[id, { id, isDirectory: true }]]));
|
|
89
|
+
});
|
|
90
|
+
test__find_modules('fail with unmapped_input_paths', async () => {
|
|
91
|
+
const result = await find_modules([
|
|
92
|
+
resolve('src/fixtures/bar1'),
|
|
93
|
+
resolve('src/fixtures/failme1'),
|
|
94
|
+
resolve('src/fixtures/bar2'),
|
|
95
|
+
resolve('src/fixtures/failme2'),
|
|
96
|
+
], (id) => search_fs(id, { files_only: false }), (input_path) => get_possible_source_ids(input_path, ['.foo.ts']));
|
|
97
|
+
assert.ok(!result.ok);
|
|
98
|
+
assert.ok(result.reasons.length);
|
|
99
|
+
if (result.type === 'unmapped_input_paths') {
|
|
100
|
+
assert.equal(result.unmapped_input_paths, [
|
|
101
|
+
resolve('src/fixtures/failme1'),
|
|
102
|
+
resolve('src/fixtures/failme2'),
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw Error('Expected to fail with unmapped_input_paths');
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
test__find_modules('fail with input_directories_with_no_files', async () => {
|
|
110
|
+
const result = await find_modules([
|
|
111
|
+
resolve('src/fixtures/baz1'),
|
|
112
|
+
resolve('src/fixtures/bar1'),
|
|
113
|
+
resolve('src/fixtures/bar2'),
|
|
114
|
+
resolve('src/fixtures/baz2'),
|
|
115
|
+
], (id) => search_fs(id, { filter: (path) => !path.includes('.bar.'), files_only: false }));
|
|
116
|
+
assert.ok(!result.ok);
|
|
117
|
+
assert.ok(result.reasons.length);
|
|
118
|
+
if (result.type === 'input_directories_with_no_files') {
|
|
119
|
+
assert.equal(result.input_directories_with_no_files, [
|
|
120
|
+
resolve('src/fixtures/bar1'),
|
|
121
|
+
resolve('src/fixtures/bar2'),
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
throw Error('Expected to fail with input_directories_with_no_files');
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
test__find_modules.run();
|
|
129
|
+
/* test__find_modules */
|
|
130
|
+
/* test__load_modules */
|
|
131
|
+
const test__load_modules = suite('load_modules');
|
|
132
|
+
test__load_modules('fail with load_module_failures', async () => {
|
|
133
|
+
const path_bar1 = resolve('src/fixtures/bar1');
|
|
134
|
+
const path_bar2 = resolve('src/fixtures/bar2');
|
|
135
|
+
const path_baz1 = resolve('src/fixtures/baz1');
|
|
136
|
+
const path_baz2 = resolve('src/fixtures/baz2');
|
|
137
|
+
const id_bar1 = join(path_bar1, 'test1.bar.ts');
|
|
138
|
+
const id_bar2 = join(path_bar2, 'test2.bar.ts');
|
|
139
|
+
const id_baz1 = join(path_baz1, 'test1.baz.ts');
|
|
140
|
+
const id_baz2 = join(path_baz2, 'test2.baz.ts');
|
|
141
|
+
const test_validation = ((mod) => mod.bar !== 1);
|
|
142
|
+
let error;
|
|
143
|
+
const result = await load_modules(new Map([
|
|
144
|
+
[path_bar1, [id_bar1, id_bar2]],
|
|
145
|
+
[path_baz1, [id_baz1, id_baz2]],
|
|
146
|
+
]), async (id) => {
|
|
147
|
+
if (id === id_bar2) {
|
|
148
|
+
return {
|
|
149
|
+
ok: false,
|
|
150
|
+
type: 'importFailed',
|
|
151
|
+
id,
|
|
152
|
+
error: (error = new Error('Test failed import')),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return load_module(id, test_validation);
|
|
156
|
+
});
|
|
157
|
+
assert.ok(!result.ok);
|
|
158
|
+
assert.ok(result.reasons.length);
|
|
159
|
+
if (result.type !== 'load_module_failures') {
|
|
160
|
+
throw Error('Expected to fail with load_module_failures');
|
|
161
|
+
}
|
|
162
|
+
assert.is(result.load_module_failures.length, 2);
|
|
163
|
+
const [failure1, failure2] = result.load_module_failures;
|
|
164
|
+
if (failure1.type !== 'invalid') {
|
|
165
|
+
throw Error('Expected to fail with invalid');
|
|
166
|
+
}
|
|
167
|
+
assert.is(failure1.id, id_bar1);
|
|
168
|
+
assert.ok(failure1.mod);
|
|
169
|
+
assert.is(failure1.validation, test_validation.name);
|
|
170
|
+
if (failure2.type !== 'importFailed') {
|
|
171
|
+
throw Error('Expected to fail with importFailed');
|
|
172
|
+
}
|
|
173
|
+
assert.is(failure2.id, id_bar2);
|
|
174
|
+
assert.is(failure2.error, error);
|
|
175
|
+
assert.is(result.modules.length, 2);
|
|
176
|
+
assert.is(result.modules[0].id, id_baz1);
|
|
177
|
+
assert.is(result.modules[0].mod, modTestBaz1);
|
|
178
|
+
assert.is(result.modules[1].id, id_baz2);
|
|
179
|
+
assert.is(result.modules[1].mod, modTestBaz2);
|
|
180
|
+
});
|
|
181
|
+
test__load_modules.run();
|
|
182
|
+
/* test__load_modules */
|