Skip to content

Commit ed79c28

Browse files
committed
chore(rules): upgrade rules for 4.1.0
1 parent 8cec3b7 commit ed79c28

File tree

3 files changed

+662
-1
lines changed

3 files changed

+662
-1
lines changed

rules/4.1.0/config.md

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
# Trigger.dev Configuration (v4)
2+
3+
**Complete guide to configuring `trigger.config.ts` with build extensions**
4+
5+
## Basic Configuration
6+
7+
```ts
8+
import { defineConfig } from "@trigger.dev/sdk";
9+
10+
export default defineConfig({
11+
project: "<project-ref>", // Required: Your project reference
12+
dirs: ["./trigger"], // Task directories
13+
runtime: "node", // "node", "node-22", or "bun"
14+
logLevel: "info", // "debug", "info", "warn", "error"
15+
16+
// Default retry settings
17+
retries: {
18+
enabledInDev: false,
19+
default: {
20+
maxAttempts: 3,
21+
minTimeoutInMs: 1000,
22+
maxTimeoutInMs: 10000,
23+
factor: 2,
24+
randomize: true,
25+
},
26+
},
27+
28+
// Build configuration
29+
build: {
30+
autoDetectExternal: true,
31+
keepNames: true,
32+
minify: false,
33+
extensions: [], // Build extensions go here
34+
},
35+
36+
// Global lifecycle hooks
37+
onStartAttempt: async ({ payload, ctx }) => {
38+
console.log("Global task start");
39+
},
40+
onSuccess: async ({ payload, output, ctx }) => {
41+
console.log("Global task success");
42+
},
43+
onFailure: async ({ payload, error, ctx }) => {
44+
console.log("Global task failure");
45+
},
46+
});
47+
```
48+
49+
## Build Extensions
50+
51+
### Database & ORM
52+
53+
#### Prisma
54+
55+
```ts
56+
import { prismaExtension } from "@trigger.dev/build/extensions/prisma";
57+
58+
extensions: [
59+
prismaExtension({
60+
schema: "prisma/schema.prisma",
61+
version: "5.19.0", // Optional: specify version
62+
migrate: true, // Run migrations during build
63+
directUrlEnvVarName: "DIRECT_DATABASE_URL",
64+
typedSql: true, // Enable TypedSQL support
65+
}),
66+
];
67+
```
68+
69+
#### TypeScript Decorators (for TypeORM)
70+
71+
```ts
72+
import { emitDecoratorMetadata } from "@trigger.dev/build/extensions/typescript";
73+
74+
extensions: [
75+
emitDecoratorMetadata(), // Enables decorator metadata
76+
];
77+
```
78+
79+
### Scripting Languages
80+
81+
#### Python
82+
83+
```ts
84+
import { pythonExtension } from "@trigger.dev/build/extensions/python";
85+
86+
extensions: [
87+
pythonExtension({
88+
scripts: ["./python/**/*.py"], // Copy Python files
89+
requirementsFile: "./requirements.txt", // Install packages
90+
devPythonBinaryPath: ".venv/bin/python", // Dev mode binary
91+
}),
92+
];
93+
94+
// Usage in tasks
95+
const result = await python.runInline(`print("Hello, world!")`);
96+
const output = await python.runScript("./python/script.py", ["arg1"]);
97+
```
98+
99+
### Browser Automation
100+
101+
#### Playwright
102+
103+
```ts
104+
import { playwright } from "@trigger.dev/build/extensions/playwright";
105+
106+
extensions: [
107+
playwright({
108+
browsers: ["chromium", "firefox", "webkit"], // Default: ["chromium"]
109+
headless: true, // Default: true
110+
}),
111+
];
112+
```
113+
114+
#### Puppeteer
115+
116+
```ts
117+
import { puppeteer } from "@trigger.dev/build/extensions/puppeteer";
118+
119+
extensions: [puppeteer()];
120+
121+
// Environment variable needed:
122+
// PUPPETEER_EXECUTABLE_PATH: "/usr/bin/google-chrome-stable"
123+
```
124+
125+
#### Lightpanda
126+
127+
```ts
128+
import { lightpanda } from "@trigger.dev/build/extensions/lightpanda";
129+
130+
extensions: [
131+
lightpanda({
132+
version: "latest", // or "nightly"
133+
disableTelemetry: false,
134+
}),
135+
];
136+
```
137+
138+
### Media Processing
139+
140+
#### FFmpeg
141+
142+
```ts
143+
import { ffmpeg } from "@trigger.dev/build/extensions/core";
144+
145+
extensions: [
146+
ffmpeg({ version: "7" }), // Static build, or omit for Debian version
147+
];
148+
149+
// Automatically sets FFMPEG_PATH and FFPROBE_PATH
150+
// Add fluent-ffmpeg to external packages if using
151+
```
152+
153+
#### Audio Waveform
154+
155+
```ts
156+
import { audioWaveform } from "@trigger.dev/build/extensions/audioWaveform";
157+
158+
extensions: [
159+
audioWaveform(), // Installs Audio Waveform 1.1.0
160+
];
161+
```
162+
163+
### System & Package Management
164+
165+
#### System Packages (apt-get)
166+
167+
```ts
168+
import { aptGet } from "@trigger.dev/build/extensions/core";
169+
170+
extensions: [
171+
aptGet({
172+
packages: ["ffmpeg", "imagemagick", "curl=7.68.0-1"], // Can specify versions
173+
}),
174+
];
175+
```
176+
177+
#### Additional NPM Packages
178+
179+
Only use this for installing CLI tools, NOT packages you import in your code.
180+
181+
```ts
182+
import { additionalPackages } from "@trigger.dev/build/extensions/core";
183+
184+
extensions: [
185+
additionalPackages({
186+
packages: ["wrangler"], // CLI tools and specific versions
187+
}),
188+
];
189+
```
190+
191+
#### Additional Files
192+
193+
```ts
194+
import { additionalFiles } from "@trigger.dev/build/extensions/core";
195+
196+
extensions: [
197+
additionalFiles({
198+
files: ["wrangler.toml", "./assets/**", "./fonts/**"], // Glob patterns supported
199+
}),
200+
];
201+
```
202+
203+
### Environment & Build Tools
204+
205+
#### Environment Variable Sync
206+
207+
```ts
208+
import { syncEnvVars } from "@trigger.dev/build/extensions/core";
209+
210+
extensions: [
211+
syncEnvVars(async (ctx) => {
212+
// ctx contains: environment, projectRef, env
213+
return [
214+
{ name: "SECRET_KEY", value: await getSecret(ctx.environment) },
215+
{ name: "API_URL", value: ctx.environment === "prod" ? "api.prod.com" : "api.dev.com" },
216+
];
217+
}),
218+
];
219+
```
220+
221+
#### ESBuild Plugins
222+
223+
```ts
224+
import { esbuildPlugin } from "@trigger.dev/build/extensions";
225+
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
226+
227+
extensions: [
228+
esbuildPlugin(
229+
sentryEsbuildPlugin({
230+
org: process.env.SENTRY_ORG,
231+
project: process.env.SENTRY_PROJECT,
232+
authToken: process.env.SENTRY_AUTH_TOKEN,
233+
}),
234+
{ placement: "last", target: "deploy" } // Optional config
235+
),
236+
];
237+
```
238+
239+
## Custom Build Extensions
240+
241+
```ts
242+
import { defineConfig } from "@trigger.dev/sdk";
243+
244+
const customExtension = {
245+
name: "my-custom-extension",
246+
247+
externalsForTarget: (target) => {
248+
return ["some-native-module"]; // Add external dependencies
249+
},
250+
251+
onBuildStart: async (context) => {
252+
console.log(`Build starting for ${context.target}`);
253+
// Register esbuild plugins, modify build context
254+
},
255+
256+
onBuildComplete: async (context, manifest) => {
257+
console.log("Build complete, adding layers");
258+
// Add build layers, modify deployment
259+
context.addLayer({
260+
id: "my-layer",
261+
files: [{ source: "./custom-file", destination: "/app/custom" }],
262+
commands: ["chmod +x /app/custom"],
263+
});
264+
},
265+
};
266+
267+
export default defineConfig({
268+
project: "my-project",
269+
build: {
270+
extensions: [customExtension],
271+
},
272+
});
273+
```
274+
275+
## Advanced Configuration
276+
277+
### Telemetry
278+
279+
```ts
280+
import { PrismaInstrumentation } from "@prisma/instrumentation";
281+
import { OpenAIInstrumentation } from "@langfuse/openai";
282+
283+
export default defineConfig({
284+
// ... other config
285+
telemetry: {
286+
instrumentations: [new PrismaInstrumentation(), new OpenAIInstrumentation()],
287+
exporters: [customExporter], // Optional custom exporters
288+
},
289+
});
290+
```
291+
292+
### Machine & Performance
293+
294+
```ts
295+
export default defineConfig({
296+
// ... other config
297+
defaultMachine: "large-1x", // Default machine for all tasks
298+
maxDuration: 300, // Default max duration (seconds)
299+
enableConsoleLogging: true, // Console logging in development
300+
});
301+
```
302+
303+
## Common Extension Combinations
304+
305+
### Full-Stack Web App
306+
307+
```ts
308+
extensions: [
309+
prismaExtension({ schema: "prisma/schema.prisma", migrate: true }),
310+
additionalFiles({ files: ["./public/**", "./assets/**"] }),
311+
syncEnvVars(async (ctx) => [...envVars]),
312+
];
313+
```
314+
315+
### AI/ML Processing
316+
317+
```ts
318+
extensions: [
319+
pythonExtension({
320+
scripts: ["./ai/**/*.py"],
321+
requirementsFile: "./requirements.txt",
322+
}),
323+
ffmpeg({ version: "7" }),
324+
additionalPackages({ packages: ["wrangler"] }),
325+
];
326+
```
327+
328+
### Web Scraping
329+
330+
```ts
331+
extensions: [
332+
playwright({ browsers: ["chromium"] }),
333+
puppeteer(),
334+
additionalFiles({ files: ["./selectors.json", "./proxies.txt"] }),
335+
];
336+
```
337+
338+
## Best Practices
339+
340+
- **Use specific versions**: Pin extension versions for reproducible builds
341+
- **External packages**: Add modules with native addons to the `build.external` array
342+
- **Environment sync**: Use `syncEnvVars` for dynamic secrets
343+
- **File paths**: Use glob patterns for flexible file inclusion
344+
- **Debug builds**: Use `--log-level debug --dry-run` for troubleshooting
345+
346+
Extensions only affect deployment, not local development. Use `external` array for packages that shouldn't be bundled.

0 commit comments

Comments
 (0)