@cedarjs/api-server 6.0.0-rc.189 → 6.0.0-rc.221

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.
Files changed (44) hide show
  1. package/README.md +0 -1
  2. package/dist/apiCLIConfig.d.ts.map +1 -1
  3. package/dist/apiCLIConfig.js +1 -1
  4. package/dist/apiCLIConfigHandler.d.ts.map +1 -1
  5. package/dist/apiCLIConfigHandler.js +5 -0
  6. package/dist/bin.js +121 -39
  7. package/dist/bothCLIConfig.d.ts.map +1 -1
  8. package/dist/bothCLIConfig.js +2 -2
  9. package/dist/bothCLIConfigHandler.d.ts.map +1 -1
  10. package/dist/bothCLIConfigHandler.js +8 -2
  11. package/dist/cliHelpers.d.ts +21 -4
  12. package/dist/cliHelpers.d.ts.map +1 -1
  13. package/dist/cliHelpers.js +39 -11
  14. package/dist/createServer.d.ts.map +1 -1
  15. package/dist/createServer.js +4 -4
  16. package/dist/createServerHelpers.d.ts.map +1 -1
  17. package/dist/createServerHelpers.js +6 -2
  18. package/dist/plugins/api.d.ts +1 -1
  19. package/dist/plugins/api.d.ts.map +1 -1
  20. package/dist/plugins/api.js +1 -1
  21. package/dist/plugins/graphql.d.ts +3 -3
  22. package/dist/plugins/graphql.d.ts.map +1 -1
  23. package/dist/plugins/graphql.js +12 -10
  24. package/dist/serverFile.d.ts +23 -0
  25. package/dist/serverFile.d.ts.map +1 -0
  26. package/dist/serverFile.js +35 -0
  27. package/dist/types.d.ts +3 -3
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/utils.d.ts +0 -3
  30. package/dist/utils.d.ts.map +1 -1
  31. package/dist/utils.js +0 -20
  32. package/package.json +9 -19
  33. package/dist/buildManager.d.ts +0 -15
  34. package/dist/buildManager.d.ts.map +0 -1
  35. package/dist/buildManager.js +0 -55
  36. package/dist/serverManager.d.ts +0 -8
  37. package/dist/serverManager.d.ts.map +0 -1
  38. package/dist/serverManager.js +0 -102
  39. package/dist/watch.d.ts +0 -10
  40. package/dist/watch.d.ts.map +0 -1
  41. package/dist/watch.js +0 -375
  42. package/dist/watchPaths.d.ts +0 -3
  43. package/dist/watchPaths.d.ts.map +0 -1
  44. package/dist/watchPaths.js +0 -109
@@ -8,10 +8,10 @@ import { coerceRootPath } from "@cedarjs/fastify-web/dist/helpers.js";
8
8
  import { createGraphQLYoga } from "@cedarjs/graphql-server";
9
9
  import { getPaths } from "@cedarjs/project-config";
10
10
  import { lambdaEventForFastifyRequest } from "../requestHandlers/awsLambdaFastify.js";
