@holo-js/cli 0.3.0 → 0.3.1

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 (47) hide show
  1. package/dist/bin/holo.mjs +38 -35
  2. package/dist/{broadcast-5VZM5SGQ.mjs → broadcast-PJLFVZH4.mjs} +9 -11
  3. package/dist/{cache-A42JSVYA.mjs → cache-KR4ACOYD.mjs} +8 -9
  4. package/dist/{cache-migrations-4WKSEN2Q.mjs → cache-migrations-J34RE4WH.mjs} +13 -15
  5. package/dist/{chunk-OLZEMIDQ.mjs → chunk-2XXJ76YC.mjs} +1 -1
  6. package/dist/{chunk-3RFRE7XG.mjs → chunk-3ICVWL2M.mjs} +2 -2
  7. package/dist/{chunk-JVLZ3SOW.mjs → chunk-4VYR2ARA.mjs} +2 -2
  8. package/dist/{chunk-QSVMXMTQ.mjs → chunk-7KZVFDSI.mjs} +3 -3
  9. package/dist/{chunk-TRYHX5S4.mjs → chunk-AZ6NVJAP.mjs} +1 -1
  10. package/dist/{chunk-LHK5YUR4.mjs → chunk-CT23GSEC.mjs} +1 -1
  11. package/dist/{chunk-6BHJLCAO.mjs → chunk-FFTJKBQF.mjs} +43 -13
  12. package/dist/{chunk-EQUFFLRG.mjs → chunk-I3RRWDLV.mjs} +5 -5
  13. package/dist/{chunk-R4ZYMEDU.mjs → chunk-L3YATEQY.mjs} +1 -1
  14. package/dist/{chunk-TH5YCOZB.mjs → chunk-L6FF22IV.mjs} +28 -17
  15. package/dist/{chunk-YACY2572.mjs → chunk-PVVGQSUP.mjs} +47 -47
  16. package/dist/{chunk-I7QBCEV7.mjs → chunk-Y355VYRN.mjs} +5 -3
  17. package/dist/{chunk-VRGB6DIS.mjs → chunk-YJWHIQ45.mjs} +2 -0
  18. package/dist/{config-BZHQK532.mjs → config-XVPV6DJW.mjs} +3 -3
  19. package/dist/{dev-7KGRV56X.mjs → dev-NTQTEY5B.mjs} +9 -10
  20. package/dist/{discovery-HNH3BLDL.mjs → discovery-TMPUQQHI.mjs} +4 -4
  21. package/dist/{generators-3FVW4AEJ.mjs → generators-3FDCCJDC.mjs} +14 -16
  22. package/dist/index.mjs +38 -35
  23. package/dist/{media-migrations-EG34NYAG.mjs → media-migrations-UJ6BMUSZ.mjs} +10 -12
  24. package/dist/{plugins-ZGLB6JO6.mjs → plugins-USHY6SPF.mjs} +3 -3
  25. package/dist/{queue-BEZDCZCY.mjs → queue-6U7JU4T6.mjs} +11 -13
  26. package/dist/{queue-R54DUUYA.mjs → queue-VJEFD6SE.mjs} +13 -15
  27. package/dist/{queue-migrations-AM3AKT76.mjs → queue-migrations-6YUUOKMH.mjs} +13 -15
  28. package/dist/{runtime-4TJYZLQV.mjs → runtime-FVRB4O2M.mjs} +8 -10
  29. package/dist/{runtime-VR5BDPYQ.mjs → runtime-P5R7H3B4.mjs} +1 -1
  30. package/dist/{scaffold-ASEX5LEX.mjs → scaffold-F3AZDNPG.mjs} +7 -6
  31. package/dist/{security-KYTLP4DF.mjs → security-X4274RHX.mjs} +8 -9
  32. package/package.json +19 -19
  33. package/dist/broadcast-AABT52BK.mjs +0 -206
  34. package/dist/cache-DUVBBOZU.mjs +0 -138
  35. package/dist/cache-migrations-PD2T5AV4.mjs +0 -175
  36. package/dist/chunk-HX6MOYBO.mjs +0 -2
  37. package/dist/chunk-KRADH7PK.mjs +0 -501
  38. package/dist/chunk-LALDNNPH.mjs +0 -428
  39. package/dist/chunk-M3IPUCTM.mjs +0 -25
  40. package/dist/chunk-OI54DOHK.mjs +0 -3170
  41. package/dist/dev-GQT37XJU.mjs +0 -46
  42. package/dist/generators-JWVNGUUE.mjs +0 -523
  43. package/dist/media-migrations-LGI7R7AR.mjs +0 -108
  44. package/dist/queue-migrations-U477YSFD.mjs +0 -173
  45. package/dist/runtime-MSRQD5W5.mjs +0 -59
  46. package/dist/scaffold-ZAD3XUSD.mjs +0 -143
  47. package/dist/security-4QLV7QCH.mjs +0 -73
