@kubb/fabric-core 0.1.6 → 0.1.7
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/{App-Dvetv2V_.d.ts → App-DVWD6TgC.d.cts} +17 -6
- package/dist/{App-Cplfh8QA.d.cts → App-_vPNh477.d.ts} +17 -6
- package/dist/defineProperty-BtekiGIK.js +332 -0
- package/dist/defineProperty-BtekiGIK.js.map +1 -0
- package/dist/defineProperty-CspRhtP3.cjs +364 -0
- package/dist/defineProperty-CspRhtP3.cjs.map +1 -0
- package/dist/{index-Agz-2M75.d.ts → index-CfV-59_M.d.ts} +5 -5
- package/dist/{index-C3GyFwE1.d.cts → index-DVok6g82.d.cts} +5 -5
- package/dist/index.cjs +32 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +32 -25
- package/dist/index.js.map +1 -1
- package/dist/parsers/typescript.d.cts +2 -2
- package/dist/parsers/typescript.d.ts +2 -2
- package/dist/parsers.d.cts +2 -2
- package/dist/parsers.d.ts +2 -2
- package/dist/plugins.cjs +66 -27
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +29 -12
- package/dist/plugins.d.ts +29 -12
- package/dist/plugins.js +65 -29
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/{typescriptParser-CxGhFQXh.d.cts → typescriptParser-BM90H8Tx.d.cts} +2 -2
- package/dist/{typescriptParser-B49WHoGL.d.ts → typescriptParser-Chjs-RhT.d.ts} +2 -2
- package/package.json +4 -2
- package/src/App.ts +12 -3
- package/src/FileProcessor.ts +41 -17
- package/src/defineApp.ts +3 -3
- package/src/plugins/barrelPlugin.ts +24 -6
- package/src/plugins/fsPlugin.ts +30 -29
- package/src/plugins/index.ts +1 -0
- package/src/plugins/progressPlugin.ts +48 -0
- package/dist/defineProperty-3OJdpith.js +0 -168
- package/dist/defineProperty-3OJdpith.js.map +0 -1
- package/dist/defineProperty-CjCLDutJ.cjs +0 -201
- package/dist/defineProperty-CjCLDutJ.cjs.map +0 -1
package/src/plugins/fsPlugin.ts
CHANGED
|
@@ -6,15 +6,15 @@ import type * as KubbFile from '../KubbFile.ts'
|
|
|
6
6
|
|
|
7
7
|
type WriteOptions = {
|
|
8
8
|
extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
|
|
9
|
-
dryRun?: boolean
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
type Options = {
|
|
12
|
+
dryRun?: boolean
|
|
13
13
|
/**
|
|
14
14
|
* Optional callback that is invoked whenever a file is written by the plugin.
|
|
15
15
|
* Useful for tests to observe write operations without spying on internal functions.
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
onBeforeWrite?: (path: string, data: string | undefined) => void | Promise<void>
|
|
18
18
|
clean?: {
|
|
19
19
|
path: string
|
|
20
20
|
}
|
|
@@ -24,13 +24,14 @@ type ExtendOptions = {
|
|
|
24
24
|
write(options?: WriteOptions): Promise<void>
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export async function write(path: string, data: string, options: { sanity?: boolean } = {}): Promise<string | undefined> {
|
|
28
|
-
if (data.trim() === '') {
|
|
29
|
-
return undefined
|
|
30
|
-
}
|
|
27
|
+
export async function write(path: string, data: string | undefined, options: { sanity?: boolean } = {}): Promise<string | undefined> {
|
|
31
28
|
return switcher(
|
|
32
29
|
{
|
|
33
|
-
node: async (path
|
|
30
|
+
node: async (path, data: string | undefined, { sanity }: { sanity?: boolean }) => {
|
|
31
|
+
if (!data || data?.trim() === '') {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
|
|
34
35
|
try {
|
|
35
36
|
const oldContent = await fs.readFile(resolve(path), {
|
|
36
37
|
encoding: 'utf-8',
|
|
@@ -42,7 +43,7 @@ export async function write(path: string, data: string, options: { sanity?: bool
|
|
|
42
43
|
/* empty */
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })
|
|
46
|
+
await fs.outputFile(resolve(path), data.trim(), { encoding: 'utf-8' })
|
|
46
47
|
|
|
47
48
|
if (sanity) {
|
|
48
49
|
const savedData = await fs.readFile(resolve(path), {
|
|
@@ -58,29 +59,29 @@ export async function write(path: string, data: string, options: { sanity?: bool
|
|
|
58
59
|
|
|
59
60
|
return data
|
|
60
61
|
},
|
|
61
|
-
bun: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
bun: async (path: string, data: string | undefined, { sanity }: { sanity?: boolean }) => {
|
|
63
|
+
if (!data || data?.trim() === '') {
|
|
64
|
+
return undefined
|
|
65
|
+
}
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
const file = Bun.file(resolve(path))
|
|
67
|
-
const savedData = await file.text()
|
|
67
|
+
await Bun.write(resolve(path), data.trim())
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
if (sanity) {
|
|
70
|
+
const file = Bun.file(resolve(path))
|
|
71
|
+
const savedData = await file.text()
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
if (savedData?.toString() !== data?.toString()) {
|
|
74
|
+
throw new Error(`Sanity check failed for ${path}\n\nData[${path.length}]:\n${path}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
return
|
|
77
|
-
} catch (e) {
|
|
78
|
-
console.error(e)
|
|
77
|
+
return savedData
|
|
79
78
|
}
|
|
79
|
+
|
|
80
|
+
return data
|
|
80
81
|
},
|
|
81
82
|
},
|
|
82
83
|
'node',
|
|
83
|
-
)(path, data
|
|
84
|
+
)(path, data, options)
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
// biome-ignore lint/suspicious/noTsIgnore: production ready
|
|
@@ -101,29 +102,29 @@ declare global {
|
|
|
101
102
|
|
|
102
103
|
export const fsPlugin = createPlugin<Options, ExtendOptions>({
|
|
103
104
|
name: 'fs',
|
|
104
|
-
install(app, options) {
|
|
105
|
-
if (options
|
|
105
|
+
install(app, options = {}) {
|
|
106
|
+
if (options.clean) {
|
|
106
107
|
fs.removeSync(options.clean.path)
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
app.context.events.on('process:progress', async ({ file, source }) => {
|
|
110
|
-
if (options
|
|
111
|
-
await options.
|
|
111
|
+
if (options.onBeforeWrite) {
|
|
112
|
+
await options.onBeforeWrite(file.path, source)
|
|
112
113
|
}
|
|
113
114
|
await write(file.path, source, { sanity: false })
|
|
114
115
|
})
|
|
115
116
|
},
|
|
116
|
-
inject(app) {
|
|
117
|
+
inject(app, { dryRun } = {}) {
|
|
117
118
|
return {
|
|
118
119
|
async write(
|
|
119
120
|
options = {
|
|
120
121
|
extension: { '.ts': '.ts' },
|
|
121
|
-
dryRun: false,
|
|
122
122
|
},
|
|
123
123
|
) {
|
|
124
124
|
await app.context.fileManager.write({
|
|
125
|
+
mode: app.context.options?.mode,
|
|
125
126
|
extension: options.extension,
|
|
126
|
-
dryRun
|
|
127
|
+
dryRun,
|
|
127
128
|
parsers: app.context.installedParsers,
|
|
128
129
|
})
|
|
129
130
|
},
|
package/src/plugins/index.ts
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Presets, SingleBar } from 'cli-progress'
|
|
2
|
+
import { createPlugin } from './createPlugin.ts'
|
|
3
|
+
import { relative } from 'node:path'
|
|
4
|
+
import process from 'node:process'
|
|
5
|
+
|
|
6
|
+
type Options = {}
|
|
7
|
+
|
|
8
|
+
// biome-ignore lint/suspicious/noTsIgnore: production ready
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
declare module '@kubb/fabric-core' {
|
|
11
|
+
interface App {}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare global {
|
|
15
|
+
namespace Kubb {
|
|
16
|
+
interface App {}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const progressPlugin = createPlugin<Options>({
|
|
21
|
+
name: 'progress',
|
|
22
|
+
install(app) {
|
|
23
|
+
const progressBar = new SingleBar(
|
|
24
|
+
{
|
|
25
|
+
format: '{bar} {percentage}% | {value}/{total} | {message}',
|
|
26
|
+
barCompleteChar: '█',
|
|
27
|
+
barIncompleteChar: '░',
|
|
28
|
+
hideCursor: true,
|
|
29
|
+
clearOnComplete: true,
|
|
30
|
+
},
|
|
31
|
+
Presets.shades_grey,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
app.context.events.on('process:start', async ({ files }) => {
|
|
35
|
+
progressBar.start(files.length, 0, { message: 'Starting...' })
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
app.context.events.on('process:progress', async ({ file }) => {
|
|
39
|
+
const message = `Writing ${relative(process.cwd(), file.path)}`
|
|
40
|
+
progressBar.increment(1, { message })
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
app.context.events.on('process:end', async ({ files }) => {
|
|
44
|
+
progressBar.update(files.length, { message: 'Done ✅' })
|
|
45
|
+
progressBar.stop()
|
|
46
|
+
})
|
|
47
|
+
},
|
|
48
|
+
})
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { t as trimExtName } from "./trimExtName-CeOVQVbu.js";
|
|
2
|
-
import { orderBy } from "natural-orderby";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { isDeepEqual, uniqueBy } from "remeda";
|
|
6
|
-
|
|
7
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/checkPrivateRedeclaration.js
|
|
8
|
-
function _checkPrivateRedeclaration(e, t) {
|
|
9
|
-
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/classPrivateFieldInitSpec.js
|
|
14
|
-
function _classPrivateFieldInitSpec(e, t, a) {
|
|
15
|
-
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/assertClassBrand.js
|
|
20
|
-
function _assertClassBrand(e, t, n) {
|
|
21
|
-
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
22
|
-
throw new TypeError("Private element is not present on this object");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/classPrivateFieldGet2.js
|
|
27
|
-
function _classPrivateFieldGet2(s, a) {
|
|
28
|
-
return s.get(_assertClassBrand(s, a));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/createFile.ts
|
|
33
|
-
function hashObject(obj) {
|
|
34
|
-
const str = JSON.stringify(obj, Object.keys(obj).sort());
|
|
35
|
-
return createHash("sha256").update(str).digest("hex");
|
|
36
|
-
}
|
|
37
|
-
function combineSources(sources) {
|
|
38
|
-
return uniqueBy(sources, (obj) => [
|
|
39
|
-
obj.name,
|
|
40
|
-
obj.isExportable,
|
|
41
|
-
obj.isTypeOnly
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
function combineExports(exports) {
|
|
45
|
-
return orderBy(exports, [
|
|
46
|
-
(v) => !!Array.isArray(v.name),
|
|
47
|
-
(v) => !v.isTypeOnly,
|
|
48
|
-
(v) => v.path,
|
|
49
|
-
(v) => !!v.name,
|
|
50
|
-
(v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
|
|
51
|
-
]).reduce((prev, curr) => {
|
|
52
|
-
const name = curr.name;
|
|
53
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
54
|
-
if (prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)) return prev;
|
|
55
|
-
if (prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias) || Array.isArray(name) && !name.length || (prevByPath === null || prevByPath === void 0 ? void 0 : prevByPath.asAlias) && !curr.asAlias) return prev;
|
|
56
|
-
if (!prevByPath) return [...prev, {
|
|
57
|
-
...curr,
|
|
58
|
-
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
59
|
-
}];
|
|
60
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
61
|
-
prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])];
|
|
62
|
-
return prev;
|
|
63
|
-
}
|
|
64
|
-
return [...prev, curr];
|
|
65
|
-
}, []);
|
|
66
|
-
}
|
|
67
|
-
function combineImports(imports, exports, source) {
|
|
68
|
-
return orderBy(imports, [
|
|
69
|
-
(v) => !!Array.isArray(v.name),
|
|
70
|
-
(v) => !v.isTypeOnly,
|
|
71
|
-
(v) => v.path,
|
|
72
|
-
(v) => !!v.name,
|
|
73
|
-
(v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
|
|
74
|
-
]).reduce((prev, curr) => {
|
|
75
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
76
|
-
const hasImportInSource = (importName) => {
|
|
77
|
-
if (!source) return true;
|
|
78
|
-
const checker = (name$1) => {
|
|
79
|
-
return name$1 && source.includes(name$1);
|
|
80
|
-
};
|
|
81
|
-
return checker(importName) || exports.some(({ name: name$1 }) => Array.isArray(name$1) ? name$1.some(checker) : checker(name$1));
|
|
82
|
-
};
|
|
83
|
-
if (curr.path === curr.root) return prev;
|
|
84
|
-
if (Array.isArray(name)) name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
85
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
86
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
87
|
-
if (prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)) return prev;
|
|
88
|
-
if (uniquePrev || Array.isArray(name) && !name.length) return prev;
|
|
89
|
-
if (!prevByPath) return [...prev, {
|
|
90
|
-
...curr,
|
|
91
|
-
name
|
|
92
|
-
}];
|
|
93
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
94
|
-
prevByPath.name = [...new Set([...prevByPath.name, ...name])];
|
|
95
|
-
return prev;
|
|
96
|
-
}
|
|
97
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) return prev;
|
|
98
|
-
return [...prev, curr];
|
|
99
|
-
}, []);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Helper to create a file with name and id set
|
|
103
|
-
*/
|
|
104
|
-
function createFile(file) {
|
|
105
|
-
var _file$exports, _file$imports, _file$sources;
|
|
106
|
-
const extname = path.extname(file.baseName);
|
|
107
|
-
if (!extname) throw new Error(`No extname found for ${file.baseName}`);
|
|
108
|
-
const source = file.sources.map((item) => item.value).join("\n\n");
|
|
109
|
-
const exports = ((_file$exports = file.exports) === null || _file$exports === void 0 ? void 0 : _file$exports.length) ? combineExports(file.exports) : [];
|
|
110
|
-
const imports = ((_file$imports = file.imports) === null || _file$imports === void 0 ? void 0 : _file$imports.length) && source ? combineImports(file.imports, exports, source) : [];
|
|
111
|
-
const sources = ((_file$sources = file.sources) === null || _file$sources === void 0 ? void 0 : _file$sources.length) ? combineSources(file.sources) : [];
|
|
112
|
-
return {
|
|
113
|
-
...file,
|
|
114
|
-
id: hashObject({ path: file.path }),
|
|
115
|
-
name: trimExtName(file.baseName),
|
|
116
|
-
extname,
|
|
117
|
-
imports,
|
|
118
|
-
exports,
|
|
119
|
-
sources,
|
|
120
|
-
meta: file.meta || {}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/typeof.js
|
|
126
|
-
function _typeof(o) {
|
|
127
|
-
"@babel/helpers - typeof";
|
|
128
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
129
|
-
return typeof o$1;
|
|
130
|
-
} : function(o$1) {
|
|
131
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
132
|
-
}, _typeof(o);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
//#endregion
|
|
136
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/toPrimitive.js
|
|
137
|
-
function toPrimitive(t, r) {
|
|
138
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
139
|
-
var e = t[Symbol.toPrimitive];
|
|
140
|
-
if (void 0 !== e) {
|
|
141
|
-
var i = e.call(t, r || "default");
|
|
142
|
-
if ("object" != _typeof(i)) return i;
|
|
143
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
144
|
-
}
|
|
145
|
-
return ("string" === r ? String : Number)(t);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
//#endregion
|
|
149
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/toPropertyKey.js
|
|
150
|
-
function toPropertyKey(t) {
|
|
151
|
-
var i = toPrimitive(t, "string");
|
|
152
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
//#endregion
|
|
156
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/defineProperty.js
|
|
157
|
-
function _defineProperty(e, r, t) {
|
|
158
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
159
|
-
value: t,
|
|
160
|
-
enumerable: !0,
|
|
161
|
-
configurable: !0,
|
|
162
|
-
writable: !0
|
|
163
|
-
}) : e[r] = t, e;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
//#endregion
|
|
167
|
-
export { _classPrivateFieldInitSpec as a, _assertClassBrand as i, createFile as n, _classPrivateFieldGet2 as r, _defineProperty as t };
|
|
168
|
-
//# sourceMappingURL=defineProperty-3OJdpith.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineProperty-3OJdpith.js","names":["name"],"sources":["../src/createFile.ts"],"sourcesContent":["import type * as KubbFile from './KubbFile.ts'\nimport { trimExtName } from './utils/trimExtName.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,WAAW,KAAsC;CACxD,MAAM,MAAM,KAAK,UAAU,KAAK,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC;AACxD,QAAO,WAAW,SAAS,CAAC,OAAO,IAAI,CAAC,OAAO,MAAM;;AAGvD,SAAgB,eAAe,SAAyD;AACtF,QAAO,SAAS,UAAU,QAAQ;EAAC,IAAI;EAAM,IAAI;EAAc,IAAI;EAAW,CAAU;;AAG1F,SAAgB,eAAe,SAAyD;AACtF,QAAO,QAAQ,SAAS;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GAAG,IAAI,IAAI,CAAC,GAAG,WAAW,MAAM,GAAG,KAAK,CAAC,CAAC;AAE7D,UAAO;;AAIT,MAAI,CAAC,MAAM,QAAQ,KAAK,IAAI,QAAQ,CAAC,kBAAkB,KAAK,CAC1D,QAAO;AAGT,SAAO,CAAC,GAAG,MAAM,KAAK;IAExB,EAAE,CACH;;;;;AAMH,SAAgB,WAA0C,MAA0D;;CAClH,MAAM,UAAU,KAAK,QAAQ,KAAK,SAAS;AAC3C,KAAI,CAAC,QACH,OAAM,IAAI,MAAM,wBAAwB,KAAK,WAAW;CAG1D,MAAM,SAAS,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;CAClE,MAAM,4BAAU,KAAK,uEAAS,UAAS,eAAe,KAAK,QAAQ,GAAG,EAAE;CACxE,MAAM,4BAAU,KAAK,uEAAS,WAAU,SAAS,eAAe,KAAK,SAAS,SAAS,OAAO,GAAG,EAAE;CACnG,MAAM,4BAAU,KAAK,uEAAS,UAAS,eAAe,KAAK,QAAQ,GAAG,EAAE;AAExE,QAAO;EACL,GAAG;EACH,IAAI,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC;EACnC,MAAM,YAAY,KAAK,SAAS;EAChC;EACS;EACA;EACA;EACT,MAAM,KAAK,QAAS,EAAE;EACvB"}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
const require_trimExtName = require('./trimExtName-Bb4zGVF1.cjs');
|
|
2
|
-
let natural_orderby = require("natural-orderby");
|
|
3
|
-
natural_orderby = require_trimExtName.__toESM(natural_orderby);
|
|
4
|
-
let node_crypto = require("node:crypto");
|
|
5
|
-
node_crypto = require_trimExtName.__toESM(node_crypto);
|
|
6
|
-
let node_path = require("node:path");
|
|
7
|
-
node_path = require_trimExtName.__toESM(node_path);
|
|
8
|
-
let remeda = require("remeda");
|
|
9
|
-
remeda = require_trimExtName.__toESM(remeda);
|
|
10
|
-
|
|
11
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/checkPrivateRedeclaration.js
|
|
12
|
-
function _checkPrivateRedeclaration(e, t) {
|
|
13
|
-
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/classPrivateFieldInitSpec.js
|
|
18
|
-
function _classPrivateFieldInitSpec(e, t, a) {
|
|
19
|
-
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/assertClassBrand.js
|
|
24
|
-
function _assertClassBrand(e, t, n) {
|
|
25
|
-
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
26
|
-
throw new TypeError("Private element is not present on this object");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/classPrivateFieldGet2.js
|
|
31
|
-
function _classPrivateFieldGet2(s, a) {
|
|
32
|
-
return s.get(_assertClassBrand(s, a));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/createFile.ts
|
|
37
|
-
function hashObject(obj) {
|
|
38
|
-
const str = JSON.stringify(obj, Object.keys(obj).sort());
|
|
39
|
-
return (0, node_crypto.createHash)("sha256").update(str).digest("hex");
|
|
40
|
-
}
|
|
41
|
-
function combineSources(sources) {
|
|
42
|
-
return (0, remeda.uniqueBy)(sources, (obj) => [
|
|
43
|
-
obj.name,
|
|
44
|
-
obj.isExportable,
|
|
45
|
-
obj.isTypeOnly
|
|
46
|
-
]);
|
|
47
|
-
}
|
|
48
|
-
function combineExports(exports$1) {
|
|
49
|
-
return (0, natural_orderby.orderBy)(exports$1, [
|
|
50
|
-
(v) => !!Array.isArray(v.name),
|
|
51
|
-
(v) => !v.isTypeOnly,
|
|
52
|
-
(v) => v.path,
|
|
53
|
-
(v) => !!v.name,
|
|
54
|
-
(v) => Array.isArray(v.name) ? (0, natural_orderby.orderBy)(v.name) : v.name
|
|
55
|
-
]).reduce((prev, curr) => {
|
|
56
|
-
const name = curr.name;
|
|
57
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
58
|
-
if (prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly)) return prev;
|
|
59
|
-
if (prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias) || Array.isArray(name) && !name.length || (prevByPath === null || prevByPath === void 0 ? void 0 : prevByPath.asAlias) && !curr.asAlias) return prev;
|
|
60
|
-
if (!prevByPath) return [...prev, {
|
|
61
|
-
...curr,
|
|
62
|
-
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
63
|
-
}];
|
|
64
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
65
|
-
prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])];
|
|
66
|
-
return prev;
|
|
67
|
-
}
|
|
68
|
-
return [...prev, curr];
|
|
69
|
-
}, []);
|
|
70
|
-
}
|
|
71
|
-
function combineImports(imports, exports$1, source) {
|
|
72
|
-
return (0, natural_orderby.orderBy)(imports, [
|
|
73
|
-
(v) => !!Array.isArray(v.name),
|
|
74
|
-
(v) => !v.isTypeOnly,
|
|
75
|
-
(v) => v.path,
|
|
76
|
-
(v) => !!v.name,
|
|
77
|
-
(v) => Array.isArray(v.name) ? (0, natural_orderby.orderBy)(v.name) : v.name
|
|
78
|
-
]).reduce((prev, curr) => {
|
|
79
|
-
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
80
|
-
const hasImportInSource = (importName) => {
|
|
81
|
-
if (!source) return true;
|
|
82
|
-
const checker = (name$1) => {
|
|
83
|
-
return name$1 && source.includes(name$1);
|
|
84
|
-
};
|
|
85
|
-
return checker(importName) || exports$1.some(({ name: name$1 }) => Array.isArray(name$1) ? name$1.some(checker) : checker(name$1));
|
|
86
|
-
};
|
|
87
|
-
if (curr.path === curr.root) return prev;
|
|
88
|
-
if (Array.isArray(name)) name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
89
|
-
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
90
|
-
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
91
|
-
if (prev.findLast((imp) => imp.path === curr.path && (0, remeda.isDeepEqual)(imp.name, name) && imp.isTypeOnly)) return prev;
|
|
92
|
-
if (uniquePrev || Array.isArray(name) && !name.length) return prev;
|
|
93
|
-
if (!prevByPath) return [...prev, {
|
|
94
|
-
...curr,
|
|
95
|
-
name
|
|
96
|
-
}];
|
|
97
|
-
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
98
|
-
prevByPath.name = [...new Set([...prevByPath.name, ...name])];
|
|
99
|
-
return prev;
|
|
100
|
-
}
|
|
101
|
-
if (!Array.isArray(name) && name && !hasImportInSource(name)) return prev;
|
|
102
|
-
return [...prev, curr];
|
|
103
|
-
}, []);
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Helper to create a file with name and id set
|
|
107
|
-
*/
|
|
108
|
-
function createFile(file) {
|
|
109
|
-
var _file$exports, _file$imports, _file$sources;
|
|
110
|
-
const extname = node_path.default.extname(file.baseName);
|
|
111
|
-
if (!extname) throw new Error(`No extname found for ${file.baseName}`);
|
|
112
|
-
const source = file.sources.map((item) => item.value).join("\n\n");
|
|
113
|
-
const exports$1 = ((_file$exports = file.exports) === null || _file$exports === void 0 ? void 0 : _file$exports.length) ? combineExports(file.exports) : [];
|
|
114
|
-
const imports = ((_file$imports = file.imports) === null || _file$imports === void 0 ? void 0 : _file$imports.length) && source ? combineImports(file.imports, exports$1, source) : [];
|
|
115
|
-
const sources = ((_file$sources = file.sources) === null || _file$sources === void 0 ? void 0 : _file$sources.length) ? combineSources(file.sources) : [];
|
|
116
|
-
return {
|
|
117
|
-
...file,
|
|
118
|
-
id: hashObject({ path: file.path }),
|
|
119
|
-
name: require_trimExtName.trimExtName(file.baseName),
|
|
120
|
-
extname,
|
|
121
|
-
imports,
|
|
122
|
-
exports: exports$1,
|
|
123
|
-
sources,
|
|
124
|
-
meta: file.meta || {}
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/typeof.js
|
|
130
|
-
function _typeof(o) {
|
|
131
|
-
"@babel/helpers - typeof";
|
|
132
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
133
|
-
return typeof o$1;
|
|
134
|
-
} : function(o$1) {
|
|
135
|
-
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
136
|
-
}, _typeof(o);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/toPrimitive.js
|
|
141
|
-
function toPrimitive(t, r) {
|
|
142
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
143
|
-
var e = t[Symbol.toPrimitive];
|
|
144
|
-
if (void 0 !== e) {
|
|
145
|
-
var i = e.call(t, r || "default");
|
|
146
|
-
if ("object" != _typeof(i)) return i;
|
|
147
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
148
|
-
}
|
|
149
|
-
return ("string" === r ? String : Number)(t);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/toPropertyKey.js
|
|
154
|
-
function toPropertyKey(t) {
|
|
155
|
-
var i = toPrimitive(t, "string");
|
|
156
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region \0@oxc-project+runtime@0.95.0/helpers/defineProperty.js
|
|
161
|
-
function _defineProperty(e, r, t) {
|
|
162
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
163
|
-
value: t,
|
|
164
|
-
enumerable: !0,
|
|
165
|
-
configurable: !0,
|
|
166
|
-
writable: !0
|
|
167
|
-
}) : e[r] = t, e;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
//#endregion
|
|
171
|
-
Object.defineProperty(exports, '_assertClassBrand', {
|
|
172
|
-
enumerable: true,
|
|
173
|
-
get: function () {
|
|
174
|
-
return _assertClassBrand;
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
Object.defineProperty(exports, '_classPrivateFieldGet2', {
|
|
178
|
-
enumerable: true,
|
|
179
|
-
get: function () {
|
|
180
|
-
return _classPrivateFieldGet2;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
Object.defineProperty(exports, '_classPrivateFieldInitSpec', {
|
|
184
|
-
enumerable: true,
|
|
185
|
-
get: function () {
|
|
186
|
-
return _classPrivateFieldInitSpec;
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
Object.defineProperty(exports, '_defineProperty', {
|
|
190
|
-
enumerable: true,
|
|
191
|
-
get: function () {
|
|
192
|
-
return _defineProperty;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
Object.defineProperty(exports, 'createFile', {
|
|
196
|
-
enumerable: true,
|
|
197
|
-
get: function () {
|
|
198
|
-
return createFile;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
//# sourceMappingURL=defineProperty-CjCLDutJ.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineProperty-CjCLDutJ.cjs","names":["exports","name","path","trimExtName"],"sources":["../src/createFile.ts"],"sourcesContent":["import type * as KubbFile from './KubbFile.ts'\nimport { trimExtName } from './utils/trimExtName.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,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,QAAQ;EAAC,IAAI;EAAM,IAAI;EAAc,IAAI;EAAW,CAAU;;AAG1F,SAAgB,eAAe,WAAyD;AACtF,qCAAeA,WAAS;GACrB,MAAM,CAAC,CAAC,MAAM,QAAQ,EAAE,KAAK;GAC7B,MAAM,CAAC,EAAE;GACT,MAAM,EAAE;GACR,MAAM,CAAC,CAAC,EAAE;GACV,MAAO,MAAM,QAAQ,EAAE,KAAK,gCAAW,EAAE,KAAK,GAAG,EAAE;EACrD,CAAC,CAAC,QACA,MAAM,SAAS;EAC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