@cedarjs/api-server 9.0.0-canary.1784 → 9.0.0-canary.3124

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 (127) 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 +316 -98
  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 +22 -4
  12. package/dist/cliHelpers.d.ts.map +1 -1
  13. package/dist/cliHelpers.js +43 -11
  14. package/dist/createServer.d.ts +19 -3
  15. package/dist/createServer.d.ts.map +1 -1
  16. package/dist/createServer.js +18 -11
  17. package/dist/createServerHelpers.d.ts +15 -2
  18. package/dist/createServerHelpers.d.ts.map +1 -1
  19. package/dist/createServerHelpers.js +14 -4
  20. package/dist/fastify.d.ts.map +1 -1
  21. package/dist/fastify.js +5 -0
  22. package/dist/logFormatter/formatters.d.ts +1 -1
  23. package/dist/logFormatter/formatters.d.ts.map +1 -1
  24. package/dist/logFormatter/index.d.ts.map +1 -1
  25. package/dist/plugins/api.d.ts +4 -5
  26. package/dist/plugins/api.d.ts.map +1 -1
  27. package/dist/plugins/api.js +15 -15
  28. package/dist/plugins/graphql.d.ts +20 -3
  29. package/dist/plugins/graphql.d.ts.map +1 -1
  30. package/dist/plugins/graphql.js +69 -28
  31. package/dist/plugins/lambdaLoader.d.ts +16 -6
  32. package/dist/plugins/lambdaLoader.d.ts.map +1 -1
  33. package/dist/plugins/lambdaLoader.js +73 -10
  34. package/dist/requestHandlers/awsLambdaFastify.d.ts.map +1 -1
  35. package/dist/requestHandlers/awsLambdaFastify.js +16 -4
  36. package/dist/serverFile.d.ts +23 -0
  37. package/dist/serverFile.d.ts.map +1 -0
  38. package/dist/serverFile.js +35 -0
  39. package/dist/types.d.ts +4 -4
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils.d.ts +0 -3
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +0 -20
  44. package/package.json +56 -72
  45. package/LICENSE +0 -21
  46. package/dist/buildManager.d.ts +0 -15
  47. package/dist/buildManager.d.ts.map +0 -1
  48. package/dist/buildManager.js +0 -50
  49. package/dist/cjs/apiCLIConfig.d.ts +0 -6
  50. package/dist/cjs/apiCLIConfig.d.ts.map +0 -1
  51. package/dist/cjs/apiCLIConfig.js +0 -71
  52. package/dist/cjs/apiCLIConfigHandler.d.ts +0 -3
  53. package/dist/cjs/apiCLIConfigHandler.d.ts.map +0 -1
  54. package/dist/cjs/apiCLIConfigHandler.js +0 -67
  55. package/dist/cjs/bin.d.ts +0 -2
  56. package/dist/cjs/bin.d.ts.map +0 -1
  57. package/dist/cjs/bin.js +0 -896
  58. package/dist/cjs/bothCLIConfig.d.ts +0 -6
  59. package/dist/cjs/bothCLIConfig.d.ts.map +0 -1
  60. package/dist/cjs/bothCLIConfig.js +0 -76
  61. package/dist/cjs/bothCLIConfigHandler.d.ts +0 -3
  62. package/dist/cjs/bothCLIConfigHandler.d.ts.map +0 -1
  63. package/dist/cjs/bothCLIConfigHandler.js +0 -107
  64. package/dist/cjs/buildManager.d.ts +0 -15
  65. package/dist/cjs/buildManager.d.ts.map +0 -1
  66. package/dist/cjs/buildManager.js +0 -74
  67. package/dist/cjs/cliHelpers.d.ts +0 -5
  68. package/dist/cjs/cliHelpers.d.ts.map +0 -1
  69. package/dist/cjs/cliHelpers.js +0 -52
  70. package/dist/cjs/createServer.d.ts +0 -30
  71. package/dist/cjs/createServer.d.ts.map +0 -1
  72. package/dist/cjs/createServer.js +0 -144
  73. package/dist/cjs/createServerHelpers.d.ts +0 -38
  74. package/dist/cjs/createServerHelpers.d.ts.map +0 -1
  75. package/dist/cjs/createServerHelpers.js +0 -112
  76. package/dist/cjs/fastify.d.ts +0 -13
  77. package/dist/cjs/fastify.d.ts.map +0 -1
  78. package/dist/cjs/fastify.js +0 -91
  79. package/dist/cjs/logFormatter/ambient.d.js +0 -1
  80. package/dist/cjs/logFormatter/bin.d.ts +0 -2
  81. package/dist/cjs/logFormatter/bin.d.ts.map +0 -1
  82. package/dist/cjs/logFormatter/bin.js +0 -369
  83. package/dist/cjs/logFormatter/formatters.d.ts +0 -30
  84. package/dist/cjs/logFormatter/formatters.d.ts.map +0 -1
  85. package/dist/cjs/logFormatter/formatters.js +0 -275
  86. package/dist/cjs/logFormatter/index.d.ts +0 -2
  87. package/dist/cjs/logFormatter/index.d.ts.map +0 -1
  88. package/dist/cjs/logFormatter/index.js +0 -184
  89. package/dist/cjs/package.json +0 -1
  90. package/dist/cjs/plugins/api.d.ts +0 -14
  91. package/dist/cjs/plugins/api.d.ts.map +0 -1
  92. package/dist/cjs/plugins/api.js +0 -78
  93. package/dist/cjs/plugins/graphql.d.ts +0 -10
  94. package/dist/cjs/plugins/graphql.d.ts.map +0 -1
  95. package/dist/cjs/plugins/graphql.js +0 -109
  96. package/dist/cjs/plugins/lambdaLoader.d.ts +0 -24
  97. package/dist/cjs/plugins/lambdaLoader.d.ts.map +0 -1
  98. package/dist/cjs/plugins/lambdaLoader.js +0 -134
  99. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts +0 -5
  100. package/dist/cjs/requestHandlers/awsLambdaFastify.d.ts.map +0 -1
  101. package/dist/cjs/requestHandlers/awsLambdaFastify.js +0 -103
  102. package/dist/cjs/requestHandlers/utils.d.ts +0 -26
  103. package/dist/cjs/requestHandlers/utils.d.ts.map +0 -1
  104. package/dist/cjs/requestHandlers/utils.js +0 -55
  105. package/dist/cjs/serverManager.d.ts +0 -8
  106. package/dist/cjs/serverManager.d.ts.map +0 -1
  107. package/dist/cjs/serverManager.js +0 -137
  108. package/dist/cjs/types.d.ts +0 -19
  109. package/dist/cjs/types.d.ts.map +0 -1
  110. package/dist/cjs/utils.d.ts +0 -6
  111. package/dist/cjs/utils.d.ts.map +0 -1
  112. package/dist/cjs/utils.js +0 -58
  113. package/dist/cjs/watch.d.ts +0 -10
  114. package/dist/cjs/watch.d.ts.map +0 -1
  115. package/dist/cjs/watch.js +0 -394
  116. package/dist/cjs/watchPaths.d.ts +0 -3
  117. package/dist/cjs/watchPaths.d.ts.map +0 -1
  118. package/dist/cjs/watchPaths.js +0 -140
  119. package/dist/serverManager.d.ts +0 -8
  120. package/dist/serverManager.d.ts.map +0 -1
  121. package/dist/serverManager.js +0 -102
  122. package/dist/watch.d.ts +0 -10
  123. package/dist/watch.d.ts.map +0 -1
  124. package/dist/watch.js +0 -370
  125. package/dist/watchPaths.d.ts +0 -3
  126. package/dist/watchPaths.d.ts.map +0 -1
  127. package/dist/watchPaths.js +0 -109
