Skip to content

Commit

Permalink
Merge branch 'feat/esbuild' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
Arun-KumarH committed Feb 29, 2024
2 parents 015e674 + 5d22b41 commit 6c73588
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@
},
"scripts": {
"start": "node lib/start.cjs",
"dev": "cross-env NODE_ENV=development nodemon --watch './src/**/*.ts' --exec node --loader ts-node/esm ./src/start.ts",
"dev": "cross-env NODE_ENV=development node lib/start.cjs",
"test": "npm run lint && c8 --reporter=text npm run mocha",
"lint": "eslint src --ext .ts",
"mocha": "cross-env NODE_ENV=test mocha --full-trace --exit --timeout 30000",
"test-debug": "npm run mocha -- --inspect-brk",
"lcov-report": "c8 report --reporter=lcov",
"coveralls": "c8 report --reporter=text-lcov | coveralls",
"build:tsc": "esbuild ./src/start.ts --bundle --platform=node --outfile=lib/start.cjs --minify --tree-shaking=true --sourcemap=inline",
"build:es": "esbuild ./src/start.ts --bundle --platform=node --outfile=lib/start.cjs --minify --tree-shaking=true --sourcemap=inline",
"build:jobs": "find ./src/jobs -maxdepth 1 -type f -exec bash -c 'esbuild {} --bundle --platform=node --outfile=lib/jobs/$(basename {} .ts).cjs --minify --tree-shaking=true --sourcemap=inline' \\;",
"build:clean": "rimraf lib",
"build": "npm-run-all lint build:clean build:tsc build:jobs"
"build": "npm-run-all lint build:clean build:es build:jobs"
},
"engines": {
"node": ">= 20.8.0"
Expand Down
20 changes: 14 additions & 6 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,23 @@ export class Worker {
}
}
if (externalJobFiles && externalJobFiles.length > 0) {
externalJobFiles.forEach((externalFile) => {
if (externalFile.endsWith('.js')) {
let require_dir = './jobs';
externalJobFiles.forEach( async (externalFile) => {
if (externalFile.endsWith('.js') || externalFile.endsWith('.cjs') ) {
let require_dir = './jobs/';
if (process.env.EXTERNAL_JOBS_REQUIRE_DIR) {
require_dir = process.env.EXTERNAL_JOBS_REQUIRE_DIR;
}
(async () => (await import(require_dir + '/' + externalFile)).default(cfg, logger, events, runWorker))().catch(err => {
logger.error(`Error scheduling job ${externalFile}`, { err: err.message });
});
// check for double default
let fileImport = await import(require_dir + externalFile);
if(fileImport?.default?.default) {
(async () => (await import(require_dir + externalFile)).default.default(cfg, logger, events, runWorker))().catch(err => {
this.logger.error(`Error scheduling external job ${externalFile}`, { err: err.message });
});
} else {
(async () => (await import(require_dir + externalFile)).default(cfg, logger, events, runWorker))().catch(err => {
this.logger.error(`Error scheduling external job ${externalFile}`, { err: err.message });
});
}
}
});
}
Expand Down

0 comments on commit 6c73588

Please sign in to comment.