Skip to content

Commit 0ebec41

Browse files
committed
Fix build problem on non-Windows
1 parent 28b0562 commit 0ebec41

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/windows.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,29 @@ import preGyp from '@mapbox/node-pre-gyp';
66

77
const __dirname = path.dirname(fileURLToPath(import.meta.url));
88

9-
const require = createRequire(import.meta.url);
9+
const getAddon = () => {
10+
const require = createRequire(import.meta.url);
1011

11-
const bindingPath = preGyp.find(path.resolve(path.join(__dirname, '../package.json')));
12+
const bindingPath = preGyp.find(path.resolve(path.join(__dirname, '../package.json')));
1213

13-
const addon = (fs.existsSync(bindingPath)) ? require(bindingPath) : {
14-
getActiveWindow() {},
15-
getOpenWindows() {},
14+
return (fs.existsSync(bindingPath)) ? require(bindingPath) : {
15+
getActiveWindow() {},
16+
getOpenWindows() {},
17+
};
1618
};
1719

1820
export async function activeWindow() {
19-
return addon.getActiveWindow();
21+
return getAddon().getActiveWindow();
2022
}
2123

2224
export function activeWindowSync() {
23-
return addon.getActiveWindow();
25+
return getAddon().getActiveWindow();
2426
}
2527

2628
export function openWindows() {
27-
return addon.getOpenWindows();
29+
return getAddon().getOpenWindows();
2830
}
2931

3032
export function openWindowsSync() {
31-
return addon.getOpenWindows();
33+
return getAddon().getOpenWindows();
3234
}

0 commit comments

Comments
 (0)