@luckystack/server 0.8.2 → 0.8.4

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/CHANGELOG.md CHANGED
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.8.4] - 2026-08-17
11
+
12
+ ### Changed
13
+
14
+ - Port resolution is now `options.port > positional argv registry override >
15
+ options.defaultPort > 80`. The legacy `SERVER_PORT` environment fallback and
16
+ argv-to-environment writeback are removed. Migrate by editing
17
+ `config.ports.ts`, passing `port` / `defaultPort`, or supplying the second
18
+ positional argv.
19
+ - `@luckystack/server/parseArgv` now registers its port through the browser-safe
20
+ `@luckystack/core/config` registry, keeping consumer OAuth config and server
21
+ listen resolution aligned without environment mutation.
22
+
23
+ ### Fixed
24
+
25
+ - Declare `@luckystack/cron` as an optional peer so the auto-detected cron overlay is represented in the server package contract.
26
+ - Programmatic `options.port` can now rewrite an OAuth callback that still names
27
+ `options.defaultPort`, while explicit local router/reverse-proxy ingress ports
28
+ remain authoritative.
29
+
10
30
  ## [0.8.2] - 2026-07-27
11
31
 
12
32
  ### Fixed
package/CLAUDE.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## What this package does
6
6
 
7
- One-call server bootstrap for a LuckyStack project. Wires together a raw Node.js HTTP server, Socket.io (with optional Redis adapter), framework routes (`/api/*`, `/sync/*`, `/_health`, `/livez`, `/readyz`, `/_test/reset`, `/auth/*`, `/uploads/*`, `/csrf-token`), CSRF middleware, CORS + security headers, presence broadcasting, and dev-only hot reload. Consumer's `server.ts` shrinks to roughly twenty lines. Boots are gated by `verifyBootstrap` so missing registrations surface a single readable error instead of mid-request crashes. If devkit initialization fails, API/sync dispatch and `/readyz` all fail closed with 503.
7
+ One-call server bootstrap for a LuckyStack project. Wires together a raw Node.js HTTP server, Socket.io (with optional Redis adapter), framework routes (`/api/*`, `/sync/*`, `/_health`, `/livez`, `/readyz`, `/_test/reset`, `/auth/*`, `/uploads/*`, including `GET /auth/csrf`), CSRF middleware, CORS + security headers, presence broadcasting, and dev-only hot reload. Consumer's `server.ts` shrinks to roughly twenty lines. Boots are gated by `verifyBootstrap` so missing registrations surface a single readable error instead of mid-request crashes. If devkit initialization fails, API/sync dispatch and `/readyz` all fail closed with 503.
8
8
 
9
9
  ## When to USE this package
10
10
 
@@ -32,10 +32,10 @@ One-call server bootstrap for a LuckyStack project. Wires together a raw Node.js
32
32
  | `registerOverlayLoader(loader)` | Production-bundle seam: the server bundler (`scripts/bundleServer.mjs`) generates an entry that statically imports the overlay files and registers this loader; `bootstrapLuckyStack` then runs it INSTEAD of the runtime `.ts` folder walk (plain `node` cannot import `.ts` — ERR_UNKNOWN_FILE_EXTENSION). | -> docs/create-server.md |
33
33
  | `verifyBootstrap(requirements?)` | Pre-flight check for ProjectConfig / DeployConfig / ServicesConfig / OAuth / RuntimeMapsProvider / LocalizedNormalizer. Throws one descriptive `Error`. | -> docs/create-server.md |
34
34
  | `parseServerArgv(argv)` | Pure parser: validates positional `<bundles> [port]` and returns `{ bundles, port }`. Throws on malformed input. | -> docs/argv-parsing.md |
35
- | `applyServerArgv()` | Side-effect runner: parses `process.argv.slice(2)`, stores bundles + port, writes `process.env.SERVER_PORT` for downstream env readers. Idempotent. | -> docs/argv-parsing.md |
35
+ | `applyServerArgv()` | Side-effect runner: parses `process.argv.slice(2)`, stores bundles, and registers the port through browser-safe `@luckystack/core/config`. Idempotent. | -> docs/argv-parsing.md |
36
36
  | `getParsedBundles()` | Returns the preset list parsed by `applyServerArgv()` (empty array before first call). | -> docs/argv-parsing.md |
