@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.
Files changed (196) hide show
  1. package/README.md +1 -1
  2. package/dist/build.task.d.ts +2 -0
  3. package/dist/build.task.d.ts.map +1 -1
  4. package/dist/build.task.js +15 -11
  5. package/dist/build_cache.d.ts +4 -4
  6. package/dist/build_cache.d.ts.map +1 -1
  7. package/dist/build_cache.js +54 -44
  8. package/dist/changelog.d.ts +2 -2
  9. package/dist/changelog.d.ts.map +1 -1
  10. package/dist/changeset.task.js +11 -11
  11. package/dist/check.task.js +2 -2
  12. package/dist/child_process_logging.js +1 -1
  13. package/dist/clean.task.js +2 -2
  14. package/dist/clean_fs.d.ts +1 -1
  15. package/dist/clean_fs.d.ts.map +1 -1
  16. package/dist/clean_fs.js +3 -4
  17. package/dist/cli.d.ts +7 -7
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +11 -12
  20. package/dist/commit.task.js +2 -2
  21. package/dist/deploy.task.d.ts +7 -0
  22. package/dist/deploy.task.d.ts.map +1 -1
  23. package/dist/deploy.task.js +30 -17
  24. package/dist/disknode.d.ts +1 -1
  25. package/dist/disknode.d.ts.map +1 -1
  26. package/dist/esbuild_helpers.d.ts +1 -1
  27. package/dist/esbuild_helpers.d.ts.map +1 -1
  28. package/dist/esbuild_plugin_external_worker.d.ts +1 -1
  29. package/dist/esbuild_plugin_external_worker.d.ts.map +1 -1
  30. package/dist/esbuild_plugin_external_worker.js +1 -1
  31. package/dist/esbuild_plugin_svelte.js +4 -4
  32. package/dist/esbuild_plugin_sveltekit_local_imports.js +2 -2
  33. package/dist/esbuild_plugin_sveltekit_shim_alias.js +1 -1
  34. package/dist/filer.d.ts +4 -4
  35. package/dist/filer.d.ts.map +1 -1
  36. package/dist/filer.js +105 -54
  37. package/dist/format.task.js +1 -1
  38. package/dist/format_directory.d.ts +2 -2
  39. package/dist/format_directory.d.ts.map +1 -1
  40. package/dist/format_file.js +1 -1
  41. package/dist/gen.d.ts +5 -5
  42. package/dist/gen.d.ts.map +1 -1
  43. package/dist/gen.js +28 -22
  44. package/dist/gen.task.js +3 -3
  45. package/dist/gen_helpers.d.ts +3 -3
  46. package/dist/gen_helpers.d.ts.map +1 -1
  47. package/dist/github.d.ts +2 -2
  48. package/dist/github.d.ts.map +1 -1
  49. package/dist/github.js +1 -1
  50. package/dist/gro.config.default.js +1 -1
  51. package/dist/gro_config.d.ts +1 -1
  52. package/dist/gro_config.d.ts.map +1 -1
  53. package/dist/gro_config.js +4 -4
  54. package/dist/gro_helpers.d.ts +1 -1
  55. package/dist/gro_helpers.d.ts.map +1 -1
  56. package/dist/gro_helpers.js +1 -1
  57. package/dist/gro_plugin_gen.js +4 -4
  58. package/dist/gro_plugin_server.d.ts +2 -2
  59. package/dist/gro_plugin_server.d.ts.map +1 -1
  60. package/dist/gro_plugin_server.js +7 -7
  61. package/dist/gro_plugin_sveltekit_app.d.ts.map +1 -1
  62. package/dist/gro_plugin_sveltekit_app.js +40 -36
  63. package/dist/gro_plugin_sveltekit_library.js +3 -2
  64. package/dist/input_path.d.ts +5 -5
  65. package/dist/input_path.d.ts.map +1 -1
  66. package/dist/input_path.js +17 -15
  67. package/dist/invoke.js +2 -2
  68. package/dist/invoke_task.d.ts +2 -2
  69. package/dist/invoke_task.d.ts.map +1 -1
  70. package/dist/invoke_task.js +5 -5
  71. package/dist/lint.task.js +2 -2
  72. package/dist/loader.js +2 -2
  73. package/dist/modules.d.ts +3 -3
  74. package/dist/modules.d.ts.map +1 -1
  75. package/dist/modules.js +4 -4
  76. package/dist/package_json.d.ts +6 -6
  77. package/dist/package_json.d.ts.map +1 -1
  78. package/dist/package_json.js +14 -16
  79. package/dist/parse_exports.d.ts +4 -4
  80. package/dist/parse_exports.d.ts.map +1 -1
  81. package/dist/parse_exports_context.d.ts +1 -1
  82. package/dist/parse_exports_context.d.ts.map +1 -1
  83. package/dist/parse_imports.d.ts +2 -2
  84. package/dist/parse_imports.d.ts.map +1 -1
  85. package/dist/parse_imports.js +1 -1
  86. package/dist/paths.d.ts +1 -1
  87. package/dist/paths.d.ts.map +1 -1
  88. package/dist/paths.js +1 -1
  89. package/dist/publish.task.js +8 -8
  90. package/dist/reinstall.task.js +1 -1
  91. package/dist/release.task.js +1 -1
  92. package/dist/resolve.task.js +2 -2
  93. package/dist/resolve_specifier.d.ts +2 -2
  94. package/dist/resolve_specifier.d.ts.map +1 -1
  95. package/dist/resolve_specifier.js +5 -4
  96. package/dist/run.task.js +2 -2
  97. package/dist/run_gen.d.ts +2 -2
  98. package/dist/run_gen.d.ts.map +1 -1
  99. package/dist/run_gen.js +10 -9
  100. package/dist/run_task.d.ts +2 -2
  101. package/dist/run_task.d.ts.map +1 -1
  102. package/dist/run_task.js +4 -4
  103. package/dist/source_json.d.ts +5 -5
  104. package/dist/source_json.d.ts.map +1 -1
  105. package/dist/source_json.js +18 -17
  106. package/dist/svelte_config.js +1 -1
  107. package/dist/sveltekit_helpers.d.ts +3 -3
  108. package/dist/sveltekit_helpers.d.ts.map +1 -1
  109. package/dist/sveltekit_helpers.js +4 -4
  110. package/dist/sveltekit_shim_app_forms.js +1 -1
  111. package/dist/sveltekit_shim_app_navigation.js +1 -1
  112. package/dist/sveltekit_shim_app_paths.js +1 -1
  113. package/dist/sveltekit_shim_env.js +1 -1
  114. package/dist/sync.task.js +1 -1
  115. package/dist/task.d.ts +5 -5
  116. package/dist/task.d.ts.map +1 -1
  117. package/dist/task.js +5 -5
  118. package/dist/task_logging.d.ts +1 -1
  119. package/dist/task_logging.d.ts.map +1 -1
  120. package/dist/task_logging.js +2 -2
  121. package/dist/test.task.d.ts.map +1 -1
  122. package/dist/test.task.js +5 -4
  123. package/dist/typecheck.task.js +4 -4
  124. package/dist/upgrade.task.js +6 -6
  125. package/dist/watch_dir.d.ts +1 -1
  126. package/dist/watch_dir.d.ts.map +1 -1
  127. package/dist/watch_dir.js +2 -2
  128. package/package.json +8 -8
  129. package/src/lib/build.task.ts +16 -11
  130. package/src/lib/build_cache.ts +81 -65
  131. package/src/lib/changelog.ts +2 -2
  132. package/src/lib/changeset.task.ts +12 -12
  133. package/src/lib/check.task.ts +2 -2
  134. package/src/lib/child_process_logging.ts +1 -1
  135. package/src/lib/clean.task.ts +2 -2
  136. package/src/lib/clean_fs.ts +4 -4
  137. package/src/lib/cli.ts +18 -17
  138. package/src/lib/commit.task.ts +2 -2
  139. package/src/lib/deploy.task.ts +33 -16
  140. package/src/lib/disknode.ts +1 -1
  141. package/src/lib/esbuild_helpers.ts +1 -1
  142. package/src/lib/esbuild_plugin_external_worker.ts +3 -3
  143. package/src/lib/esbuild_plugin_svelte.ts +4 -4
  144. package/src/lib/esbuild_plugin_sveltekit_local_imports.ts +2 -2
  145. package/src/lib/esbuild_plugin_sveltekit_shim_alias.ts +1 -1
  146. package/src/lib/filer.ts +117 -58
  147. package/src/lib/format.task.ts +1 -1
  148. package/src/lib/format_directory.ts +2 -2
  149. package/src/lib/format_file.ts +1 -1
  150. package/src/lib/gen.task.ts +3 -3
  151. package/src/lib/gen.ts +56 -50
  152. package/src/lib/gen_helpers.ts +3 -3
  153. package/src/lib/github.ts +2 -2
  154. package/src/lib/gro.config.default.ts +1 -1
  155. package/src/lib/gro_config.ts +5 -5
  156. package/src/lib/gro_helpers.ts +1 -1
  157. package/src/lib/gro_plugin_gen.ts +4 -4
  158. package/src/lib/gro_plugin_server.ts +9 -9
  159. package/src/lib/gro_plugin_sveltekit_app.ts +44 -40
  160. package/src/lib/gro_plugin_sveltekit_library.ts +3 -3
  161. package/src/lib/input_path.ts +23 -24
  162. package/src/lib/invoke.ts +2 -2
  163. package/src/lib/invoke_task.ts +5 -5
  164. package/src/lib/lint.task.ts +2 -2
  165. package/src/lib/loader.ts +2 -2
  166. package/src/lib/modules.ts +7 -7
  167. package/src/lib/package_json.ts +19 -23
  168. package/src/lib/parse_exports.ts +4 -4
  169. package/src/lib/parse_exports_context.ts +2 -2
  170. package/src/lib/parse_imports.ts +3 -3
  171. package/src/lib/paths.ts +2 -2
  172. package/src/lib/publish.task.ts +8 -8
  173. package/src/lib/reinstall.task.ts +1 -1
  174. package/src/lib/release.task.ts +1 -1
  175. package/src/lib/resolve.task.ts +2 -2
  176. package/src/lib/resolve_specifier.ts +9 -5
  177. package/src/lib/run.task.ts +2 -2
  178. package/src/lib/run_gen.ts +18 -13
  179. package/src/lib/run_task.ts +6 -6
  180. package/src/lib/source_json.ts +26 -22
  181. package/src/lib/svelte_config.ts +1 -1
  182. package/src/lib/sveltekit_helpers.ts +7 -7
  183. package/src/lib/sveltekit_shim_app_forms.ts +1 -1
  184. package/src/lib/sveltekit_shim_app_navigation.ts +1 -1
  185. package/src/lib/sveltekit_shim_app_paths.ts +1 -1
  186. package/src/lib/sync.task.ts +1 -1
  187. package/src/lib/task.ts +16 -14
  188. package/src/lib/task_logging.ts +3 -3
  189. package/src/lib/test.task.ts +4 -3
  190. package/src/lib/typecheck.task.ts +4 -4
  191. package/src/lib/upgrade.task.ts +6 -6
  192. package/src/lib/watch_dir.ts +3 -3
  193. package/dist/search_fs.d.ts +0 -26
  194. package/dist/search_fs.d.ts.map +0 -1
  195. package/dist/search_fs.js +0 -52
  196. 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 '@ryanatkn/belt/function.js';
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 '@ryanatkn/belt/function.js';
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;
@@ -13,7 +13,7 @@ import type {
13
13
  asset as base_asset,
14
14
  resolveRoute as base_resolveRoute,
15
15
  } from '$app/paths';
