@cedarjs/vite 5.0.7-next.258 → 5.0.7-next.310

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.
@@ -21,6 +21,7 @@ export declare function parseCliArgs(argv?: string[]): {
21
21
  portArg: any;
22
22
  debugPort: any;
23
23
  debugBrk: any;
24
+ jobsArg: any;
24
25
  serverArgs: {
25
26
  [argName: string]: any;
26
27
  "--"?: Array<string | number>;
@@ -1 +1 @@
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,kBAyI1C"}
1
+ {"version":3,"file":"cedar-unified-dev.d.ts","sourceRoot":"","sources":["../src/cedar-unified-dev.ts"],"names":[],"mappings":"AAiBA,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;;;;;;;;;;;EAkC/C;AAuCD,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,UAAQ,iBAkKvE;AAED,wBAAsB,qBAAqB,kBAkK1C"}
@@ -3,6 +3,7 @@ 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
+ import { startJobsDevWorkers } from "./jobsDevMiddleware.js";
6
7
  const SHUTDOWN_TIMEOUT_MS = 5e3;
7
8
  function createShutdownHandler({
8
9
  close,
@@ -50,6 +51,7 @@ function parseCliArgs(argv = process.argv) {
50
51
  apiPort: _apiPortArg,
51
52
  "debug-port": debugPort,
52
53
  "debug-brk": debugBrk,
54
+ jobs: jobsArg,
53
55
  _: _positional,
54
56
  ...serverArgs
55
57
  } = yargsParser(argv.slice(2), {
@@ -60,11 +62,20 @@ function parseCliArgs(argv = process.argv) {
60
62
  "force",
61
63
  "cors",
62
64
  "debug",
63
- "debug-brk"
65
+ "debug-brk",
66
+ "jobs"
64
67
  ],
65
68
  number: ["port", "apiPort", "debug-port"]
66
69
  });
67
- return { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs };
70
+ return {
71
+ forceOptimize,
72
+ debug,
73
+ portArg,
74
+ debugPort,
75
+ debugBrk,
76
+ jobsArg,
77
+ serverArgs
78
+ };
68
79
  }
69
80
  async function clearPendingPause() {
70
81
  const inspector = await import("node:inspector");
@@ -212,7 +223,15 @@ async function startUnifiedDevServer() {
212
223
  if (!configFile) {
213
224
  throw new Error("Could not locate your web/vite.config.{js,ts} file");
214
225
  }
215
- const { forceOptimize, debug, portArg, debugPort, debugBrk, serverArgs } = parseCliArgs();
226
+ const {
227
+ forceOptimize,
228
+ debug,
229
+ portArg,
230
+ debugPort,
231
+ debugBrk,
232
+ jobsArg,
233
+ serverArgs
234
+ } = parseCliArgs();
216
235
  if (serverArgs.open === void 0 && !process.stdout.isTTY) {
217
236
  serverArgs.open = false;
218
237
  }
@@ -220,8 +239,13 @@ async function startUnifiedDevServer() {
220
239
  await openDebugger(debugPort, debugBrk);
221
240
  }
222
241
  const webPort = portArg ?? cedarConfig.web.port ?? 8910;
223
- const { close: closeApi, handler: apiHandler } = await startApiDevMiddleware();
242
+ const {
243
+ viteServer: apiViteServer,
244
+ close: closeApi,
245
+ handler: apiHandler
246
+ } = await startApiDevMiddleware();
224
247
  const apiAdapter = createServerAdapter(apiHandler);
248
+ const jobsWorkerPool = jobsArg === false ? null : await startJobsDevWorkers(apiViteServer);
225
249
  const devServer = await createServer({
226
250
  configFile,
227
251
  // env file is handled by Cedar's plugins
@@ -297,7 +321,11 @@ async function startUnifiedDevServer() {
297
321
  const shutdown = createShutdownHandler({
298
322
  close: async () => {
299
323
  await devServer.close();
300
- await closeApi();
324
+ try {
325
+ await jobsWorkerPool?.stop();
326
+ } finally {
327
+ await closeApi();
328
+ }
301
329
  }
302
330
  });
303
331
  process.on("SIGINT", shutdown);
@@ -0,0 +1,17 @@
1
+ import type { ViteDevServer } from 'vite';
2
+ export interface JobsWorkerPool {
3
+ stop: () => Promise<void>;
4
+ }
5
+ type SsrModuleLoader = Pick<ViteDevServer, 'ssrLoadModule'>;
6
+ /**
7
+ * Starts the configured background jobs workers in-process, loading both the
8
+ * jobs config and job implementations through the given (already-running)
9
+ * api Vite dev server instead of from compiled `api/dist` output.
10
+ *
11
+ * Returns `null` (and logs nothing) when no jobs are configured, mirroring
12
+ * the "just works, opt-in already happened at `cedar setup jobs` time"
13
+ * behaviour of classic dev's nodemon-wrapped worker.
14
+ */
15
+ export declare function startJobsDevWorkers(viteServer: SsrModuleLoader): Promise<JobsWorkerPool | null>;
16
+ export {};
17
+ //# sourceMappingURL=jobsDevMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobsDevMiddleware.d.ts","sourceRoot":"","sources":["../src/jobsDevMiddleware.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAyEzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC1B;AAKD,KAAK,eAAe,GAAG,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC,CAAA;AAE3D;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,eAAe,GAC1B,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CA8FhC"}
@@ -0,0 +1,106 @@
1
+ import { pathToFileURL } from "node:url";
2
+ import ansis from "ansis";
3
+ import {
4
+ JobNotFoundError,
5
+ JobsLibNotFoundError,
6
+ setJobLoaderOverrides
7
+ } from "@cedarjs/jobs";
8
+ import { getPaths } from "@cedarjs/project-config";
9
+ function buildNumWorkers(workers) {
10
+ const numWorkers = [];
11
+ workers.forEach((worker, index) => {
12
+ const count = worker.count ?? 1;
13
+ for (let id = 0; id < count; id++) {
14
+ numWorkers.push([index, id]);
15
+ }
16
+ });
17
+ return numWorkers;
18
+ }
19
+ async function loadJobsManagerViaVite(viteServer) {
20
+ const jobsConfigPath = getPaths().api.jobsConfig;
21
+ if (!jobsConfigPath) {
22
+ throw new JobsLibNotFoundError();
23
+ }
24
+ const mod = await viteServer.ssrLoadModule(pathToFileURL(jobsConfigPath).href);
25
+ if (!mod.jobs) {
26
+ throw new JobsLibNotFoundError();
27
+ }
28
+ return mod.jobs;
29
+ }
30
+ async function loadJobViaVite(viteServer, { name: jobName, path: jobPath }) {
31
+ const completeJobPath = `${getPaths().api.jobs}/${jobPath}`;
32
+ let mod;
33
+ try {
34
+ mod = await viteServer.ssrLoadModule(pathToFileURL(completeJobPath).href);
35
+ } catch {
36
+ throw new JobNotFoundError(jobName);
37
+ }
38
+ if (!mod[jobName]) {
39
+ throw new JobNotFoundError(jobName);
40
+ }
41
+ return mod[jobName];
42
+ }
43
+ async function startJobsDevWorkers(viteServer) {
44
+ setJobLoaderOverrides({
45
+ loadJobsManager: () => loadJobsManagerViaVite(viteServer),
46
+ loadJob: (computedProperties) => loadJobViaVite(viteServer, computedProperties)
47
+ });
48
+ let jobsManager;
49
+ try {
50
+ jobsManager = await loadJobsManagerViaVite(viteServer);
51
+ } catch (e) {
52
+ if (e instanceof JobsLibNotFoundError) {
53
+ setJobLoaderOverrides(void 0);
54
+ return null;
55
+ }
56
+ throw e;
57
+ }
58
+ const numWorkers = buildNumWorkers(jobsManager.workers);
59
+ const logger = jobsManager.logger ?? console;
60
+ if (numWorkers.length === 0) {
61
+ setJobLoaderOverrides(void 0);
62
+ return null;
63
+ }
64
+ logger.warn(
65
+ `[CedarJS Jobs] Starting ${numWorkers.length} worker(s) in-process (Unified Dev)...`
66
+ );
67
+ const workers = numWorkers.map(([index, id]) => {
68
+ const workerConfig = jobsManager.workers[index];
69
+ const processName = `ud-jobs.${[workerConfig.queue].flat().join("-")}.${id}`;
70
+ return jobsManager.createWorker({
71
+ index,
72
+ clear: false,
73
+ workoff: false,
74
+ processName
75
+ });
76
+ });
77
+ const workerRunPromises = workers.map(
78
+ (worker) => worker.run().catch((e) => {
79
+ logger.error("[CedarJS Jobs] A worker stopped unexpectedly", e);
80
+ })
81
+ );
82
+ console.log(
83
+ ansis.dim.italic(
84
+ `[CedarJS Jobs] ${workers.length} worker(s) running: ` + workers.map((w) => w.processName).join(", ")
85
+ )
86
+ );
87
+ const stop = async () => {
88
+ console.log(
89
+ ansis.dim.italic(
90
+ "[CedarJS Jobs] Waiting for in-progress jobs to finish..."
91
+ )
92
+ );
93
+ workers.forEach((worker) => {
94
+ worker.forever = false;
95
+ });
96
+ try {
97
+ await Promise.all(workerRunPromises);
98
+ } finally {
99
+ setJobLoaderOverrides(void 0);
100
+ }
101
+ };
102
+ return { stop };
103
+ }
104
+ export {
105
+ startJobsDevWorkers
106
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "5.0.7-next.258",
3
+ "version": "5.0.7-next.310",
4
4
  "description": "Vite configuration package for CedarJS",
5
5
  "repository": {
6
6
  "type": "git",
@@ -52,23 +52,24 @@
52
52
  "@babel/parser": "7.29.7",
53
53
  "@babel/traverse": "7.29.7",
54
54
  "@babel/types": "7.29.7",
55
- "@cedarjs/api": "5.0.7-next.258",
56
- "@cedarjs/api-server": "5.0.7-next.258",
57
- "@cedarjs/babel-config": "5.0.7-next.258",
58
- "@cedarjs/context": "5.0.7-next.258",
59
- "@cedarjs/graphql-server": "5.0.7-next.258",
60
- "@cedarjs/internal": "5.0.7-next.258",
61
- "@cedarjs/project-config": "5.0.7-next.258",
62
- "@cedarjs/server-store": "5.0.7-next.258",
63
- "@cedarjs/structure": "5.0.7-next.258",
64
- "@cedarjs/testing": "5.0.7-next.258",
55
+ "@cedarjs/api": "5.0.7-next.310",
56
+ "@cedarjs/api-server": "5.0.7-next.310",
57
+ "@cedarjs/babel-config": "5.0.7-next.310",
58
+ "@cedarjs/context": "5.0.7-next.310",
59
+ "@cedarjs/graphql-server": "5.0.7-next.310",
60
+ "@cedarjs/internal": "5.0.7-next.310",
61
+ "@cedarjs/jobs": "5.0.7-next.310",
62
+ "@cedarjs/project-config": "5.0.7-next.310",
63
+ "@cedarjs/server-store": "5.0.7-next.310",
64
+ "@cedarjs/structure": "5.0.7-next.310",
65
+ "@cedarjs/testing": "5.0.7-next.310",
65
66
  "@swc/core": "1.15.47",
66
67
  "@universal-deploy/store": "^0.2.1",
67
68
  "@universal-deploy/vite": "^0.1.9",
68
69
  "@vitejs/plugin-react": "4.7.0",
69
70
  "@whatwg-node/fetch": "0.10.13",
70
71
  "@whatwg-node/server": "0.11.0",
71
- "acorn": "8.17.0",
72
+ "acorn": "8.18.0",
72
73
  "acorn-loose": "8.5.2",
73
74
  "ansis": "4.3.1",
74
75
  "busboy": "^1.6.0",
@@ -79,7 +80,7 @@
79
80
  "http-proxy-middleware": "3.0.7",
80
81
  "isbot": "5.2.1",
81
82
  "magic-string": "0.30.21",
82
- "oxc-parser": "0.141.0",
83
+ "oxc-parser": "0.144.0",
83
84
  "react": "18.3.1",
84
85
  "react-server-dom-webpack": "19.2.7",
85
86
  "unimport": "5.7.0",
@@ -92,14 +93,14 @@
92
93
  "yargs-parser": "21.1.1"
93
94
  },
94
95
  "devDependencies": {
95
- "@cedarjs/auth": "5.0.7-next.258",
96
- "@cedarjs/framework-tools": "5.0.7-next.258",
97
- "@cedarjs/router": "5.0.7-next.258",
98
- "@cedarjs/web": "5.0.7-next.258",
96
+ "@cedarjs/auth": "5.0.7-next.310",
97
+ "@cedarjs/framework-tools": "5.0.7-next.310",
98
+ "@cedarjs/router": "5.0.7-next.310",
99
+ "@cedarjs/web": "5.0.7-next.310",
99
100
  "@dr.pogodin/react-helmet": "2.0.4",
100
101
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",
101
102
  "@jridgewell/trace-mapping": "0.3.31",
102
- "@oxc-project/types": "^0.141.0",
103
+ "@oxc-project/types": "^0.144.0",
103
104
  "@types/aws-lambda": "8.10.162",
104
105
  "@types/busboy": "^1",
105
106
  "@types/express": "4",
@@ -107,7 +108,7 @@
107
108
  "@types/ws": "^8",
108
109
  "@types/yargs-parser": "21.0.3",
109
110
  "concurrently": "9.2.4",
110
- "memfs": "4.64.0",
111
+ "memfs": "4.68.1",
111
112
  "publint": "0.3.23",
112
113
  "rollup": "4.60.4",
113
114
  "ts-dedent": "2.3.0",
@@ -115,9 +116,9 @@
115
116
  "vitest": "4.1.10"
116
117
  },
117
118
  "peerDependencies": {
118
- "@cedarjs/auth": "5.0.7-next.258",
119
- "@cedarjs/router": "5.0.7-next.258",
120
- "@cedarjs/web": "5.0.7-next.258"
119
+ "@cedarjs/auth": "5.0.7-next.310",
120
+ "@cedarjs/router": "5.0.7-next.310",
121
+ "@cedarjs/web": "5.0.7-next.310"
121
122
  },
122
123
  "engines": {
123
124
  "node": ">=24"