@take-out/scripts 0.0.65 → 0.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/helpers/get-test-env.ts +4 -53
package/package.json
CHANGED
|
@@ -1,69 +1,22 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs'
|
|
2
1
|
import { join } from 'node:path'
|
|
3
2
|
|
|
4
3
|
import { loadEnv } from './env-load'
|
|
5
4
|
import { getDockerHost } from './get-docker-host'
|
|
6
5
|
import { getZeroVersion } from './zero-get-version'
|
|
7
6
|
|
|
8
|
-
// extract the port from a postgres connection string
|
|
9
|
-
function getPortFromConnectionString(url: string | undefined): string | undefined {
|
|
10
|
-
if (!url) return undefined
|
|
11
|
-
try {
|
|
12
|
-
// handle postgresql:// URLs
|
|
13
|
-
const match = url.match(/:(\d+)\//)
|
|
14
|
-
return match?.[1]
|
|
15
|
-
} catch {
|
|
16
|
-
return undefined
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// read a specific env var directly from .env.development file
|
|
21
|
-
// (process.env may have production values if NODE_ENV=production)
|
|
22
|
-
function getDevEnvVar(key: string): string | undefined {
|
|
23
|
-
try {
|
|
24
|
-
const envPath = join(process.cwd(), '.env.development')
|
|
25
|
-
const content = readFileSync(envPath, 'utf-8')
|
|
26
|
-
const regex = new RegExp(`^${key}=["']?([^"'\\n]+)["']?`, 'm')
|
|
27
|
-
const match = content.match(regex)
|
|
28
|
-
return match?.[1]
|
|
29
|
-
} catch {
|
|
30
|
-
return undefined
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function getDevDbPort(): string | undefined {
|
|
35
|
-
const url = getDevEnvVar('ZERO_UPSTREAM_DB')
|
|
36
|
-
return url ? getPortFromConnectionString(url) : undefined
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// extract port from a URL like http://localhost:8081
|
|
40
|
-
function getPortFromUrl(url: string | undefined): string | undefined {
|
|
41
|
-
if (!url) return undefined
|
|
42
|
-
try {
|
|
43
|
-
const parsed = new URL(url)
|
|
44
|
-
return parsed.port || undefined
|
|
45
|
-
} catch {
|
|
46
|
-
return undefined
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
7
|
export async function getTestEnv() {
|
|
51
8
|
const zeroVersion = getZeroVersion()
|
|
52
9
|
const dockerHost = getDockerHost()
|
|
53
10
|
const devEnv = await loadEnv('development')
|
|
54
11
|
const serverEnvFallback = await import(join(process.cwd(), 'src/server/env-server'))
|
|
55
12
|
|
|
56
|
-
//
|
|
57
|
-
const dbPort = process.env.
|
|
58
|
-
const appPort = process.env.
|
|
59
|
-
const minioPort = process.env.
|
|
13
|
+
// ports come from VITE_PORT_* in .env.development (loaded by loadEnv)
|
|
14
|
+
const dbPort = process.env.VITE_PORT_POSTGRES || '5433'
|
|
15
|
+
const appPort = process.env.VITE_PORT_WEB || '8081'
|
|
16
|
+
const minioPort = process.env.VITE_PORT_MINIO || '9200'
|
|
60
17
|
|
|
61
18
|
const dockerDbBase = `postgresql://user:password@127.0.0.1:${dbPort}`
|
|
62
19
|
|
|
63
|
-
// use dev BETTER_AUTH_SECRET for CI/staging to match local dev database keys
|
|
64
|
-
// (better-auth encrypts JWKS private keys with this secret, so it must match)
|
|
65
|
-
const devAuthSecret = getDevEnvVar('BETTER_AUTH_SECRET')
|
|
66
|
-
|
|
67
20
|
return {
|
|
68
21
|
...serverEnvFallback,
|
|
69
22
|
...devEnv,
|
|
@@ -82,7 +35,5 @@ export async function getTestEnv() {
|
|
|
82
35
|
CLOUDFLARE_R2_PUBLIC_URL: `http://127.0.0.1:${minioPort}`,
|
|
83
36
|
CLOUDFLARE_R2_ACCESS_KEY: 'minio',
|
|
84
37
|
CLOUDFLARE_R2_SECRET_KEY: 'minio_password',
|
|
85
|
-
// ensure auth secret matches dev db keys
|
|
86
|
-
...(devAuthSecret && { BETTER_AUTH_SECRET: devAuthSecret }),
|
|
87
38
|
}
|
|
88
39
|
}
|