@thoughtpivot/flight 2.0.1 → 3.0.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/CHANGELOG.md +41 -0
- package/README.md +182 -18
- package/dist/backend-discovery.js +61 -0
- package/dist/flight.js +8 -47
- package/dist/spa-pipeline.js +22 -4
- package/package.json +20 -10
- package/src/bun/app.test.ts +191 -0
- package/src/bun/app.ts +140 -0
- package/src/bun/backends.ts +93 -0
- package/src/bun/cache.ts +56 -0
- package/src/bun/config.ts +163 -0
- package/src/bun/koa-compat.ts +166 -0
- package/src/bun/middleware.ts +217 -0
- package/src/bun/server.ts +16 -0
- package/src/bun/session.ts +120 -0
- package/src/bun/static.ts +72 -0
- package/src/bun/store.ts +128 -0
- package/src/flight.ts +6 -47
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- **Vite 8** toolchain: `vite` `^8.3.2`, `@vitejs/plugin-react` `^6.1.1`, `@vitejs/plugin-vue` `^6.0.9`, and `vite-plugin-vuetify` `^2.1.3`. `@vitejs/plugin-react` 6 requires Vite 8 (`vite/internal`). Apps that still pin Vite 6 should stay on `@thoughtpivot/flight@2.0.2` until they upgrade.
|
|
8
|
+
- **`ioredis` 6**: requires Node.js 20+ and uses **RESP3** by default. Set `protocol: 2` on the Redis client if a server still needs the ioredis v5 wire protocol.
|
|
9
|
+
- **Node engines**: `^20.19.0 || >=22.12.0` (aligned with Vite 8 / ioredis 6).
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Bun runtime** (`src/bun`, `flight-bun` / `bun src/bun/server.ts`): `Bun.serve`, `/healthz`, and the same middleware jobs (logging, security headers, CORS, gzip, rate limit, sessions, response cache) on the native Bun path.
|
|
14
|
+
- **Koa compatibility on that runtime.** A `*.backend.ts` file may still `export default router.routes()`. Those backends are mounted through Koa and `koa-bodyparser`. Compiled `*.backend.js` files are discovered too.
|
|
15
|
+
- **`FLIGHT_TRUST_PROXY` on the Bun rate limiter.** `X-Forwarded-For` is ignored unless the proxy is trusted.
|
|
16
|
+
- **`@vitejs/plugin-react`** as a dependency (alongside `@vitejs/plugin-vue`) so React + Vite apps get the same style of transitive plugin coverage as Vue apps.
|
|
17
|
+
- Broader Node test coverage for SPA fallback, env flags, rate-limit skips, and backend exclude paths. `npm test` runs every compiled `dist/*.test.js` file.
|
|
18
|
+
- GitHub Actions **CI** (`.github/workflows/ci.yml`) and **npm publish** (`.github/workflows/publish.yml`) with provenance. CircleCI is retired.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Dependency majors also include `koa-helmet` 9 and `koa-ratelimit` 6.
|
|
23
|
+
- SPA index paths with `..` stay inside the dist root; exclude paths named `..foo` stay inside `app_home`; `.` / app-root excludes warn instead of ignoring everything.
|
|
24
|
+
|
|
25
|
+
### Notes
|
|
26
|
+
|
|
27
|
+
- The Node / Koa `flight` binary is unchanged in role. Sessions on Bun stay off until `FLIGHT_SESSION_SECRET` is set. Rate limiting on Bun stays off until `FLIGHT_RATE_LIMIT_MAX` is greater than zero.
|
|
28
|
+
- Git changelog entry **2.1.0** below was prepared in-repo but never published to npm; its React + Vite docs/plugin work ships in this 3.0.0 release together with the Vite 8 upgrade.
|
|
29
|
+
|
|
30
|
+
## 2.1.0
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- **`@vitejs/plugin-react`** as a **dependency** (alongside **`@vitejs/plugin-vue`**), so React + Vite apps that depend on `@thoughtpivot/flight` get the same style of transitive Vite plugin coverage as Vue apps. Install **`react`**, **`react-dom`**, and (for TypeScript) **`@types/react`** / **`@types/react-dom`** in your application; Flight remains the server/runtime, not the UI runtime.
|
|
35
|
+
|
|
36
|
+
### Documentation
|
|
37
|
+
|
|
38
|
+
- README: **React + Vite** quick path (sample `vite.config`, `index.html`, `main.tsx`, `App.tsx`), highlights updated for Vue and React, and clarification that **Flight does not pick Vue vs React**—your **`vite.config`** does.
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- Development log lines refer to the **Vite** dev server generically (Vue/React per app config).
|
|
43
|
+
|
|
3
44
|
## 2.0.0
|
|
4
45
|
|
|
5
46
|
### Breaking
|
package/README.md
CHANGED
|
@@ -4,17 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
# Flight
|
|
6
6
|
|
|
7
|
-
**Flight** is
|
|
7
|
+
**Flight** is an application server for teams who want something **fast**, **boring in the good way**, and **ready for serious traffic**. You bring your own hosting—there is no lock-in to a proprietary edge or a single vendor’s deployment story. It fits **twelve-factor** style workflows: configuration via environment variables, horizontal scaling, and state kept where it belongs (for Flight, that includes **Redis** for sessions and cache-friendly layers).
|
|
8
8
|
|
|
9
|
-
Think **platform-agnostic**: not framework-as-a-platform, but a clear runtime you can run wherever Node runs—VMs, Kubernetes, bare metal, your cloud of choice. Flight is aimed at **hyperscale-friendly** designs (cluster workers
|
|
9
|
+
Think **platform-agnostic**: not framework-as-a-platform, but a clear runtime you can run wherever **Node** or **Bun** runs—VMs, Kubernetes, bare metal, your cloud of choice. The `flight` binary is the Node / Koa server. `flight-bun` is the Bun server (`Bun.serve`), and it can still mount existing Koa `router.routes()` backends while you move routes over. Flight is aimed at **hyperscale-friendly** designs (cluster workers on Node, a single Bun process with native TypeScript on the Bun path), **ephemeral** processes, and **component-shaped** backends so routes stay colocated with the features they serve. **Vue** and **React** are both supported through the same **Vite** dev and production flows (your app’s **`vite.config`** chooses the UI stack; Flight does not).
|
|
10
10
|
|
|
11
11
|
Flight is **open source** from **[ThoughtPivot](https://github.com/thoughtpivot)**.
|
|
12
12
|
|
|
13
13
|
## Highlights
|
|
14
14
|
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
15
|
+
- **Two runtimes**: **Node / Koa** (`flight`) and **Bun** (`flight-bun`). The Bun server loads TypeScript directly, exposes `GET /healthz`, and still accepts existing Koa backends
|
|
16
|
+
- **Performance-focused**: Cluster mode on Node, compression, Redis-backed caching hooks, rate limiting in production
|
|
17
|
+
- **Developer velocity**: **Vite** dev server with HMR on port **3001** for **Vue** or **React** (per your project’s Vite config)
|
|
18
|
+
- **Composable backends**: Discover `**/*.backend.ts` (and `**/*.backend.js` on Bun) under your app root and mount them per component
|
|
18
19
|
- **Production SPA**: Built-in **`dist` + `index.html`** fallback (option B) when running **`production`** with **`disable_vite`**, with an explicit opt-out for API-only processes
|
|
19
20
|
- **Configurable discovery**: `--exclude_paths` / `FLIGHT_EXCLUDE_PATHS` to skip directories when scanning backends
|
|
20
21
|
- **TypeScript-native**: Written for TS projects; sensible defaults, minimal ceremony
|
|
@@ -50,6 +51,8 @@ npm init -y
|
|
|
50
51
|
npm install @thoughtpivot/flight ioredis
|
|
51
52
|
```
|
|
52
53
|
|
|
54
|
+
For a **React** UI, also install `react`, `react-dom`, and (with TypeScript) `@types/react` / `@types/react-dom` as dev dependencies. For **Vue**, install `vue` and wire **`@vitejs/plugin-vue`** in **`vite.config`**.
|
|
55
|
+
|
|
53
56
|
3. Ensure Redis is running locally or set environment variables (see table below).
|
|
54
57
|
|
|
55
58
|
4. Create a component with a backend route:
|
|
@@ -103,24 +106,42 @@ npx flight --mode production
|
|
|
103
106
|
|
|
104
107
|
**`--app_home`** defaults to **`.`** (the current working directory). Pass **`--app_home path/to/app`** only when your app root is not the directory you run the command from.
|
|
105
108
|
|
|
106
|
-
**Try without adding a dependency** (downloads the package for this invocation):
|
|
109
|
+
**Try without adding a dependency** (downloads the package for this invocation). Use **`--package=@scope/pkg`** (equals form) and a literal **`--`** before the binary name so `npx` does not treat `flight` as a separate package or lose the install’s **`node_modules/.bin`** on your `PATH` (otherwise you can see `sh: flight: command not found`):
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
npx --yes --package=@thoughtpivot/flight -- flight --mode development
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Equivalent:
|
|
107
116
|
|
|
108
117
|
```bash
|
|
109
|
-
|
|
118
|
+
npm exec --yes --package=@thoughtpivot/flight -- flight --mode development
|
|
110
119
|
```
|
|
111
120
|
|
|
112
121
|
**Global install** (optional): `npm install -g @thoughtpivot/flight`, then run **`flight`** from your PATH the same way as **`npx flight`**.
|
|
113
122
|
|
|
123
|
+
**Bun** (same app directory, [Bun](https://bun.sh) 1.x on your PATH):
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# development: API on :3000, Vite on :3001
|
|
127
|
+
FLIGHT_MODE=development flight-bun
|
|
128
|
+
|
|
129
|
+
# production: serve dist/ plus backends
|
|
130
|
+
FLIGHT_MODE=production flight-bun
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
From a clone of this repo, before the package is published, that is `bun src/bun/server.ts`. Existing `export default router.routes()` files keep working. New files can export a Web `Request` / `Response` route map. Details, env vars, and the backend contract are in [Bun runtime](#bun-runtime).
|
|
134
|
+
|
|
114
135
|
## Development vs production
|
|
115
136
|
|
|
116
|
-
|
|
137
|
+
The Node server picks **`mode`** as: **`FLIGHT_MODE`** (if set and non-empty), else **`--mode`** from argv, else **`production`**. The table below is that Node / Koa process. It assumes Redis is reachable unless you only use routes that avoid session, rate limit, and cache. The Bun server is documented in [Bun runtime](#bun-runtime).
|
|
117
138
|
|
|
118
|
-
| Topic | Development
|
|
119
|
-
| ---------------- |
|
|
120
|
-
| **Vite** | Child process: `npx vite --port 3001 --host 0.0.0.0` (HMR).
|
|
121
|
-
| **Listen port** | API + sessions on **`--port`** / `FLIGHT_PORT` (default **3000**). UI dev server on **3001**.
|
|
122
|
-
| **Static / SPA** | The Vite dev server serves UI; Flight does **not** mount the production static/SPA stack.
|
|
123
|
-
| **Typical use** | Local full-stack with HMR.
|
|
139
|
+
| Topic | Development | Production |
|
|
140
|
+
| ---------------- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
141
|
+
| **Vite** | Child process: `npx vite --port 3001 --host 0.0.0.0` (HMR for **Vue or React**, per your `vite.config`). | If **`disable_vite` is false**: `exec('npx vite build')` is triggered once at worker startup. If **`disable_vite` is true**: no Vite build. |
|
|
142
|
+
| **Listen port** | API + sessions on **`--port`** / `FLIGHT_PORT` (default **3000**). UI dev server on **3001**. | Same **`--port`** / `FLIGHT_PORT` for the worker. |
|
|
143
|
+
| **Static / SPA** | The Vite dev server serves UI; Flight does **not** mount the production static/SPA stack. | See **Production SPA pipeline** below: when **`production`** + **`disable_vite`**, Flight uses **Option A** by default unless opted out. |
|
|
144
|
+
| **Typical use** | Local full-stack with HMR. | CI-built `dist` served by Flight (or behind a load balancer). |
|
|
124
145
|
|
|
125
146
|
**Edge cases**
|
|
126
147
|
|
|
@@ -163,6 +184,8 @@ Flight loads a **`.env`** file from the **current working directory** at startup
|
|
|
163
184
|
| _(n/a)_ | `FLIGHT_REDIS_PORT` | `6379` | Redis port. |
|
|
164
185
|
| _(n/a)_ | `FLIGHT_MAX_WORKERS` | CPU count | Cap cluster worker count on small nodes. |
|
|
165
186
|
|
|
187
|
+
`1`, `true`, and `yes` are matched exactly. `TRUE` does not turn those settings on.
|
|
188
|
+
|
|
166
189
|
Example `.env` fragment:
|
|
167
190
|
|
|
168
191
|
```bash
|
|
@@ -227,9 +250,72 @@ router.get('/hello', async (ctx) => {
|
|
|
227
250
|
export default router.routes()
|
|
228
251
|
```
|
|
229
252
|
|
|
253
|
+
## React + Vite (same Flight commands)
|
|
254
|
+
|
|
255
|
+
Flight does **not** choose Vue vs React—it runs **`vite`** / **`vite build`** from your **`app_home`**; your **`vite.config.*`** and app **`package.json`** select the framework. The `@thoughtpivot/flight` package includes **`@vitejs/plugin-react`** alongside **`@vitejs/plugin-vue`** so React+Vite apps get the same style of transitive plugin coverage as Vue apps. You still install the UI runtime in **your** app. Flight ships **Vite 8** and matching plugins; apps that stay on Vite 6 should pin **`@thoughtpivot/flight@2.0.2`** until they upgrade.
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
npm install react react-dom
|
|
259
|
+
npm install -D @types/react @types/react-dom
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Set **`"type": "module"`** in the app **`package.json`** (or use a `.mts` / `.mjs` Vite config) so Vite 8 loads ESM config without falling back to the deprecated CommonJS path.
|
|
263
|
+
|
|
264
|
+
`vite.config.ts` (project root):
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
import { defineConfig } from 'vite'
|
|
268
|
+
import react from '@vitejs/plugin-react'
|
|
269
|
+
|
|
270
|
+
export default defineConfig({
|
|
271
|
+
plugins: [react()]
|
|
272
|
+
})
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
`index.html`:
|
|
276
|
+
|
|
277
|
+
```html
|
|
278
|
+
<!doctype html>
|
|
279
|
+
<html lang="en">
|
|
280
|
+
<head>
|
|
281
|
+
<meta charset="UTF-8" />
|
|
282
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
283
|
+
<title>Flight + React</title>
|
|
284
|
+
</head>
|
|
285
|
+
<body>
|
|
286
|
+
<div id="root"></div>
|
|
287
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
288
|
+
</body>
|
|
289
|
+
</html>
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
`src/main.tsx`:
|
|
293
|
+
|
|
294
|
+
```tsx
|
|
295
|
+
import { StrictMode } from 'react'
|
|
296
|
+
import { createRoot } from 'react-dom/client'
|
|
297
|
+
import App from './App'
|
|
298
|
+
|
|
299
|
+
createRoot(document.getElementById('root')!).render(
|
|
300
|
+
<StrictMode>
|
|
301
|
+
<App />
|
|
302
|
+
</StrictMode>
|
|
303
|
+
)
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
`src/App.tsx`:
|
|
307
|
+
|
|
308
|
+
```tsx
|
|
309
|
+
export default function App() {
|
|
310
|
+
return <h1>Hello from Flight + React</h1>
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Use the same **`npx flight --mode development`** / **`--mode production`** flow as Vue. Production **`dist`**, **`FLIGHT_DISABLE_VITE`**, and the **Production SPA pipeline** behave the same for a Vite-built React SPA.
|
|
315
|
+
|
|
230
316
|
## Development mode
|
|
231
317
|
|
|
232
|
-
- **
|
|
318
|
+
- **Vite** with HMR on port **3001** for **Vue or React** (whatever your `vite.config` configures)
|
|
233
319
|
- Backend worker on **`--port`** (default **3000**)
|
|
234
320
|
- Request logging via **`koa-logger`**
|
|
235
321
|
|
|
@@ -283,19 +369,97 @@ flowchart TD
|
|
|
283
369
|
|
|
284
370
|
See **[CHANGELOG.md](CHANGELOG.md)** for the full **2.0.0** notes.
|
|
285
371
|
|
|
372
|
+
## Bun runtime
|
|
373
|
+
|
|
374
|
+
`flight-bun` is the Bun entry. `npx flight` remains the Node server. From an installed package:
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
FLIGHT_MODE=development flight-bun
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
From a clone of this repo:
|
|
381
|
+
|
|
382
|
+
```bash
|
|
383
|
+
FLIGHT_MODE=development bun src/bun/server.ts
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
`npm run test:bun` runs the Bun suite. `npm test` stays the Node suite.
|
|
387
|
+
|
|
388
|
+
The Bun server uses `Bun.serve` and loads TypeScript directly. It exposes `GET /healthz` and the same edge jobs as the Node server (logging, security headers, CORS, gzip, rate limit, sessions, response cache) without Koa packages on the native path. Redis is optional (`FLIGHT_REDIS_URL`); without it, sessions and cache use memory.
|
|
389
|
+
|
|
390
|
+
**Two backend contracts can be mixed in one app.**
|
|
391
|
+
|
|
392
|
+
Bun-native files default-export a path map. Handlers are `(req: Request) => Response`. Path params use Bun's `:id` routes.
|
|
393
|
+
|
|
394
|
+
```typescript
|
|
395
|
+
export default {
|
|
396
|
+
'/api/hello': {
|
|
397
|
+
GET: () => Response.json({ message: 'Hello from Flight!' })
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Existing Koa files keep working. `export default router.routes()` is mounted through Koa, including JSON body parsing. That is the on-ramp: boot the app on Bun, then rewrite routes file by file. `*.backend.js` is discovered as well as `*.backend.ts`.
|
|
403
|
+
|
|
404
|
+
In development (`FLIGHT_MODE=development`) the API stays on `FLIGHT_PORT` (default 3000) and Vite is spawned on 3001. In production the built SPA is read from `FLIGHT_DIST_PATH` (default `<app home>/dist`) with an `index.html` fallback. `/api`, `/health`, and `/healthz` do not fall back.
|
|
405
|
+
|
|
406
|
+
| Variable | Default | Bun runtime |
|
|
407
|
+
| ------------------------ | ---------------- | ------------------------------------------------------------------------------------------------ |
|
|
408
|
+
| `FLIGHT_SESSION_SECRET` | unset | Sessions stay **off** until this is set. There is no baked-in secret. |
|
|
409
|
+
| `FLIGHT_RATE_LIMIT_MAX` | `0` | Rate limit stays **off** until this is greater than zero. |
|
|
410
|
+
| `FLIGHT_TRUST_PROXY` | false | When `1` / `true` / `yes`, the limiter uses `X-Forwarded-For`. Otherwise that header is ignored. |
|
|
411
|
+
| `FLIGHT_REDIS_URL` | unset | `redis://host:6379` for shared sessions and cache. |
|
|
412
|
+
| `FLIGHT_CACHE_ENABLED` | false | Cache GET responses that send `Cache-Control: max-age`. |
|
|
413
|
+
| `FLIGHT_STATIC_PREFIXES` | `/assets,/fonts` | GET/HEAD under these prefixes skip the rate limit. |
|
|
414
|
+
|
|
415
|
+
Other `FLIGHT_*` knobs from the Node server (`FLIGHT_MODE`, `FLIGHT_PORT`, `FLIGHT_APP_HOME`, `FLIGHT_EXCLUDE_PATHS`, `FLIGHT_SPA_DENY_PREFIXES`, `FLIGHT_PAYLOAD_LIMIT`) apply here too. `GET /healthz` returns `ok` and is not rate limited.
|
|
416
|
+
|
|
286
417
|
## Requirements
|
|
287
418
|
|
|
288
|
-
- Node.js
|
|
289
|
-
-
|
|
419
|
+
- Node.js **`^20.19.0` or `>=22.12.0`** (the `flight` binary; matches Vite 8 / ioredis 6)
|
|
420
|
+
- [Bun](https://bun.sh) 1.x (only for `flight-bun` / `npm run test:bun`)
|
|
421
|
+
- **Redis** (sessions / rate limit / cache integrations on the Node server; optional for the Bun runtime)
|
|
290
422
|
- **TypeScript** in your app if you author `.backend.ts` modules as TS
|
|
291
423
|
|
|
424
|
+
## CI and npm publish
|
|
425
|
+
|
|
426
|
+
GitHub Actions is the only CI/publish path:
|
|
427
|
+
|
|
428
|
+
| Workflow | When | What it does |
|
|
429
|
+
| ---------------------------------------------------------------- | -------------------------------------------------------- | --------------------------------------------------------------- |
|
|
430
|
+
| [`.github/workflows/ci.yml`](.github/workflows/ci.yml) | Pull requests and pushes to `main` | `npm ci`, `lint:check`, `npm test` on Node 20 and 22 |
|
|
431
|
+
| [`.github/workflows/publish.yml`](.github/workflows/publish.yml) | GitHub Release published (or manual `workflow_dispatch`) | Re-runs checks, then `npm publish --access public --provenance` |
|
|
432
|
+
|
|
433
|
+
### One-time npm setup (Trusted Publishing)
|
|
434
|
+
|
|
435
|
+
Preferred: no long-lived npm token in GitHub.
|
|
436
|
+
|
|
437
|
+
1. Sign in at [npmjs.com](https://www.npmjs.com/) as a maintainer of `@thoughtpivot/flight`.
|
|
438
|
+
2. Open the package → **Settings** → **Trusted Publisher**.
|
|
439
|
+
3. Add GitHub Actions with:
|
|
440
|
+
- **Organization / user:** `thoughtpivot`
|
|
441
|
+
- **Repository:** `flight`
|
|
442
|
+
- **Workflow filename:** `publish.yml`
|
|
443
|
+
- **Environment name:** `npm` (must match the workflow `environment:`)
|
|
444
|
+
4. In the GitHub repo, create an **Environment** named `npm` (Settings → Environments). Optional: require reviewers before publish.
|
|
445
|
+
|
|
446
|
+
Fallback if Trusted Publishing is unavailable: add a repository or environment secret **`NPM_TOKEN`** (granular token with read/write to `@thoughtpivot/flight`). The publish workflow already passes it as `NODE_AUTH_TOKEN` when present.
|
|
447
|
+
|
|
448
|
+
### Cut a release
|
|
449
|
+
|
|
450
|
+
1. Land the version bump on `main` (`package.json` + `CHANGELOG.md`).
|
|
451
|
+
2. Create a GitHub Release whose tag is `v` + that version (example: package `3.0.0` → tag `v3.0.0`).
|
|
452
|
+
3. Publishing the release runs `.github/workflows/publish.yml`. The job fails if the tag and `package.json` version disagree.
|
|
453
|
+
|
|
454
|
+
Dry-run without publishing: Actions → **Publish** → **Run workflow** → leave **dry_run** checked.
|
|
455
|
+
|
|
292
456
|
## License
|
|
293
457
|
|
|
294
458
|
MIT
|
|
295
459
|
|
|
296
460
|
## Contributing
|
|
297
461
|
|
|
298
|
-
Issues and pull requests are welcome. Flight improves fastest with real workloads—if you hit an edge case, open an issue with a minimal repro.
|
|
462
|
+
Issues and pull requests are welcome. Flight improves fastest with real workloads—if you hit an edge case, open an issue with a minimal repro. Run `npm test` and `npm run lint:check` before opening a PR.
|
|
299
463
|
|
|
300
464
|
## Acknowledgments
|
|
301
465
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeExcludePaths = normalizeExcludePaths;
|
|
7
|
+
exports.dedupeStrings = dedupeStrings;
|
|
8
|
+
exports.mergeExcludePaths = mergeExcludePaths;
|
|
9
|
+
exports.backendDiscoveryIgnorePatterns = backendDiscoveryIgnorePatterns;
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
/** Turn a CLI value or env string into trimmed, comma-split directory names. */
|
|
12
|
+
function normalizeExcludePaths(value) {
|
|
13
|
+
if (value == null || value === '')
|
|
14
|
+
return [];
|
|
15
|
+
const parts = Array.isArray(value) ? value : [value];
|
|
16
|
+
const out = [];
|
|
17
|
+
for (const p of parts) {
|
|
18
|
+
const s = String(p).trim();
|
|
19
|
+
if (!s)
|
|
20
|
+
continue;
|
|
21
|
+
out.push(...s
|
|
22
|
+
.split(',')
|
|
23
|
+
.map((x) => x.trim())
|
|
24
|
+
.filter(Boolean));
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
/** Preserve first-seen order while dropping duplicate strings. */
|
|
29
|
+
function dedupeStrings(items) {
|
|
30
|
+
return [...new Set(items)];
|
|
31
|
+
}
|
|
32
|
+
/** Combine CLI and FLIGHT_EXCLUDE_PATHS values, CLI first, without duplicates. */
|
|
33
|
+
function mergeExcludePaths(cliValue, envValue) {
|
|
34
|
+
return dedupeStrings([...normalizeExcludePaths(cliValue), ...normalizeExcludePaths(envValue)]);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build fast-glob ignore globs for trees rooted under `appRootAbs`.
|
|
38
|
+
* Entries that resolve outside that root, or to the root itself, are skipped.
|
|
39
|
+
* Folder names are not escaped, so a name like `[abc]` is still a fast-glob pattern.
|
|
40
|
+
*/
|
|
41
|
+
function backendDiscoveryIgnorePatterns(appRootAbs, excludeRelativeDirs) {
|
|
42
|
+
const patterns = [];
|
|
43
|
+
for (const raw of excludeRelativeDirs) {
|
|
44
|
+
const trimmed = raw.trim();
|
|
45
|
+
if (!trimmed)
|
|
46
|
+
continue;
|
|
47
|
+
const resolved = path_1.default.resolve(appRootAbs, trimmed);
|
|
48
|
+
const rel = path_1.default.relative(appRootAbs, resolved);
|
|
49
|
+
const relPosix = rel.replace(/\\/g, '/');
|
|
50
|
+
if (!relPosix) {
|
|
51
|
+
console.warn(`Flight: exclude_paths entry skipped (would ignore all of app_home): ${trimmed}`);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (relPosix === '..' || relPosix.startsWith('../') || path_1.default.isAbsolute(rel)) {
|
|
55
|
+
console.warn(`Flight: exclude_paths entry skipped (outside app_home): ${trimmed}`);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
patterns.push(`${relPosix}/**`);
|
|
59
|
+
}
|
|
60
|
+
return patterns;
|
|
61
|
+
}
|
package/dist/flight.js
CHANGED
|
@@ -22,44 +22,8 @@ const path_1 = __importDefault(require("path"));
|
|
|
22
22
|
const koa_ratelimit_1 = __importDefault(require("koa-ratelimit"));
|
|
23
23
|
const koa_static_1 = __importDefault(require("koa-static"));
|
|
24
24
|
const koa_session_1 = __importDefault(require("koa-session"));
|
|
25
|
+
const backend_discovery_js_1 = require("./backend-discovery.js");
|
|
25
26
|
const spa_pipeline_js_1 = require("./spa-pipeline.js");
|
|
26
|
-
function normalizeExcludePaths(value) {
|
|
27
|
-
if (value == null || value === '')
|
|
28
|
-
return [];
|
|
29
|
-
const parts = Array.isArray(value) ? value : [value];
|
|
30
|
-
const out = [];
|
|
31
|
-
for (const p of parts) {
|
|
32
|
-
const s = String(p).trim();
|
|
33
|
-
if (!s)
|
|
34
|
-
continue;
|
|
35
|
-
out.push(...s
|
|
36
|
-
.split(',')
|
|
37
|
-
.map((x) => x.trim())
|
|
38
|
-
.filter(Boolean));
|
|
39
|
-
}
|
|
40
|
-
return out;
|
|
41
|
-
}
|
|
42
|
-
function dedupeStrings(items) {
|
|
43
|
-
return [...new Set(items)];
|
|
44
|
-
}
|
|
45
|
-
/** Build fast-glob ignore globs for trees rooted under `appRootAbs`. */
|
|
46
|
-
function backendDiscoveryIgnorePatterns(appRootAbs, excludeRelativeDirs) {
|
|
47
|
-
const patterns = [];
|
|
48
|
-
for (const raw of excludeRelativeDirs) {
|
|
49
|
-
const trimmed = raw.trim();
|
|
50
|
-
if (!trimmed)
|
|
51
|
-
continue;
|
|
52
|
-
const resolved = path_1.default.resolve(appRootAbs, trimmed);
|
|
53
|
-
const rel = path_1.default.relative(appRootAbs, resolved);
|
|
54
|
-
const relPosix = rel.replace(/\\/g, '/');
|
|
55
|
-
if (!relPosix || relPosix.startsWith('..') || path_1.default.isAbsolute(rel)) {
|
|
56
|
-
console.warn(`Flight: exclude_paths entry skipped (outside app_home): ${trimmed}`);
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
patterns.push(`${relPosix}/**`);
|
|
60
|
-
}
|
|
61
|
-
return patterns;
|
|
62
|
-
}
|
|
63
27
|
const _yargs = require('yargs/yargs');
|
|
64
28
|
const yargsEntry = typeof _yargs === 'function' ? _yargs : _yargs.default;
|
|
65
29
|
const argv = yargsEntry(process.argv.slice(2))
|
|
@@ -72,7 +36,7 @@ const argv = yargsEntry(process.argv.slice(2))
|
|
|
72
36
|
})
|
|
73
37
|
.option('mode', {
|
|
74
38
|
type: 'string',
|
|
75
|
-
describe: 'development (Vite HMR) or production'
|
|
39
|
+
describe: 'development (Vite HMR for Vue/React per vite.config) or production'
|
|
76
40
|
})
|
|
77
41
|
.option('port', {
|
|
78
42
|
type: 'number',
|
|
@@ -145,11 +109,8 @@ if (argv.disable_vite === undefined) {
|
|
|
145
109
|
// Ensure the value is a boolean
|
|
146
110
|
argv.disable_vite = Boolean(argv.disable_vite);
|
|
147
111
|
const appHomePath = path_1.default.resolve(argv.app_home);
|
|
148
|
-
const excludePathsConfigured =
|
|
149
|
-
|
|
150
|
-
...normalizeExcludePaths(process.env.FLIGHT_EXCLUDE_PATHS)
|
|
151
|
-
]);
|
|
152
|
-
const backendDiscoveryIgnores = backendDiscoveryIgnorePatterns(appHomePath, excludePathsConfigured);
|
|
112
|
+
const excludePathsConfigured = (0, backend_discovery_js_1.mergeExcludePaths)(argv.exclude_paths, process.env.FLIGHT_EXCLUDE_PATHS);
|
|
113
|
+
const backendDiscoveryIgnores = (0, backend_discovery_js_1.backendDiscoveryIgnorePatterns)(appHomePath, excludePathsConfigured);
|
|
153
114
|
process.chdir(appHomePath);
|
|
154
115
|
console.log(appHomePath);
|
|
155
116
|
if (backendDiscoveryIgnores.length > 0) {
|
|
@@ -230,7 +191,7 @@ else {
|
|
|
230
191
|
const distRoot = (0, spa_pipeline_js_1.resolveDistRoot)(process.cwd());
|
|
231
192
|
const useSpaPipeline = (0, spa_pipeline_js_1.productionSpaPipelineActive)(mode, Boolean(argv.disable_vite));
|
|
232
193
|
const staticPrefixes = (0, spa_pipeline_js_1.parseCommaPrefixes)(process.env.FLIGHT_STATIC_PREFIXES, '/assets,/fonts');
|
|
233
|
-
const rateLimitSkipPrefixes = dedupeStrings([
|
|
194
|
+
const rateLimitSkipPrefixes = (0, backend_discovery_js_1.dedupeStrings)([
|
|
234
195
|
...staticPrefixes,
|
|
235
196
|
...(0, spa_pipeline_js_1.parseCommaPrefixes)(process.env.FLIGHT_RATE_LIMIT_EXCLUDE_PREFIXES, '')
|
|
236
197
|
]);
|
|
@@ -286,17 +247,17 @@ else {
|
|
|
286
247
|
shell: true
|
|
287
248
|
});
|
|
288
249
|
viteProcess.on('error', (error) => {
|
|
289
|
-
console.error('Failed to start
|
|
250
|
+
console.error('Failed to start Vite dev server:', error);
|
|
290
251
|
});
|
|
291
252
|
viteProcess.on('exit', (code) => {
|
|
292
253
|
if (code !== 0) {
|
|
293
|
-
console.error(`Vite server exited with code ${code}`);
|
|
254
|
+
console.error(`Vite dev server exited with code ${code}`);
|
|
294
255
|
}
|
|
295
256
|
});
|
|
296
257
|
process.on('SIGINT', () => {
|
|
297
258
|
viteProcess.kill('SIGINT');
|
|
298
259
|
process.exit(0);
|
|
299
260
|
});
|
|
300
|
-
console.log(`Vite
|
|
261
|
+
console.log(`Vite dev server (HMR for Vue/React per your vite.config) for worker ${process.pid} on port 3001`);
|
|
301
262
|
}
|
|
302
263
|
}
|
package/dist/spa-pipeline.js
CHANGED
|
@@ -30,6 +30,7 @@ function applyTrustProxy(app, env = process.env) {
|
|
|
30
30
|
const t = env.FLIGHT_TRUST_PROXY;
|
|
31
31
|
app.proxy = t === '1' || t === 'true' || t === 'yes';
|
|
32
32
|
}
|
|
33
|
+
/** Use `fallback` only when `value` is missing. Add a leading `/` to entries that lack one. */
|
|
33
34
|
function parseCommaPrefixes(value, fallback) {
|
|
34
35
|
const raw = (value ?? fallback).trim();
|
|
35
36
|
if (!raw)
|
|
@@ -41,11 +42,18 @@ function parseCommaPrefixes(value, fallback) {
|
|
|
41
42
|
.map((p) => (p.startsWith('/') ? p : `/${p}`));
|
|
42
43
|
}
|
|
43
44
|
function resolveDistRoot(cwd, env = process.env) {
|
|
44
|
-
|
|
45
|
+
const configured = env.FLIGHT_DIST_PATH?.trim();
|
|
46
|
+
return path_1.default.resolve(cwd, configured || '../dist');
|
|
45
47
|
}
|
|
48
|
+
/** SPA shell path inside the dist root. `..` segments and blank values fall back to `index.html`. */
|
|
46
49
|
function spaIndexRelative(env = process.env) {
|
|
47
|
-
const
|
|
48
|
-
|
|
50
|
+
const configured = env.FLIGHT_SPA_INDEX?.trim().replace(/^\/+/, '');
|
|
51
|
+
if (!configured)
|
|
52
|
+
return 'index.html';
|
|
53
|
+
const normalized = configured.replace(/\\/g, '/');
|
|
54
|
+
if (normalized.split('/').includes('..'))
|
|
55
|
+
return 'index.html';
|
|
56
|
+
return normalized;
|
|
49
57
|
}
|
|
50
58
|
const DEFAULT_DENY_PREFIXES = ['/api', '/health'];
|
|
51
59
|
/** Match connect-history-api-fallback default: do not rewrite paths whose last segment looks like a file name. */
|
|
@@ -56,8 +64,16 @@ function lastPathSegmentLooksLikeFile(urlPath) {
|
|
|
56
64
|
/**
|
|
57
65
|
* After koa-static: serve index.html for document navigations that are not API, health, or static-like paths.
|
|
58
66
|
*/
|
|
67
|
+
function indexInsideDist(distRoot, indexRel) {
|
|
68
|
+
const indexAbs = path_1.default.resolve(distRoot, indexRel);
|
|
69
|
+
const rel = path_1.default.relative(distRoot, indexAbs);
|
|
70
|
+
const relPosix = rel.replace(/\\/g, '/');
|
|
71
|
+
if (!relPosix || relPosix === '..' || relPosix.startsWith('../') || path_1.default.isAbsolute(rel))
|
|
72
|
+
return undefined;
|
|
73
|
+
return indexAbs;
|
|
74
|
+
}
|
|
59
75
|
function spaIndexHtmlFallback(distRoot, indexRel, extraDenyPrefixes = []) {
|
|
60
|
-
const indexAbs =
|
|
76
|
+
const indexAbs = indexInsideDist(distRoot, indexRel);
|
|
61
77
|
const deny = dedupePathList([...DEFAULT_DENY_PREFIXES, ...extraDenyPrefixes]);
|
|
62
78
|
return async (ctx, next) => {
|
|
63
79
|
if (ctx.method !== 'GET' && ctx.method !== 'HEAD')
|
|
@@ -75,6 +91,8 @@ function spaIndexHtmlFallback(distRoot, indexRel, extraDenyPrefixes = []) {
|
|
|
75
91
|
return next();
|
|
76
92
|
}
|
|
77
93
|
}
|
|
94
|
+
if (!indexAbs)
|
|
95
|
+
return next();
|
|
78
96
|
try {
|
|
79
97
|
await fs_1.default.promises.access(indexAbs, fs_1.default.constants.R_OK);
|
|
80
98
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thoughtpivot/flight",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A web server designed for running full stack, component based applications at enterprise scale.",
|
|
5
5
|
"main": "src/flight.ts",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
11
|
+
},
|
|
9
12
|
"bin": {
|
|
10
|
-
"flight": "dist/flight.js"
|
|
13
|
+
"flight": "dist/flight.js",
|
|
14
|
+
"flight-bun": "src/bun/server.ts"
|
|
11
15
|
},
|
|
12
16
|
"scripts": {
|
|
13
17
|
"lint": "eslint . --fix && prettier -w .",
|
|
18
|
+
"lint:check": "eslint . && prettier -c .",
|
|
14
19
|
"build": "rm -rf dist; node_modules/.bin/tsc --project .",
|
|
15
|
-
"test": "npm run build && node --test dist
|
|
20
|
+
"test": "npm run build && node --test dist/*.test.js",
|
|
21
|
+
"test:bun": "bun test src/bun/app.test.ts",
|
|
22
|
+
"start:bun": "bun src/bun/server.ts",
|
|
16
23
|
"prepublishOnly": "npm run build"
|
|
17
24
|
},
|
|
18
25
|
"repository": {
|
|
@@ -28,6 +35,8 @@
|
|
|
28
35
|
"files": [
|
|
29
36
|
"dist/flight.js",
|
|
30
37
|
"dist/spa-pipeline.js",
|
|
38
|
+
"dist/backend-discovery.js",
|
|
39
|
+
"src/bun",
|
|
31
40
|
"README.md",
|
|
32
41
|
"CHANGELOG.md",
|
|
33
42
|
"readme-assets"
|
|
@@ -35,28 +44,29 @@
|
|
|
35
44
|
"dependencies": {
|
|
36
45
|
"@koa/cors": "^5.0.0",
|
|
37
46
|
"@koa/router": "^13.1.0",
|
|
38
|
-
"@vitejs/plugin-
|
|
47
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
48
|
+
"@vitejs/plugin-vue": "^6.0.9",
|
|
39
49
|
"@vue/language-plugin-pug": "^2.2.0",
|
|
40
50
|
"core-js": "^3.40.0",
|
|
41
51
|
"dotenv": "^17.4.2",
|
|
42
52
|
"esbuild": "^0.28.0",
|
|
43
53
|
"fast-glob": "^3.3.3",
|
|
44
|
-
"ioredis": "^
|
|
54
|
+
"ioredis": "^6.0.0",
|
|
45
55
|
"koa": "^2.15.3",
|
|
46
56
|
"koa-bodyparser": "^4.4.1",
|
|
47
57
|
"koa-cash": "^5.0.0",
|
|
48
58
|
"koa-compress": "^5.1.1",
|
|
49
59
|
"koa-connect-history-api-fallback": "^0.3.1",
|
|
50
|
-
"koa-helmet": "^
|
|
51
|
-
"koa-logger": "^
|
|
52
|
-
"koa-ratelimit": "^
|
|
60
|
+
"koa-helmet": "^9.0.0",
|
|
61
|
+
"koa-logger": "^4.0.0",
|
|
62
|
+
"koa-ratelimit": "^6.0.0",
|
|
53
63
|
"koa-redis": "^4.0.1",
|
|
54
64
|
"koa-send": "^5.0.1",
|
|
55
65
|
"koa-session": "^6.4.0",
|
|
56
66
|
"koa-static": "^5.0.0",
|
|
57
67
|
"unplugin-fonts": "^2.0.0",
|
|
58
|
-
"vite": "^
|
|
59
|
-
"vite-plugin-vuetify": "^2.
|
|
68
|
+
"vite": "^8.3.2",
|
|
69
|
+
"vite-plugin-vuetify": "^2.1.3",
|
|
60
70
|
"yargs": "^18.0.0"
|
|
61
71
|
},
|
|
62
72
|
"devDependencies": {
|