@ryanatkn/gro 0.119.1 → 0.120.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/README.md +3 -2
- package/dist/changelog.d.ts +1 -0
- package/dist/changeset.task.js +4 -5
- package/dist/clean_fs.d.ts +1 -2
- package/dist/clean_fs.js +3 -2
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +14 -1
- package/dist/config.js +17 -5
- package/dist/config.test.js +50 -1
- package/dist/deploy.task.js +8 -7
- package/dist/docs/README.gen.md.js +3 -3
- package/dist/docs/config.md +22 -6
- package/dist/docs/gen.md +2 -1
- package/dist/docs/task.md +4 -3
- package/dist/docs/tasks.gen.md.js +17 -10
- package/dist/docs/tasks.md +1 -0
- package/dist/env.d.ts +2 -3
- package/dist/env.js +2 -2
- package/dist/esbuild_helpers.d.ts +2 -1
- package/dist/esbuild_plugin_external_worker.d.ts +0 -1
- package/dist/esbuild_plugin_external_worker.js +7 -7
- package/dist/esbuild_plugin_svelte.d.ts +0 -1
- package/dist/esbuild_plugin_sveltekit_local_imports.js +2 -2
- package/dist/format_directory.d.ts +1 -0
- package/dist/fs.d.ts +1 -3
- package/dist/fs.js +3 -13
- package/dist/fs.test.js +5 -5
- package/dist/gen.d.ts +66 -13
- package/dist/gen.js +77 -9
- package/dist/gen.task.d.ts +3 -0
- package/dist/gen.task.js +24 -19
- package/dist/gen.test.js +48 -35
- package/dist/git.d.ts +0 -1
- package/dist/git.js +3 -3
- package/dist/gro_helpers.js +4 -4
- package/dist/gro_plugin_gen.js +7 -7
- package/dist/gro_plugin_server.d.ts +2 -2
- package/dist/gro_plugin_server.js +5 -5
- package/dist/gro_plugin_sveltekit_app.js +8 -8
- package/dist/hash.d.ts +1 -2
- package/dist/input_path.d.ts +34 -16
- package/dist/input_path.js +119 -67
- package/dist/input_path.test.js +150 -46
- package/dist/invoke_task.d.ts +2 -1
- package/dist/invoke_task.js +33 -79
- package/dist/loader.d.ts +0 -1
- package/dist/loader.js +4 -4
- package/dist/modules.d.ts +17 -36
- package/dist/modules.js +29 -68
- package/dist/modules.test.js +19 -143
- package/dist/package.d.ts +11 -20
- package/dist/package.js +61 -64
- package/dist/package_json.d.ts +1 -0
- package/dist/package_json.js +1 -1
- package/dist/package_meta.d.ts +1 -1
- package/dist/path.d.ts +12 -8
- package/dist/path.js +0 -6
- package/dist/paths.d.ts +7 -12
- package/dist/paths.js +11 -34
- package/dist/paths.test.js +17 -15
- package/dist/plugin.d.ts +1 -1
- package/dist/publish.task.js +3 -3
- package/dist/resolve.task.d.ts +11 -0
- package/dist/resolve.task.js +24 -0
- package/dist/resolve_node_specifier.d.ts +2 -2
- package/dist/resolve_node_specifier.js +3 -3
- package/dist/resolve_specifier.d.ts +2 -1
- package/dist/resolve_specifier.js +16 -16
- package/dist/resolve_specifier.test.js +9 -9
- package/dist/run.task.js +2 -2
- package/dist/run_gen.d.ts +4 -4
- package/dist/run_gen.js +9 -16
- package/dist/run_gen.test.js +10 -15
- package/dist/run_task.d.ts +2 -1
- package/dist/run_task.js +2 -0
- package/dist/search_fs.d.ts +20 -7
- package/dist/search_fs.js +40 -18
- package/dist/search_fs.test.js +9 -11
- package/dist/src_json.js +2 -2
- package/dist/sveltekit_config.d.ts +0 -1
- package/dist/sveltekit_helpers.js +4 -4
- package/dist/sveltekit_shim_app.d.ts +1 -1
- package/dist/sveltekit_shim_app_forms.d.ts +0 -1
- package/dist/sveltekit_shim_app_navigation.d.ts +0 -1
- package/dist/sveltekit_shim_app_paths.d.ts +0 -1
- package/dist/sveltekit_shim_app_stores.d.ts +0 -1
- package/dist/sveltekit_shim_env.d.ts +1 -1
- package/dist/task.d.ts +65 -1
- package/dist/task.js +85 -13
- package/dist/task.test.js +25 -11
- package/dist/task_logging.d.ts +3 -6
- package/dist/task_logging.js +18 -36
- package/dist/watch_dir.d.ts +2 -2
- package/dist/watch_dir.js +14 -16
- package/package.json +18 -23
- package/dist/gen_module.d.ts +0 -34
- package/dist/gen_module.js +0 -32
- package/dist/gen_module.test.d.ts +0 -1
- package/dist/gen_module.test.js +0 -30
- package/dist/task_module.d.ts +0 -15
- package/dist/task_module.js +0 -18
- package/dist/task_module.test.d.ts +0 -1
- package/dist/task_module.test.js +0 -67
package/dist/paths.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { join, extname, relative, basename } from 'node:path';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
|
-
import { strip_end
|
|
3
|
+
import { strip_end } from '@ryanatkn/belt/string.js';
|
|
4
4
|
import { gray } from 'kleur/colors';
|
|
5
|
-
import { z } from 'zod';
|
|
6
5
|
import { GRO_CONFIG_PATH, GRO_DEV_DIR, GRO_DIR, SOURCE_DIR, SVELTEKIT_DIST_DIRNAME, } from './path_constants.js';
|
|
7
6
|
import { sveltekit_config_global } from './sveltekit_config_global.js';
|
|
8
7
|
/*
|
|
@@ -15,9 +14,6 @@ export const LIB_DIRNAME = basename(sveltekit_config_global.lib_path);
|
|
|
15
14
|
export const LIB_PATH = SOURCE_DIR + LIB_DIRNAME;
|
|
16
15
|
export const LIB_DIR = LIB_PATH + '/';
|
|
17
16
|
export const ROUTES_DIRNAME = basename(sveltekit_config_global.routes_path);
|
|
18
|
-
// TODO probably rename to `Path_Id` from `Source_Id`?
|
|
19
|
-
// TODO Flavored doesn't work when used in schemas, use Zod brand instead? problem is ergonomics
|
|
20
|
-
export const Source_Id = z.string();
|
|
21
17
|
export const create_paths = (root_dir) => {
|
|
22
18
|
// TODO remove reliance on trailing slash towards windows support
|
|
23
19
|
const root = strip_end(root_dir, '/') + '/';
|
|
@@ -30,39 +26,20 @@ export const create_paths = (root_dir) => {
|
|
|
30
26
|
config: root + GRO_CONFIG_PATH,
|
|
31
27
|
};
|
|
32
28
|
};
|
|
33
|
-
export const
|
|
34
|
-
export const is_gro_id = (id) => id.startsWith(gro_paths.root);
|
|
35
|
-
// TODO maybe infer `p` for the functions that take in ids using `paths_from_id`?
|
|
29
|
+
export const infer_paths = (id) => (is_gro_id(id) ? gro_paths : paths);
|
|
30
|
+
export const is_gro_id = (id) => id.startsWith(strip_end(gro_paths.root, '/')); // strip `/` in case we're looking at the Gro root without a trailing slash
|
|
36
31
|
// '/home/me/app/src/foo/bar/baz.ts' → 'src/foo/bar/baz.ts'
|
|
37
|
-
export const to_root_path = (id, p =
|
|
32
|
+
export const to_root_path = (id, p = infer_paths(id)) => relative(p.root, id) || './';
|
|
38
33
|
// '/home/me/app/src/foo/bar/baz.ts' → 'foo/bar/baz.ts'
|
|
39
|
-
export const
|
|
34
|
+
export const path_id_to_base_path = (path_id, p = infer_paths(path_id)) => relative(p.source, path_id);
|
|
40
35
|
// TODO base_path is an obsolete concept, it was a remnant from forcing `src/`
|
|
41
36
|
// 'foo/bar/baz.ts' → '/home/me/app/src/foo/bar/baz.ts'
|
|
42
|
-
export const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const stripped = strip_start(strip_start(import_id, p.lib), GRO_DIST_DIR); // TODO hacky, needs more work to clarify related things
|
|
49
|
-
const lib_path = IS_THIS_GRO ? stripped : replace_extension(stripped, '.ts');
|
|
50
|
-
return lib_path;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return strip_start(import_id, p.lib);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
export const print_path = (path, p = paths, prefix = './') => {
|
|
57
|
-
const root_path = path === GRO_DIST_DIR ? 'gro' : to_root_path(path, p);
|
|
58
|
-
return gray(`${prefix}${root_path}`);
|
|
59
|
-
};
|
|
60
|
-
export const print_path_or_gro_path = (path, from_paths = paths) => {
|
|
61
|
-
const inferred_paths = paths_from_id(path);
|
|
62
|
-
if (from_paths === gro_paths || inferred_paths === from_paths) {
|
|
63
|
-
return print_path(path, inferred_paths, '');
|
|
64
|
-
}
|
|
65
|
-
return print_path(path, gro_paths, '');
|
|
37
|
+
export const base_path_to_path_id = (base_path, p = infer_paths(base_path)) => join(p.source, base_path);
|
|
38
|
+
export const print_path = (path, p = infer_paths(path)) => {
|
|
39
|
+
let final_path = strip_end(path, '/') === strip_end(GRO_DIST_DIR, '/') ? 'gro' : to_root_path(path, p);
|
|
40
|
+
final_path =
|
|
41
|
+
final_path === 'gro' ? final_path : final_path[0] === '.' ? final_path : './' + final_path;
|
|
42
|
+
return gray(final_path);
|
|
66
43
|
};
|
|
67
44
|
export const replace_extension = (path, new_extension) => {
|
|
68
45
|
const { length } = extname(path);
|
package/dist/paths.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { suite } from 'uvu';
|
|
2
2
|
import * as assert from 'uvu/assert';
|
|
3
3
|
import { resolve, join } from 'node:path';
|
|
4
|
-
import { create_paths, paths, gro_paths, is_gro_id, to_root_path,
|
|
4
|
+
import { create_paths, paths, gro_paths, is_gro_id, to_root_path, path_id_to_base_path, base_path_to_path_id, } from './paths.js';
|
|
5
5
|
/* test__create_paths */
|
|
6
6
|
const test__create_paths = suite('create_paths');
|
|
7
7
|
test__create_paths('basic behavior', () => {
|
|
@@ -27,23 +27,25 @@ test__is_gro_id.run();
|
|
|
27
27
|
const test__to_root_path = suite('to_root_path');
|
|
28
28
|
test__to_root_path('basic behavior', () => {
|
|
29
29
|
assert.is(to_root_path(resolve('foo/bar')), 'foo/bar');
|
|
30
|
+
assert.is(to_root_path(resolve('./')), './');
|
|
31
|
+
assert.is(to_root_path(resolve('./')), './');
|
|
30
32
|
});
|
|
31
33
|
test__to_root_path.run();
|
|
32
34
|
/* test__to_root_path */
|
|
33
|
-
/*
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
assert.is(
|
|
35
|
+
/* test__path_id_to_base_path */
|
|
36
|
+
const test__path_id_to_base_path = suite('path_id_to_base_path');
|
|
37
|
+
test__path_id_to_base_path('basic behavior', () => {
|
|
38
|
+
assert.is(path_id_to_base_path(resolve('src/foo/bar/baz.ts')), 'foo/bar/baz.ts');
|
|
37
39
|
});
|
|
38
|
-
|
|
39
|
-
/*
|
|
40
|
-
/*
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
assert.is(
|
|
40
|
+
test__path_id_to_base_path.run();
|
|
41
|
+
/* test__path_id_to_base_path */
|
|
42
|
+
/* test__base_path_to_path_id */
|
|
43
|
+
const test__base_path_to_path_id = suite('base_path_to_path_id');
|
|
44
|
+
test__base_path_to_path_id('basic behavior', () => {
|
|
45
|
+
assert.is(base_path_to_path_id('foo/bar/baz.ts'), resolve('src/foo/bar/baz.ts'));
|
|
44
46
|
});
|
|
45
|
-
|
|
46
|
-
assert.is(
|
|
47
|
+
test__base_path_to_path_id('does not change extension', () => {
|
|
48
|
+
assert.is(base_path_to_path_id('foo/bar/baz.js'), resolve('src/foo/bar/baz.js'));
|
|
47
49
|
});
|
|
48
|
-
|
|
49
|
-
/*
|
|
50
|
+
test__base_path_to_path_id.run();
|
|
51
|
+
/* test__base_path_to_path_id */
|
package/dist/plugin.d.ts
CHANGED
|
@@ -33,4 +33,4 @@ export declare class Plugins<T_Plugin_Context extends Plugin_Context> {
|
|
|
33
33
|
* @param name - @default new_plugin.name
|
|
34
34
|
* @returns `plugins` with `new_plugin` at the index of the plugin with `name`
|
|
35
35
|
*/
|
|
36
|
-
export declare const replace_plugin: <T_Plugins extends T_Plugin |
|
|
36
|
+
export declare const replace_plugin: <T_Plugins extends T_Plugin | null | Array<T_Plugin | null>, T_Plugin extends Plugin>(plugins: T_Plugins, new_plugin: Plugin, name?: string) => T_Plugin[];
|
package/dist/publish.task.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { spawn } from '@ryanatkn/belt/process.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { green, cyan } from 'kleur/colors';
|
|
4
|
+
import { existsSync } from 'node:fs';
|
|
4
5
|
import { Task_Error } from './task.js';
|
|
5
6
|
import { load_package_json, parse_repo_url } from './package_json.js';
|
|
6
7
|
import { find_cli, spawn_cli } from './cli.js';
|
|
7
|
-
import { exists } from './fs.js';
|
|
8
8
|
import { IS_THIS_GRO } from './paths.js';
|
|
9
9
|
import { has_sveltekit_library } from './sveltekit_helpers.js';
|
|
10
10
|
import { update_changelog } from './changelog.js';
|
|
@@ -58,7 +58,7 @@ export const task = {
|
|
|
58
58
|
if (IS_THIS_GRO) {
|
|
59
59
|
await spawn('npm', ['run', 'build']);
|
|
60
60
|
}
|
|
61
|
-
const changelog_exists =
|
|
61
|
+
const changelog_exists = existsSync(changelog);
|
|
62
62
|
if (!(await find_cli('changeset'))) {
|
|
63
63
|
throw new Task_Error('changeset command not found, install @changesets/cli locally or globally');
|
|
64
64
|
}
|
|
@@ -132,7 +132,7 @@ export const task = {
|
|
|
132
132
|
if (!npm_publish_result?.ok) {
|
|
133
133
|
throw new Task_Error('changeset publish failed - revert the version tag or run it again manually');
|
|
134
134
|
}
|
|
135
|
-
if (!changelog_exists && (
|
|
135
|
+
if (!changelog_exists && existsSync(changelog)) {
|
|
136
136
|
await spawn('git', ['add', changelog]);
|
|
137
137
|
}
|
|
138
138
|
await spawn('git', ['commit', '-a', '-m', `publish v${version}`]);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Task } from './task.js';
|
|
3
|
+
export declare const Args: z.ZodObject<{
|
|
4
|
+
_: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
5
|
+
}, "strict", z.ZodTypeAny, {
|
|
6
|
+
_: string[];
|
|
7
|
+
}, {
|
|
8
|
+
_?: string[] | undefined;
|
|
9
|
+
}>;
|
|
10
|
+
export type Args = z.infer<typeof Args>;
|
|
11
|
+
export declare const task: Task<Args>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TASK_FILE_SUFFIXES } from './task.js';
|
|
3
|
+
import { resolve_input_paths, to_input_paths } from './input_path.js';
|
|
4
|
+
export const Args = z
|
|
5
|
+
.object({
|
|
6
|
+
_: z.array(z.string(), { description: 'the input paths to resolve' }).default(['']),
|
|
7
|
+
})
|
|
8
|
+
.strict();
|
|
9
|
+
export const task = {
|
|
10
|
+
summary: 'diagnostic that logs the info resolved from the filesystem for the given input paths',
|
|
11
|
+
Args,
|
|
12
|
+
run: async ({ args, config, log }) => {
|
|
13
|
+
const { _ } = args;
|
|
14
|
+
log.info('raw input paths:', _);
|
|
15
|
+
const input_paths = to_input_paths(_);
|
|
16
|
+
log.info('input paths:', input_paths);
|
|
17
|
+
const { task_root_dirs } = config;
|
|
18
|
+
log.info('task root paths:', task_root_dirs);
|
|
19
|
+
const { resolved_input_paths, possible_paths_by_input_path, unmapped_input_paths } = await resolve_input_paths(input_paths, task_root_dirs, TASK_FILE_SUFFIXES);
|
|
20
|
+
log.info('resolved_input_paths:', resolved_input_paths);
|
|
21
|
+
log.info('possible_paths_by_input_path:', possible_paths_by_input_path);
|
|
22
|
+
log.info('unmapped_input_paths:', unmapped_input_paths);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Package_Json } from './package_json.js';
|
|
2
|
-
import {
|
|
3
|
-
export declare const resolve_node_specifier: (specifier: string, dir?: string, parent_url?: string, cache?: Record<string, Package_Json>, exports_key?: string) => Promise<
|
|
2
|
+
import type { Path_Id } from './path.js';
|
|
3
|
+
export declare const resolve_node_specifier: (specifier: string, dir?: string, parent_url?: string, cache?: Record<string, Package_Json>, exports_key?: string) => Promise<Path_Id>;
|
|
4
4
|
export interface Parsed_Node_Specifier {
|
|
5
5
|
name: string;
|
|
6
6
|
path: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
2
|
import { Package_Json, load_package_json } from './package_json.js';
|
|
3
|
-
import {
|
|
3
|
+
import { paths } from './paths.js';
|
|
4
4
|
import { NODE_MODULES_DIRNAME } from './path_constants.js';
|
|
5
5
|
export const resolve_node_specifier = async (specifier, dir = paths.root, parent_url, cache, exports_key = specifier.endsWith('.svelte') ? 'svelte' : 'default') => {
|
|
6
6
|
const parsed = parse_node_specifier(specifier);
|
|
@@ -13,8 +13,8 @@ export const resolve_node_specifier = async (specifier, dir = paths.root, parent
|
|
|
13
13
|
throw Error(`[ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath '${subpath}' is not defined by "exports" in ${package_dir}/package.json` +
|
|
14
14
|
(parent_url ? ` imported from ${parent_url}` : ''));
|
|
15
15
|
}
|
|
16
|
-
const
|
|
17
|
-
return
|
|
16
|
+
const path_id = join(package_dir, exported[exports_key]);
|
|
17
|
+
return path_id;
|
|
18
18
|
};
|
|
19
19
|
export const parse_node_specifier = (specifier) => {
|
|
20
20
|
let idx;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { extname, join, relative } from 'node:path';
|
|
1
|
+
import { extname, isAbsolute, join, relative } from 'node:path';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
2
3
|
import { replace_extension } from './paths.js';
|
|
3
|
-
import { exists } from './fs.js';
|
|
4
4
|
/**
|
|
5
5
|
* Maps a `path` import specifier relative to the `importer`,
|
|
6
6
|
* and infer the correct extension following Vite conventions.
|
|
@@ -11,41 +11,41 @@ import { exists } from './fs.js';
|
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
|
13
13
|
export const resolve_specifier = async (path, dir) => {
|
|
14
|
-
const
|
|
14
|
+
const absolute_path = isAbsolute(path) ? path : join(dir, path);
|
|
15
15
|
let mapped_path;
|
|
16
|
-
let
|
|
16
|
+
let path_id;
|
|
17
17
|
let namespace;
|
|
18
|
-
const ext = extname(
|
|
18
|
+
const ext = extname(absolute_path);
|
|
19
19
|
const is_js = ext === '.js';
|
|
20
20
|
const is_ts = ext === '.ts';
|
|
21
|
-
if (!is_js && !is_ts && (
|
|
21
|
+
if (!is_js && !is_ts && existsSync(absolute_path)) {
|
|
22
22
|
// unrecognized extension and the file exists
|
|
23
|
-
mapped_path =
|
|
24
|
-
|
|
23
|
+
mapped_path = absolute_path;
|
|
24
|
+
path_id = absolute_path;
|
|
25
25
|
}
|
|
26
26
|
else if (is_ts) {
|
|
27
27
|
// explicitly ts
|
|
28
|
-
mapped_path = replace_extension(
|
|
29
|
-
|
|
28
|
+
mapped_path = replace_extension(absolute_path, '.js');
|
|
29
|
+
path_id = absolute_path;
|
|
30
30
|
namespace = 'sveltekit_local_imports_ts';
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
// extensionless, or js that points to ts, or just js
|
|
34
|
-
const js_id = is_js ?
|
|
35
|
-
const ts_id = is_js ? replace_extension(
|
|
36
|
-
if (!(
|
|
34
|
+
const js_id = is_js ? absolute_path : absolute_path + '.js';
|
|
35
|
+
const ts_id = is_js ? replace_extension(absolute_path, '.ts') : absolute_path + '.ts';
|
|
36
|
+
if (!existsSync(ts_id) && existsSync(js_id)) {
|
|
37
37
|
mapped_path = js_id;
|
|
38
|
-
|
|
38
|
+
path_id = js_id;
|
|
39
39
|
namespace = 'sveltekit_local_imports_js';
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
42
|
mapped_path = js_id;
|
|
43
|
-
|
|
43
|
+
path_id = ts_id;
|
|
44
44
|
namespace = 'sveltekit_local_imports_ts';
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
let specifier = relative(dir, mapped_path);
|
|
48
48
|
if (specifier[0] !== '.')
|
|
49
49
|
specifier = './' + specifier;
|
|
50
|
-
return { specifier,
|
|
50
|
+
return { specifier, path_id, namespace };
|
|
51
51
|
};
|
|
@@ -7,59 +7,59 @@ const dir = paths.source + 'fixtures/';
|
|
|
7
7
|
test('resolves a specifier to a file that exists with an unknown file extension', async () => {
|
|
8
8
|
assert.equal(await resolve_specifier(join(dir, 'test_file.other.ext'), dir), {
|
|
9
9
|
specifier: './test_file.other.ext',
|
|
10
|
-
|
|
10
|
+
path_id: join(dir, 'test_file.other.ext'),
|
|
11
11
|
namespace: undefined,
|
|
12
12
|
});
|
|
13
13
|
});
|
|
14
14
|
test('resolves a ts specifier', async () => {
|
|
15
15
|
assert.equal(await resolve_specifier(join(dir, 'test_ts.ts'), dir), {
|
|
16
16
|
specifier: './test_ts.js',
|
|
17
|
-
|
|
17
|
+
path_id: join(dir, 'test_ts.ts'),
|
|
18
18
|
namespace: 'sveltekit_local_imports_ts',
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
test('resolves relative ts specifiers', async () => {
|
|
22
22
|
assert.equal(await resolve_specifier('./test_ts.ts', dir), {
|
|
23
23
|
specifier: './test_ts.js',
|
|
24
|
-
|
|
24
|
+
path_id: join(dir, 'test_ts.ts'),
|
|
25
25
|
namespace: 'sveltekit_local_imports_ts',
|
|
26
26
|
});
|
|
27
27
|
assert.equal(await resolve_specifier('./a/b/test_ts.ts', dir), {
|
|
28
28
|
specifier: './a/b/test_ts.js',
|
|
29
|
-
|
|
29
|
+
path_id: join(dir, 'a/b/test_ts.ts'),
|
|
30
30
|
namespace: 'sveltekit_local_imports_ts',
|
|
31
31
|
});
|
|
32
32
|
assert.equal(await resolve_specifier('../../test_ts.ts', dir), {
|
|
33
33
|
specifier: '../../test_ts.js',
|
|
34
|
-
|
|
34
|
+
path_id: join(dir, '../../test_ts.ts'),
|
|
35
35
|
namespace: 'sveltekit_local_imports_ts',
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
test('resolves an extensionless specifier', async () => {
|
|
39
39
|
assert.equal(await resolve_specifier(join(dir, 'test_ts'), dir), {
|
|
40
40
|
specifier: './test_ts.js',
|
|
41
|
-
|
|
41
|
+
path_id: join(dir, 'test_ts.ts'),
|
|
42
42
|
namespace: 'sveltekit_local_imports_ts',
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
45
|
test('resolves a js specifier', async () => {
|
|
46
46
|
assert.equal(await resolve_specifier(join(dir, 'test_js.js'), dir), {
|
|
47
47
|
specifier: './test_js.js',
|
|
48
|
-
|
|
48
|
+
path_id: join(dir, 'test_js.js'),
|
|
49
49
|
namespace: 'sveltekit_local_imports_js',
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
test('resolves a js specifier as ts for a file that does not exist', async () => {
|
|
53
53
|
assert.equal(await resolve_specifier(join(dir, 'test_missing.js'), dir), {
|
|
54
54
|
specifier: './test_missing.js',
|
|
55
|
-
|
|
55
|
+
path_id: join(dir, 'test_missing.ts'),
|
|
56
56
|
namespace: 'sveltekit_local_imports_ts',
|
|
57
57
|
});
|
|
58
58
|
});
|
|
59
59
|
test('resolves an extensionless specifier for a file that does not exist', async () => {
|
|
60
60
|
assert.equal(await resolve_specifier(join(dir, 'test_missing'), dir), {
|
|
61
61
|
specifier: './test_missing.js',
|
|
62
|
-
|
|
62
|
+
path_id: join(dir, 'test_missing.ts'),
|
|
63
63
|
namespace: 'sveltekit_local_imports_ts',
|
|
64
64
|
});
|
|
65
65
|
});
|
package/dist/run.task.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { green, cyan } from 'kleur/colors';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
3
4
|
import { Task_Error } from './task.js';
|
|
4
|
-
import { exists } from './fs.js';
|
|
5
5
|
import { resolve_gro_module_path, spawn_with_loader } from './gro_helpers.js';
|
|
6
6
|
export const Args = z
|
|
7
7
|
.object({
|
|
@@ -19,7 +19,7 @@ export const task = {
|
|
|
19
19
|
log.info(green('\n\nUsage: ') + cyan('gro run path/to/file.ts [...node_args]\n'));
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
if (!(
|
|
22
|
+
if (!existsSync(path)) {
|
|
23
23
|
throw new Task_Error('Cannot find file to run at path: ' + path);
|
|
24
24
|
}
|
|
25
25
|
const loader_path = await resolve_gro_module_path('loader.js');
|
package/dist/run_gen.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Timings } from '@ryanatkn/belt/timings.js';
|
|
2
|
+
import type { Logger } from '@ryanatkn/belt/log.js';
|
|
3
|
+
import { type Gen_Results, type Genfile_Module_Meta } from './gen.js';
|
|
3
4
|
import type { format_file as base_format_file } from './format_file.js';
|
|
4
5
|
import type { Gro_Config } from './config.js';
|
|
5
6
|
export declare const GEN_NO_PROD_MESSAGE = "gen runs only during development";
|
|
6
|
-
export declare const run_gen: (gen_modules:
|
|
7
|
-
export declare const to_gen_import_path: (id: string) => string;
|
|
7
|
+
export declare const run_gen: (gen_modules: Genfile_Module_Meta[], config: Gro_Config, log: Logger, timings: Timings, format_file?: typeof base_format_file) => Promise<Gen_Results>;
|
package/dist/run_gen.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { red } from 'kleur/colors';
|
|
2
2
|
import { print_error } from '@ryanatkn/belt/print.js';
|
|
3
|
-
import { Unreachable_Error } from '@ryanatkn/belt/error.js';
|
|
4
|
-
import { strip_end } from '@ryanatkn/belt/string.js';
|
|
5
|
-
import { GEN_SCHEMA_PATH_SUFFIX } from './gen_module.js';
|
|
6
3
|
import { to_gen_result, } from './gen.js';
|
|
7
|
-
import { print_path
|
|
4
|
+
import { print_path } from './paths.js';
|
|
5
|
+
import { sveltekit_config_global } from './sveltekit_config_global.js';
|
|
8
6
|
export const GEN_NO_PROD_MESSAGE = 'gen runs only during development';
|
|
9
7
|
export const run_gen = async (gen_modules, config, log, timings, format_file) => {
|
|
10
8
|
let input_count = 0;
|
|
@@ -15,18 +13,15 @@ export const run_gen = async (gen_modules, config, log, timings, format_file) =>
|
|
|
15
13
|
const { id } = module_meta;
|
|
16
14
|
const timing_for_module = timings.start(id);
|
|
17
15
|
// Perform code generation by calling `gen` on the module.
|
|
18
|
-
const gen_ctx = {
|
|
16
|
+
const gen_ctx = {
|
|
17
|
+
config,
|
|
18
|
+
sveltekit_config: sveltekit_config_global,
|
|
19
|
+
origin_id: id,
|
|
20
|
+
log,
|
|
21
|
+
};
|
|
19
22
|
let raw_gen_result;
|
|
20
23
|
try {
|
|
21
|
-
|
|
22
|
-
case 'basic': {
|
|
23
|
-
raw_gen_result = await module_meta.mod.gen(gen_ctx);
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
default: {
|
|
27
|
-
throw new Unreachable_Error(module_meta.type);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
24
|
+
raw_gen_result = await module_meta.mod.gen(gen_ctx);
|
|
30
25
|
}
|
|
31
26
|
catch (err) {
|
|
32
27
|
return {
|
|
@@ -70,5 +65,3 @@ export const run_gen = async (gen_modules, config, log, timings, format_file) =>
|
|
|
70
65
|
elapsed: timing_for_run_gen(),
|
|
71
66
|
};
|
|
72
67
|
};
|
|
73
|
-
// TODO configurable
|
|
74
|
-
export const to_gen_import_path = (id) => '$' + strip_end(source_id_to_base_path(id), GEN_SCHEMA_PATH_SUFFIX);
|
package/dist/run_gen.test.js
CHANGED
|
@@ -9,18 +9,17 @@ const log = new Logger('test__gen'); // TODO test logger?
|
|
|
9
9
|
/* test__gen */
|
|
10
10
|
const test__gen = suite('gen');
|
|
11
11
|
test__gen('basic behavior', async () => {
|
|
12
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const path_id_a = resolve('src/foo.gen.ts');
|
|
13
|
+
const path_id_bc = resolve('src/bar/bc');
|
|
14
14
|
let file_a;
|
|
15
15
|
let file_b;
|
|
16
16
|
let file_c1;
|
|
17
17
|
let file_c2;
|
|
18
18
|
const mod_a = {
|
|
19
|
-
|
|
20
|
-
id: source_id_a,
|
|
19
|
+
id: path_id_a,
|
|
21
20
|
mod: {
|
|
22
21
|
gen: async (ctx) => {
|
|
23
|
-
assert.is(ctx.origin_id,
|
|
22
|
+
assert.is(ctx.origin_id, path_id_a);
|
|
24
23
|
if (file_a)
|
|
25
24
|
throw Error('Already generated file_a');
|
|
26
25
|
file_a = {
|
|
@@ -32,8 +31,7 @@ test__gen('basic behavior', async () => {
|
|
|
32
31
|
},
|
|
33
32
|
};
|
|
34
33
|
const mod_b = {
|
|
35
|
-
|
|
36
|
-
id: join(source_id_bc, 'mod_b.gen.ts'),
|
|
34
|
+
id: join(path_id_bc, 'mod_b.gen.ts'),
|
|
37
35
|
mod: {
|
|
38
36
|
gen: async (ctx) => {
|
|
39
37
|
assert.is(ctx.origin_id, mod_b.id);
|
|
@@ -48,8 +46,7 @@ test__gen('basic behavior', async () => {
|
|
|
48
46
|
},
|
|
49
47
|
};
|
|
50
48
|
const mod_c = {
|
|
51
|
-
|
|
52
|
-
id: join(source_id_bc, 'mod_c.gen.ts'),
|
|
49
|
+
id: join(path_id_bc, 'mod_c.gen.ts'),
|
|
53
50
|
mod: {
|
|
54
51
|
gen: async (ctx) => {
|
|
55
52
|
assert.is(ctx.origin_id, mod_c.id);
|
|
@@ -121,15 +118,14 @@ test__gen('basic behavior', async () => {
|
|
|
121
118
|
]);
|
|
122
119
|
});
|
|
123
120
|
test__gen('failing gen function', async () => {
|
|
124
|
-
const
|
|
125
|
-
const
|
|
121
|
+
const path_id_a = resolve('src/foo.gen.ts');
|
|
122
|
+
const path_idB = resolve('src/bar/baz');
|
|
126
123
|
let file_b; // no file_a because it's never generated
|
|
127
124
|
let genError; // this error should be passed through to the result
|
|
128
125
|
// This is the failing gen module.
|
|
129
126
|
// It's ordered first to test that its failure doesn't cascade.
|
|
130
127
|
const mod_a = {
|
|
131
|
-
|
|
132
|
-
id: source_id_a,
|
|
128
|
+
id: path_id_a,
|
|
133
129
|
mod: {
|
|
134
130
|
gen: async () => {
|
|
135
131
|
genError = Error('This fails for testing');
|
|
@@ -138,8 +134,7 @@ test__gen('failing gen function', async () => {
|
|
|
138
134
|
},
|
|
139
135
|
};
|
|
140
136
|
const mod_b = {
|
|
141
|
-
|
|
142
|
-
id: join(source_idB, 'mod_b.gen.ts'),
|
|
137
|
+
id: join(path_idB, 'mod_b.gen.ts'),
|
|
143
138
|
mod: {
|
|
144
139
|
gen: async (ctx) => {
|
|
145
140
|
assert.is(ctx.origin_id, mod_b.id);
|
package/dist/run_task.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Timings } from '@ryanatkn/belt/timings.js';
|
|
2
2
|
import { type Args } from './args.js';
|
|
3
3
|
import type { invoke_task as base_invoke_task } from './invoke_task.js';
|
|
4
4
|
import type { Gro_Config } from './config.js';
|
|
5
|
+
import { type Task_Module_Meta } from './task.js';
|
|
5
6
|
export type Run_Task_Result = {
|
|
6
7
|
ok: true;
|
|
7
8
|
output: unknown;
|
package/dist/run_task.js
CHANGED
|
@@ -3,6 +3,7 @@ import { print_log_label, System_Logger } from '@ryanatkn/belt/log.js';
|
|
|
3
3
|
import { parse_args } from './args.js';
|
|
4
4
|
import { log_task_help } from './task_logging.js';
|
|
5
5
|
import { Task_Error } from './task.js';
|
|
6
|
+
import { sveltekit_config_global } from './sveltekit_config_global.js';
|
|
6
7
|
export const run_task = async (task_meta, unparsed_args, invoke_task, config, timings) => {
|
|
7
8
|
const { task } = task_meta.mod;
|
|
8
9
|
const log = new System_Logger(print_log_label(task_meta.name));
|
|
@@ -26,6 +27,7 @@ export const run_task = async (task_meta, unparsed_args, invoke_task, config, ti
|
|
|
26
27
|
output = await task.run({
|
|
27
28
|
args,
|
|
28
29
|
config,
|
|
30
|
+
sveltekit_config: sveltekit_config_global,
|
|
29
31
|
log,
|
|
30
32
|
timings,
|
|
31
33
|
invoke_task: (invoked_task_name, invoked_args, invoked_config) => invoke_task(invoked_task_name, invoked_args, invoked_config || config, timings),
|
package/dist/search_fs.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Path_Stats, Path_Filter } from './path.js';
|
|
1
|
+
import type { File_Filter, Resolved_Path, Path_Filter } from './path.js';
|
|
3
2
|
export interface Search_Fs_Options {
|
|
4
|
-
filter?: Path_Filter;
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
4
|
+
* One or more filter functions, any of which can short-circuit the search by returning `false`.
|
|
7
5
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
filter?: Path_Filter | Path_Filter[] | null;
|
|
7
|
+
/**
|
|
8
|
+
* An array of file suffixes to include.
|
|
9
|
+
*/
|
|
10
|
+
file_filter?: File_Filter | File_Filter[];
|
|
11
|
+
/**
|
|
12
|
+
* Pass `null` or `false` to speed things up at the cost of volatile ordering.
|
|
13
|
+
*/
|
|
14
|
+
sort?: boolean | null | ((a: Resolved_Path, b: Resolved_Path) => number);
|
|
15
|
+
/**
|
|
16
|
+
* Set to `false` to include directories.
|
|
17
|
+
*/
|
|
18
|
+
include_directories?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Sets the cwd for `dir` unless it's an absolute path or `null`.
|
|
21
|
+
*/
|
|
22
|
+
cwd?: string | null;
|
|
10
23
|
}
|
|
11
|
-
export declare const search_fs: (dir: string, options?: Search_Fs_Options) => Promise<
|
|
24
|
+
export declare const search_fs: (dir: string, options?: Search_Fs_Options) => Promise<Resolved_Path[]>;
|