support for cjs and esm javascript
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user