37
37
  | `getParsedPort()` | Returns the port parsed by `applyServerArgv()` (`null` if argv omitted it). | -> docs/argv-parsing.md |
38
- | `@luckystack/server/parseArgv` (side-effect import) | First-line import that runs `applyServerArgv()` before any module reads `process.env.SERVER_PORT` (notably `config.ts`). | -> docs/argv-parsing.md |
38
+ | `@luckystack/server/parseArgv` (side-effect import) | First-line import that runs `applyServerArgv()` before consumer `config.ts` reads the typed override registry. | -> docs/argv-parsing.md |
39
39
  | `createProdRuntimeMapsProvider(options)` | Build a `RuntimeMapsProvider` that loads generated maps in prod and delegates to devkit discovery in dev. Composed presets reject duplicate API/sync ownership, deduplicate equivalent full-registry function entries, and reject differing function implementations. Returns the provider without registering. | -> docs/runtime-maps.md |
40
40
  | `registerProdRuntimeMapsProvider(options)` | Convenience wrapper: builds the provider AND calls `registerRuntimeMapsProvider`. Most consumers want this. | -> docs/runtime-maps.md |
41
41
  | `registerCustomRoute(handler, options?)` | Append a custom HTTP route handler. `options.phase`: `'post-params'` (default, runs after body parse) or `'pre-params'` (runs before `getParams`, raw `req` stream intact — webhooks + streaming uploads). | -> /docs/ARCHITECTURE_HTTP.md |
@@ -63,7 +63,7 @@ One-call server bootstrap for a LuckyStack project. Wires together a raw Node.js
63
63
 
64
64
  ## Config keys (env vars + registerProjectConfig slots)
65
65
 
66
- - Port precedence — `options.port` → positional argv → `options.defaultPort` (the scaffold passes `config.ports.backend`) → legacy `SERVER_PORT` → `80`. Inputs must be integer ports in `0..65535`. After bind, `httpServer.address().port` is authoritative (including `listen(0)`). In dev, that port is advertised to `node_modules/.luckystack/dev-server.json`; cleanup removes it only when the exiting PID still owns it. The Vite proxy follows the advertisement for HTTP + WebSocket requests.
66
+ - Port precedence — `options.port` → positional argv registry override → `options.defaultPort` (the scaffold passes `config.ports.backend`) → `80`. Inputs must be integer ports in `0..65535`. After bind, `httpServer.address().port` is authoritative (including `listen(0)`). In dev, that port is advertised to `node_modules/.luckystack/dev-server.json`; cleanup removes it only when the exiting PID still owns it. The Vite proxy follows the advertisement for HTTP + WebSocket requests.
67
67
  - `SERVER_IP` (env, optional, default `127.0.0.1`) — bind address fallback when `options.ip` is omitted.
68
68
  - `NODE_ENV` (env, required for security-sensitive branches) — `development` / `test` toggle devkit hot reload + REPL and gate `/_test/reset`.
69
69
  - `TEST_RESET_TOKEN` (env, required for `/_test/reset` to be reachable at all) — must match the `x-test-reset-token` request header. No fallback "no auth" mode.
@@ -77,8 +77,8 @@ One-call server bootstrap for a LuckyStack project. Wires together a raw Node.js
77
77
  ## Peer dependencies
78
78
 
79
79
  - **Required (runtime deps)**: `@luckystack/api`, `@luckystack/core`.
