From ff7167c7dd1d867ca9954a6b503e12490c94c099 Mon Sep 17 00:00:00 2001 From: Kirill Shumilov Date: Thu, 7 Feb 2019 18:55:42 +0300 Subject: [PATCH] fix(xod-client-electron): fix including of bundled arduino libraries on upload to board in development mode of IDE --- packages/xod-client-electron/src/app/utils.js | 24 ++++++++++++++++--- .../xod-client-electron/webpack.config.js | 4 ++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/xod-client-electron/src/app/utils.js b/packages/xod-client-electron/src/app/utils.js index 8f4bd13d..9be2626d 100644 --- a/packages/xod-client-electron/src/app/utils.js +++ b/packages/xod-client-electron/src/app/utils.js @@ -54,10 +54,28 @@ export const getFilePathToOpen = app => { return () => pathToOpen; }; +/** + * Returns Path to the resources directory root. + * + * When IDE runs in development mode it resolves to directory + * with transpiled code, and it handles call either from Main Process + * and Renderer Process. They're have a different `__dirname` values: + * - Main Process: /some/path/to/src-babel/app + * - Renderer Process: /some/path/to/src-babel + * + * When IDE runs in production mode it resolves to resources path. + */ +export const getResourcesRoot = () => { + if (IS_DEV) { + return process.type === 'renderer' + ? __dirname + : path.resolve(__dirname, '..'); + } + return process.resourcesPath; +}; + /** * Returns Path to the bundled workspace */ export const getPathToBundledWorkspace = () => - IS_DEV - ? path.resolve(__dirname, '../workspace') - : path.resolve(process.resourcesPath, './workspace'); + path.join(getResourcesRoot(), 'workspace'); diff --git a/packages/xod-client-electron/webpack.config.js b/packages/xod-client-electron/webpack.config.js index 6175a516..af3ad198 100644 --- a/packages/xod-client-electron/webpack.config.js +++ b/packages/xod-client-electron/webpack.config.js @@ -9,6 +9,10 @@ const pkgpath = subpath => path.resolve(__dirname, subpath); module.exports = merge.smart(getBaseConfig(__dirname), { target: 'electron-renderer', + node: { + __dirname: false, + __filename: false, + }, entry: [ pkgpath('src/view/styles/main.scss'), ],