zone5 1.6.7 → 1.6.8

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/dist/config.d.ts CHANGED
@@ -46,6 +46,10 @@ declare const ConfigSchema: z.ZodObject<{
46
46
  }>>>;
47
47
  }, z.core.$strip>;
48
48
  export type ConfigType = z.infer<typeof ConfigSchema>;
49
+ /**
50
+ * Walk up directory tree looking for a file.
51
+ * Uses iterative approach instead of recursion for better performance.
52
+ */
49
53
  export declare const walkUntilFound: (path: string) => Promise<string | undefined>;
50
54
  export declare const load: (configDir?: string | undefined) => Promise<{
51
55
  base: {
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { access } from 'node:fs/promises';
2
- import { join, parse, relative, resolve } from 'node:path';
2
+ import { dirname, join, parse, relative, resolve } from 'node:path';
3
3
  import { cwd } from 'node:process';
4
4
  import { stringify } from 'smol-toml';
5
5
  import { z } from 'zod';
@@ -17,19 +17,27 @@ const ConfigSchema = z.object({
17
17
  processor: ProcessorConfigSchema.prefault({}),
18
18
  gallery: GalleryConfigSchema.prefault({}),
19
19
  });
20
+ /**
21
+ * Walk up directory tree looking for a file.
22
+ * Uses iterative approach instead of recursion for better performance.
23
+ */
20
24
  export const walkUntilFound = async (path) => {
21
- try {
22
- await access(path);
23
- return path;
24
- }
25
- catch {
26
- const parsed = parse(path);
27
- if (parsed.dir != '/') {
28
- const next = join(parsed.dir, '..', parsed.base);
29
- return await walkUntilFound(next);
25
+ let currentPath = path;
26
+ while (true) {
27
+ try {
28
+ await access(currentPath);
29
+ return currentPath;
30
+ }
31
+ catch {
32
+ const parentDir = dirname(dirname(currentPath));
33
+ const filename = parse(currentPath).base;
34
+ // Reached filesystem root
35
+ if (parentDir === dirname(currentPath)) {
36
+ return undefined;
37
+ }
38
+ currentPath = join(parentDir, filename);
30
39
  }
31
40
  }
32
- return undefined;
33
41
  };
34
42
  export const load = async (configDir = undefined) => {
35
43
  const tomlFile = await walkUntilFound(resolve(configDir || cwd(), '.zone5.toml'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zone5",
3
- "version": "1.6.7",
3
+ "version": "1.6.8",
4
4
  "repository": {
5
5
  "url": "https://github.com/cwygoda/zone5"
6
6
  },