diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-04 01:19:39 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-02-08 21:42:25 +0100 |
commit | 1b17d2f9fefb53329838a16ff72436bd9bdcf220 (patch) | |
tree | 85e7464ed09779daaa456c7ffcc395a7f42db38d /packages/main/src | |
parent | feat: Rewrite the config if new details are added (diff) | |
download | sophie-1b17d2f9fefb53329838a16ff72436bd9bdcf220.tar.gz sophie-1b17d2f9fefb53329838a16ff72436bd9bdcf220.tar.zst sophie-1b17d2f9fefb53329838a16ff72436bd9bdcf220.zip |
feat: Source mapping for stacktraces in dev mode
We have to cheat again and use require() to lazy load a dev dependency.
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src')
-rw-r--r-- | packages/main/src/devTools.ts | 20 | ||||
-rw-r--r-- | packages/main/src/index.ts | 8 |
2 files changed, 24 insertions, 4 deletions
diff --git a/packages/main/src/devTools.ts b/packages/main/src/devTools.ts index 4ca1bf3..10f4545 100644 --- a/packages/main/src/devTools.ts +++ b/packages/main/src/devTools.ts | |||
@@ -35,13 +35,28 @@ export const DEVMODE_ALLOWED_URL_PREFIXES = [ | |||
35 | ]; | 35 | ]; |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Enables using source maps for node stack traces. | ||
39 | */ | ||
40 | export function enableStacktraceSourceMaps(): void { | ||
41 | const sourceMapSupport = | ||
42 | /* eslint-disable-next-line | ||
43 | import/no-extraneous-dependencies, | ||
44 | global-require, | ||
45 | @typescript-eslint/no-var-requires, | ||
46 | unicorn/prefer-module -- | ||
47 | Hack to lazily require a CJS module from an ES module transpiled into a CJS module. | ||
48 | */ | ||
49 | require('source-map-support') as typeof import('source-map-support'); | ||
50 | sourceMapSupport.install(); | ||
51 | } | ||
52 | |||
53 | /** | ||
38 | * Installs the react and redux developer tools extensions. | 54 | * Installs the react and redux developer tools extensions. |
39 | * | 55 | * |
40 | * We use the redux devtools and connect the mobx store to it with `mst-middlewares`, | 56 | * We use the redux devtools and connect the mobx store to it with `mst-middlewares`, |
41 | * because the mobx-state-tree devtools are currently unmaintained. | 57 | * because the mobx-state-tree devtools are currently unmaintained. |
42 | */ | 58 | */ |
43 | export async function installDevToolsExtensions(): Promise<void> { | 59 | export async function installDevToolsExtensions(): Promise<void> { |
44 | // Hack to lazily require a CJS module from an ES module transpiled into a CJS module. | ||
45 | const { | 60 | const { |
46 | default: installExtension, | 61 | default: installExtension, |
47 | REACT_DEVELOPER_TOOLS, | 62 | REACT_DEVELOPER_TOOLS, |
@@ -50,7 +65,8 @@ export async function installDevToolsExtensions(): Promise<void> { | |||
50 | import/no-extraneous-dependencies, | 65 | import/no-extraneous-dependencies, |
51 | global-require, | 66 | global-require, |
52 | @typescript-eslint/no-var-requires, | 67 | @typescript-eslint/no-var-requires, |
53 | unicorn/prefer-module | 68 | unicorn/prefer-module -- |
69 | Hack to lazily require a CJS module from an ES module transpiled into a CJS module. | ||
54 | */ | 70 | */ |
55 | } = require('electron-devtools-installer') as typeof import('electron-devtools-installer'); | 71 | } = require('electron-devtools-installer') as typeof import('electron-devtools-installer'); |
56 | await installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS], { | 72 | await installExtension([REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS], { |
diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index 2830fa7..ee89f49 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts | |||
@@ -41,6 +41,7 @@ import osName from 'os-name'; | |||
41 | 41 | ||
42 | import { | 42 | import { |
43 | DEVMODE_ALLOWED_URL_PREFIXES, | 43 | DEVMODE_ALLOWED_URL_PREFIXES, |
44 | enableStacktraceSourceMaps, | ||
44 | installDevToolsExtensions, | 45 | installDevToolsExtensions, |
45 | openDevToolsWhenReady, | 46 | openDevToolsWhenReady, |
46 | } from './devTools'; | 47 | } from './devTools'; |
@@ -55,11 +56,14 @@ const log = getLogger('index'); | |||
55 | // Always enable sandboxing. | 56 | // Always enable sandboxing. |
56 | app.enableSandbox(); | 57 | app.enableSandbox(); |
57 | 58 | ||
58 | // Use alternative directory when debugging to avoid clobbering the main installation. | ||
59 | if (isDevelopment) { | 59 | if (isDevelopment) { |
60 | // Use alternative directory when debugging to avoid clobbering the main installation. | ||
60 | app.setPath('userData', `${app.getPath('userData')}-dev`); | 61 | app.setPath('userData', `${app.getPath('userData')}-dev`); |
62 | ensureDirSync(app.getPath('userData')); | ||
63 | |||
64 | // Use source maps in stack traces. | ||
65 | enableStacktraceSourceMaps(); | ||
61 | } | 66 | } |
62 | ensureDirSync(app.getPath('userData')); | ||
63 | 67 | ||
64 | // Only allow a single instance at a time. | 68 | // Only allow a single instance at a time. |
65 | const isSingleInstance = app.requestSingleInstanceLock(); | 69 | const isSingleInstance = app.requestSingleInstanceLock(); |