@@ -1,175 +0,0 @@
1
- import {
2
- runProjectPrepare
3
- } from "./chunk-TH5YCOZB.mjs";
4
- import "./chunk-LHK5YUR4.mjs";
5
- import {
6
- getRegistryMigrationSlug,
7
- hasRegisteredCreateTableMigration,
8
- hasRegisteredMigrationSlug,
9
- nextMigrationTemplate
10
- } from "./chunk-OLZEMIDQ.mjs";
11
- import "./chunk-M3IPUCTM.mjs";
12
- import {
13
- writeLine
14
- } from "./chunk-I7QBCEV7.mjs";
15
- import "./chunk-HX6MOYBO.mjs";
16
- import "./chunk-6BHJLCAO.mjs";
17
- import {
18
- ensureProjectConfig
19
- } from "./chunk-JVLZ3SOW.mjs";
20
- import {
21
- prepareProjectDiscovery
22
- } from "./chunk-QSVMXMTQ.mjs";
23
- import {
24
- loadGeneratedProjectRegistry
25
- } from "./chunk-R4ZYMEDU.mjs";
26
- import "./chunk-3RFRE7XG.mjs";
27
- import "./chunk-TRYHX5S4.mjs";
28
- import {
29
- makeProjectRelativePath,
30
- resolveDefaultArtifactPath,
31
- writeTextFile
32
- } from "./chunk-YACY2572.mjs";
33
-
34
- // src/cache-migrations.ts
35
- import { resolve } from "path";
36
- import {
37
- CACHE_DATABASE_TABLE_DEFINITIONS,
38
- DEFAULT_CACHE_DATABASE_LOCK_TABLE as CACHE_DB_DEFAULT_LOCK_TABLE,
39
- DEFAULT_CACHE_DATABASE_TABLE as CACHE_DB_DEFAULT_TABLE
40
- } from "@holo-js/cache-db";
41
- import { loadConfigDirectory } from "@holo-js/config";
42
- import { normalizeMigrationSlug } from "@holo-js/db";
43
- var DEFAULT_CACHE_DATABASE_TABLE = CACHE_DB_DEFAULT_TABLE;
44
- var DEFAULT_CACHE_DATABASE_LOCK_TABLE = CACHE_DB_DEFAULT_LOCK_TABLE;
45
- async function loadCacheConfig(projectRoot) {
46
- const loadedConfig = await loadConfigDirectory(projectRoot);
47
- if (!loadedConfig || typeof loadedConfig !== "object" || !("cache" in loadedConfig) || !loadedConfig.cache || typeof loadedConfig.cache !== "object" || !("drivers" in loadedConfig.cache) || typeof loadedConfig.cache.drivers !== "object" || loadedConfig.cache.drivers === null || Array.isArray(loadedConfig.cache.drivers)) {
48
- throw new Error("Cache config is missing or malformed. Expected a cache config object with a drivers property.");
49
- }
50
- const cacheConfig = loadedConfig.cache;
51
- for (const [driverName, driverConfig] of Object.entries(cacheConfig.drivers)) {
52
- if (driverConfig.driver !== "database") {
53
- continue;
54
- }
55
- const databaseDriver = driverConfig;
56
- if (typeof databaseDriver.table !== "string" || !databaseDriver.table.trim() || typeof databaseDriver.lockTable !== "string" || !databaseDriver.lockTable.trim()) {
57
- throw new Error(`Database cache driver "${driverName}" must define non-empty "table" and "lockTable" strings.`);
58
- }
59
- }
60
- return cacheConfig;
61
- }
62
- function normalizeCacheMigrationName(tableName) {
63
- return normalizeMigrationSlug(`create_${tableName.replaceAll(".", "_")}_cache_table`);
64
- }
65
- function escapeSingleQuotedString(value) {
66
- return value.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
67
- }
68
- function renderCacheTableColumn(columnDefinition) {
69
- const calls = [
70
- `table.${columnDefinition.kind}('${escapeSingleQuotedString(columnDefinition.name)}')`
71
- ];
72
- if (columnDefinition.primaryKey) {
73
- calls.push("primaryKey()");
74
- }
75
- if (columnDefinition.nullable) {
76
- calls.push("nullable()");
77
- }
78
- return ` ${calls.join(".")}`;
79
- }
80
- function renderCacheTableCreateStatement(tableName, tableDefinition) {
81
- return [
82
- ` await schema.createTable('${escapeSingleQuotedString(tableName)}', (table) => {`,
83
- ...tableDefinition.columns.map(renderCacheTableColumn),
84
- ` table.index(['${escapeSingleQuotedString(tableDefinition.indexColumn)}'], '${escapeSingleQuotedString(tableDefinition.indexName(tableName))}')`,
85
- " })"
86
- ];
87
- }
88
- function resolveCacheDatabaseTableDefinition(role) {
89
- const tableDefinition = CACHE_DATABASE_TABLE_DEFINITIONS.find((definition) => definition.role === role);
90
- if (!tableDefinition) {
91
- throw new Error(`Missing cache database table definition for "${role}".`);
92
- }
93
- return tableDefinition;
94
- }
95
- function renderCacheTableMigration(tableName = DEFAULT_CACHE_DATABASE_TABLE, lockTableName = DEFAULT_CACHE_DATABASE_LOCK_TABLE) {
96
- const entryTableDefinition = resolveCacheDatabaseTableDefinition("entries");
97
- const lockTableDefinition = resolveCacheDatabaseTableDefinition("locks");
98
- return [
99
- "import { defineMigration } from '@holo-js/db'",
100
- "",
101
- "export default defineMigration({",
102
- " async up({ schema }) {",
103
- ...renderCacheTableCreateStatement(tableName, entryTableDefinition),
104
- ...renderCacheTableCreateStatement(lockTableName, lockTableDefinition),
105
- " },",
106
- " async down({ schema }) {",
107
- ` await schema.dropTable('${escapeSingleQuotedString(lockTableName)}')`,
108
- ` await schema.dropTable('${escapeSingleQuotedString(tableName)}')`,
109
- " },",
110
- "})",
111
- ""
112
- ].join("\n");
113
- }
114
- function resolveDatabaseCacheTables(cacheConfig) {
115
- const configured = Object.values(cacheConfig.drivers).filter((driver) => driver.driver === "database").map((driver) => ({
116
- table: driver.table,
117
- lockTable: driver.lockTable
118
- }));
119
- if (configured.length === 0) {
120
- throw new Error("The configured cache drivers do not use the database driver.");
121
- }
122
- return Object.freeze(configured);
123
- }
124
- async function runCacheTableCommand(io, projectRoot) {
125
- const project = await ensureProjectConfig(projectRoot);
126
- const registry = await loadGeneratedProjectRegistry(projectRoot) ?? await prepareProjectDiscovery(projectRoot, project.config);
127
- const cacheConfig = await loadCacheConfig(projectRoot);
128
- const migrationsDir = resolve(projectRoot, project.config.paths.migrations);
129
- const createdFiles = [];
130
- const resolvedTables = resolveDatabaseCacheTables(cacheConfig);
131
- const seenPhysicalTables = /* @__PURE__ */ new Set();
132
- const seenSlugs = /* @__PURE__ */ new Map();
133
- for (const { table, lockTable } of resolvedTables) {
134
- const migrationName = normalizeCacheMigrationName(table);
135
- const previousTable = seenSlugs.get(migrationName);
136
- if (table === lockTable || seenPhysicalTables.has(table) || seenPhysicalTables.has(lockTable) || previousTable && previousTable !== table) {
137
- throw new Error(`A migration for cache tables "${table}" and "${lockTable}" already exists.`);
138
- }
139
- seenPhysicalTables.add(table);
140
- seenPhysicalTables.add(lockTable);
141
- seenSlugs.set(migrationName, table);
142
- }
143
- for (const { table, lockTable } of resolvedTables) {
144
- const migrationName = normalizeCacheMigrationName(table);
145
- if (hasRegisteredMigrationSlug(registry, migrationName) || hasRegisteredCreateTableMigration(registry, table) || hasRegisteredCreateTableMigration(registry, lockTable)) {
146
- throw new Error(`A migration for cache tables "${table}" and "${lockTable}" already exists.`);
147
- }
148
- }
149
- for (const { table, lockTable } of resolvedTables) {
150
- const migrationTemplate = await nextMigrationTemplate(normalizeCacheMigrationName(table), migrationsDir);
151
- const migrationFilePath = resolveDefaultArtifactPath(projectRoot, project.config.paths.migrations, migrationTemplate.fileName);
152
- await writeTextFile(migrationFilePath, renderCacheTableMigration(table, lockTable));
153
- createdFiles.push(migrationFilePath);
154
- }
155
- await runProjectPrepare(projectRoot);
156
- for (const filePath of createdFiles) {
157
- writeLine(io.stdout, `Created migration: ${makeProjectRelativePath(projectRoot, filePath)}`);
158
- }
159
- }
160
- var cacheMigrationInternals = {
161
- getRegistryMigrationSlug,
162
- hasRegisteredMigrationSlug,
163
- hasRegisteredCreateTableMigration,
164
- nextMigrationTemplate
165
- };
166
- export {
167
- DEFAULT_CACHE_DATABASE_LOCK_TABLE,
168
- DEFAULT_CACHE_DATABASE_TABLE,
169
- cacheMigrationInternals,
170
- loadCacheConfig,
171
- normalizeCacheMigrationName,
172
- renderCacheTableMigration,
173
- resolveDatabaseCacheTables,
174
- runCacheTableCommand
175
- };
@@ -1,2 +0,0 @@
1
- // src/project.ts
2
- import { normalizeHoloProjectConfig } from "@holo-js/kernel";
@@ -1,501 +0,0 @@
1
- import {
2
- hasProjectDependency
3
- } from "./chunk-LHK5YUR4.mjs";
4
- import {
5
- prepareProjectDiscovery
6
- } from "./chunk-QSVMXMTQ.mjs";
7
- import {
8
- syncManagedDriverDependencies
9
- } from "./chunk-OI54DOHK.mjs";
10
- import {
11
- ensureGeneratedSchemaPlaceholder,
12
- ensureProjectConfig
13
- } from "./chunk-JVLZ3SOW.mjs";
14
- import {
15
- renderFrameworkRunnerForDescriptor
16
- } from "./chunk-R4ZYMEDU.mjs";
17
- import {
18
- loadProjectPluginFrameworkDescriptors
19
- } from "./chunk-3RFRE7XG.mjs";
20
- import {
21
- getFrameworkDescriptorByIdFrom,
22
- getFrameworkDescriptorsWith,
23
- readTextFile,
24
- writeTextFile
25
- } from "./chunk-YACY2572.mjs";
26
-
27
- // src/dev.ts
28
- import { spawnSync, spawn } from "child_process";
29
- import { watch } from "fs";
30
- import { readdir, stat } from "fs/promises";
31
- import { join, dirname, relative, resolve } from "path";
32
- import { readFile } from "fs/promises";
33
- async function fileExists(path) {
34
- try {
35
- await stat(path);
36
- return true;
37
- } catch {
38
- return false;
39
- }
40
- }
41
- async function resolveProjectPackageManager(projectRoot) {
42
- const packageJsonPath = join(projectRoot, "package.json");
43
- const packageJson = await readTextFile(packageJsonPath);
44
- if (packageJson) {
45
- try {
46
- const parsed = JSON.parse(packageJson);
47
- const packageManager = typeof parsed.packageManager === "string" ? parsed.packageManager.split("@")[0] : void 0;
48
- if (packageManager === "bun" || packageManager === "npm" || packageManager === "pnpm" || packageManager === "yarn") {
49
- return packageManager;
50
- }
51
- } catch {
52
- }
53
- }
54
- if (await fileExists(join(projectRoot, "bun.lock"))) {
55
- return "bun";
56
- }
57
- if (await fileExists(join(projectRoot, "pnpm-lock.yaml"))) {
58
- return "pnpm";
59
- }
60
- if (await fileExists(join(projectRoot, "yarn.lock"))) {
61
- return "yarn";
62
- }
63
- if (await fileExists(join(projectRoot, "package-lock.json"))) {
64
- return "npm";
65
- }
66
- return "bun";
67
- }
68
- async function resolvePackageManagerCommand(projectRoot, scriptName) {
69
- const packageManager = await resolveProjectPackageManager(projectRoot);
70
- return {
71
- command: packageManager,
72
- args: ["run", scriptName]
73
- };
74
- }
75
- async function resolvePackageManagerInstallInvocation(projectRoot) {
76
- const packageManager = await resolveProjectPackageManager(projectRoot);
77
- return {
78
- command: packageManager,
79
- args: ["install"]
80
- };
81
- }
82
- function resolveFrameworkRunnerInvocation(projectRoot, mode) {
83
- return {
84
- command: process.execPath,
85
- args: [join(projectRoot, ".holo-js/framework/run.mjs"), mode]
86
- };
87
- }
88
- async function runProjectBuild(io, projectRoot, spawn2 = spawnSync) {
89
- const invocation = resolveFrameworkRunnerInvocation(projectRoot, "build");
90
- const result = spawn2(invocation.command, [...invocation.args], {
91
- cwd: projectRoot,
92
- encoding: "utf8",
93
- env: process.env
94
- });
95
- if (result.stdout) {
96
- io.stdout.write(result.stdout);
97
- }
98
- if (result.stderr) {
99
- io.stderr.write(result.stderr);
100
- }
101
- if (result.status !== 0) {
102
- throw new Error(result.stderr?.trim() || result.stdout?.trim() || "Project build failed.");
103
- }
104
- }
105
- async function runProjectStartServer(io, projectRoot, spawnProcess = spawn, passthroughArgs = []) {
106
- const invocation = resolveFrameworkRunnerInvocation(projectRoot, "start");
107
- const child = spawnProcess(invocation.command, [...invocation.args, ...passthroughArgs], {
108
- cwd: projectRoot,
109
- env: process.env,
110
- stdio: ["pipe", "pipe", "pipe"]
111
- });
112
- child.stdout?.on("data", (chunk) => io.stdout.write(chunk));
113
- child.stderr?.on("data", (chunk) => io.stderr.write(chunk));
114
- if (child.stdin) {
115
- io.stdin.pipe(child.stdin);
116
- }
117
- const result = await new Promise((resolvePromise) => {
118
- child.on("error", (error) => resolvePromise({ kind: "error", error }));
119
- child.on("close", (code) => resolvePromise({ kind: "close", code }));
120
- });
121
- if (result.kind === "error") {
122
- throw result.error;
123
- }
124
- if (result.code !== 0) {
125
- throw new Error(`Project production server failed with exit code ${result.code ?? "unknown"}.`);
126
- }
127
- }
128
- async function runProjectDependencyInstall(io, projectRoot, spawn2 = spawnSync) {
129
- const invocation = await resolvePackageManagerInstallInvocation(projectRoot);
130
- const result = spawn2(invocation.command, [...invocation.args], {
131
- cwd: projectRoot,
132
- encoding: "utf8",
133
- env: process.env
134
- });
135
- if (result.stdout) {
136
- io.stdout.write(result.stdout);
137
- }
138
- if (result.stderr) {
139
- io.stderr.write(result.stderr);
140
- }
141
- if (result.status !== 0) {
142
- throw new Error(result.stderr?.trim() || result.stdout?.trim() || "Project dependency installation failed.");
143
- }
144
- }
145
- async function runProjectPrepare(projectRoot, io, options = {}) {
146
- const project = await ensureProjectConfig(projectRoot);
147
- await ensureGeneratedSchemaPlaceholder(projectRoot, project.config);
148
- await prepareProjectDiscovery(projectRoot, project.config);
149
- await refreshFrameworkRunner(projectRoot);
150
- const syncFramework = options.syncFramework ?? true;
151
- const syncDefinitions = syncFramework ? await resolveProjectFrameworkSyncDefinitions(projectRoot) : [];
152
- if (syncFramework) {
153
- for (const definition of syncDefinitions) {
154
- await runFrameworkSync(projectRoot, definition);
155
- }
156
- }
157
- const updatedDependencies = await syncManagedDriverDependencies(projectRoot);
158
- if (updatedDependencies && io) {
159
- await runProjectDependencyInstall(io, projectRoot);
160
- await prepareProjectDiscovery(projectRoot, project.config);
161
- await refreshFrameworkRunner(projectRoot);
162
- if (syncFramework) {
163
- for (const definition of syncDefinitions) {
164
- await runFrameworkSync(projectRoot, definition);
165
- }
166
- }
167
- }
168
- }
169
- async function runProjectHotPrepare(projectRoot, io) {
170
- await runProjectPrepare(projectRoot, io, { syncFramework: false });
171
- }
172
- async function refreshFrameworkRunner(projectRoot) {
173
- const frameworkProjectPath = resolve(projectRoot, ".holo-js/framework/project.json");
174
- const frameworkRunnerPath = resolve(projectRoot, ".holo-js/framework/run.mjs");
175
- const descriptor = await resolveProjectFramework(projectRoot, frameworkProjectPath);
176
- if (!descriptor) {
177
- return;
178
- }
179
- await writeTextFile(frameworkProjectPath, `${JSON.stringify({ framework: descriptor.id }, null, 2)}
180
- `);
181
- await writeTextFile(frameworkRunnerPath, renderFrameworkRunnerForDescriptor(descriptor));
182
- }
183
- async function resolveProjectFramework(projectRoot, frameworkProjectPath) {
184
- const pluginDescriptors = await loadProjectPluginFrameworkDescriptors(projectRoot);
185
- try {
186
- const content = await readFile(frameworkProjectPath, "utf8");
187
- const manifest = JSON.parse(content);
188
- const descriptor = typeof manifest.framework === "string" ? getFrameworkDescriptorByIdFrom(manifest.framework, pluginDescriptors) : void 0;
189
- return descriptor ?? resolveProjectFrameworkFromDependencies(projectRoot, pluginDescriptors);
190
- } catch {
191
- return resolveProjectFrameworkFromDependencies(projectRoot, pluginDescriptors);
192
- }
193
- }
194
- async function resolveProjectFrameworkFromDependencies(projectRoot, pluginDescriptors = []) {
195
- for (const descriptor of getFrameworkDescriptorsWith(pluginDescriptors)) {
196
- const matches = await Promise.all(
197
- descriptor.detectPackages.map((packageName) => hasProjectDependency(projectRoot, packageName))
198
- );
199
- if (matches.some(Boolean)) {
200
- return descriptor;
201
- }
202
- }
203
- return void 0;
204
- }
205
- async function resolveProjectFrameworkSyncDefinitions(projectRoot) {
206
- const pluginDescriptors = await loadProjectPluginFrameworkDescriptors(projectRoot);
207
- const seen = /* @__PURE__ */ new Set();
208
- const definitions = [];
209
- for (const descriptor of getFrameworkDescriptorsWith(pluginDescriptors)) {
210
- if (!descriptor.sync || seen.has(descriptor.id)) {
211
- continue;
212
- }
213
- seen.add(descriptor.id);
214
- definitions.push({
215
- framework: descriptor.id,
216
- commands: descriptor.sync.commands,
217
- errorLabel: descriptor.sync.errorLabel
218
- });
219
- }
220
- return Object.freeze(definitions);
221
- }
222
- async function runFrameworkSync(projectRoot, definition) {
223
- const frameworkProjectPath = resolve(projectRoot, ".holo-js/framework/project.json");
224
- try {
225
- const content = await readFile(frameworkProjectPath, "utf8");
226
- const manifest = JSON.parse(content);
227
- if (manifest.framework !== definition.framework) {
228
- return;
229
- }
230
- } catch {
231
- return;
232
- }
233
- const manager = await resolveProjectPackageManager(projectRoot);
234
- const invocation = definition.commands[manager];
235
- const command = invocation[0];
236
- const args = invocation.slice(1);
237
- await new Promise((resolve2, reject) => {
238
- const child = spawn(command, args, {
239
- cwd: projectRoot,
240
- stdio: "inherit"
241
- });
242
- child.on("close", (code) => {
243
- if (code === 0) {
244
- resolve2(void 0);
245
- } else {
246
- reject(new Error(`${definition.errorLabel} exited with ${code}`));
247
- }
248
- });
249
- child.on("error", reject);
250
- });
251
- }
252
- function toPosixSlashes(value) {
253
- return value.replaceAll("\\", "/");
254
- }
255
- var PACKAGE_MANIFEST_DISCOVERY_PATHS = /* @__PURE__ */ new Set([
256
- "package.json",
257
- "bun.lock",
258
- "package-lock.json",
259
- "pnpm-lock.yaml",
260
- "yarn.lock"
261
- ]);
262
- function resolveConfiguredBroadcastPath(project) {
263
- const configuredPaths = project.config.paths;
264
- return configuredPaths.broadcast ?? "server/broadcast";
265
- }
266
- function resolveConfiguredChannelsPath(project) {
267
- const configuredPaths = project.config.paths;
268
- return configuredPaths.channels ?? "server/channels";
269
- }
270
- function resolveConfiguredRealtimePath(project) {
271
- const configuredPaths = project.config.paths;
272
- return configuredPaths.realtime ?? "server/realtime";
273
- }
274
- function resolveConfiguredDiscoveryRoots(project) {
275
- const authorizationPoliciesPath = project.config.paths.authorizationPolicies || "server/policies";
276
- const authorizationAbilitiesPath = project.config.paths.authorizationAbilities || "server/abilities";
277
- return [
278
- project.config.paths.models,
279
- project.config.paths.migrations,
280
- project.config.paths.seeders,
281
- project.config.paths.commands,
282
- project.config.paths.jobs,
283
- project.config.paths.events,
284
- project.config.paths.listeners,
285
- authorizationPoliciesPath,
286
- authorizationAbilitiesPath,
287
- resolveConfiguredBroadcastPath(project),
288
- resolveConfiguredChannelsPath(project),
289
- resolveConfiguredRealtimePath(project),
290
- "config"
291
- ];
292
- }
293
- function isDiscoveryRelevantPath(filePath, project) {
294
- const normalized = toPosixSlashes(filePath);
295
- if (PACKAGE_MANIFEST_DISCOVERY_PATHS.has(normalized)) {
296
- return true;
297
- }
298
- const generatedSchemaPath = toPosixSlashes(project.config.paths.generatedSchema ?? ".holo-js/generated/schema.generated.ts");
299
- if (normalized === generatedSchemaPath) {
300
- return true;
301
- }
302
- if (normalized === ".holo-js/generated" || normalized.startsWith(".holo-js/generated/")) {
303
- return false;
304
- }
305
- if (normalized === ".env" || normalized.startsWith(".env.")) {
306
- return true;
307
- }
308
- return resolveConfiguredDiscoveryRoots(project).some((root) => normalized === root || normalized.startsWith(`${toPosixSlashes(root)}/`));
309
- }
310
- function isRecursiveWatchUnsupported(error) {
311
- return error instanceof Error && (error.message.includes("recursive") || "code" in error && error.code === "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM");
312
- }
313
- function isIgnorableWatchError(error) {
314
- return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "EPERM");
315
- }
316
- async function collectDirectoryTree(rootPath, directories) {
317
- const rootStats = await stat(rootPath).catch(() => void 0);
318
- if (!rootStats?.isDirectory()) {
319
- return;
320
- }
321
- directories.add(rootPath);
322
- const entries = await readdir(rootPath, { withFileTypes: true }).catch(() => []);
323
- for (const entry of entries) {
324
- if (!entry.isDirectory()) {
325
- continue;
326
- }
327
- await collectDirectoryTree(join(rootPath, entry.name), directories);
328
- }
329
- }
330
- async function collectDiscoveryWatchRoots(projectRoot, project) {
331
- const directories = /* @__PURE__ */ new Set();
332
- const roots = [
333
- projectRoot,
334
- ...resolveConfiguredDiscoveryRoots(project).map((root) => resolve(projectRoot, root)),
335
- resolve(projectRoot, dirname(project.config.paths.generatedSchema ?? ".holo-js/generated/schema.generated.ts"))
336
- ];
337
- for (const rootPath of roots) {
338
- await collectDirectoryTree(rootPath, directories);
339
- }
340
- return [...directories];
341
- }
342
- function normalizeWatchedFilePath(projectRoot, watchedRoot, fileName) {
343
- return toPosixSlashes(relative(projectRoot, resolve(watchedRoot, fileName)));
344
- }
345
- async function runProjectDevServer(io, projectRoot, spawnProcess = spawn, createWatcher = watch, prepare = runProjectPrepare) {
346
- let project = await ensureProjectConfig(projectRoot);
347
- let refreshNonRecursiveWatchers;
348
- let requestChildRestart;
349
- const hotPrepare = prepare === runProjectPrepare ? runProjectHotPrepare : prepare;
350
- const prepareDiscovery = async (syncFramework = false) => {
351
- await (syncFramework ? prepare : hotPrepare)(projectRoot, io);
352
- project = await ensureProjectConfig(projectRoot);
353
- await refreshNonRecursiveWatchers?.();
354
- };
355
- await prepareDiscovery(true);
356
- let pendingPrepare;
357
- let queued = false;
358
- let shuttingDown = false;
359
- const rerunPrepare = () => {
360
- if (shuttingDown) {
361
- return;
362
- }
363
- if (pendingPrepare) {
364
- queued = true;
365
- return;
366
- }
367
- pendingPrepare = prepareDiscovery().then(() => {
368
- requestChildRestart?.();
369
- }).catch((error) => {
370
- io.stderr.write(`${error instanceof Error ? error.message : String(error)}
371
- `);
372
- }).finally(() => {
373
- pendingPrepare = void 0;
374
- if (queued) {
375
- queued = false;
376
- rerunPrepare();
377
- }
378
- });
379
- };
380
- const closeWatchers = (() => {
381
- try {
382
- const watcher = createWatcher(projectRoot, { recursive: true }, (_eventType, fileName) => {
383
- if (shuttingDown || typeof fileName !== "string" || !isDiscoveryRelevantPath(fileName, project)) {
384
- return;
385
- }
386
- rerunPrepare();
387
- });
388
- return () => watcher.close();
389
- } catch (error) {
390
- if (!isRecursiveWatchUnsupported(error)) {
391
- throw error;
392
- }
393
- const watchers = [];
394
- const closeAllWatchers = () => {
395
- while (watchers.length > 0) {
396
- watchers.pop()?.close();
397
- }
398
- };
399
- refreshNonRecursiveWatchers = async () => {
400
- closeAllWatchers();
401
- const watchRoots = await collectDiscoveryWatchRoots(projectRoot, project);
402
- for (const watchRoot of watchRoots) {
403
- try {
404
- watchers.push(createWatcher(watchRoot, { recursive: false }, (_eventType, fileName) => {
405
- if (shuttingDown || typeof fileName !== "string") {
406
- return;
407
- }
408
- const normalizedPath = normalizeWatchedFilePath(projectRoot, watchRoot, fileName);
409
- if (!isDiscoveryRelevantPath(normalizedPath, project)) {
410
- return;
411
- }
412
- rerunPrepare();
413
- }));
414
- } catch (watchError) {
415
- if (!isIgnorableWatchError(watchError)) {
416
- throw watchError;
417
- }
418
- }
419
- }
420
- };
421
- return () => closeAllWatchers();
422
- }
423
- })();
424
- await refreshNonRecursiveWatchers?.();
425
- const invocation = resolveFrameworkRunnerInvocation(projectRoot, "dev");
426
- while (!shuttingDown) {
427
- const child = spawnProcess(invocation.command, [...invocation.args], {
428
- cwd: projectRoot,
429
- env: process.env,
430
- stdio: ["pipe", "pipe", "pipe"]
431
- });
432
- child.stdout?.on("data", (chunk) => io.stdout.write(chunk));
433
- child.stderr?.on("data", (chunk) => io.stderr.write(chunk));
434
- if (child.stdin) {
435
- io.stdin.pipe(child.stdin);
436
- }
437
- const result = await new Promise((resolvePromise) => {
438
- let restartRequested = false;
439
- requestChildRestart = () => {
440
- if (restartRequested || shuttingDown || typeof child.kill !== "function") {
441
- return;
442
- }
443
- restartRequested = true;
444
- child.kill("SIGTERM");
445
- };
446
- child.on("error", (error) => {
447
- if (child.stdin) {
448
- io.stdin.unpipe(child.stdin);
449
- }
450
- requestChildRestart = void 0;
451
- if (restartRequested) {
452
- resolvePromise({ kind: "restart" });
453
- return;
454
- }
455
- resolvePromise({ kind: "error", error });
456
- });
457
- child.on("close", (code) => {
458
- if (child.stdin) {
459
- io.stdin.unpipe(child.stdin);
460
- }
461
- requestChildRestart = void 0;
462
- if (restartRequested) {
463
- resolvePromise({ kind: "restart" });
464
- return;
465
- }
466
- resolvePromise({ kind: "close", code });
467
- });
468
- });
469
- if (result.kind === "restart") {
470
- continue;
471
- }
472
- shuttingDown = true;
473
- closeWatchers();
474
- await Promise.resolve(pendingPrepare);
475
- if (result.kind === "error") {
476
- throw result.error;
477
- }
478
- if (result.code === 0) {
479
- return;
480
- }
481
- throw new Error(`Project development server failed with exit code ${result.code ?? "unknown"}.`);
482
- }
483
- }
484
-
485
- export {
486
- resolveProjectPackageManager,
487
- resolvePackageManagerCommand,
488
- resolvePackageManagerInstallInvocation,
489
- runProjectBuild,
490
- runProjectStartServer,
491
- runProjectDependencyInstall,
492
- runProjectPrepare,
493
- toPosixSlashes,
494
- isDiscoveryRelevantPath,
495
- isRecursiveWatchUnsupported,
496
- isIgnorableWatchError,
497
- collectDirectoryTree,
498
- collectDiscoveryWatchRoots,
499
- normalizeWatchedFilePath,
500
- runProjectDevServer
501
- };