Skip to content

Commit e78ce75

Browse files
committed
feat: warn when duplicate plugins are specified
Emit a console warning when the same plugin name appears multiple times in the plugins array. The last configuration still wins, but users now get a diagnostic pointing to the root cause of unexpected behavior. Closes #3600
1 parent 5e1eaea commit e78ce75

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
Warn when the same plugin is specified multiple times in the plugins array

packages/openapi-ts/src/config/plugins.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { AnyPluginName, PluginContext, PluginNames } from '@hey-api/shared';
22
import { dependencyFactory, valueToObject } from '@hey-api/shared';
3+
import colors from 'ansi-colors';
34

45
import { defaultPluginConfigs } from '../plugins/config';
56
import type { Config, UserConfig } from './types';
@@ -146,15 +147,30 @@ export function getPlugins({
146147
}
147148
}
148149

150+
const seenPlugins = new Set<string>();
151+
149152
const userPlugins = definedPlugins
150153
.map((plugin) => {
151154
if (typeof plugin === 'string') {
155+
if (seenPlugins.has(plugin)) {
156+
console.warn(
157+
`⚙️ ${colors.yellow('Warning:')} Duplicate plugin ${colors.cyan(`"${plugin}"`)} detected. The last configuration will be used.`,
158+
);
159+
}
160+
seenPlugins.add(plugin);
152161
return plugin;
153162
}
154163

155164
const pluginName = plugin.name;
156165

157166
if (pluginName) {
167+
if (seenPlugins.has(pluginName)) {
168+
console.warn(
169+
`⚙️ ${colors.yellow('Warning:')} Duplicate plugin ${colors.cyan(`"${pluginName}"`)} detected. The last configuration will be used.`,
170+
);
171+
}
172+
seenPlugins.add(pluginName);
173+
158174
// @ts-expect-error
159175
if (plugin.handler) {
160176
// @ts-expect-error

0 commit comments

Comments
 (0)