Skip to content

Commit 3d417e5

Browse files
authored
refactor: vite env vars (#2532)
* refactor: vite env vars Signed-off-by: Adam Setch <adam.setch@outlook.com> * refactor: vite env vars Signed-off-by: Adam Setch <adam.setch@outlook.com> --------- Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent b17c056 commit 3d417e5

File tree

13 files changed

+99
-44
lines changed

13 files changed

+99
-44
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Aptabase Key - Analytics
2-
APTABASE_KEY=some-key
2+
VITE_APTABASE_KEY=some-key

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ jobs:
3838
- name: Build application
3939
run: pnpm build
4040
env:
41-
APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
41+
VITE_APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
4242

4343
- name: Package for ${{ matrix.platform }}
4444
run: ${{ matrix.package-cmd }}
4545
env:
46-
APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
46+
VITE_APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
4747
# Signing certificates - important to use the correct cert per platform
4848
CSC_LINK: ${{ matrix.platform == 'macOS' && secrets.CSC_LINK || (matrix.platform == 'windows' && secrets.WIN_CSC_LINK || '') }}
4949
CSC_KEY_PASSWORD: ${{ matrix.platform == 'macOS' && secrets.CSC_KEY_PASSWORD || (matrix.platform == 'windows' && secrets.WIN_CSC_KEY_PASSWORD || '') }}

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ jobs:
6767
- name: Build application
6868
run: pnpm build
6969
env:
70-
APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
70+
VITE_APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
7171

7272
- name: Package and publish for ${{ matrix.platform }}
7373
run: ${{ matrix.package-cmd }}
7474
env:
75-
APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
75+
VITE_APTABASE_KEY: ${{ secrets.APTABASE_KEY }}
7676
# Signing certificates - important to use the correct cert per platform
7777
CSC_LINK: ${{ matrix.platform == 'macOS' && secrets.CSC_LINK || (matrix.platform == 'windows' && secrets.WIN_CSC_LINK || '') }}
7878
CSC_KEY_PASSWORD: ${{ matrix.platform == 'macOS' && secrets.CSC_KEY_PASSWORD || (matrix.platform == 'windows' && secrets.WIN_CSC_KEY_PASSWORD || '') }}

.vscode/settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
"[typescript]": {
1616
"editor.defaultFormatter": "biomejs.biome"
1717
},
18-
"cSpell.words": ["Atlassify", "codegen", "partialize", "rovo", "xcss"],
18+
"cSpell.words": [
19+
"atlassify",
20+
"codegen",
21+
"partialize",
22+
"rovo",
23+
"xcss",
24+
"aptabase"
25+
],
1926
"i18n-ally.translate.engines": ["google"],
2027
"i18n-ally.localesPaths": ["src/renderer/i18n/locales"],
2128
"i18n-ally.sourceLanguage": "en",

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@
111111
"clsx": "2.1.1",
112112
"concurrently": "9.2.1",
113113
"date-fns": "4.1.0",
114-
"dotenv": "17.3.1",
115114
"electron": "41.0.3",
116115
"electron-builder": "26.8.1",
117116
"graphql": "16.13.1",

pnpm-lock.yaml

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/handlers/analytics.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,26 @@ vi.mock('../../shared/logger', () => ({
2525
}));
2626

2727
describe('main/handlers/analytics.ts', () => {
28-
const originalEnv = process.env;
29-
30-
beforeEach(() => {
31-
process.env = { ...originalEnv };
28+
afterEach(() => {
29+
vi.unstubAllEnvs();
3230
});
3331

3432
describe('initializeAnalytics', () => {
35-
it('logs an error and skips initialization when APTABASE_KEY is not set', async () => {
36-
delete process.env.APTABASE_KEY;
33+
it('logs an error and skips initialization when VITE_APTABASE_KEY is not set', async () => {
34+
vi.stubEnv('VITE_APTABASE_KEY', '');
3735

3836
await initializeAnalytics();
3937

4038
expect(initializeMock).not.toHaveBeenCalled();
4139
expect(logErrorMock).toHaveBeenCalledWith(
4240
'analytics',
43-
'APTABASE_KEY environment variable is not set',
41+
'VITE_APTABASE_KEY environment variable is not set',
4442
expect.any(Error),
4543
);
4644
});
4745

48-
it('initializes the SDK and logs success when APTABASE_KEY is set', async () => {
49-
process.env.APTABASE_KEY = 'test-key-123';
46+
it('initializes the SDK and logs success when VITE_APTABASE_KEY is set', async () => {
47+
vi.stubEnv('VITE_APTABASE_KEY', 'test-key-123');
5048

5149
await initializeAnalytics();
5250

@@ -59,7 +57,7 @@ describe('main/handlers/analytics.ts', () => {
5957
});
6058

6159
it('logs an error when SDK initialization throws', async () => {
62-
process.env.APTABASE_KEY = 'test-key-123';
60+
vi.stubEnv('VITE_APTABASE_KEY', 'test-key-123');
6361
const sdkError = new Error('SDK init failed');
6462
initializeMock.mockImplementationOnce(() => {
6563
throw sdkError;

src/main/handlers/analytics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { logError, logInfo } from '../../shared/logger';
66
import { onMainEvent } from '../events';
77

88
/**
9-
* Initialize the Aptabase analytics SDK using the APTABASE_KEY environment variable.
9+
* Initialize the Aptabase analytics SDK using the VITE_APTABASE_KEY environment variable.
1010
*/
1111
export async function initializeAnalytics(): Promise<void> {
12-
const aptabaseKey = process.env.APTABASE_KEY;
12+
const aptabaseKey = import.meta.env.VITE_APTABASE_KEY;
1313

1414
if (!aptabaseKey) {
1515
logError(
1616
'analytics',
17-
'APTABASE_KEY environment variable is not set',
18-
new Error('APTABASE_KEY environment variable is not set'),
17+
'VITE_APTABASE_KEY environment variable is not set',
18+
new Error('VITE_APTABASE_KEY environment variable is not set'),
1919
);
2020
return;
2121
}

src/main/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { config } from 'dotenv';
2-
3-
config();
4-
51
import { app } from 'electron';
62
import log from 'electron-log';
73
import { menubar } from 'menubar';

src/renderer/utils/api/graphql/generated/graphql.ts

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)