@wwchen/stack 0.9.1 → 0.10.1
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 +23 -13
- package/blocks/AGENTS.md +4 -12
- package/blocks/CLAUDE.md +7 -15
- package/blocks/env.example +0 -11
- package/blocks/gitignore +1 -2
- package/dist/cli/builtin.d.ts +6 -0
- package/dist/cli/builtin.js +47 -0
- package/dist/cli/context.d.ts +6 -20
- package/dist/cli/context.js +2 -2
- package/dist/cli/host.d.ts +8 -0
- package/dist/cli/host.js +128 -0
- package/dist/cli/index.js +4 -71
- package/dist/cli/neon.d.ts +4 -4
- package/dist/cli/neon.js +19 -9
- package/dist/cli/run.js +1 -1
- package/dist/cli/sync-blocks.d.ts +9 -8
- package/dist/cli/sync-blocks.js +157 -47
- package/dist/configs/vitest.js +1 -6
- 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/db/branches.d.ts +11 -0
- package/dist/db/branches.js +19 -0
- package/dist/db/doctor.d.ts +9 -0
- package/dist/db/doctor.js +120 -0
- package/dist/db/env.d.ts +14 -0
- package/dist/db/env.js +15 -0
- package/dist/db/health.d.ts +10 -0
- package/dist/db/health.js +26 -0
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.js +1 -0
- package/dist/db/target.js +2 -1
- 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/health.d.ts +5 -7
- package/dist/next/health.js +16 -17
- package/dist/stack/contracts.d.ts +152 -0
- package/dist/stack/contracts.js +42 -0
- package/dist/vercel/index.d.ts +28 -0
- package/dist/vercel/index.js +90 -0
- package/package.json +22 -4
- 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/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/env/stack-env.d.ts +0 -37
- package/dist/env/stack-env.js +0 -54
package/README.md
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
# @wwchen/stack
|
|
2
2
|
|
|
3
|
-
Shared building blocks for Next.js 16 apps on Neon
|
|
3
|
+
Shared building blocks for Next.js 16 apps on Neon and lew-ds, and the `stack` command that runs the packages an app composes. Sign-in is [`@wwchen/stack-auth`](../auth), mail is [`@wwchen/stack-notify`](../notify) and hosting on Vercel is [`@wwchen/stack-infra`](../infra), released with this package under the same version, as is [`@wwchen/stack-upgrade`](../upgrade), which moves an app onto a release. Apps are normally created from the Copier template in [wwchen/bootstrap-stack](https://github.com/wwchen/bootstrap-stack), which wires everything below; this README is the package's reference.
|
|
4
4
|
|
|
5
|
-
Requires Node 24. The peer dependencies are exact pins: `next`, `react`, `react-dom`, `drizzle-orm`, `@lew-ds/lds`, `@lew-ds/lds-react`, `@lew-ds/open-icons`; `typescript` takes patch releases (`~`)
|
|
5
|
+
Requires Node 24. The peer dependencies are exact pins: `next`, `react`, `react-dom`, `drizzle-orm`, `@lew-ds/lds`, `@lew-ds/lds-react`, `@lew-ds/open-icons`; `typescript` takes patch releases (`~`). `@electric-sql/pglite` and `@electric-sql/pglite-socket` are optional peers for tests and local development, and `storybook` and `@storybook/nextjs-vite` for an app's Storybook.
|
|
6
6
|
|
|
7
7
|
## Entry points
|
|
8
8
|
|
|
9
9
|
| Import | What it gives you |
|
|
10
10
|
|---|---|
|
|
11
|
-
| `@wwchen/stack
|
|
12
|
-
| `@wwchen/stack/
|
|
11
|
+
| `@wwchen/stack` | `defineStack({ packages })` for the app's `stack.config.ts`, and the types a package implements for it (`StackPackage`, `Command`, `BuildStep`, `DoctorCheck`, `EnvFragment`, `Gate`, `HealthCheck`, …) |
|
|
12
|
+
| `@wwchen/stack/env` | `defineEnv({ fragments, schema })`: the app's variables, validated, from each package's env fragment plus the app's own `schema` (a name defined twice is an error naming both); `coreEnv`, the shared variables (production requires `APP_URL`, derived on Vercel when unset). `SKIP_ENV_VALIDATION=1` skips it in builds (never at production runtime). |
|
|
13
|
+
| `@wwchen/stack/db/env` | `dbEnv`: `DATABASE_URL` (required in production, a placeholder during a build), `DATABASE_URL_UNPOOLED`, `PRODUCTION_DATABASE_HOST` |
|
|
14
|
+
| `@wwchen/stack/db/branches` | `databaseEnv(ctx, { preview })`, for a package's `stack` command that reaches the app's database: your Neon dev branch's connection variables (nothing when `DATABASE_URL` or `ENV_FILE` already names one), or with `preview` the shared `preview` branch's; never part of the app's runtime |
|
|
15
|
+
| `@wwchen/stack/db` | the pooled client, `migrationStatus`, `databaseCheck(db)` (the database's `HealthCheck` for `healthRoute`), the dev-database guard that refuses production |
|
|
13
16
|
| `@wwchen/stack/db/testing`, `/db/testing/isolate` | test databases: PGlite by default, a real Postgres when `TEST_DATABASE_URL` is set |
|
|
14
|
-
| `@wwchen/stack/next` | `withStack(appConfig)` for `next.config.ts`, `apiHandler` and `readJson`, `cronRoute` (answers 500 when the job returns `alerting: true`) and `healthRoute` |
|
|
17
|
+
| `@wwchen/stack/next` | `withStack(appConfig)` for `next.config.ts`, `apiHandler({ label, gate }, fn)` (the `Gate` decides the caller: its 401 answers `unauthenticated`, its 404 `not_found`, its principal reaches `fn`) and `readJson`, `cronRoute` (answers 500 when the job returns `alerting: true`) and `healthRoute({ token, checks })` (each `HealthCheck`'s fields join the answer for the token) |
|
|
18
|
+
| `@wwchen/stack/http` | `safeNext(raw, fallback?)` (a `?next=` kept only when it is a path on this site) and `clientIp(headers, hops)` (the caller, read from `X-Forwarded-For` counted from the right) |
|
|
19
|
+
| `@wwchen/stack/vercel` | the linked Vercel project's metadata through the Vercel CLI, for a package's `stack` command: `linkedProject` (`.vercel/project.json`), `vercelApi`, `listEnvs` and `envVarMeta` (each variable's metadata, never its value), `readJsonFile`; never part of the app's runtime |
|
|
15
20
|
| `@wwchen/stack/connections` | connected accounts (not sign-in): `connectionTable`, `createConnections` (start and callback route handlers, `token`, `list`, `connected`, `disconnect`), the `ConnectionProvider` type each app implements for its own services, AES-256-GCM token encryption under `TOKEN_ENCRYPTION_KEY` |
|
|
21
|
+
| `@wwchen/stack/connections/env` | `connectionsEnv`: `TOKEN_ENCRYPTION_KEY` |
|
|
16
22
|
| `@wwchen/stack/jobs` | multi-person scheduled jobs: `failingSince` and `isNewFailure` (alert on a failure's first 24 hours only), `mapLimit` |
|
|
17
23
|
| `@wwchen/stack/ui`, `/ui/icons`, `/ui/globals.css`, `/ui/app.css` | lew-ds wiring, theme cookie, icon sprite and its usage check, and the CSS partials |
|
|
18
24
|
| `@wwchen/stack/storybook` | an app's Storybook set up as its root layout sets up a page: `stackPreview({ icons, fontVariable, bodyClassName })` (the `<html>` theme classes with a light/dark toolbar, the icon sprite, a logging stand-in for the App Router's `useRouter()`, the viewports), and `PHONE` and `SMALL_PHONE` story globals |
|
|
19
25
|
| `@wwchen/stack/configs/tsconfig.next.json`, `/configs/biome.json`, `/configs/vitest` | shared tool configs, consumed with `extends` or an import |
|
|
20
26
|
| `@wwchen/stack/testing/next` | tests only: `inServerAction` runs a function in a real Next server-action scope, `thrownBy` reads a `redirect()`/`notFound()` |
|
|
21
27
|
|
|
22
|
-
Sign-in and mail are [`@wwchen/stack-auth`](../auth) and [`@wwchen/stack-notify`](../notify); the old paths (`@wwchen/stack/auth`, `/auth/better-auth`, `/auth/proxy`, `/mail`) are gone, and
|
|
28
|
+
Sign-in and mail are [`@wwchen/stack-auth`](../auth) and [`@wwchen/stack-notify`](../notify); the old paths (`@wwchen/stack/auth`, `/auth/better-auth`, `/auth/proxy`, `/mail`) are gone, and [`@wwchen/stack-upgrade`](../upgrade) moves an app's imports off them. Sign-in never creates users: every user is added first (`stack user:create`, a command of `@wwchen/stack-auth`), has an email, and the email is unique, trimmed and lower-cased.
|
|
23
29
|
|
|
24
30
|
### Connected accounts
|
|
25
31
|
|
|
@@ -53,15 +59,19 @@ The callback lands on `next` with `?connection=<provider>&result=<code>`, where
|
|
|
53
59
|
| `stack run <script> [args]` | runs an app script with Node (type stripping) and the app's database and `.env`; `ENV_FILE` opts in to another |
|
|
54
60
|
| `stack neon seed` | rebuilds the `seed` branch (fake data) and runs the app's `db/seed.ts` |
|
|
55
61
|
| `stack neon reset-preview [--set-vercel]` | re-cuts the shared `preview` branch from `seed`; `--set-vercel` writes its URLs as Vercel's sensitive Preview `DATABASE_URL`/`DATABASE_URL_UNPOOLED` |
|
|
56
|
-
| `stack
|
|
57
|
-
| `stack
|
|
58
|
-
| `stack
|
|
59
|
-
| `stack
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
| `stack db:check` | fails when the app's `src/db/schema.ts` has changes `drizzle/` has no migration for; app CI runs it |
|
|
63
|
+
| `stack db:generate <name> [drizzle-kit flags]` | the app's `pnpm db:generate`: drizzle-kit generate under a snake_case name that says what the migration does (`stack_` names are the upgrade's) |
|
|
64
|
+
| `stack db:upgrade` | generates the migration for the stack's tables' changes into `drizzle/` as `stack_<version>`; Copier's task runs it after the upgrade |
|
|
65
|
+
| `stack sync-blocks [--check]` | writes each composed package's marked block (`stack` first, then `stack.config.ts`'s order) in `AGENTS.md`, `CLAUDE.md`, `.gitignore`, `.env.example`, and removes the block of a package the app no longer composes, saying each one it removes; `--check` exits 1 when any block is missing, stale or orphaned |
|
|
66
|
+
|
|
67
|
+
Each package the app's `stack.config.ts` composes adds its own commands: `@wwchen/stack-auth` gives `stack user:create` and `stack user:role`, and `@wwchen/stack-infra` gives `stack vercel-build` and `stack doctor` (their READMEs). When two composed packages give one command, `stack` runs nothing and names both; so too for an entry of `packages` that is not a package, such as a factory listed without its call (`infra` for `infra()`), which `defineStack` also makes a type error.
|
|
68
|
+
|
|
69
|
+
`stack` also says on stderr what the app does not compose, without changing what runs, its exit code or its stdout. With no `stack.config.ts`, every command first prints one line: ``stack.config.ts is missing: the app composes no packages, so only the stack's built-in commands run and `stack sync-blocks` writes only the stack's own blocks.`` With one, it prints a line for each dependency in the app's `package.json` (`dependencies` and `devDependencies`) whose installed package has a `./stack` entry that `stack.config.ts` does not compose: ``<name> is installed but stack.config.ts does not compose it: add its `/stack` entry to `packages`, or remove the dependency.``
|
|
70
|
+
|
|
71
|
+
This package gives those two its share: the `migrate` build step, which `stack vercel-build` runs before `next build` (a Preview or Production deployment migrates its own database, and a preview whose database URL is production's is refused; anything else does nothing), and `stack doctor`'s checks of the Neon integration, the database variables and the shared `CRON_SECRET` and `TOKEN_ENCRYPTION_KEY`.
|
|
62
72
|
|
|
63
73
|
`NEON_PROJECT_ID` comes from the environment; nothing in the package names a project or domain.
|
|
64
74
|
|
|
65
75
|
## Versioning
|
|
66
76
|
|
|
67
|
-
The package, `@wwchen/stack-auth`, `@wwchen/stack-notify`, the Copier template and the shared CI workflow share one version, tagged `vX.Y.Z`. Releases are published to npm with provenance.
|
|
77
|
+
The package, `@wwchen/stack-auth`, `@wwchen/stack-notify`, `@wwchen/stack-infra`, `@wwchen/stack-upgrade`, the Copier template and the shared CI workflow share one version, tagged `vX.Y.Z`. Releases are published to npm with provenance.
|
package/blocks/AGENTS.md
CHANGED
|
@@ -16,10 +16,6 @@
|
|
|
16
16
|
| Storybook | `pnpm storybook` (http://localhost:6006) · every story built, as CI does: `pnpm storybook:build` |
|
|
17
17
|
| Migrate | `pnpm db:migrate` (your dev branch) |
|
|
18
18
|
| Rebuild the `seed` branch (fake data; every dev and preview branch is cut from it) | `pnpm exec stack neon seed` |
|
|
19
|
-
| Add a user | `stack user:create <email> [--admin]` (on your dev branch; production: the runbook's "First admin") |
|
|
20
|
-
| Sign in on a preview | `stack user:create <your email> --admin --preview` (your own email only; `stack neon reset-preview` drops it) |
|
|
21
|
-
| Change a user's role | `stack user:role <email> <admin\|user>` |
|
|
22
|
-
| Check the Vercel project's setup | `stack doctor` (read-only; exits 1 on an error) |
|
|
23
19
|
| Refresh the stack blocks in this file | `stack sync-blocks` (`--check` in CI) |
|
|
24
20
|
|
|
25
21
|
**Gate:** `pnpm typecheck && pnpm lint && pnpm test` must pass before any task is marked done.
|
|
@@ -32,7 +28,6 @@
|
|
|
32
28
|
4. Server components by default. `"use client"` only for state, effects or event handlers, on the smallest leaf, never on a layout.
|
|
33
29
|
5. Validate at the edge: parse every route handler's input with zod before any logic.
|
|
34
30
|
6. Authorization is server-side on every request. Another user's row answers 404, never 403.
|
|
35
|
-
7. Everyone signs in by email; sign-in never creates a user.
|
|
36
31
|
|
|
37
32
|
## Next.js notes
|
|
38
33
|
|
|
@@ -54,16 +49,13 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
|
|
|
54
49
|
- Postgres on Neon, with Drizzle. Local dev runs on your own Neon branch cut from `seed`, never from production; previews get their own branch, also from `seed`. Other people's data stays out of dev and previews.
|
|
55
50
|
- Local tooling refuses the production database unless you opt in deliberately.
|
|
56
51
|
- Tests run on PGlite (one connection only) and, in CI, a real Postgres.
|
|
57
|
-
- Every user has an email: required, unique, lower-cased and trimmed.
|
|
58
52
|
- Schema changes go through `pnpm db:generate <name>` and a reviewed migration, never through the Neon console or a database MCP server.
|
|
59
53
|
|
|
60
54
|
## Security
|
|
61
55
|
|
|
62
56
|
1. `CRON_SECRET` can only trigger scheduled jobs; admin and data access never accept it.
|
|
63
57
|
2. Never render free text from a URL; redirects carry short codes.
|
|
64
|
-
3.
|
|
65
|
-
4.
|
|
66
|
-
5.
|
|
67
|
-
6.
|
|
68
|
-
7. Previews get their own secrets and no production third-party keys.
|
|
69
|
-
8. Never write a deployment's domain in the repo. Name variables (`APP_URL`, `EMAIL_FROM`), never a host.
|
|
58
|
+
3. Mutations require JSON and a same-origin request.
|
|
59
|
+
4. Connected-account tokens are encrypted at rest.
|
|
60
|
+
5. Previews get their own secrets and no production third-party keys.
|
|
61
|
+
6. Never write a deployment's domain in the repo. Name variables (`APP_URL`, `NEON_PROJECT_ID`), never a host.
|
package/blocks/CLAUDE.md
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
| Local database | Your own Neon dev branch: `stack dev-setup` once, then `stack with-neon <command>` |
|
|
10
10
|
| No Neon at hand | `stack dev --pglite`: PGlite in `.local-db/`, migrated and seeded, then `next dev` |
|
|
11
11
|
| Run an app script | `stack run <script> [args]` (your dev branch and `.env`, like `with-neon`) |
|
|
12
|
-
| Build | `pnpm build` · on Vercel: `stack vercel-build` (migrates the deployment's own database first) |
|
|
13
12
|
| Typecheck | `pnpm typecheck` |
|
|
14
13
|
| Lint / format | `pnpm lint` · `pnpm lint:fix` |
|
|
15
14
|
| Tests | `pnpm test` · one file: `pnpm test tests/unit/<name>.test.ts` |
|
|
@@ -17,10 +16,6 @@
|
|
|
17
16
|
| DB generate / apply migration | `pnpm db:generate <name>` (snake_case, what it does: `add_widgets`) · `pnpm db:migrate` |
|
|
18
17
|
| Seed the shared `seed` branch | `stack neon seed` (runs the app's `db/seed.ts`) |
|
|
19
18
|
| Reset the shared preview branch | `stack neon reset-preview` (`--set-vercel` also writes its URLs into Vercel's Preview variables) |
|
|
20
|
-
| Check the Vercel project's setup | `stack doctor` (read-only; exits 1 on an error) |
|
|
21
|
-
| Add a user / an admin | `stack user:create <email> [--admin]` (on your dev branch; production: the runbook's "First admin") |
|
|
22
|
-
| Sign in on a preview | `stack user:create <your email> --admin --preview` (your own email only; `stack neon reset-preview` drops it) |
|
|
23
|
-
| Change a user's role | `stack user:role <email> <admin\|user>` (keeps at least one admin) |
|
|
24
19
|
| Refresh the stack blocks in this file | `stack sync-blocks` (`--check` in CI) |
|
|
25
20
|
|
|
26
21
|
**Gate:** `pnpm typecheck && pnpm lint && pnpm test` must pass before any task is marked done. Never mark a task done with a failing gate command.
|
|
@@ -29,9 +24,9 @@ Node is pinned in `.nvmrc`; pnpm is installed with `npm install -g pnpm@<version
|
|
|
29
24
|
|
|
30
25
|
## Stack
|
|
31
26
|
|
|
32
|
-
Next.js (App Router) · TypeScript · Tailwind CSS v4 (layout only) · LDS, product theme (`@lew-ds/lds`) · Postgres on Neon (PGlite in tests) · Drizzle ORM ·
|
|
27
|
+
Next.js (App Router) · TypeScript · Tailwind CSS v4 (layout only) · LDS, product theme (`@lew-ds/lds`) · Postgres on Neon (PGlite in tests) · Drizzle ORM · Vercel · `@wwchen/stack` for the shared code, configs and CLI.
|
|
33
28
|
|
|
34
|
-
**Local dev runs on a Neon dev branch** (`dev/<os-user>`), cut from `seed`, which holds fake
|
|
29
|
+
**Local dev runs on a Neon dev branch** (`dev/<os-user>`), cut from `seed`, which holds fake data. `stack with-neon` reads the branch's connection strings on every run and refuses the production database. Check the `[neon] <branch>` line it prints before running a database command.
|
|
35
30
|
|
|
36
31
|
**One connection on PGlite.** The tests run on PGlite: a single backend. A script run while another process holds that connection is refused; stop the other process first.
|
|
37
32
|
|
|
@@ -66,19 +61,16 @@ The design system is LDS (Lew Design System), product theme: `@lew-ds/lds`, `@le
|
|
|
66
61
|
- The app uses `pg` on the pooled `DATABASE_URL`; migrations use `DATABASE_URL_UNPOOLED` when set.
|
|
67
62
|
- Dev and preview branches come from `seed`, never from production, so other people's data stays out of dev and previews. Previews get their own secrets and no production third-party keys.
|
|
68
63
|
- Money, if any, is stored as integer minor units, never floats.
|
|
69
|
-
- Every user has an email: required, unique, lower-cased and trimmed.
|
|
70
64
|
|
|
71
65
|
## Security rules
|
|
72
66
|
|
|
73
67
|
1. `CRON_SECRET` can only trigger scheduled jobs (counts-only responses); admin and data access never accept it.
|
|
74
68
|
2. No free text from URLs is ever rendered; redirects carry short codes.
|
|
75
|
-
3.
|
|
76
|
-
4.
|
|
77
|
-
5.
|
|
78
|
-
6.
|
|
79
|
-
7.
|
|
80
|
-
8. Other people's data stays out of dev and previews.
|
|
81
|
-
9. Never commit secrets, `.env` or build output. No deployment's domain, Neon project id or key in the repo: code, docs and this file name variables (`APP_URL`, `EMAIL_FROM`, `NEON_PROJECT_ID`), never a value. `.env.example` is committed and stays in sync; `.env` never is.
|
|
69
|
+
3. Mutations require JSON and same-origin.
|
|
70
|
+
4. Local tooling refuses the production database unless explicitly opted in.
|
|
71
|
+
5. Connected-account tokens are encrypted at rest (AES-256-GCM).
|
|
72
|
+
6. Other people's data stays out of dev and previews.
|
|
73
|
+
7. Never commit secrets, `.env` or build output. No deployment's domain, Neon project id or key in the repo: code, docs and this file name variables (`APP_URL`, `NEON_PROJECT_ID`), never a value. `.env.example` is committed and stays in sync; `.env` never is.
|
|
82
74
|
|
|
83
75
|
## Non-negotiable
|
|
84
76
|
|
package/blocks/env.example
CHANGED
|
@@ -8,23 +8,12 @@ DATABASE_URL=
|
|
|
8
8
|
DATABASE_URL_UNPOOLED=
|
|
9
9
|
# Production database host, so local tooling can refuse it
|
|
10
10
|
PRODUCTION_DATABASE_HOST=
|
|
11
|
-
# Signs session cookies and tokens, at least 32 characters (required in production)
|
|
12
|
-
BETTER_AUTH_SECRET=
|
|
13
|
-
# Sign-in mail through Resend (required in production; elsewhere the link goes to the sink file)
|
|
14
|
-
RESEND_API_KEY=
|
|
15
|
-
# Sender on a domain verified in Resend (required in production)
|
|
16
|
-
EMAIL_FROM=
|
|
17
|
-
# Where development writes sign-in links (default .magic-links.log)
|
|
18
|
-
MAGIC_LINK_SINK_PATH=
|
|
19
11
|
# Bearer secret for scheduled jobs only
|
|
20
12
|
CRON_SECRET=
|
|
21
13
|
# Encrypts connected-account tokens: openssl rand -base64 32. Keep it forever (a new key orphans every token)
|
|
22
14
|
TOKEN_ENCRYPTION_KEY=
|
|
23
15
|
# Bearer token for the health route's database probe
|
|
24
16
|
HEALTH_TOKEN=
|
|
25
|
-
# Sign in with Google: set both or neither
|
|
26
|
-
GOOGLE_CLIENT_ID=
|
|
27
|
-
GOOGLE_CLIENT_SECRET=
|
|
28
17
|
# Proxy hops to trust for the client IP (0 on Vercel)
|
|
29
18
|
TRUSTED_PROXY_HOPS=
|
|
30
19
|
# Log level (default info)
|
package/blocks/gitignore
CHANGED
|
@@ -12,8 +12,7 @@ storybook-static
|
|
|
12
12
|
.pglite/
|
|
13
13
|
.pglite.lock
|
|
14
14
|
.local-db/
|
|
15
|
-
.magic-links.log
|
|
16
15
|
|
|
17
|
-
# Secrets: only the example is committed.
|
|
16
|
+
# Secrets: only the example is committed. No pattern after these may match `.env.example`.
|
|
18
17
|
.env*
|
|
19
18
|
!.env.example
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type StackPackage } from "../stack/contracts.ts";
|
|
2
|
+
import type { Cli } from "./context.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The core's own commands, build step, doctor checks and blocks, as the package the host always runs first. Each loader imports its command's module when that command runs. A command that needs the full `Cli` closes over it (its `sql`, `startLocalDatabase` and `username` are the built-in commands' own, not the context's); `sync-blocks` takes the context, whose `packages` it writes the blocks of.
|
|
5
|
+
*/
|
|
6
|
+
export declare function builtinPackage(cli: Cli): StackPackage;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { BLOCK_FILES, BUILTIN_PACKAGE, packageBlocks, } from "../stack/contracts.js";
|
|
2
|
+
/** The package's `blocks/`, beside `src/` and `dist/`, so one relative path serves both and an installed package. */
|
|
3
|
+
const BLOCKS = new URL("../../blocks/", import.meta.url);
|
|
4
|
+
/** The database's and the core's variables, checked by `stack doctor`; named, so a failure names it. */
|
|
5
|
+
const databaseChecks = async (facts) => (await import("../db/doctor.js")).databaseChecks(facts);
|
|
6
|
+
/**
|
|
7
|
+
* The core's own commands, build step, doctor checks and blocks, as the package the host always runs first. Each loader imports its command's module when that command runs. A command that needs the full `Cli` closes over it (its `sql`, `startLocalDatabase` and `username` are the built-in commands' own, not the context's); `sync-blocks` takes the context, whose `packages` it writes the blocks of.
|
|
8
|
+
*/
|
|
9
|
+
export function builtinPackage(cli) {
|
|
10
|
+
const command = (load) => async () => {
|
|
11
|
+
const run = await load();
|
|
12
|
+
return (_ctx, args) => run(cli, args);
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
name: BUILTIN_PACKAGE,
|
|
16
|
+
commands: {
|
|
17
|
+
"with-neon": command(async () => (await import("./neon.js")).withNeon),
|
|
18
|
+
dev: command(async () => (await import("./dev.js")).dev),
|
|
19
|
+
"dev-setup": command(async () => (await import("./neon.js")).devSetup),
|
|
20
|
+
run: command(async () => (await import("./run.js")).runScript),
|
|
21
|
+
neon: command(async () => {
|
|
22
|
+
const { neonSeed, resetPreview } = await import("./neon.js");
|
|
23
|
+
return async (c, [sub, ...rest]) => {
|
|
24
|
+
if (sub === "seed")
|
|
25
|
+
return neonSeed(c);
|
|
26
|
+
if (sub === "reset-preview")
|
|
27
|
+
return resetPreview(c, rest);
|
|
28
|
+
c.error("usage: stack neon seed | stack neon reset-preview [--set-vercel]");
|
|
29
|
+
return 2;
|
|
30
|
+
};
|
|
31
|
+
}),
|
|
32
|
+
"sync-blocks": async () => (await import("./sync-blocks.js")).syncBlocksCommand,
|
|
33
|
+
"db:check": command(async () => (await import("./db.js")).dbCheck),
|
|
34
|
+
"db:generate": command(async () => (await import("./db.js")).dbGenerate),
|
|
35
|
+
"db:upgrade": command(async () => (await import("./db.js")).dbUpgrade),
|
|
36
|
+
},
|
|
37
|
+
// A composed hosting package's `stack vercel-build` and `stack doctor` run these; each loads the database's module only when it runs.
|
|
38
|
+
buildSteps: [
|
|
39
|
+
{
|
|
40
|
+
name: "migrate",
|
|
41
|
+
run: async (ctx) => (await import("../db/doctor.js")).migrateStep.run(ctx),
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
doctorChecks: [databaseChecks],
|
|
45
|
+
blocks: packageBlocks(BLOCKS, Object.values(BLOCK_FILES)),
|
|
46
|
+
};
|
|
47
|
+
}
|
package/dist/cli/context.d.ts
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Env, ExecOptions, ExecResult } from "../stack/contracts.ts";
|
|
2
|
+
/** The stack's own package.json, for the installed version. It sits two levels above both `src/cli/` and `dist/cli/`. */
|
|
2
3
|
export declare const STACK_PACKAGE: {
|
|
3
4
|
version: string;
|
|
4
|
-
dependencies: Record<string, string>;
|
|
5
|
-
};
|
|
6
|
-
export type Env = Record<string, string | undefined>;
|
|
7
|
-
export type ExecResult = {
|
|
8
|
-
stdout: string;
|
|
9
|
-
code: number;
|
|
10
|
-
};
|
|
11
|
-
export type ExecOptions = {
|
|
12
|
-
/** The child's environment; defaults to the CLI's own. */
|
|
13
|
-
env?: Env;
|
|
14
|
-
/** Hand the child this terminal (a dev server, a build) instead of capturing its stdout. */
|
|
15
|
-
inherit?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Written to the child's stdin, then closed: how a secret reaches another CLI without appearing in its arguments. Pass a value already held in full, never a stream still arriving: a CLI that reads stdin at start-up takes whatever is there, which may be nothing yet.
|
|
18
|
-
*/
|
|
19
|
-
input?: string;
|
|
20
5
|
};
|
|
6
|
+
export type { Env, ExecOptions, ExecResult };
|
|
21
7
|
/** A Postgres served on loopback for `stack dev --pglite`. */
|
|
22
8
|
export type LocalDatabase = {
|
|
23
9
|
url: string;
|
|
@@ -34,7 +20,7 @@ export type CliDeps = {
|
|
|
34
20
|
username?: string;
|
|
35
21
|
log?(message: string): void;
|
|
36
22
|
error?(message: string): void;
|
|
37
|
-
/** Imports the app's own TypeScript (`
|
|
23
|
+
/** Imports the app's own TypeScript (`stack.config.ts`, `db/seed.ts`) with Node's type stripping. */
|
|
38
24
|
importModule?(specifier: string): Promise<Record<string, unknown>>;
|
|
39
25
|
/** Runs one SQL statement against a database, for emptying the new `seed` branch. */
|
|
40
26
|
sql?(url: string, statement: string): Promise<Record<string, unknown>[]>;
|
|
@@ -47,8 +33,8 @@ export type CliDeps = {
|
|
|
47
33
|
};
|
|
48
34
|
export type Cli = Required<CliDeps>;
|
|
49
35
|
export declare function resolveDeps(deps: CliDeps): Cli;
|
|
50
|
-
/** Loads the app's `.env` (or the file `ENV_FILE` names) into `env`; real variables always win. */
|
|
51
|
-
export declare function loadAppEnv(cli: Cli): void;
|
|
36
|
+
/** Loads the app's `.env` (or the file `ENV_FILE` names, the deliberate production opt-in) into `env`; real variables always win. */
|
|
37
|
+
export declare function loadAppEnv(cli: Pick<Cli, "cwd" | "env">): void;
|
|
52
38
|
/** Imports a file of the app by path relative to its root. */
|
|
53
39
|
export declare function importApp(cli: Cli, path: string): Promise<Record<string, unknown>>;
|
|
54
40
|
/** A failure the CLI reports as one line and a non-zero exit, with no stack trace. */
|
package/dist/cli/context.js
CHANGED
|
@@ -14,7 +14,7 @@ import pg from "pg";
|
|
|
14
14
|
import { explicitSslMode } from "../db/ssl.js";
|
|
15
15
|
import { startPgliteServer } from "../db/testing/pglite.js";
|
|
16
16
|
import { loadEnvFile } from "../env/index.js";
|
|
17
|
-
/** The stack's own package.json
|
|
17
|
+
/** The stack's own package.json, for the installed version. It sits two levels above both `src/cli/` and `dist/cli/`. */
|
|
18
18
|
export const STACK_PACKAGE = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
19
19
|
export function resolveDeps(deps) {
|
|
20
20
|
return {
|
|
@@ -37,7 +37,7 @@ export function resolveDeps(deps) {
|
|
|
37
37
|
...deps,
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
/** Loads the app's `.env` (or the file `ENV_FILE` names) into `env`; real variables always win. */
|
|
40
|
+
/** Loads the app's `.env` (or the file `ENV_FILE` names, the deliberate production opt-in) into `env`; real variables always win. */
|
|
41
41
|
export function loadAppEnv(cli) {
|
|
42
42
|
loadEnvFile(cli.env.ENV_FILE?.trim() ? undefined : join(cli.cwd, ".env"), cli.env);
|
|
43
43
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type StackPackage } from "../stack/contracts.ts";
|
|
2
|
+
import { type Cli } from "./context.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The built-in package, then the packages `stack.config.ts` composes, in its order. Only the built-in one when the app has no `stack.config.ts`, which it says in one line on stderr; with one, a line on stderr for each stack package the app depends on and does not compose. Neither line changes what runs or its exit code, and stdout stays the command's own.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadPackages(cli: Cli): Promise<StackPackage[]>;
|
|
7
|
+
/** Runs `argv`'s command from whichever package gives it, and resolves to its exit code: 2 with the usage for no command or an unknown one. */
|
|
8
|
+
export declare function runCommand(cli: Cli, argv: string[]): Promise<number>;
|
package/dist/cli/host.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// The `stack` CLI host: it composes the built-in package with the packages the app's `stack.config.ts` lists, refuses a command two packages claim, says what the app does not compose, and runs the one command asked for.
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { STACK_CONFIG_FILE } from "../stack/contracts.js";
|
|
5
|
+
import { readJsonFile } from "../vercel/index.js";
|
|
6
|
+
import { builtinPackage } from "./builtin.js";
|
|
7
|
+
import { CliError, importApp } from "./context.js";
|
|
8
|
+
/** The `exports` entry that makes a dependency a stack package: its `stack.config.ts` entry. */
|
|
9
|
+
const STACK_ENTRY = "./stack";
|
|
10
|
+
const messageOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
11
|
+
/** What every command says first when the app has no `stack.config.ts`. */
|
|
12
|
+
const NO_CONFIG = `${STACK_CONFIG_FILE} is missing: the app composes no packages, so only the stack's built-in commands run and \`stack sync-blocks\` writes only the stack's own blocks.`;
|
|
13
|
+
/**
|
|
14
|
+
* The built-in package, then the packages `stack.config.ts` composes, in its order. Only the built-in one when the app has no `stack.config.ts`, which it says in one line on stderr; with one, a line on stderr for each stack package the app depends on and does not compose. Neither line changes what runs or its exit code, and stdout stays the command's own.
|
|
15
|
+
*/
|
|
16
|
+
export async function loadPackages(cli) {
|
|
17
|
+
const builtin = builtinPackage(cli);
|
|
18
|
+
if (!existsSync(join(cli.cwd, STACK_CONFIG_FILE))) {
|
|
19
|
+
cli.error(NO_CONFIG);
|
|
20
|
+
return [builtin];
|
|
21
|
+
}
|
|
22
|
+
let config;
|
|
23
|
+
try {
|
|
24
|
+
config = (await importApp(cli, STACK_CONFIG_FILE)).default;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
const message = messageOf(error);
|
|
28
|
+
throw new CliError(message.startsWith(`${STACK_CONFIG_FILE}:`) ? message : `${STACK_CONFIG_FILE}: ${message}`);
|
|
29
|
+
}
|
|
30
|
+
const packages = config?.packages;
|
|
31
|
+
if (!Array.isArray(packages)) {
|
|
32
|
+
throw new CliError(`${STACK_CONFIG_FILE}: its default export is not a composition. Export \`defineStack({ packages: [...] })\` as its default.`);
|
|
33
|
+
}
|
|
34
|
+
const problems = packages.flatMap((entry, index) => {
|
|
35
|
+
const problem = notAPackage(entry);
|
|
36
|
+
return problem ? [`${STACK_CONFIG_FILE}: packages[${index}] ${problem}`] : [];
|
|
37
|
+
});
|
|
38
|
+
if (problems.length > 0)
|
|
39
|
+
throw new CliError([...problems, "Nothing was run."].join("\n"));
|
|
40
|
+
const composed = [builtin, ...packages];
|
|
41
|
+
for (const name of uncomposed(cli.cwd, composed)) {
|
|
42
|
+
cli.error(`${name} is installed but ${STACK_CONFIG_FILE} does not compose it: add its \`/stack\` entry to \`packages\`, or remove the dependency.`);
|
|
43
|
+
}
|
|
44
|
+
return composed;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Why a `packages` entry is not a package, or undefined when it is one: a non-null object, not a function, with a non-empty string `name`. A package's factory listed without its call (`infra` for `infra()`) has a string `name` too; composed as is it would give no commands and no blocks, and `sync-blocks` would remove its blocks.
|
|
48
|
+
*/
|
|
49
|
+
function notAPackage(entry) {
|
|
50
|
+
if (typeof entry === "function") {
|
|
51
|
+
const name = entry.name || "the factory";
|
|
52
|
+
return `is a function, not a package; call it: \`${name}(${entry.length > 0 ? "…" : ""})\``;
|
|
53
|
+
}
|
|
54
|
+
if (entry === null)
|
|
55
|
+
return "is null, not a package";
|
|
56
|
+
if (typeof entry !== "object")
|
|
57
|
+
return `is a ${typeof entry}, not a package`;
|
|
58
|
+
const { name } = entry;
|
|
59
|
+
if (typeof name !== "string" || name === "") {
|
|
60
|
+
return "has no name: a package is an object with a non-empty string `name`";
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Each command, sorted, with the packages that give it. */
|
|
65
|
+
function commandOwners(packages) {
|
|
66
|
+
const owners = new Map();
|
|
67
|
+
for (const pkg of packages) {
|
|
68
|
+
for (const command of Object.keys(pkg.commands ?? {})) {
|
|
69
|
+
owners.set(command, [...(owners.get(command) ?? []), pkg]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return new Map([...owners].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
73
|
+
}
|
|
74
|
+
function usage(owners) {
|
|
75
|
+
const lines = ["usage: stack <command>"];
|
|
76
|
+
for (const [command, [pkg]] of owners)
|
|
77
|
+
lines.push(` ${command} (${pkg?.name})`);
|
|
78
|
+
return lines.join("\n");
|
|
79
|
+
}
|
|
80
|
+
/** A JSON file's object, or undefined when it is missing or does not parse: a broken install is pnpm's and the typecheck's to report, not the host's. */
|
|
81
|
+
function manifest(path) {
|
|
82
|
+
try {
|
|
83
|
+
return readJsonFile(path);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The app's dependencies (`dependencies` and `devDependencies` in its package.json) that are stack packages, by the `./stack` entry in their installed package.json's `exports`, and that no composed package is named for: each would otherwise do nothing, with no word. Only the listed dependencies are read, none of theirs.
|
|
91
|
+
*/
|
|
92
|
+
function uncomposed(cwd, packages) {
|
|
93
|
+
const app = manifest(join(cwd, "package.json"));
|
|
94
|
+
const names = new Set([app?.dependencies, app?.devDependencies].flatMap((deps) => typeof deps === "object" && deps !== null ? Object.keys(deps) : []));
|
|
95
|
+
const composed = new Set(packages.map((p) => p.name));
|
|
96
|
+
return [...names].filter((name) => {
|
|
97
|
+
if (composed.has(name))
|
|
98
|
+
return false;
|
|
99
|
+
const exports = manifest(join(cwd, "node_modules", name, "package.json"))?.exports;
|
|
100
|
+
return typeof exports === "object" && exports !== null && STACK_ENTRY in exports;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** Runs `argv`'s command from whichever package gives it, and resolves to its exit code: 2 with the usage for no command or an unknown one. */
|
|
104
|
+
export async function runCommand(cli, argv) {
|
|
105
|
+
const packages = await loadPackages(cli);
|
|
106
|
+
const owners = commandOwners(packages);
|
|
107
|
+
const clashes = [...owners].filter(([, pkgs]) => pkgs.length > 1);
|
|
108
|
+
if (clashes.length > 0) {
|
|
109
|
+
throw new CliError(clashes
|
|
110
|
+
.map(([command, pkgs]) => `${STACK_CONFIG_FILE}: more than one package gives the command ${command}: ${pkgs.map((p) => p.name).join(", ")}. Compose only one of them; nothing was run.`)
|
|
111
|
+
.join("\n"));
|
|
112
|
+
}
|
|
113
|
+
const [command, ...args] = argv;
|
|
114
|
+
const load = command === undefined ? undefined : owners.get(command)?.[0]?.commands?.[command];
|
|
115
|
+
if (!load) {
|
|
116
|
+
cli.error(usage(owners));
|
|
117
|
+
return 2;
|
|
118
|
+
}
|
|
119
|
+
const ctx = {
|
|
120
|
+
cwd: cli.cwd,
|
|
121
|
+
env: cli.env,
|
|
122
|
+
exec: cli.exec,
|
|
123
|
+
log: cli.log,
|
|
124
|
+
error: cli.error,
|
|
125
|
+
packages,
|
|
126
|
+
};
|
|
127
|
+
return (await load())(ctx, args);
|
|
128
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -2,85 +2,18 @@
|
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { realpathSync } from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { dev } from "./dev.js";
|
|
8
|
-
import { doctor } from "./doctor.js";
|
|
9
|
-
import { migrateSuite } from "./migrate-suite.js";
|
|
10
|
-
import { devSetup, neonSeed, resetPreview, withNeon } from "./neon.js";
|
|
11
|
-
import { runScript } from "./run.js";
|
|
12
|
-
import { syncBlocksCommand } from "./sync-blocks.js";
|
|
13
|
-
import { userCreate, userRole } from "./user-create.js";
|
|
14
|
-
import { vercelBuild } from "./vercel-build.js";
|
|
15
|
-
const USAGE = `usage: stack <command>
|
|
16
|
-
with-neon <command> [args] run a command against your Neon dev branch
|
|
17
|
-
dev [--pglite] [next dev args] next dev on your dev branch; --pglite: on PGlite in .local-db/, no Neon
|
|
18
|
-
dev-setup create your dev branch from seed and migrate it
|
|
19
|
-
run <script> [args] run an app script with Node, with the app's database and .env
|
|
20
|
-
neon seed (re)create the seed branch and load the app's seed data
|
|
21
|
-
neon reset-preview [--set-vercel] (re)create the shared preview branch from seed;
|
|
22
|
-
--set-vercel writes its URLs into Vercel's Preview variables
|
|
23
|
-
vercel-build Vercel's build command: migrate, then next build
|
|
24
|
-
doctor audit the linked Vercel project's setup (read-only)
|
|
25
|
-
user:create <email> [--admin] add a user through the app's auth; --preview: on the shared
|
|
26
|
-
preview branch (your own email only, to sign in on a preview)
|
|
27
|
-
user:role <email> <admin|user> change a user's role through the app's auth; --preview as above
|
|
28
|
-
sync-blocks [--check] refresh the stack-owned blocks in AGENTS.md, CLAUDE.md, .gitignore, .env.example
|
|
29
|
-
db:check fail when src/db/schema.ts has changes drizzle/ has no migration for
|
|
30
|
-
db:generate <name> [flags] drizzle-kit generate, named for what the migration does (snake_case)
|
|
31
|
-
db:upgrade generate drizzle/'s migration for the schema's changes, named stack_<version>
|
|
32
|
-
migrate-suite [--expect <version>] move the app onto the suite's packages (@wwchen/stack-auth, -notify);
|
|
33
|
-
--expect: refuse unless the installed stack is that version`;
|
|
5
|
+
import { resolveDeps } from "./context.js";
|
|
6
|
+
import { runCommand } from "./host.js";
|
|
34
7
|
/** The testable entry: every outside effect arrives through `deps`; the exit code comes back. */
|
|
35
8
|
export async function runCli(argv, deps) {
|
|
36
9
|
const cli = resolveDeps(deps);
|
|
37
|
-
const [command, ...args] = argv;
|
|
38
10
|
try {
|
|
39
|
-
|
|
40
|
-
case "with-neon":
|
|
41
|
-
return await withNeon(cli, args);
|
|
42
|
-
case "dev":
|
|
43
|
-
return await dev(cli, args);
|
|
44
|
-
case "dev-setup":
|
|
45
|
-
return await devSetup(cli);
|
|
46
|
-
case "run":
|
|
47
|
-
return await runScript(cli, args);
|
|
48
|
-
case "neon":
|
|
49
|
-
if (args[0] === "seed")
|
|
50
|
-
return await neonSeed(cli);
|
|
51
|
-
if (args[0] === "reset-preview")
|
|
52
|
-
return await resetPreview(cli, args.slice(1));
|
|
53
|
-
break;
|
|
54
|
-
case "vercel-build":
|
|
55
|
-
return await vercelBuild(cli);
|
|
56
|
-
case "doctor":
|
|
57
|
-
return await doctor(cli);
|
|
58
|
-
case "user:create":
|
|
59
|
-
return await userCreate(cli, args);
|
|
60
|
-
case "user:role":
|
|
61
|
-
return await userRole(cli, args);
|
|
62
|
-
case "sync-blocks":
|
|
63
|
-
return await syncBlocksCommand(cli, args);
|
|
64
|
-
case "db:check":
|
|
65
|
-
return await dbCheck(cli);
|
|
66
|
-
case "db:generate":
|
|
67
|
-
return await dbGenerate(cli, args);
|
|
68
|
-
case "db:upgrade":
|
|
69
|
-
return await dbUpgrade(cli);
|
|
70
|
-
case "migrate-suite":
|
|
71
|
-
return await migrateSuite(cli, args);
|
|
72
|
-
}
|
|
11
|
+
return await runCommand(cli, argv);
|
|
73
12
|
}
|
|
74
13
|
catch (error) {
|
|
75
|
-
cli.error(error instanceof
|
|
76
|
-
? error.message
|
|
77
|
-
: error instanceof Error
|
|
78
|
-
? error.message
|
|
79
|
-
: String(error));
|
|
14
|
+
cli.error(error instanceof Error ? error.message : String(error));
|
|
80
15
|
return 1;
|
|
81
16
|
}
|
|
82
|
-
cli.error(USAGE);
|
|
83
|
-
return 2;
|
|
84
17
|
}
|
|
85
18
|
/**
|
|
86
19
|
* Runs a program with an argument array (never a shell), forwarding signals to an inherited child. `input` is written to the child's stdin whole, then closed.
|
package/dist/cli/neon.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type Branch = {
|
|
|
11
11
|
export declare const SEED_NEXT = "seed-next";
|
|
12
12
|
export declare function projectId(env: Env): string;
|
|
13
13
|
/**
|
|
14
|
-
* Refuses a dev branch name that is not a dev branch: production (whatever this project calls its default branch, and the name `production` itself), the shared `seed` and `preview`, and `seed-next` (the seed being built, which may briefly hold production's data). One check for every command that uses your dev branch: with-neon, dev-setup and
|
|
14
|
+
* Refuses a dev branch name that is not a dev branch: production (whatever this project calls its default branch, and the name `production` itself), the shared `seed` and `preview`, and `seed-next` (the seed being built, which may briefly hold production's data). One check for every command that uses your dev branch: with-neon, dev-setup, and a package's command through `databaseEnv`.
|
|
15
15
|
*/
|
|
16
16
|
export declare function assertDevBranchName(name: string, production: Branch): void;
|
|
17
17
|
/** `dev/<os user>` unless NEON_DEV_BRANCH names another. */
|
|
@@ -24,7 +24,7 @@ export declare function defaultBranch(branches: Branch[]): Branch;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function branchEnv(cli: Cli, branch: string, production?: Branch): Promise<Record<string, string>>;
|
|
26
26
|
/** The migrations, run against whatever database `env` names, through the direct endpoint. */
|
|
27
|
-
export declare function migrate(cli: Cli, env: Env): Promise<number>;
|
|
27
|
+
export declare function migrate(cli: Pick<Cli, "exec">, env: Env): Promise<number>;
|
|
28
28
|
/**
|
|
29
29
|
* `stack with-neon <command> [args]` — runs a local command against your Neon dev branch with no `.env`: the connection strings and production's host come from the Neon CLI on every run.
|
|
30
30
|
*
|
|
@@ -36,11 +36,11 @@ export declare function withNeon(cli: Cli, [command, ...args]: string[]): Promis
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function devBranchEnv(cli: Cli): Promise<Record<string, string>>;
|
|
38
38
|
/**
|
|
39
|
-
* The shared `preview` branch's `branchEnv`, for
|
|
39
|
+
* The shared `preview` branch's `branchEnv`, for a package's command run with `--preview` (`databaseEnv({ preview: true })`): previews hold only `db/seed.ts`'s rows, so this is how a developer changes what one holds. `--preview` names the database, so DATABASE_URL or ENV_FILE set as well is refused rather than overridden, as is a `preview` that is the default branch or answers with production's endpoint.
|
|
40
40
|
*/
|
|
41
41
|
export declare function previewBranchEnv(cli: Cli): Promise<Record<string, string>>;
|
|
42
42
|
/**
|
|
43
|
-
* `stack dev-setup` — once per developer: makes your Neon dev branch from `seed` (never from production) if it does not exist yet (`dev/<os user>`, or NEON_DEV_BRANCH) and migrates it. Safe to re-run.
|
|
43
|
+
* `stack dev-setup` — once per developer: makes your Neon dev branch from `seed` (never from production) if it does not exist yet (`dev/<os user>`, or NEON_DEV_BRANCH) and migrates it. Safe to re-run. There is no `.env` to write: `stack with-neon` reads the branch from the Neon CLI on every command.
|
|
44
44
|
*/
|
|
45
45
|
export declare function devSetup(cli: Cli): Promise<number>;
|
|
46
46
|
/**
|