package/dist/cjs/watch.js DELETED
@@ -1,394 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/watch.ts
32
- var watch_exports = {};
33
- __export(watch_exports, {
34
- startWatch: () => startWatch
35
- });
36
- module.exports = __toCommonJS(watch_exports);
37
- var import_node_path2 = __toESM(require("node:path"), 1);
38
- var import_ansis2 = __toESM(require("ansis"), 1);
39
- var import_chokidar = __toESM(require("chokidar"), 1);
40
- var import_dotenv_defaults = require("dotenv-defaults");
41
- var import_api = require("@cedarjs/internal/dist/build/api");
42
- var import_validateSchema = require("@cedarjs/internal/dist/validateSchema");
43
- var import_project_config3 = require("@cedarjs/project-config");
44
-
45
- // src/utils.ts
46
- function debounce(func, wait) {
47
- let timeoutId = null;
48
- const debounced = (...args) => {
49
- if (timeoutId !== null) {
50
- clearTimeout(timeoutId);
51
- }
52
- timeoutId = setTimeout(() => {
53
- timeoutId = null;
54
- func(...args);
55
- }, wait);
56
- };
57
- debounced.cancel = () => {
58
- if (timeoutId !== null) {
59
- clearTimeout(timeoutId);
60
- timeoutId = null;
61
- }
62
- };
63
- return debounced;
64
- }
65
-
66
- // src/buildManager.ts
67
- var BuildManager = class {
68
- shouldRebuild;
69
- shouldClean;
70
- debouncedBuild;
71
- buildFn;
72
- constructor(buildFn) {
73
- this.shouldRebuild = true;
74
- this.shouldClean = false;
75
- this.buildFn = buildFn;
76
- const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
77
- this.debouncedBuild = debounce(
78
- async (options) => {
79
- try {
80
- await this.buildFn({
81
- ...options,
82
- rebuild: this.shouldRebuild,
83
- clean: this.shouldClean
84
- });
85
- } finally {
86
- this.shouldRebuild = true;
87
- this.shouldClean = false;
88
- }
89
- },
90
- // We want to delay execution when multiple files are modified on the
91
- // filesystem. This usually happens when running Cedar generator commands.
92
- // Local writes are very fast, but writes in e2e environments are not, so
93
- // allow the default to be adjusted with an env-var.
94
- delay ? parseInt(delay, 10) : 500
95
- );
96
- }
97
- // Wrapper method to handle options and set precedence flags.
98
- // If we ever see a `rebuild: false` option while debouncing, we never want to rebuild.
99
- // If we ever see a `clean: true` option, we always want to clean.
100
- async run(options) {
101
- if (options.rebuild === false) {
102
- this.shouldRebuild = false;
103
- }
104
- if (options.clean) {
105
- this.shouldClean = true;
106
- }
107
- await this.debouncedBuild(options);
108
- }
109
- cancelScheduledBuild() {
110
- this.debouncedBuild.cancel();
111
- }
112
- };
113
-
114
- // src/serverManager.ts
115
- var import_child_process = require("child_process");
116
- var import_node_fs = __toESM(require("node:fs"), 1);
117
- var import_path = __toESM(require("path"), 1);
118
- var import_ansis = __toESM(require("ansis"), 1);
119
- var import_yargs = __toESM(require("yargs"), 1);
120
- var import_helpers = require("yargs/helpers");
121
- var import_project_config = require("@cedarjs/project-config");
122
- var argv = (0, import_yargs.default)((0, import_helpers.hideBin)(process.argv)).option("debugPort", {
123
- description: "Port on which to expose API server debugger",
124
- type: "number",
125
- alias: ["debug-port", "dp"]
126
- }).option("port", {
127
- description: "The port to listen at",
128
- type: "number",
129
- alias: "p"
130
- }).parseSync();
131
- var rwjsPaths = (0, import_project_config.getPaths)();
132
- var ServerManager = class {
133
- httpServerProcess = null;
134
- async startApiServer() {
135
- const forkOpts = {
136
- execArgv: process.execArgv
137
- };
138
- if ((0, import_project_config.getConfig)().experimental.opentelemetry.enabled) {
139
- const opentelemetrySDKScriptPath = import_path.default.join(
140
- rwjsPaths.api.dist,
141
- "opentelemetry.js"
142
- );
143
- const opentelemetrySDKScriptPathRelative = import_path.default.relative(
144
- rwjsPaths.base,
145
- opentelemetrySDKScriptPath
146
- );
147
- console.log(
148
- `Setting up OpenTelemetry using the setup file: ${opentelemetrySDKScriptPathRelative}`
149
- );
150
- if (import_node_fs.default.existsSync(opentelemetrySDKScriptPath)) {
151
- forkOpts.execArgv = forkOpts.execArgv.concat([
152
- `--require=${opentelemetrySDKScriptPath}`
153
- ]);
154
- } else {
155
- console.error(
156
- `OpenTelemetry setup file does not exist at ${opentelemetrySDKScriptPathRelative}`
157
- );
158
- }
159
- }
160
- const debugPort = argv["debug-port"];
161
- if (debugPort) {
162
- forkOpts.execArgv = forkOpts.execArgv.concat([`--inspect=${debugPort}`]);
163
- }
164
- const port = argv.port ?? (0, import_project_config.getConfig)().api.port;
165
- const serverFile = (0, import_project_config.resolveFile)(`${rwjsPaths.api.dist}/server`);
166
- if (serverFile) {
167
- this.httpServerProcess = (0, import_child_process.fork)(
168
- serverFile,
169
- ["--apiPort", port.toString()],
170
- forkOpts
171
- );
172
- } else {
173
- const dirname = __dirname;
174
- const binPath = import_path.default.join(dirname, "bin.js");
175
- const args = ["api", "--port", port.toString()];
176
- this.httpServerProcess = (0, import_child_process.fork)(binPath, args, forkOpts);
177
- }
178
- }
179
- async restartApiServer() {
180
- await this.killApiServer();
181
- await this.startApiServer();
182
- }
183
- async killApiServer() {
184
- if (!this.httpServerProcess) {
185
- return;
186
- }
187
- await new Promise((resolve) => {
188
- console.log(import_ansis.default.yellow("Shutting down API server."));
189
- const cleanup = () => {
190
- this.httpServerProcess?.removeAllListeners("exit");
191
- clearTimeout(forceKillTimeout);
192
- };
193
- this.httpServerProcess?.on("exit", () => {
194
- console.log(import_ansis.default.yellow("API server exited."));
195
- cleanup();
196
- resolve();
197
- });
198
- const forceKillTimeout = setTimeout(() => {
199
- console.log(
200
- import_ansis.default.yellow(
201
- "API server did not exit within 2 seconds, forcefully closing it."
202
- )
203
- );
204
- cleanup();
205
- this.httpServerProcess?.kill("SIGKILL");
206
- resolve();
207
- }, 2e3);
208
- this.httpServerProcess?.kill();
209
- });
210
- }
211
- };
212
- var serverManager = new ServerManager();
213
-
214
- // src/watchPaths.ts
215
- var import_node_fs2 = __toESM(require("node:fs"), 1);
216
- var import_node_path = __toESM(require("node:path"), 1);
217
- var import_project_config2 = require("@cedarjs/project-config");
218
- async function workspacePackagesPaths() {
219
- const cedarPaths2 = (0, import_project_config2.getPaths)();
220
- const packagesDir = import_node_path.default.join(cedarPaths2.packages);
221
- const packages = [];
222
- try {
223
- const rootPackageJsonPath = import_node_path.default.join(cedarPaths2.base, "package.json");
224
- const rootPackageJson = JSON.parse(
225
- import_node_fs2.default.readFileSync(rootPackageJsonPath, "utf8")
226
- );
227
- const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some((w) => w.startsWith("packages/"));
228
- if (!hasPackageJsonWorkspaces || !import_node_fs2.default.existsSync(packagesDir)) {
229
- return [];
230
- }
231
- const globPattern = import_node_path.default.join(packagesDir, "*").replaceAll("\\", "/");
232
- const packageDirs = await Array.fromAsync(import_node_fs2.default.promises.glob(globPattern));
233
- const apiPackageJsonPath = import_node_path.default.join(cedarPaths2.api.base, "package.json");
234
- const apiPackageJson = JSON.parse(
235
- import_node_fs2.default.readFileSync(apiPackageJsonPath, "utf8")
236
- );
237
- const deps = {
238
- ...apiPackageJson.dependencies ?? {},
239
- ...apiPackageJson.devDependencies ?? {},
240
- ...apiPackageJson.peerDependencies ?? {}
241
- };
242
- const workspaceDepNames = /* @__PURE__ */ new Set();
243
- for (const [name, version] of Object.entries(deps)) {
244
- if (String(version).startsWith("workspace:")) {
245
- workspaceDepNames.add(name);
246
- }
247
- }
248
- for (const packageDir of packageDirs) {
249
- const packageJsonPath = import_node_path.default.join(packageDir, "package.json");
250
- if (!import_node_fs2.default.existsSync(packageJsonPath)) {
251
- continue;
252
- }
253
- const pkgJson = JSON.parse(import_node_fs2.default.readFileSync(packageJsonPath, "utf8"));
254
- if (workspaceDepNames.has(pkgJson.name)) {
255
- packages.push(import_node_path.default.join(packageDir, "dist"));
256
- }
257
- }
258
- } catch {
259
- }
260
- return packages;
261
- }
262
- async function apiIgnorePaths() {
263
- const cedarPaths2 = (0, import_project_config2.getPaths)();
264
- const dbDir = await (0, import_project_config2.getDbDir)(cedarPaths2.api.prismaConfig);
265
- if (dbDir === cedarPaths2.api.base) {
266
- throw new Error(
267
- "Database directory cannot be the same as the API directory"
268
- );
269
- }
270
- const ignoredApiPaths = [
271
- // TODO: Is this still true?
272
- // use this, because using cedarPaths.api.dist seems to not ignore on first
273
- // build
274
- "api/dist",
275
- cedarPaths2.api.types,
276
- dbDir
277
- ];
278
- return ignoredApiPaths;
279
- }
280
- async function getIgnoreFunction() {
281
- const cedarPaths2 = (0, import_project_config2.getPaths)();
282
- const ignoredApiPaths = await apiIgnorePaths();
283
- const ignoredExtensions = [
284
- ".DS_Store",
285
- ".db",
286
- ".sqlite",
287
- "-journal",
288
- ".test.js",
289
- ".test.ts",
290
- ".scenarios.ts",
291
- ".scenarios.js",
292
- ".d.ts",
293
- ".log"
294
- ];
295
- return (file) => {
296
- if (file.includes("node_modules")) {
297
- return true;
298
- }
299
- if (ignoredExtensions.some((ext) => file.endsWith(ext))) {
300
- return true;
301
- }
302
- if (file.includes((0, import_project_config2.importStatementPath)(cedarPaths2.packages)) && file.includes("/src/")) {
303
- return true;
304
- }
305
- if (ignoredApiPaths.some((ignoredPath) => file.includes(ignoredPath))) {
306
- return true;
307
- }
308
- return false;
309
- };
310
- }
311
- async function pathsToWatch() {
312
- const cedarPaths2 = (0, import_project_config2.getPaths)();
313
- const watchPaths = [cedarPaths2.api.src, ...await workspacePackagesPaths()];
314
- return watchPaths.map((p) => (0, import_project_config2.importStatementPath)(p));
315
- }
316
-
317
- // src/watch.ts
318
- var cedarPaths = (0, import_project_config3.getPaths)();
319
- if (!process.env.REDWOOD_ENV_FILES_LOADED) {
320
- (0, import_dotenv_defaults.config)({
321
- path: import_node_path2.default.join(cedarPaths.base, ".env"),
322
- defaults: import_node_path2.default.join(cedarPaths.base, ".env.defaults"),
323
- multiline: true
324
- });
325
- process.env.REDWOOD_ENV_FILES_LOADED = "true";
326
- }
327
- async function buildAndServe(options) {
328
- const buildTs = Date.now();
329
- console.log(import_ansis2.default.dim.italic("Building..."));
330
- if (options.clean) {
331
- await (0, import_api.cleanApiBuild)();
332
- }
333
- if (options.rebuild) {
334
- await (0, import_api.rebuildApi)();
335
- } else {
336
- await (0, import_api.buildApi)();
337
- }
338
- await serverManager.restartApiServer();
339
- console.log(import_ansis2.default.dim.italic("Took " + (Date.now() - buildTs) + " ms"));
340
- }
341
- var buildManager = new BuildManager(buildAndServe);
342
- async function validateSdls() {
343
- try {
344
- await (0, import_validateSchema.loadAndValidateSdls)();
345
- return true;
346
- } catch (e) {
347
- serverManager.killApiServer();
348
- console.error(
349
- import_ansis2.default.redBright(`[GQL Server Error] - Schema validation failed`)
350
- );
351
- console.error(import_ansis2.default.red(e?.message));
352
- console.error(import_ansis2.default.redBright("-".repeat(40)));
353
- buildManager.cancelScheduledBuild();
354
- return false;
355
- }
356
- }
357
- async function startWatch() {
358
- const patterns = await pathsToWatch();
359
- const watcher = import_chokidar.default.watch(patterns, {
360
- persistent: true,
361
- ignoreInitial: true,
362
- ignored: await getIgnoreFunction()
363
- });
364
- watcher.on("ready", async () => {
365
- await buildManager.run({ clean: true, rebuild: false });
366
- await validateSdls();
367
- });
368
- watcher.on("all", async (eventName, filePath) => {
369
- if (eventName === "addDir" && filePath === cedarPaths.api.base) {
370
- return;
371
- }
372
- if (eventName) {
373
- if (filePath.includes(".sdl")) {
374
- const isValid = await validateSdls();
375
- if (!isValid) {
376
- return;
377
- }
378
- }
379
- }
380
- const displayPath = import_node_path2.default.relative(cedarPaths.base, filePath);
381
- console.log(import_ansis2.default.dim(`[${eventName}] ${displayPath}`));
382
- buildManager.cancelScheduledBuild();
383
- if (eventName === "add" || eventName === "unlink") {
384
- await buildManager.run({ rebuild: false });
385
- } else {
386
- await buildManager.run({ rebuild: true });
387
- }
388
- });
389
- }
390
- startWatch();
391
- // Annotate the CommonJS export names for ESM import in node:
392
- 0 && (module.exports = {
393
- startWatch
394
- });
@@ -1,3 +0,0 @@
1
- export declare function getIgnoreFunction(): Promise<(file: string) => boolean>;
2
- export declare function pathsToWatch(): Promise<string[]>;
3
- //# sourceMappingURL=watchPaths.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watchPaths.d.ts","sourceRoot":"","sources":["../../src/watchPaths.ts"],"names":[],"mappings":"AAmGA,wBAAsB,iBAAiB,mBAqBvB,MAAM,cAwBrB;AAED,wBAAsB,YAAY,sBAQjC"}
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var watchPaths_exports = {};
30
- __export(watchPaths_exports, {
31
- getIgnoreFunction: () => getIgnoreFunction,
32
- pathsToWatch: () => pathsToWatch
33
- });
34
- module.exports = __toCommonJS(watchPaths_exports);
35
- var import_node_fs = __toESM(require("node:fs"), 1);
36
- var import_node_path = __toESM(require("node:path"), 1);
37
- var import_project_config = require("@cedarjs/project-config");
38
- async function workspacePackagesPaths() {
39
- const cedarPaths = (0, import_project_config.getPaths)();
40
- const packagesDir = import_node_path.default.join(cedarPaths.packages);
41
- const packages = [];
42
- try {
43
- const rootPackageJsonPath = import_node_path.default.join(cedarPaths.base, "package.json");
44
- const rootPackageJson = JSON.parse(
45
- import_node_fs.default.readFileSync(rootPackageJsonPath, "utf8")
46
- );
47
- const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some((w) => w.startsWith("packages/"));
48
- if (!hasPackageJsonWorkspaces || !import_node_fs.default.existsSync(packagesDir)) {
49
- return [];
50
- }
51
- const globPattern = import_node_path.default.join(packagesDir, "*").replaceAll("\\", "/");
52
- const packageDirs = await Array.fromAsync(import_node_fs.default.promises.glob(globPattern));
53
- const apiPackageJsonPath = import_node_path.default.join(cedarPaths.api.base, "package.json");
54
- const apiPackageJson = JSON.parse(
55
- import_node_fs.default.readFileSync(apiPackageJsonPath, "utf8")
56
- );
57
- const deps = {
58
- ...apiPackageJson.dependencies ?? {},
59
- ...apiPackageJson.devDependencies ?? {},
60
- ...apiPackageJson.peerDependencies ?? {}
61
- };
62
- const workspaceDepNames = /* @__PURE__ */ new Set();
63
- for (const [name, version] of Object.entries(deps)) {
64
- if (String(version).startsWith("workspace:")) {
65
- workspaceDepNames.add(name);
66
- }
67
- }
68
- for (const packageDir of packageDirs) {
69
- const packageJsonPath = import_node_path.default.join(packageDir, "package.json");
70
- if (!import_node_fs.default.existsSync(packageJsonPath)) {
71
- continue;
72
- }
73
- const pkgJson = JSON.parse(import_node_fs.default.readFileSync(packageJsonPath, "utf8"));
74
- if (workspaceDepNames.has(pkgJson.name)) {
75
- packages.push(import_node_path.default.join(packageDir, "dist"));
76
- }
77
- }
78
- } catch {
79
- }
80
- return packages;
81
- }
82
- async function apiIgnorePaths() {
83
- const cedarPaths = (0, import_project_config.getPaths)();
84
- const dbDir = await (0, import_project_config.getDbDir)(cedarPaths.api.prismaConfig);
85
- if (dbDir === cedarPaths.api.base) {
86
- throw new Error(
87
- "Database directory cannot be the same as the API directory"
88
- );
89
- }
90
- const ignoredApiPaths = [
91
- // TODO: Is this still true?
92
- // use this, because using cedarPaths.api.dist seems to not ignore on first
93
- // build
94
- "api/dist",
95
- cedarPaths.api.types,
96
- dbDir
97
- ];
98
- return ignoredApiPaths;
99
- }
100
- async function getIgnoreFunction() {
101
- const cedarPaths = (0, import_project_config.getPaths)();
102
- const ignoredApiPaths = await apiIgnorePaths();
103
- const ignoredExtensions = [
104
- ".DS_Store",
105
- ".db",
106
- ".sqlite",
107
- "-journal",
108
- ".test.js",
109
- ".test.ts",
110
- ".scenarios.ts",
111
- ".scenarios.js",
112
- ".d.ts",
113
- ".log"
114
- ];
115
- return (file) => {
116
- if (file.includes("node_modules")) {
117
- return true;
118
- }
119
- if (ignoredExtensions.some((ext) => file.endsWith(ext))) {
120
- return true;
121
- }
122
- if (file.includes((0, import_project_config.importStatementPath)(cedarPaths.packages)) && file.includes("/src/")) {
123
- return true;
124
- }
125
- if (ignoredApiPaths.some((ignoredPath) => file.includes(ignoredPath))) {
126
- return true;
127
- }
128
- return false;
129
- };
130
- }
131
- async function pathsToWatch() {
132
- const cedarPaths = (0, import_project_config.getPaths)();
133
- const watchPaths = [cedarPaths.api.src, ...await workspacePackagesPaths()];
134
- return watchPaths.map((p) => (0, import_project_config.importStatementPath)(p));
135
- }
136
- // Annotate the CommonJS export names for ESM import in node:
137
- 0 && (module.exports = {
138
- getIgnoreFunction,
139
- pathsToWatch
140
- });
@@ -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":"AA6BA,qBAAa,aAAa;IACxB,OAAO,CAAC,iBAAiB,CAA4B;YAEvC,cAAc;IAyDtB,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":"AAwEA;;;;;;;GAOG;AACH,wBAAsB,UAAU,kBAsD/B"}