Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: separate build chunks for services #3

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
entries: [
"src/index",
"src/services/mailgun",
"src/services/plunk",
"src/services/postmark",
"src/services/resend",
"src/services/sendgrid",
],
clean: false,
declaration: true,
rollup: {
emitCJS: true,
},
});
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./mailgun": {
"types": "./dist/services/mailgun.d.ts",
"import": "./dist/services/mailgun.mjs",
"require": "./dist/services/mailgun.cjs"
},
"./plunk": {
"types": "./dist/services/plunk.d.ts",
"import": "./dist/services/plunk.mjs",
"require": "./dist/services/plunk.cjs"
},
"./postmark": {
"types": "./dist/services/postmark.d.ts",
"import": "./dist/services/postmark.mjs",
"require": "./dist/services/postmark.cjs"
},
"./resend": {
"types": "./dist/services/resend.d.ts",
"import": "./dist/services/resend.mjs",
"require": "./dist/services/resend.cjs"
},
"./sendgrid": {
"types": "./dist/services/sendgrid.d.ts",
"import": "./dist/services/sendgrid.mjs",
"require": "./dist/services/sendgrid.cjs"
}
},
"main": "./dist/index.cjs",
Expand Down
16 changes: 6 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
import { PlunkService } from "./services/plunk";
import { PostmarkService } from "./services/postmark";
import { ResendService } from "./services/resend";
import { SendGridService } from "./services/sendgrid";
import { MailgunService } from "./services/mailgun";
import type { EmailProvider } from "./types/email-options";
import type { EmailService } from "./types/email-service";

/**
* Factory function to get the email service based on the provider
* @param provider - The email provider
* @returns The email service instance
* @returns A Promise that resolves to the email service instance
* @throws Error if the provider is not supported
*/
export function useEmail(provider: EmailProvider): EmailService {
export async function useEmail(provider: EmailProvider): Promise<EmailService> {
switch (provider) {
case "resend": {
const { ResendService } = await import("./services/resend");
return new ResendService();
}
case "plunk": {
const { PlunkService } = await import("./services/plunk");
return new PlunkService();
}
case "sendgrid": {
const { SendGridService } = await import("./services/sendgrid");
return new SendGridService();
}
case "postmark": {
const { PostmarkService } = await import("./services/postmark");
return new PostmarkService();
}
case "mailgun": {
return MailgunService();
}
default: {
throw new Error(`Unsupported email provider: ${provider}`);

Check failure on line 29 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci

Unhandled error

Error: Unsupported email provider: unsupported ❯ Module.useEmail src/index.ts:29:13 ❯ test/index.test.ts:18:18 ❯ Proxy.assertThrows node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.js:2682:5 ❯ Proxy.methodWrapper node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.js:1591:25 ❯ Proxy.<anonymous> node_modules/.pnpm/@vitest+expect@2.0.5/node_modules/@vitest/expect/dist/index.js:977:16 ❯ Proxy.overwritingMethodWrapper node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.js:1647:33 ❯ Proxy.<anonymous> node_modules/.pnpm/@vitest+expect@2.0.5/node_modules/@vitest/expect/dist/index.js:1512:21 ❯ Proxy.<anonymous> node_modules/.pnpm/@vitest+expect@2.0.5/node_modules/@vitest/expect/dist/index.js:920:17 ❯ Proxy.methodWrapper node_modules/.pnpm/chai@5.1.1/node_modules/chai/chai.js:1591:25 ❯ test/index.test.ts:18:43 This error originated in "test/index.test.ts" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "test/index.test.ts". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.
}
}
}
1 change: 0 additions & 1 deletion src/services/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class ResendService implements EmailService {
}

async send(emailOptions: EmailOptions): Promise<void> {
console.log(this.apiToken);
if (!this.apiToken) {
throw new Error("Resend API token is missing");
}
Expand Down
Loading