vue-ssr-lite 0.2.14 → 0.2.15

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 CHANGED
@@ -42,12 +42,19 @@ It includes routing, browser hydration, production builds, a managed Node server
42
42
  | `vue-ssr-lite/server` | Managed Node server, config compile, host matching, cookies |
43
43
  | `vue-ssr-lite/vite` | Vite plugin that wires HTML templates and virtual client entries |
44
44
 
45
- CLI binary (auto-discovers `ssr.config.ts|.mts|.js|.mjs` in the project root):
45
+ CLI binary:
46
46
 
47
47
  ```bash
48
48
  vue-ssr-lite <dev|build|start> [--root .] [--config ssr.config.ts] [--server-output dist/server/SsrRuntime.js] [--hmr-port 31001]
49
49
  ```
50
50
 
51
+ - `dev` / `build` auto-discover `ssr.config.ts|.mts|.js|.mjs` in the project root
52
+ (or take `--config`).
53
+ - `start` loads the baked production runtime
54
+ (`dist/server/SsrRuntime.js` or `--server-output`) and does **not** require
55
+ source `ssr.config.*` in the working directory — slim Docker images only need
56
+ `package.json`, production `node_modules`, and `dist/`.
57
+
51
58
  Requires Node.js 20 or newer.
52
59
 
53
60
  Development servers use an operating-system-assigned HMR WebSocket port, so
@@ -0,0 +1,22 @@
1
+ export type SsrCliCommand = 'dev' | 'build' | 'start';
2
+ export interface SsrCliOptions {
3
+ command: SsrCliCommand;
4
+ root: string;
5
+ /**
6
+ * Absolute path to `ssr.config.*`. Present for `dev` / `build` only —
7
+ * production `start` loads the baked runtime and never reads source config.
8
+ */
9
+ config?: string;
10
+ serverOutput: string;
11
+ hmrPort?: string;
12
+ }
13
+ /**
14
+ * Parse CLI argv for `vue-ssr-lite <dev|build|start>`.
15
+ *
16
+ * - `dev` / `build` discover (or accept `--config`) source `ssr.config.*`.
17
+ * - `start` only requires the baked server bundle (`--server-output` or
18
+ * `dist/server/SsrRuntime.js`) so slim production images need not COPY
19
+ * source config.
20
+ */
21
+ export declare const parseSsrCliArguments: (args: string[]) => Promise<SsrCliOptions>;
22
+ //# sourceMappingURL=SsrCliOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SsrCliOptions.d.ts","sourceRoot":"","sources":["../../src/cli/SsrCliOptions.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,OAAO,GAAG,OAAO,CAAA;AAErD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,aAAa,CAAA;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAqBD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,MAAM,EAAE,KACb,OAAO,CAAC,aAAa,CAgCvB,CAAA"}
package/dist/cli.mjs CHANGED
@@ -1,99 +1,116 @@
1
1
  #!/usr/bin/env node
2
- import { resolve as c } from "node:path";
3
- import { pathToFileURL as f } from "node:url";
2
+ import { pathToFileURL as v } from "node:url";
4
3
  import { S as m, r as w } from "./chunks/SsrHtmlRuntime-BJUxjM2F.mjs";
5
4
  import { c as S } from "./chunks/SsrServerRuntime-BbWemkgs.mjs";
5
+ import { resolve as d } from "node:path";
6
6
  import { createServer as R } from "node:net";
