@wwchen/stack 0.9.1 → 0.11.0
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/README.md +50 -23
- package/blocks/AGENTS.md +11 -31
- package/blocks/CLAUDE.md +10 -36
- package/blocks/env.example +1 -18
- package/blocks/gitignore +1 -8
- package/dist/cli/builtin.d.ts +7 -0
- package/dist/cli/builtin.js +42 -0
- package/dist/cli/check.d.ts +5 -0
- package/dist/cli/check.js +39 -0
- package/dist/cli/context.d.ts +4 -35
- package/dist/cli/context.js +1 -23
- package/dist/cli/discover.d.ts +15 -0
- package/dist/cli/discover.js +156 -0
- package/dist/cli/generate.d.ts +6 -0
- package/dist/cli/generate.js +94 -0
- package/dist/cli/host.d.ts +8 -0
- package/dist/cli/host.js +146 -0
- package/dist/cli/index.js +4 -71
- package/dist/cli/owned.d.ts +33 -0
- package/dist/cli/owned.js +151 -0
- package/dist/cli/sync.d.ts +19 -0
- package/dist/cli/sync.js +231 -0
- package/dist/configs/vitest.d.ts +3 -1
- package/dist/configs/vitest.js +8 -11
- package/dist/connections/env.d.ts +8 -0
- package/dist/connections/env.js +15 -0
- package/dist/connections/index.d.ts +1 -1
- package/dist/connections/index.js +1 -1
- package/dist/connections/table.d.ts +5 -3
- package/dist/connections/table.js +3 -3
- package/dist/env/core-env.d.ts +23 -0
- package/dist/env/core-env.js +24 -0
- package/dist/env/define-env.d.ts +22 -10
- package/dist/env/define-env.js +72 -17
- package/dist/env/index.d.ts +2 -2
- package/dist/env/index.js +1 -1
- package/dist/http/client-ip.d.ts +6 -0
- package/dist/http/client-ip.js +21 -0
- package/dist/http/index.d.ts +2 -0
- package/dist/http/index.js +2 -0
- package/dist/http/safe-next.d.ts +11 -0
- package/dist/http/safe-next.js +30 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/next/api.d.ts +9 -8
- package/dist/next/api.js +10 -8
- package/dist/next/config.d.ts +2 -0
- package/dist/next/config.js +10 -6
- package/dist/next/health.d.ts +5 -7
- package/dist/next/health.js +16 -17
- package/dist/stack/contracts.d.ts +202 -0
- package/dist/stack/contracts.js +66 -0
- package/dist/vercel/index.d.ts +28 -0
- package/dist/vercel/index.js +90 -0
- package/files/.claude/rules/stack-ui.md +24 -0
- package/files/next.config.ts +6 -0
- package/files/src/app/api/health/route.ts +9 -0
- package/package.json +16 -29
- package/dist/cli/db.d.ts +0 -4
- package/dist/cli/db.js +0 -43
- package/dist/cli/dev.d.ts +0 -4
- package/dist/cli/dev.js +0 -70
- package/dist/cli/doctor.d.ts +0 -40
- package/dist/cli/doctor.js +0 -166
- package/dist/cli/migrate-suite.d.ts +0 -2
- package/dist/cli/migrate-suite.js +0 -491
- package/dist/cli/neon.d.ts +0 -79
- package/dist/cli/neon.js +0 -384
- package/dist/cli/run.d.ts +0 -2
- package/dist/cli/run.js +0 -29
- package/dist/cli/sync-blocks.d.ts +0 -14
- package/dist/cli/sync-blocks.js +0 -93
- package/dist/cli/user-create.d.ts +0 -6
- package/dist/cli/user-create.js +0 -77
- package/dist/cli/vercel-build.d.ts +0 -4
- package/dist/cli/vercel-build.js +0 -61
- package/dist/db/explaining-pool.d.ts +0 -11
- package/dist/db/explaining-pool.js +0 -55
- package/dist/db/index.d.ts +0 -20
- package/dist/db/index.js +0 -31
- package/dist/db/migration-status.d.ts +0 -5
- package/dist/db/migration-status.js +0 -38
- package/dist/db/schema-changes.d.ts +0 -13
- package/dist/db/schema-changes.js +0 -99
- package/dist/db/ssl.d.ts +0 -4
- package/dist/db/ssl.js +0 -17
- package/dist/db/target.d.ts +0 -19
- package/dist/db/target.js +0 -65
- package/dist/db/testing/index.d.ts +0 -23
- package/dist/db/testing/index.js +0 -67
- package/dist/db/testing/isolate.d.ts +0 -1
- package/dist/db/testing/isolate.js +0 -3
- package/dist/db/testing/pglite.d.ts +0 -20
- package/dist/db/testing/pglite.js +0 -79
- package/dist/env/stack-env.d.ts +0 -37
- package/dist/env/stack-env.js +0 -54
- package/dist/env/testing.d.ts +0 -6
- package/dist/env/testing.js +0 -13
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { BLOCK_FILES, BUILTIN_PACKAGE, CORE_PACKAGE, FILES_RECORD, } from "../stack/contracts.js";
|
|
5
|
+
import { CliError } from "./context.js";
|
|
6
|
+
/** The name a package owns files under: the built-in package is the core. */
|
|
7
|
+
export const ownerOf = (pkg) => pkg.name === BUILTIN_PACKAGE ? CORE_PACKAGE : pkg.name;
|
|
8
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
9
|
+
/** Each package's `files`, read from their sources and made by their `render` where they have one, in package order. */
|
|
10
|
+
export function ownedOutputs(packages) {
|
|
11
|
+
return packages.flatMap((pkg) => (pkg.files ?? []).map(({ path, source, render }) => {
|
|
12
|
+
let text;
|
|
13
|
+
try {
|
|
14
|
+
text = readFileSync(fileURLToPath(source), "utf8");
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
throw new CliError(`${ownerOf(pkg)}: its file ${path} cannot be read from ${source.href} (${messageOf(error)}). Reinstall the package; nothing was changed.`);
|
|
18
|
+
}
|
|
19
|
+
if (render === undefined)
|
|
20
|
+
return { path, owner: ownerOf(pkg), text };
|
|
21
|
+
try {
|
|
22
|
+
return { path, owner: ownerOf(pkg), text: render(text) };
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new CliError(`${ownerOf(pkg)}: its file ${path} cannot be written from its source (${messageOf(error)}). Reinstall the package; nothing was changed.`);
|
|
26
|
+
}
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
/** Whether `path` stays under the app's root: relative, `/`-separated, with no empty, `.` or `..` segment. */
|
|
30
|
+
const isSafePath = (path) => path !== "" &&
|
|
31
|
+
!path.includes("\\") &&
|
|
32
|
+
!/^[A-Za-z]:/.test(path) &&
|
|
33
|
+
path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
|
|
34
|
+
/** What is at `file`, without following a link: nothing, a regular file, or anything else. */
|
|
35
|
+
function kindOf(file) {
|
|
36
|
+
try {
|
|
37
|
+
return lstatSync(file).isFile() ? "file" : "other";
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return "absent";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** The paths the plan changes, each named once, in the order they are applied. */
|
|
44
|
+
export const changedPaths = (plan) => [
|
|
45
|
+
...plan.writes.map((w) => w.path),
|
|
46
|
+
...plan.deletes.map((d) => d.path),
|
|
47
|
+
...(plan.recordChanged ? [FILES_RECORD] : []),
|
|
48
|
+
];
|
|
49
|
+
/** The record on disk: path to owner; empty when there is none. */
|
|
50
|
+
function readRecord(cwd, problems) {
|
|
51
|
+
const path = join(cwd, FILES_RECORD);
|
|
52
|
+
if (!existsSync(path))
|
|
53
|
+
return {};
|
|
54
|
+
const fix = "Restore it from version control, or delete it and every file it names.";
|
|
55
|
+
try {
|
|
56
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
57
|
+
const files = parsed?.files;
|
|
58
|
+
const entries = typeof files === "object" && files !== null && !Array.isArray(files)
|
|
59
|
+
? Object.entries(files)
|
|
60
|
+
: undefined;
|
|
61
|
+
if (!entries || entries.some(([, owner]) => typeof owner !== "string")) {
|
|
62
|
+
problems.push(`${FILES_RECORD} has no "files" object of paths to package names. ${fix}`);
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
return Object.fromEntries(entries);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
problems.push(`${FILES_RECORD} cannot be read (${messageOf(error)}). ${fix}`);
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Plans the owned files against the app's disk and its record: writes a path only when it is absent or recorded, deletes every recorded path no output claims, and refuses, with nothing planned, an unsafe path, a path two packages own and an existing file the record does not name. Every refusal is reported together.
|
|
74
|
+
*/
|
|
75
|
+
export function planFiles(cwd, outputs) {
|
|
76
|
+
const problems = [];
|
|
77
|
+
const recorded = readRecord(cwd, problems);
|
|
78
|
+
const claimed = new Map();
|
|
79
|
+
for (const { path, owner } of outputs) {
|
|
80
|
+
const first = claimed.get(path);
|
|
81
|
+
if (first !== undefined) {
|
|
82
|
+
problems.push(`${path} is owned by both ${first} and ${owner}: a path has one owner.`);
|
|
83
|
+
}
|
|
84
|
+
else if (path === FILES_RECORD) {
|
|
85
|
+
problems.push(`${owner}: ${FILES_RECORD} is the stack's own record, so no package can own it.`);
|
|
86
|
+
}
|
|
87
|
+
else if (Object.values(BLOCK_FILES).includes(path)) {
|
|
88
|
+
problems.push(`${owner}: ${path} holds the stack's marked blocks, so no package can own it whole.`);
|
|
89
|
+
}
|
|
90
|
+
else if (!isSafePath(path)) {
|
|
91
|
+
problems.push(`${owner}: its file ${path} is not a path the stack can own: give a path under the app's root, with / separators and no "." or ".." segment.`);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
claimed.set(path, owner);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const writes = [];
|
|
98
|
+
for (const output of outputs) {
|
|
99
|
+
if (claimed.get(output.path) !== output.owner)
|
|
100
|
+
continue;
|
|
101
|
+
const file = join(cwd, output.path);
|
|
102
|
+
const kind = kindOf(file);
|
|
103
|
+
if (kind === "absent") {
|
|
104
|
+
writes.push(output);
|
|
105
|
+
}
|
|
106
|
+
else if (kind === "other") {
|
|
107
|
+
problems.push(`${output.path} is a link, a directory or another file that is not a regular file, and the stack writes only regular files: move it out of the way, then run \`stack sync\`.`);
|
|
108
|
+
}
|
|
109
|
+
else if (!(output.path in recorded)) {
|
|
110
|
+
problems.push(`${output.path} exists and the stack does not own it: move your code out of it or delete it, then run \`stack sync\`.`);
|
|
111
|
+
}
|
|
112
|
+
else if (readFileSync(file, "utf8") !== output.text) {
|
|
113
|
+
writes.push(output);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const deletes = [];
|
|
117
|
+
for (const [path, owner] of Object.entries(recorded)) {
|
|
118
|
+
if (claimed.has(path))
|
|
119
|
+
continue;
|
|
120
|
+
if (path === FILES_RECORD || !isSafePath(path)) {
|
|
121
|
+
problems.push(`${FILES_RECORD} records ${path}, which is not a path the stack can own. Remove that entry.`);
|
|
122
|
+
}
|
|
123
|
+
else if (kindOf(join(cwd, path)) === "other") {
|
|
124
|
+
problems.push(`${path} is recorded as owned by ${owner} but is a link, a directory or another file that is not a regular file: move it out of the way, then run \`stack sync\`.`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
deletes.push({ path, owner });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (problems.length > 0)
|
|
131
|
+
throw new CliError([...problems, "Nothing was run."].join("\n"));
|
|
132
|
+
const now = Object.fromEntries([...claimed].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
133
|
+
const record = claimed.size > 0 ? `${JSON.stringify({ files: now }, null, 2)}\n` : null;
|
|
134
|
+
const file = join(cwd, FILES_RECORD);
|
|
135
|
+
const onDisk = existsSync(file) ? readFileSync(file, "utf8") : null;
|
|
136
|
+
return { writes, deletes, record, recordChanged: record !== onDisk };
|
|
137
|
+
}
|
|
138
|
+
/** Applies a plan: writes the files, deletes the recorded ones, then writes or removes the record. */
|
|
139
|
+
export function applyFiles(cwd, plan) {
|
|
140
|
+
for (const { path, text } of plan.writes) {
|
|
141
|
+
const file = join(cwd, path);
|
|
142
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
143
|
+
writeFileSync(file, text);
|
|
144
|
+
}
|
|
145
|
+
for (const { path } of plan.deletes)
|
|
146
|
+
rmSync(join(cwd, path), { force: true });
|
|
147
|
+
if (plan.record === null)
|
|
148
|
+
rmSync(join(cwd, FILES_RECORD), { force: true });
|
|
149
|
+
else if (plan.recordChanged)
|
|
150
|
+
writeFileSync(join(cwd, FILES_RECORD), plan.record);
|
|
151
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Command, type StackPackage } from "../stack/contracts.ts";
|
|
2
|
+
import { type Output, ownedOutputs, ownerOf } from "./owned.ts";
|
|
3
|
+
export { type Output, ownedOutputs, ownerOf };
|
|
4
|
+
/**
|
|
5
|
+
* Brings every composed package's marked blocks in AGENTS.md, CLAUDE.md, .gitignore and .env.example up to date, removes the blocks of packages the app no longer composes, and returns the files that were (or, with `check`, would be) changed, and each block that was (or would be) removed. Every file is checked before any is written, so a malformed one leaves all of them untouched.
|
|
6
|
+
*/
|
|
7
|
+
export declare function syncBlocks(cwd: string, packages: readonly StackPackage[], opts?: {
|
|
8
|
+
check?: boolean;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
changed: string[];
|
|
11
|
+
removed: {
|
|
12
|
+
file: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}[];
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* `stack sync [--check]`: writes each composed package's blocks and the whole files packages own, records the files in stack.files.json, and deletes a recorded file whose package is gone. Every write and deletion is planned before any happens, so a refusal leaves everything untouched; `--check` exits 1, naming each stale file, and writes nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare const syncCommand: Command;
|
package/dist/cli/sync.js
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { BLOCK_FILES, BUILTIN_PACKAGE, } from "../stack/contracts.js";
|
|
5
|
+
import { CliError } from "./context.js";
|
|
6
|
+
import { generatedModules } from "./generate.js";
|
|
7
|
+
import { applyFiles, changedPaths, ownedOutputs, ownerOf, planFiles, } from "./owned.js";
|
|
8
|
+
export { ownedOutputs, ownerOf };
|
|
9
|
+
const MARKDOWN = {
|
|
10
|
+
begin: (name) => `<!-- BEGIN:${name} -->`,
|
|
11
|
+
end: (name) => `<!-- END:${name} -->`,
|
|
12
|
+
marker: /^<!-- (BEGIN|END):(\S+) -->$/,
|
|
13
|
+
};
|
|
14
|
+
const HASH = {
|
|
15
|
+
begin: (name) => `# BEGIN:${name}`,
|
|
16
|
+
end: (name) => `# END:${name}`,
|
|
17
|
+
marker: /^# (BEGIN|END):(\S+)$/,
|
|
18
|
+
};
|
|
19
|
+
/** Each managed file's marker style. */
|
|
20
|
+
const STYLES = {
|
|
21
|
+
[BLOCK_FILES.agents]: MARKDOWN,
|
|
22
|
+
[BLOCK_FILES.claude]: MARKDOWN,
|
|
23
|
+
[BLOCK_FILES.gitignore]: HASH,
|
|
24
|
+
[BLOCK_FILES.envExample]: HASH,
|
|
25
|
+
};
|
|
26
|
+
/** The files `sync` manages, in the order it reports them, and each one's marker style. */
|
|
27
|
+
const TARGETS = Object.values(BLOCK_FILES).map((file) => ({ file, style: STYLES[file] }));
|
|
28
|
+
/**
|
|
29
|
+
* Whether a marker name is a package's: the built-in one, or a scoped npm name. Every package that writes blocks has one of these names, so a block left by a package the app no longer composes is still recognised, while another tool's marked block (Next's `nextjs-agent-rules`) is never the stack's to touch.
|
|
30
|
+
*/
|
|
31
|
+
const isPackageName = (name) => name === BUILTIN_PACKAGE || /^@[^/\s]+\/[^/\s]+$/.test(name);
|
|
32
|
+
/** The lines of `source` with their offsets; `end` includes the line break, `text` does not. */
|
|
33
|
+
function linesOf(source) {
|
|
34
|
+
const lines = [];
|
|
35
|
+
let start = 0;
|
|
36
|
+
while (start < source.length) {
|
|
37
|
+
const nl = source.indexOf("\n", start);
|
|
38
|
+
const end = nl === -1 ? source.length : nl + 1;
|
|
39
|
+
lines.push({ start, end, text: source.slice(start, nl === -1 ? end : nl).replace(/\r$/, "") });
|
|
40
|
+
start = end;
|
|
41
|
+
}
|
|
42
|
+
return lines;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Every package block in the file, in file order. Anything ambiguous (a marker with stray whitespace, a marker without its partner, reversed, repeated or overlapping blocks) throws: guessing which text a package owns could delete the app's own.
|
|
46
|
+
*/
|
|
47
|
+
function findBlocks(file, lines, style) {
|
|
48
|
+
const fix = "Fix the markers by hand; nothing was changed.";
|
|
49
|
+
const marks = [];
|
|
50
|
+
lines.forEach((line, index) => {
|
|
51
|
+
const exact = style.marker.exec(line.text);
|
|
52
|
+
const match = exact ?? style.marker.exec(line.text.trim());
|
|
53
|
+
if (!match?.[1] || !match[2] || !isPackageName(match[2]))
|
|
54
|
+
return;
|
|
55
|
+
if (!exact) {
|
|
56
|
+
throw new CliError(`${file}: marker "${line.text.trim()}" has leading or trailing whitespace. ${fix}`);
|
|
57
|
+
}
|
|
58
|
+
marks.push({ kind: match[1], name: match[2], index });
|
|
59
|
+
});
|
|
60
|
+
const blocks = [];
|
|
61
|
+
for (const name of new Set(marks.map((m) => m.name))) {
|
|
62
|
+
const begins = marks.filter((m) => m.name === name && m.kind === "BEGIN");
|
|
63
|
+
const ends = marks.filter((m) => m.name === name && m.kind === "END");
|
|
64
|
+
const [begin] = begins;
|
|
65
|
+
const [end] = ends;
|
|
66
|
+
if (begins.length !== 1 || ends.length !== 1 || !begin || !end) {
|
|
67
|
+
throw new CliError(`${file}: expected exactly one "${style.begin(name)}" and one "${style.end(name)}", found ${begins.length} and ${ends.length}. ${fix}`);
|
|
68
|
+
}
|
|
69
|
+
if (end.index < begin.index) {
|
|
70
|
+
throw new CliError(`${file}: "${style.end(name)}" comes before "${style.begin(name)}". ${fix}`);
|
|
71
|
+
}
|
|
72
|
+
blocks.push({ name, begin: begin.index, end: end.index });
|
|
73
|
+
}
|
|
74
|
+
blocks.sort((a, b) => a.begin - b.begin);
|
|
75
|
+
blocks.forEach((block, i) => {
|
|
76
|
+
const previous = blocks[i - 1];
|
|
77
|
+
if (previous && block.begin < previous.end) {
|
|
78
|
+
throw new CliError(`${file}: the blocks of ${previous.name} and ${block.name} overlap. ${fix}`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return blocks;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Brings `source`'s package blocks in line with `wanted` (each package's name and block lines, in config order): a present block's text is replaced, a block for a package not in `wanted` is removed with the blank line before it, and a missing one is appended after the last block (or at the end of the file), so text outside every block is kept byte for byte. `removed` names the packages whose blocks went, in file order.
|
|
85
|
+
*/
|
|
86
|
+
function apply(file, source, wanted, style) {
|
|
87
|
+
const eol = source.includes("\r\n") ? "\r\n" : "\n";
|
|
88
|
+
const lines = linesOf(source);
|
|
89
|
+
const found = findBlocks(file, lines, style);
|
|
90
|
+
const bodies = new Map(wanted.map(({ name, body }) => [name, body]));
|
|
91
|
+
const marked = (name, body) => [style.begin(name), ...body, style.end(name)].map((line) => line + eol).join("");
|
|
92
|
+
// Each edit replaces `source.slice(start, end)` with `text`; none overlap.
|
|
93
|
+
const edits = [];
|
|
94
|
+
let last;
|
|
95
|
+
const removed = [];
|
|
96
|
+
for (const block of found) {
|
|
97
|
+
const begin = lines[block.begin];
|
|
98
|
+
const end = lines[block.end];
|
|
99
|
+
const body = bodies.get(block.name);
|
|
100
|
+
if (body) {
|
|
101
|
+
edits.push({ start: begin.end, end: end.start, text: body.map((l) => l + eol).join("") });
|
|
102
|
+
last = end;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const before = lines[block.begin - 1];
|
|
106
|
+
const blank = before !== undefined && before.text === "";
|
|
107
|
+
edits.push({ start: blank ? before.start : begin.start, end: end.end, text: "" });
|
|
108
|
+
removed.push(block.name);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const present = new Set(found.map((b) => b.name));
|
|
112
|
+
const added = wanted
|
|
113
|
+
.filter(({ name }) => !present.has(name))
|
|
114
|
+
.map(({ name, body }) => marked(name, body))
|
|
115
|
+
.join(eol);
|
|
116
|
+
if (added && last) {
|
|
117
|
+
const lead = source.slice(last.start, last.end).endsWith("\n") ? "" : eol;
|
|
118
|
+
edits.push({ start: last.end, end: last.end, text: `${lead}${eol}${added}` });
|
|
119
|
+
}
|
|
120
|
+
// Forward, with an insertion before a removal that starts where it does.
|
|
121
|
+
edits.sort((a, b) => a.start - b.start || a.end - b.end);
|
|
122
|
+
let out = "";
|
|
123
|
+
let cursor = 0;
|
|
124
|
+
for (const edit of edits) {
|
|
125
|
+
out += source.slice(cursor, edit.start) + edit.text;
|
|
126
|
+
cursor = edit.end;
|
|
127
|
+
}
|
|
128
|
+
out += source.slice(cursor);
|
|
129
|
+
if (!added || last)
|
|
130
|
+
return { text: out, removed };
|
|
131
|
+
const lead = out === "" ? "" : out.endsWith("\n") ? eol : eol + eol;
|
|
132
|
+
return { text: `${out}${lead}${added}`, removed };
|
|
133
|
+
}
|
|
134
|
+
/** A block's lines, without trailing blank lines. */
|
|
135
|
+
function readBody(pkg, source) {
|
|
136
|
+
let text;
|
|
137
|
+
try {
|
|
138
|
+
text = readFileSync(fileURLToPath(source), "utf8");
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
throw new CliError(`${pkg}: its block ${source.href} cannot be read (${error instanceof Error ? error.message : String(error)}). Reinstall the package; nothing was changed.`);
|
|
142
|
+
}
|
|
143
|
+
return text.replace(/\s+$/, "").split(/\r?\n/);
|
|
144
|
+
}
|
|
145
|
+
/** Each managed file's blocks, package by package in config order. */
|
|
146
|
+
function wantedBlocks(packages) {
|
|
147
|
+
const wanted = new Map(TARGETS.map(({ file }) => [file, []]));
|
|
148
|
+
for (const pkg of packages) {
|
|
149
|
+
if (!pkg.blocks?.length)
|
|
150
|
+
continue;
|
|
151
|
+
if (!isPackageName(pkg.name)) {
|
|
152
|
+
throw new CliError(`${pkg.name}: a package that writes blocks needs a scoped name (@scope/name), so its block can be found once the app stops composing it. Nothing was changed.`);
|
|
153
|
+
}
|
|
154
|
+
for (const { file, source } of pkg.blocks) {
|
|
155
|
+
const list = wanted.get(file);
|
|
156
|
+
if (!list) {
|
|
157
|
+
throw new CliError(`${pkg.name}: sync writes no block into ${file}; it manages ${TARGETS.map((t) => t.file).join(", ")}. Nothing was changed.`);
|
|
158
|
+
}
|
|
159
|
+
if (list.some((b) => b.name === pkg.name)) {
|
|
160
|
+
throw new CliError(`${pkg.name}: gives two blocks for ${file}. Nothing was changed.`);
|
|
161
|
+
}
|
|
162
|
+
list.push({ name: pkg.name, body: readBody(pkg.name, source) });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return wanted;
|
|
166
|
+
}
|
|
167
|
+
/** Every block file's new text, planned before any is written: a malformed file throws and leaves all untouched. */
|
|
168
|
+
function planBlocks(cwd, packages) {
|
|
169
|
+
const wanted = wantedBlocks(packages);
|
|
170
|
+
const writes = [];
|
|
171
|
+
const removed = [];
|
|
172
|
+
for (const { file, style } of TARGETS) {
|
|
173
|
+
const path = join(cwd, file);
|
|
174
|
+
const before = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
175
|
+
const after = apply(file, before, wanted.get(file) ?? [], style);
|
|
176
|
+
if (after.text !== before)
|
|
177
|
+
writes.push({ path, file, text: after.text });
|
|
178
|
+
removed.push(...after.removed.map((name) => ({ file, name })));
|
|
179
|
+
}
|
|
180
|
+
return { writes, removed };
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Brings every composed package's marked blocks in AGENTS.md, CLAUDE.md, .gitignore and .env.example up to date, removes the blocks of packages the app no longer composes, and returns the files that were (or, with `check`, would be) changed, and each block that was (or would be) removed. Every file is checked before any is written, so a malformed one leaves all of them untouched.
|
|
184
|
+
*/
|
|
185
|
+
export async function syncBlocks(cwd, packages, opts = {}) {
|
|
186
|
+
const { writes, removed } = planBlocks(cwd, packages);
|
|
187
|
+
if (!opts.check)
|
|
188
|
+
for (const w of writes)
|
|
189
|
+
writeFileSync(w.path, w.text);
|
|
190
|
+
return { changed: writes.map((w) => w.file), removed };
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* `stack sync [--check]`: writes each composed package's blocks and the whole files packages own, records the files in stack.files.json, and deletes a recorded file whose package is gone. Every write and deletion is planned before any happens, so a refusal leaves everything untouched; `--check` exits 1, naming each stale file, and writes nothing.
|
|
194
|
+
*/
|
|
195
|
+
export const syncCommand = async (ctx, args) => {
|
|
196
|
+
const unknown = args.filter((a) => a !== "--check");
|
|
197
|
+
if (unknown.length > 0)
|
|
198
|
+
throw new CliError(`sync: unknown argument ${unknown[0]}`);
|
|
199
|
+
const check = args.includes("--check");
|
|
200
|
+
const blocks = planBlocks(ctx.cwd, ctx.packages);
|
|
201
|
+
const files = planFiles(ctx.cwd, [
|
|
202
|
+
...ownedOutputs(ctx.packages),
|
|
203
|
+
...generatedModules(ctx.packages),
|
|
204
|
+
]);
|
|
205
|
+
const staleBlocks = blocks.writes.map((w) => w.file);
|
|
206
|
+
const staleFiles = changedPaths(files);
|
|
207
|
+
if (check) {
|
|
208
|
+
if (staleBlocks.length > 0) {
|
|
209
|
+
ctx.error(`stale stack blocks: ${staleBlocks.join(", ")}. Run \`stack sync\`.`);
|
|
210
|
+
}
|
|
211
|
+
if (staleFiles.length > 0) {
|
|
212
|
+
ctx.error(`stale stack files: ${staleFiles.join(", ")}. Run \`stack sync\`.`);
|
|
213
|
+
}
|
|
214
|
+
return staleBlocks.length + staleFiles.length > 0 ? 1 : 0;
|
|
215
|
+
}
|
|
216
|
+
applyFiles(ctx.cwd, files);
|
|
217
|
+
for (const w of blocks.writes)
|
|
218
|
+
writeFileSync(w.path, w.text);
|
|
219
|
+
// Removing a block or a file is something sync deletes, so each is said: a package the app no longer lists in package.json, or one dropped from it by mistake.
|
|
220
|
+
for (const { file, name } of blocks.removed)
|
|
221
|
+
ctx.log(`removed ${name}'s block from ${file}`);
|
|
222
|
+
for (const file of staleBlocks)
|
|
223
|
+
ctx.log(`updated ${file}`);
|
|
224
|
+
for (const { path, owner } of files.writes)
|
|
225
|
+
ctx.log(`wrote ${path} (${owner})`);
|
|
226
|
+
for (const { path, owner } of files.deletes)
|
|
227
|
+
ctx.log(`deleted ${path} (${owner})`);
|
|
228
|
+
if (staleBlocks.length + staleFiles.length === 0)
|
|
229
|
+
ctx.log("stack is up to date");
|
|
230
|
+
return 0;
|
|
231
|
+
};
|
package/dist/configs/vitest.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ViteUserConfig as UserConfig } from "vitest/config";
|
|
2
|
-
|
|
2
|
+
import type { EnvFragment } from "../stack/contracts.ts";
|
|
3
|
+
export declare function stackVitestConfig(overrides: UserConfig, options: {
|
|
3
4
|
root?: string;
|
|
5
|
+
fragments: readonly EnvFragment[];
|
|
4
6
|
}): UserConfig;
|
package/dist/configs/vitest.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { resolve as resolvePath } from "node:path";
|
|
2
2
|
const toArray = (value) => value === undefined ? [] : Array.isArray(value) ? value : [value];
|
|
3
|
-
// Vitest settings shared by every app. `overrides` is merged, not substituted: an app's `setupFiles`, `include`, `exclude` and `env` are added to the preset's, and any other key the app sets wins.
|
|
4
|
-
export function stackVitestConfig(overrides
|
|
3
|
+
// Vitest settings shared by every app. `overrides` is merged, not substituted: an app's `setupFiles`, `include`, `exclude` and `env` are added to the preset's, and any other key the app sets wins. `fragments` put each package's test values in `test.env`, under the app's own `env`, and are required, so an app's tests never run without them (a database package's keep every test off a real database): an app passes its generated `src/stack/env.ts`'s, whatever packages it has, and a package's own test config passes its own list or `[]`.
|
|
4
|
+
export function stackVitestConfig(overrides, options) {
|
|
5
|
+
if (!Array.isArray(options?.fragments)) {
|
|
6
|
+
throw new Error('stackVitestConfig: pass the packages\' test values: stackVitestConfig(…, { fragments }), with `fragments` from "./src/stack/env.ts".');
|
|
7
|
+
}
|
|
5
8
|
const { test: appTest = {}, resolve: appResolve, ...appRest } = overrides;
|
|
6
|
-
const { root = process.cwd() } = options;
|
|
9
|
+
const { root = process.cwd(), fragments } = options;
|
|
7
10
|
const alias = { "@": resolvePath(root, "src") };
|
|
8
11
|
const appAlias = appResolve?.alias;
|
|
9
12
|
const { setupFiles, include, exclude, env, ...appTestRest } = appTest;
|
|
@@ -24,8 +27,7 @@ export function stackVitestConfig(overrides = {}, options = {}) {
|
|
|
24
27
|
testTimeout: 60000,
|
|
25
28
|
hookTimeout: 60000,
|
|
26
29
|
...appTestRest,
|
|
27
|
-
|
|
28
|
-
setupFiles: ["@wwchen/stack/db/testing/isolate", ...toArray(setupFiles)],
|
|
30
|
+
setupFiles: toArray(setupFiles),
|
|
29
31
|
include: [
|
|
30
32
|
"tests/unit/**/*.test.{ts,tsx}",
|
|
31
33
|
"tests/integration/**/*.test.{ts,tsx}",
|
|
@@ -33,12 +35,7 @@ export function stackVitestConfig(overrides = {}, options = {}) {
|
|
|
33
35
|
...toArray(include),
|
|
34
36
|
],
|
|
35
37
|
exclude: ["node_modules/**", ".next/**", "dist/**", "tests/e2e/**", ...toArray(exclude)],
|
|
36
|
-
env: {
|
|
37
|
-
TZ: "UTC",
|
|
38
|
-
// A fixed, test-only value so the suite is self-sufficient on a clean checkout (CI has no `.env`). It is not a secret and must never be used outside tests.
|
|
39
|
-
BETTER_AUTH_SECRET: "test-only-better-auth-secret-not-a-real-secret",
|
|
40
|
-
...env,
|
|
41
|
-
},
|
|
38
|
+
env: { TZ: "UTC", ...Object.assign({}, ...fragments.map((f) => f.testValues)), ...env },
|
|
42
39
|
},
|
|
43
40
|
};
|
|
44
41
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Connected accounts' variables, an env fragment for `defineEnv({ fragments })`. */
|
|
3
|
+
export declare const connectionsEnv: {
|
|
4
|
+
readonly name: "connectionsEnv";
|
|
5
|
+
readonly schema: {
|
|
6
|
+
readonly TOKEN_ENCRYPTION_KEY: z.ZodOptional<z.ZodString>;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Loaded by the app's `env.ts`, so it imports nothing but zod: never the connections module itself.
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
/** Connected accounts' variables, an env fragment for `defineEnv({ fragments })`. */
|
|
4
|
+
export const connectionsEnv = {
|
|
5
|
+
name: "connectionsEnv",
|
|
6
|
+
schema: {
|
|
7
|
+
// Encrypts connected-account tokens (`@wwchen/stack/connections`): 32 bytes, base64 (`openssl rand -base64 32`). Keep it forever: a new key makes every stored token unreadable.
|
|
8
|
+
TOKEN_ENCRYPTION_KEY: z
|
|
9
|
+
.string()
|
|
10
|
+
.refine((v) => Buffer.from(v, "base64").length === 32, {
|
|
11
|
+
message: "must be 32 bytes, base64-encoded (openssl rand -base64 32)",
|
|
12
|
+
})
|
|
13
|
+
.optional(),
|
|
14
|
+
},
|
|
15
|
+
};
|
|
@@ -23,7 +23,7 @@ export type ConnectionsOptions = {
|
|
|
23
23
|
db: Database;
|
|
24
24
|
table: ConnectionTable;
|
|
25
25
|
providers: ConnectionProvider[];
|
|
26
|
-
/** Signs the OAuth state
|
|
26
|
+
/** Signs the OAuth state: a long secret of the app's own; a sub-key is derived from it. */
|
|
27
27
|
secret: string;
|
|
28
28
|
/** `TOKEN_ENCRYPTION_KEY`: 32 bytes, base64. Checked on first use, not at construction. */
|
|
29
29
|
encryptionKey: string | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
-
import { safeNext } from "@wwchen/stack-auth";
|
|
3
2
|
import { and, asc, eq } from "drizzle-orm";
|
|
3
|
+
import { safeNext } from "../http/index.js";
|
|
4
4
|
import { decryptToken, encryptToken, parseEncryptionKey } from "./crypto.js";
|
|
5
5
|
/**
|
|
6
6
|
* Connected accounts: a signed-in person connects an account at another service so the app can work on their behalf. This is deliberately not sign-in — a connection never signs anyone in and never creates a user; people sign in by email.
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AnyPgColumn } from "drizzle-orm/pg-core";
|
|
2
2
|
/**
|
|
3
|
-
* The `connection` table: an account at another service that a signed-in person connected so the app can work on their behalf. The app re-exports it from its schema next to
|
|
3
|
+
* The `connection` table: an account at another service that a signed-in person connected so the app can work on their behalf. The app re-exports it from its schema next to its user table, so drizzle-kit generates it into the app's own migrations.
|
|
4
4
|
*
|
|
5
5
|
* - One connection per person per provider (reconnecting replaces the token).
|
|
6
6
|
* - One person per provider account (`subject`): an account already connected to someone else is refused, so two people can never share one account's data.
|
|
7
7
|
* - Removing the person removes their connections (the foreign key cascades in the same statement).
|
|
8
8
|
* - `token` is only ever ciphertext (`crypto.ts`).
|
|
9
9
|
*/
|
|
10
|
-
export declare function connectionTable(
|
|
10
|
+
export declare function connectionTable(users: {
|
|
11
|
+
id: AnyPgColumn;
|
|
12
|
+
}): import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
11
13
|
name: "connection";
|
|
12
14
|
schema: undefined;
|
|
13
15
|
columns: {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { pgTable, text, timestamp, unique, uuid } from "drizzle-orm/pg-core";
|
|
2
2
|
/**
|
|
3
|
-
* The `connection` table: an account at another service that a signed-in person connected so the app can work on their behalf. The app re-exports it from its schema next to
|
|
3
|
+
* The `connection` table: an account at another service that a signed-in person connected so the app can work on their behalf. The app re-exports it from its schema next to its user table, so drizzle-kit generates it into the app's own migrations.
|
|
4
4
|
*
|
|
5
5
|
* - One connection per person per provider (reconnecting replaces the token).
|
|
6
6
|
* - One person per provider account (`subject`): an account already connected to someone else is refused, so two people can never share one account's data.
|
|
7
7
|
* - Removing the person removes their connections (the foreign key cascades in the same statement).
|
|
8
8
|
* - `token` is only ever ciphertext (`crypto.ts`).
|
|
9
9
|
*/
|
|
10
|
-
export function connectionTable(
|
|
10
|
+
export function connectionTable(users) {
|
|
11
11
|
return pgTable("connection", {
|
|
12
12
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
13
13
|
userId: uuid("user_id")
|
|
14
14
|
.notNull()
|
|
15
|
-
.references(() =>
|
|
15
|
+
.references(() => users.id, { onDelete: "cascade" }),
|
|
16
16
|
provider: text("provider").notNull(),
|
|
17
17
|
subject: text("subject").notNull(),
|
|
18
18
|
name: text("name"),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { EnvSource } from "./define-env.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The variables every stack app shares, the first of the app's fragments: `defineEnv({ fragments: [coreEnv, dbEnv, …], schema: { MY_VAR: z.string() } })`. Blank values are treated as absent by `defineEnv`, so no field needs its own preprocessing.
|
|
5
|
+
*/
|
|
6
|
+
export declare const coreEnv: {
|
|
7
|
+
name: string;
|
|
8
|
+
schema: {
|
|
9
|
+
NODE_ENV: z.ZodDefault<z.ZodEnum<{
|
|
10
|
+
readonly development: "development";
|
|
11
|
+
readonly test: "test";
|
|
12
|
+
readonly production: "production";
|
|
13
|
+
}>>;
|
|
14
|
+
APP_URL: z.ZodDefault<z.ZodString>;
|
|
15
|
+
CRON_SECRET: z.ZodOptional<z.ZodString>;
|
|
16
|
+
HEALTH_TOKEN: z.ZodOptional<z.ZodString>;
|
|
17
|
+
TRUSTED_PROXY_HOPS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
18
|
+
LOG_LEVEL: z.ZodDefault<z.ZodString>;
|
|
19
|
+
};
|
|
20
|
+
productionRequired: "APP_URL"[];
|
|
21
|
+
};
|
|
22
|
+
/** Whether this is a production run. For the build-time config, which loads before any env schema. */
|
|
23
|
+
export declare function isProductionEnv(source?: EnvSource): boolean;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { NODE_ENVS } from "../stack/contracts.js";
|
|
3
|
+
const schema = {
|
|
4
|
+
// Set by tooling, never by `.env`: next dev/build set it, Vitest sets `test`, Vercel's runtime sets `production`.
|
|
5
|
+
NODE_ENV: z.enum(NODE_ENVS).default(NODE_ENVS.development),
|
|
6
|
+
APP_URL: z.string().default("http://localhost:3000"),
|
|
7
|
+
CRON_SECRET: z.string().optional(),
|
|
8
|
+
HEALTH_TOKEN: z.string().optional(),
|
|
9
|
+
// For `clientIp`: 0 on Vercel, which terminates the proxy chain itself.
|
|
10
|
+
TRUSTED_PROXY_HOPS: z.coerce.number().int().nonnegative().default(0),
|
|
11
|
+
LOG_LEVEL: z.string().default("info"),
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The variables every stack app shares, the first of the app's fragments: `defineEnv({ fragments: [coreEnv, dbEnv, …], schema: { MY_VAR: z.string() } })`. Blank values are treated as absent by `defineEnv`, so no field needs its own preprocessing.
|
|
15
|
+
*/
|
|
16
|
+
export const coreEnv = {
|
|
17
|
+
name: "coreEnv",
|
|
18
|
+
schema,
|
|
19
|
+
productionRequired: ["APP_URL"],
|
|
20
|
+
};
|
|
21
|
+
/** Whether this is a production run. For the build-time config, which loads before any env schema. */
|
|
22
|
+
export function isProductionEnv(source = process.env) {
|
|
23
|
+
return source.NODE_ENV === NODE_ENVS.production;
|
|
24
|
+
}
|
package/dist/env/define-env.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { type EnvFragment } from "../stack/contracts.ts";
|
|
2
3
|
export type EnvSource = Record<string, string | undefined>;
|
|
3
4
|
export interface EnvProblem {
|
|
4
5
|
variable: string;
|
|
@@ -11,20 +12,31 @@ export declare class ConfigError extends Error {
|
|
|
11
12
|
readonly problems: EnvProblem[];
|
|
12
13
|
constructor(problems: EnvProblem[]);
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
15
|
+
/** What `defineEnv` validates: the fragments the app's packages give, plus the app's own variables. */
|
|
16
|
+
export interface EnvSpec<F extends readonly EnvFragment[] = readonly EnvFragment[], S extends z.ZodRawShape = z.ZodRawShape> {
|
|
17
|
+
/** Each package's variables. A name may be defined once across the fragments and `schema`. */
|
|
18
|
+
fragments?: F;
|
|
19
|
+
/** The app's own variables. */
|
|
20
|
+
schema?: S;
|
|
21
|
+
/** The app's production requirements, on top of each fragment's. */
|
|
22
|
+
productionRequired?: readonly string[];
|
|
23
|
+
/** The app's all-or-none groups, on top of each fragment's. */
|
|
24
|
+
groups?: Readonly<Record<string, readonly string[]>>;
|
|
20
25
|
}
|
|
26
|
+
type UnionToIntersection<U> = (U extends unknown ? (u: U) => void : never) extends (i: infer I) => void ? I : never;
|
|
27
|
+
/** A shape with no variables: the app's schema when it has none, and the fragments' when there are none. */
|
|
28
|
+
type NoShape = Record<never, never>;
|
|
29
|
+
/** Every fragment's schema, as one shape. */
|
|
30
|
+
export type MergedShape<F extends readonly EnvFragment[]> = UnionToIntersection<F[number]["schema"]> extends infer M extends z.ZodRawShape ? M : NoShape;
|
|
21
31
|
/**
|
|
22
|
-
* Validates `source` (default `process.env`, the only place the package reads it) against `schema
|
|
32
|
+
* Validates `source` (default `process.env`, the only place the package reads it) against the fragments' schemas and the app's own `schema`, merged.
|
|
23
33
|
*
|
|
34
|
+
* - A variable defined by two fragments, or by a fragment and the app's schema, throws an `Error` naming both.
|
|
24
35
|
* - Blank values are absent; `<NAME>_FILE` is read when `<NAME>` is unset (both set is an error).
|
|
25
36
|
* - Production requirements are checked against the resolved value before defaults apply, so a development default can never satisfy one.
|
|
26
|
-
* - During a Next build (`NEXT_PHASE=phase-production-build`) or with `SKIP_ENV_VALIDATION=1`, a build is not a boot: production requirements
|
|
27
|
-
* - When the schema has `APP_URL` and it is unset, it is derived on Vercel: from VERCEL_PROJECT_PRODUCTION_URL in production, from VERCEL_BRANCH_URL / VERCEL_URL on a preview
|
|
37
|
+
* - During a Next build (`NEXT_PHASE=phase-production-build`) or with `SKIP_ENV_VALIDATION=1`, a build is not a boot: production requirements and groups are not enforced, and an unset variable with a fragment's build placeholder takes it, but defaults still apply. With `NODE_ENV=production`, `SKIP_ENV_VALIDATION` is ignored outside the build phase.
|
|
38
|
+
* - When the merged schema has `APP_URL` and it is unset, it is derived on Vercel: from VERCEL_PROJECT_PRODUCTION_URL in production, from VERCEL_BRANCH_URL / VERCEL_URL on a preview.
|
|
28
39
|
* - Throws one `ConfigError` listing every problem.
|
|
29
40
|
*/
|
|
30
|
-
export declare function defineEnv<S extends z.ZodRawShape>(spec: EnvSpec<S>, rawSource?: EnvSource): z.infer<z.ZodObject<S>>;
|
|
41
|
+
export declare function defineEnv<const F extends readonly EnvFragment[] = [], S extends z.ZodRawShape = NoShape>(spec: EnvSpec<F, S>, rawSource?: EnvSource): z.infer<z.ZodObject<MergedShape<F> & S>>;
|
|
42
|
+
export {};
|