fix(pw): 🐛 disable emulate and skip .env.local against prod db
bunfig preloads scripts/preload-env.ts which loaded dw .env.local files BEFORE pw could rename them, so pw inherited the dev DB URL and dev.ts auto-set EMULATE_GOOGLE_URL. The previous stash-rename approach raced the preload and lost. Now: preload-env.ts honours PW_MODE=1 and skips .env.local loading; pw sets EMULATE_GOOGLE_URL='' so dev.ts's ?? fallback can't reinstate emulate; the stash dance is gone. A 'bun pw restore' command remains for one-time cleanup of pre-fix .pw-stash files.
This commit is contained in:
@@ -8,27 +8,25 @@ import { loadLocalEnv } from "@server/utils/envUtils.js";
|
||||
loadLocalEnv();
|
||||
|
||||
// Worktree-aware: `bun dw` writes per-worktree `.env.local` files to each
|
||||
// workspace dir. infisical run + server/.env stop short of these, so things
|
||||
// like AUTUMN_TEST_BASE_URL and DATABASE_URL never get the worktree value.
|
||||
// Loading here covers `bun t`, `bun cm`, `bun setup-test`, and any direct
|
||||
// `bun test` invocation from the repo root. Missing files = no-op (canonical
|
||||
// repo has none of these).
|
||||
const __preloadRoot = resolve(
|
||||
fileURLToPath(new URL(".", import.meta.url)),
|
||||
"..",
|
||||
);
|
||||
for (const rel of [
|
||||
"server/.env.local",
|
||||
"vite/.env.local",
|
||||
"apps/checkout/.env.local",
|
||||
]) {
|
||||
const abs = join(__preloadRoot, rel);
|
||||
if (!existsSync(abs)) continue;
|
||||
const contents = readFileSync(abs, "utf-8");
|
||||
for (const line of contents.split(/\r?\n/)) {
|
||||
const m = line.match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/);
|
||||
if (!m) continue;
|
||||
// Worktree-local overrides win over infisical + server/.env.
|
||||
process.env[m[1]] = m[2];
|
||||
// workspace dir. PW_MODE=1 (set by `bun pw`) skips this so prod Infisical
|
||||
// secrets aren't overridden by dev DB URLs.
|
||||
if (process.env.PW_MODE !== "1") {
|
||||
const __preloadRoot = resolve(
|
||||
fileURLToPath(new URL(".", import.meta.url)),
|
||||
"..",
|
||||
);
|
||||
for (const rel of [
|
||||
"server/.env.local",
|
||||
"vite/.env.local",
|
||||
"apps/checkout/.env.local",
|
||||
]) {
|
||||
const abs = join(__preloadRoot, rel);
|
||||
if (!existsSync(abs)) continue;
|
||||
const contents = readFileSync(abs, "utf-8");
|
||||
for (const line of contents.split(/\r?\n/)) {
|
||||
const m = line.match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/);
|
||||
if (!m) continue;
|
||||
process.env[m[1]] = m[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user