Browse Source

fix env var loading

Jeffrey Morgan 1 year ago
parent
commit
7974ad58ff
5 changed files with 15 additions and 7 deletions
  1. 4 4
      app/package-lock.json
  2. 1 1
      app/package.json
  3. 4 2
      app/src/telemetry.ts
  4. 2 0
      app/webpack.main.config.ts
  5. 4 0
      app/webpack.plugins.ts

+ 4 - 4
app/package-lock.json

@@ -29,7 +29,7 @@
         "@electron-forge/plugin-webpack": "^6.2.1",
         "@electron-forge/publisher-github": "^6.2.1",
         "@types/chmodr": "^1.0.0",
-        "@types/node": "^20.3.1",
+        "@types/node": "^20.4.0",
         "@types/react": "^18.2.14",
         "@types/react-dom": "^18.2.6",
         "@types/uuid": "^9.0.2",
@@ -2712,9 +2712,9 @@
       "optional": true
     },
     "node_modules/@types/node": {
-      "version": "20.3.1",
-      "resolved": "https://registry.npmjs.org/@types/node/-/node-20.3.1.tgz",
-      "integrity": "sha512-EhcH/wvidPy1WeML3TtYFGR83UzjxeWRen9V402T8aUGYsCHOmfoisV3ZSg03gAFIbLq8TnWOJ0f4cALtnSEUg=="
+      "version": "20.4.0",
+      "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.0.tgz",
+      "integrity": "sha512-jfT7iTf/4kOQ9S7CHV9BIyRaQqHu67mOjsIQBC3BKZvzvUB6zLxEwJ6sBE3ozcvP8kF6Uk5PXN0Q+c0dfhGX0g=="
     },
     "node_modules/@types/parse-json": {
       "version": "4.0.0",

+ 1 - 1
app/package.json

@@ -31,7 +31,7 @@
     "@electron-forge/plugin-webpack": "^6.2.1",
     "@electron-forge/publisher-github": "^6.2.1",
     "@types/chmodr": "^1.0.0",
-    "@types/node": "^20.3.1",
+    "@types/node": "^20.4.0",
     "@types/react": "^18.2.14",
     "@types/react-dom": "^18.2.6",
     "@types/uuid": "^9.0.2",

+ 4 - 2
app/src/telemetry.ts

@@ -1,13 +1,15 @@
 import { Analytics } from '@segment/analytics-node'
 import { v4 as uuidv4 } from 'uuid'
+import Store from 'electron-store'
 
-const Store = require('electron-store')
 const store = new Store()
 
+console.log(process.env)
+
 export const analytics = new Analytics({ writeKey: process.env.TELEMETRY_WRITE_KEY || '<empty>' })
 
 export function id(): string {
-  const id = store.get('id')
+  const id = store.get('id') as string
 
   if (id) {
     return id

+ 2 - 0
app/webpack.main.config.ts

@@ -1,6 +1,7 @@
 import type { Configuration } from 'webpack'
 
 import { rules } from './webpack.rules'
+import { plugins } from './webpack.plugins'
 
 export const mainConfig: Configuration = {
   /**
@@ -12,6 +13,7 @@ export const mainConfig: Configuration = {
   module: {
     rules,
   },
+  plugins,
   resolve: {
     extensions: ['.js', '.ts', '.jsx', '.tsx', '.css', '.json'],
   },

+ 4 - 0
app/webpack.plugins.ts

@@ -1,4 +1,5 @@
 import type IForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
+import { DefinePlugin } from 'webpack'
 
 // eslint-disable-next-line @typescript-eslint/no-var-requires
 const ForkTsCheckerWebpackPlugin: typeof IForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
@@ -7,4 +8,7 @@ export const plugins = [
   new ForkTsCheckerWebpackPlugin({
     logger: 'webpack-infrastructure',
   }),
+  new DefinePlugin({
+    'process.env.TELEMETRY_WRITE_KEY': JSON.stringify(process.env.TELEMETRY_WRITE_KEY),
+  }),
 ]