80
- - **Peer (canonical ranges)**: `@prisma/client@^6.19.0` (transitive via core), `socket.io@^4.8.0`.
81
- - **Optional (all auto-detected by `bootstrapLuckyStack`; the server degrades gracefully when absent — `auth.disabled` / `sync.disabled`, presence skipped)**: `@luckystack/login`, `@luckystack/presence`, `@luckystack/sync`, `@luckystack/error-tracking`, `@luckystack/email`, `@luckystack/cron`, `@luckystack/docs-ui`, `@luckystack/devkit` (dev-only, dynamically imported by the `enableDevTools` branch).
80
+ - **Required peer**: `socket.io@^4.8.0`.
81
+ - **Optional (all auto-detected by `bootstrapLuckyStack`; the server degrades gracefully when absent — `auth.disabled` / `sync.disabled`, presence skipped)**: `@prisma/client@^6.19.0`, `@luckystack/login`, `@luckystack/presence`, `@luckystack/sync`, `@luckystack/error-tracking`, `@luckystack/email`, `@luckystack/cron`, `@luckystack/docs-ui`, `@luckystack/devkit` (dev-only, dynamically imported by the `enableDevTools` branch).
82
82
  - **0.2.0 install-anything-anytime**: `bootstrapLuckyStack` runs an auto-detect phase BEFORE the consumer overlay that imports each installed optional package's `@luckystack/<pkg>/register` side-effect subpath (`OPTIONAL_PACKAGES` in `capabilities.ts` = `login, email, error-tracking, presence, cron, docs-ui`). So `npm i @luckystack/<pkg>` + env + restart self-wires the BACKEND with zero code edits. Detection uses `import.meta.resolve` (the `@luckystack/*` exports maps are import-only — a CJS `require.resolve` reports them absent). Client-side mounts (presence JSX, login pages) need `npx luckystack add <feature>` (`@luckystack/cli`) because Vite can't statically import an uninstalled package and file-routing only scans `src/`.
83
83
 
84
84
  ## Related
