Skip to content

Commit 23ed768

Browse files
authored
dont assume process exists in runtime code (#216)
1 parent a5355c7 commit 23ed768

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

.changeset/slimy-women-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"varlock": patch
3+
---
4+
5+
fix runtime env code to not assume process (or shim) exists - for sveltekit

packages/varlock/src/runtime/env.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@ let varlockInjectedProcessEnvKeys: Array<string> | undefined;
202202
export function initVarlockEnv(opts?: {
203203
allowFail?: boolean,
204204
}) {
205-
debug('⚡️ INIT VARLOCK ENV!', initializedEnv, !!(globalThis as any).__varlockLoadedEnv, processExists && !!process.env.__VARLOCK_ENV);
205+
debug('⚡️ INIT VARLOCK ENV!', initializedEnv, !!(globalThis as any).__varlockLoadedEnv, !!globalThis.process?.env.__VARLOCK_ENV);
206206

207207
// normally we can just bail if we detect we are in the browser
208208
// however when front-end related tests, it may appear that we are in the browser but it is not
209-
if (isBrowser && !process.env.__VARLOCK_ENV) {
209+
// also some frameworks inject a process polyfill, others do not
210+
if (isBrowser && !globalThis.process?.env.__VARLOCK_ENV) {
210211
initializedEnv = true;
211212
return;
212213
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
22
export function debug(...args: Array<any>) {
3-
if (!process.env.DEBUG_VARLOCK) return;
3+
if (!globalThis.process?.env.DEBUG_VARLOCK) return;
44
console.log(...args);
55
}

0 commit comments

Comments
 (0)