16
- import {noop} from '@ryanatkn/belt/function.js';
16
+ import {noop} from '@fuzdev/fuz_util/function.js';
17
17
 
18
18
  export const assets = '';
19
19
  /** @deprecated */
@@ -1,5 +1,5 @@
1
1
  import {z} from 'zod';
2
- import {spawn} from '@ryanatkn/belt/process.js';
2
+ import {spawn} from '@fuzdev/fuz_util/process.js';
3
3
 
4
4
  import {TaskError, type Task} from './task.ts';
5
5
  import {sync_package_json} from './package_json.ts';
package/src/lib/task.ts CHANGED
@@ -1,11 +1,12 @@
1
- import type {Logger} from '@ryanatkn/belt/log.js';
2
- import {ensure_end, strip_end, strip_start} from '@ryanatkn/belt/string.js';
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 '@ryanatkn/belt/timings.js';
4
+ import type {Timings} from '@fuzdev/fuz_util/timings.js';
5
5
  import {styleText as st} from 'node:util';
6
- import type {Result} from '@ryanatkn/belt/result.js';
6
+ import type {Result} from '@fuzdev/fuz_util/result.js';
7
7
  import {isAbsolute, join, relative} from 'node:path';
8
- import type {PathId} from '@ryanatkn/belt/path.js';
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(resolved_input_paths, (id) =>
163
- search_fs(id, {
164
- filter: config.search_filters,
165
- file_filter: (p) => TASK_FILE_SUFFIXES.some((s) => p.endsWith(s)),
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
 
@@ -1,7 +1,7 @@
1
1
  import {styleText as st} from 'node:util';
2
- import type {Logger} from '@ryanatkn/belt/log.js';
3
- import {plural} from '@ryanatkn/belt/string.js';
4
- import {print_value} from '@ryanatkn/belt/print.js';
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';
@@ -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
- if (!has_dep(VITEST_CLI)) {
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 '@ryanatkn/belt/process.js';
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;
@@ -1,7 +1,7 @@
1
- import {spawn} from '@ryanatkn/belt/process.js';
1
+ import {spawn} from '@fuzdev/fuz_util/process.js';
2
2
  import {z} from 'zod';
3
- import {rmSync} from 'node:fs';
4
- import {GitOrigin, git_pull} from '@ryanatkn/belt/git.js';
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
- rmSync(node_modules_path, {recursive: true, force: true});
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
- rmSync(lockfile_path, {force: true});
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
 
@@ -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 '@ryanatkn/belt/async.js';
5
- import type {PathFilter} from '@ryanatkn/belt/path.js';
6
- import {EMPTY_OBJECT} from '@ryanatkn/belt/object.js';
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
 
@@ -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
@@ -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
- };
@@ -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
- };