@holo-js/cli 0.1.1 → 0.1.3

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 (56) hide show
  1. package/dist/bin/holo.mjs +533 -4616
  2. package/dist/broadcast-YZS4OFCM.mjs +84 -0
  3. package/dist/broadcast-ZYFKUFM5.mjs +85 -0
  4. package/dist/cache-ODBZT6IP.mjs +67 -0
  5. package/dist/cache-V43YMG4K.mjs +66 -0
  6. package/dist/cache-migrations-KPOEH6GP.mjs +155 -0
  7. package/dist/cache-migrations-ZUOI2A7N.mjs +154 -0
  8. package/dist/chunk-3OTCSFDG.mjs +849 -0
  9. package/dist/chunk-66FHW725.mjs +465 -0
  10. package/dist/chunk-BWW5TDFI.mjs +4 -0
  11. package/dist/chunk-CUL4RJTG.mjs +22 -0
  12. package/dist/chunk-D4GG556Y.mjs +23 -0
  13. package/dist/chunk-D7O4SU6N.mjs +2 -0
  14. package/dist/chunk-ET7UXHHQ.mjs +166 -0
  15. package/dist/chunk-EUIVXVJL.mjs +25 -0
  16. package/dist/chunk-G5ADO27Q.mjs +463 -0
  17. package/dist/chunk-GSQ3HTRO.mjs +165 -0
  18. package/dist/chunk-H7TJ4FB3.mjs +848 -0
  19. package/dist/chunk-HE6FYNVN.mjs +3203 -0
  20. package/dist/chunk-ICJR7TS4.mjs +66 -0
  21. package/dist/chunk-ICKN56JY.mjs +342 -0
  22. package/dist/chunk-JX2ZH6XY.mjs +270 -0
  23. package/dist/chunk-M7J3YTHR.mjs +26 -0
  24. package/dist/chunk-Q5F6C2D4.mjs +65 -0
  25. package/dist/chunk-QYLSMF7V.mjs +539 -0
  26. package/dist/chunk-RB65DLR4.mjs +343 -0
  27. package/dist/chunk-S7P7EBM3.mjs +787 -0
  28. package/dist/chunk-SRWJU3A5.mjs +11 -0
  29. package/dist/chunk-T4OVZZEE.mjs +3204 -0
  30. package/dist/chunk-URK7C3VQ.mjs +538 -0
  31. package/dist/chunk-VT5IDQG6.mjs +788 -0
  32. package/dist/chunk-XUYKPU5Q.mjs +272 -0
  33. package/dist/chunk-ZXDU7RHU.mjs +9 -0
  34. package/dist/config-DMWBMMGD.mjs +26 -0
  35. package/dist/config-LS5USBRB.mjs +25 -0
  36. package/dist/dev-KGRIGLJY.mjs +42 -0
  37. package/dist/dev-LVHDCPVS.mjs +43 -0
  38. package/dist/discovery-GBLAUTXS.mjs +28 -0
  39. package/dist/discovery-R733D2PO.mjs +29 -0
  40. package/dist/generators-32R45P6Z.mjs +426 -0
  41. package/dist/generators-WSF23UKM.mjs +425 -0
  42. package/dist/index.d.ts +1 -0
  43. package/dist/index.mjs +536 -4618
  44. package/dist/queue-6N7HQMRL.mjs +625 -0
  45. package/dist/queue-QG5EXOG4.mjs +626 -0
  46. package/dist/queue-migrations-JWKU45Y3.mjs +163 -0
  47. package/dist/queue-migrations-O6QSSDPQ.mjs +162 -0
  48. package/dist/runtime-ANBO7VQM.mjs +33 -0
  49. package/dist/runtime-OOSJ5JBY.mjs +32 -0
  50. package/dist/runtime-RI4OWTIT.mjs +55 -0
  51. package/dist/runtime-ZRPK5DIT.mjs +56 -0
  52. package/dist/scaffold-IYWZKT3W.mjs +120 -0
  53. package/dist/scaffold-ULATB4CA.mjs +121 -0
  54. package/dist/security-AE6LGNC4.mjs +68 -0
  55. package/dist/security-OCOPEH2V.mjs +69 -0
  56. package/package.json +10 -9
