|
| 1 | +import { log } from '@hey-api/codegen-core'; |
1 | 2 | import type { AnyPluginName, PluginContext, PluginNames } from '@hey-api/shared'; |
2 | 3 | import { dependencyFactory, valueToObject } from '@hey-api/shared'; |
3 | | -import colors from 'ansi-colors'; |
4 | 4 |
|
5 | 5 | import { defaultPluginConfigs } from '../plugins/config'; |
6 | 6 | import type { Config, UserConfig } from './types'; |
@@ -150,24 +150,27 @@ export function getPlugins({ |
150 | 150 | const seenPlugins = new Map<string, string>(); |
151 | 151 |
|
152 | 152 | const stableStringify = (value: unknown): string => |
153 | | - JSON.stringify(value, (_, v) => |
154 | | - v && typeof v === 'object' && !Array.isArray(v) |
155 | | - ? Object.fromEntries( |
156 | | - Object.entries(v as Record<string, unknown>).sort(([a], [b]) => a.localeCompare(b)), |
157 | | - ) |
158 | | - : v, |
159 | | - ); |
160 | | - |
161 | | - const warnConflictingPlugin = (name: string) => |
162 | | - console.warn( |
163 | | - `⚙️ ${colors.yellow('Warning:')} Plugin ${colors.cyan(`"${name}"`)} is configured more than once with conflicting options. Only the last occurrence will take effect.`, |
164 | | - ); |
| 153 | + JSON.stringify(value, (_, v) => { |
| 154 | + if (typeof v === 'function') { |
| 155 | + return `[function:${(v as () => unknown).toString()}]`; |
| 156 | + } |
| 157 | + if (v && typeof v === 'object' && !Array.isArray(v)) { |
| 158 | + return Object.fromEntries( |
| 159 | + Object.entries(v as Record<string, unknown>).sort(([a], [b]) => |
| 160 | + a.localeCompare(b), |
| 161 | + ), |
| 162 | + ); |
| 163 | + } |
| 164 | + return v; |
| 165 | + }); |
165 | 166 |
|
166 | 167 | const checkDuplicate = (name: string, config: Record<string, unknown>) => { |
167 | 168 | const serialized = stableStringify(config); |
168 | 169 | const previous = seenPlugins.get(name); |
169 | 170 | if (previous !== undefined && previous !== serialized) { |
170 | | - warnConflictingPlugin(name); |
| 171 | + log.warn( |
| 172 | + `Plugin "${name}" is configured more than once with conflicting options. Only the last occurrence will take effect.`, |
| 173 | + ); |
171 | 174 | } |
172 | 175 | seenPlugins.set(name, serialized); |
173 | 176 | }; |
|
0 commit comments