rosetack 0.0.0 → 0.1.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/LICENSE +21 -0
- package/deploy/Dockerfile.node +25 -0
- package/deploy/Dockerfile.static +34 -0
- package/deploy/api/rosetack.ts +29 -0
- package/deploy/docker-compose.yml +33 -0
- package/deploy/fly.toml +28 -0
- package/deploy/vercel.json +13 -0
- package/dist-cli/compiler.mjs +2302 -0
- package/dist-cli/edge.mjs +297 -0
- package/dist-cli/rosetack.mjs +3411 -0
- package/dist-cli/runtime.mjs +619 -0
- package/dist-cli/test.mjs +2696 -0
- package/pack.mjs +49 -0
- package/package.json +50 -11
- package/src/FRAMEWORK_VERSION +1 -0
- package/src/cli/edge.ts +162 -0
- package/src/cli/index.ts +1233 -0
- package/src/cli/shell.ts +337 -0
- package/src/cli/test.ts +400 -0
- package/src/compiler/index.ts +3076 -0
- package/src/runtime/index.ts +915 -0
- package/src/types/rosetack.d.ts +142 -0
- package/README.md +0 -3
- package/index.js +0 -12
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 xdunli
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# The Node service: the dynamic half as a container. Builds the app, then
|
|
2
|
+
# runs `rosetack serve` - the cluster runner (one worker per core, bounded
|
|
3
|
+
# request bodies, request/header/keep-alive timeouts, graceful SIGTERM
|
|
4
|
+
# drain, one access line per request on stdout). Pair it with
|
|
5
|
+
# Dockerfile.static (the Go binary in front) using docker-compose.yml.
|
|
6
|
+
FROM node:22-alpine AS build
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
COPY package.json package-lock.json ./
|
|
9
|
+
RUN npm ci
|
|
10
|
+
COPY . .
|
|
11
|
+
RUN npm run build
|
|
12
|
+
|
|
13
|
+
FROM node:22-alpine
|
|
14
|
+
WORKDIR /app
|
|
15
|
+
ENV NODE_ENV=production PORT=3000
|
|
16
|
+
COPY --from=build /app/node_modules ./node_modules
|
|
17
|
+
COPY --from=build /app/dist ./dist
|
|
18
|
+
COPY --from=build /app/src ./src
|
|
19
|
+
COPY --from=build /app/package.json ./
|
|
20
|
+
EXPOSE 3000
|
|
21
|
+
# rosetack_WORKERS defaults to the container's CPU count.
|
|
22
|
+
# The demo api's SQLite file lands in the working directory: mount a volume
|
|
23
|
+
# at /app to keep it across deploys (a real deployment points the api at
|
|
24
|
+
# Postgres instead - the connection block is the only thing that changes).
|
|
25
|
+
CMD ["node", "node_modules/tsx/dist/cli.mjs", "src/cli/index.ts", "serve"]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# The static half of the hybrid deploy (innovation #34, consultant P0 §3 方案B).
|
|
2
|
+
#
|
|
3
|
+
# Build the site with Node, embed it into ONE Go binary, ship an image with
|
|
4
|
+
# no runtime to install and nothing to configure:
|
|
5
|
+
#
|
|
6
|
+
# docker build -f deploy/Dockerfile.static -t rosetack-static .
|
|
7
|
+
# docker run -p 8080:8080 -e UPSTREAM=http://dynamic:3000 rosetack-static
|
|
8
|
+
#
|
|
9
|
+
# UPSTREAM is optional. Without it the binary is the pure-static deploy (it
|
|
10
|
+
# answers 405 for POSTs and a JSON 404 for unbaked /api routes - the
|
|
11
|
+
# documented boundary). With it, POST server actions and live /api handlers
|
|
12
|
+
# are reverse-proxied to the Node/edge backend.
|
|
13
|
+
FROM node:22-alpine AS site
|
|
14
|
+
WORKDIR /app
|
|
15
|
+
COPY package.json package-lock.json ./
|
|
16
|
+
RUN npm ci
|
|
17
|
+
COPY . .
|
|
18
|
+
RUN npm run build
|
|
19
|
+
|
|
20
|
+
# golang:alpine (not a pinned patch) tracks go.mod: the module declares the
|
|
21
|
+
# minimum toolchain, and a stale pin is a build failure nobody needs.
|
|
22
|
+
FROM golang:alpine AS bin
|
|
23
|
+
WORKDIR /app
|
|
24
|
+
COPY main.go go.mod ./
|
|
25
|
+
COPY --from=site /app/dist ./dist
|
|
26
|
+
RUN go build -trimpath -o rosetack-server .
|
|
27
|
+
|
|
28
|
+
FROM alpine:3.20
|
|
29
|
+
COPY --from=bin /app/rosetack-server /usr/local/bin/rosetack-server
|
|
30
|
+
ENV PORT=8080
|
|
31
|
+
EXPOSE 8080
|
|
32
|
+
# The access log goes to stdout and errors to stderr, so `docker logs`
|
|
33
|
+
# and any collector see them without mounting a file.
|
|
34
|
+
ENTRYPOINT ["rosetack-server"]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rosetack Vercel function - the dynamic half of a Vercel deploy.
|
|
3
|
+
*
|
|
4
|
+
* Every request that is NOT a static file in dist/ lands here: dynamic
|
|
5
|
+
* pages (/sign, anything reading getContext() or $store()), /api routes,
|
|
6
|
+
* and POST server actions. Static answers - prerendered documents, the
|
|
7
|
+
* bundles, baked API bodies - are served by the CDN straight from dist/
|
|
8
|
+
* and never touch this code. That split is the whole rosetack story: the
|
|
9
|
+
* static half costs zero function invocations.
|
|
10
|
+
*
|
|
11
|
+
* It reuses the framework's own edge adapter (the same Web-standard fetch
|
|
12
|
+
* handler the edge adapter test exercises) over the built server bundle,
|
|
13
|
+
* on Vercel's Node.js runtime, whose Web Standard handler is
|
|
14
|
+
* `export default { fetch }` - one handler object, every method. The
|
|
15
|
+
* Node.js runtime compiles TypeScript entrypoints and their imports, so
|
|
16
|
+
* this file and the adapter it pulls in stay .ts.
|
|
17
|
+
*
|
|
18
|
+
* Install: copy this file to <project>/api/rosetack.ts and deploy/vercel.json
|
|
19
|
+
* to <project>/vercel.json, then `vercel --prod`. In a project that depends
|
|
20
|
+
* on the published package the import below becomes:
|
|
21
|
+
* import { createEdgeHandler } from 'rosetack/edge';
|
|
22
|
+
*/
|
|
23
|
+
import { createEdgeHandler } from '../src/cli/edge.ts';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
|
|
26
|
+
// dist/ next to the api/ directory, whatever the working directory is.
|
|
27
|
+
const handle = await createEdgeHandler(fileURLToPath(new URL('../dist', import.meta.url)));
|
|
28
|
+
|
|
29
|
+
export default { fetch: handle };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# The hybrid deploy (innovation #34, consultant P0 §3 方案B): one command - `docker compose
|
|
2
|
+
# -f deploy/docker-compose.yml up --build`.
|
|
3
|
+
services:
|
|
4
|
+
static:
|
|
5
|
+
build:
|
|
6
|
+
context: ..
|
|
7
|
+
dockerfile: deploy/Dockerfile.static
|
|
8
|
+
environment:
|
|
9
|
+
PORT: "8080"
|
|
10
|
+
UPSTREAM: http://dynamic:3000
|
|
11
|
+
ports:
|
|
12
|
+
- "8080:8080"
|
|
13
|
+
depends_on:
|
|
14
|
+
dynamic:
|
|
15
|
+
condition: service_healthy
|
|
16
|
+
restart: unless-stopped
|
|
17
|
+
dynamic:
|
|
18
|
+
image: node:22-alpine
|
|
19
|
+
working_dir: /app
|
|
20
|
+
# Build inside the container: the host's node_modules may hold
|
|
21
|
+
# foreign-platform binaries (esbuild ships one per OS).
|
|
22
|
+
command: sh -c "npm ci && npm run build && npm run preview"
|
|
23
|
+
environment:
|
|
24
|
+
PORT: "3000"
|
|
25
|
+
volumes:
|
|
26
|
+
- ..:/app
|
|
27
|
+
- /app/node_modules
|
|
28
|
+
healthcheck:
|
|
29
|
+
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:' + (process.env.PORT || 3000) + '/').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"]
|
|
30
|
+
interval: 5s
|
|
31
|
+
timeout: 3s
|
|
32
|
+
retries: 20
|
|
33
|
+
restart: unless-stopped
|
package/deploy/fly.toml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Fly.io: the rosetack Node service as a machine.
|
|
2
|
+
#
|
|
3
|
+
# cp deploy/fly.toml ./fly.toml
|
|
4
|
+
# fly launch --no-deploy
|
|
5
|
+
# fly deploy
|
|
6
|
+
#
|
|
7
|
+
# The app builds deploy/Dockerfile.node (Node builds the site, then runs
|
|
8
|
+
# `rosetack serve` - the cluster runner). Swap the dockerfile line for
|
|
9
|
+
# "deploy/Dockerfile.static" to ship the Go single binary instead, and set
|
|
10
|
+
# UPSTREAM to the Node app for the dynamic half.
|
|
11
|
+
app = "rosetack"
|
|
12
|
+
primary_region = "iad"
|
|
13
|
+
|
|
14
|
+
[build]
|
|
15
|
+
dockerfile = "deploy/Dockerfile.node"
|
|
16
|
+
|
|
17
|
+
[http_service]
|
|
18
|
+
internal_port = 3000
|
|
19
|
+
force_https = true
|
|
20
|
+
# rosetack serve already clusters across every core of the machine; give it
|
|
21
|
+
# the cores instead of paying for more, smaller machines.
|
|
22
|
+
auto_stop_machines = "suspend"
|
|
23
|
+
auto_start_machines = true
|
|
24
|
+
min_machines_running = 1
|
|
25
|
+
|
|
26
|
+
[[vm]]
|
|
27
|
+
size = "shared-cpu-2x"
|
|
28
|
+
memory = "512mb"
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://openapi.vercel.sh/vercel.json",
|
|
3
|
+
"buildCommand": "npm run build",
|
|
4
|
+
"outputDirectory": "dist",
|
|
5
|
+
"functions": {
|
|
6
|
+
"api/rosetack.ts": {
|
|
7
|
+
"includeFiles": "dist/**"
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
"rewrites": [
|
|
11
|
+
{ "source": "/(.*)", "destination": "/api/rosetack" }
|
|
12
|
+
]
|
|
13
|
+
}
|