@kubb/studio 5.18.8 → 5.19.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.cjs +62 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -63
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -22,6 +22,63 @@ import net from "node:net";
|
|
|
22
22
|
import { Readable, Transform } from "node:stream";
|
|
23
23
|
import { ofetch } from "ofetch";
|
|
24
24
|
import { gzipSync } from "node:zlib";
|
|
25
|
+
// ../../internals/utils/src/promise.ts
|
|
26
|
+
/**
|
|
27
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
28
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
29
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
33
|
+
*/
|
|
34
|
+
function memo(store, key, compute) {
|
|
35
|
+
const cached = store.get(key);
|
|
36
|
+
if (cached !== void 0 || store.has(key)) return cached;
|
|
37
|
+
const value = compute();
|
|
38
|
+
store.set(key, value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function createStore({ weak, max } = {}) {
|
|
42
|
+
if (weak) return /* @__PURE__ */ new WeakMap();
|
|
43
|
+
const entry = /* @__PURE__ */ new Map();
|
|
44
|
+
if (max === void 0) return entry;
|
|
45
|
+
const set = (key, value) => {
|
|
46
|
+
if (entry.size >= max) entry.clear();
|
|
47
|
+
entry.set(key, value);
|
|
48
|
+
};
|
|
49
|
+
if (max !== 1) return {
|
|
50
|
+
has: (key) => entry.has(key),
|
|
51
|
+
get: (key) => entry.get(key),
|
|
52
|
+
set
|
|
53
|
+
};
|
|
54
|
+
const touch = (key) => {
|
|
55
|
+
if (!entry.has(key)) return false;
|
|
56
|
+
set(key, entry.get(key));
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
has: touch,
|
|
61
|
+
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
62
|
+
set
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
memo.create = createStore;
|
|
66
|
+
/**
|
|
67
|
+
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
68
|
+
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
async function inParallel({ items, limit, run }) {
|
|
76
|
+
const queue = items.entries();
|
|
77
|
+
const worker = async () => {
|
|
78
|
+
for (const [index, item] of queue) await run(item, index);
|
|
79
|
+
};
|
|
80
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
81
|
+
}
|
|
25
82
|
// ../../internals/utils/src/casing.ts
|
|
26
83
|
/**
|
|
27
84
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -36,16 +93,10 @@ function convert(text, pascal) {
|
|
|
36
93
|
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
37
94
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
38
95
|
}
|
|
39
|
-
const cache =
|
|
40
|
-
const cacheLimit = 1e5;
|
|
96
|
+
const cache = memo.create({ max: 1e5 });
|
|
41
97
|
function toCamelOrPascal(text, pascal) {
|
|
42
98
|
const key = `${pascal ? "P" : "c"}${text}`;
|
|
43
|
-
|
|
44
|
-
if (cached !== void 0) return cached;
|
|
45
|
-
const result = convert(text, pascal);
|
|
46
|
-
if (cache.size >= cacheLimit) cache.clear();
|
|
47
|
-
cache.set(key, result);
|
|
48
|
-
return result;
|
|
99
|
+
return memo(cache, key, () => convert(text, pascal));
|
|
49
100
|
}
|
|
50
101
|
/**
|
|
51
102
|
* Converts `text` to camelCase.
|
|
@@ -171,60 +222,8 @@ function isPathInside(path, parent) {
|
|
|
171
222
|
const rel = relative(resolvedParent, resolvedPath);
|
|
172
223
|
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
173
224
|
}
|
|
174
|
-
// ../../internals/utils/src/promise.ts
|
|
175
|
-
/**
|
|
176
|
-
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
177
|
-
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
178
|
-
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
182
|
-
*/
|
|
183
|
-
function memo(store, key, compute) {
|
|
184
|
-
const cached = store.get(key);
|
|
185
|
-
if (cached !== void 0 || store.has(key)) return cached;
|
|
186
|
-
const value = compute();
|
|
187
|
-
store.set(key, value);
|
|
188
|
-
return value;
|
|
189
|
-
}
|
|
190
|
-
function createStore({ type }) {
|
|
191
|
-
if (type === "weak") return /* @__PURE__ */ new WeakMap();
|
|
192
|
-
const entry = /* @__PURE__ */ new Map();
|
|
193
|
-
if (type === "map") return entry;
|
|
194
|
-
const set = (key, value) => {
|
|
195
|
-
entry.clear();
|
|
196
|
-
entry.set(key, value);
|
|
197
|
-
};
|
|
198
|
-
const touch = (key) => {
|
|
199
|
-
if (!entry.has(key)) return false;
|
|
200
|
-
set(key, entry.get(key));
|
|
201
|
-
return true;
|
|
202
|
-
};
|
|
203
|
-
return {
|
|
204
|
-
has: touch,
|
|
205
|
-
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
206
|
-
set
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
memo.create = createStore;
|
|
210
|
-
/**
|
|
211
|
-
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
212
|
-
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
* ```ts
|
|
216
|
-
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
async function inParallel({ items, limit, run }) {
|
|
220
|
-
const queue = items.entries();
|
|
221
|
-
const worker = async () => {
|
|
222
|
-
for (const [index, item] of queue) await run(item, index);
|
|
223
|
-
};
|
|
224
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
225
|
-
}
|
|
226
225
|
// package.json
|
|
227
|
-
var version = "5.
|
|
226
|
+
var version = "5.19.0";
|
|
228
227
|
// ../../internals/shared/src/constants.ts
|
|
229
228
|
/**
|
|
230
229
|
* Extensions `kubb` ships at its own version, so they count as installed without being a direct
|
|
@@ -964,14 +963,14 @@ function addPlugin({ source, parsed, config, edit, quote, extensions }) {
|
|
|
964
963
|
if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` };
|
|
965
964
|
const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : [];
|
|
966
965
|
const imports = getImports(parsed.program);
|
|
967
|
-
const missing =
|
|
966
|
+
const missing = memo.create();
|
|
968
967
|
for (const item of [...defaults, {
|
|
969
968
|
importName,
|
|
970
969
|
packageName: edit.plugin
|
|
971
970
|
}]) {
|
|
972
971
|
const from = imports.get(item.importName)?.from;
|
|
973
972
|
if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` };
|
|
974
|
-
if (!from) missing
|
|
973
|
+
if (!from) memo(missing, item.packageName, () => []).push(item.importName);
|
|
975
974
|
}
|
|
976
975
|
const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ""})`;
|
|
977
976
|
const next = array?.type === nodeTypes.arrayExpression ? appendItem(source, array, call) : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(", ")}]`);
|