Skip to content

Commit

Permalink
chore: Expose CORE_PLUGIN_PREFIX as a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyJones committed Jun 15, 2024
1 parent aaa0b01 commit da3ba50
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
10 changes: 8 additions & 2 deletions packages/case-core-plugin-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
MOCK_HTTP_SERVER,
URL_ENCODED_STRING_TYPE,
} from '@contract-case/case-core-plugin-http-dsl';
import { ContractCasePlugin } from '@contract-case/case-plugin-base';
import {
CORE_PLUGIN_PREFIX,
ContractCasePlugin,
} from '@contract-case/case-plugin-base';
import {
HttpBasicAuthMatcher,
HttpRequestMatcher,
Expand All @@ -39,7 +42,10 @@ const CoreHttpPlugin: ContractCasePlugin<
AllHttpMockDescriptors,
AllHttpMockSetupInfo
> = {
name: `_CaseCore: Http / Rest Plugin`,
// Note: If using this code as an example for your own plugin,
// DO NOT start your plugin name with the core plugin prefix
// or ContractCase will not log debug information / load failures appropriately
name: `${CORE_PLUGIN_PREFIX} Http / Rest Plugin`,
version: pluginVersion,
matcherExecutors: {
[HTTP_BASIC_AUTH_TYPE]: HttpBasicAuthMatcher,
Expand Down
13 changes: 7 additions & 6 deletions packages/case-core/src/diffmatch/plugins/loadPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IsCaseNodeForType,
LogContext,
MockExecutorFn,
CORE_PLUGIN_PREFIX,
} from '@contract-case/case-plugin-base';

import { caseVersion } from '../../entities/caseVersion';
Expand All @@ -28,7 +29,7 @@ export const loadPlugin = <
if (loadedPluginVersions[plugin.name] != null) {
if (plugin.version !== loadedPluginVersions[plugin.name]) {
if (
plugin.name.startsWith(`_CaseCore:`) &&
plugin.name.startsWith(CORE_PLUGIN_PREFIX) &&
plugin.version !== caseVersion
) {
throw new CaseCoreError(
Expand All @@ -40,15 +41,15 @@ export const loadPlugin = <
);
}
context.logger.deepMaintainerDebug(
`Plugin '${plugin.name}' at version '${plugin.version}' has been previously loaded, skipping load of mock executors`,
`Plugin '${plugin.name}' at version '${plugin.version}' has been previously loaded, skipping`,
);
return;
}
if (plugin.name.startsWith(`_CaseCore:`)) {
if (plugin.name.startsWith(CORE_PLUGIN_PREFIX)) {
context.logger.deepMaintainerDebug(`Loading core plugin '${plugin.name}'`);
} else {
context.logger.debug(
`Loading mock definitions for plugin '${plugin.name}' version ${plugin.version}`,
`Loading plugin '${plugin.name}' version ${plugin.version}`,
);
}

Expand Down Expand Up @@ -77,8 +78,8 @@ export const loadPlugin = <
unknown,
'_case:MockHttpServer'
>;

typeToPluginName[mockType] = plugin.name;
loadedPluginVersions[plugin.name] = plugin.version;
});

loadedPluginVersions[plugin.name] = plugin.version;
};
12 changes: 12 additions & 0 deletions packages/case-plugin-base/src/corePlugins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* DO NOT USE THIS IN YOUR OWN PLUGINS
*
* The prefix for ContractCase core plugin names. Plugin names with
* this prefix are treated as always loaded, log less debug information,
* and any errors in loading are treated as core crashes rather than user
* configuration errors.
*
* Other than the way logs and load failures are treated, there's no special
* treatment given to core plugins,
*/
export const CORE_PLUGIN_PREFIX = '_CaseCore:' as const;
1 change: 1 addition & 0 deletions packages/case-plugin-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

export * from './context';
// export * from './core';
export * from './corePlugins';
export * from './errors';
export * from './logger';
export * from './matchers';
Expand Down

0 comments on commit da3ba50

Please sign in to comment.