vue-ssr-lite 0.1.8 → 0.1.9

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
@@ -45,11 +45,15 @@ It includes routing, browser hydration, production builds, a managed Node server
45
45
  CLI binary:
46
46
 
47
47
  ```bash
48
- vue-ssr-lite <dev|build|start> [--root .] [--runtime src/SsrRuntime.ts] [--server-output dist/server/SsrRuntime.js]
48
+ vue-ssr-lite <dev|build|start> [--root .] [--runtime src/SsrRuntime.ts] [--server-output dist/server/SsrRuntime.js] [--hmr-port 31001]
49
49
  ```
50
50
 
51
51
  Requires Node.js 20 or newer.
52
52
 
53
+ Development servers use an operating-system-assigned HMR WebSocket port, so
54
+ multiple `vue-ssr-lite dev` processes can run concurrently. Use `--hmr-port`
55
+ or `VUE_SSR_LITE_HMR_PORT` when a proxy or container requires a fixed port.
56
+
53
57
  ## Installation
54
58
 
55
59
  ```bash
@@ -0,0 +1,4 @@
1
+ export declare const parseSsrCliHmrPort: (value?: string) => number | undefined;
2
+ export declare const findAvailableSsrCliHmrPort: () => Promise<number>;
3
+ export declare const resolveSsrCliHmrPort: (value?: string) => Promise<number>;
4
+ //# sourceMappingURL=SsrCliHmrPort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SsrCliHmrPort.d.ts","sourceRoot":"","sources":["../../src/cli/SsrCliHmrPort.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,GAAI,QAAQ,MAAM,KAAG,MAAM,GAAG,SAY5D,CAAA;AAED,eAAO,MAAM,0BAA0B,uBAerC,CAAA;AAEF,eAAO,MAAM,oBAAoB,GAAU,QAAQ,MAAM,KAAG,OAAO,CAAC,MAAM,CACf,CAAA"}
package/dist/cli.mjs CHANGED
@@ -1,71 +1,97 @@
1
1
  #!/usr/bin/env node
2
- import { resolve as o, relative as m } from "node:path";
3
- import { pathToFileURL as v } from "node:url";
4
- import { c as p } from "./chunks/SsrServerRuntime-ChrpJneS.mjs";
5
- const s = (e, r) => {
6
- const t = e.indexOf(r);
7
- return t >= 0 ? e[t + 1] : void 0;
8
- }, f = (e) => {
9
- const r = e[0];
10
- if (!["dev", "build", "start"].includes(r))
2
+ import { resolve as i, relative as w } from "node:path";
3
+ import { pathToFileURL as f } from "node:url";
4
+ import { c as S } from "./chunks/SsrServerRuntime-ChrpJneS.mjs";
5
+ import { createServer as b } from "node:net";
6
+ const a = 1, c = 65535, R = (r) => {
7
+ const e = r?.trim();
8
+ if (!e) return;
9
+ if (!/^\d+$/.test(e))
10
+ throw new Error(`HMR port must be an integer between ${a} and ${c}.`);
11
+ const t = Number(e);
12
+ if (!Number.isInteger(t) || t < a || t > c)
13
+ throw new Error(`HMR port must be an integer between ${a} and ${c}.`);
14
+ return t;
15
+ }, h = () => new Promise((r, e) => {
16
+ const t = b();
17
+ t.once("error", e), t.listen({ port: 0, exclusive: !0 }, () => {
18
+ const o = t.address();
19
+ if (!o || typeof o == "string") {
20
+ t.close(), e(new Error("Unable to allocate an HMR WebSocket port."));
21
+ return;
22
+ }
23
+ t.close((s) => {
24
+ s ? e(s) : r(o.port);
25
+ });
26
+ });
27
+ }), P = async (r) => R(r) ?? h(), n = (r, e) => {
28
+ const t = r.indexOf(e);
29
+ return t >= 0 ? r[t + 1] : void 0;
30
+ }, T = (r) => {
31
+ const e = r[0];
32
+ if (!["dev", "build", "start"].includes(e))
11
33
  throw new Error(
12
- "Usage: vue-ssr-lite <dev|build|start> [--root .] [--runtime src/SsrRuntime.ts]"
34
+ "Usage: vue-ssr-lite <dev|build|start> [--root .] [--runtime src/SsrRuntime.ts] [--hmr-port 31001]"
13
35
  );
14
- const t = o(s(e, "--root") || process.cwd());
36
+ const t = i(n(r, "--root") || process.cwd());
15
37
  return {
16
- command: r,
38
+ command: e,
17
39
  root: t,
18
- runtime: o(t, s(e, "--runtime") || "src/SsrRuntime.ts"),
19
- serverOutput: o(
40
+ runtime: i(t, n(r, "--runtime") || "src/SsrRuntime.ts"),
41
+ serverOutput: i(
20
42
  t,
21
- s(e, "--server-output") || "dist/server/SsrRuntime.js"
22
- )
43
+ n(r, "--server-output") || "dist/server/SsrRuntime.js"
44
+ ),
45
+ hmrPort: n(r, "--hmr-port") || process.env.VUE_SSR_LITE_HMR_PORT
23
46
  };
24
- }, w = async (e, r) => {
25
- const t = r ? void 0 : (await import("vite")).createServer, i = r ? void 0 : await t({
26
- root: e.root,
27
- server: { middlewareMode: !0 },
47
+ }, M = async (r, e) => {
48
+ const t = e ? void 0 : await P(r.hmrPort), o = e ? void 0 : (await import("vite")).createServer, s = e ? void 0 : await o({
49
+ root: r.root,
50
+ server: {
51
+ middlewareMode: !0,
52
+ hmr: { port: t, clientPort: t }
53
+ },
28
54
  appType: "custom"
29
- }), u = `/${m(e.root, e.runtime).replaceAll("\\", "/")}`, a = await p({
30
- production: r,
31
- root: e.root,
32
- vite: i,
33
- loadRuntime: r ? () => import(v(e.serverOutput).href) : () => i.ssrLoadModule(u)
55
+ }), d = `/${w(r.root, r.runtime).replaceAll("\\", "/")}`, l = await S({
56
+ production: e,
57
+ root: r.root,
58
+ vite: s,
59
+ loadRuntime: e ? () => import(f(r.serverOutput).href) : () => s.ssrLoadModule(d)
34
60
  });
35
- await a.listen();
36
- let n = !1;
37
- const c = async (d) => {
38
- if (!n) {
39
- n = !0;
61
+ await l.listen();
62
+ let u = !1;
63
+ const m = async (p) => {
64
+ if (!u) {
65
+ u = !0;
40
66
  try {
41
- await a.close(), console.log(`stopped after ${d}`), process.exitCode = 0;
42
- } catch (l) {
43
- console.error("graceful shutdown failed", l), process.exitCode = 1;
67
+ await l.close(), console.log(`stopped after ${p}`), process.exitCode = 0;
68
+ } catch (v) {
69
+ console.error("graceful shutdown failed", v), process.exitCode = 1;
44
70
  }
45
71
  }
46
72
  };
47
73
  process.once("SIGINT", () => {
48
- c("SIGINT");
74
+ m("SIGINT");
49
75
  }), process.once("SIGTERM", () => {
50
- c("SIGTERM");
76
+ m("SIGTERM");
51
77
  });
52
- }, S = async (e) => {
53
- const { build: r } = await import("vite");
54
- await r({ root: e.root }), await r({
55
- root: e.root,
78
+ }, y = async (r) => {
79
+ const { build: e } = await import("vite");
80
+ await e({ root: r.root }), await e({
81
+ root: r.root,
56
82
  build: {
57
- ssr: e.runtime,
58
- outDir: o(e.root, "dist/server"),
83
+ ssr: r.runtime,
84
+ outDir: i(r.root, "dist/server"),
59
85
  emptyOutDir: !0,
60
86
  rollupOptions: {
61
87
  output: { entryFileNames: "SsrRuntime.js" }
62
88
  }
63
89
  }
64
90
  });
65
- }, y = async () => {
66
- const e = f(process.argv.slice(2));
67
- return e.command === "build" ? S(e) : w(e, e.command === "start");
91
+ }, I = async () => {
92
+ const r = T(process.argv.slice(2));
93
+ return r.command === "build" ? y(r) : M(r, r.command === "start");
68
94
  };
69
- y().catch((e) => {
70
- console.error("fatal error", e), process.exitCode = 1;
95
+ I().catch((r) => {
96
+ console.error("fatal error", r), process.exitCode = 1;
71
97
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-ssr-lite",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
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",