@kubb/core 1.1.11 → 1.1.13
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 +25 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -0
- package/package.json +3 -4
- package/src/build.ts +0 -106
- package/src/config.ts +0 -15
- package/src/generators/Generator.ts +0 -23
- package/src/generators/SchemaGenerator.ts +0 -8
- package/src/generators/index.ts +0 -2
- package/src/index.ts +0 -12
- package/src/managers/fileManager/FileManager.ts +0 -127
- package/src/managers/fileManager/index.ts +0 -3
- package/src/managers/fileManager/types.ts +0 -40
- package/src/managers/fileManager/utils.ts +0 -167
- package/src/managers/index.ts +0 -2
- package/src/managers/pluginManager/ParallelPluginError.ts +0 -15
- package/src/managers/pluginManager/PluginError.ts +0 -11
- package/src/managers/pluginManager/PluginManager.ts +0 -474
- package/src/managers/pluginManager/index.ts +0 -5
- package/src/managers/pluginManager/types.ts +0 -29
- package/src/managers/pluginManager/validate.ts +0 -21
- package/src/plugin.ts +0 -111
- package/src/types.ts +0 -253
- package/src/utils/Queue.ts +0 -46
- package/src/utils/TreeNode.ts +0 -122
- package/src/utils/cache.ts +0 -33
- package/src/utils/clean.ts +0 -5
- package/src/utils/getEncodedText.ts +0 -3
- package/src/utils/getStackTrace.ts +0 -20
- package/src/utils/getUniqueName.ts +0 -9
- package/src/utils/index.ts +0 -19
- package/src/utils/isPromise.ts +0 -5
- package/src/utils/isURL.ts +0 -11
- package/src/utils/jsdoc.ts +0 -13
- package/src/utils/nameSorter.ts +0 -9
- package/src/utils/objectToParameters.ts +0 -28
- package/src/utils/read.ts +0 -45
- package/src/utils/renderTemplate.ts +0 -11
- package/src/utils/throttle.ts +0 -30
- package/src/utils/timeout.ts +0 -7
- package/src/utils/transformReservedWord.ts +0 -97
- package/src/utils/uniqueId.ts +0 -5
- package/src/utils/write.ts +0 -25
package/src/build.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { getFileSource } from './managers/fileManager/index.ts'
|
|
2
|
-
import { PluginManager } from './managers/pluginManager/index.ts'
|
|
3
|
-
import { clean, isURL, read } from './utils/index.ts'
|
|
4
|
-
import { isPromise } from './utils/isPromise.ts'
|
|
5
|
-
|
|
6
|
-
import type { Ora } from 'ora'
|
|
7
|
-
import type { File } from './managers/fileManager/index.ts'
|
|
8
|
-
import type { OnExecute } from './managers/pluginManager/index.ts'
|
|
9
|
-
import type { BuildOutput, KubbPlugin, LogLevel, PluginContext, TransformResult } from './types.ts'
|
|
10
|
-
import type { QueueTask } from './utils/index.ts'
|
|
11
|
-
|
|
12
|
-
export type Logger<TParams = Record<string, any>> = {
|
|
13
|
-
log: (message: string | null, options: { logLevel: LogLevel; params?: TParams }) => void
|
|
14
|
-
spinner?: Ora
|
|
15
|
-
}
|
|
16
|
-
type BuildOptions = {
|
|
17
|
-
config: PluginContext['config']
|
|
18
|
-
logger?: Logger
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function transformReducer(
|
|
22
|
-
this: PluginContext,
|
|
23
|
-
_previousCode: string,
|
|
24
|
-
result: TransformResult | Promise<TransformResult>,
|
|
25
|
-
|
|
26
|
-
_plugin: KubbPlugin
|
|
27
|
-
): Promise<string | null> {
|
|
28
|
-
return result
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function build(options: BuildOptions): Promise<BuildOutput> {
|
|
32
|
-
const { config, logger } = options
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
if (!isURL(config.input.path)) {
|
|
36
|
-
await read(config.input.path)
|
|
37
|
-
}
|
|
38
|
-
} catch (e: any) {
|
|
39
|
-
throw new Error('Cannot read file/URL defined in `input.path` or set with --input in the CLI of your Kubb config', { cause: e })
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (config.output.clean) {
|
|
43
|
-
await clean(config.output.path)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const queueTask = async (id: string, file: File) => {
|
|
47
|
-
const { path } = file
|
|
48
|
-
|
|
49
|
-
let code: string | null = getFileSource(file)
|
|
50
|
-
|
|
51
|
-
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
52
|
-
hookName: 'load',
|
|
53
|
-
parameters: [path],
|
|
54
|
-
})
|
|
55
|
-
if (loadedResult && isPromise(loadedResult)) {
|
|
56
|
-
code = await loadedResult
|
|
57
|
-
}
|
|
58
|
-
if (loadedResult && !isPromise(loadedResult)) {
|
|
59
|
-
code = loadedResult
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (code) {
|
|
63
|
-
const transformedCode = await pluginManager.hookReduceArg0({
|
|
64
|
-
hookName: 'transform',
|
|
65
|
-
parameters: [code, path],
|
|
66
|
-
reduce: transformReducer,
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if (config.output.write || config.output.write === undefined) {
|
|
70
|
-
await pluginManager.hookParallel({
|
|
71
|
-
hookName: 'writeFile',
|
|
72
|
-
parameters: [transformedCode, path],
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const onExecute: OnExecute = (executer) => {
|
|
79
|
-
if (!executer) {
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const { hookName, plugin } = executer
|
|
84
|
-
|
|
85
|
-
if (config.logLevel === 'info' && logger) {
|
|
86
|
-
logger.log(null, { logLevel: config.logLevel, params: { hookName, pluginName: plugin.name } })
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const pluginManager = new PluginManager(config, { task: queueTask as QueueTask<File>, onExecute })
|
|
91
|
-
const { plugins, fileManager } = pluginManager
|
|
92
|
-
|
|
93
|
-
await pluginManager.hookParallel<'validate', true>({
|
|
94
|
-
hookName: 'validate',
|
|
95
|
-
parameters: [plugins],
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
await pluginManager.hookParallel({
|
|
99
|
-
hookName: 'buildStart',
|
|
100
|
-
parameters: [config],
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
await pluginManager.hookParallel({ hookName: 'buildEnd' })
|
|
104
|
-
|
|
105
|
-
return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })), pluginManager }
|
|
106
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CLIOptions, KubbUserConfig, MaybePromise } from './types.ts'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Type helper to make it easier to use kubb.config.js
|
|
5
|
-
* accepts a direct {@link KubbConfig} object, or a function that returns it.
|
|
6
|
-
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
7
|
-
*/
|
|
8
|
-
export const defineConfig = (
|
|
9
|
-
options:
|
|
10
|
-
| MaybePromise<KubbUserConfig>
|
|
11
|
-
| ((
|
|
12
|
-
/** The options derived from the CLI flags */
|
|
13
|
-
cliOptions: CLIOptions
|
|
14
|
-
) => MaybePromise<KubbUserConfig>)
|
|
15
|
-
) => options
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
3
|
-
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
4
|
-
*/
|
|
5
|
-
export abstract class Generator<TOptions extends object = object> {
|
|
6
|
-
private _options: TOptions = {} as TOptions
|
|
7
|
-
|
|
8
|
-
constructor(options: TOptions = {} as TOptions) {
|
|
9
|
-
if (options) {
|
|
10
|
-
this._options = {
|
|
11
|
-
...this._options,
|
|
12
|
-
...options,
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return this
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get options() {
|
|
19
|
-
return this._options
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
abstract build(...params: unknown[]): unknown
|
|
23
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Generator } from './Generator.ts'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
|
|
5
|
-
*/
|
|
6
|
-
export abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {
|
|
7
|
-
abstract build(schema: TInput, name: string, description?: string): TOutput
|
|
8
|
-
}
|
package/src/generators/index.ts
DELETED
package/src/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { build } from './build.ts'
|
|
2
|
-
|
|
3
|
-
export * from './config.ts'
|
|
4
|
-
export * from './build.ts'
|
|
5
|
-
export * from './types.ts'
|
|
6
|
-
export { CorePluginOptions, createPlugin, name } from './plugin.ts'
|
|
7
|
-
|
|
8
|
-
export * from './utils/index.ts'
|
|
9
|
-
export * from './managers/index.ts'
|
|
10
|
-
export * from './generators/index.ts'
|
|
11
|
-
|
|
12
|
-
export default build
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import crypto from 'node:crypto'
|
|
2
|
-
|
|
3
|
-
import { read, write } from '../../utils/index.ts'
|
|
4
|
-
|
|
5
|
-
import type { Queue, QueueTask } from '../../utils/index.ts'
|
|
6
|
-
import type { CacheStore, File, Status, UUID } from './types.ts'
|
|
7
|
-
|
|
8
|
-
export class FileManager {
|
|
9
|
-
private cache: Map<CacheStore['id'], CacheStore> = new Map()
|
|
10
|
-
|
|
11
|
-
private task?: QueueTask<File>
|
|
12
|
-
|
|
13
|
-
private queue?: Queue
|
|
14
|
-
|
|
15
|
-
constructor(options?: { queue: Queue; task?: QueueTask<File> }) {
|
|
16
|
-
if (options) {
|
|
17
|
-
this.task = options.task
|
|
18
|
-
this.queue = options.queue
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
private getCache(id: UUID) {
|
|
23
|
-
return this.cache.get(id)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getCacheByPath(path: string | undefined): CacheStore | undefined {
|
|
27
|
-
let cache
|
|
28
|
-
|
|
29
|
-
this.cache.forEach((item) => {
|
|
30
|
-
if (item.file.path === path) {
|
|
31
|
-
cache = item
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
return cache as unknown as CacheStore
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get files() {
|
|
38
|
-
const files: File[] = []
|
|
39
|
-
this.cache.forEach((item) => {
|
|
40
|
-
files.push(item.file)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
return files
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get cachedFiles() {
|
|
47
|
-
const files: CacheStore[] = []
|
|
48
|
-
this.cache.forEach((item) => {
|
|
49
|
-
files.push(item)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
return files
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async add(file: File) {
|
|
56
|
-
const cacheItem: CacheStore = { id: crypto.randomUUID(), file, status: 'new' as Status }
|
|
57
|
-
|
|
58
|
-
this.cache.set(cacheItem.id, cacheItem)
|
|
59
|
-
|
|
60
|
-
if (this.queue) {
|
|
61
|
-
await this.queue.run(async () => {
|
|
62
|
-
await this.task?.(cacheItem.id, file)
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return file
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
addOrAppend(file: File) {
|
|
70
|
-
if (!file.path.endsWith(file.fileName)) {
|
|
71
|
-
// console.warn(`Path ${file.path}(file.path) should end with the fileName ${file.fileName}(file.filename)`)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const previousCache = this.getCacheByPath(file.path)
|
|
75
|
-
|
|
76
|
-
if (previousCache) {
|
|
77
|
-
// empty source will also return true when using includes
|
|
78
|
-
const sourceAlreadyExists = file.source && previousCache.file.source.includes(file.source)
|
|
79
|
-
|
|
80
|
-
if (sourceAlreadyExists) {
|
|
81
|
-
return Promise.resolve(file)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
this.cache.delete(previousCache.id)
|
|
85
|
-
|
|
86
|
-
return this.add({
|
|
87
|
-
...file,
|
|
88
|
-
source: `${previousCache.file.source}\n${file.source}`,
|
|
89
|
-
imports: [...(previousCache.file.imports || []), ...(file.imports || [])],
|
|
90
|
-
exports: [...(previousCache.file.exports || []), ...(file.exports || [])],
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
return this.add(file)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
setStatus(id: UUID, status: Status) {
|
|
97
|
-
const cacheItem = this.getCache(id)
|
|
98
|
-
if (!cacheItem) {
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
cacheItem.status = status
|
|
103
|
-
this.cache.set(id, cacheItem)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
get(id: UUID) {
|
|
107
|
-
const cacheItem = this.getCache(id)
|
|
108
|
-
return cacheItem?.file
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
remove(id: UUID) {
|
|
112
|
-
const cacheItem = this.getCache(id)
|
|
113
|
-
if (!cacheItem) {
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
this.setStatus(id, 'removed')
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
async write(...params: Parameters<typeof write>) {
|
|
121
|
-
return write(...params)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async read(...params: Parameters<typeof read>) {
|
|
125
|
-
return read(...params)
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
type Import = {
|
|
2
|
-
name: string | string[]
|
|
3
|
-
path: string
|
|
4
|
-
isTypeOnly?: boolean
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
type Export = {
|
|
8
|
-
name?: string | string[]
|
|
9
|
-
path: string
|
|
10
|
-
isTypeOnly?: boolean
|
|
11
|
-
asAlias?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type File = {
|
|
15
|
-
/**
|
|
16
|
-
* Name to be used to dynamicly create the fileName(based on input.path)
|
|
17
|
-
*/
|
|
18
|
-
fileName: string
|
|
19
|
-
/**
|
|
20
|
-
* Path will be full qualified path to a specified file
|
|
21
|
-
*/
|
|
22
|
-
path: string
|
|
23
|
-
source: string
|
|
24
|
-
imports?: Import[]
|
|
25
|
-
exports?: Export[]
|
|
26
|
-
/**
|
|
27
|
-
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
28
|
-
* @default `false`
|
|
29
|
-
*/
|
|
30
|
-
override?: boolean
|
|
31
|
-
meta?: {
|
|
32
|
-
pluginName?: string
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type UUID = string
|
|
37
|
-
|
|
38
|
-
export type CacheStore = { id: UUID; file: File; status: Status }
|
|
39
|
-
|
|
40
|
-
export type Status = 'new' | 'success' | 'removed'
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import pathParser from 'node:path'
|
|
2
|
-
|
|
3
|
-
import { createExportDeclaration, createImportDeclaration, print } from '@kubb/ts-codegen'
|
|
4
|
-
|
|
5
|
-
import { TreeNode } from '../../utils/index.ts'
|
|
6
|
-
|
|
7
|
-
import type ts from 'typescript'
|
|
8
|
-
import type { Path } from '../../types.ts'
|
|
9
|
-
import type { PathMode, TreeNodeOptions } from '../../utils/index.ts'
|
|
10
|
-
import type { File } from './types.ts'
|
|
11
|
-
|
|
12
|
-
type TreeNodeData = { type: PathMode; path: Path; name: string }
|
|
13
|
-
|
|
14
|
-
export function writeIndexes(root: string, options: TreeNodeOptions = {}): File[] | null {
|
|
15
|
-
const tree = TreeNode.build<TreeNodeData>(root, { extensions: /\.ts/, ...options })
|
|
16
|
-
|
|
17
|
-
if (!tree) {
|
|
18
|
-
return null
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const fileReducer = (files: File[], currentTree: typeof tree) => {
|
|
22
|
-
if (!currentTree.children) {
|
|
23
|
-
return []
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (currentTree.children?.length > 1) {
|
|
27
|
-
const path = pathParser.resolve(currentTree.data.path, 'index.ts')
|
|
28
|
-
const exports = currentTree.children
|
|
29
|
-
.map((file) => {
|
|
30
|
-
if (!file) {
|
|
31
|
-
return undefined
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const importPath: string = file.data.type === 'directory' ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, '')}`
|
|
35
|
-
|
|
36
|
-
// TODO weird hacky fix
|
|
37
|
-
if (importPath.includes('index') && path.includes('index')) {
|
|
38
|
-
return undefined
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return { path: importPath }
|
|
42
|
-
})
|
|
43
|
-
.filter(Boolean) as File['exports']
|
|
44
|
-
|
|
45
|
-
files.push({
|
|
46
|
-
path,
|
|
47
|
-
fileName: 'index.ts',
|
|
48
|
-
source: '',
|
|
49
|
-
exports,
|
|
50
|
-
})
|
|
51
|
-
} else {
|
|
52
|
-
currentTree.children?.forEach((child) => {
|
|
53
|
-
const path = pathParser.resolve(currentTree.data.path, 'index.ts')
|
|
54
|
-
const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, '')}`
|
|
55
|
-
|
|
56
|
-
files.push({
|
|
57
|
-
path,
|
|
58
|
-
fileName: 'index.ts',
|
|
59
|
-
source: '',
|
|
60
|
-
exports: [{ path: importPath }],
|
|
61
|
-
})
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
currentTree.children.forEach((childItem) => {
|
|
66
|
-
fileReducer(files, childItem)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
return files
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const files = fileReducer([], tree)
|
|
73
|
-
|
|
74
|
-
return files
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function combineFiles(files: Array<File | null>): File[] {
|
|
78
|
-
return (files.filter(Boolean) as File[]).reduce((acc, curr: File) => {
|
|
79
|
-
const prevIndex = acc.findIndex((item) => item.path === curr.path)
|
|
80
|
-
|
|
81
|
-
if (prevIndex !== -1) {
|
|
82
|
-
const prev = acc[prevIndex]
|
|
83
|
-
acc[prevIndex] = {
|
|
84
|
-
...curr,
|
|
85
|
-
source: prev.source && curr.source ? `${prev.source}\n${curr.source}` : "'",
|
|
86
|
-
imports: [...(prev.imports || []), ...(curr.imports || [])],
|
|
87
|
-
exports: [...(prev.exports || []), ...(curr.exports || [])],
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
acc.push(curr)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return acc
|
|
94
|
-
}, [] as File[])
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function getFileSource(file: File): string {
|
|
98
|
-
let { source } = file
|
|
99
|
-
|
|
100
|
-
// TODO make generic check
|
|
101
|
-
if (!file.fileName.endsWith('.ts')) {
|
|
102
|
-
return file.source
|
|
103
|
-
}
|
|
104
|
-
const imports: File['imports'] = []
|
|
105
|
-
const exports: File['exports'] = []
|
|
106
|
-
|
|
107
|
-
file.imports?.forEach((curr) => {
|
|
108
|
-
const existingImport = imports.find((imp) => imp.path === curr.path)
|
|
109
|
-
|
|
110
|
-
if (!existingImport) {
|
|
111
|
-
imports.push({
|
|
112
|
-
...curr,
|
|
113
|
-
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name,
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (existingImport && !Array.isArray(existingImport.name) && existingImport.name !== curr.name) {
|
|
118
|
-
imports.push(curr)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (existingImport && Array.isArray(existingImport.name)) {
|
|
122
|
-
if (Array.isArray(curr.name)) {
|
|
123
|
-
existingImport.name = [...new Set([...existingImport.name, ...curr.name])]
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
file.exports?.forEach((curr) => {
|
|
129
|
-
const exists = exports.find((imp) => imp.path === curr.path)
|
|
130
|
-
if (!exists) {
|
|
131
|
-
exports.push({
|
|
132
|
-
...curr,
|
|
133
|
-
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name,
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (exists && !Array.isArray(exists.name) && exists.name !== curr.name && exists.asAlias === curr.asAlias) {
|
|
138
|
-
exports.push(curr)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (exists && Array.isArray(exists.name)) {
|
|
142
|
-
if (Array.isArray(curr.name)) {
|
|
143
|
-
exists.name = [...new Set([...exists.name, ...curr.name])]
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
const importNodes = imports.reduce((prev, curr) => {
|
|
149
|
-
return [...prev, createImportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly })]
|
|
150
|
-
}, [] as ts.ImportDeclaration[])
|
|
151
|
-
const importSource = print(importNodes)
|
|
152
|
-
|
|
153
|
-
const exportNodes = exports.reduce((prev, curr) => {
|
|
154
|
-
return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly, asAlias: curr.asAlias })]
|
|
155
|
-
}, [] as ts.ExportDeclaration[])
|
|
156
|
-
const exportSource = print(exportNodes)
|
|
157
|
-
|
|
158
|
-
if (importSource) {
|
|
159
|
-
source = `${importSource}\n${source}`
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (exportSource) {
|
|
163
|
-
source = `${exportSource}\n${source}`
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return source
|
|
167
|
-
}
|
package/src/managers/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { PluginError } from './PluginError.ts'
|
|
2
|
-
import type { PluginManager } from './PluginManager'
|
|
3
|
-
|
|
4
|
-
export class ParallelPluginError extends Error {
|
|
5
|
-
public errors: PluginError[]
|
|
6
|
-
|
|
7
|
-
public pluginManager: PluginManager
|
|
8
|
-
|
|
9
|
-
constructor(message: string, options: { cause?: Error; errors: PluginError[]; pluginManager: PluginManager }) {
|
|
10
|
-
super(message, { cause: options.cause })
|
|
11
|
-
|
|
12
|
-
this.errors = options.errors
|
|
13
|
-
this.pluginManager = options.pluginManager
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PluginManager } from './PluginManager'
|
|
2
|
-
|
|
3
|
-
export class PluginError extends Error {
|
|
4
|
-
public pluginManager: PluginManager
|
|
5
|
-
|
|
6
|
-
constructor(message: string, options: { cause?: Error; pluginManager: PluginManager }) {
|
|
7
|
-
super(message, { cause: options.cause })
|
|
8
|
-
|
|
9
|
-
this.pluginManager = options.pluginManager
|
|
10
|
-
}
|
|
11
|
-
}
|