package/README.md CHANGED
@@ -5,7 +5,11 @@
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install @luckystack/server @luckystack/core @luckystack/api @luckystack/login @luckystack/sync @luckystack/presence socket.io
8
+ npm install @luckystack/server socket.io
9
+
10
+ # Add the features your project uses; the server auto-detects these optional peers.
11
+ # For the standard API + realtime stack, for example:
12
+ npm install @luckystack/api @luckystack/sync
9
13
  ```
10
14
 
11
15
  ## Quickstart — recommended (`bootstrapLuckyStack`)
@@ -31,7 +35,7 @@ await server.listen();
31
35
 
32
36
  The bootstrap call runs (in order):
33
37
 
34
- 1. Auto-imports `luckystack/core/*.ts`, `luckystack/deploy/*.ts`, `luckystack/login/*.ts`, `luckystack/sentry/*.ts`, `luckystack/presence/*.ts`, `luckystack/docs-ui/*.ts`, `luckystack/server/*.ts` (topologically sorted, then alphabetically inside each folder).
38
+ 1. Auto-imports `luckystack/core/*.ts`, `luckystack/deploy/*.ts`, `luckystack/login/*.ts`, `luckystack/email/*.ts`, `luckystack/sentry/*.ts`, `luckystack/presence/*.ts`, `luckystack/cron/*.ts`, `luckystack/docs-ui/*.ts`, `luckystack/server/*.ts` (topologically sorted, then alphabetically inside each folder).
35
39
  2. Hands off to `createLuckyStackServer(options)`.
36
40
 
37
41
  Set `skipOverlayLoad: true` to handle every registration yourself, or `overlayRoot: 'custom-folder'` to load from somewhere other than `./luckystack`.
@@ -88,7 +92,8 @@ Both entries handle devkit hot reload + console init in dev mode automatically
88
92
 
89
93
  ```ts
90
94
  interface CreateLuckyStackServerOptions {
91
- port?: number | string; // default: process.env.SERVER_PORT ?? 80
95
+ port?: number | string; // options.port > argv > defaultPort > 80
96
+ defaultPort?: number; // scaffold's config.ports.ts backend default
92
97
  ip?: string; // default: process.env.SERVER_IP ?? '127.0.0.1'
93
98
  serveFile?: StaticFileHandler; // catch-all for non-framework GETs (Vite output, SPA fallback)
94
99
  serveFavicon?: FaviconHandler; // /favicon.ico
@@ -117,7 +122,7 @@ registerCustomRoute(async (req, res) => {
117
122
 
118
123
  - **HTTP server** with CORS + security headers, OPTIONS preflight, method validation, cookie sliding, CSRF middleware.
119
124
  - **Socket.io server** attached to the HTTP server, with optional Redis adapter when configured in deploy config.
120
- - **Framework routes:** `/_health`, `/livez`, `/readyz`, `/_test/reset` (dev/test only), `/api/*` and `/sync/*` (with SSE streaming), `/auth/api`, `/auth/callback/*`, `/uploads/*`, `/assets/*`, `/csrf-token`.
125
+ - **Framework routes:** `/_health`, `/livez`, `/readyz`, `/_test/reset` (dev/test only), `/api/*` and `/sync/*` (with SSE streaming), `/auth/api`, `/auth/callback/*`, `GET /auth/csrf`, `/uploads/*`, and `/assets/*`.
121
126
  - **Presence broadcasting** (when enabled in project config): connect / disconnect / reconnect, location updates, peer notifications.
122
127
  - **Boot UUID** written on startup so the load-balancer (`@luckystack/router`) can detect rolling restarts.
123
128
  - **Dev tools** in non-production: devkit hot reload, console initializer.
@@ -128,7 +133,7 @@ registerCustomRoute(async (req, res) => {
128
133
 
129
134
  | File | Routes |
130
135
  | --- | --- |
131
- | `csrfMiddleware.ts` + `csrfRoute.ts` | CSRF guard on writes + `GET /csrf-token` |
136
+ | `csrfMiddleware.ts` + `csrfRoute.ts` | CSRF guard on cookie-mode writes + `GET /auth/csrf` token issue |
132
137
  | `healthRoutes.ts` | `/livez`, `/readyz`, `/_health` |
133
138
  | `testResetRoute.ts` | `/_test/reset` (dev/test only — see Security below) |
134
139
  | `faviconRoute.ts` | `/favicon.ico` |
@@ -146,7 +151,7 @@ Top-level `handleHttpRequest` + `dispatchRoutes(handlers, ctx)` are the only orc
146
151
 
147
152
  - **CORS fail-closed.** If neither `Origin` nor `Referer` is present, only read-only methods (GET, HEAD, OPTIONS) are allowed; state-changing methods are rejected with 403. Earlier builds fell back to `Host`, which silently bypassed CORS for non-browser callers (`curl`, server-to-server). When you `curl` a write endpoint, set `-H 'Origin: https://your-allowed-origin'`.
148
153
  - **`/_test/reset` is fail-closed.** It requires both `NODE_ENV` to be exactly `development` or `test` AND a non-empty `TEST_RESET_TOKEN` env var. Any other state returns 403 (no silent allow-list). Wire `TEST_RESET_TOKEN` in your dev/test `.env.local` and pass it as the `x-test-reset-token: ${TOKEN}` header on the reset call. `@luckystack/test-runner`'s `resetServerState` reads the same env var.
149
- - **CSRF middleware.** Writes to `/api/*` and `/sync/*` require an `x-csrf-token` header that matches the value minted on the session record (mirrored via `GET /auth/csrf`). The `apiRequest` helper in `@luckystack/core/client` attaches it automatically. Rejections dispatch the `csrfMismatch` hook before returning 403; the payload contains presence-only token info, never the value. The header name, token length, and cookie options are customisable via `registerCsrfConfig({ headerName, tokenLength, cookieOptions })` from `@luckystack/core` — see `packages/core/docs/csrf-config.md`.
154
+ - **CSRF middleware.** In cookie mode, state-changing framework routes and eligible custom routes require the configured CSRF header (default `x-csrf-token`). With login installed it must match the session-bound token; without login it must match the stateless double-submit cookie issued by `GET /auth/csrf`. The `apiRequest` helper in `@luckystack/core/client` fetches and attaches it automatically. Auth bootstrap/callback routes and explicitly origin-exempt paths are excluded. Rejections dispatch `csrfMismatch` before returning 403; the hook receives token presence only, never the value. Configure the header name, token length, and cookie name/options through `registerCsrfConfig(...)` — see `packages/core/docs/csrf-config.md` and `packages/server/docs/security-defaults.md`.
150
155
 
151
156
  ## Public API
152
157
 
@@ -161,15 +166,13 @@ Top-level `handleHttpRequest` + `dispatchRoutes(handlers, ctx)` are the only orc
161
166
 
162
167
  ## Dependencies
163
168
 
164
- - Runtime: `@luckystack/api`, `@luckystack/core`, `@luckystack/login`, `@luckystack/presence`, `@luckystack/sync`
165
- - Peer (canonical ranges, standardized 2026-05-07):
166
- - `@prisma/client@^6.19.0` (transitively required via `@luckystack/core`)
167
- - `socket.io@^4.8.0`
168
- - Optional peer: `@luckystack/error-tracking`, `@luckystack/email`, `@luckystack/docs-ui` — bootstrap auto-detects them but does not require them.
169
+ - Runtime: `@luckystack/api`, `@luckystack/core`
170
+ - Required peer: `socket.io@^4.8.0`
171
+ - Optional peers: `@prisma/client@^6.19.0`, `@luckystack/login`, `@luckystack/presence`, `@luckystack/sync`, `@luckystack/error-tracking`, `@luckystack/email`, `@luckystack/cron`, `@luckystack/docs-ui`, and `@luckystack/devkit` (dev-only). Bootstrap auto-detects installed optional peers and degrades when they are absent.
169
172
 
170
173
  ## Selecting bundles + port at runtime
171
174
 
172
- `@luckystack/server/parseArgv` is a side-effect-only entrypoint. Import it as the **first line** of your `server.ts` so positional CLI args are parsed before any module that reads `process.env.SERVER_PORT` at load time (notably your project's `config.ts`).
175
+ `@luckystack/server/parseArgv` is a side-effect-only entrypoint. Import it as the **first line** of your `server.ts` so a positional CLI port reaches the browser-safe `@luckystack/core/config` registry before your project's `config.ts` evaluates.
173
176
 
174
177
  ```ts
175
178
  // server.ts
@@ -177,11 +180,13 @@ import '@luckystack/server/parseArgv';
177
180
  // ...rest of your bootstrap
178
181
  ```
179
182
 
180
- Argv shape: `<bundle[,bundle...]> [port]`
183
+ Argv shape: `<bundle[,bundle...]> [port]`. The positional port overrides the
184
+ scaffold's `defaultPort: ports.backend`. Generic boots with no explicit,
185
+ positional, or default port retain the numeric fallback `80`.
181
186
 
182
187
  ```bash
183
- npm run server # default preset, port 80
184
- npm run server -- billing # one bundle, port 80
188
+ npm run server # default preset, config.ports.ts backend
189
+ npm run server -- billing # one bundle, config.ports.ts backend
185
190
  npm run server -- billing,vehicles 4001 # merge bundles, listen on 4001
186
191
  ```
187
192
 
@@ -1,3 +1,6 @@
1
+ // src/argv.ts
2
+ import { getPortOverride, registerPortOverride } from "@luckystack/core/config";
3
+
1
4
  // src/portResolution.ts
2
5
  var normalizeServerPort = (value, source = "server port") => {
3
6
  let normalized;
@@ -12,20 +15,17 @@ var normalizeServerPort = (value, source = "server port") => {
12
15
  };
13
16
  var resolveServerPort = ({
14
17
  optionsPort,
15
- parsedPort: parsedPort2,
16
- defaultPort,
17
- envPort
18
+ parsedPort,
19
+ defaultPort
18
20
  }) => {
19
21
  if (optionsPort !== void 0) return normalizeServerPort(optionsPort, "options.port");
20
- if (parsedPort2 !== void 0 && parsedPort2 !== null) return normalizeServerPort(parsedPort2, "argv port");
22
+ if (parsedPort !== void 0 && parsedPort !== null) return normalizeServerPort(parsedPort, "argv port");
21
23
  if (defaultPort !== void 0) return normalizeServerPort(defaultPort, "options.defaultPort");
22
- if (envPort !== void 0) return normalizeServerPort(envPort, "SERVER_PORT");
23
24
  return 80;
24
25
  };
25
26
 
26
27
  // src/argv.ts
27
28
  var parsedBundles = [];
28
- var parsedPort = null;
29
29
  var hasRun = false;
30
30
  var PORT_PATTERN = /^\d+$/;
31
31
  var parseServerArgv = (argv) => {
@@ -52,13 +52,10 @@ var applyServerArgv = () => {
52
52
  hasRun = true;
53
53
  const result = parseServerArgv(process.argv.slice(2));
54
54
  parsedBundles = result.bundles;
55
- parsedPort = result.port;
56
- if (parsedPort !== null) {
57
- process.env.SERVER_PORT = String(parsedPort);
58
- }
55
+ registerPortOverride(result.port);
59
56
  };
60
57
  var getParsedBundles = () => parsedBundles;
61
- var getParsedPort = () => parsedPort;
58
+ var getParsedPort = () => getPortOverride() ?? null;
62
59
 
63
60
  export {
64
61
  normalizeServerPort,
@@ -68,4 +65,4 @@ export {
68
65
  getParsedBundles,
69
66
  getParsedPort
70
67
  };
71
- //# sourceMappingURL=chunk-QLVQ75QL.js.map
68
+ //# sourceMappingURL=chunk-HJXOI6LY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/argv.ts","../src/portResolution.ts"],"sourcesContent":["//? Positional argv parser for the LuckyStack server boot. Replaces legacy\n//? environment toggles with a single shape:\n//?\n//? npm run server -- billing,vehicles 4001\n//?\n//? Arg 0 = comma-separated preset list (runtime maps merged across them).\n//? Arg 1 = listen port (numeric).\n//?\n//? `applyServerArgv()` is called by the side-effect module\n//? `@luckystack/server/parseArgv`, which consumers import as the FIRST line\n//? of their `server.ts` so the parsed port lands in the browser-safe core/config\n//? registry before `config.ts` evaluates its top-level OAuth callback base.\n\nimport { getPortOverride, registerPortOverride } from '@luckystack/core/config';\nimport { normalizeServerPort } from './portResolution';\n\nexport interface ParsedServerArgv {\n bundles: string[];\n port: number | null;\n}\n\nlet parsedBundles: string[] = [];\nlet hasRun = false;\n\nconst PORT_PATTERN = /^\\d+$/;\n\nexport const parseServerArgv = (argv: string[]): ParsedServerArgv => {\n if (argv.length > 2) {\n throw new Error(\n `[luckystack:argv] unexpected positional argument(s): \"${argv.slice(2).join(' ')}\". ` +\n `Usage: npm run server -- <bundle[,bundle...]> [port]`,\n );\n }\n\n const bundles = argv[0] && argv[0].length > 0\n ? [...new Set(argv[0].split(',').map((s) => s.trim()).filter(Boolean))]\n : [];\n\n let port: number | null = null;\n const portArg = argv[1];\n if (portArg !== undefined) {\n if (!PORT_PATTERN.test(portArg)) {\n throw new Error(\n `[luckystack:argv] port argument must be numeric, got: \"${portArg}\". ` +\n `Usage: npm run server -- <bundle[,bundle...]> [port]`,\n );\n }\n port = normalizeServerPort(portArg, 'port argument');\n }\n\n return { bundles, port };\n};\n\nexport const applyServerArgv = (): void => {\n if (hasRun) return;\n hasRun = true;\n\n const result = parseServerArgv(process.argv.slice(2));\n parsedBundles = result.bundles;\n registerPortOverride(result.port);\n};\n\nexport const getParsedBundles = (): string[] => parsedBundles;\nexport const getParsedPort = (): number | null => getPortOverride() ?? null;\n","export interface ResolveServerPortInput {\n optionsPort?: number | string;\n parsedPort?: number | null;\n defaultPort?: number | string;\n}\n\nexport const normalizeServerPort = (\n value: number | string,\n source = 'server port',\n): number => {\n let normalized: number;\n if (typeof value === 'number') normalized = value;\n else normalized = /^\\d+$/.test(value) ? Number(value) : Number.NaN;\n\n if (!Number.isInteger(normalized) || normalized < 0 || normalized > 65_535) {\n throw new RangeError(\n `[luckystack:port] ${source} must be an integer from 0 through 65535, got: \"${String(value)}\".`,\n );\n }\n\n return normalized;\n};\n\n//? One explicit, testable precedence chain. The scaffold passes ports.backend as\n//? `defaultPort`; generic consumers that omit every source retain port 80.\nexport const resolveServerPort = ({\n optionsPort,\n parsedPort,\n defaultPort,\n}: ResolveServerPortInput): number => {\n if (optionsPort !== undefined) return normalizeServerPort(optionsPort, 'options.port');\n if (parsedPort !== undefined && parsedPort !== null) return normalizeServerPort(parsedPort, 'argv port');\n if (defaultPort !== undefined) return normalizeServerPort(defaultPort, 'options.defaultPort');\n return 80;\n};\n"],"mappings":";AAaA,SAAS,iBAAiB,4BAA4B;;;ACP/C,IAAM,sBAAsB,CACjC,OACA,SAAS,kBACE;AACX,MAAI;AACJ,MAAI,OAAO,UAAU,SAAU,cAAa;AAAA,MACvC,cAAa,QAAQ,KAAK,KAAK,IAAI,OAAO,KAAK,IAAI,OAAO;AAE/D,MAAI,CAAC,OAAO,UAAU,UAAU,KAAK,aAAa,KAAK,aAAa,OAAQ;AAC1E,UAAM,IAAI;AAAA,MACR,qBAAqB,MAAM,mDAAmD,OAAO,KAAK,CAAC;AAAA,IAC7F;AAAA,EACF;AAEA,SAAO;AACT;AAIO,IAAM,oBAAoB,CAAC;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,MAAsC;AACpC,MAAI,gBAAgB,OAAW,QAAO,oBAAoB,aAAa,cAAc;AACrF,MAAI,eAAe,UAAa,eAAe,KAAM,QAAO,oBAAoB,YAAY,WAAW;AACvG,MAAI,gBAAgB,OAAW,QAAO,oBAAoB,aAAa,qBAAqB;AAC5F,SAAO;AACT;;;ADbA,IAAI,gBAA0B,CAAC;AAC/B,IAAI,SAAS;AAEb,IAAM,eAAe;AAEd,IAAM,kBAAkB,CAAC,SAAqC;AACnE,MAAI,KAAK,SAAS,GAAG;AACnB,UAAM,IAAI;AAAA,MACR,yDAAyD,KAAK,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAAA,IAElF;AAAA,EACF;AAEA,QAAM,UAAU,KAAK,CAAC,KAAK,KAAK,CAAC,EAAE,SAAS,IACxC,CAAC,GAAG,IAAI,IAAI,KAAK,CAAC,EAAE,MAAM,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,OAAO,CAAC,CAAC,IACpE,CAAC;AAEL,MAAI,OAAsB;AAC1B,QAAM,UAAU,KAAK,CAAC;AACtB,MAAI,YAAY,QAAW;AACzB,QAAI,CAAC,aAAa,KAAK,OAAO,GAAG;AAC/B,YAAM,IAAI;AAAA,QACR,0DAA0D,OAAO;AAAA,MAEnE;AAAA,IACF;AACA,WAAO,oBAAoB,SAAS,eAAe;AAAA,EACrD;AAEA,SAAO,EAAE,SAAS,KAAK;AACzB;AAEO,IAAM,kBAAkB,MAAY;AACzC,MAAI,OAAQ;AACZ,WAAS;AAET,QAAM,SAAS,gBAAgB,QAAQ,KAAK,MAAM,CAAC,CAAC;AACpD,kBAAgB,OAAO;AACvB,uBAAqB,OAAO,IAAI;AAClC;AAEO,IAAM,mBAAmB,MAAgB;AACzC,IAAM,gBAAgB,MAAqB,gBAAgB,KAAK;","names":[]}
package/dist/index.d.ts CHANGED
@@ -84,16 +84,14 @@ interface CreateLuckyStackServerOptions {
84
84
  * by `@luckystack/server/parseArgv`
85
85
  * 3. `options.defaultPort` (the project's single-instance default, e.g. the
86
86
  * `backend` port from `config.ports.ts`)
87
- * 4. `process.env.SERVER_PORT` (back-compat for boots that skip `parseArgv`)
88
- * 5. `80`
87
+ * 4. `80` for generic consumers that supplied no port source
89
88
  */
