From c46c1b12ef34ac9c010000f8e71a77dc7cb06642 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Sun, 31 Jan 2021 22:21:08 +0700 Subject: [PATCH 1/3] fix: load piscina only if available Signed-off-by: Tuan Anh Tran --- .github/workflows/ci.yaml | 2 +- index.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ae1847a..4787603 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - node-version: [12.x, 13.x, 14.x, 15.x] + node-version: [10.x, 11.x, 12.x, 13.x, 14.x, 15.x] runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v2 diff --git a/index.js b/index.js index fddd295..de3d305 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,19 @@ const { resolve } = require('path') -const WorkerPool = require('piscina') -const pool = new WorkerPool({ filename: resolve(__dirname, 'worker.js') }) +let pool = null +try { + const WorkerPool = require('piscina') + pool = new WorkerPool({ filename: resolve(__dirname, 'worker.js') }) +} catch(e) { + if (e.code === 'MODULE_NOT_FOUND') { + console.warn('[camaro] worker_threads is not available, expect performance drop. Try using Node version >= 12.') + } + + const workerFn = require('./worker') + pool = { + runTask: async (args) => workerFn(args) + } +} function isNonEmptyString(str) { return typeof str === 'string' && str.length > 0 From 82c93c7f8577ba963213acbb91be4efa257f3292 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Sun, 31 Jan 2021 22:29:41 +0700 Subject: [PATCH 2/3] fix: update node ver check + update piscina ver Signed-off-by: Tuan Anh Tran --- index.js | 16 +++++++--------- package.json | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index de3d305..80d2cd1 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,16 @@ const { resolve } = require('path') - +const NODE_MAJOR_VERSION = process.versions.node.split('.')[0] let pool = null -try { - const WorkerPool = require('piscina') - pool = new WorkerPool({ filename: resolve(__dirname, 'worker.js') }) -} catch(e) { - if (e.code === 'MODULE_NOT_FOUND') { - console.warn('[camaro] worker_threads is not available, expect performance drop. Try using Node version >= 12.') - } - + +if (NODE_MAJOR_VERSION < 12) { + console.warn('[camaro] worker_threads is not available, expect performance drop. Try using Node version >= 12.') const workerFn = require('./worker') pool = { runTask: async (args) => workerFn(args) } +} else { + const WorkerPool = require('piscina') + pool = new WorkerPool({ filename: resolve(__dirname, 'worker.js') }) } function isNonEmptyString(str) { diff --git a/package.json b/package.json index 04b9546..566a763 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,6 @@ "tape": "^5.0.1" }, "dependencies": { - "piscina": "^1.6.3" + "piscina": "^2.1.0" } } From 8365fea0d6d8cb3c433ab2b163f116bac349d218 Mon Sep 17 00:00:00 2001 From: Tuan Anh Tran Date: Sun, 31 Jan 2021 22:40:30 +0700 Subject: [PATCH 3/3] release: 6.1.0 Signed-off-by: Tuan Anh Tran --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 566a763..d27ed73 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "camaro", - "version": "6.0.4", + "version": "6.1.0", "description": "Transforming XML to JSON using Node.js binding to native pugixml parser library", "homepage": "https://github.com/tuananh/camaro", "bugs": "https://github.com/tuananh/camaro/issues",