Merge pull request #12555 from Knagis/worker-node-version

Fix new Worker() compatibility check in unit tests for older node versions
This commit is contained in:
Tobias Koppers 2021-02-01 20:05:04 +01:00 committed by GitHub
commit bcfb3ad2c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 5 deletions

View File

@ -1,8 +1,14 @@
const nodeVersion = process.versions.node.split(".").map(Number);
module.exports = function supportsWorker() {
try {
// eslint-disable-next-line node/no-unsupported-features/node-builtins
return require("worker_threads") !== undefined;
} catch (e) {
return false;
// Verify that in the current node version new Worker() accepts URL as the first parameter:
// https://nodejs.org/api/worker_threads.html#worker_threads_new_worker_filename_options
if (nodeVersion[0] >= 14) {
return true;
} else if (nodeVersion[0] === 13 && nodeVersion[1] >= 12) {
return true;
} else if (nodeVersion[0] === 12 && nodeVersion[1] >= 17) {
return true;
}
return false;
};