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 | |
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')
-rw-r--r-- | packages/main/esbuild.config.js | 2 | ||||
-rw-r--r-- | packages/main/package.json | 4 | ||||
-rw-r--r-- | packages/main/src/devTools.ts | 20 | ||||
-rw-r--r-- | packages/main/src/index.ts | 8 |
4 files changed, 28 insertions, 6 deletions
diff --git a/packages/main/esbuild.config.js b/packages/main/esbuild.config.js index ef0aa71..996ec5a 100644 --- a/packages/main/esbuild.config.js +++ b/packages/main/esbuild.config.js | |||
@@ -7,7 +7,7 @@ import getEsbuildConfig from '../../config/getEsbuildConfig.js'; | |||
7 | const externalPackages = ['electron']; | 7 | const externalPackages = ['electron']; |
8 | 8 | ||
9 | if (process.env.MODE !== 'development') { | 9 | if (process.env.MODE !== 'development') { |
10 | externalPackages.push('electron-devtools-installer'); | 10 | externalPackages.push('electron-devtools-installer', 'source-map-support'); |
11 | } | 11 | } |
12 | 12 | ||
13 | const gitInfo = getRepoInfo(); | 13 | const gitInfo = getRepoInfo(); |
diff --git a/packages/main/package.json b/packages/main/package.json index c03e81e..9b87835 100644 --- a/packages/main/package.json +++ b/packages/main/package.json | |||
@@ -33,10 +33,12 @@ | |||
33 | "@types/ms": "^0.7.31", | 33 | "@types/ms": "^0.7.31", |
34 | "@types/node": "^17.0.12", | 34 | "@types/node": "^17.0.12", |
35 | "@types/slug": "^5", | 35 | "@types/slug": "^5", |
36 | "@types/source-map-support": "^0", | ||
36 | "electron-devtools-installer": "^3.2.0", | 37 | "electron-devtools-installer": "^3.2.0", |
37 | "esbuild": "^0.14.14", | 38 | "esbuild": "^0.14.14", |
38 | "git-repo-info": "^2.1.1", | 39 | "git-repo-info": "^2.1.1", |
39 | "jest": "^27.4.7", | 40 | "jest": "^27.4.7", |
40 | "jest-mock": "^27.4.6" | 41 | "jest-mock": "^27.4.6", |
42 | "source-map-support": "^0.5.21" | ||
41 | } | 43 | } |
42 | } | 44 | } |
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(); |