aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-01-04 01:19:39 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-08 21:42:25 +0100
commit1b17d2f9fefb53329838a16ff72436bd9bdcf220 (patch)
tree85e7464ed09779daaa456c7ffcc395a7f42db38d
parentfeat: Rewrite the config if new details are added (diff)
downloadsophie-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>
-rw-r--r--packages/main/esbuild.config.js2
-rw-r--r--packages/main/package.json4
-rw-r--r--packages/main/src/devTools.ts20
-rw-r--r--packages/main/src/index.ts8
-rw-r--r--yarn.lock13
5 files changed, 40 insertions, 7 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';
7const externalPackages = ['electron']; 7const externalPackages = ['electron'];
8 8
9if (process.env.MODE !== 'development') { 9if (process.env.MODE !== 'development') {
10 externalPackages.push('electron-devtools-installer'); 10 externalPackages.push('electron-devtools-installer', 'source-map-support');
11} 11}
12 12
13const gitInfo = getRepoInfo(); 13const 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 */
40export 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 */
43export async function installDevToolsExtensions(): Promise<void> { 59export 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
42import { 42import {
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.
56app.enableSandbox(); 57app.enableSandbox();
57 58
58// Use alternative directory when debugging to avoid clobbering the main installation.
59if (isDevelopment) { 59if (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}
62ensureDirSync(app.getPath('userData'));
63 67
64// Only allow a single instance at a time. 68// Only allow a single instance at a time.
65const isSingleInstance = app.requestSingleInstanceLock(); 69const isSingleInstance = app.requestSingleInstanceLock();
diff --git a/yarn.lock b/yarn.lock
index f7dd338..6a1288e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1243,6 +1243,7 @@ __metadata:
1243 "@types/ms": ^0.7.31 1243 "@types/ms": ^0.7.31
1244 "@types/node": ^17.0.12 1244 "@types/node": ^17.0.12
1245 "@types/slug": ^5 1245 "@types/slug": ^5
1246 "@types/source-map-support": ^0
1246 chalk: ^5.0.0 1247 chalk: ^5.0.0
1247 deep-equal: ^2.0.5 1248 deep-equal: ^2.0.5
1248 electron: 17.0.0 1249 electron: 17.0.0
@@ -1262,6 +1263,7 @@ __metadata:
1262 nanoid: ^3.1.30 1263 nanoid: ^3.1.30
1263 os-name: ^5.0.1 1264 os-name: ^5.0.1
1264 slug: ^5.2.0 1265 slug: ^5.2.0
1266 source-map-support: ^0.5.21
1265 languageName: unknown 1267 languageName: unknown
1266 linkType: soft 1268 linkType: soft
1267 1269
@@ -1672,6 +1674,15 @@ __metadata:
1672 languageName: node 1674 languageName: node
1673 linkType: hard 1675 linkType: hard
1674 1676
1677"@types/source-map-support@npm:^0":
1678 version: 0.5.4
1679 resolution: "@types/source-map-support@npm:0.5.4"
1680 dependencies:
1681 source-map: ^0.6.0
1682 checksum: 160ff77e8a101b18d9915cb5320fd73d484679aef8518ce007b9b5988e333631778730196c4bb15517ff881bee805663fd8640c0ce2ebfab65f061103c452369
1683 languageName: node
1684 linkType: hard
1685
1675"@types/stack-utils@npm:^2.0.0": 1686"@types/stack-utils@npm:^2.0.0":
1676 version: 2.0.1 1687 version: 2.0.1
1677 resolution: "@types/stack-utils@npm:2.0.1" 1688 resolution: "@types/stack-utils@npm:2.0.1"
@@ -8390,7 +8401,7 @@ __metadata:
8390 languageName: node 8401 languageName: node
8391 linkType: hard 8402 linkType: hard
8392 8403
8393"source-map-support@npm:^0.5.19, source-map-support@npm:^0.5.6": 8404"source-map-support@npm:^0.5.19, source-map-support@npm:^0.5.21, source-map-support@npm:^0.5.6":
8394 version: 0.5.21 8405 version: 0.5.21
8395 resolution: "source-map-support@npm:0.5.21" 8406 resolution: "source-map-support@npm:0.5.21"
8396 dependencies: 8407 dependencies: