@cedarjs/api-server 2.4.2-next.0 → 2.5.0-rc.146
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 +7 -7
- package/dist/buildManager.js +6 -6
- package/dist/cjs/buildManager.js +6 -6
- package/dist/cjs/createServerHelpers.d.ts +2 -2
- package/dist/cjs/createServerHelpers.d.ts.map +1 -1
- package/dist/cjs/watch.d.ts +3 -0
- package/dist/cjs/watch.d.ts.map +1 -1
- package/dist/cjs/watch.js +116 -39
- package/dist/cjs/watchPaths.d.ts +3 -0
- package/dist/cjs/watchPaths.d.ts.map +1 -0
- package/dist/cjs/watchPaths.js +137 -0
- package/dist/createServerHelpers.d.ts +2 -2
- package/dist/createServerHelpers.d.ts.map +1 -1
- package/dist/watch.d.ts +3 -0
- package/dist/watch.d.ts.map +1 -1
- package/dist/watch.js +120 -39
- package/dist/watchPaths.d.ts +3 -0
- package/dist/watchPaths.d.ts.map +1 -0
- package/dist/watchPaths.js +106 -0
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -36,18 +36,18 @@ run the API and (if needed) Web servers independently, along with tools like
|
|
|
36
36
|
PM2, Nginx, or Kubernetes, which appropriately handle concurrent requests,
|
|
37
37
|
errors, static asset, etc. for production contexts.
|
|
38
38
|
|
|
39
|
-
- Runs web on
|
|
40
|
-
- API listens on web port at path
|
|
39
|
+
- Runs web on cedar.toml web.port (default 8910)
|
|
40
|
+
- API listens on web port at path cedar.toml web.apiUrl
|
|
41
41
|
- Command Options:
|
|
42
42
|
- port (default 8910)
|
|
43
43
|
- socket (optional)
|
|
44
|
-
- apiHost (default
|
|
44
|
+
- apiHost (default cedar.toml web.apiUrl)
|
|
45
45
|
|
|
46
46
|
### `cedarjs-server api`
|
|
47
47
|
|
|
48
48
|
For production use.
|
|
49
49
|
|
|
50
|
-
- Runs api on
|
|
50
|
+
- Runs api on cedar.toml api.port (default 8911)
|
|
51
51
|
- Command Options:
|
|
52
52
|
- port (default 8911)
|
|
53
53
|
- socket (optional)
|
|
@@ -59,9 +59,9 @@ Not optimized for production use at scale (see comments above for
|
|
|
59
59
|
`cedarjs-server`).
|
|
60
60
|
Recommended to use CDN or Nginx as performant alternatives.
|
|
61
61
|
|
|
62
|
-
- Runs web on
|
|
63
|
-
- GraphQL endpoint is set to
|
|
62
|
+
- Runs web on cedar.toml web.port (default 8910)
|
|
63
|
+
- GraphQL endpoint is set to cedar.toml web.apiUrl/graphql
|
|
64
64
|
- Command Options:
|
|
65
65
|
- port (default 8910)
|
|
66
66
|
- socket (optional)
|
|
67
|
-
- apiHost (default
|
|
67
|
+
- apiHost (default cedar.toml web.apiUrl)
|
package/dist/buildManager.js
CHANGED
|
@@ -8,6 +8,7 @@ class BuildManager {
|
|
|
8
8
|
this.shouldRebuild = true;
|
|
9
9
|
this.shouldClean = false;
|
|
10
10
|
this.buildFn = buildFn;
|
|
11
|
+
const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
|
|
11
12
|
this.debouncedBuild = debounce(
|
|
12
13
|
async (options) => {
|
|
13
14
|
try {
|
|
@@ -21,12 +22,11 @@ class BuildManager {
|
|
|
21
22
|
this.shouldClean = false;
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
|
-
// We want to delay execution when multiple files are modified on the
|
|
25
|
-
//
|
|
26
|
-
// Local writes are very fast, but writes in e2e environments are not,
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
process.env.RWJS_DELAY_RESTART ? parseInt(process.env.RWJS_DELAY_RESTART, 10) : 500
|
|
25
|
+
// We want to delay execution when multiple files are modified on the
|
|
26
|
+
// filesystem. This usually happens when running Cedar generator commands.
|
|
27
|
+
// Local writes are very fast, but writes in e2e environments are not, so
|
|
28
|
+
// allow the default to be adjusted with an env-var.
|
|
29
|
+
delay ? parseInt(delay, 10) : 500
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
// Wrapper method to handle options and set precedence flags.
|
package/dist/cjs/buildManager.js
CHANGED
|
@@ -31,6 +31,7 @@ class BuildManager {
|
|
|
31
31
|
this.shouldRebuild = true;
|
|
32
32
|
this.shouldClean = false;
|
|
33
33
|
this.buildFn = buildFn;
|
|
34
|
+
const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
|
|
34
35
|
this.debouncedBuild = (0, import_utils.debounce)(
|
|
35
36
|
async (options) => {
|
|
36
37
|
try {
|
|
@@ -44,12 +45,11 @@ class BuildManager {
|
|
|
44
45
|
this.shouldClean = false;
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
|
-
// We want to delay execution when multiple files are modified on the
|
|
48
|
-
//
|
|
49
|
-
// Local writes are very fast, but writes in e2e environments are not,
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
process.env.RWJS_DELAY_RESTART ? parseInt(process.env.RWJS_DELAY_RESTART, 10) : 500
|
|
48
|
+
// We want to delay execution when multiple files are modified on the
|
|
49
|
+
// filesystem. This usually happens when running Cedar generator commands.
|
|
50
|
+
// Local writes are very fast, but writes in e2e environments are not, so
|
|
51
|
+
// allow the default to be adjusted with an env-var.
|
|
52
|
+
delay ? parseInt(delay, 10) : 500
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
55
|
// Wrapper method to handle options and set precedence flags.
|
|
@@ -22,9 +22,9 @@ export interface CreateServerOptions {
|
|
|
22
22
|
configureApiServer?: (server: Server) => void | Promise<void>;
|
|
23
23
|
/** Whether to parse args or not. Defaults to `true` */
|
|
24
24
|
parseArgs?: boolean;
|
|
25
|
-
/** The port to listen on. Defaults to what's configured in
|
|
25
|
+
/** The port to listen on. Defaults to what's configured in cedar.toml */
|
|
26
26
|
apiPort?: number;
|
|
27
|
-
/** The host to bind to. Defaults to what's configured in
|
|
27
|
+
/** The host to bind to. Defaults to what's configured in cedar.toml */
|
|
28
28
|
apiHost?: string;
|
|
29
29
|
}
|
|
30
30
|
type DefaultCreateServerOptions = Required<Omit<CreateServerOptions, 'fastifyServerOptions'> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,
|
|
1
|
+
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,KAAK,0BAA0B,GAAG,QAAQ,CACxC,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG;IAClD,oBAAoB,EAAE,oBAAoB,CAAA;CAC3C,CACF,CAAA;AAID,eAAO,MAAM,6BAA6B,EAAE,MAAM,0BAiB9C,CAAA;AAgBJ,wBAAgB,cAAc,CAC5B,OAAO,GAAE,mBAAwB,EACjC,IAAI,CAAC,EAAE,MAAM,EAAE;0BAdS,oBAAoB;GA4F7C"}
|
package/dist/cjs/watch.d.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Initialize the file watcher for the API server
|
|
3
3
|
* Watches for changes in the API source directory and rebuilds/restarts as
|
|
4
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).
|
|
5
8
|
*/
|
|
6
9
|
export declare function startWatch(): Promise<void>;
|
|
7
10
|
//# sourceMappingURL=watch.d.ts.map
|
package/dist/cjs/watch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/watch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../src/watch.ts"],"names":[],"mappings":"AAwEA;;;;;;;GAOG;AACH,wBAAsB,UAAU,kBAsD/B"}
|
package/dist/cjs/watch.js
CHANGED
|
@@ -34,13 +34,13 @@ __export(watch_exports, {
|
|
|
34
34
|
startWatch: () => startWatch
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(watch_exports);
|
|
37
|
-
var
|
|
37
|
+
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
38
38
|
var import_ansis2 = __toESM(require("ansis"), 1);
|
|
39
39
|
var import_chokidar = __toESM(require("chokidar"), 1);
|
|
40
40
|
var import_dotenv_defaults = require("dotenv-defaults");
|
|
41
41
|
var import_api = require("@cedarjs/internal/dist/build/api");
|
|
42
42
|
var import_validateSchema = require("@cedarjs/internal/dist/validateSchema");
|
|
43
|
-
var
|
|
43
|
+
var import_project_config3 = require("@cedarjs/project-config");
|
|
44
44
|
|
|
45
45
|
// src/utils.ts
|
|
46
46
|
function debounce(func, wait) {
|
|
@@ -73,6 +73,7 @@ var BuildManager = class {
|
|
|
73
73
|
this.shouldRebuild = true;
|
|
74
74
|
this.shouldClean = false;
|
|
75
75
|
this.buildFn = buildFn;
|
|
76
|
+
const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
|
|
76
77
|
this.debouncedBuild = debounce(
|
|
77
78
|
async (options) => {
|
|
78
79
|
try {
|
|
@@ -86,12 +87,11 @@ var BuildManager = class {
|
|
|
86
87
|
this.shouldClean = false;
|
|
87
88
|
}
|
|
88
89
|
},
|
|
89
|
-
// We want to delay execution when multiple files are modified on the
|
|
90
|
-
//
|
|
91
|
-
// Local writes are very fast, but writes in e2e environments are not,
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
process.env.RWJS_DELAY_RESTART ? parseInt(process.env.RWJS_DELAY_RESTART, 10) : 500
|
|
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
95
|
);
|
|
96
96
|
}
|
|
97
97
|
// Wrapper method to handle options and set precedence flags.
|
|
@@ -211,12 +211,112 @@ var ServerManager = class {
|
|
|
211
211
|
};
|
|
212
212
|
var serverManager = new ServerManager();
|
|
213
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.base, "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
|
+
function workspacePackagesIgnorePaths() {
|
|
263
|
+
const cedarPaths2 = (0, import_project_config2.getPaths)();
|
|
264
|
+
const packagesDir = import_node_path.default.join(cedarPaths2.base, "packages");
|
|
265
|
+
const packageIgnoredPaths = [];
|
|
266
|
+
if (import_node_fs2.default.existsSync(packagesDir)) {
|
|
267
|
+
packageIgnoredPaths.push(import_node_path.default.join(packagesDir, "*/src"));
|
|
268
|
+
}
|
|
269
|
+
return packageIgnoredPaths;
|
|
270
|
+
}
|
|
271
|
+
async function apiIgnorePaths() {
|
|
272
|
+
const cedarPaths2 = (0, import_project_config2.getPaths)();
|
|
273
|
+
const dbDir = await (0, import_project_config2.getDbDir)(cedarPaths2.api.prismaConfig);
|
|
274
|
+
const ignoredApiPaths = [
|
|
275
|
+
// TODO: Is this still true?
|
|
276
|
+
// use this, because using cedarPaths.api.dist seems to not ignore on first
|
|
277
|
+
// build
|
|
278
|
+
"api/dist",
|
|
279
|
+
cedarPaths2.api.types,
|
|
280
|
+
dbDir
|
|
281
|
+
];
|
|
282
|
+
return ignoredApiPaths;
|
|
283
|
+
}
|
|
284
|
+
async function ignorePaths() {
|
|
285
|
+
const apiIgnore = await apiIgnorePaths();
|
|
286
|
+
const packagesIgnore = workspacePackagesIgnorePaths();
|
|
287
|
+
return [...apiIgnore, ...packagesIgnore].map((p) => (0, import_project_config2.importStatementPath)(p));
|
|
288
|
+
}
|
|
289
|
+
async function getIgnoreFunction() {
|
|
290
|
+
const ignoredWatchPaths = await ignorePaths();
|
|
291
|
+
const ignoredExtensions = [
|
|
292
|
+
".DS_Store",
|
|
293
|
+
".db",
|
|
294
|
+
".sqlite",
|
|
295
|
+
"-journal",
|
|
296
|
+
".test.js",
|
|
297
|
+
".test.ts",
|
|
298
|
+
".scenarios.ts",
|
|
299
|
+
".scenarios.js",
|
|
300
|
+
".d.ts",
|
|
301
|
+
".log"
|
|
302
|
+
];
|
|
303
|
+
return (file) => {
|
|
304
|
+
const shouldIgnore = file.includes("node_modules") || ignoredWatchPaths.some((ignoredPath) => file.includes(ignoredPath)) || ignoredExtensions.some((ext) => file.endsWith(ext));
|
|
305
|
+
return shouldIgnore;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
async function pathsToWatch() {
|
|
309
|
+
const cedarPaths2 = (0, import_project_config2.getPaths)();
|
|
310
|
+
const watchPaths = [cedarPaths2.api.src, ...await workspacePackagesPaths()];
|
|
311
|
+
return watchPaths.map((p) => (0, import_project_config2.importStatementPath)(p));
|
|
312
|
+
}
|
|
313
|
+
|
|
214
314
|
// src/watch.ts
|
|
215
|
-
var cedarPaths = (0,
|
|
315
|
+
var cedarPaths = (0, import_project_config3.getPaths)();
|
|
216
316
|
if (!process.env.REDWOOD_ENV_FILES_LOADED) {
|
|
217
317
|
(0, import_dotenv_defaults.config)({
|
|
218
|
-
path:
|
|
219
|
-
defaults:
|
|
318
|
+
path: import_node_path2.default.join(cedarPaths.base, ".env"),
|
|
319
|
+
defaults: import_node_path2.default.join(cedarPaths.base, ".env.defaults"),
|
|
220
320
|
multiline: true
|
|
221
321
|
});
|
|
222
322
|
process.env.REDWOOD_ENV_FILES_LOADED = "true";
|
|
@@ -252,33 +352,11 @@ async function validateSdls() {
|
|
|
252
352
|
}
|
|
253
353
|
}
|
|
254
354
|
async function startWatch() {
|
|
255
|
-
const
|
|
256
|
-
const
|
|
257
|
-
// use this, because using cedarPaths.api.dist seems to not ignore on first
|
|
258
|
-
// build
|
|
259
|
-
"api/dist",
|
|
260
|
-
cedarPaths.api.types,
|
|
261
|
-
dbDir
|
|
262
|
-
].map((path3) => (0, import_project_config2.ensurePosixPath)(path3));
|
|
263
|
-
const ignoredExtensions = [
|
|
264
|
-
".DS_Store",
|
|
265
|
-
".db",
|
|
266
|
-
".sqlite",
|
|
267
|
-
"-journal",
|
|
268
|
-
".test.js",
|
|
269
|
-
".test.ts",
|
|
270
|
-
".scenarios.ts",
|
|
271
|
-
".scenarios.js",
|
|
272
|
-
".d.ts",
|
|
273
|
-
".log"
|
|
274
|
-
];
|
|
275
|
-
const watcher = import_chokidar.default.watch([cedarPaths.api.src], {
|
|
355
|
+
const patterns = await pathsToWatch();
|
|
356
|
+
const watcher = import_chokidar.default.watch(patterns, {
|
|
276
357
|
persistent: true,
|
|
277
358
|
ignoreInitial: true,
|
|
278
|
-
ignored: (
|
|
279
|
-
const shouldIgnore = file.includes("node_modules") || ignoredApiPaths.some((ignoredPath) => file.includes(ignoredPath)) || ignoredExtensions.some((ext) => file.endsWith(ext));
|
|
280
|
-
return shouldIgnore;
|
|
281
|
-
}
|
|
359
|
+
ignored: await getIgnoreFunction()
|
|
282
360
|
});
|
|
283
361
|
watcher.on("ready", async () => {
|
|
284
362
|
await buildManager.run({ clean: true, rebuild: false });
|
|
@@ -296,9 +374,8 @@ async function startWatch() {
|
|
|
296
374
|
}
|
|
297
375
|
}
|
|
298
376
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
);
|
|
377
|
+
const displayPath = import_node_path2.default.relative(cedarPaths.base, filePath);
|
|
378
|
+
console.log(import_ansis2.default.dim(`[${eventName}] ${displayPath}`));
|
|
302
379
|
buildManager.cancelScheduledBuild();
|
|
303
380
|
if (eventName === "add" || eventName === "unlink") {
|
|
304
381
|
await buildManager.run({ rebuild: false });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchPaths.d.ts","sourceRoot":"","sources":["../../src/watchPaths.ts"],"names":[],"mappings":"AAoHA,wBAAsB,iBAAiB,mBAgBvB,MAAM,cAQrB;AAED,wBAAsB,YAAY,sBAQjC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
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.base, "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
|
+
function workspacePackagesIgnorePaths() {
|
|
83
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
84
|
+
const packagesDir = import_node_path.default.join(cedarPaths.base, "packages");
|
|
85
|
+
const packageIgnoredPaths = [];
|
|
86
|
+
if (import_node_fs.default.existsSync(packagesDir)) {
|
|
87
|
+
packageIgnoredPaths.push(import_node_path.default.join(packagesDir, "*/src"));
|
|
88
|
+
}
|
|
89
|
+
return packageIgnoredPaths;
|
|
90
|
+
}
|
|
91
|
+
async function apiIgnorePaths() {
|
|
92
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
93
|
+
const dbDir = await (0, import_project_config.getDbDir)(cedarPaths.api.prismaConfig);
|
|
94
|
+
const ignoredApiPaths = [
|
|
95
|
+
// TODO: Is this still true?
|
|
96
|
+
// use this, because using cedarPaths.api.dist seems to not ignore on first
|
|
97
|
+
// build
|
|
98
|
+
"api/dist",
|
|
99
|
+
cedarPaths.api.types,
|
|
100
|
+
dbDir
|
|
101
|
+
];
|
|
102
|
+
return ignoredApiPaths;
|
|
103
|
+
}
|
|
104
|
+
async function ignorePaths() {
|
|
105
|
+
const apiIgnore = await apiIgnorePaths();
|
|
106
|
+
const packagesIgnore = workspacePackagesIgnorePaths();
|
|
107
|
+
return [...apiIgnore, ...packagesIgnore].map((p) => (0, import_project_config.importStatementPath)(p));
|
|
108
|
+
}
|
|
109
|
+
async function getIgnoreFunction() {
|
|
110
|
+
const ignoredWatchPaths = await ignorePaths();
|
|
111
|
+
const ignoredExtensions = [
|
|
112
|
+
".DS_Store",
|
|
113
|
+
".db",
|
|
114
|
+
".sqlite",
|
|
115
|
+
"-journal",
|
|
116
|
+
".test.js",
|
|
117
|
+
".test.ts",
|
|
118
|
+
".scenarios.ts",
|
|
119
|
+
".scenarios.js",
|
|
120
|
+
".d.ts",
|
|
121
|
+
".log"
|
|
122
|
+
];
|
|
123
|
+
return (file) => {
|
|
124
|
+
const shouldIgnore = file.includes("node_modules") || ignoredWatchPaths.some((ignoredPath) => file.includes(ignoredPath)) || ignoredExtensions.some((ext) => file.endsWith(ext));
|
|
125
|
+
return shouldIgnore;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
async function pathsToWatch() {
|
|
129
|
+
const cedarPaths = (0, import_project_config.getPaths)();
|
|
130
|
+
const watchPaths = [cedarPaths.api.src, ...await workspacePackagesPaths()];
|
|
131
|
+
return watchPaths.map((p) => (0, import_project_config.importStatementPath)(p));
|
|
132
|
+
}
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
getIgnoreFunction,
|
|
136
|
+
pathsToWatch
|
|
137
|
+
});
|
|
@@ -22,9 +22,9 @@ export interface CreateServerOptions {
|
|
|
22
22
|
configureApiServer?: (server: Server) => void | Promise<void>;
|
|
23
23
|
/** Whether to parse args or not. Defaults to `true` */
|
|
24
24
|
parseArgs?: boolean;
|
|
25
|
-
/** The port to listen on. Defaults to what's configured in
|
|
25
|
+
/** The port to listen on. Defaults to what's configured in cedar.toml */
|
|
26
26
|
apiPort?: number;
|
|
27
|
-
/** The host to bind to. Defaults to what's configured in
|
|
27
|
+
/** The host to bind to. Defaults to what's configured in cedar.toml */
|
|
28
28
|
apiHost?: string;
|
|
29
29
|
}
|
|
30
30
|
type DefaultCreateServerOptions = Required<Omit<CreateServerOptions, 'fastifyServerOptions'> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,
|
|
1
|
+
{"version":3,"file":"createServerHelpers.d.ts","sourceRoot":"","sources":["../src/createServerHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,MAAM,SAAS,CAAA;AAMhB,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEtE,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CACnD;AAED,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB,iCAAiC;IACjC,MAAM,CAAC,EACH,oBAAoB,CAAC,QAAQ,CAAC,GAC9B,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;IAE1C;;;OAGG;IACH,oBAAoB,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAA;IAE3D;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAEzC,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D,uDAAuD;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,KAAK,0BAA0B,GAAG,QAAQ,CACxC,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG;IAClD,oBAAoB,EAAE,oBAAoB,CAAA;CAC3C,CACF,CAAA;AAID,eAAO,MAAM,6BAA6B,EAAE,MAAM,0BAiB9C,CAAA;AAgBJ,wBAAgB,cAAc,CAC5B,OAAO,GAAE,mBAAwB,EACjC,IAAI,CAAC,EAAE,MAAM,EAAE;0BAdS,oBAAoB;GA4F7C"}
|
package/dist/watch.d.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
* Initialize the file watcher for the API server
|
|
3
3
|
* Watches for changes in the API source directory and rebuilds/restarts as
|
|
4
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).
|
|
5
8
|
*/
|
|
6
9
|
export declare function startWatch(): Promise<void>;
|
|
7
10
|
//# sourceMappingURL=watch.d.ts.map
|
package/dist/watch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAwEA;;;;;;;GAOG;AACH,wBAAsB,UAAU,kBAsD/B"}
|
package/dist/watch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/watch.ts
|
|
4
|
-
import
|
|
4
|
+
import path3 from "node:path";
|
|
5
5
|
import ansis2 from "ansis";
|
|
6
6
|
import chokidar from "chokidar";
|
|
7
7
|
import { config } from "dotenv-defaults";
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
rebuildApi
|
|
12
12
|
} from "@cedarjs/internal/dist/build/api";
|
|
13
13
|
import { loadAndValidateSdls } from "@cedarjs/internal/dist/validateSchema";
|
|
14
|
-
import {
|
|
14
|
+
import { getPaths as getPaths3 } from "@cedarjs/project-config";
|
|
15
15
|
|
|
16
16
|
// src/utils.ts
|
|
17
17
|
function debounce(func, wait) {
|
|
@@ -44,6 +44,7 @@ var BuildManager = class {
|
|
|
44
44
|
this.shouldRebuild = true;
|
|
45
45
|
this.shouldClean = false;
|
|
46
46
|
this.buildFn = buildFn;
|
|
47
|
+
const delay = process.env.CEDAR_DELAY_API_RESTART || process.env.RWJS_DELAY_RESTART;
|
|
47
48
|
this.debouncedBuild = debounce(
|
|
48
49
|
async (options) => {
|
|
49
50
|
try {
|
|
@@ -57,12 +58,11 @@ var BuildManager = class {
|
|
|
57
58
|
this.shouldClean = false;
|
|
58
59
|
}
|
|
59
60
|
},
|
|
60
|
-
// We want to delay execution when multiple files are modified on the
|
|
61
|
-
//
|
|
62
|
-
// Local writes are very fast, but writes in e2e environments are not,
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
process.env.RWJS_DELAY_RESTART ? parseInt(process.env.RWJS_DELAY_RESTART, 10) : 500
|
|
61
|
+
// We want to delay execution when multiple files are modified on the
|
|
62
|
+
// filesystem. This usually happens when running Cedar generator commands.
|
|
63
|
+
// Local writes are very fast, but writes in e2e environments are not, so
|
|
64
|
+
// allow the default to be adjusted with an env-var.
|
|
65
|
+
delay ? parseInt(delay, 10) : 500
|
|
66
66
|
);
|
|
67
67
|
}
|
|
68
68
|
// Wrapper method to handle options and set precedence flags.
|
|
@@ -182,12 +182,116 @@ var ServerManager = class {
|
|
|
182
182
|
};
|
|
183
183
|
var serverManager = new ServerManager();
|
|
184
184
|
|
|
185
|
+
// src/watchPaths.ts
|
|
186
|
+
import fs2 from "node:fs";
|
|
187
|
+
import path2 from "node:path";
|
|
188
|
+
import {
|
|
189
|
+
getDbDir,
|
|
190
|
+
getPaths as getPaths2,
|
|
191
|
+
importStatementPath
|
|
192
|
+
} from "@cedarjs/project-config";
|
|
193
|
+
async function workspacePackagesPaths() {
|
|
194
|
+
const cedarPaths2 = getPaths2();
|
|
195
|
+
const packagesDir = path2.join(cedarPaths2.base, "packages");
|
|
196
|
+
const packages = [];
|
|
197
|
+
try {
|
|
198
|
+
const rootPackageJsonPath = path2.join(cedarPaths2.base, "package.json");
|
|
199
|
+
const rootPackageJson = JSON.parse(
|
|
200
|
+
fs2.readFileSync(rootPackageJsonPath, "utf8")
|
|
201
|
+
);
|
|
202
|
+
const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some((w) => w.startsWith("packages/"));
|
|
203
|
+
if (!hasPackageJsonWorkspaces || !fs2.existsSync(packagesDir)) {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
const globPattern = path2.join(packagesDir, "*").replaceAll("\\", "/");
|
|
207
|
+
const packageDirs = await Array.fromAsync(fs2.promises.glob(globPattern));
|
|
208
|
+
const apiPackageJsonPath = path2.join(cedarPaths2.api.base, "package.json");
|
|
209
|
+
const apiPackageJson = JSON.parse(
|
|
210
|
+
fs2.readFileSync(apiPackageJsonPath, "utf8")
|
|
211
|
+
);
|
|
212
|
+
const deps = {
|
|
213
|
+
...apiPackageJson.dependencies ?? {},
|
|
214
|
+
...apiPackageJson.devDependencies ?? {},
|
|
215
|
+
...apiPackageJson.peerDependencies ?? {}
|
|
216
|
+
};
|
|
217
|
+
const workspaceDepNames = /* @__PURE__ */ new Set();
|
|
218
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
219
|
+
if (String(version).startsWith("workspace:")) {
|
|
220
|
+
workspaceDepNames.add(name);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const packageDir of packageDirs) {
|
|
224
|
+
const packageJsonPath = path2.join(packageDir, "package.json");
|
|
225
|
+
if (!fs2.existsSync(packageJsonPath)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const pkgJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf8"));
|
|
229
|
+
if (workspaceDepNames.has(pkgJson.name)) {
|
|
230
|
+
packages.push(path2.join(packageDir, "dist"));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
} catch {
|
|
234
|
+
}
|
|
235
|
+
return packages;
|
|
236
|
+
}
|
|
237
|
+
function workspacePackagesIgnorePaths() {
|
|
238
|
+
const cedarPaths2 = getPaths2();
|
|
239
|
+
const packagesDir = path2.join(cedarPaths2.base, "packages");
|
|
240
|
+
const packageIgnoredPaths = [];
|
|
241
|
+
if (fs2.existsSync(packagesDir)) {
|
|
242
|
+
packageIgnoredPaths.push(path2.join(packagesDir, "*/src"));
|
|
243
|
+
}
|
|
244
|
+
return packageIgnoredPaths;
|
|
245
|
+
}
|
|
246
|
+
async function apiIgnorePaths() {
|
|
247
|
+
const cedarPaths2 = getPaths2();
|
|
248
|
+
const dbDir = await getDbDir(cedarPaths2.api.prismaConfig);
|
|
249
|
+
const ignoredApiPaths = [
|
|
250
|
+
// TODO: Is this still true?
|
|
251
|
+
// use this, because using cedarPaths.api.dist seems to not ignore on first
|
|
252
|
+
// build
|
|
253
|
+
"api/dist",
|
|
254
|
+
cedarPaths2.api.types,
|
|
255
|
+
dbDir
|
|
256
|
+
];
|
|
257
|
+
return ignoredApiPaths;
|
|
258
|
+
}
|
|
259
|
+
async function ignorePaths() {
|
|
260
|
+
const apiIgnore = await apiIgnorePaths();
|
|
261
|
+
const packagesIgnore = workspacePackagesIgnorePaths();
|
|
262
|
+
return [...apiIgnore, ...packagesIgnore].map((p) => importStatementPath(p));
|
|
263
|
+
}
|
|
264
|
+
async function getIgnoreFunction() {
|
|
265
|
+
const ignoredWatchPaths = await ignorePaths();
|
|
266
|
+
const ignoredExtensions = [
|
|
267
|
+
".DS_Store",
|
|
268
|
+
".db",
|
|
269
|
+
".sqlite",
|
|
270
|
+
"-journal",
|
|
271
|
+
".test.js",
|
|
272
|
+
".test.ts",
|
|
273
|
+
".scenarios.ts",
|
|
274
|
+
".scenarios.js",
|
|
275
|
+
".d.ts",
|
|
276
|
+
".log"
|
|
277
|
+
];
|
|
278
|
+
return (file) => {
|
|
279
|
+
const shouldIgnore = file.includes("node_modules") || ignoredWatchPaths.some((ignoredPath) => file.includes(ignoredPath)) || ignoredExtensions.some((ext) => file.endsWith(ext));
|
|
280
|
+
return shouldIgnore;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
async function pathsToWatch() {
|
|
284
|
+
const cedarPaths2 = getPaths2();
|
|
285
|
+
const watchPaths = [cedarPaths2.api.src, ...await workspacePackagesPaths()];
|
|
286
|
+
return watchPaths.map((p) => importStatementPath(p));
|
|
287
|
+
}
|
|
288
|
+
|
|
185
289
|
// src/watch.ts
|
|
186
|
-
var cedarPaths =
|
|
290
|
+
var cedarPaths = getPaths3();
|
|
187
291
|
if (!process.env.REDWOOD_ENV_FILES_LOADED) {
|
|
188
292
|
config({
|
|
189
|
-
path:
|
|
190
|
-
defaults:
|
|
293
|
+
path: path3.join(cedarPaths.base, ".env"),
|
|
294
|
+
defaults: path3.join(cedarPaths.base, ".env.defaults"),
|
|
191
295
|
multiline: true
|
|
192
296
|
});
|
|
193
297
|
process.env.REDWOOD_ENV_FILES_LOADED = "true";
|
|
@@ -223,33 +327,11 @@ async function validateSdls() {
|
|
|
223
327
|
}
|
|
224
328
|
}
|
|
225
329
|
async function startWatch() {
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
// use this, because using cedarPaths.api.dist seems to not ignore on first
|
|
229
|
-
// build
|
|
230
|
-
"api/dist",
|
|
231
|
-
cedarPaths.api.types,
|
|
232
|
-
dbDir
|
|
233
|
-
].map((path3) => ensurePosixPath(path3));
|
|
234
|
-
const ignoredExtensions = [
|
|
235
|
-
".DS_Store",
|
|
236
|
-
".db",
|
|
237
|
-
".sqlite",
|
|
238
|
-
"-journal",
|
|
239
|
-
".test.js",
|
|
240
|
-
".test.ts",
|
|
241
|
-
".scenarios.ts",
|
|
242
|
-
".scenarios.js",
|
|
243
|
-
".d.ts",
|
|
244
|
-
".log"
|
|
245
|
-
];
|
|
246
|
-
const watcher = chokidar.watch([cedarPaths.api.src], {
|
|
330
|
+
const patterns = await pathsToWatch();
|
|
331
|
+
const watcher = chokidar.watch(patterns, {
|
|
247
332
|
persistent: true,
|
|
248
333
|
ignoreInitial: true,
|
|
249
|
-
ignored: (
|
|
250
|
-
const shouldIgnore = file.includes("node_modules") || ignoredApiPaths.some((ignoredPath) => file.includes(ignoredPath)) || ignoredExtensions.some((ext) => file.endsWith(ext));
|
|
251
|
-
return shouldIgnore;
|
|
252
|
-
}
|
|
334
|
+
ignored: await getIgnoreFunction()
|
|
253
335
|
});
|
|
254
336
|
watcher.on("ready", async () => {
|
|
255
337
|
await buildManager.run({ clean: true, rebuild: false });
|
|
@@ -267,9 +349,8 @@ async function startWatch() {
|
|
|
267
349
|
}
|
|
268
350
|
}
|
|
269
351
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
);
|
|
352
|
+
const displayPath = path3.relative(cedarPaths.base, filePath);
|
|
353
|
+
console.log(ansis2.dim(`[${eventName}] ${displayPath}`));
|
|
273
354
|
buildManager.cancelScheduledBuild();
|
|
274
355
|
if (eventName === "add" || eventName === "unlink") {
|
|
275
356
|
await buildManager.run({ rebuild: false });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watchPaths.d.ts","sourceRoot":"","sources":["../src/watchPaths.ts"],"names":[],"mappings":"AAoHA,wBAAsB,iBAAiB,mBAgBvB,MAAM,cAQrB;AAED,wBAAsB,YAAY,sBAQjC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
getDbDir,
|
|
5
|
+
getPaths,
|
|
6
|
+
importStatementPath
|
|
7
|
+
} from "@cedarjs/project-config";
|
|
8
|
+
async function workspacePackagesPaths() {
|
|
9
|
+
const cedarPaths = getPaths();
|
|
10
|
+
const packagesDir = path.join(cedarPaths.base, "packages");
|
|
11
|
+
const packages = [];
|
|
12
|
+
try {
|
|
13
|
+
const rootPackageJsonPath = path.join(cedarPaths.base, "package.json");
|
|
14
|
+
const rootPackageJson = JSON.parse(
|
|
15
|
+
fs.readFileSync(rootPackageJsonPath, "utf8")
|
|
16
|
+
);
|
|
17
|
+
const hasPackageJsonWorkspaces = Array.isArray(rootPackageJson.workspaces) && rootPackageJson.workspaces.some((w) => w.startsWith("packages/"));
|
|
18
|
+
if (!hasPackageJsonWorkspaces || !fs.existsSync(packagesDir)) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const globPattern = path.join(packagesDir, "*").replaceAll("\\", "/");
|
|
22
|
+
const packageDirs = await Array.fromAsync(fs.promises.glob(globPattern));
|
|
23
|
+
const apiPackageJsonPath = path.join(cedarPaths.api.base, "package.json");
|
|
24
|
+
const apiPackageJson = JSON.parse(
|
|
25
|
+
fs.readFileSync(apiPackageJsonPath, "utf8")
|
|
26
|
+
);
|
|
27
|
+
const deps = {
|
|
28
|
+
...apiPackageJson.dependencies ?? {},
|
|
29
|
+
...apiPackageJson.devDependencies ?? {},
|
|
30
|
+
...apiPackageJson.peerDependencies ?? {}
|
|
31
|
+
};
|
|
32
|
+
const workspaceDepNames = /* @__PURE__ */ new Set();
|
|
33
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
34
|
+
if (String(version).startsWith("workspace:")) {
|
|
35
|
+
workspaceDepNames.add(name);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const packageDir of packageDirs) {
|
|
39
|
+
const packageJsonPath = path.join(packageDir, "package.json");
|
|
40
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const pkgJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
44
|
+
if (workspaceDepNames.has(pkgJson.name)) {
|
|
45
|
+
packages.push(path.join(packageDir, "dist"));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
}
|
|
50
|
+
return packages;
|
|
51
|
+
}
|
|
52
|
+
function workspacePackagesIgnorePaths() {
|
|
53
|
+
const cedarPaths = getPaths();
|
|
54
|
+
const packagesDir = path.join(cedarPaths.base, "packages");
|
|
55
|
+
const packageIgnoredPaths = [];
|
|
56
|
+
if (fs.existsSync(packagesDir)) {
|
|
57
|
+
packageIgnoredPaths.push(path.join(packagesDir, "*/src"));
|
|
58
|
+
}
|
|
59
|
+
return packageIgnoredPaths;
|
|
60
|
+
}
|
|
61
|
+
async function apiIgnorePaths() {
|
|
62
|
+
const cedarPaths = getPaths();
|
|
63
|
+
const dbDir = await getDbDir(cedarPaths.api.prismaConfig);
|
|
64
|
+
const ignoredApiPaths = [
|
|
65
|
+
// TODO: Is this still true?
|
|
66
|
+
// use this, because using cedarPaths.api.dist seems to not ignore on first
|
|
67
|
+
// build
|
|
68
|
+
"api/dist",
|
|
69
|
+
cedarPaths.api.types,
|
|
70
|
+
dbDir
|
|
71
|
+
];
|
|
72
|
+
return ignoredApiPaths;
|
|
73
|
+
}
|
|
74
|
+
async function ignorePaths() {
|
|
75
|
+
const apiIgnore = await apiIgnorePaths();
|
|
76
|
+
const packagesIgnore = workspacePackagesIgnorePaths();
|
|
77
|
+
return [...apiIgnore, ...packagesIgnore].map((p) => importStatementPath(p));
|
|
78
|
+
}
|
|
79
|
+
async function getIgnoreFunction() {
|
|
80
|
+
const ignoredWatchPaths = await ignorePaths();
|
|
81
|
+
const ignoredExtensions = [
|
|
82
|
+
".DS_Store",
|
|
83
|
+
".db",
|
|
84
|
+
".sqlite",
|
|
85
|
+
"-journal",
|
|
86
|
+
".test.js",
|
|
87
|
+
".test.ts",
|
|
88
|
+
".scenarios.ts",
|
|
89
|
+
".scenarios.js",
|
|
90
|
+
".d.ts",
|
|
91
|
+
".log"
|
|
92
|
+
];
|
|
93
|
+
return (file) => {
|
|
94
|
+
const shouldIgnore = file.includes("node_modules") || ignoredWatchPaths.some((ignoredPath) => file.includes(ignoredPath)) || ignoredExtensions.some((ext) => file.endsWith(ext));
|
|
95
|
+
return shouldIgnore;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function pathsToWatch() {
|
|
99
|
+
const cedarPaths = getPaths();
|
|
100
|
+
const watchPaths = [cedarPaths.api.src, ...await workspacePackagesPaths()];
|
|
101
|
+
return watchPaths.map((p) => importStatementPath(p));
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
getIgnoreFunction,
|
|
105
|
+
pathsToWatch
|
|
106
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/api-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0-rc.146",
|
|
4
4
|
"description": "CedarJS's HTTP server for Serverless Functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -111,19 +111,19 @@
|
|
|
111
111
|
"test:watch": "vitest watch"
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"@cedarjs/context": "2.
|
|
115
|
-
"@cedarjs/fastify-web": "2.
|
|
116
|
-
"@cedarjs/internal": "2.
|
|
117
|
-
"@cedarjs/project-config": "2.
|
|
118
|
-
"@cedarjs/web-server": "2.
|
|
119
|
-
"@fastify/multipart": "9.
|
|
114
|
+
"@cedarjs/context": "2.5.0-rc.146",
|
|
115
|
+
"@cedarjs/fastify-web": "2.5.0-rc.146",
|
|
116
|
+
"@cedarjs/internal": "2.5.0-rc.146",
|
|
117
|
+
"@cedarjs/project-config": "2.5.0-rc.146",
|
|
118
|
+
"@cedarjs/web-server": "2.5.0-rc.146",
|
|
119
|
+
"@fastify/multipart": "9.4.0",
|
|
120
120
|
"@fastify/url-data": "6.0.3",
|
|
121
121
|
"ansis": "4.2.0",
|
|
122
122
|
"chokidar": "3.6.0",
|
|
123
123
|
"dotenv-defaults": "5.0.2",
|
|
124
124
|
"fast-glob": "3.3.3",
|
|
125
125
|
"fast-json-parse": "1.0.3",
|
|
126
|
-
"fastify": "5.
|
|
126
|
+
"fastify": "5.7.2",
|
|
127
127
|
"fastify-raw-body": "5.0.0",
|
|
128
128
|
"pretty-bytes": "5.6.0",
|
|
129
129
|
"pretty-ms": "7.0.1",
|
|
@@ -132,20 +132,20 @@
|
|
|
132
132
|
"yargs": "17.7.2"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
|
-
"@cedarjs/framework-tools": "2.
|
|
136
|
-
"@types/aws-lambda": "8.10.
|
|
135
|
+
"@cedarjs/framework-tools": "2.5.0-rc.146",
|
|
136
|
+
"@types/aws-lambda": "8.10.160",
|
|
137
137
|
"@types/dotenv-defaults": "^5.0.0",
|
|
138
138
|
"@types/qs": "6.14.0",
|
|
139
139
|
"@types/split2": "4.2.3",
|
|
140
140
|
"@types/yargs": "17.0.35",
|
|
141
|
-
"memfs": "4.
|
|
141
|
+
"memfs": "4.56.10",
|
|
142
142
|
"pino-abstract-transport": "1.2.0",
|
|
143
143
|
"tsx": "4.21.0",
|
|
144
144
|
"typescript": "5.9.3",
|
|
145
145
|
"vitest": "3.2.4"
|
|
146
146
|
},
|
|
147
147
|
"peerDependencies": {
|
|
148
|
-
"@cedarjs/graphql-server": "2.
|
|
148
|
+
"@cedarjs/graphql-server": "2.5.0-rc.146"
|
|
149
149
|
},
|
|
150
150
|
"peerDependenciesMeta": {
|
|
151
151
|
"@cedarjs/graphql-server": {
|
|
@@ -155,5 +155,5 @@
|
|
|
155
155
|
"publishConfig": {
|
|
156
156
|
"access": "public"
|
|
157
157
|
},
|
|
158
|
-
"gitHead": "
|
|
158
|
+
"gitHead": "5f7f574583ae4d248fe0978e52eabe406ea06e55"
|
|
159
159
|
}
|