diff --git a/packages/gau/src/solidstart/index.ts b/packages/gau/src/solidstart/index.ts index 9d329b2..719eb08 100644 --- a/packages/gau/src/solidstart/index.ts +++ b/packages/gau/src/solidstart/index.ts @@ -1,7 +1,7 @@ import type { CreateAuthOptions, RefreshSessionOptions } from '../core' import type { AuthInstance } from '../core/serverSession' import type { OAuthProvider } from '../oauth' -import process from 'node:process' +import { DEV } from 'esm-env' import { createHandler, REFRESHED_TOKEN_HEADER } from '../core' import { createRequestSessionCache, resolveAuth, resolveServerSession } from '../core/serverSession' @@ -22,7 +22,7 @@ export { REFRESHED_TOKEN_HEADER } export function SolidAuth[]>(optionsOrAuth: CreateAuthOptions | AuthInstance) { const auth = resolveAuth(optionsOrAuth) - auth.development = process.env.NODE_ENV === 'development' + auth.development = DEV if (!auth.errorRedirect) auth.errorRedirect = '/auth/error' diff --git a/packages/gau/test/solidstart/index.test.ts b/packages/gau/test/solidstart/index.test.ts index 0c1984c..8bb2aec 100644 --- a/packages/gau/test/solidstart/index.test.ts +++ b/packages/gau/test/solidstart/index.test.ts @@ -1,3 +1,5 @@ +import { readFile } from 'node:fs/promises' +import { DEV } from 'esm-env' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { NULL_SESSION, REFRESHED_TOKEN_HEADER, SESSION_COOKIE_NAME } from '../../src/core' import { authMiddleware, createSolidStartGetServerSession, refreshMiddleware, SolidAuth } from '../../src/solidstart/index' @@ -29,6 +31,7 @@ describe('solidAuth', () => { beforeEach(() => { mockAuth.providerMap = new Map() mockAuth.validateSession.mockReset() + delete mockAuth.development }) it('should return GET, POST, and OPTIONS handlers', () => { @@ -57,20 +60,19 @@ describe('solidAuth', () => { expect(GET).toBeInstanceOf(Function) }) - it('sets development based on NODE_ENV', () => { - const original = process.env.NODE_ENV - try { - process.env.NODE_ENV = 'development' - SolidAuth({ providers: [], adapter: {} as any } as any) - expect(mockAuth.development).toBe(true) - - process.env.NODE_ENV = 'production' - SolidAuth({ providers: [], adapter: {} as any } as any) - expect(mockAuth.development).toBe(false) - } - finally { - process.env.NODE_ENV = original - } + it('sets development from esm-env', () => { + SolidAuth({ providers: [], adapter: {} as any } as any) + + expect(mockAuth.development).toBe(DEV) + }) + + it('does not statically import process in the SolidStart runtime source', async () => { + const source = await readFile(new URL('../../src/solidstart/index.ts', import.meta.url), 'utf8') + const imports = source.match(/^import\s+.*$/gm)?.join('\n') ?? '' + + expect(imports).not.toMatch(/\bprocess\b/) + expect(source).not.toContain('node:process') + expect(source).not.toMatch(/\bprocess\.env\b/) }) })