@@ -0,0 +1,343 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ prepareProjectDiscovery
4
+ } from "./chunk-VT5IDQG6.mjs";
5
+ import {
6
+ syncManagedDriverDependencies
7
+ } from "./chunk-T4OVZZEE.mjs";
8
+ import {
9
+ ensureProjectConfig
10
+ } from "./chunk-ET7UXHHQ.mjs";
11
+ import {
12
+ readTextFile
13
+ } from "./chunk-66FHW725.mjs";
14
+
15
+ // src/dev.ts
16
+ import { spawnSync, spawn } from "child_process";
17
+ import { watch } from "fs";
18
+ import { readdir, stat } from "fs/promises";
19
+ import { dirname, join, relative, resolve } from "path";
20
+ async function fileExists(path) {
21
+ try {
22
+ await stat(path);
23
+ return true;
24
+ } catch {
25
+ return false;
26
+ }
27
+ }
28
+ async function resolveProjectPackageManager(projectRoot) {
29
+ const packageJsonPath = join(projectRoot, "package.json");
30
+ const packageJson = await readTextFile(packageJsonPath);
31
+ if (packageJson) {
32
+ try {
33
+ const parsed = JSON.parse(packageJson);
34
+ const packageManager = typeof parsed.packageManager === "string" ? parsed.packageManager.split("@")[0] : void 0;
35
+ if (packageManager === "bun" || packageManager === "npm" || packageManager === "pnpm" || packageManager === "yarn") {
36
+ return packageManager;
37
+ }
38
+ } catch {
39
+ }
40
+ }
41
+ if (await fileExists(join(projectRoot, "bun.lock"))) {
42
+ return "bun";
43
+ }
44
+ if (await fileExists(join(projectRoot, "pnpm-lock.yaml"))) {
45
+ return "pnpm";
46
+ }
47
+ if (await fileExists(join(projectRoot, "yarn.lock"))) {
48
+ return "yarn";
49
+ }
50
+ if (await fileExists(join(projectRoot, "package-lock.json"))) {
51
+ return "npm";
52
+ }
53
+ return "bun";
54
+ }
55
+ async function resolvePackageManagerCommand(projectRoot, scriptName) {
56
+ const packageManager = await resolveProjectPackageManager(projectRoot);
57
+ return {
58
+ command: packageManager,
59
+ args: ["run", scriptName]
60
+ };
61
+ }
62
+ async function resolvePackageManagerInstallInvocation(projectRoot) {
63
+ const packageManager = await resolveProjectPackageManager(projectRoot);
64
+ return {
65
+ command: packageManager,
66
+ args: ["install"]
67
+ };
68
+ }
69
+ async function runProjectLifecycleScript(io, projectRoot, scriptName, spawn2 = spawnSync) {
70
+ const invocation = await resolvePackageManagerCommand(projectRoot, scriptName);
71
+ const result = spawn2(invocation.command, [...invocation.args], {
72
+ cwd: projectRoot,
73
+ encoding: "utf8",
74
+ env: process.env
75
+ });
76
+ if (result.stdout) {
77
+ io.stdout.write(result.stdout);
78
+ }
79
+ if (result.stderr) {
80
+ io.stderr.write(result.stderr);
81
+ }
82
+ if (result.status !== 0) {
83
+ throw new Error(result.stderr?.trim() || result.stdout?.trim() || `Project script "${scriptName}" failed.`);
84
+ }
85
+ }
86
+ async function runProjectDependencyInstall(io, projectRoot, spawn2 = spawnSync) {
87
+ const invocation = await resolvePackageManagerInstallInvocation(projectRoot);
88
+ const result = spawn2(invocation.command, [...invocation.args], {
89
+ cwd: projectRoot,
90
+ encoding: "utf8",
91
+ env: process.env
92
+ });
93
+ if (result.stdout) {
94
+ io.stdout.write(result.stdout);
95
+ }
96
+ if (result.stderr) {
97
+ io.stderr.write(result.stderr);
98
+ }
99
+ if (result.status !== 0) {
100
+ throw new Error(result.stderr?.trim() || result.stdout?.trim() || "Project dependency installation failed.");
101
+ }
102
+ }
103
+ async function runProjectPrepare(projectRoot, io) {
104
+ const project = await ensureProjectConfig(projectRoot);
105
+ await prepareProjectDiscovery(projectRoot, project.config);
106
+ const updatedDependencies = await syncManagedDriverDependencies(projectRoot);
107
+ if (updatedDependencies && io) {
108
+ await runProjectDependencyInstall(io, projectRoot);
109
+ await prepareProjectDiscovery(projectRoot, project.config);
110
+ }
111
+ }
112
+ function toPosixSlashes(value) {
113
+ return value.replaceAll("\\", "/");
114
+ }
115
+ function isDiscoveryRelevantPath(filePath, project) {
116
+ const normalized = toPosixSlashes(filePath);
117
+ const authorizationPoliciesPath = project.config.paths.authorizationPolicies || "server/policies";
118
+ const authorizationAbilitiesPath = project.config.paths.authorizationAbilities || "server/abilities";
119
+ const roots = [
120
+ project.config.paths.models,
121
+ project.config.paths.migrations,
122
+ project.config.paths.seeders,
123
+ project.config.paths.commands,
124
+ project.config.paths.jobs,
125
+ project.config.paths.events,
126
+ project.config.paths.listeners,
127
+ authorizationPoliciesPath,
128
+ authorizationAbilitiesPath,
129
+ "server/broadcast",
130
+ "server/channels",
131
+ project.config.paths.generatedSchema,
132
+ "config",
133
+ ".holo-js/generated"
134
+ ];
135
+ if (normalized === ".env" || normalized.startsWith(".env.")) {
136
+ return true;
137
+ }
138
+ return roots.some((root) => normalized === root || normalized.startsWith(`${toPosixSlashes(root)}/`));
139
+ }
140
+ function isRecursiveWatchUnsupported(error) {
141
+ return error instanceof Error && (error.message.includes("recursive") || "code" in error && error.code === "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM");
142
+ }
143
+ function isIgnorableWatchError(error) {
144
+ return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "EPERM");
145
+ }
146
+ async function collectDirectoryTree(rootPath, directories) {
147
+ const rootStats = await stat(rootPath).catch(() => void 0);
148
+ if (!rootStats?.isDirectory()) {
149
+ return;
150
+ }
151
+ directories.add(rootPath);
152
+ const entries = await readdir(rootPath, { withFileTypes: true }).catch(() => []);
153
+ for (const entry of entries) {
154
+ if (!entry.isDirectory()) {
155
+ continue;
156
+ }
157
+ await collectDirectoryTree(join(rootPath, entry.name), directories);
158
+ }
159
+ }
160
+ async function collectDiscoveryWatchRoots(projectRoot, project) {
161
+ const directories = /* @__PURE__ */ new Set();
162
+ const authorizationPoliciesPath = project.config.paths.authorizationPolicies || "server/policies";
163
+ const authorizationAbilitiesPath = project.config.paths.authorizationAbilities || "server/abilities";
164
+ const roots = [
165
+ projectRoot,
166
+ resolve(projectRoot, "config"),
167
+ resolve(projectRoot, ".holo-js/generated"),
168
+ resolve(projectRoot, project.config.paths.models),
169
+ resolve(projectRoot, project.config.paths.migrations),
170
+ resolve(projectRoot, project.config.paths.seeders),
171
+ resolve(projectRoot, project.config.paths.commands),
172
+ resolve(projectRoot, project.config.paths.jobs),
173
+ resolve(projectRoot, project.config.paths.events),
174
+ resolve(projectRoot, project.config.paths.listeners),
175
+ resolve(projectRoot, authorizationPoliciesPath),
176
+ resolve(projectRoot, authorizationAbilitiesPath),
177
+ resolve(projectRoot, "server/broadcast"),
178
+ resolve(projectRoot, "server/channels"),
179
+ dirname(resolve(projectRoot, project.config.paths.generatedSchema))
180
+ ];
181
+ for (const rootPath of roots) {
182
+ await collectDirectoryTree(rootPath, directories);
183
+ }
184
+ return [...directories];
185
+ }
186
+ function normalizeWatchedFilePath(projectRoot, watchedRoot, fileName) {
187
+ return toPosixSlashes(relative(projectRoot, resolve(watchedRoot, fileName)));
188
+ }
189
+ async function runProjectDevServer(io, projectRoot, spawnProcess = spawn, createWatcher = watch, prepare = runProjectPrepare) {
190
+ let project = await ensureProjectConfig(projectRoot);
191
+ let refreshNonRecursiveWatchers;
192
+ let requestChildRestart;
193
+ const prepareDiscovery = async () => {
194
+ await prepare(projectRoot, io);
195
+ project = await ensureProjectConfig(projectRoot);
196
+ await refreshNonRecursiveWatchers?.();
197
+ };
198
+ await prepareDiscovery();
199
+ let pendingPrepare;
200
+ let queued = false;
201
+ let shuttingDown = false;
202
+ const rerunPrepare = () => {
203
+ if (shuttingDown) {
204
+ return;
205
+ }
206
+ if (pendingPrepare) {
207
+ queued = true;
208
+ return;
209
+ }
210
+ pendingPrepare = prepareDiscovery().then(() => {
211
+ requestChildRestart?.();
212
+ }).catch((error) => {
213
+ io.stderr.write(`${error instanceof Error ? error.message : String(error)}
214
+ `);
215
+ }).finally(() => {
216
+ pendingPrepare = void 0;
217
+ if (queued) {
218
+ queued = false;
219
+ rerunPrepare();
220
+ }
221
+ });
222
+ };
223
+ const closeWatchers = (() => {
224
+ try {
225
+ const watcher = createWatcher(projectRoot, { recursive: true }, (_eventType, fileName) => {
226
+ if (shuttingDown || typeof fileName !== "string" || !isDiscoveryRelevantPath(fileName, project)) {
227
+ return;
228
+ }
229
+ rerunPrepare();
230
+ });
231
+ return () => watcher.close();
232
+ } catch (error) {
233
+ if (!isRecursiveWatchUnsupported(error)) {
234
+ throw error;
235
+ }
236
+ const watchers = [];
237
+ const closeAllWatchers = () => {
238
+ while (watchers.length > 0) {
239
+ watchers.pop()?.close();
240
+ }
241
+ };
242
+ refreshNonRecursiveWatchers = async () => {
243
+ closeAllWatchers();
244
+ const watchRoots = await collectDiscoveryWatchRoots(projectRoot, project);
245
+ for (const watchRoot of watchRoots) {
246
+ try {
247
+ watchers.push(createWatcher(watchRoot, { recursive: false }, (_eventType, fileName) => {
248
+ if (shuttingDown || typeof fileName !== "string") {
249
+ return;
250
+ }
251
+ const normalizedPath = normalizeWatchedFilePath(projectRoot, watchRoot, fileName);
252
+ if (!isDiscoveryRelevantPath(normalizedPath, project)) {
253
+ return;
254
+ }
255
+ rerunPrepare();
256
+ }));
257
+ } catch (watchError) {
258
+ if (!isIgnorableWatchError(watchError)) {
259
+ throw watchError;
260
+ }
261
+ }
262
+ }
263
+ };
264
+ return () => closeAllWatchers();
265
+ }
266
+ })();
267
+ await refreshNonRecursiveWatchers?.();
268
+ const invocation = await resolvePackageManagerCommand(projectRoot, "holo:dev");
269
+ while (!shuttingDown) {
270
+ const child = spawnProcess(invocation.command, [...invocation.args], {
271
+ cwd: projectRoot,
272
+ env: process.env,
273
+ stdio: ["pipe", "pipe", "pipe"]
274
+ });
275
+ child.stdout?.on("data", (chunk) => io.stdout.write(chunk));
276
+ child.stderr?.on("data", (chunk) => io.stderr.write(chunk));
277
+ if (child.stdin) {
278
+ io.stdin.pipe(child.stdin);
279
+ }
280
+ const result = await new Promise((resolvePromise) => {
281
+ let restartRequested = false;
282
+ requestChildRestart = () => {
283
+ if (restartRequested || shuttingDown || typeof child.kill !== "function") {
284
+ return;
285
+ }
286
+ restartRequested = true;
287
+ child.kill("SIGTERM");
288
+ };
289
+ child.on("error", (error) => {
290
+ if (child.stdin) {
291
+ io.stdin.unpipe(child.stdin);
292
+ }
293
+ requestChildRestart = void 0;
294
+ if (restartRequested) {
295
+ resolvePromise({ kind: "restart" });
296
+ return;
297
+ }
298
+ resolvePromise({ kind: "error", error });
299
+ });
300
+ child.on("close", (code) => {
301
+ if (child.stdin) {
302
+ io.stdin.unpipe(child.stdin);
303
+ }
304
+ requestChildRestart = void 0;
305
+ if (restartRequested) {
306
+ resolvePromise({ kind: "restart" });
307
+ return;
308
+ }
309
+ resolvePromise({ kind: "close", code });
310
+ });
311
+ });
312
+ if (result.kind === "restart") {
313
+ continue;
314
+ }
315
+ shuttingDown = true;
316
+ closeWatchers();
317
+ await Promise.resolve(pendingPrepare);
318
+ if (result.kind === "error") {
319
+ throw result.error;
320
+ }
321
+ if (result.code === 0) {
322
+ return;
323
+ }
324
+ throw new Error(`Project script "holo:dev" failed with exit code ${result.code ?? "unknown"}.`);
325
+ }
326
+ }
327
+
328
+ export {
329
+ resolveProjectPackageManager,
330
+ resolvePackageManagerCommand,
331
+ resolvePackageManagerInstallInvocation,
332
+ runProjectLifecycleScript,
333
+ runProjectDependencyInstall,
334
+ runProjectPrepare,
335
+ toPosixSlashes,
336
+ isDiscoveryRelevantPath,
337
+ isRecursiveWatchUnsupported,
338
+ isIgnorableWatchError,
339
+ collectDirectoryTree,
340
+ collectDiscoveryWatchRoots,
341
+ normalizeWatchedFilePath,
342
+ runProjectDevServer
343
+ };