diff --git a/lib/windows.js b/lib/windows.js index b040c74..2f27ab9 100644 --- a/lib/windows.js +++ b/lib/windows.js @@ -6,27 +6,29 @@ import preGyp from '@mapbox/node-pre-gyp'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const require = createRequire(import.meta.url); +const getAddon = () => { + const require = createRequire(import.meta.url); -const bindingPath = preGyp.find(path.resolve(path.join(__dirname, '../package.json'))); + const bindingPath = preGyp.find(path.resolve(path.join(__dirname, '../package.json'))); -const addon = (fs.existsSync(bindingPath)) ? require(bindingPath) : { - getActiveWindow() {}, - getOpenWindows() {}, + return (fs.existsSync(bindingPath)) ? require(bindingPath) : { + getActiveWindow() {}, + getOpenWindows() {}, + }; }; export async function activeWindow() { - return addon.getActiveWindow(); + return getAddon().getActiveWindow(); } export function activeWindowSync() { - return addon.getActiveWindow(); + return getAddon().getActiveWindow(); } export function openWindows() { - return addon.getOpenWindows(); + return getAddon().getOpenWindows(); } export function openWindowsSync() { - return addon.getOpenWindows(); + return getAddon().getOpenWindows(); }