unplugin-kubb 4.0.2 → 5.0.0-alpha.35
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/LICENSE +10 -17
- package/dist/astro.cjs +7 -8
- package/dist/astro.cjs.map +1 -1
- package/dist/astro.d.ts +3 -8
- package/dist/astro.js +7 -9
- package/dist/astro.js.map +1 -1
- package/dist/{chunk-CIm-hhu7.js → chunk--u3MIqq1.js} +2 -3
- package/dist/esbuild.cjs +3 -5
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.d.ts +4 -4
- package/dist/esbuild.js +2 -3
- package/dist/esbuild.js.map +1 -1
- package/dist/farm.cjs +7 -0
- package/dist/farm.cjs.map +1 -0
- package/dist/farm.d.ts +9 -0
- package/dist/farm.js +8 -0
- package/dist/farm.js.map +1 -0
- package/dist/index.cjs +12 -5
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -0
- package/dist/nuxt.cjs +8 -9
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.d.ts +4 -4
- package/dist/nuxt.js +4 -5
- package/dist/nuxt.js.map +1 -1
- package/dist/rolldown.cjs +7 -0
- package/dist/rolldown.cjs.map +1 -0
- package/dist/rolldown.d.ts +9 -0
- package/dist/rolldown.js +8 -0
- package/dist/rolldown.js.map +1 -0
- package/dist/rollup.cjs +3 -5
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.ts +4 -4
- package/dist/rollup.js +2 -3
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +3 -5
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.d.ts +2 -2
- package/dist/rspack.js +2 -3
- package/dist/rspack.js.map +1 -1
- package/dist/types.d.ts +13 -2
- package/dist/types.js +1 -1
- package/dist/unpluginFactory-TMEwHLb9.js +220 -0
- package/dist/unpluginFactory-TMEwHLb9.js.map +1 -0
- package/dist/unpluginFactory-USz7K71q.cjs +263 -0
- package/dist/unpluginFactory-USz7K71q.cjs.map +1 -0
- package/dist/unpluginFactory.cjs +3 -0
- package/dist/unpluginFactory.d.ts +9 -0
- package/dist/unpluginFactory.js +2 -0
- package/dist/vite.cjs +3 -5
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +4 -4
- package/dist/vite.js +2 -3
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +3 -5
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +2 -3
- package/dist/webpack.js.map +1 -1
- package/package.json +74 -45
- package/src/astro.ts +4 -5
- package/src/esbuild.ts +1 -1
- package/src/farm.ts +5 -0
- package/src/index.ts +5 -133
- package/src/nuxt.ts +2 -2
- package/src/rolldown.ts +5 -0
- package/src/rollup.ts +1 -1
- package/src/rspack.ts +1 -1
- package/src/types.ts +2 -2
- package/src/unpluginFactory.ts +140 -0
- package/src/vite.ts +1 -1
- package/src/webpack.ts +1 -2
- package/dist/astro.d.cts +0 -11
- package/dist/esbuild.d.cts +0 -7
- package/dist/index.d.cts +0 -10
- package/dist/nuxt.d.cts +0 -9
- package/dist/rollup.d.cts +0 -7
- package/dist/rspack.d.cts +0 -6
- package/dist/src-BiN2tznZ.cjs +0 -155
- package/dist/src-BiN2tznZ.cjs.map +0 -1
- package/dist/src-CiUcBKSs.js +0 -95
- package/dist/src-CiUcBKSs.js.map +0 -1
- package/dist/types-C-ZTDGdJ.d.cts +0 -650
- package/dist/types-CUVJ-CBJ.d.ts +0 -649
- package/dist/types.d.cts +0 -2
- package/dist/vite.d.cts +0 -7
- package/dist/webpack.d.cts +0 -8
package/dist/webpack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","names":[],"sources":["../src/webpack.ts"],"sourcesContent":["import type { UnpluginFactoryOutput } from 'unplugin'\nimport { createWebpackPlugin } from 'unplugin'\nimport type { WebpackPluginInstance } from 'webpack'\nimport {
|
|
1
|
+
{"version":3,"file":"webpack.js","names":[],"sources":["../src/webpack.ts"],"sourcesContent":["import type { UnpluginFactoryOutput } from 'unplugin'\nimport { createWebpackPlugin } from 'unplugin'\nimport type { WebpackPluginInstance } from 'webpack'\nimport type { Options } from './types.ts'\nimport { unpluginFactory } from './unpluginFactory.ts'\n\nexport default createWebpackPlugin(unpluginFactory) as unknown as UnpluginFactoryOutput<Options, WebpackPluginInstance>\n"],"mappings":";;;AAMA,IAAA,kBAAe,oBAAoB,gBAAgB"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-kubb",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.0.0-alpha.35",
|
|
4
|
+
"description": "Universal build plugin for Kubb, integrating OpenAPI code generation into Vite, Webpack, Rollup, esbuild, Rspack, Nuxt, and Astro build processes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unplugin",
|
|
7
7
|
"vite",
|
|
8
8
|
"webpack",
|
|
9
9
|
"rollup",
|
|
10
|
-
"
|
|
11
|
-
"astro",
|
|
12
|
-
"kubb",
|
|
13
|
-
"swagger",
|
|
14
|
-
"OpenAPI",
|
|
10
|
+
"esbuild",
|
|
15
11
|
"rspack",
|
|
16
12
|
"nuxt",
|
|
17
|
-
"
|
|
13
|
+
"astro",
|
|
14
|
+
"build-tool",
|
|
15
|
+
"bundler",
|
|
16
|
+
"transform",
|
|
17
|
+
"openapi",
|
|
18
|
+
"swagger",
|
|
19
|
+
"code-generator",
|
|
20
|
+
"typescript",
|
|
21
|
+
"kubb"
|
|
18
22
|
],
|
|
19
23
|
"repository": {
|
|
20
24
|
"type": "git",
|
|
21
|
-
"url": "https://github.com/kubb-labs/kubb.git",
|
|
25
|
+
"url": "git+https://github.com/kubb-labs/kubb.git",
|
|
22
26
|
"directory": "packages/unplugin"
|
|
23
27
|
},
|
|
24
28
|
"license": "MIT",
|
|
@@ -27,46 +31,56 @@
|
|
|
27
31
|
"type": "module",
|
|
28
32
|
"exports": {
|
|
29
33
|
".": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.cjs"
|
|
32
36
|
},
|
|
33
37
|
"./astro": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
38
|
+
"import": "./dist/astro.js",
|
|
39
|
+
"require": "./dist/astro.cjs"
|
|
36
40
|
},
|
|
37
41
|
"./esbuild": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
42
|
+
"import": "./dist/esbuild.js",
|
|
43
|
+
"require": "./dist/esbuild.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./farm": {
|
|
46
|
+
"import": "./dist/farm.js",
|
|
47
|
+
"require": "./dist/farm.cjs"
|
|
40
48
|
},
|
|
41
49
|
"./nuxt": {
|
|
42
|
-
"
|
|
43
|
-
"
|
|
50
|
+
"import": "./dist/nuxt.js",
|
|
51
|
+
"require": "./dist/nuxt.cjs"
|
|
52
|
+
},
|
|
53
|
+
"./rolldown": {
|
|
54
|
+
"import": "./dist/rolldown.js",
|
|
55
|
+
"require": "./dist/rolldown.cjs"
|
|
44
56
|
},
|
|
45
57
|
"./rollup": {
|
|
46
|
-
"
|
|
47
|
-
"
|
|
58
|
+
"import": "./dist/rollup.js",
|
|
59
|
+
"require": "./dist/rollup.cjs"
|
|
48
60
|
},
|
|
49
61
|
"./rspack": {
|
|
50
|
-
"
|
|
51
|
-
"
|
|
62
|
+
"import": "./dist/rspack.js",
|
|
63
|
+
"require": "./dist/rspack.cjs"
|
|
52
64
|
},
|
|
53
65
|
"./types": {
|
|
54
|
-
"
|
|
55
|
-
"
|
|
66
|
+
"import": "./dist/types.js",
|
|
67
|
+
"require": "./dist/types.cjs"
|
|
68
|
+
},
|
|
69
|
+
"./unpluginFactory": {
|
|
70
|
+
"import": "./dist/unpluginFactory.js",
|
|
71
|
+
"require": "./dist/unpluginFactory.cjs"
|
|
56
72
|
},
|
|
57
73
|
"./vite": {
|
|
58
|
-
"
|
|
59
|
-
"
|
|
74
|
+
"import": "./dist/vite.js",
|
|
75
|
+
"require": "./dist/vite.cjs"
|
|
60
76
|
},
|
|
61
77
|
"./webpack": {
|
|
62
|
-
"
|
|
63
|
-
"
|
|
78
|
+
"import": "./dist/webpack.js",
|
|
79
|
+
"require": "./dist/webpack.cjs"
|
|
64
80
|
},
|
|
65
81
|
"./package.json": "./package.json"
|
|
66
82
|
},
|
|
67
|
-
"
|
|
68
|
-
"module": "./dist/index.js",
|
|
69
|
-
"types": "./dist/index.d.cts",
|
|
83
|
+
"types": "./dist/index.d.ts",
|
|
70
84
|
"typesVersions": {
|
|
71
85
|
"*": {
|
|
72
86
|
"*": [
|
|
@@ -79,31 +93,41 @@
|
|
|
79
93
|
"src",
|
|
80
94
|
"dist",
|
|
81
95
|
"!/**/**.test.**",
|
|
82
|
-
"!/**/__tests__/**"
|
|
96
|
+
"!/**/__tests__/**",
|
|
97
|
+
"!/**/__snapshots__/**"
|
|
83
98
|
],
|
|
84
99
|
"dependencies": {
|
|
85
|
-
"unplugin": "^
|
|
100
|
+
"unplugin": "^3.0.0",
|
|
101
|
+
"@kubb/adapter-oas": "5.0.0-alpha.35",
|
|
102
|
+
"@kubb/core": "5.0.0-alpha.35",
|
|
103
|
+
"@kubb/parser-ts": "5.0.0-alpha.35"
|
|
86
104
|
},
|
|
87
105
|
"devDependencies": {
|
|
88
|
-
"@
|
|
89
|
-
"@nuxt/
|
|
106
|
+
"@farmfe/core": "^1.7.11",
|
|
107
|
+
"@nuxt/kit": "^4.4.2",
|
|
108
|
+
"@nuxt/schema": "^4.4.2",
|
|
90
109
|
"esbuild": "*",
|
|
91
|
-
"
|
|
92
|
-
"rollup": "^4.
|
|
93
|
-
"vite": "^7.3.
|
|
94
|
-
"webpack": "^5.
|
|
95
|
-
"@
|
|
110
|
+
"rolldown": "~1.0.0-rc.16",
|
|
111
|
+
"rollup": "^4.60.1",
|
|
112
|
+
"vite": "^7.3.2",
|
|
113
|
+
"webpack": "^5.106.2",
|
|
114
|
+
"@internals/utils": "0.0.0"
|
|
96
115
|
},
|
|
97
116
|
"peerDependencies": {
|
|
98
|
-
"@
|
|
99
|
-
"@
|
|
100
|
-
"@nuxt/
|
|
117
|
+
"@farmfe/core": "^1.7.0",
|
|
118
|
+
"@kubb/core": "^5.0.0-alpha.0",
|
|
119
|
+
"@nuxt/kit": "^3 || ^4",
|
|
120
|
+
"@nuxt/schema": "^3 || ^4",
|
|
101
121
|
"esbuild": "*",
|
|
102
|
-
"
|
|
122
|
+
"rolldown": ">=1",
|
|
123
|
+
"rollup": "^3 || ^4",
|
|
103
124
|
"vite": ">=3",
|
|
104
125
|
"webpack": "^5"
|
|
105
126
|
},
|
|
106
127
|
"peerDependenciesMeta": {
|
|
128
|
+
"@farmfe/core": {
|
|
129
|
+
"optional": true
|
|
130
|
+
},
|
|
107
131
|
"@nuxt/kit": {
|
|
108
132
|
"optional": true
|
|
109
133
|
},
|
|
@@ -113,6 +137,9 @@
|
|
|
113
137
|
"esbuild": {
|
|
114
138
|
"optional": true
|
|
115
139
|
},
|
|
140
|
+
"rolldown": {
|
|
141
|
+
"optional": true
|
|
142
|
+
},
|
|
116
143
|
"rollup": {
|
|
117
144
|
"optional": true
|
|
118
145
|
},
|
|
@@ -124,15 +151,17 @@
|
|
|
124
151
|
}
|
|
125
152
|
},
|
|
126
153
|
"engines": {
|
|
127
|
-
"node": ">=
|
|
154
|
+
"node": ">=22"
|
|
128
155
|
},
|
|
129
156
|
"publishConfig": {
|
|
130
157
|
"access": "public",
|
|
131
158
|
"registry": "https://registry.npmjs.org/"
|
|
132
159
|
},
|
|
160
|
+
"main": "./dist/index.cjs",
|
|
161
|
+
"module": "./dist/index.js",
|
|
133
162
|
"scripts": {
|
|
134
163
|
"build": "tsdown",
|
|
135
|
-
"clean": "
|
|
164
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
136
165
|
"lint": "bun biome lint .",
|
|
137
166
|
"lint:fix": "bun biome lint --fix --unsafe .",
|
|
138
167
|
"release": "pnpm publish --no-git-check",
|
package/src/astro.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import unplugin from './index.ts'
|
|
2
|
-
|
|
3
1
|
import type { Options } from './types.ts'
|
|
2
|
+
import vitePlugin from './vite.ts'
|
|
4
3
|
|
|
5
|
-
export default (options: Options) => ({
|
|
6
|
-
name: 'unplugin-
|
|
4
|
+
export default (options: Options): any => ({
|
|
5
|
+
name: 'unplugin-kubb',
|
|
7
6
|
hooks: {
|
|
8
7
|
'astro:config:setup': async (astro: any) => {
|
|
9
8
|
astro.config.vite.plugins ||= []
|
|
10
|
-
astro.config.vite.plugins.push(
|
|
9
|
+
astro.config.vite.plugins.push(vitePlugin(options))
|
|
11
10
|
},
|
|
12
11
|
},
|
|
13
12
|
})
|
package/src/esbuild.ts
CHANGED
package/src/farm.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -1,137 +1,9 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
|
-
import { type Config, type KubbEvents, safeBuild } from '@kubb/core'
|
|
3
|
-
import { AsyncEventEmitter } from '@kubb/core/utils'
|
|
4
|
-
import type { UnpluginFactory } from 'unplugin'
|
|
5
1
|
import { createUnplugin } from 'unplugin'
|
|
6
|
-
import {
|
|
7
|
-
import type { Options } from './types.ts'
|
|
2
|
+
import { unpluginFactory } from './unpluginFactory.ts'
|
|
8
3
|
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
warn?: (message: string) => void
|
|
12
|
-
error?: (message: string) => void
|
|
13
|
-
}
|
|
4
|
+
export type { Options } from './types.ts'
|
|
5
|
+
export { unpluginFactory } from './unpluginFactory.ts'
|
|
14
6
|
|
|
15
|
-
|
|
16
|
-
const name = 'unplugin-kubb' as const
|
|
17
|
-
const events = new AsyncEventEmitter<KubbEvents>()
|
|
18
|
-
const isVite = meta.framework === 'vite'
|
|
19
|
-
const hrStart = process.hrtime()
|
|
7
|
+
const plugin = /* #__PURE__ */ createUnplugin(unpluginFactory)
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
if (!options?.config) {
|
|
23
|
-
if (ctx.error) {
|
|
24
|
-
ctx.error?.(`[${name}] Config is not set`)
|
|
25
|
-
} else {
|
|
26
|
-
console.error(`[${name}] Config is not set`)
|
|
27
|
-
}
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
events.on('lifecycle:start', (version) => {
|
|
32
|
-
console.log(`Kubb Unplugin ${version} 🧩`)
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
events.on('error', (error) => {
|
|
36
|
-
console.error(`✗ ${error?.message || 'failed'}`)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
events.on('warn', (message) => {
|
|
40
|
-
console.warn(`⚠ ${message}`)
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
events.on('info', (message) => {
|
|
44
|
-
console.info(`ℹ ${message}`)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
events.on('success', (message) => {
|
|
48
|
-
console.log(`✓ ${message}`)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
events.on('plugin:end', (plugin, { duration }) => {
|
|
52
|
-
const durationStr = duration >= 1000 ? `${(duration / 1000).toFixed(2)}s` : `${duration}ms`
|
|
53
|
-
|
|
54
|
-
console.log(`✓ ${plugin.name} completed in ${durationStr}`)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
events.on('files:processing:end', () => {
|
|
58
|
-
const text = '✓ Files written successfully'
|
|
59
|
-
|
|
60
|
-
console.log(text)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
events.on('generation:end', (config) => {
|
|
64
|
-
console.log(config.name ? `✓ Generation completed for ${config.name}` : '✓ Generation completed')
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
events.on('generation:summary', (config, { status, failedPlugins }) => {
|
|
68
|
-
const pluginsCount = config.plugins?.length || 0
|
|
69
|
-
const successCount = pluginsCount - failedPlugins.size
|
|
70
|
-
|
|
71
|
-
console.log(
|
|
72
|
-
status === 'success'
|
|
73
|
-
? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total`
|
|
74
|
-
: `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`,
|
|
75
|
-
)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
await events.emit('lifecycle:start', unpluginVersion)
|
|
79
|
-
|
|
80
|
-
const { root: _root, ...userConfig } = options.config as Config
|
|
81
|
-
|
|
82
|
-
await events.emit('generation:start', options.config as Config)
|
|
83
|
-
|
|
84
|
-
const { error, failedPlugins, pluginTimings, files } = await safeBuild({
|
|
85
|
-
config: {
|
|
86
|
-
root: process.cwd(),
|
|
87
|
-
...userConfig,
|
|
88
|
-
output: {
|
|
89
|
-
write: true,
|
|
90
|
-
...userConfig.output,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
events,
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
const hasFailures = failedPlugins.size > 0 || error
|
|
97
|
-
if (hasFailures) {
|
|
98
|
-
// Collect all errors from failed plugins and general error
|
|
99
|
-
const allErrors: Error[] = [
|
|
100
|
-
error,
|
|
101
|
-
...Array.from(failedPlugins)
|
|
102
|
-
.filter((it) => it.error)
|
|
103
|
-
.map((it) => it.error),
|
|
104
|
-
].filter(Boolean)
|
|
105
|
-
|
|
106
|
-
allErrors.forEach((err) => {
|
|
107
|
-
events.emit('error', err)
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
await events.emit('generation:end', options.config as Config)
|
|
112
|
-
await events.emit('generation:summary', options.config as Config, {
|
|
113
|
-
failedPlugins,
|
|
114
|
-
filesCreated: files.length,
|
|
115
|
-
status: failedPlugins.size > 0 || error ? 'failed' : 'success',
|
|
116
|
-
hrStart,
|
|
117
|
-
pluginTimings,
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
await events.emit('lifecycle:end')
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
name,
|
|
125
|
-
enforce: 'pre',
|
|
126
|
-
apply: isVite ? 'build' : undefined,
|
|
127
|
-
async buildStart() {
|
|
128
|
-
await runBuild(this as unknown as RollupContext)
|
|
129
|
-
},
|
|
130
|
-
|
|
131
|
-
vite: {},
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)
|
|
136
|
-
|
|
137
|
-
export default unplugin
|
|
9
|
+
export { plugin as unplugin, plugin as default }
|
package/src/nuxt.ts
CHANGED
|
@@ -9,8 +9,8 @@ export interface ModuleOptions extends Options {}
|
|
|
9
9
|
|
|
10
10
|
export default defineNuxtModule<ModuleOptions>({
|
|
11
11
|
meta: {
|
|
12
|
-
name: 'nuxt-unplugin-
|
|
13
|
-
configKey: '
|
|
12
|
+
name: 'nuxt-unplugin-kubb',
|
|
13
|
+
configKey: 'unpluginKubb',
|
|
14
14
|
},
|
|
15
15
|
defaults: undefined,
|
|
16
16
|
setup(options, _nuxt) {
|
package/src/rolldown.ts
ADDED
package/src/rollup.ts
CHANGED
package/src/rspack.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { AsyncEventEmitter } from '@internals/utils'
|
|
3
|
+
import { adapterOas } from '@kubb/adapter-oas'
|
|
4
|
+
import { type Config, createKubb, type KubbHooks } from '@kubb/core'
|
|
5
|
+
import { parserTs } from '@kubb/parser-ts'
|
|
6
|
+
import type { UnpluginFactory } from 'unplugin'
|
|
7
|
+
import { version as unpluginVersion } from '../package.json'
|
|
8
|
+
import type { Options } from './types.ts'
|
|
9
|
+
|
|
10
|
+
type RollupContext = {
|
|
11
|
+
info?: (message: string) => void
|
|
12
|
+
warn?: (message: string) => void
|
|
13
|
+
error?: (message: string) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const unpluginFactory: UnpluginFactory<Options | undefined> = (options, meta) => {
|
|
17
|
+
const name = 'unplugin-kubb' as const
|
|
18
|
+
const hooks = new AsyncEventEmitter<KubbHooks>()
|
|
19
|
+
const isVite = meta.framework === 'vite'
|
|
20
|
+
const hrStart = process.hrtime()
|
|
21
|
+
|
|
22
|
+
async function runBuild(ctx: RollupContext) {
|
|
23
|
+
if (!options?.config) {
|
|
24
|
+
if (ctx.error) {
|
|
25
|
+
ctx.error?.(`[${name}] Config is not set`)
|
|
26
|
+
} else {
|
|
27
|
+
console.error(`[${name}] Config is not set`)
|
|
28
|
+
}
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const config = {
|
|
33
|
+
...options.config,
|
|
34
|
+
adapter: options.config.adapter ?? adapterOas(),
|
|
35
|
+
parsers: options.config.parsers?.length ? options.config.parsers : [parserTs],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
hooks.on('kubb:lifecycle:start', (version) => {
|
|
39
|
+
console.log(`Kubb Unplugin ${version} 🧩`)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
hooks.on('kubb:error', (error) => {
|
|
43
|
+
console.error(`✗ ${error?.message || 'failed'}`)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
hooks.on('kubb:warn', (message) => {
|
|
47
|
+
console.warn(`⚠ ${message}`)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
hooks.on('kubb:info', (message) => {
|
|
51
|
+
console.info(`ℹ ${message}`)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
hooks.on('kubb:success', (message) => {
|
|
55
|
+
console.log(`✓ ${message}`)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
59
|
+
const durationStr = duration >= 1000 ? `${(duration / 1000).toFixed(2)}s` : `${duration}ms`
|
|
60
|
+
|
|
61
|
+
console.log(`✓ ${plugin.name} completed in ${durationStr}`)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
hooks.on('kubb:files:processing:end', () => {
|
|
65
|
+
const text = '✓ Files written successfully'
|
|
66
|
+
|
|
67
|
+
console.log(text)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
hooks.on('kubb:generation:end', (config) => {
|
|
71
|
+
console.log(config.name ? `✓ Generation completed for ${config.name}` : '✓ Generation completed')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
hooks.on('kubb:generation:summary', (config, { status, failedPlugins }) => {
|
|
75
|
+
const pluginsCount = config.plugins.length
|
|
76
|
+
const successCount = pluginsCount - failedPlugins.size
|
|
77
|
+
|
|
78
|
+
console.log(
|
|
79
|
+
status === 'success'
|
|
80
|
+
? `Kubb Summary: ✓ ${`${successCount} successful`}, ${pluginsCount} total`
|
|
81
|
+
: `Kubb Summary: ✓ ${`${successCount} successful`}, ✗ ${`${failedPlugins.size} failed`}, ${pluginsCount} total`,
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
await hooks.emit('kubb:lifecycle:start', unpluginVersion)
|
|
86
|
+
|
|
87
|
+
const { root: _root, ...userConfig } = config as Config
|
|
88
|
+
|
|
89
|
+
await hooks.emit('kubb:generation:start', config as Config)
|
|
90
|
+
|
|
91
|
+
const { error, failedPlugins, pluginTimings, files, sources } = await createKubb({
|
|
92
|
+
config: {
|
|
93
|
+
root: process.cwd(),
|
|
94
|
+
...userConfig,
|
|
95
|
+
output: {
|
|
96
|
+
write: true,
|
|
97
|
+
...userConfig.output,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
hooks,
|
|
101
|
+
}).safeBuild()
|
|
102
|
+
|
|
103
|
+
const hasFailures = failedPlugins.size > 0 || error
|
|
104
|
+
if (hasFailures) {
|
|
105
|
+
// Collect all errors from failed plugins and general error
|
|
106
|
+
const allErrors: Error[] = [
|
|
107
|
+
error,
|
|
108
|
+
...Array.from(failedPlugins)
|
|
109
|
+
.filter((it) => it.error)
|
|
110
|
+
.map((it) => it.error),
|
|
111
|
+
].filter(Boolean)
|
|
112
|
+
|
|
113
|
+
allErrors.forEach((err) => {
|
|
114
|
+
hooks.emit('kubb:error', err)
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
await hooks.emit('kubb:generation:end', config as Config, files, sources)
|
|
119
|
+
await hooks.emit('kubb:generation:summary', config as Config, {
|
|
120
|
+
failedPlugins,
|
|
121
|
+
filesCreated: files.length,
|
|
122
|
+
status: failedPlugins.size > 0 || error ? 'failed' : 'success',
|
|
123
|
+
hrStart,
|
|
124
|
+
pluginTimings,
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
await hooks.emit('kubb:lifecycle:end')
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
name,
|
|
132
|
+
enforce: 'pre',
|
|
133
|
+
apply: isVite ? 'build' : undefined,
|
|
134
|
+
async buildStart() {
|
|
135
|
+
await runBuild(this as unknown as RollupContext)
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
vite: {},
|
|
139
|
+
}
|
|
140
|
+
}
|
package/src/vite.ts
CHANGED
package/src/webpack.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { UnpluginFactoryOutput } from 'unplugin'
|
|
2
2
|
import { createWebpackPlugin } from 'unplugin'
|
|
3
3
|
import type { WebpackPluginInstance } from 'webpack'
|
|
4
|
-
import { unpluginFactory } from './index.ts'
|
|
5
4
|
import type { Options } from './types.ts'
|
|
5
|
+
import { unpluginFactory } from './unpluginFactory.ts'
|
|
6
6
|
|
|
7
|
-
// resolves issue for: The inferred type of 'default' cannot be named without a reference to 'node_modules/webpack'. This is likely not portable. A type annotation is necessary.
|
|
8
7
|
export default createWebpackPlugin(unpluginFactory) as unknown as UnpluginFactoryOutput<Options, WebpackPluginInstance>
|
package/dist/astro.d.cts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { n as __name, t as Options } from "./types-C-ZTDGdJ.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/astro.d.ts
|
|
4
|
-
declare const _default: (options: Options) => {
|
|
5
|
-
name: string;
|
|
6
|
-
hooks: {
|
|
7
|
-
'astro:config:setup': (astro: any) => Promise<void>;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export = _default;
|
|
11
|
-
//# sourceMappingURL=astro.d.cts.map
|
package/dist/esbuild.d.cts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { n as __name, t as Options } from "./types-C-ZTDGdJ.cjs";
|
|
2
|
-
import * as esbuild0 from "esbuild";
|
|
3
|
-
|
|
4
|
-
//#region src/esbuild.d.ts
|
|
5
|
-
declare const _default: (options?: Options | undefined) => esbuild0.Plugin;
|
|
6
|
-
export = _default;
|
|
7
|
-
//# sourceMappingURL=esbuild.d.cts.map
|
package/dist/index.d.cts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { n as __name, t as Options } from "./types-C-ZTDGdJ.cjs";
|
|
2
|
-
import * as unplugin0 from "unplugin";
|
|
3
|
-
import { UnpluginFactory } from "unplugin";
|
|
4
|
-
|
|
5
|
-
//#region src/index.d.ts
|
|
6
|
-
declare const unpluginFactory: UnpluginFactory<Options | undefined>;
|
|
7
|
-
declare const unplugin: unplugin0.UnpluginInstance<Options | undefined, boolean>;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
10
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/nuxt.d.cts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { n as __name, t as Options } from "./types-C-ZTDGdJ.cjs";
|
|
2
|
-
import * as _nuxt_schema0 from "@nuxt/schema";
|
|
3
|
-
|
|
4
|
-
//#region src/nuxt.d.ts
|
|
5
|
-
interface ModuleOptions extends Options {}
|
|
6
|
-
declare const _default: _nuxt_schema0.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { ModuleOptions, _default as default };
|
|
9
|
-
//# sourceMappingURL=nuxt.d.cts.map
|
package/dist/rollup.d.cts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { n as __name, t as Options } from "./types-C-ZTDGdJ.cjs";
|
|
2
|
-
import * as rollup0 from "rollup";
|
|
3
|
-
|
|
4
|
-
//#region src/rollup.d.ts
|
|
5
|
-
declare const _default: (options?: Options | undefined) => rollup0.Plugin<any> | rollup0.Plugin<any>[];
|
|
6
|
-
export = _default;
|
|
7
|
-
//# sourceMappingURL=rollup.d.cts.map
|
package/dist/rspack.d.cts
DELETED