@kubb/fabric-core 0.0.0-canary-20251021103113 → 0.0.0-canary-20251021135548
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/createFileParser-BD8yn0LT.cjs +14 -0
- package/dist/createFileParser-BD8yn0LT.cjs.map +1 -0
- package/dist/createFileParser-Cix3AMLd.js +8 -0
- package/dist/createFileParser-Cix3AMLd.js.map +1 -0
- package/dist/default-DCpuPmrL.js +10 -0
- package/dist/default-DCpuPmrL.js.map +1 -0
- package/dist/default-DNBu_jsL.cjs +15 -0
- package/dist/default-DNBu_jsL.cjs.map +1 -0
- package/dist/{defineApp-DKW3IRO8.d.cts → defineApp-BX0gsgY3.d.cts} +3 -11
- package/dist/{defineApp-Bg7JewJQ.d.ts → defineApp-DygRR8LS.d.ts} +3 -11
- package/dist/index.cjs +97 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -4
- package/dist/index.d.ts +51 -4
- package/dist/index.js +87 -31
- package/dist/index.js.map +1 -1
- package/dist/parsers/default.cjs +4 -0
- package/dist/parsers/default.d.cts +8 -0
- package/dist/parsers/default.d.ts +8 -0
- package/dist/parsers/default.js +4 -0
- package/dist/parsers/tsx.cjs +4 -2
- package/dist/parsers/tsx.d.cts +2 -2
- package/dist/parsers/tsx.d.ts +2 -2
- package/dist/parsers/tsx.js +3 -1
- package/dist/parsers/typescript.cjs +6 -5
- package/dist/parsers/typescript.d.cts +2 -2
- package/dist/parsers/typescript.d.ts +2 -2
- package/dist/parsers/typescript.js +2 -1
- package/dist/tsx-BSUaIML3.cjs +16 -0
- package/dist/tsx-BSUaIML3.cjs.map +1 -0
- package/dist/tsx-DBAk9dqS.js +11 -0
- package/dist/tsx-DBAk9dqS.js.map +1 -0
- package/dist/types-CkbelZaS.d.ts +15 -0
- package/dist/types-GueHciQ3.d.cts +15 -0
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{parser-CWB_OBtr.js → typescript-C60gWBu8.js} +4 -34
- package/dist/typescript-C60gWBu8.js.map +1 -0
- package/dist/{parser-QF8j8-pj.cjs → typescript-Z90jN87k.cjs} +5 -47
- package/dist/typescript-Z90jN87k.cjs.map +1 -0
- package/package.json +8 -1
- package/src/FileManager.ts +4 -196
- package/src/FileProcessor.ts +86 -0
- package/src/createFile.ts +167 -0
- package/src/defineApp.ts +7 -5
- package/src/index.ts +3 -1
- package/src/parsers/createFileParser.ts +5 -0
- package/src/parsers/default.ts +7 -0
- package/src/parsers/tsx.ts +1 -1
- package/src/parsers/types.ts +12 -0
- package/src/parsers/typescript.ts +1 -1
- package/src/utils/EventEmitter.ts +23 -0
- package/dist/parser-CWB_OBtr.js.map +0 -1
- package/dist/parser-D64DdV1v.d.cts +0 -21
- package/dist/parser-QF8j8-pj.cjs.map +0 -1
- package/dist/parser-yYqnryUV.d.ts +0 -21
- package/src/parsers/parser.ts +0 -56
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/parsers/createFileParser.ts
|
|
3
|
+
function createFileParser(parser) {
|
|
4
|
+
return parser;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
Object.defineProperty(exports, 'createFileParser', {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return createFileParser;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=createFileParser-BD8yn0LT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFileParser-BD8yn0LT.cjs","names":[],"sources":["../src/parsers/createFileParser.ts"],"sourcesContent":["import type { Parser } from './types.ts'\n\nexport function createFileParser<TMeta extends object = object>(parser: Parser<TMeta>): Parser<TMeta> {\n return parser\n}\n"],"mappings":";;AAEA,SAAgB,iBAAgD,QAAsC;AACpG,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFileParser-Cix3AMLd.js","names":[],"sources":["../src/parsers/createFileParser.ts"],"sourcesContent":["import type { Parser } from './types.ts'\n\nexport function createFileParser<TMeta extends object = object>(parser: Parser<TMeta>): Parser<TMeta> {\n return parser\n}\n"],"mappings":";AAEA,SAAgB,iBAAgD,QAAsC;AACpG,QAAO"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as createFileParser } from "./createFileParser-Cix3AMLd.js";
|
|
2
|
+
|
|
3
|
+
//#region src/parsers/default.ts
|
|
4
|
+
const defaultParser = createFileParser({ async print(file) {
|
|
5
|
+
return file.sources.map((item) => item.value).join("\n\n");
|
|
6
|
+
} });
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
export { defaultParser as t };
|
|
10
|
+
//# sourceMappingURL=default-DCpuPmrL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-DCpuPmrL.js","names":[],"sources":["../src/parsers/default.ts"],"sourcesContent":["import { createFileParser } from './createFileParser.ts'\n\nexport const defaultParser = createFileParser({\n async print(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgB,iBAAiB,EAC5C,MAAM,MAAM,MAAM;AAChB,QAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;GAE7D,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const require_createFileParser = require('./createFileParser-BD8yn0LT.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/parsers/default.ts
|
|
4
|
+
const defaultParser = require_createFileParser.createFileParser({ async print(file) {
|
|
5
|
+
return file.sources.map((item) => item.value).join("\n\n");
|
|
6
|
+
} });
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
Object.defineProperty(exports, 'defaultParser', {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return defaultParser;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=default-DNBu_jsL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-DNBu_jsL.cjs","names":["createFileParser"],"sources":["../src/parsers/default.ts"],"sourcesContent":["import { createFileParser } from './createFileParser.ts'\n\nexport const defaultParser = createFileParser({\n async print(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgBA,0CAAiB,EAC5C,MAAM,MAAM,MAAM;AAChB,QAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;GAE7D,CAAC"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { a as ResolvedFile, i as Path, n as File, t as Extname } from "./KubbFile-BrN7Wwp6.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/FileManager.d.ts
|
|
4
|
-
type WriteFilesProps = {
|
|
5
|
-
extension?: Record<Extname, Extname | ''>;
|
|
6
|
-
dryRun?: boolean;
|
|
7
|
-
};
|
|
8
4
|
declare class FileManager {
|
|
9
5
|
#private;
|
|
10
6
|
constructor();
|
|
@@ -13,11 +9,7 @@ declare class FileManager {
|
|
|
13
9
|
getByPath(path: Path): ResolvedFile | null;
|
|
14
10
|
deleteByPath(path: Path): void;
|
|
15
11
|
clear(): void;
|
|
16
|
-
|
|
17
|
-
processFiles({
|
|
18
|
-
dryRun,
|
|
19
|
-
extension
|
|
20
|
-
}: WriteFilesProps): Promise<Array<ResolvedFile>>;
|
|
12
|
+
get files(): Array<ResolvedFile>;
|
|
21
13
|
}
|
|
22
14
|
//#endregion
|
|
23
15
|
//#region src/defineApp.d.ts
|
|
@@ -49,7 +41,7 @@ interface App {
|
|
|
49
41
|
_component: Component;
|
|
50
42
|
render(): Promise<void>;
|
|
51
43
|
renderToString(): Promise<string>;
|
|
52
|
-
|
|
44
|
+
files: Array<ResolvedFile>;
|
|
53
45
|
use<Options>(plugin: Plugin<Options>, options: NoInfer<Options>): this;
|
|
54
46
|
write(options?: WriteOptions): Promise<void>;
|
|
55
47
|
addFile(...files: Array<File>): Promise<void>;
|
|
@@ -59,4 +51,4 @@ type DefineApp<TContext extends AppContext> = (rootComponent?: Component, option
|
|
|
59
51
|
declare function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext>;
|
|
60
52
|
//#endregion
|
|
61
53
|
export { FileManager as a, defineApp as i, AppContext as n, DefineApp as r, App as t };
|
|
62
|
-
//# sourceMappingURL=defineApp-
|
|
54
|
+
//# sourceMappingURL=defineApp-BX0gsgY3.d.cts.map
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { a as ResolvedFile, i as Path, n as File, t as Extname } from "./KubbFile-BzVkcu9M.js";
|
|
2
2
|
|
|
3
3
|
//#region src/FileManager.d.ts
|
|
4
|
-
type WriteFilesProps = {
|
|
5
|
-
extension?: Record<Extname, Extname | ''>;
|
|
6
|
-
dryRun?: boolean;
|
|
7
|
-
};
|
|
8
4
|
declare class FileManager {
|
|
9
5
|
#private;
|
|
10
6
|
constructor();
|
|
@@ -13,11 +9,7 @@ declare class FileManager {
|
|
|
13
9
|
getByPath(path: Path): ResolvedFile | null;
|
|
14
10
|
deleteByPath(path: Path): void;
|
|
15
11
|
clear(): void;
|
|
16
|
-
|
|
17
|
-
processFiles({
|
|
18
|
-
dryRun,
|
|
19
|
-
extension
|
|
20
|
-
}: WriteFilesProps): Promise<Array<ResolvedFile>>;
|
|
12
|
+
get files(): Array<ResolvedFile>;
|
|
21
13
|
}
|
|
22
14
|
//#endregion
|
|
23
15
|
//#region src/defineApp.d.ts
|
|
@@ -49,7 +41,7 @@ interface App {
|
|
|
49
41
|
_component: Component;
|
|
50
42
|
render(): Promise<void>;
|
|
51
43
|
renderToString(): Promise<string>;
|
|
52
|
-
|
|
44
|
+
files: Array<ResolvedFile>;
|
|
53
45
|
use<Options>(plugin: Plugin<Options>, options: NoInfer<Options>): this;
|
|
54
46
|
write(options?: WriteOptions): Promise<void>;
|
|
55
47
|
addFile(...files: Array<File>): Promise<void>;
|
|
@@ -59,4 +51,4 @@ type DefineApp<TContext extends AppContext> = (rootComponent?: Component, option
|
|
|
59
51
|
declare function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext>;
|
|
60
52
|
//#endregion
|
|
61
53
|
export { FileManager as a, defineApp as i, AppContext as n, DefineApp as r, App as t };
|
|
62
|
-
//# sourceMappingURL=defineApp-
|
|
54
|
+
//# sourceMappingURL=defineApp-DygRR8LS.d.ts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const require_typescript = require('./typescript-Z90jN87k.cjs');
|
|
2
|
+
const require_createFileParser = require('./createFileParser-BD8yn0LT.cjs');
|
|
3
|
+
const require_tsx = require('./tsx-BSUaIML3.cjs');
|
|
4
|
+
const require_default = require('./default-DNBu_jsL.cjs');
|
|
4
5
|
let node_path = require("node:path");
|
|
5
|
-
node_path =
|
|
6
|
-
let node_crypto = require("node:crypto");
|
|
7
|
-
node_crypto = require_parser.__toESM(node_crypto);
|
|
6
|
+
node_path = require_typescript.__toESM(node_path);
|
|
8
7
|
let natural_orderby = require("natural-orderby");
|
|
9
|
-
natural_orderby =
|
|
8
|
+
natural_orderby = require_typescript.__toESM(natural_orderby);
|
|
9
|
+
let node_crypto = require("node:crypto");
|
|
10
|
+
node_crypto = require_typescript.__toESM(node_crypto);
|
|
10
11
|
let remeda = require("remeda");
|
|
11
|
-
remeda =
|
|
12
|
+
remeda = require_typescript.__toESM(remeda);
|
|
13
|
+
let node_events = require("node:events");
|
|
14
|
+
node_events = require_typescript.__toESM(node_events);
|
|
15
|
+
let p_limit = require("p-limit");
|
|
16
|
+
p_limit = require_typescript.__toESM(p_limit);
|
|
12
17
|
|
|
13
18
|
//#region \0@oxc-project+runtime@0.95.0/helpers/checkPrivateRedeclaration.js
|
|
14
19
|
function _checkPrivateRedeclaration(e, t) {
|
|
@@ -64,19 +69,11 @@ var Cache = class {
|
|
|
64
69
|
};
|
|
65
70
|
|
|
66
71
|
//#endregion
|
|
67
|
-
//#region src/
|
|
72
|
+
//#region src/createFile.ts
|
|
68
73
|
function hashObject(obj) {
|
|
69
74
|
const str = JSON.stringify(obj, Object.keys(obj).sort());
|
|
70
75
|
return (0, node_crypto.createHash)("sha256").update(str).digest("hex");
|
|
71
76
|
}
|
|
72
|
-
function mergeFile(a, b) {
|
|
73
|
-
return {
|
|
74
|
-
...a,
|
|
75
|
-
sources: [...a.sources || [], ...b.sources || []],
|
|
76
|
-
imports: [...a.imports || [], ...b.imports || []],
|
|
77
|
-
exports: [...a.exports || [], ...b.exports || []]
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
77
|
function combineSources(sources) {
|
|
81
78
|
return (0, remeda.uniqueBy)(sources, (obj) => [
|
|
82
79
|
obj.name,
|
|
@@ -155,7 +152,7 @@ function createFile(file) {
|
|
|
155
152
|
return {
|
|
156
153
|
...file,
|
|
157
154
|
id: hashObject({ path: file.path }),
|
|
158
|
-
name:
|
|
155
|
+
name: require_typescript.trimExtName(file.baseName),
|
|
159
156
|
extname,
|
|
160
157
|
imports,
|
|
161
158
|
exports: exports$1,
|
|
@@ -163,12 +160,21 @@ function createFile(file) {
|
|
|
163
160
|
meta: file.meta || {}
|
|
164
161
|
};
|
|
165
162
|
}
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/FileManager.ts
|
|
166
|
+
function mergeFile(a, b) {
|
|
167
|
+
return {
|
|
168
|
+
...a,
|
|
169
|
+
sources: [...a.sources || [], ...b.sources || []],
|
|
170
|
+
imports: [...a.imports || [], ...b.imports || []],
|
|
171
|
+
exports: [...a.exports || [], ...b.exports || []]
|
|
172
|
+
};
|
|
173
|
+
}
|
|
166
174
|
var _cache = /* @__PURE__ */ new WeakMap();
|
|
167
|
-
var _limit = /* @__PURE__ */ new WeakMap();
|
|
168
175
|
var FileManager = class {
|
|
169
176
|
constructor() {
|
|
170
177
|
_classPrivateFieldInitSpec(this, _cache, new Cache());
|
|
171
|
-
_classPrivateFieldInitSpec(this, _limit, (0, p_limit.default)(100));
|
|
172
178
|
return this;
|
|
173
179
|
}
|
|
174
180
|
async add(...files) {
|
|
@@ -200,21 +206,71 @@ var FileManager = class {
|
|
|
200
206
|
clear() {
|
|
201
207
|
_classPrivateFieldGet2(_cache, this).clear();
|
|
202
208
|
}
|
|
203
|
-
|
|
204
|
-
return (0, natural_orderby.orderBy)(_classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) =>
|
|
209
|
+
get files() {
|
|
210
|
+
return (0, natural_orderby.orderBy)(_classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) => require_typescript.trimExtName(v).endsWith("index")]).map((key) => _classPrivateFieldGet2(_cache, this).get(key)).filter(Boolean);
|
|
205
211
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/utils/EventEmitter.ts
|
|
216
|
+
var _emitter = /* @__PURE__ */ new WeakMap();
|
|
217
|
+
var EventEmitter = class {
|
|
218
|
+
constructor(maxListener = 100) {
|
|
219
|
+
_classPrivateFieldInitSpec(this, _emitter, new node_events.EventEmitter());
|
|
220
|
+
_classPrivateFieldGet2(_emitter, this).setMaxListeners(maxListener);
|
|
221
|
+
}
|
|
222
|
+
emit(eventName, ...eventArg) {
|
|
223
|
+
_classPrivateFieldGet2(_emitter, this).emit(eventName, ...eventArg);
|
|
224
|
+
}
|
|
225
|
+
on(eventName, handler) {
|
|
226
|
+
_classPrivateFieldGet2(_emitter, this).on(eventName, handler);
|
|
227
|
+
}
|
|
228
|
+
off(eventName, handler) {
|
|
229
|
+
_classPrivateFieldGet2(_emitter, this).off(eventName, handler);
|
|
230
|
+
}
|
|
231
|
+
removeAll() {
|
|
232
|
+
_classPrivateFieldGet2(_emitter, this).removeAllListeners();
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/FileProcessor.ts
|
|
238
|
+
async function getParser(extname) {
|
|
239
|
+
const parsers = {
|
|
240
|
+
".ts": require_typescript.typeScriptParser,
|
|
241
|
+
".js": require_typescript.typeScriptParser,
|
|
242
|
+
".jsx": require_tsx.tsxParser,
|
|
243
|
+
".tsx": require_tsx.tsxParser,
|
|
244
|
+
".json": require_default.defaultParser
|
|
245
|
+
};
|
|
246
|
+
if (!extname) return require_default.defaultParser;
|
|
247
|
+
const parser = parsers[extname];
|
|
248
|
+
if (!parser) console.warn(`[parser] No parser found for ${extname}, default parser will be used`);
|
|
249
|
+
return parser || require_default.defaultParser;
|
|
250
|
+
}
|
|
251
|
+
async function parseFile(file, { extname } = {}) {
|
|
252
|
+
return (await getParser(file.extname)).print(file, { extname });
|
|
253
|
+
}
|
|
254
|
+
var _limit = /* @__PURE__ */ new WeakMap();
|
|
255
|
+
var FileProcessor = class extends EventEmitter {
|
|
256
|
+
constructor(maxListener = 1e3) {
|
|
257
|
+
super(maxListener);
|
|
258
|
+
_classPrivateFieldInitSpec(this, _limit, (0, p_limit.default)(100));
|
|
259
|
+
return this;
|
|
260
|
+
}
|
|
261
|
+
async run(files, { dryRun, extension }) {
|
|
262
|
+
this.emit("start", { files });
|
|
263
|
+
const promises = files.map((resolvedFile) => _classPrivateFieldGet2(_limit, this).call(this, async () => {
|
|
264
|
+
const extname = (extension === null || extension === void 0 ? void 0 : extension[resolvedFile.extname]) || void 0;
|
|
265
|
+
this.emit("file:start", { file: resolvedFile });
|
|
266
|
+
if (!dryRun) {
|
|
267
|
+
const source = await parseFile(resolvedFile, { extname });
|
|
268
|
+
await require_typescript.write(resolvedFile.path, source, { sanity: false });
|
|
269
|
+
}
|
|
270
|
+
this.emit("file:finish", { file: resolvedFile });
|
|
271
|
+
}));
|
|
217
272
|
await Promise.all(promises);
|
|
273
|
+
this.emit("finish", { files });
|
|
218
274
|
return files;
|
|
219
275
|
}
|
|
220
276
|
};
|
|
@@ -226,6 +282,7 @@ function defineApp(instance) {
|
|
|
226
282
|
function createApp$1(rootComponent, options) {
|
|
227
283
|
const installedPlugins = /* @__PURE__ */ new WeakSet();
|
|
228
284
|
const fileManager = new FileManager();
|
|
285
|
+
const fileProcessor = new FileProcessor();
|
|
229
286
|
const context = {
|
|
230
287
|
options,
|
|
231
288
|
fileManager,
|
|
@@ -236,7 +293,7 @@ function defineApp(instance) {
|
|
|
236
293
|
context.fileManager.clear();
|
|
237
294
|
},
|
|
238
295
|
get files() {
|
|
239
|
-
return fileManager.
|
|
296
|
+
return fileManager.files;
|
|
240
297
|
}
|
|
241
298
|
};
|
|
242
299
|
const { render, renderToString, waitUntilExit } = instance.call(context, rootComponent, context);
|
|
@@ -249,8 +306,8 @@ function defineApp(instance) {
|
|
|
249
306
|
async renderToString() {
|
|
250
307
|
return renderToString();
|
|
251
308
|
},
|
|
252
|
-
|
|
253
|
-
return fileManager.
|
|
309
|
+
get files() {
|
|
310
|
+
return fileManager.files;
|
|
254
311
|
},
|
|
255
312
|
waitUntilExit,
|
|
256
313
|
addFile: context.addFile,
|
|
@@ -258,7 +315,7 @@ function defineApp(instance) {
|
|
|
258
315
|
extension: { ".ts": ".ts" },
|
|
259
316
|
dryRun: false
|
|
260
317
|
}) {
|
|
261
|
-
await fileManager.
|
|
318
|
+
await fileProcessor.run(fileManager.files, {
|
|
262
319
|
extension: options$1.extension,
|
|
263
320
|
dryRun: options$1.dryRun
|
|
264
321
|
});
|
|
@@ -298,7 +355,9 @@ const createApp = defineApp(() => {
|
|
|
298
355
|
|
|
299
356
|
//#endregion
|
|
300
357
|
exports.FileManager = FileManager;
|
|
358
|
+
exports.FileProcessor = FileProcessor;
|
|
301
359
|
exports.createApp = createApp;
|
|
360
|
+
exports.createFile = createFile;
|
|
361
|
+
exports.createFileParser = require_createFileParser.createFileParser;
|
|
302
362
|
exports.defineApp = defineApp;
|
|
303
|
-
exports.parseFile = require_parser.parseFile;
|
|
304
363
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["exports","name","path","trimExtName","resolvedFiles: Array<KubbFile.ResolvedFile>","parseFile","write","createApp","app: App","options"],"sources":["../src/utils/Cache.ts","../src/FileManager.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import pLimit from 'p-limit'\n\nimport type * as KubbFile from './KubbFile.ts'\nimport { parseFile } from './parsers/parser.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName, write } from './fs.ts'\nimport { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { orderBy } from 'natural-orderby'\nimport { isDeepEqual, uniqueBy } from 'remeda'\n\ntype WriteFilesProps = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\nfunction hashObject(obj: Record<string, unknown>): string {\n const str = JSON.stringify(obj, Object.keys(obj).sort())\n return createHash('sha256').update(str).digest('hex')\n}\n\nexport function mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\nexport function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {\n return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly] as const)\n}\n\nexport function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {\n return orderBy(exports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n const name = curr.name\n const prevByPath = prev.findLast((imp) => imp.path === curr.path)\n const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (export type ...)\n return prev\n }\n\n const uniquePrev = prev.findLast(\n (imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,\n )\n\n // we already have an item that was unique enough or name field is empty or prev asAlias is set but current has no changes\n if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {\n return prev\n }\n\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name: Array.isArray(name) ? [...new Set(name)] : name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]\n\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Export>,\n )\n}\n\nexport function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {\n return orderBy(imports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name\n\n const hasImportInSource = (importName: string) => {\n if (!source) {\n return true\n }\n\n const checker = (name?: string) => {\n return name && source.includes(name)\n }\n\n return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))\n }\n\n if (curr.path === curr.root) {\n // root and path are the same file, remove the \"./\" import\n return prev\n }\n\n // merge all names and check if the importName is being used in the generated source and if not filter those imports out\n if (Array.isArray(name)) {\n name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))\n }\n\n const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)\n const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)\n const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathNameAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (import type ...)\n return prev\n }\n\n // already unique enough or name is empty\n if (uniquePrev || (Array.isArray(name) && !name.length)) {\n return prev\n }\n\n // new item, append name\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...name])]\n\n return prev\n }\n\n // no import was found in the source, ignore import\n if (!Array.isArray(name) && name && !hasImportInSource(name)) {\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Import>,\n )\n}\n\n/**\n * Helper to create a file with name and id set\n */\nexport function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta> {\n const extname = path.extname(file.baseName) as KubbFile.Extname\n if (!extname) {\n throw new Error(`No extname found for ${file.baseName}`)\n }\n\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n const exports = file.exports?.length ? combineExports(file.exports) : []\n const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : []\n const sources = file.sources?.length ? combineSources(file.sources) : []\n\n return {\n ...file,\n id: hashObject({ path: file.path }),\n name: trimExtName(file.baseName),\n extname,\n imports: imports,\n exports: exports,\n sources: sources,\n meta: file.meta || ({} as TMeta),\n }\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n #limit = pLimit(100)\n\n constructor() {\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n getFiles(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n\n async processFiles({ dryRun, extension }: WriteFilesProps): Promise<Array<KubbFile.ResolvedFile>> {\n const files = this.getFiles()\n\n const promises = files.map((resolvedFile) => {\n return this.#limit(async () => {\n const extname = extension ? extension[resolvedFile.extname] || undefined : resolvedFile.extname\n\n if (!dryRun) {\n const source = await parseFile(resolvedFile, { extname })\n\n await write(resolvedFile.path, source, { sanity: false })\n }\n })\n })\n\n await Promise.all(promises)\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { FileManager } from './FileManager.ts'\nimport { isPromise } from 'remeda'\n\nconst isFunction = (val: unknown): val is Function => typeof val === 'function'\n\ntype Component = any\n\ntype PluginInstallFunction<Options = any[]> = Options extends unknown[] ? (app: App, ...options: Options) => any : (app: App, options: Options) => any\n\nexport type ObjectPlugin<Options = any[]> = {\n install: PluginInstallFunction<Options>\n}\nexport type FunctionPlugin<Options = any[]> = PluginInstallFunction<Options> & Partial<ObjectPlugin<Options>>\n\ntype AppRenderer = {\n render(): Promise<void> | void\n renderToString(): Promise<string> | string\n waitUntilExit(): Promise<void>\n}\n\nexport type AppContext<TOptions = unknown> = {\n options?: TOptions\n fileManager: FileManager\n addFile(...files: Array<KubbFile.File>): Promise<void>\n files: Array<KubbFile.ResolvedFile>\n clear: () => void\n}\n\ntype RootRenderFunction<THostElement, TContext extends AppContext> = (this: TContext, container: THostElement, context: TContext) => AppRenderer\n\ntype Plugin<Options = any[], P extends unknown[] = Options extends unknown[] ? Options : [Options]> = FunctionPlugin<P> | ObjectPlugin<P>\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\nexport interface App {\n _component: Component\n render(): Promise<void>\n renderToString(): Promise<string>\n getFiles(): Promise<Array<KubbFile.ResolvedFile>>\n use<Options>(plugin: Plugin<Options>, options: NoInfer<Options>): this\n write(options?: WriteOptions): Promise<void>\n addFile(...files: Array<KubbFile.File>): Promise<void>\n waitUntilExit(): Promise<void>\n}\n\nexport type DefineApp<TContext extends AppContext> = (rootComponent?: Component, options?: TContext['options']) => App\n\nexport function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext> {\n function createApp(rootComponent: Component, options?: TContext['options']): App {\n const installedPlugins = new WeakSet()\n const fileManager = new FileManager()\n const context = {\n options,\n fileManager,\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n clear() {\n context.fileManager.clear()\n },\n get files() {\n return fileManager.getFiles()\n },\n } as TContext\n\n const { render, renderToString, waitUntilExit } = instance.call(context, rootComponent, context)\n\n const app: App = {\n _component: rootComponent,\n async render() {\n if (isPromise(render)) {\n await render()\n } else {\n render()\n }\n },\n async renderToString() {\n return renderToString()\n },\n async getFiles() {\n return fileManager.getFiles()\n },\n waitUntilExit,\n addFile: context.addFile,\n async write(\n options = {\n extension: { '.ts': '.ts' },\n dryRun: false,\n },\n ) {\n await fileManager.processFiles({\n extension: options.extension,\n dryRun: options.dryRun,\n })\n },\n use(plugin: Plugin, ...options: any[]) {\n if (installedPlugins.has(plugin)) {\n console.warn('Plugin has already been applied to target app.')\n } else if (plugin && isFunction(plugin.install)) {\n installedPlugins.add(plugin)\n plugin.install(app, ...options)\n } else if (isFunction(plugin)) {\n installedPlugins.add(plugin)\n plugin(app, ...options)\n }\n\n return app\n },\n }\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp(() => {\n return {\n async render() {\n throw new Error('Method not implemented')\n },\n async renderToString() {\n throw new Error('Method not implemented')\n },\n async waitUntilExit() {\n throw new Error('Method not implemented')\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,6DAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,uCAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,uCAAY,CAAC,OAAO,IAAI;;CAG1B,QAA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AAQ;IACT,EACD;AACA,UAAM,YAAY,aAAa;KAC7B,WAAWC,UAAQ;KACnB,QAAQA,UAAQ;KACjB,CAAC;;GAEJ,IAAI,QAAgB,GAAGA,WAAgB;AACrC,QAAI,iBAAiB,IAAI,OAAO,CAC9B,SAAQ,KAAK,iDAAiD;aACrD,UAAU,WAAW,OAAO,QAAQ,EAAE;AAC/C,sBAAiB,IAAI,OAAO;AAC5B,YAAO,QAAQ,KAAK,GAAGA,UAAQ;eACtB,WAAW,OAAO,EAAE;AAC7B,sBAAiB,IAAI,OAAO;AAC5B,YAAO,KAAK,GAAGA,UAAQ;;AAGzB,WAAO;;GAEV;AAED,SAAO;;AAGT,QAAOF;;;;;ACnHT,MAAa,YAAY,gBAAgB;AACvC,QAAO;EACL,MAAM,SAAS;AACb,SAAM,IAAI,MAAM,yBAAyB;;EAE3C,MAAM,iBAAiB;AACrB,SAAM,IAAI,MAAM,yBAAyB;;EAE3C,MAAM,gBAAgB;AACpB,SAAM,IAAI,MAAM,yBAAyB;;EAE5C;EACD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["exports","name","path","trimExtName","resolvedFiles: Array<KubbFile.ResolvedFile>","path","trimExtName","NodeEventEmitter","parsers: Record<KubbFile.Extname, Parser<any>>","typeScriptParser","tsxParser","defaultParser","write","createApp","app: App","options"],"sources":["../src/utils/Cache.ts","../src/createFile.ts","../src/FileManager.ts","../src/utils/EventEmitter.ts","../src/FileProcessor.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { trimExtName } from './fs.ts'\nimport { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { isDeepEqual, uniqueBy } from 'remeda'\nimport { orderBy } from 'natural-orderby'\n\nfunction hashObject(obj: Record<string, unknown>): string {\n const str = JSON.stringify(obj, Object.keys(obj).sort())\n return createHash('sha256').update(str).digest('hex')\n}\n\nexport function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {\n return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly] as const)\n}\n\nexport function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {\n return orderBy(exports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n const name = curr.name\n const prevByPath = prev.findLast((imp) => imp.path === curr.path)\n const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (export type ...)\n return prev\n }\n\n const uniquePrev = prev.findLast(\n (imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,\n )\n\n // we already have an item that was unique enough or name field is empty or prev asAlias is set but current has no changes\n if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {\n return prev\n }\n\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name: Array.isArray(name) ? [...new Set(name)] : name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]\n\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Export>,\n )\n}\n\nexport function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {\n return orderBy(imports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name\n\n const hasImportInSource = (importName: string) => {\n if (!source) {\n return true\n }\n\n const checker = (name?: string) => {\n return name && source.includes(name)\n }\n\n return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))\n }\n\n if (curr.path === curr.root) {\n // root and path are the same file, remove the \"./\" import\n return prev\n }\n\n // merge all names and check if the importName is being used in the generated source and if not filter those imports out\n if (Array.isArray(name)) {\n name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))\n }\n\n const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)\n const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)\n const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathNameAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (import type ...)\n return prev\n }\n\n // already unique enough or name is empty\n if (uniquePrev || (Array.isArray(name) && !name.length)) {\n return prev\n }\n\n // new item, append name\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...name])]\n\n return prev\n }\n\n // no import was found in the source, ignore import\n if (!Array.isArray(name) && name && !hasImportInSource(name)) {\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Import>,\n )\n}\n\n/**\n * Helper to create a file with name and id set\n */\nexport function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta> {\n const extname = path.extname(file.baseName) as KubbFile.Extname\n if (!extname) {\n throw new Error(`No extname found for ${file.baseName}`)\n }\n\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n const exports = file.exports?.length ? combineExports(file.exports) : []\n const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : []\n const sources = file.sources?.length ? combineSources(file.sources) : []\n\n return {\n ...file,\n id: hashObject({ path: file.path }),\n name: trimExtName(file.baseName),\n extname,\n imports: imports,\n exports: exports,\n sources: sources,\n meta: file.meta || ({} as TMeta),\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './fs.ts'\nimport { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n\n constructor() {\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\n\nexport class EventEmitter<TEvents extends Record<string, any>> {\n constructor(maxListener = 100) {\n this.#emitter.setMaxListeners(maxListener)\n }\n #emitter = new NodeEventEmitter()\n\n emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void {\n this.#emitter.emit(eventName, ...(eventArg as any))\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { EventEmitter } from './utils/EventEmitter.ts'\nimport { write } from './fs.ts'\nimport pLimit from 'p-limit'\nimport type { Parser } from './parsers/types.ts'\nimport { typeScriptParser } from './parsers/typescript.ts'\nimport { tsxParser } from './parsers/tsx.ts'\nimport { defaultParser } from './parsers/default.ts'\n\ntype FileProcessorEvents = {\n start: [{ files: KubbFile.ResolvedFile[] }]\n finish: [{ files: KubbFile.ResolvedFile[] }]\n 'file:start': [{ file: KubbFile.ResolvedFile }]\n 'file:finish': [{ file: KubbFile.ResolvedFile }]\n}\n\ntype ProcessFilesProps = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype GetSourceOptions = {\n extname?: KubbFile.Extname\n}\n\nasync function getParser<TMeta extends object = object>(extname: KubbFile.Extname | undefined): Promise<Parser<TMeta>> {\n const parsers: Record<KubbFile.Extname, Parser<any>> = {\n '.ts': typeScriptParser,\n '.js': typeScriptParser,\n '.jsx': tsxParser,\n '.tsx': tsxParser,\n '.json': defaultParser,\n }\n\n if (!extname) {\n return defaultParser\n }\n\n const parser = parsers[extname]\n\n if (!parser) {\n console.warn(`[parser] No parser found for ${extname}, default parser will be used`)\n }\n\n return parser || defaultParser\n}\n\nexport async function parseFile(file: KubbFile.ResolvedFile, { extname }: GetSourceOptions = {}): Promise<string> {\n const parser = await getParser(file.extname)\n\n return parser.print(file, { extname })\n}\n\nexport class FileProcessor extends EventEmitter<FileProcessorEvents> {\n #limit = pLimit(100)\n\n constructor(maxListener = 1000) {\n super(maxListener)\n return this\n }\n\n async run(files: Array<KubbFile.ResolvedFile>, { dryRun, extension }: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n this.emit('start', { files })\n\n const promises = files.map((resolvedFile) =>\n this.#limit(async () => {\n const extname = extension?.[resolvedFile.extname] || undefined\n\n this.emit('file:start', { file: resolvedFile })\n\n if (!dryRun) {\n const source = await parseFile(resolvedFile, { extname })\n await write(resolvedFile.path, source, { sanity: false })\n }\n\n this.emit('file:finish', { file: resolvedFile })\n }),\n )\n\n await Promise.all(promises)\n\n this.emit('finish', { files })\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { FileManager } from './FileManager.ts'\nimport { isPromise } from 'remeda'\nimport { FileProcessor } from './FileProcessor.ts'\n\nconst isFunction = (val: unknown): val is Function => typeof val === 'function'\n\ntype Component = any\n\ntype PluginInstallFunction<Options = any[]> = Options extends unknown[] ? (app: App, ...options: Options) => any : (app: App, options: Options) => any\n\nexport type ObjectPlugin<Options = any[]> = {\n install: PluginInstallFunction<Options>\n}\nexport type FunctionPlugin<Options = any[]> = PluginInstallFunction<Options> & Partial<ObjectPlugin<Options>>\n\ntype AppRenderer = {\n render(): Promise<void> | void\n renderToString(): Promise<string> | string\n waitUntilExit(): Promise<void>\n}\n\nexport type AppContext<TOptions = unknown> = {\n options?: TOptions\n fileManager: FileManager\n addFile(...files: Array<KubbFile.File>): Promise<void>\n files: Array<KubbFile.ResolvedFile>\n clear: () => void\n}\n\ntype RootRenderFunction<THostElement, TContext extends AppContext> = (this: TContext, container: THostElement, context: TContext) => AppRenderer\n\ntype Plugin<Options = any[], P extends unknown[] = Options extends unknown[] ? Options : [Options]> = FunctionPlugin<P> | ObjectPlugin<P>\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\nexport interface App {\n _component: Component\n render(): Promise<void>\n renderToString(): Promise<string>\n files: Array<KubbFile.ResolvedFile>\n use<Options>(plugin: Plugin<Options>, options: NoInfer<Options>): this\n write(options?: WriteOptions): Promise<void>\n addFile(...files: Array<KubbFile.File>): Promise<void>\n waitUntilExit(): Promise<void>\n}\n\nexport type DefineApp<TContext extends AppContext> = (rootComponent?: Component, options?: TContext['options']) => App\n\nexport function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext> {\n function createApp(rootComponent: Component, options?: TContext['options']): App {\n const installedPlugins = new WeakSet()\n const fileManager = new FileManager()\n const fileProcessor = new FileProcessor()\n const context = {\n options,\n fileManager,\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n clear() {\n context.fileManager.clear()\n },\n get files() {\n return fileManager.files\n },\n } as TContext\n\n const { render, renderToString, waitUntilExit } = instance.call(context, rootComponent, context)\n\n const app: App = {\n _component: rootComponent,\n async render() {\n if (isPromise(render)) {\n await render()\n } else {\n render()\n }\n },\n async renderToString() {\n return renderToString()\n },\n get files() {\n return fileManager.files\n },\n waitUntilExit,\n addFile: context.addFile,\n async write(\n options = {\n extension: { '.ts': '.ts' },\n dryRun: false,\n },\n ) {\n await fileProcessor.run(fileManager.files, {\n extension: options.extension,\n dryRun: options.dryRun,\n })\n },\n use(plugin: Plugin, ...options: any[]) {\n if (installedPlugins.has(plugin)) {\n console.warn('Plugin has already been applied to target app.')\n } else if (plugin && isFunction(plugin.install)) {\n installedPlugins.add(plugin)\n plugin.install(app, ...options)\n } else if (isFunction(plugin)) {\n installedPlugins.add(plugin)\n plugin(app, ...options)\n }\n\n return app\n },\n }\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp(() => {\n return {\n async render() {\n throw new Error('Method not implemented')\n },\n async renderToString() {\n throw new Error('Method not implemented')\n },\n async waitUntilExit() {\n throw new Error('Method not implemented')\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,6DAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,uCAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,uCAAY,CAAC,OAAO,IAAI;;CAG1B,QAAc;AACZ,uCAAY,CAAC,OAAO;;CAGtB,OAAiB;AACf,SAAO,CAAC,mCAAG,KAAY,CAAC,MAAM,CAAC;;CAGjC,SAAmB;AACjB,SAAO,CAAC,mCAAG,KAAY,CAAC,QAAQ,CAAC;;CAGnC,QAAc;;;;;ACpBhB,SAAS,WAAW,KAAsC;CACxD,MAAM,MAAM,KAAK,UAAU,KAAK,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC;AACxD,oCAAkB,SAAS,CAAC,OAAO,IAAI,CAAC,OAAO,MAAM;;AAGvD,SAAgB,eAAe,SAAyD;AACtF,6BAAgB,UAAU,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gBAAgB;AACpB,SAAM,IAAI,MAAM,yBAAyB;;EAE5C;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,56 @@
|
|
|
1
|
-
import "./KubbFile-BrN7Wwp6.cjs";
|
|
2
|
-
import { a as FileManager, i as defineApp, n as AppContext, r as DefineApp } from "./defineApp-
|
|
3
|
-
import {
|
|
1
|
+
import { a as ResolvedFile, n as File, t as Extname } from "./KubbFile-BrN7Wwp6.cjs";
|
|
2
|
+
import { a as FileManager, i as defineApp, n as AppContext, r as DefineApp } from "./defineApp-BX0gsgY3.cjs";
|
|
3
|
+
import { t as Parser } from "./types-GueHciQ3.cjs";
|
|
4
4
|
|
|
5
5
|
//#region src/createApp.d.ts
|
|
6
6
|
declare const createApp: DefineApp<AppContext<unknown>>;
|
|
7
7
|
//#endregion
|
|
8
|
-
|
|
8
|
+
//#region src/createFile.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Helper to create a file with name and id set
|
|
11
|
+
*/
|
|
12
|
+
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/utils/EventEmitter.d.ts
|
|
15
|
+
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(maxListener?: number);
|
|
18
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
19
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
20
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
21
|
+
removeAll(): void;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/FileProcessor.d.ts
|
|
25
|
+
type FileProcessorEvents = {
|
|
26
|
+
start: [{
|
|
27
|
+
files: ResolvedFile[];
|
|
28
|
+
}];
|
|
29
|
+
finish: [{
|
|
30
|
+
files: ResolvedFile[];
|
|
31
|
+
}];
|
|
32
|
+
'file:start': [{
|
|
33
|
+
file: ResolvedFile;
|
|
34
|
+
}];
|
|
35
|
+
'file:finish': [{
|
|
36
|
+
file: ResolvedFile;
|
|
37
|
+
}];
|
|
38
|
+
};
|
|
39
|
+
type ProcessFilesProps = {
|
|
40
|
+
extension?: Record<Extname, Extname | ''>;
|
|
41
|
+
dryRun?: boolean;
|
|
42
|
+
};
|
|
43
|
+
declare class FileProcessor extends EventEmitter<FileProcessorEvents> {
|
|
44
|
+
#private;
|
|
45
|
+
constructor(maxListener?: number);
|
|
46
|
+
run(files: Array<ResolvedFile>, {
|
|
47
|
+
dryRun,
|
|
48
|
+
extension
|
|
49
|
+
}: ProcessFilesProps): Promise<ResolvedFile[]>;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/parsers/createFileParser.d.ts
|
|
53
|
+
declare function createFileParser<TMeta extends object = object>(parser: Parser<TMeta>): Parser<TMeta>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { FileManager, FileProcessor, createApp, createFile, createFileParser, defineApp };
|
|
9
56
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,56 @@
|
|
|
1
|
-
import "./KubbFile-BzVkcu9M.js";
|
|
2
|
-
import { a as FileManager, i as defineApp, n as AppContext, r as DefineApp } from "./defineApp-
|
|
3
|
-
import {
|
|
1
|
+
import { a as ResolvedFile, n as File, t as Extname } from "./KubbFile-BzVkcu9M.js";
|
|
2
|
+
import { a as FileManager, i as defineApp, n as AppContext, r as DefineApp } from "./defineApp-DygRR8LS.js";
|
|
3
|
+
import { t as Parser } from "./types-CkbelZaS.js";
|
|
4
4
|
|
|
5
5
|
//#region src/createApp.d.ts
|
|
6
6
|
declare const createApp: DefineApp<AppContext<unknown>>;
|
|
7
7
|
//#endregion
|
|
8
|
-
|
|
8
|
+
//#region src/createFile.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Helper to create a file with name and id set
|
|
11
|
+
*/
|
|
12
|
+
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/utils/EventEmitter.d.ts
|
|
15
|
+
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(maxListener?: number);
|
|
18
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
19
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
20
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
21
|
+
removeAll(): void;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/FileProcessor.d.ts
|
|
25
|
+
type FileProcessorEvents = {
|
|
26
|
+
start: [{
|
|
27
|
+
files: ResolvedFile[];
|
|
28
|
+
}];
|
|
29
|
+
finish: [{
|
|
30
|
+
files: ResolvedFile[];
|
|
31
|
+
}];
|
|
32
|
+
'file:start': [{
|
|
33
|
+
file: ResolvedFile;
|
|
34
|
+
}];
|
|
35
|
+
'file:finish': [{
|
|
36
|
+
file: ResolvedFile;
|
|
37
|
+
}];
|
|
38
|
+
};
|
|
39
|
+
type ProcessFilesProps = {
|
|
40
|
+
extension?: Record<Extname, Extname | ''>;
|
|
41
|
+
dryRun?: boolean;
|
|
42
|
+
};
|
|
43
|
+
declare class FileProcessor extends EventEmitter<FileProcessorEvents> {
|
|
44
|
+
#private;
|
|
45
|
+
constructor(maxListener?: number);
|
|
46
|
+
run(files: Array<ResolvedFile>, {
|
|
47
|
+
dryRun,
|
|
48
|
+
extension
|
|
49
|
+
}: ProcessFilesProps): Promise<ResolvedFile[]>;
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/parsers/createFileParser.d.ts
|
|
53
|
+
declare function createFileParser<TMeta extends object = object>(parser: Parser<TMeta>): Parser<TMeta>;
|
|
54
|
+
//#endregion
|
|
55
|
+
export { FileManager, FileProcessor, createApp, createFile, createFileParser, defineApp };
|
|
9
56
|
//# sourceMappingURL=index.d.ts.map
|