kerria 0.3.4 → 0.4.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/core/useLoad.d.ts
2
- interface LoadInfo extends Omit<UseLoadOptions, "defaultValue" | "beforeOutput"> {
2
+ interface LoadInfo extends Omit<UseLoadOptions, "defaultValue" | "output"> {
3
3
  name: string;
4
4
  value: any;
5
5
  output: () => void;
@@ -8,8 +8,8 @@ interface UseLoadOptions {
8
8
  src?: string;
9
9
  out: string;
10
10
  defaultValue?: unknown;
11
- onUpdate?: (newVal: any, oldVal: any) => any;
12
- beforeOutput?: (val: any) => any;
11
+ update?: (newVal: any, oldVal: any) => any;
12
+ output?: (val: any) => any;
13
13
  }
14
14
  declare function useLoad(name: string, options: UseLoadOptions): LoadInfo;
15
15
  //#endregion
@@ -32,10 +32,10 @@ interface UseSourceOptions<T = any> {
32
32
  deep?: boolean;
33
33
  skip?: number;
34
34
  parse: (path: string, info: SourceInfo) => MaybePromise<T | null | void>;
35
+ cache?: (cache: T) => void;
35
36
  unlink?: (cache: T) => void;
36
- onCacheHit?: (cache: T) => void;
37
37
  }
38
- declare function useSource<C extends object>(kind: number, options: UseSourceOptions<C>): SourceInfo;
38
+ declare function useSource<T extends object>(kind: number, options: UseSourceOptions<T>): SourceInfo;
39
39
  //#endregion
40
40
  //#region src/core/kerria.d.ts
41
41
  interface KerriaContext {
package/dist/index.js CHANGED
@@ -78,7 +78,7 @@ function createKerria(sign, setup) {
78
78
  if (!info.src) continue;
79
79
  chokidar.watch(info.src, { ignoreInitial: true }).on("change", async () => {
80
80
  const newVal = await readJson(info.src);
81
- info.value = info.onUpdate?.(newVal, info.value) ?? newVal;
81
+ info.value = info.update?.(newVal, info.value) ?? newVal;
82
82
  info.output();
83
83
  consola.success(`[${sign}] Change "${info.src}"`);
84
84
  });
@@ -89,7 +89,7 @@ function createKerria(sign, setup) {
89
89
  const hash = createHash("md5").update(stats.mtimeMs.toString()).digest("hex");
90
90
  let cache = caches[path];
91
91
  if (isDev && cache?.hash === hash) {
92
- info.onCacheHit?.(cache);
92
+ info.cache?.(cache);
93
93
  return false;
94
94
  }
95
95
  const data = await info.parse(path, info);
@@ -98,7 +98,7 @@ function createKerria(sign, setup) {
98
98
  hash,
99
99
  ...data
100
100
  };
101
- info.onCacheHit?.(cache);
101
+ info.cache?.(cache);
102
102
  caches[path] = cache;
103
103
  } else unlink(path, info);
104
104
  return true;
@@ -130,7 +130,7 @@ function createKerria(sign, setup) {
130
130
  //#region src/core/useLoad.ts
131
131
  function useLoad(name, options) {
132
132
  const ctx = useCurrentContext();
133
- const { defaultValue = {}, onUpdate, beforeOutput } = options;
133
+ const { defaultValue = {}, update, output } = options;
134
134
  const src = options.src ? resolve(options.src) : void 0;
135
135
  const out = resolve(options.out);
136
136
  const info = {
@@ -138,14 +138,14 @@ function useLoad(name, options) {
138
138
  src,
139
139
  out,
140
140
  value: src ? readJsonSync(src) : defaultValue,
141
- onUpdate,
141
+ update,
142
142
  output() {
143
- const data = beforeOutput?.(info.value) ?? info.value;
143
+ const data = output?.(info.value) ?? info.value;
144
144
  writeJsonSync(out, data);
145
145
  }
146
146
  };
147
147
  ctx.loadInfos.push(info);
148
- onUpdate?.(info.value, void 0);
148
+ update?.(info.value, void 0);
149
149
  return info;
150
150
  }
151
151
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kerria",
3
3
  "type": "module",
4
- "version": "0.3.4",
4
+ "version": "0.4.0",
5
5
  "description": "Composable source processor",
6
6
  "author": "KazariEX",
7
7
  "license": "MIT",
@@ -24,13 +24,12 @@
24
24
  "tinyglobby": "^0.2.14"
25
25
  },
26
26
  "devDependencies": {
27
- "@antfu/eslint-config": "^4.16.2",
28
- "@types/node": "^24.0.10",
29
- "@zinkawaii/eslint-config": "^0.3.0",
27
+ "@types/node": "^24.3.0",
28
+ "@zinkawaii/eslint-config": "^0.4.1",
30
29
  "@zinkawaii/tsconfig": "^0.0.2",
31
- "bumpp": "^10.2.0",
32
- "eslint": "^9.30.1",
33
- "tsdown": "^0.12.9"
30
+ "bumpp": "^10.2.3",
31
+ "eslint": "^9.33.0",
32
+ "tsdown": "^0.14.1"
34
33
  },
35
34
  "scripts": {
36
35
  "build": "tsdown",