Skip to content

Commit

Permalink
Detect duplicates in plugin names to avoid overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannmoinet committed Dec 9, 2024
1 parent cc2e03e commit bbe728b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/factory/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import type {
} from '@dd/core/types';
import type { UnpluginContextMeta, UnpluginInstance, UnpluginOptions } from 'unplugin';
import { createUnplugin } from 'unplugin';
import chalk from 'chalk';

import { getContext, getLoggerFactory, validateOptions } from './helpers';

/* eslint-disable arca/import-ordering, arca/newline-after-import-section */
// #imports-injection-marker
import type { OptionsWithErrorTracking } from '@dd/error-tracking-plugin/types';
import * as errorTracking from '@dd/error-tracking-plugin';
Expand All @@ -41,7 +41,6 @@ import { getInjectionPlugins } from '@dd/internal-injection-plugin';
export type { types as ErrorTrackingTypes } from '@dd/error-tracking-plugin';
export type { types as TelemetryTypes } from '@dd/telemetry-plugin';
// #types-export-injection-marker
/* eslint-enable arca/import-ordering, arca/newline-after-import-section */

export const helpers = {
// Each product should have a unique entry.
Expand Down Expand Up @@ -138,6 +137,18 @@ export const buildPluginFactory = ({
// List all our plugins in the context.
context.pluginNames.push(...plugins.map((plugin) => plugin.name));

// Verify we don't have plugins with the same name, as they would override each other.
const duplicates = new Set(
context.pluginNames.filter(
(name) => context.pluginNames.filter((n) => n === name).length > 1,
),
);
if (duplicates.size > 0) {
throw new Error(
`Duplicate plugin names: ${chalk.bold.red(Array.from(duplicates).join(', '))}`,
);
}

return plugins;
});
};

0 comments on commit bbe728b

Please sign in to comment.