@ryanatkn/gro 0.179.0 → 0.181.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 +1 -1
- package/dist/build.task.d.ts +2 -0
- package/dist/build.task.d.ts.map +1 -1
- package/dist/build.task.js +15 -11
- package/dist/build_cache.d.ts +4 -4
- package/dist/build_cache.d.ts.map +1 -1
- package/dist/build_cache.js +54 -44
- package/dist/changelog.d.ts +2 -2
- package/dist/changelog.d.ts.map +1 -1
- package/dist/changeset.task.js +11 -11
- package/dist/check.task.js +2 -2
- package/dist/child_process_logging.js +1 -1
- package/dist/clean.task.js +2 -2
- package/dist/clean_fs.d.ts +1 -1
- package/dist/clean_fs.d.ts.map +1 -1
- package/dist/clean_fs.js +3 -4
- package/dist/cli.d.ts +7 -7
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -12
- package/dist/commit.task.js +2 -2
- package/dist/deploy.task.d.ts +7 -0
- package/dist/deploy.task.d.ts.map +1 -1
- package/dist/deploy.task.js +30 -17
- package/dist/disknode.d.ts +1 -1
- package/dist/disknode.d.ts.map +1 -1
- package/dist/esbuild_helpers.d.ts +1 -1
- package/dist/esbuild_helpers.d.ts.map +1 -1
- package/dist/esbuild_plugin_external_worker.d.ts +1 -1
- package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
- package/dist/esbuild_plugin_external_worker.js +1 -1
- package/dist/esbuild_plugin_svelte.js +4 -4
- package/dist/esbuild_plugin_sveltekit_local_imports.js +2 -2
- package/dist/esbuild_plugin_sveltekit_shim_alias.js +1 -1
- package/dist/filer.d.ts +4 -4
- package/dist/filer.d.ts.map +1 -1
- package/dist/filer.js +105 -54
- package/dist/format.task.js +1 -1
- package/dist/format_directory.d.ts +2 -2
- package/dist/format_directory.d.ts.map +1 -1
- package/dist/format_file.js +1 -1
- package/dist/gen.d.ts +5 -5
- package/dist/gen.d.ts.map +1 -1
- package/dist/gen.js +28 -22
- package/dist/gen.task.js +3 -3
- package/dist/gen_helpers.d.ts +3 -3
- package/dist/gen_helpers.d.ts.map +1 -1
- package/dist/github.d.ts +2 -2
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +1 -1
- package/dist/gro.config.default.js +1 -1
- package/dist/gro_config.d.ts +1 -1
- package/dist/gro_config.d.ts.map +1 -1
- package/dist/gro_config.js +4 -4
- package/dist/gro_helpers.d.ts +1 -1
- package/dist/gro_helpers.d.ts.map +1 -1
- package/dist/gro_helpers.js +1 -1
- package/dist/gro_plugin_gen.js +4 -4
- package/dist/gro_plugin_server.d.ts +2 -2
- package/dist/gro_plugin_server.d.ts.map +1 -1
- package/dist/gro_plugin_server.js +7 -7
- package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
- package/dist/gro_plugin_sveltekit_app.js +40 -36
- package/dist/gro_plugin_sveltekit_library.js +3 -2
- package/dist/input_path.d.ts +5 -5
- package/dist/input_path.d.ts.map +1 -1
- package/dist/input_path.js +17 -15
- package/dist/invoke.js +2 -2
- package/dist/invoke_task.d.ts +2 -2
- package/dist/invoke_task.d.ts.map +1 -1
- package/dist/invoke_task.js +5 -5
- package/dist/lint.task.js +2 -2
- package/dist/loader.js +2 -2
- package/dist/modules.d.ts +3 -3
- package/dist/modules.d.ts.map +1 -1
- package/dist/modules.js +4 -4
- package/dist/package_json.d.ts +6 -6
- package/dist/package_json.d.ts.map +1 -1
- package/dist/package_json.js +14 -16
- package/dist/parse_exports.d.ts +4 -4
- package/dist/parse_exports.d.ts.map +1 -1
- package/dist/parse_exports_context.d.ts +1 -1
- package/dist/parse_exports_context.d.ts.map +1 -1
- package/dist/parse_imports.d.ts +2 -2
- package/dist/parse_imports.d.ts.map +1 -1
- package/dist/parse_imports.js +1 -1
- package/dist/paths.d.ts +1 -1
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +1 -1
- package/dist/publish.task.js +8 -8
- package/dist/reinstall.task.js +1 -1
- package/dist/release.task.js +1 -1
- package/dist/resolve.task.js +2 -2
- package/dist/resolve_specifier.d.ts +2 -2
- package/dist/resolve_specifier.d.ts.map +1 -1
- package/dist/resolve_specifier.js +5 -4
- package/dist/run.task.js +2 -2
- package/dist/run_gen.d.ts +2 -2
- package/dist/run_gen.d.ts.map +1 -1
- package/dist/run_gen.js +10 -9
- package/dist/run_task.d.ts +2 -2
- package/dist/run_task.d.ts.map +1 -1
- package/dist/run_task.js +4 -4
- package/dist/source_json.d.ts +5 -5
- package/dist/source_json.d.ts.map +1 -1
- package/dist/source_json.js +18 -17
- package/dist/svelte_config.js +1 -1
- package/dist/sveltekit_helpers.d.ts +3 -3
- package/dist/sveltekit_helpers.d.ts.map +1 -1
- package/dist/sveltekit_helpers.js +4 -4
- package/dist/sveltekit_shim_app_forms.js +1 -1
- package/dist/sveltekit_shim_app_navigation.js +1 -1
- package/dist/sveltekit_shim_app_paths.js +1 -1
- package/dist/sveltekit_shim_env.js +1 -1
- package/dist/sync.task.js +1 -1
- package/dist/task.d.ts +5 -5
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +5 -5
- package/dist/task_logging.d.ts +1 -1
- package/dist/task_logging.d.ts.map +1 -1
- package/dist/task_logging.js +2 -2
- package/dist/test.task.d.ts.map +1 -1
- package/dist/test.task.js +5 -4
- package/dist/typecheck.task.js +4 -4
- package/dist/upgrade.task.js +6 -6
- package/dist/watch_dir.d.ts +1 -1
- package/dist/watch_dir.d.ts.map +1 -1
- package/dist/watch_dir.js +2 -2
- package/package.json +8 -8
- package/src/lib/build.task.ts +16 -11
- package/src/lib/build_cache.ts +81 -65
- package/src/lib/changelog.ts +2 -2
- package/src/lib/changeset.task.ts +12 -12
- package/src/lib/check.task.ts +2 -2
- package/src/lib/child_process_logging.ts +1 -1
- package/src/lib/clean.task.ts +2 -2
- package/src/lib/clean_fs.ts +4 -4
- package/src/lib/cli.ts +18 -17
- package/src/lib/commit.task.ts +2 -2
- package/src/lib/deploy.task.ts +33 -16
- package/src/lib/disknode.ts +1 -1
- package/src/lib/esbuild_helpers.ts +1 -1
- package/src/lib/esbuild_plugin_external_worker.ts +3 -3
- package/src/lib/esbuild_plugin_svelte.ts +4 -4
- package/src/lib/esbuild_plugin_sveltekit_local_imports.ts +2 -2
- package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +1 -1
- package/src/lib/filer.ts +117 -58
- package/src/lib/format.task.ts +1 -1
- package/src/lib/format_directory.ts +2 -2
- package/src/lib/format_file.ts +1 -1
- package/src/lib/gen.task.ts +3 -3
- package/src/lib/gen.ts +56 -50
- package/src/lib/gen_helpers.ts +3 -3
- package/src/lib/github.ts +2 -2
- package/src/lib/gro.config.default.ts +1 -1
- package/src/lib/gro_config.ts +5 -5
- package/src/lib/gro_helpers.ts +1 -1
- package/src/lib/gro_plugin_gen.ts +4 -4
- package/src/lib/gro_plugin_server.ts +9 -9
- package/src/lib/gro_plugin_sveltekit_app.ts +44 -40
- package/src/lib/gro_plugin_sveltekit_library.ts +3 -3
- package/src/lib/input_path.ts +23 -24
- package/src/lib/invoke.ts +2 -2
- package/src/lib/invoke_task.ts +5 -5
- package/src/lib/lint.task.ts +2 -2
- package/src/lib/loader.ts +2 -2
- package/src/lib/modules.ts +7 -7
- package/src/lib/package_json.ts +19 -23
- package/src/lib/parse_exports.ts +4 -4
- package/src/lib/parse_exports_context.ts +2 -2
- package/src/lib/parse_imports.ts +3 -3
- package/src/lib/paths.ts +2 -2
- package/src/lib/publish.task.ts +8 -8
- package/src/lib/reinstall.task.ts +1 -1
- package/src/lib/release.task.ts +1 -1
- package/src/lib/resolve.task.ts +2 -2
- package/src/lib/resolve_specifier.ts +9 -5
- package/src/lib/run.task.ts +2 -2
- package/src/lib/run_gen.ts +18 -13
- package/src/lib/run_task.ts +6 -6
- package/src/lib/source_json.ts +26 -22
- package/src/lib/svelte_config.ts +1 -1
- package/src/lib/sveltekit_helpers.ts +7 -7
- package/src/lib/sveltekit_shim_app_forms.ts +1 -1
- package/src/lib/sveltekit_shim_app_navigation.ts +1 -1
- package/src/lib/sveltekit_shim_app_paths.ts +1 -1
- package/src/lib/sync.task.ts +1 -1
- package/src/lib/task.ts +16 -14
- package/src/lib/task_logging.ts +3 -3
- package/src/lib/test.task.ts +4 -3
- package/src/lib/typecheck.task.ts +4 -4
- package/src/lib/upgrade.task.ts +6 -6
- package/src/lib/watch_dir.ts +3 -3
- package/dist/search_fs.d.ts +0 -26
- package/dist/search_fs.d.ts.map +0 -1
- package/dist/search_fs.js +0 -52
- package/src/lib/search_fs.ts +0 -100
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
deserialize as base_deserialize,
|
|
7
7
|
enhance as base_enhance,
|
|
8
8
|
} from '$app/forms';
|
|
9
|
-
import {noop, noop_async} from '@
|
|
9
|
+
import {noop, noop_async} from '@fuzdev/fuz_util/function.js';
|
|
10
10
|
|
|
11
11
|
export const applyAction: typeof base_applyAction = noop_async;
|
|
12
12
|
export const deserialize: typeof base_deserialize = () => ({}) as any;
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
preloadCode as base_preloadCode,
|
|
12
12
|
preloadData as base_preloadData,
|
|
13
13
|
} from '$app/navigation';
|
|
14
|
-
import {noop, noop_async} from '@
|
|
14
|
+
import {noop, noop_async} from '@fuzdev/fuz_util/function.js';
|
|
15
15
|
|
|
16
16
|
export const afterNavigate: typeof base_afterNavigate = noop;
|
|
17
17
|
export const beforeNavigate: typeof base_beforeNavigate = noop;
|
package/src/lib/sync.task.ts
CHANGED
package/src/lib/task.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type {Logger} from '@
|
|
2
|
-
import {ensure_end, strip_end, strip_start} from '@
|
|
1
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
2
|
+
import {ensure_end, strip_end, strip_start} from '@fuzdev/fuz_util/string.js';
|
|
3
3
|
import type {z} from 'zod';
|
|
4
|
-
import type {Timings} from '@
|
|
4
|
+
import type {Timings} from '@fuzdev/fuz_util/timings.js';
|
|
5
5
|
import {styleText as st} from 'node:util';
|
|
6
|
-
import type {Result} from '@
|
|
6
|
+
import type {Result} from '@fuzdev/fuz_util/result.js';
|
|
7
7
|
import {isAbsolute, join, relative} from 'node:path';
|
|
8
|
-
import type {PathId} from '@
|
|
8
|
+
import type {PathId} from '@fuzdev/fuz_util/path.js';
|
|
9
|
+
import {fs_search} from '@fuzdev/fuz_util/fs.js';
|
|
9
10
|
|
|
10
11
|
import type {Args} from './args.ts';
|
|
11
12
|
import type {GroConfig} from './gro_config.ts';
|
|
@@ -18,7 +19,6 @@ import {
|
|
|
18
19
|
type ResolvedInputPath,
|
|
19
20
|
} from './input_path.ts';
|
|
20
21
|
import {GRO_DIST_DIR, print_path} from './paths.ts';
|
|
21
|
-
import {search_fs} from './search_fs.ts';
|
|
22
22
|
import {load_modules, type LoadModulesFailure, type ModuleMeta} from './modules.ts';
|
|
23
23
|
import type {Filer} from './filer.ts';
|
|
24
24
|
|
|
@@ -126,15 +126,15 @@ export type FindModulesFailure =
|
|
|
126
126
|
/**
|
|
127
127
|
* Finds modules from input paths. (see `src/lib/input_path.ts` for more)
|
|
128
128
|
*/
|
|
129
|
-
export const find_tasks = (
|
|
129
|
+
export const find_tasks = async (
|
|
130
130
|
input_paths: Array<InputPath>,
|
|
131
131
|
task_root_dirs: Array<PathId>,
|
|
132
132
|
config: GroConfig,
|
|
133
133
|
timings?: Timings,
|
|
134
|
-
): FindTasksResult => {
|
|
134
|
+
): Promise<FindTasksResult> => {
|
|
135
135
|
// Check which extension variation works - if it's a directory, prefer others first!
|
|
136
136
|
const timing_to_resolve_input_paths = timings?.start('resolve input paths');
|
|
137
|
-
const {resolved_input_paths, unmapped_input_paths} = resolve_input_paths(
|
|
137
|
+
const {resolved_input_paths, unmapped_input_paths} = await resolve_input_paths(
|
|
138
138
|
input_paths,
|
|
139
139
|
task_root_dirs,
|
|
140
140
|
TASK_FILE_SUFFIXES,
|
|
@@ -159,11 +159,13 @@ export const find_tasks = (
|
|
|
159
159
|
// Find all of the files for any directories.
|
|
160
160
|
const timing_to_resolve_input_files = timings?.start('resolve input files');
|
|
161
161
|
const {resolved_input_files, resolved_input_files_by_root_dir, input_directories_with_no_files} =
|
|
162
|
-
resolve_input_files(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
await resolve_input_files(
|
|
163
|
+
resolved_input_paths,
|
|
164
|
+
async (id) =>
|
|
165
|
+
await fs_search(id, {
|
|
166
|
+
filter: config.search_filters,
|
|
167
|
+
file_filter: (p) => TASK_FILE_SUFFIXES.some((s) => p.endsWith(s)),
|
|
168
|
+
}),
|
|
167
169
|
);
|
|
168
170
|
timing_to_resolve_input_files?.();
|
|
169
171
|
|
package/src/lib/task_logging.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {styleText as st} from 'node:util';
|
|
2
|
-
import type {Logger} from '@
|
|
3
|
-
import {plural} from '@
|
|
4
|
-
import {print_value} from '@
|
|
2
|
+
import type {Logger} from '@fuzdev/fuz_util/log.js';
|
|
3
|
+
import {plural} from '@fuzdev/fuz_util/string.js';
|
|
4
|
+
import {print_value} from '@fuzdev/fuz_util/print.js';
|
|
5
5
|
import {z} from 'zod';
|
|
6
6
|
|
|
7
7
|
import type {ArgSchema} from './args.ts';
|
package/src/lib/test.task.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {spawn_cli} from '@ryanatkn/gro/cli.js';
|
|
|
3
3
|
|
|
4
4
|
import {TaskError, type Task} from './task.ts';
|
|
5
5
|
import {find_cli} from './cli.ts';
|
|
6
|
-
import {has_dep} from './package_json.ts';
|
|
6
|
+
import {has_dep, load_package_json} from './package_json.ts';
|
|
7
7
|
import {serialize_args, to_implicit_forwarded_args} from './args.ts';
|
|
8
8
|
import {VITEST_CLI} from './constants.ts';
|
|
9
9
|
import {paths} from './paths.ts';
|
|
@@ -30,11 +30,12 @@ export const task: Task<Args> = {
|
|
|
30
30
|
run: async ({args}): Promise<void> => {
|
|
31
31
|
const {_: patterns, dir, fail_without_tests, t} = args;
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const package_json = await load_package_json();
|
|
34
|
+
if (!has_dep(VITEST_CLI, package_json)) {
|
|
34
35
|
throw new TaskError('no test runner found, install vitest');
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
if (!find_cli(VITEST_CLI)) {
|
|
38
|
+
if (!(await find_cli(VITEST_CLI))) {
|
|
38
39
|
throw new TaskError('vitest is a dependency but not installed; run `npm i`?');
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {print_spawn_result} from '@
|
|
1
|
+
import {print_spawn_result} from '@fuzdev/fuz_util/process.js';
|
|
2
2
|
import {z} from 'zod';
|
|
3
3
|
|
|
4
4
|
import {TaskError, type Task} from './task.ts';
|
|
@@ -37,10 +37,10 @@ export const task: Task<Args> = {
|
|
|
37
37
|
await sveltekit_sync_if_available();
|
|
38
38
|
|
|
39
39
|
// Prefer svelte-check if available.
|
|
40
|
-
const found_svelte_check_cli = find_cli(svelte_check_cli);
|
|
40
|
+
const found_svelte_check_cli = await find_cli(svelte_check_cli);
|
|
41
41
|
if (found_svelte_check_cli) {
|
|
42
42
|
const serialized = serialize_args(to_forwarded_args(svelte_check_cli));
|
|
43
|
-
const spawned = spawn_cli_process(found_svelte_check_cli, serialized, undefined, {
|
|
43
|
+
const spawned = await spawn_cli_process(found_svelte_check_cli, serialized, undefined, {
|
|
44
44
|
stdio: ['inherit', 'pipe', 'pipe'],
|
|
45
45
|
env: {...process.env, FORCE_COLOR: '1'}, // Needed for colors (maybe make an option)
|
|
46
46
|
});
|
|
@@ -61,7 +61,7 @@ export const task: Task<Args> = {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// Fall back to tsc.
|
|
64
|
-
const found_typescript_cli = find_cli(typescript_cli);
|
|
64
|
+
const found_typescript_cli = await find_cli(typescript_cli);
|
|
65
65
|
if (found_typescript_cli) {
|
|
66
66
|
const forwarded = to_forwarded_args(typescript_cli);
|
|
67
67
|
if (!forwarded.noEmit) forwarded.noEmit = true;
|
package/src/lib/upgrade.task.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {spawn} from '@
|
|
1
|
+
import {spawn} from '@fuzdev/fuz_util/process.js';
|
|
2
2
|
import {z} from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
import {GitOrigin, git_pull} from '@
|
|
3
|
+
import {rm} from 'node:fs/promises';
|
|
4
|
+
import {GitOrigin, git_pull} from '@fuzdev/fuz_util/git.js';
|
|
5
5
|
|
|
6
6
|
import {TaskError, type Task} from './task.ts';
|
|
7
7
|
import {extract_deps, load_package_json, type PackageJsonDep} from './package_json.ts';
|
|
@@ -75,15 +75,15 @@ export const task: Task<Args> = {
|
|
|
75
75
|
|
|
76
76
|
if (delete_node_modules) {
|
|
77
77
|
log.info(`deleting node_modules at `, node_modules_path);
|
|
78
|
-
|
|
78
|
+
await rm(node_modules_path, {recursive: true, force: true});
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
if (delete_lockfile) {
|
|
82
82
|
log.info(`deleting lockfile at`, lockfile_path);
|
|
83
|
-
|
|
83
|
+
await rm(lockfile_path, {force: true});
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
const package_json = load_package_json();
|
|
86
|
+
const package_json = await load_package_json();
|
|
87
87
|
|
|
88
88
|
const all_deps = extract_deps(package_json);
|
|
89
89
|
|
package/src/lib/watch_dir.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {watch, type ChokidarOptions, type FSWatcher, type Matcher} from 'chokidar';
|
|
2
2
|
import {relative} from 'node:path';
|
|
3
3
|
import {statSync} from 'node:fs';
|
|
4
|
-
import {create_deferred, type Deferred} from '@
|
|
5
|
-
import type {PathFilter} from '@
|
|
6
|
-
import {EMPTY_OBJECT} from '@
|
|
4
|
+
import {create_deferred, type Deferred} from '@fuzdev/fuz_util/async.js';
|
|
5
|
+
import type {PathFilter} from '@fuzdev/fuz_util/path.js';
|
|
6
|
+
import {EMPTY_OBJECT} from '@fuzdev/fuz_util/object.js';
|
|
7
7
|
|
|
8
8
|
const TMP_FILE_PATTERN = /\.tmp\./;
|
|
9
9
|
|
package/dist/search_fs.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { FileFilter, ResolvedPath, PathFilter } from '@ryanatkn/belt/path.js';
|
|
2
|
-
export interface SearchFsOptions {
|
|
3
|
-
/**
|
|
4
|
-
* One or more filter functions, any of which can short-circuit the search by returning `false`.
|
|
5
|
-
*/
|
|
6
|
-
filter?: PathFilter | Array<PathFilter>;
|
|
7
|
-
/**
|
|
8
|
-
* One or more file filter functions. Every filter must pass for a file to be included.
|
|
9
|
-
*/
|
|
10
|
-
file_filter?: FileFilter | Array<FileFilter>;
|
|
11
|
-
/**
|
|
12
|
-
* Pass `null` or `false` to speed things up at the cost of volatile ordering.
|
|
13
|
-
*/
|
|
14
|
-
sort?: boolean | null | ((a: ResolvedPath, b: ResolvedPath) => number);
|
|
15
|
-
/**
|
|
16
|
-
* Set to `true` to include directories. Defaults to `false`.
|
|
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;
|
|
23
|
-
}
|
|
24
|
-
export declare const search_fs: (dir: string, options?: SearchFsOptions) => Array<ResolvedPath>;
|
|
25
|
-
export declare const find_first_existing_file: (paths: Array<string>) => string | null;
|
|
26
|
-
//# sourceMappingURL=search_fs.d.ts.map
|
package/dist/search_fs.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search_fs.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/search_fs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,UAAU,EAAE,YAAY,EAAE,UAAU,EAAC,MAAM,wBAAwB,CAAC;AAEjF,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,MAAM,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IACxC;;OAEG;IACH,WAAW,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAC7C;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,KAAK,MAAM,CAAC,CAAC;IACvE;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB;AAED,eAAO,MAAM,SAAS,GACrB,KAAK,MAAM,EACX,UAAS,eAA8B,KACrC,KAAK,CAAC,YAAY,CAwBpB,CAAC;AAmCF,eAAO,MAAM,wBAAwB,GAAI,OAAO,KAAK,CAAC,MAAM,CAAC,KAAG,MAAM,GAAG,IAOxE,CAAC"}
|
package/dist/search_fs.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { EMPTY_OBJECT } from '@ryanatkn/belt/object.js';
|
|
2
|
-
import { to_array } from '@ryanatkn/belt/array.js';
|
|
3
|
-
import { ensure_end } from '@ryanatkn/belt/string.js';
|
|
4
|
-
import { isAbsolute, join } from 'node:path';
|
|
5
|
-
import { existsSync, readdirSync } from 'node:fs';
|
|
6
|
-
export const search_fs = (dir, options = EMPTY_OBJECT) => {
|
|
7
|
-
const { filter, file_filter, sort = default_sort, include_directories = false, cwd = process.cwd(), } = options;
|
|
8
|
-
const final_dir = ensure_end(cwd && !isAbsolute(dir) ? join(cwd, dir) : dir, '/');
|
|
9
|
-
const filters = !filter || (Array.isArray(filter) && !filter.length) ? undefined : to_array(filter);
|
|
10
|
-
const file_filters = !file_filter || (Array.isArray(file_filter) && !file_filter.length)
|
|
11
|
-
? undefined
|
|
12
|
-
: to_array(file_filter);
|
|
13
|
-
if (!existsSync(final_dir))
|
|
14
|
-
return [];
|
|
15
|
-
const paths = [];
|
|
16
|
-
crawl(final_dir, paths, filters, file_filters, include_directories, null);
|
|
17
|
-
return sort ? paths.sort(typeof sort === 'boolean' ? default_sort : sort) : paths;
|
|
18
|
-
};
|
|
19
|
-
const default_sort = (a, b) => a.path.localeCompare(b.path);
|
|
20
|
-
const crawl = (dir, paths, filters, file_filter, include_directories, base_dir) => {
|
|
21
|
-
// This sync version is significantly faster than using the `fs/promises` version -
|
|
22
|
-
// it doesn't parallelize but that's not the common case in Gro.
|
|
23
|
-
const dirents = readdirSync(dir, { withFileTypes: true });
|
|
24
|
-
for (const dirent of dirents) {
|
|
25
|
-
const { name, parentPath } = dirent;
|
|
26
|
-
const is_directory = dirent.isDirectory();
|
|
27
|
-
const id = parentPath + name;
|
|
28
|
-
const include = !filters || filters.every((f) => f(id, is_directory));
|
|
29
|
-
if (!include)
|
|
30
|
-
continue;
|
|
31
|
-
const path = base_dir === null ? name : base_dir + '/' + name;
|
|
32
|
-
if (is_directory) {
|
|
33
|
-
const dir_id = id + '/';
|
|
34
|
-
if (include_directories) {
|
|
35
|
-
paths.push({ path, id: dir_id, is_directory: true });
|
|
36
|
-
}
|
|
37
|
-
crawl(dir_id, paths, filters, file_filter, include_directories, path);
|
|
38
|
-
}
|
|
39
|
-
else if (!file_filter || file_filter.every((f) => f(id))) {
|
|
40
|
-
paths.push({ path, id, is_directory: false });
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return paths;
|
|
44
|
-
};
|
|
45
|
-
export const find_first_existing_file = (paths) => {
|
|
46
|
-
for (const path of paths) {
|
|
47
|
-
if (existsSync(path)) {
|
|
48
|
-
return path;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
};
|
package/src/lib/search_fs.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {EMPTY_OBJECT} from '@ryanatkn/belt/object.js';
|
|
2
|
-
import {to_array} from '@ryanatkn/belt/array.js';
|
|
3
|
-
import {ensure_end} from '@ryanatkn/belt/string.js';
|
|
4
|
-
import {isAbsolute, join} from 'node:path';
|
|
5
|
-
import {existsSync, readdirSync} from 'node:fs';
|
|
6
|
-
import type {FileFilter, ResolvedPath, PathFilter} from '@ryanatkn/belt/path.js';
|
|
7
|
-
|
|
8
|
-
export interface SearchFsOptions {
|
|
9
|
-
/**
|
|
10
|
-
* One or more filter functions, any of which can short-circuit the search by returning `false`.
|
|
11
|
-
*/
|
|
12
|
-
filter?: PathFilter | Array<PathFilter>;
|
|
13
|
-
/**
|
|
14
|
-
* One or more file filter functions. Every filter must pass for a file to be included.
|
|
15
|
-
*/
|
|
16
|
-
file_filter?: FileFilter | Array<FileFilter>;
|
|
17
|
-
/**
|
|
18
|
-
* Pass `null` or `false` to speed things up at the cost of volatile ordering.
|
|
19
|
-
*/
|
|
20
|
-
sort?: boolean | null | ((a: ResolvedPath, b: ResolvedPath) => number);
|
|
21
|
-
/**
|
|
22
|
-
* Set to `true` to include directories. Defaults to `false`.
|
|
23
|
-
*/
|
|
24
|
-
include_directories?: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Sets the cwd for `dir` unless it's an absolute path or `null`.
|
|
27
|
-
*/
|
|
28
|
-
cwd?: string | null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const search_fs = (
|
|
32
|
-
dir: string,
|
|
33
|
-
options: SearchFsOptions = EMPTY_OBJECT,
|
|
34
|
-
): Array<ResolvedPath> => {
|
|
35
|
-
const {
|
|
36
|
-
filter,
|
|
37
|
-
file_filter,
|
|
38
|
-
sort = default_sort,
|
|
39
|
-
include_directories = false,
|
|
40
|
-
cwd = process.cwd(),
|
|
41
|
-
} = options;
|
|
42
|
-
|
|
43
|
-
const final_dir = ensure_end(cwd && !isAbsolute(dir) ? join(cwd, dir) : dir, '/');
|
|
44
|
-
|
|
45
|
-
const filters =
|
|
46
|
-
!filter || (Array.isArray(filter) && !filter.length) ? undefined : to_array(filter);
|
|
47
|
-
const file_filters =
|
|
48
|
-
!file_filter || (Array.isArray(file_filter) && !file_filter.length)
|
|
49
|
-
? undefined
|
|
50
|
-
: to_array(file_filter);
|
|
51
|
-
|
|
52
|
-
if (!existsSync(final_dir)) return [];
|
|
53
|
-
|
|
54
|
-
const paths: Array<ResolvedPath> = [];
|
|
55
|
-
crawl(final_dir, paths, filters, file_filters, include_directories, null);
|
|
56
|
-
|
|
57
|
-
return sort ? paths.sort(typeof sort === 'boolean' ? default_sort : sort) : paths;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const default_sort = (a: ResolvedPath, b: ResolvedPath): number => a.path.localeCompare(b.path);
|
|
61
|
-
|
|
62
|
-
const crawl = (
|
|
63
|
-
dir: string,
|
|
64
|
-
paths: Array<ResolvedPath>,
|
|
65
|
-
filters: Array<PathFilter> | undefined,
|
|
66
|
-
file_filter: Array<FileFilter> | undefined,
|
|
67
|
-
include_directories: boolean,
|
|
68
|
-
base_dir: string | null,
|
|
69
|
-
): Array<ResolvedPath> => {
|
|
70
|
-
// This sync version is significantly faster than using the `fs/promises` version -
|
|
71
|
-
// it doesn't parallelize but that's not the common case in Gro.
|
|
72
|
-
const dirents = readdirSync(dir, {withFileTypes: true});
|
|
73
|
-
for (const dirent of dirents) {
|
|
74
|
-
const {name, parentPath} = dirent;
|
|
75
|
-
const is_directory = dirent.isDirectory();
|
|
76
|
-
const id = parentPath + name;
|
|
77
|
-
const include = !filters || filters.every((f) => f(id, is_directory));
|
|
78
|
-
if (!include) continue;
|
|
79
|
-
const path = base_dir === null ? name : base_dir + '/' + name;
|
|
80
|
-
if (is_directory) {
|
|
81
|
-
const dir_id = id + '/';
|
|
82
|
-
if (include_directories) {
|
|
83
|
-
paths.push({path, id: dir_id, is_directory: true});
|
|
84
|
-
}
|
|
85
|
-
crawl(dir_id, paths, filters, file_filter, include_directories, path);
|
|
86
|
-
} else if (!file_filter || file_filter.every((f) => f(id))) {
|
|
87
|
-
paths.push({path, id, is_directory: false});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return paths;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const find_first_existing_file = (paths: Array<string>): string | null => {
|
|
94
|
-
for (const path of paths) {
|
|
95
|
-
if (existsSync(path)) {
|
|
96
|
-
return path;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
};
|