@cedarjs/vite 6.0.0-canary.2733 → 6.0.0-canary.2734

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.
@@ -1,3 +1,20 @@
1
+ interface ShutdownHandlerOptions {
2
+ /** Closes the running servers. Called once, on the first signal. */
3
+ close: () => Promise<void>;
4
+ timeoutMs?: number;
5
+ exit?: (code: number) => void;
6
+ logger?: Pick<typeof console, 'warn' | 'error'>;
7
+ }
8
+ /**
9
+ * Build the SIGINT/SIGTERM handler for the unified dev server.
10
+ *
11
+ * The handler always terminates the process, and does so promptly. Vite's
12
+ * `close()` waits for in-flight requests and open HMR websocket connections to
13
+ * drain, which is not guaranteed to finish, so the graceful path is bounded by
14
+ * a timeout. A second signal skips the wait entirely, which is what a user
15
+ * pressing Ctrl+C twice is asking for.
16
+ */
17
+ export declare function createShutdownHandler({ close, timeoutMs, exit, logger, }: ShutdownHandlerOptions): () => Promise<void>;
1
18
  export declare function parseCliArgs(argv?: string[]): {
2
19
  forceOptimize: any;
3
20
  debug: any;
@@ -11,4 +28,5 @@ export declare function parseCliArgs(argv?: string[]): {
11
28
  };
12
29
  export declare function openDebugger(port: number, waitForDebugger?: boolean): Promise<void>;
13
30
  export declare function startUnifiedDevServer(): Promise<void>;
31
+ export {};
14
32
  //# sourceMappingURL=cedar-unified-dev.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cedar-unified-dev.d.ts","sourceRoot":"","sources":["../src/cedar-unified-dev.ts"],"names":[],"mappings":"AA+BA,wBAAgB,YAAY,CAAC,IAAI,WAAe;;;;;;;;;;EAwB/C;AAuCD,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,UAAQ,iBAkKvE;AAED,wBAAsB,qBAAqB,kBAiI1C"}
1
+ {"version":3,"file":"cedar-unified-dev.d.ts","sourceRoot":"","sources":["../src/cedar-unified-dev.ts"],"names":[],"mappings":"AAgBA,UAAU,sBAAsB;IAC9B,oEAAoE;IACpE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAA;CAChD;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,KAAK,EACL,SAA+B,EAC/B,IAAmC,EACnC,MAAgB,GACjB,EAAE,sBAAsB,uBAoCxB;AAuBD,wBAAgB,YAAY,CAAC,IAAI,WAAe;;;;;;;;;;EAwB/C;AAuCD,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,UAAQ,iBAkKvE;AAED,wBAAsB,qBAAqB,kBAkI1C"}
@@ -3,6 +3,38 @@ import { createServer } from "vite";
3
3
  import yargsParser from "yargs-parser";
4
4
  import { getPaths, getConfig } from "@cedarjs/project-config";
5
5
  import { startApiDevMiddleware } from "./apiDevMiddleware.js";
6
+ const SHUTDOWN_TIMEOUT_MS = 5e3;
7
+ function createShutdownHandler({
8
+ close,
9
+ timeoutMs = SHUTDOWN_TIMEOUT_MS,
10
+ exit = (code) => process.exit(code),
11
+ logger = console
12
+ }) {
13
+ let shuttingDown = false;
14
+ return async function shutdown() {
15
+ if (shuttingDown) {
16
+ exit(0);
17
+ return;
18
+ }
19
+ shuttingDown = true;
20
+ const forceExitTimer = setTimeout(() => {
21
+ logger.warn(
22
+ `Dev server did not shut down within ${timeoutMs}ms. Forcing exit.`
23
+ );
24
+ exit(0);
25
+ }, timeoutMs);
26
+ forceExitTimer.unref();
27
+ try {
28
+ await close();
29
+ } catch (e) {
30
+ const message = e instanceof Error ? e.message : String(e);
31
+ logger.error(`Error while shutting down the dev server: ${message}`);
32
+ } finally {
33
+ clearTimeout(forceExitTimer);
34
+ }
35
+ exit(0);
36
+ };
37
+ }
6
38
  function isViteInternalRequest(url) {
7
39
  const pathname = url.split("?")[0];
8
40
  return pathname.startsWith("/@") || pathname.startsWith("/__vite") || pathname.startsWith("/__hmr");
@@ -259,15 +291,17 @@ async function startUnifiedDevServer() {
259
291
  console.log(JSON.stringify(devServer.config, null, 2));
260
292
  console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~");
261
293
  }
262
- const shutdown = async () => {
263
- await devServer.close();
264
- await closeApi();
265
- process.exit(0);
266
- };
294
+ const shutdown = createShutdownHandler({
295
+ close: async () => {
296
+ await devServer.close();
297
+ await closeApi();
298
+ }
299
+ });
267
300
  process.on("SIGINT", shutdown);
268
301
  process.on("SIGTERM", shutdown);
269
302
  }
270
303
  export {
304
+ createShutdownHandler,
271
305
  openDebugger,
272
306
  parseCliArgs,
273
307
  startUnifiedDevServer
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var cedar_unified_dev_exports = {};
30
30
  __export(cedar_unified_dev_exports, {
31
+ createShutdownHandler: () => createShutdownHandler,
31
32
  openDebugger: () => openDebugger,
32
33
  parseCliArgs: () => parseCliArgs,
33
34
  startUnifiedDevServer: () => startUnifiedDevServer
@@ -38,6 +39,38 @@ var import_vite = require("vite");
38
39
  var import_yargs_parser = __toESM(require("yargs-parser"), 1);
39
40
  var import_project_config = require("@cedarjs/project-config");
40
41
  var import_apiDevMiddleware = require("./apiDevMiddleware.js");
42
+ const SHUTDOWN_TIMEOUT_MS = 5e3;
43
+ function createShutdownHandler({
44
+ close,
45
+ timeoutMs = SHUTDOWN_TIMEOUT_MS,
46
+ exit = (code) => process.exit(code),
47
+ logger = console
48
+ }) {
49
+ let shuttingDown = false;
50
+ return async function shutdown() {
51
+ if (shuttingDown) {
52
+ exit(0);
53
+ return;
54
+ }
55
+ shuttingDown = true;
56
+ const forceExitTimer = setTimeout(() => {
57
+ logger.warn(
58
+ `Dev server did not shut down within ${timeoutMs}ms. Forcing exit.`
59
+ );
60
+ exit(0);
61
+ }, timeoutMs);
62
+ forceExitTimer.unref();
63
+ try {
64
+ await close();
65
+ } catch (e) {
66
+ const message = e instanceof Error ? e.message : String(e);
67
+ logger.error(`Error while shutting down the dev server: ${message}`);
68
+ } finally {
69
+ clearTimeout(forceExitTimer);
70
+ }
71
+ exit(0);
72
+ };
73
+ }
41
74
  function isViteInternalRequest(url) {
42
75
  const pathname = url.split("?")[0];
43
76
  return pathname.startsWith("/@") || pathname.startsWith("/__vite") || pathname.startsWith("/__hmr");
@@ -294,16 +327,18 @@ async function startUnifiedDevServer() {
294
327
  console.log(JSON.stringify(devServer.config, null, 2));
295
328
  console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~");
296
329
  }
297
- const shutdown = async () => {
298
- await devServer.close();
299
- await closeApi();
300
- process.exit(0);
301
- };
330
+ const shutdown = createShutdownHandler({
331
+ close: async () => {
332
+ await devServer.close();
333
+ await closeApi();
334
+ }
335
+ });
302
336
  process.on("SIGINT", shutdown);
303
337
  process.on("SIGTERM", shutdown);
304
338
  }
305
339
  // Annotate the CommonJS export names for ESM import in node:
306
340
  0 && (module.exports = {
341
+ createShutdownHandler,
307
342
  openDebugger,
308
343
  parseCliArgs,
309
344
  startUnifiedDevServer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "6.0.0-canary.2733",
3
+ "version": "6.0.0-canary.2734",
4
4
  "description": "Vite configuration package for CedarJS",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,16 +63,16 @@
63
63
  "@babel/parser": "7.29.7",
64
64
  "@babel/traverse": "7.29.7",
65
65
  "@babel/types": "7.29.7",
66
- "@cedarjs/api": "6.0.0-canary.2733",
67
- "@cedarjs/api-server": "6.0.0-canary.2733",
68
- "@cedarjs/babel-config": "6.0.0-canary.2733",
69
- "@cedarjs/context": "6.0.0-canary.2733",
70
- "@cedarjs/cookie-jar": "6.0.0-canary.2733",
71
- "@cedarjs/graphql-server": "6.0.0-canary.2733",
72
- "@cedarjs/internal": "6.0.0-canary.2733",
73
- "@cedarjs/project-config": "6.0.0-canary.2733",
74
- "@cedarjs/server-store": "6.0.0-canary.2733",
75
- "@cedarjs/testing": "6.0.0-canary.2733",
66
+ "@cedarjs/api": "6.0.0-canary.2734",
67
+ "@cedarjs/api-server": "6.0.0-canary.2734",
68
+ "@cedarjs/babel-config": "6.0.0-canary.2734",
69
+ "@cedarjs/context": "6.0.0-canary.2734",
70
+ "@cedarjs/cookie-jar": "6.0.0-canary.2734",
71
+ "@cedarjs/graphql-server": "6.0.0-canary.2734",
72
+ "@cedarjs/internal": "6.0.0-canary.2734",
73
+ "@cedarjs/project-config": "6.0.0-canary.2734",
74
+ "@cedarjs/server-store": "6.0.0-canary.2734",
75
+ "@cedarjs/testing": "6.0.0-canary.2734",
76
76
  "@fastify/url-data": "6.0.3",
77
77
  "@swc/core": "1.15.46",
78
78
  "@universal-deploy/store": "^0.2.1",
@@ -109,9 +109,9 @@
109
109
  },
110
110
  "devDependencies": {
111
111
  "@arethetypeswrong/cli": "0.18.5",
112
- "@cedarjs/auth": "6.0.0-canary.2733",
113
- "@cedarjs/router": "6.0.0-canary.2733",
114
- "@cedarjs/web": "6.0.0-canary.2733",
112
+ "@cedarjs/auth": "6.0.0-canary.2734",
113
+ "@cedarjs/router": "6.0.0-canary.2734",
114
+ "@cedarjs/web": "6.0.0-canary.2734",
115
115
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",
116
116
  "@jridgewell/trace-mapping": "0.3.31",
117
117
  "@types/aws-lambda": "8.10.162",
@@ -130,9 +130,9 @@
130
130
  "vitest": "4.1.10"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cedarjs/auth": "6.0.0-canary.2733",
134
- "@cedarjs/router": "6.0.0-canary.2733",
135
- "@cedarjs/web": "6.0.0-canary.2733"
133
+ "@cedarjs/auth": "6.0.0-canary.2734",
134
+ "@cedarjs/router": "6.0.0-canary.2734",
135
+ "@cedarjs/web": "6.0.0-canary.2734"
136
136
  },
137
137
  "engines": {
138
138
  "node": ">=24"