7
+ import { access as h } from "node:fs/promises";
7
8
  const b = (r) => ({
8
9
  root: r,
9
10
  build: {
10
11
  ssr: !0,
11
- outDir: c(r, "dist/server"),
12
+ outDir: d(r, "dist/server"),
12
13
  emptyOutDir: !0,
13
14
  rollupOptions: {
14
15
  input: m,
15
16
  output: { entryFileNames: "SsrRuntime.js" }
16
17
  }
17
18
  }
18
- }), i = 1, a = 65535, h = (r) => {
19
- const e = r?.trim();
20
- if (!e) return;
21
- if (!/^\d+$/.test(e))
22
- throw new Error(`HMR port must be an integer between ${i} and ${a}.`);
23
- const t = Number(e);
24
- if (!Number.isInteger(t) || t < i || t > a)
25
- throw new Error(`HMR port must be an integer between ${i} and ${a}.`);
26
- return t;
27
- }, P = () => new Promise((r, e) => {
28
- const t = R();
29
- t.once("error", e), t.listen({ port: 0, exclusive: !0 }, () => {
30
- const o = t.address();
19
+ }), a = 1, c = 65535, P = (r) => {
20
+ const t = r?.trim();
21
+ if (!t) return;
22
+ if (!/^\d+$/.test(t))
23
+ throw new Error(`HMR port must be an integer between ${a} and ${c}.`);
24
+ const e = Number(t);
25
+ if (!Number.isInteger(e) || e < a || e > c)
26
+ throw new Error(`HMR port must be an integer between ${a} and ${c}.`);
27
+ return e;
28
+ }, T = () => new Promise((r, t) => {
29
+ const e = R();
30
+ e.once("error", t), e.listen({ port: 0, exclusive: !0 }, () => {
31
+ const o = e.address();
31
32
  if (!o || typeof o == "string") {
32
- t.close(), e(new Error("Unable to allocate an HMR WebSocket port."));
33
+ e.close(), t(new Error("Unable to allocate an HMR WebSocket port."));
33
34
  return;
34
35
  }
35
- t.close((s) => {
36
- s ? e(s) : r(o.port);
36
+ e.close((s) => {
37
+ s ? t(s) : r(o.port);
37
38
  });
38
39
  });
39
- }), T = async (r) => h(r) ?? P(), n = (r, e) => {
40
- const t = r.indexOf(e);
41
- return t >= 0 ? r[t + 1] : void 0;
42
- }, g = async (r) => {
43
- const e = r[0];
44
- if (!["dev", "build", "start"].includes(e))
40
+ }), g = async (r) => P(r) ?? T(), y = "dist/server/SsrRuntime.js", i = (r, t) => {
41
+ const e = r.indexOf(t);
42
+ return e >= 0 ? r[e + 1] : void 0;
43
+ }, E = async (r) => {
44
+ try {
45
+ await h(r);
46
+ } catch {
47
+ throw new Error(
48
+ `vue-ssr-lite start could not find the production SSR runtime at ${r}. Run \`vue-ssr-lite build\` first. Production start loads the baked runtime and does not require ssr.config.* in the working directory.`
49
+ );
50
+ }
51
+ }, _ = async (r) => {
52
+ const t = r[0];
53
+ if (!["dev", "build", "start"].includes(t))
45
54
  throw new Error(
46
55
  "Usage: vue-ssr-lite <dev|build|start> [--root .] [--config ssr.config.ts] [--hmr-port 31001]"
47
56
  );
48
- const t = c(n(r, "--root") || process.cwd()), o = await w(t, n(r, "--config"));
57
+ const e = d(i(r, "--root") || process.cwd()), o = d(
58
+ e,
59
+ i(r, "--server-output") || y
60
+ ), s = i(r, "--hmr-port") || process.env.VUE_SSR_LITE_HMR_PORT;
61
+ if (t === "start")
62
+ return await E(o), {
63
+ command: "start",
64
+ root: e,
65
+ serverOutput: o,
66
+ hmrPort: s
67
+ };
68
+ const n = await w(e, i(r, "--config"));
49
69
  return {
50
- command: e,
51
- root: t,
52
- config: o,
53
- serverOutput: c(
54
- t,
55
- n(r, "--server-output") || "dist/server/SsrRuntime.js"
56
- ),
57
- hmrPort: n(r, "--hmr-port") || process.env.VUE_SSR_LITE_HMR_PORT
70
+ command: t,
71
+ root: e,
72
+ config: n,
73
+ serverOutput: o,
74
+ hmrPort: s
58
75
  };
59
- }, I = async (r, e) => {
60
- const t = e ? void 0 : await T(r.hmrPort), o = e ? void 0 : (await import("vite")).createServer, s = e ? void 0 : await o({
76
+ }, I = async (r, t) => {
77
+ const e = t ? void 0 : await g(r.hmrPort), o = t ? void 0 : (await import("vite")).createServer, s = t ? void 0 : await o({
61
78
  root: r.root,
62
79
  server: {
63
80
  middlewareMode: !0,
64
- hmr: { port: t, clientPort: t }
81
+ hmr: { port: e, clientPort: e }
65
82
  },
66
83
  appType: "custom"
67
- }), l = await S({
68
- production: e,
84
+ }), n = await S({
85
+ production: t,
69
86
  root: r.root,
70
87
  vite: s,
71
- loadRuntime: e ? () => import(f(r.serverOutput).href) : () => s.ssrLoadModule(m)
88
+ loadRuntime: t ? () => import(v(r.serverOutput).href) : () => s.ssrLoadModule(m)
72
89
  });
73
- await l.listen();
74
- let d = !1;
75
- const u = async (p) => {
76
- if (!d) {
77
- d = !0;
90
+ await n.listen();
91
+ let u = !1;
92
+ const l = async (p) => {
93
+ if (!u) {
94
+ u = !0;
78
95
  try {
79
- await l.close(), console.log(`stopped after ${p}`), process.exitCode = 0;
80
- } catch (v) {
81
- console.error("graceful shutdown failed", v), process.exitCode = 1;
96
+ await n.close(), console.log(`stopped after ${p}`), process.exitCode = 0;
97
+ } catch (f) {
98
+ console.error("graceful shutdown failed", f), process.exitCode = 1;
82
99
  }
83
100
  }
84
101
  };
85
102
  process.once("SIGINT", () => {
86
- u("SIGINT");
103
+ l("SIGINT");
87
104
  }), process.once("SIGTERM", () => {
88
- u("SIGTERM");
105
+ l("SIGTERM");
89
106
  });
90
107
  }, M = async (r) => {
91
- const { build: e } = await import("vite");
92
- await e({ root: r.root }), await e(b(r.root));
93
- }, y = async () => {
94
- const r = await g(process.argv.slice(2));
108
+ const { build: t } = await import("vite");
109
+ await t({ root: r.root }), await t(b(r.root));
110
+ }, C = async () => {
111
+ const r = await _(process.argv.slice(2));
95
112
  return r.command === "build" ? M(r) : I(r, r.command === "start");
96
113
  };
97
- y().catch((r) => {
114
+ C().catch((r) => {
98
115
  console.error("fatal error", r), process.exitCode = 1;
99
116
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-ssr-lite",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Vue 3 SSR runtime with routing, generic plugin hydration, Vite, and Node server lifecycle.",
5
5
  "license": "MIT",
6
6
  "type": "module",