@cedarjs/api-server 3.0.0-canary.13321 → 3.0.0-canary.13322
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/dist/cjs/watch.d.ts +3 -0
- package/dist/cjs/watch.d.ts.map +1 -1
- package/dist/cjs/watch.js +110 -33
- 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/watch.d.ts +3 -0
- package/dist/watch.d.ts.map +1 -1
- package/dist/watch.js +114 -33
- package/dist/watchPaths.d.ts +3 -0
- package/dist/watchPaths.d.ts.map +1 -0
- package/dist/watchPaths.js +106 -0
- package/package.json +9 -9
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) {
|
|
@@ -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
|
+
});
|
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) {
|
|
@@ -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": "3.0.0-canary.
|
|
3
|
+
"version": "3.0.0-canary.13322+8fb222b6a",
|
|
4
4
|
"description": "CedarJS's HTTP server for Serverless Functions",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -111,11 +111,11 @@
|
|
|
111
111
|
"test:watch": "vitest watch"
|
|
112
112
|
},
|
|
113
113
|
"dependencies": {
|
|
114
|
-
"@cedarjs/context": "3.0.0-canary.
|
|
115
|
-
"@cedarjs/fastify-web": "3.0.0-canary.
|
|
116
|
-
"@cedarjs/internal": "3.0.0-canary.
|
|
117
|
-
"@cedarjs/project-config": "3.0.0-canary.
|
|
118
|
-
"@cedarjs/web-server": "3.0.0-canary.
|
|
114
|
+
"@cedarjs/context": "3.0.0-canary.13322",
|
|
115
|
+
"@cedarjs/fastify-web": "3.0.0-canary.13322",
|
|
116
|
+
"@cedarjs/internal": "3.0.0-canary.13322",
|
|
117
|
+
"@cedarjs/project-config": "3.0.0-canary.13322",
|
|
118
|
+
"@cedarjs/web-server": "3.0.0-canary.13322",
|
|
119
119
|
"@fastify/multipart": "9.4.0",
|
|
120
120
|
"@fastify/url-data": "6.0.3",
|
|
121
121
|
"ansis": "4.2.0",
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"yargs": "17.7.2"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
|
-
"@cedarjs/framework-tools": "3.0.0-canary.
|
|
135
|
+
"@cedarjs/framework-tools": "3.0.0-canary.13322",
|
|
136
136
|
"@types/aws-lambda": "8.10.160",
|
|
137
137
|
"@types/dotenv-defaults": "^5.0.0",
|
|
138
138
|
"@types/qs": "6.14.0",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"vitest": "3.2.4"
|
|
146
146
|
},
|
|
147
147
|
"peerDependencies": {
|
|
148
|
-
"@cedarjs/graphql-server": "3.0.0-canary.
|
|
148
|
+
"@cedarjs/graphql-server": "3.0.0-canary.13322"
|
|
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": "8fb222b6a3fee202e34bba836a29391e550e792f"
|
|
159
159
|
}
|