90
89
  port?: number | string;
91
90
  /**
92
91
  * Project's single-instance default backend port. Sits BELOW positional argv
93
- * so a multi-instance boot (`npm run server -- <preset> <port>`) still wins,
94
- * but ABOVE the legacy `SERVER_PORT` env. The scaffold passes the `backend`
95
- * value from `config.ports.ts` here, so the listen port has ONE source of
96
- * truth without re-introducing `SERVER_PORT` to `.env`.
92
+ * so a multi-instance boot (`npm run server -- <preset> <port>`) still wins.
93
+ * The scaffold passes the `backend` value from `config.ports.ts` here, so the
94
+ * listen port has one static source of truth.
97
95
  */
98
96
  defaultPort?: number;
99
97
  /** Bind address. Defaults to process.env.SERVER_IP or '127.0.0.1'. */
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  normalizeServerPort,
6
6
  parseServerArgv,
7
7
  resolveServerPort
8
- } from "./chunk-QLVQ75QL.js";
8
+ } from "./chunk-HJXOI6LY.js";
9
9
 
10
10
  // src/createServer.ts
11
11
  import http from "http";
@@ -2326,7 +2326,7 @@ var writeDevServerInfo = (ip, port) => {
2326
2326
  `);
2327
2327
  } catch (error) {
2328
2328
  getLogger12().debug(
2329
- `[dev-server-info] could not write port file (proxy will fall back to SERVER_PORT): ${error instanceof Error ? error.message : String(error)}`
2329
+ `[dev-server-info] could not write port file (proxy will fall back to config.ports.ts): ${error instanceof Error ? error.message : String(error)}`
2330
2330
  );
2331
2331
  }
2332
2332
  };
@@ -2411,7 +2411,7 @@ var listenLuckyStackServer = (httpServer, ip, port, callback) => new Promise((re
2411
2411
  return;
2412
2412
  }
2413
2413
  getLogger13().error(
2414
- `Port ${String(attemptPort)} is already in use \u2014 the server did NOT start. Another \`npm run server\` is probably still running (stop it), or set SERVER_PORT to a free port, or set SERVER_PORT_AUTO_INCREMENT=1 to auto-pick the next free port.`
2414
+ `Port ${String(attemptPort)} is already in use \u2014 the server did NOT start. Another \`npm run server\` is probably still running (stop it), or choose a free port in config.ports.ts / positional argv, or set SERVER_PORT_AUTO_INCREMENT=1 to auto-pick the next free port.`
2415
2415
  );
2416
2416
  reject(err);
2417
2417
  };
@@ -2462,12 +2462,11 @@ var createLuckyStackServer = async (options = {}) => {
2462
2462
  const port = resolveServerPort({
2463
2463
  optionsPort: options.port,
2464
2464
  parsedPort: getParsedPort(),
2465
- defaultPort: options.defaultPort,
2466
- envPort: process.env.SERVER_PORT
2465
+ defaultPort: options.defaultPort
2467
2466
  });
2468
2467
  const ip = options.ip ?? process.env.SERVER_IP ?? "127.0.0.1";
2469
2468
  const enableDevTools = options.enableDevTools ?? resolveRuntimeMode() !== "production";
2470
- registerBindAddress({ ip, port });
2469
+ registerBindAddress({ ip, port, configuredPort: options.defaultPort });
2471
2470
  if (enableDevTools) {
2472
2471
  await initDevTools();
2473
2472
  }