buster/apps/trigger/trigger.config.ts

81 lines
2.6 KiB
TypeScript

import * as fs from 'node:fs';
import * as path from 'node:path';
import { esbuildPlugin } from '@trigger.dev/build/extensions';
import { defineConfig } from '@trigger.dev/sdk';
// Load environment variables from root .env file
import { loadRootEnv } from '@buster/env-utils';
loadRootEnv();
export default defineConfig({
project: 'proj_lyyhkqmzhwiskfnavddk',
runtime: 'node',
logLevel: 'log',
// The max compute seconds a task is allowed to run. If the task run exceeds this duration, it will be stopped.
// You can override this on an individual task.
// See https://trigger.dev/docs/runs/max-duration
maxDuration: 3600,
retries: {
enabledInDev: true,
default: {
maxAttempts: 3,
minTimeoutInMs: 1000,
maxTimeoutInMs: 10000,
factor: 2,
randomize: true,
},
},
build: {
external: ['lz4', 'xxhash'],
extensions: [
esbuildPlugin({
name: 'buster-path-resolver',
setup(build) {
// Resolve all @buster/* imports
build.onResolve({ filter: /^@buster\// }, (args) => {
const fullPath = args.path.replace('@buster/', '');
const parts = fullPath.split('/');
const packageName = parts[0];
const subPath = parts.slice(1).join('/');
let resolvedPath: string;
if (subPath) {
// Handle sub-paths like @buster/server-shared/metrics
// Check if subPath already starts with 'src', if so, don't add it again
const cleanSubPath = subPath.startsWith('src/') ? subPath.slice(4) : subPath;
const basePath = path.resolve(process.cwd(), '../..', 'packages', packageName, 'src');
// Try to resolve as a directory with index.ts first, then as a .ts file
const indexPath = path.join(basePath, cleanSubPath, 'index.ts');
const directPath = path.join(basePath, `${cleanSubPath}.ts`);
// Check if it's a directory with index.ts
if (fs.existsSync(indexPath)) {
resolvedPath = indexPath;
} else {
resolvedPath = directPath;
}
} else {
// Handle direct package imports like @buster/ai
resolvedPath = path.resolve(
process.cwd(),
'../..',
'packages',
packageName,
'src',
'index.ts'
);
}
return {
path: resolvedPath,
namespace: 'file',
};
});
},
}),
],
},
dirs: ['./src'],
});