11
- async function redwoodFastifyGraphQLServer(fastify, options) {
12
- const redwoodOptions = options.redwood ?? {};
13
- redwoodOptions.apiRootPath ??= "/";
14
- redwoodOptions.apiRootPath = coerceRootPath(redwoodOptions.apiRootPath);
11
+ async function cedarFastifyGraphQLServer(fastify, options) {
12
+ const cedarOptions = options.cedar ?? {};
13
+ cedarOptions.apiRootPath ??= "/";
14
+ cedarOptions.apiRootPath = coerceRootPath(cedarOptions.apiRootPath);
15
15
  fastify.register(fastifyUrlData);
16
16
  fastify.register(fastifyMultiPart);
17
17
  const method = ["GET", "POST", "OPTIONS"];
@@ -19,7 +19,7 @@ async function redwoodFastifyGraphQLServer(fastify, options) {
19
19
  getAsyncStoreInstance().run(/* @__PURE__ */ new Map(), done);
20
20
  });
21
21
  try {
22
- if (!redwoodOptions.graphql) {
22
+ if (!cedarOptions.graphql) {
23
23
  const [graphqlFunctionPath] = await fg("dist/functions/graphql.{ts,js}", {
24
24
  cwd: getPaths().api.base,
25
25
  absolute: true
@@ -29,9 +29,9 @@ async function redwoodFastifyGraphQLServer(fastify, options) {
29
29
  if (!__cedar_graphqlOptions) {
30
30
  return;
31
31
  }
32
- redwoodOptions.graphql = __cedar_graphqlOptions;
32
+ cedarOptions.graphql = __cedar_graphqlOptions;
33
33
  }
34
- const graphqlOptions = redwoodOptions.graphql;
34
+ const graphqlOptions = cedarOptions.graphql;
35
35
  if (graphqlOptions?.realtime?.subscriptions) {
36
36
  method.push("PUT");
37
37
  }
@@ -40,7 +40,7 @@ async function redwoodFastifyGraphQLServer(fastify, options) {
40
40
  const routePaths = ["", "/health", "/readiness", "/stream"];
41
41
  for (const routePath of routePaths) {
42
42
  fastify.route({
43
- url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
43
+ url: `${cedarOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
44
44
  method,
45
45
  handler: async (req, reply) => {
46
46
  const request = createFetchRequest(req, reply);
@@ -74,7 +74,9 @@ async function redwoodFastifyGraphQLServer(fastify, options) {
74
74
  done();
75
75
  });
76
76
  } catch (e) {
77
- console.log(e);
77
+ const message = e instanceof Error ? e.message : String(e);
78
+ fastify.log.error(e, `Failed to set up the GraphQL server: ${message}`);
79
+ throw e;
78
80
  }
79
81
  }
80
82
  function trimSlashes(path) {
@@ -97,5 +99,5 @@ function createFetchRequest(req, reply) {
97
99
  });
98
100
  }
99
101
  export {
100
- redwoodFastifyGraphQLServer
102
+ cedarFastifyGraphQLServer
101
103
  };
@@ -0,0 +1,23 @@
1
+ import type { APIParsedOptions } from './types.js';
2
+ /**
3
+ * Path to a project's built custom server file, if it has one.
4
+ *
5
+ * This checks `api/dist/server.js` — the built output — not
6
+ * `api/src/server.{ts,js}`, which is what `@cedarjs/cli`'s own
7
+ * `serverFileExists()` checks. A production install typically ships only
8
+ * `api/dist`, so checking source would return false in exactly the
9
+ * situation this needs to catch.
10
+ */
11
+ export declare function apiDistServerFilePath(): string;
12
+ export declare function apiDistServerFileExists(): boolean;
13
+ /**
14
+ * Run a project's custom `api/dist/server.js` instead of the default Fastify
15
+ * server.
16
+ *
17
+ * Reimplements what `@cedarjs/cli`'s `apiServerFileHandler` does for
18
+ * `cedar serve api`, rather than importing it — `@cedarjs/cli` pulls in its
19
+ * whole build/dev toolchain, which is exactly what a production install of
20
+ * this package needs to stay clear of.
21
+ */
22
+ export declare function runApiDistServerFile(options?: APIParsedOptions): Promise<void>;
23
+ //# sourceMappingURL=serverFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverFile.d.ts","sourceRoot":"","sources":["../src/serverFile.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAEjD;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CA4Bf"}
@@ -0,0 +1,35 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { getPaths } from "@cedarjs/project-config";
5
+ function apiDistServerFilePath() {
6
+ return path.join(getPaths().api.dist, "server.js");
7
+ }
8
+ function apiDistServerFileExists() {
9
+ return fs.existsSync(apiDistServerFilePath());
10
+ }
11
+ async function runApiDistServerFile(options = {}) {
12
+ const args = ["--apiRootPath", options.apiRootPath ?? "/"];
13
+ if (options.port !== void 0) {
14
+ args.push("--apiPort", String(options.port));
15
+ }
16
+ await new Promise((resolve, reject) => {
17
+ const child = spawn(process.execPath, [apiDistServerFilePath(), ...args], {
18
+ cwd: getPaths().api.dist,
19
+ stdio: "inherit"
20
+ });
21
+ child.on("error", reject);
22
+ child.on("exit", (code, signal) => {
23
+ if (signal || code === 0) {
24
+ resolve();
25
+ return;
26
+ }
27
+ reject(new Error(`api/dist/server.js exited with code ${code}`));
28
+ });
29
+ });
30
+ }
31
+ export {
32
+ apiDistServerFileExists,
33
+ apiDistServerFilePath,
34
+ runApiDistServerFile
35
+ };
package/dist/types.d.ts CHANGED
@@ -3,17 +3,17 @@ import type { CedarFastifyAPIOptions } from './plugins/api.js';
3
3
  export type FastifySideConfigFnOptions = {
4
4
  side: 'api' | 'web';
5
5
  };
6
- export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<CedarFastifyAPIOptions['redwood'], 'apiRootPath'>) => Promise<FastifyInstance> | void;
6
+ export type FastifySideConfigFn = (fastify: FastifyInstance, options?: FastifySideConfigFnOptions & Pick<CedarFastifyAPIOptions['cedar'], 'apiRootPath'>) => Promise<FastifyInstance> | void;
7
7
  export type APIParsedOptions = {
8
8
  port?: number;
9
9
  host?: string;
10
10
  loadEnvFiles?: boolean;
11
- } & Omit<CedarFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
11
+ } & Omit<CedarFastifyAPIOptions['cedar'], 'fastGlobOptions'>;
12
12
  export type BothParsedOptions = {
13
13
  webPort?: number;
14
14
  webHost?: string;
15
15
  apiPort?: number;
16
16
  apiHost?: string;
17
17
  apiRootPath?: string;
18
- } & Omit<CedarFastifyAPIOptions['redwood'], 'fastGlobOptions'>;
18
+ } & Omit<CedarFastifyAPIOptions['cedar'], 'fastGlobOptions'>;
19
19
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAG9D,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,0BAA0B,GAClC,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,KACrD,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAE9D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAG9D,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,CAChC,OAAO,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,0BAA0B,GAClC,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,KACnD,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAA;AAE5D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAA"}
package/dist/utils.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): T & {
2
- cancel: () => void;
3
- };
4
1
  /** Escapes HTML characters to prevent XSS attacks */
5
2
  export declare function escape(string: string): string;
6
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,GACX,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAsB5B;AAED,qDAAqD;AACrD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU7C"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAU7C"}
package/dist/utils.js CHANGED
@@ -1,22 +1,3 @@
1
- function debounce(func, wait) {
2
- let timeoutId = null;
3
- const debounced = ((...args) => {
4
- if (timeoutId !== null) {
5
- clearTimeout(timeoutId);
6
- }
7
- timeoutId = setTimeout(() => {
8
- timeoutId = null;
9
- func(...args);
10
- }, wait);
11
- });
12
- debounced.cancel = () => {
13
- if (timeoutId !== null) {
14
- clearTimeout(timeoutId);
15
- timeoutId = null;
16
- }
17
- };
18
- return debounced;
19
- }
20
1
  function escape(string) {
21
2
  const htmlEscapes = {
22
3
  "&": "&amp;",
@@ -28,6 +9,5 @@ function escape(string) {
28
9
  return string.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
29
10
  }
30
11
  export {
31
- debounce,
32
12
  escape
33
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/api-server",
3
- "version": "6.0.0-rc.189",
3
+ "version": "6.0.0-rc.221",
4
4
  "description": "CedarJS's HTTP server for Serverless Functions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -53,12 +53,6 @@
53
53
  "default": "./dist/fastify.js"
54
54
  }
55
55
  },
56
- "./watch": {
57
- "default": {
58
- "types": "./dist/watch.d.ts",
59
- "default": "./dist/watch.js"
60
- }
61
- },
62
56
  "./logFormatter": {
63
57
  "default": {
64
58
  "types": "./dist/logFormatter/index.d.ts",
@@ -75,10 +69,8 @@
75
69
  "main": "./dist/createServer.js",
76
70
  "types": "./dist/createServer.d.ts",
77
71
  "bin": {
78
- "cedar-api-server-watch": "./dist/watch.js",
79
72
  "cedar-log-formatter": "./dist/logFormatter/bin.js",
80
73
  "cedar-server": "./dist/bin.js",
81
- "cedarjs-api-server-watch": "./dist/watch.js",
82
74
  "cedarjs-log-formatter": "./dist/logFormatter/bin.js",
83
75
  "cedarjs-server": "./dist/bin.js",
84
76
  "rw-log-formatter": "./dist/logFormatter/bin.js",
@@ -94,22 +86,20 @@
94
86
  "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build && yarn fix:permissions\"",
95
87
  "check:attw": "yarn cedar-fwtools-attw",
96
88
  "check:package": "concurrently npm:check:attw yarn:publint",
97
- "fix:permissions": "chmod +x dist/index.js; chmod +x dist/watch.js",
89
+ "fix:permissions": "chmod +x dist/index.js",
98
90
  "prepublishOnly": "NODE_ENV=production yarn build",
99
91
  "test": "vitest run",
100
92
  "test:watch": "vitest watch"
101
93
  },
102
94
  "dependencies": {
103
- "@cedarjs/api": "6.0.0-rc.189",
104
- "@cedarjs/context": "6.0.0-rc.189",
105
- "@cedarjs/fastify-web": "6.0.0-rc.189",
106
- "@cedarjs/internal": "6.0.0-rc.189",
107
- "@cedarjs/project-config": "6.0.0-rc.189",
108
- "@cedarjs/web-server": "6.0.0-rc.189",
95
+ "@cedarjs/api": "6.0.0-rc.221",
96
+ "@cedarjs/context": "6.0.0-rc.221",
97
+ "@cedarjs/fastify-web": "6.0.0-rc.221",
98
+ "@cedarjs/project-config": "6.0.0-rc.221",
99
+ "@cedarjs/web-server": "6.0.0-rc.221",
109
100
  "@fastify/multipart": "9.4.0",
110
101
  "@fastify/url-data": "6.0.3",
111
102
  "ansis": "4.3.1",
112
- "chokidar": "3.6.0",
113
103
  "dotenv-defaults": "5.0.2",
114
104
  "fast-glob": "3.3.3",
115
105
  "fast-json-parse": "1.0.3",
@@ -123,7 +113,7 @@
123
113
  "yargs": "17.7.3"
124
114
  },
125
115
  "devDependencies": {
126
- "@cedarjs/framework-tools": "6.0.0-rc.189",
116
+ "@cedarjs/framework-tools": "6.0.0-rc.221",
127
117
  "@types/aws-lambda": "8.10.162",
128
118
  "@types/dotenv-defaults": "^5.0.0",
129
119
  "@types/split2": "4.2.3",
@@ -138,7 +128,7 @@
138
128
  "vitest": "4.1.10"
139
129
  },
140
130
  "peerDependencies": {
141
- "@cedarjs/graphql-server": "6.0.0-rc.189"
131
+ "@cedarjs/graphql-server": "6.0.0-rc.221"
142
132
  },
143
133
  "peerDependenciesMeta": {
144
134
  "@cedarjs/graphql-server": {
@@ -1,15 +0,0 @@
1
- export type BuildAndRestartOptions = {
2
- rebuild?: boolean;
3
- clean?: boolean;
4
- };
5
- declare class BuildManager {
6
- private shouldRebuild;
7
- private shouldClean;
8
- private debouncedBuild;
9
- private buildFn;
10
- constructor(buildFn: (options: BuildAndRestartOptions) => Promise<void>);
11
- run(options: BuildAndRestartOptions): Promise<void>;
12
- cancelScheduledBuild(): void;
13
- }
14
- export { BuildManager };
15
- //# sourceMappingURL=buildManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildManager.d.ts","sourceRoot":"","sources":["../src/buildManager.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,sBAAsB,GAAG;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,cAAM,YAAY;IAChB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,OAAO,CAAoD;gBAEvD,OAAO,EAAE,CAAC,OAAO,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC;IAsCjE,GAAG,CAAC,OAAO,EAAE,sBAAsB;IAWzC,oBAAoB;CAGrB;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
@@ -1,55 +0,0 @@
1
- import { debounce } from "./utils.js";
2
- class BuildManager {
3
- shouldRebuild;
4
- shouldClean;
5
- debouncedBuild;
6
- buildFn;
7
- constructor(buildFn) {
8
- this.shouldRebuild = true;
9
- this.shouldClean = false;
10
- this.buildFn = buildFn;
11
- if (process.env.RWJS_DELAY_RESTART) {
12
- console.warn(
13
- "[DEPRECATED] RWJS_DELAY_RESTART is deprecated and will be removed in the next major release. Please rename it to CEDAR_DELAY_API_RESTART in your .env file."
14
- );
15
- }
16
- const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
17
- this.debouncedBuild = debounce(
18
- async (options) => {
19
- try {
20
- await this.buildFn({
21
- ...options,
22
- rebuild: this.shouldRebuild,
23
- clean: this.shouldClean
24
- });
25
- } finally {
26
- this.shouldRebuild = true;
27
- this.shouldClean = false;
28
- }
29
- },
30
- // We want to delay execution when multiple files are modified on the
31
- // filesystem. This usually happens when running Cedar generator commands.
32
- // Local writes are very fast, but writes in e2e environments are not, so
33
- // allow the default to be adjusted with an env-var.
34
- delay ? parseInt(delay, 10) : 500
35
- );
36
- }
37
- // Wrapper method to handle options and set precedence flags.
38
- // If we ever see a `rebuild: false` option while debouncing, we never want to rebuild.
39
- // If we ever see a `clean: true` option, we always want to clean.
40
- async run(options) {
41
- if (options.rebuild === false) {
42
- this.shouldRebuild = false;
43
- }
44
- if (options.clean) {
45
- this.shouldClean = true;
46
- }
47
- await this.debouncedBuild(options);
48
- }
49
- cancelScheduledBuild() {
50
- this.debouncedBuild.cancel();
51
- }
52
- }
53
- export {
54
- BuildManager
55
- };
@@ -1,8 +0,0 @@
1
- export declare class ServerManager {
2
- private httpServerProcess;
3
- private startApiServer;
4
- restartApiServer(): Promise<void>;
5
- killApiServer(): Promise<void>;
6
- }
7
- export declare const serverManager: ServerManager;
8
- //# sourceMappingURL=serverManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serverManager.d.ts","sourceRoot":"","sources":["../src/serverManager.ts"],"names":[],"mappings":"AA0BA,qBAAa,aAAa;IACxB,OAAO,CAAC,iBAAiB,CAA4B;YAEvC,cAAc;IAsDtB,gBAAgB;IAKhB,aAAa;CAmCpB;AAED,eAAO,MAAM,aAAa,eAAsB,CAAA"}
@@ -1,102 +0,0 @@
1
- import { fork } from "child_process";
2
- import fs from "node:fs";
3
- import path from "path";
4
- import ansis from "ansis";
5
- import yargs from "yargs";
6
- import { hideBin } from "yargs/helpers";
7
- import { getConfig, getPaths, resolveFile } from "@cedarjs/project-config";
8
- const argv = yargs(hideBin(process.argv)).option("debugPort", {
9
- description: "Port on which to expose API server debugger",
10
- type: "number",
11
- alias: ["debug-port", "dp"]
12
- }).option("port", {
13
- description: "The port to listen at",
14
- type: "number",
15
- alias: "p"
16
- }).parseSync();
17
- const rwjsPaths = getPaths();
18
- class ServerManager {
19
- httpServerProcess = null;
20
- async startApiServer() {
21
- const forkOpts = {
22
- execArgv: process.execArgv
23
- };
24
- if (getConfig().experimental.opentelemetry.enabled) {
25
- const opentelemetrySDKScriptPath = path.join(
26
- rwjsPaths.api.dist,
27
- "opentelemetry.js"
28
- );
29
- const opentelemetrySDKScriptPathRelative = path.relative(
30
- rwjsPaths.base,
31
- opentelemetrySDKScriptPath
32
- );
33
- console.log(
34
- `Setting up OpenTelemetry using the setup file: ${opentelemetrySDKScriptPathRelative}`
35
- );
36
- if (fs.existsSync(opentelemetrySDKScriptPath)) {
37
- forkOpts.execArgv = forkOpts.execArgv.concat([
38
- `--require=${opentelemetrySDKScriptPath}`
39
- ]);
40
- } else {
41
- console.error(
42
- `OpenTelemetry setup file does not exist at ${opentelemetrySDKScriptPathRelative}`
43
- );
44
- }
45
- }
46
- const debugPort = argv["debug-port"];
47
- if (debugPort) {
48
- forkOpts.execArgv = forkOpts.execArgv.concat([`--inspect=${debugPort}`]);
49
- }
50
- const port = argv.port ?? getConfig().api.port;
51
- const serverFile = resolveFile(`${rwjsPaths.api.dist}/server`);
52
- if (serverFile) {
53
- this.httpServerProcess = fork(
54
- serverFile,
55
- ["--apiPort", port.toString()],
56
- forkOpts
57
- );
58
- } else {
59
- const dirname = import.meta.dirname;
60
- const binPath = path.join(dirname, "bin.js");
61
- const args = ["api", "--port", port.toString()];
62
- this.httpServerProcess = fork(binPath, args, forkOpts);
63
- }
64
- }
65
- async restartApiServer() {
66
- await this.killApiServer();
67
- await this.startApiServer();
68
- }
69
- async killApiServer() {
70
- if (!this.httpServerProcess) {
71
- return;
72
- }
73
- await new Promise((resolve) => {
74
- console.log(ansis.yellow("Shutting down API server."));
75
- const cleanup = () => {
76
- this.httpServerProcess?.removeAllListeners("exit");
77
- clearTimeout(forceKillTimeout);
78
- };
79
- this.httpServerProcess?.on("exit", () => {
80
- console.log(ansis.yellow("API server exited."));
81
- cleanup();
82
- resolve();
83
- });
84
- const forceKillTimeout = setTimeout(() => {
85
- console.log(
86
- ansis.yellow(
87
- "API server did not exit within 2 seconds, forcefully closing it."
88
- )
89
- );
90
- cleanup();
91
- this.httpServerProcess?.kill("SIGKILL");
92
- resolve();
93
- }, 2e3);
94
- this.httpServerProcess?.kill();
95
- });
96
- }
97
- }
98
- const serverManager = new ServerManager();
99
- export {
100
- ServerManager,
101
- serverManager
102
- };
package/dist/watch.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * Initialize the file watcher for the API server
3
- * Watches for changes in the API source directory and rebuilds/restarts as
4
- * needed
5
- *
6
- * Also watches package sources so that changes to workspace packages used by
7
- * the API trigger a rebuild/restart (HMR for API-side workspace packages).
8
- */
9
- export declare function startWatch(): Promise<void>;
10
- //# sourceMappingURL=watch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAqEA;;;;;;;GAOG;AACH,wBAAsB,UAAU,kBAsD/B"}