A Trigger.dev extension that enables seamless integration between SvelteKit and Trigger.dev by allowing you to use your SvelteKit functions directly in your Trigger.dev projects.
npm add -D triggerkit
import { sveltekit } from '@sveltejs/kit/vite';
import { triggerkit } from 'triggerkit';
export default defineConfig({
project: "your-project-id",
runtime: "node",
build: {
extensions: [
triggerkit({
includeDirs: ['src/lib/server']
})
]
}
});
// src/lib/server/email.ts
import { EMAIL_API_KEY } from '$env/static/private';
/**
* Sends a welcome email to a new user
*/
export async function sendWelcomeEmail(userId: string) {
// Your email sending logic using EMAIL_API_KEY
return { success: true, userId };
}
import { sendWelcomeEmail } from "virtual:triggerkit";
import { task } from "@trigger.dev/sdk/v3";
export const welcomeEmailTask = task({
id: "welcome-email",
run: async (payload: { userId: string }) => {
const result = await sendWelcomeEmail(payload.userId);
return result;
},
});
interface PluginOptions {
/**
* Directories to scan for exportable functions.
* @default ['src/lib', 'src/lib/server']
*/
includeDirs?: string[];
/**
* File patterns to scan. Use forward slashes even on Windows.
* @default ['**/*.ts', '**/*.js', '**/+server.ts']
*/
filePatterns?: string[];
/**
* Patterns to exclude from scanning. Use forward slashes even on Windows.
* @default ['**/node_modules/**', '**/*.test.ts', '**/*.spec.ts']
*/
exclude?: string[];
}
You can access all discovered functions through the functions object:
import { functions } from 'virtual:triggerkit';
// Call a discovered function
await functions.sendWelcomeEmail(userId);
The plugin automatically handles environment variables imported from $env/static/private
or $env/static/public
, making them available in your Trigger.dev tasks through process.env
.
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.