support for cjs and esm javascript

This commit is contained in:
Eric Allam
2024-08-11 20:59:38 +01:00
committed by Eric Allam
parent 6dea6e1c7d
commit d109300492
4 changed files with 37 additions and 3 deletions
+1 -1
View File
@@ -282,7 +282,7 @@ export class BackgroundWorker {
resolved = true;
child.kill();
reject(new Error("Worker timed out"));
}, 20_000);
}, 9920_000);
child.on("message", async (msg: any) => {
const message = parseMessageFromCatalog(msg, indexerToWorkerMessages);
+18 -2
View File
@@ -85,8 +85,8 @@ async function bootstrap() {
for (const file of buildManifest.files) {
const module = await import(file.out);
for (const exportName of Object.keys(module)) {
const task = module[exportName];
for (const exportName of getExportNames(module)) {
const task = module[exportName] ?? module.default?.[exportName];
if (!task) {
continue;
@@ -142,3 +142,19 @@ await sendMessageInCatalog(
return;
});
function getExportNames(module: any) {
const exports: string[] = [];
const exportKeys = Object.keys(module);
if (exportKeys.length === 0) {
return exports;
}
if (exportKeys.length === 1 && exportKeys[0] === "default") {
return Object.keys(module.default);
}
return exportKeys;
}
@@ -0,0 +1,8 @@
import { task } from "@trigger.dev/sdk/v3";
export const myJavascriptTaskESM = task({
id: "my-javascript-task-esm",
run: async (payload) => {
console.log("Hello from JavaScript task in esm!");
},
});
@@ -0,0 +1,10 @@
const { task } = require("@trigger.dev/sdk/v3");
const myJavascriptTask = task({
id: "my-javascript-task",
run: async (payload) => {
console.log("Hello from JavaScript task!");
},
});
module.exports = { myJavascriptTask };