kerria 0.3.2 → 0.3.4

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
@@ -37,7 +37,7 @@ interface UseSourceOptions<T = any> {
37
37
  }
38
38
  declare function useSource<C extends object>(kind: number, options: UseSourceOptions<C>): SourceInfo;
39
39
  //#endregion
40
- //#region src/core/processor.d.ts
40
+ //#region src/core/kerria.d.ts
41
41
  interface KerriaContext {
42
42
  sign: string;
43
43
  loadInfos: LoadInfo[];
@@ -49,4 +49,4 @@ declare function createKerria(sign: string, setup: (ctx: KerriaContext) => void)
49
49
  watch: () => Promise<void>;
50
50
  };
51
51
  //#endregion
52
- export { LoadInfo, SourceInfo, UseLoadOptions, createKerria, useCurrentContext, useLoad, useSource };
52
+ export { KerriaContext, LoadInfo, SourceInfo, UseLoadOptions, UseSourceOptions, createKerria, useCurrentContext, useLoad, useSource };
package/dist/index.js CHANGED
@@ -4,9 +4,8 @@ import { readFile, stat, writeFile } from "node:fs/promises";
4
4
  import chokidar from "chokidar";
5
5
  import consola from "consola";
6
6
  import * as pkg from "empathic/package";
7
- import { join, resolve } from "pathe";
7
+ import { dirname, join, resolve } from "pathe";
8
8
  import { glob } from "tinyglobby";
9
- import { dirname } from "node:path";
10
9
 
11
10
  //#region src/utils.ts
12
11
  const isDev = process.env.NODE_ENV === "development";
@@ -33,7 +32,7 @@ function writeJsonSync(path, data) {
33
32
  }
34
33
 
35
34
  //#endregion
36
- //#region src/core/processor.ts
35
+ //#region src/core/kerria.ts
37
36
  let currentContext = null;
38
37
  function useCurrentContext() {
39
38
  return currentContext;
@@ -93,12 +92,11 @@ function createKerria(sign, setup) {
93
92
  info.onCacheHit?.(cache);
94
93
  return false;
95
94
  }
96
- cache = { hash };
97
95
  const data = await info.parse(path, info);
98
96
  if (data !== null) {
99
97
  cache = {
100
- ...cache,
101
- ...data ?? {}
98
+ hash,
99
+ ...data
102
100
  };
103
101
  info.onCacheHit?.(cache);
104
102
  caches[path] = cache;
@@ -132,9 +130,9 @@ function createKerria(sign, setup) {
132
130
  //#region src/core/useLoad.ts
133
131
  function useLoad(name, options) {
134
132
  const ctx = useCurrentContext();
133
+ const { defaultValue = {}, onUpdate, beforeOutput } = options;
135
134
  const src = options.src ? resolve(options.src) : void 0;
136
135
  const out = resolve(options.out);
137
- const { defaultValue = {}, onUpdate, beforeOutput } = options;
138
136
  const info = {
139
137
  name,
140
138
  src,
@@ -155,10 +153,11 @@ function useLoad(name, options) {
155
153
  //#region src/core/useSource.ts
156
154
  function useSource(kind, options) {
157
155
  const ctx = useCurrentContext();
156
+ const { deep = true, skip = 0 } = options;
158
157
  const base = resolve(options.base);
159
158
  const dist = options.dist ? resolve(options.dist) : void 0;
160
159
  const folders = options.folders?.map((folder) => resolve(base, folder)) ?? [base];
161
- const patterns = folders.map((path) => resolve(path, (options.deep ? "**/*" : "*") + options.ext));
160
+ const patterns = folders.map((path) => resolve(path, (deep ? "**/*" : "*") + options.ext));
162
161
  const info = {
163
162
  ...options,
164
163
  kind,
@@ -166,11 +165,11 @@ function useSource(kind, options) {
166
165
  dist,
167
166
  folders,
168
167
  patterns,
169
- deep: options.deep ?? true,
170
- skip: options.skip ?? 0,
168
+ deep,
169
+ skip,
171
170
  filter(path) {
172
171
  const depth = path.split("/").length - folders[0].split("/").length;
173
- return info.skip < depth;
172
+ return skip < depth;
174
173
  },
175
174
  async output(path, data) {
176
175
  const outPath = path.replace(base, dist).replace(info.ext, ".json");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kerria",
3
3
  "type": "module",
4
- "version": "0.3.2",
4
+ "version": "0.3.4",
5
5
  "description": "Composable source processor",
6
6
  "author": "KazariEX",
7
7
  "license": "MIT",
@@ -19,18 +19,18 @@
19
19
  "dependencies": {
20
20
  "chokidar": "^4.0.3",
21
21
  "consola": "^3.4.2",
22
- "empathic": "^1.1.0",
22
+ "empathic": "^2.0.0",
23
23
  "pathe": "^2.0.3",
24
24
  "tinyglobby": "^0.2.14"
25
25
  },
26
26
  "devDependencies": {
27
- "@antfu/eslint-config": "^4.13.2",
28
- "@types/node": "^22.15.29",
27
+ "@antfu/eslint-config": "^4.16.2",
28
+ "@types/node": "^24.0.10",
29
29
  "@zinkawaii/eslint-config": "^0.3.0",
30
30
  "@zinkawaii/tsconfig": "^0.0.2",
31
- "bumpp": "^10.1.1",
32
- "eslint": "^9.28.0",
33
- "tsdown": "^0.12.5"
31
+ "bumpp": "^10.2.0",
32
+ "eslint": "^9.30.1",
33
+ "tsdown": "^0.12.9"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "tsdown",