Skip to content

Commit

Permalink
fix(email-plugin): Add warning when running devMode with transport
Browse files Browse the repository at this point in the history
Fixes #2253
  • Loading branch information
michaelbromley committed Jun 29, 2023
1 parent 7a147a8 commit 7498901
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions packages/email-plugin/src/email-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ import {
export class EmailProcessor {
protected emailSender: EmailSender;
protected generator: EmailGenerator;
protected transport:
| EmailTransportOptions
| ((
injector?: Injector,
ctx?: RequestContext,
) => EmailTransportOptions | Promise<EmailTransportOptions>);

constructor(
@Inject(EMAIL_PLUGIN_OPTIONS) protected options: InitializedEmailPluginOptions,
Expand All @@ -49,20 +43,6 @@ export class EmailProcessor {
if (this.generator.onInit) {
await this.generator.onInit.call(this.generator, this.options);
}
if (isDevModeOptions(this.options)) {
this.transport = {
type: 'file',
raw: false,
outputPath: this.options.outputPath,
};
} else {
if (!this.options.transport) {
throw new InternalServerError(
"When devMode is not set to true, the 'transport' property must be set.",
);
}
this.transport = this.options.transport;
}
const transport = await this.getTransportSettings();
if (transport.type === 'file') {
// ensure the configured directory exists before
Expand Down Expand Up @@ -106,14 +86,21 @@ export class EmailProcessor {
}

async getTransportSettings(ctx?: RequestContext): Promise<EmailTransportOptions> {
const transport = await resolveTransportSettings(this.options, new Injector(this.moduleRef), ctx);
if (isDevModeOptions(this.options)) {
if (transport && transport.type !== 'file') {
Logger.warn(
`The EmailPlugin is running in dev mode. The configured '${transport.type}' transport will be replaced by the 'file' transport.`,
loggerCtx,
);
}
return {
type: 'file',
raw: false,
outputPath: this.options.outputPath,
};
} else {
return resolveTransportSettings(this.options, new Injector(this.moduleRef), ctx);
return transport;
}
}
}

0 comments on commit 7498901

Please sign in to comment.