Skip to content

Commit

Permalink
Avoid Webpack warning due to non-literal require (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Livven committed Feb 16, 2020
1 parent b01a5cc commit 9774aaa
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ const path = require('path');
const crypto = require('crypto');
const isStream = require('is-stream');

const requireOptional = (name, defaultValue) => {
const {Worker} = (() => {
try {
return require(name);
return require('worker_threads');
} catch (_) {
return defaultValue;
return {};
}
};

const {Worker} = requireOptional('worker_threads', {});
})();

let worker; // Lazy
let taskIdCounter = 0;
Expand Down

0 comments on commit 9774aaa

Please sign in to comment.