@holo-js/cli 0.2.6 → 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.
- package/dist/bin/holo.mjs +417 -109
- package/dist/{broadcast-JBQWQZSO.mjs → broadcast-PJLFVZH4.mjs} +12 -12
- package/dist/cache-KR4ACOYD.mjs +137 -0
- package/dist/{cache-migrations-77TLXIVG.mjs → cache-migrations-J34RE4WH.mjs} +13 -13
- package/dist/{chunk-LXGQCG56.mjs → chunk-2XXJ76YC.mjs} +1 -1
- package/dist/chunk-3ICVWL2M.mjs +491 -0
- package/dist/{chunk-YEFJBN56.mjs → chunk-4VYR2ARA.mjs} +11 -8
- package/dist/{chunk-VP2E62DF.mjs → chunk-7KZVFDSI.mjs} +49 -349
- package/dist/chunk-AZ6NVJAP.mjs +360 -0
- package/dist/chunk-CT23GSEC.mjs +156 -0
- package/dist/{chunk-7B2RVYLL.mjs → chunk-FFTJKBQF.mjs} +293 -399
- package/dist/{chunk-KS5TWO75.mjs → chunk-I3RRWDLV.mjs} +7 -7
- package/dist/{chunk-J76GH2DR.mjs → chunk-L3YATEQY.mjs} +129 -86
- package/dist/{chunk-4K4CWMMP.mjs → chunk-L6FF22IV.mjs} +76 -61
- package/dist/{chunk-ILU426CF.mjs → chunk-PVVGQSUP.mjs} +482 -2
- package/dist/chunk-XBOVM6LO.mjs +41 -0
- package/dist/{chunk-I7QBCEV7.mjs → chunk-Y355VYRN.mjs} +5 -3
- package/dist/{chunk-VRGB6DIS.mjs → chunk-YJWHIQ45.mjs} +2 -0
- package/dist/{config-MD27U4FM.mjs → config-XVPV6DJW.mjs} +3 -3
- package/dist/{dev-L4Y2GU2E.mjs → dev-NTQTEY5B.mjs} +9 -8
- package/dist/{discovery-GWTBF5RZ.mjs → discovery-TMPUQQHI.mjs} +8 -6
- package/dist/{generators-VCYISHWO.mjs → generators-3FDCCJDC.mjs} +16 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +419 -111
- package/dist/{media-migrations-BNVAPYEM.mjs → media-migrations-UJ6BMUSZ.mjs} +12 -12
- package/dist/plugins-USHY6SPF.mjs +24 -0
- package/dist/{queue-5BXSDFCO.mjs → queue-6U7JU4T6.mjs} +53 -17
- package/dist/{queue-D4LSWNS2.mjs → queue-VJEFD6SE.mjs} +55 -19
- package/dist/{queue-migrations-EF4AMMSY.mjs → queue-migrations-6YUUOKMH.mjs} +17 -14
- package/dist/{runtime-RPMZMTD4.mjs → runtime-FVRB4O2M.mjs} +8 -8
- package/dist/{runtime-GSXF4NB3.mjs → runtime-P5R7H3B4.mjs} +1 -1
- package/dist/runtime-worker.mjs +7 -1
- package/dist/{scaffold-NJ5VH73M.mjs → scaffold-F3AZDNPG.mjs} +9 -4
- package/dist/{security-K5PZS3E3.mjs → security-X4274RHX.mjs} +8 -7
- package/package.json +35 -8
- package/dist/broadcast-YGJFCEPP.mjs +0 -204
- package/dist/cache-HUGRWOHQ.mjs +0 -66
- package/dist/cache-OSJ4PD52.mjs +0 -66
- package/dist/cache-migrations-FKAHRP24.mjs +0 -173
- package/dist/chunk-AJLRAC5M.mjs +0 -497
- package/dist/chunk-C624G3R2.mjs +0 -3306
- package/dist/chunk-D7O4SU6N.mjs +0 -2
- package/dist/chunk-FGQ2I2YH.mjs +0 -22
- package/dist/chunk-LBJAJLKU.mjs +0 -25
- package/dist/dev-YPBQBEOE.mjs +0 -44
- package/dist/generators-H4NTV4DB.mjs +0 -520
- package/dist/media-migrations-NNB3DAQR.mjs +0 -106
- package/dist/queue-migrations-LXEWXJYT.mjs +0 -168
- package/dist/runtime-UKBJQFXM.mjs +0 -57
- package/dist/scaffold-VV3KTYGO.mjs +0 -139
- package/dist/security-JR4P7L2C.mjs +0 -71
package/dist/chunk-AJLRAC5M.mjs
DELETED
|
@@ -1,497 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hasProjectDependency
|
|
3
|
-
} from "./chunk-FGQ2I2YH.mjs";
|
|
4
|
-
import {
|
|
5
|
-
prepareProjectDiscovery
|
|
6
|
-
} from "./chunk-VP2E62DF.mjs";
|
|
7
|
-
import {
|
|
8
|
-
syncManagedDriverDependencies
|
|
9
|
-
} from "./chunk-7B2RVYLL.mjs";
|
|
10
|
-
import {
|
|
11
|
-
ensureGeneratedSchemaPlaceholder,
|
|
12
|
-
ensureProjectConfig
|
|
13
|
-
} from "./chunk-YEFJBN56.mjs";
|
|
14
|
-
import {
|
|
15
|
-
renderFrameworkRunner
|
|
16
|
-
} from "./chunk-J76GH2DR.mjs";
|
|
17
|
-
import {
|
|
18
|
-
readTextFile,
|
|
19
|
-
writeTextFile
|
|
20
|
-
} from "./chunk-ILU426CF.mjs";
|
|
21
|
-
|
|
22
|
-
// src/dev.ts
|
|
23
|
-
import { spawnSync, spawn } from "child_process";
|
|
24
|
-
import { watch } from "fs";
|
|
25
|
-
import { readdir, stat } from "fs/promises";
|
|
26
|
-
import { join, dirname, relative, resolve } from "path";
|
|
27
|
-
import { readFile } from "fs/promises";
|
|
28
|
-
async function fileExists(path) {
|
|
29
|
-
try {
|
|
30
|
-
await stat(path);
|
|
31
|
-
return true;
|
|
32
|
-
} catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
async function resolveProjectPackageManager(projectRoot) {
|
|
37
|
-
const packageJsonPath = join(projectRoot, "package.json");
|
|
38
|
-
const packageJson = await readTextFile(packageJsonPath);
|
|
39
|
-
if (packageJson) {
|
|
40
|
-
try {
|
|
41
|
-
const parsed = JSON.parse(packageJson);
|
|
42
|
-
const packageManager = typeof parsed.packageManager === "string" ? parsed.packageManager.split("@")[0] : void 0;
|
|
43
|
-
if (packageManager === "bun" || packageManager === "npm" || packageManager === "pnpm" || packageManager === "yarn") {
|
|
44
|
-
return packageManager;
|
|
45
|
-
}
|
|
46
|
-
} catch {
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (await fileExists(join(projectRoot, "bun.lock"))) {
|
|
50
|
-
return "bun";
|
|
51
|
-
}
|
|
52
|
-
if (await fileExists(join(projectRoot, "pnpm-lock.yaml"))) {
|
|
53
|
-
return "pnpm";
|
|
54
|
-
}
|
|
55
|
-
if (await fileExists(join(projectRoot, "yarn.lock"))) {
|
|
56
|
-
return "yarn";
|
|
57
|
-
}
|
|
58
|
-
if (await fileExists(join(projectRoot, "package-lock.json"))) {
|
|
59
|
-
return "npm";
|
|
60
|
-
}
|
|
61
|
-
return "bun";
|
|
62
|
-
}
|
|
63
|
-
async function resolvePackageManagerCommand(projectRoot, scriptName) {
|
|
64
|
-
const packageManager = await resolveProjectPackageManager(projectRoot);
|
|
65
|
-
return {
|
|
66
|
-
command: packageManager,
|
|
67
|
-
args: ["run", scriptName]
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
async function resolvePackageManagerInstallInvocation(projectRoot) {
|
|
71
|
-
const packageManager = await resolveProjectPackageManager(projectRoot);
|
|
72
|
-
return {
|
|
73
|
-
command: packageManager,
|
|
74
|
-
args: ["install"]
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function resolveFrameworkRunnerInvocation(projectRoot, mode) {
|
|
78
|
-
return {
|
|
79
|
-
command: process.execPath,
|
|
80
|
-
args: [join(projectRoot, ".holo-js/framework/run.mjs"), mode]
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
async function runProjectBuild(io, projectRoot, spawn2 = spawnSync) {
|
|
84
|
-
const invocation = resolveFrameworkRunnerInvocation(projectRoot, "build");
|
|
85
|
-
const result = spawn2(invocation.command, [...invocation.args], {
|
|
86
|
-
cwd: projectRoot,
|
|
87
|
-
encoding: "utf8",
|
|
88
|
-
env: process.env
|
|
89
|
-
});
|
|
90
|
-
if (result.stdout) {
|
|
91
|
-
io.stdout.write(result.stdout);
|
|
92
|
-
}
|
|
93
|
-
if (result.stderr) {
|
|
94
|
-
io.stderr.write(result.stderr);
|
|
95
|
-
}
|
|
96
|
-
if (result.status !== 0) {
|
|
97
|
-
throw new Error(result.stderr?.trim() || result.stdout?.trim() || "Project build failed.");
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
async function runProjectStartServer(io, projectRoot, spawnProcess = spawn, passthroughArgs = []) {
|
|
101
|
-
const invocation = resolveFrameworkRunnerInvocation(projectRoot, "start");
|
|
102
|
-
const child = spawnProcess(invocation.command, [...invocation.args, ...passthroughArgs], {
|
|
103
|
-
cwd: projectRoot,
|
|
104
|
-
env: process.env,
|
|
105
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
106
|
-
});
|
|
107
|
-
child.stdout?.on("data", (chunk) => io.stdout.write(chunk));
|
|
108
|
-
child.stderr?.on("data", (chunk) => io.stderr.write(chunk));
|
|
109
|
-
if (child.stdin) {
|
|
110
|
-
io.stdin.pipe(child.stdin);
|
|
111
|
-
}
|
|
112
|
-
const result = await new Promise((resolvePromise) => {
|
|
113
|
-
child.on("error", (error) => resolvePromise({ kind: "error", error }));
|
|
114
|
-
child.on("close", (code) => resolvePromise({ kind: "close", code }));
|
|
115
|
-
});
|
|
116
|
-
if (result.kind === "error") {
|
|
117
|
-
throw result.error;
|
|
118
|
-
}
|
|
119
|
-
if (result.code !== 0) {
|
|
120
|
-
throw new Error(`Project production server failed with exit code ${result.code ?? "unknown"}.`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
async function runProjectDependencyInstall(io, projectRoot, spawn2 = spawnSync) {
|
|
124
|
-
const invocation = await resolvePackageManagerInstallInvocation(projectRoot);
|
|
125
|
-
const result = spawn2(invocation.command, [...invocation.args], {
|
|
126
|
-
cwd: projectRoot,
|
|
127
|
-
encoding: "utf8",
|
|
128
|
-
env: process.env
|
|
129
|
-
});
|
|
130
|
-
if (result.stdout) {
|
|
131
|
-
io.stdout.write(result.stdout);
|
|
132
|
-
}
|
|
133
|
-
if (result.stderr) {
|
|
134
|
-
io.stderr.write(result.stderr);
|
|
135
|
-
}
|
|
136
|
-
if (result.status !== 0) {
|
|
137
|
-
throw new Error(result.stderr?.trim() || result.stdout?.trim() || "Project dependency installation failed.");
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
var FRAMEWORK_SYNC_DEFINITIONS = [
|
|
141
|
-
{
|
|
142
|
-
framework: "nuxt",
|
|
143
|
-
commands: {
|
|
144
|
-
bun: ["bun", "x", "nuxt", "prepare"],
|
|
145
|
-
npm: ["npm", "exec", "--", "nuxt", "prepare"],
|
|
146
|
-
pnpm: ["pnpm", "exec", "nuxt", "prepare"],
|
|
147
|
-
yarn: ["yarn", "run", "nuxt", "prepare"]
|
|
148
|
-
},
|
|
149
|
-
errorLabel: "nuxt prepare"
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
framework: "sveltekit",
|
|
153
|
-
commands: {
|
|
154
|
-
bun: ["bun", "x", "svelte-kit", "sync"],
|
|
155
|
-
npm: ["npm", "exec", "--", "svelte-kit", "sync"],
|
|
156
|
-
pnpm: ["pnpm", "exec", "svelte-kit", "sync"],
|
|
157
|
-
yarn: ["yarn", "run", "svelte-kit", "sync"]
|
|
158
|
-
},
|
|
159
|
-
errorLabel: "svelte-kit sync"
|
|
160
|
-
}
|
|
161
|
-
];
|
|
162
|
-
async function runProjectPrepare(projectRoot, io, options = {}) {
|
|
163
|
-
const project = await ensureProjectConfig(projectRoot);
|
|
164
|
-
await ensureGeneratedSchemaPlaceholder(projectRoot, project.config);
|
|
165
|
-
await prepareProjectDiscovery(projectRoot, project.config);
|
|
166
|
-
await refreshFrameworkRunner(projectRoot);
|
|
167
|
-
const syncFramework = options.syncFramework ?? true;
|
|
168
|
-
if (syncFramework) {
|
|
169
|
-
await runFrameworkSync(projectRoot, FRAMEWORK_SYNC_DEFINITIONS[0]);
|
|
170
|
-
await runFrameworkSync(projectRoot, FRAMEWORK_SYNC_DEFINITIONS[1]);
|
|
171
|
-
}
|
|
172
|
-
const updatedDependencies = await syncManagedDriverDependencies(projectRoot);
|
|
173
|
-
if (updatedDependencies && io) {
|
|
174
|
-
await runProjectDependencyInstall(io, projectRoot);
|
|
175
|
-
await prepareProjectDiscovery(projectRoot, project.config);
|
|
176
|
-
await refreshFrameworkRunner(projectRoot);
|
|
177
|
-
if (syncFramework) {
|
|
178
|
-
await runFrameworkSync(projectRoot, FRAMEWORK_SYNC_DEFINITIONS[0]);
|
|
179
|
-
await runFrameworkSync(projectRoot, FRAMEWORK_SYNC_DEFINITIONS[1]);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
async function runProjectHotPrepare(projectRoot, io) {
|
|
184
|
-
await runProjectPrepare(projectRoot, io, { syncFramework: false });
|
|
185
|
-
}
|
|
186
|
-
async function refreshFrameworkRunner(projectRoot) {
|
|
187
|
-
const frameworkProjectPath = resolve(projectRoot, ".holo-js/framework/project.json");
|
|
188
|
-
const frameworkRunnerPath = resolve(projectRoot, ".holo-js/framework/run.mjs");
|
|
189
|
-
const framework = await resolveProjectFramework(projectRoot, frameworkProjectPath);
|
|
190
|
-
if (!framework) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
await writeTextFile(frameworkProjectPath, `${JSON.stringify({ framework }, null, 2)}
|
|
194
|
-
`);
|
|
195
|
-
await writeTextFile(frameworkRunnerPath, renderFrameworkRunner({ framework }));
|
|
196
|
-
}
|
|
197
|
-
async function resolveProjectFramework(projectRoot, frameworkProjectPath) {
|
|
198
|
-
try {
|
|
199
|
-
const content = await readFile(frameworkProjectPath, "utf8");
|
|
200
|
-
const manifest = JSON.parse(content);
|
|
201
|
-
if (manifest.framework !== "next" && manifest.framework !== "nuxt" && manifest.framework !== "sveltekit") {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
return manifest.framework;
|
|
205
|
-
} catch {
|
|
206
|
-
}
|
|
207
|
-
if (await hasProjectDependency(projectRoot, "next")) {
|
|
208
|
-
return "next";
|
|
209
|
-
}
|
|
210
|
-
if (await hasProjectDependency(projectRoot, "nuxt")) {
|
|
211
|
-
return "nuxt";
|
|
212
|
-
}
|
|
213
|
-
if (await hasProjectDependency(projectRoot, "@sveltejs/kit")) {
|
|
214
|
-
return "sveltekit";
|
|
215
|
-
}
|
|
216
|
-
return void 0;
|
|
217
|
-
}
|
|
218
|
-
async function runFrameworkSync(projectRoot, definition) {
|
|
219
|
-
const frameworkProjectPath = resolve(projectRoot, ".holo-js/framework/project.json");
|
|
220
|
-
try {
|
|
221
|
-
const content = await readFile(frameworkProjectPath, "utf8");
|
|
222
|
-
const manifest = JSON.parse(content);
|
|
223
|
-
if (manifest.framework !== definition.framework) {
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
} catch {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const manager = await resolveProjectPackageManager(projectRoot);
|
|
230
|
-
const invocation = definition.commands[manager];
|
|
231
|
-
const command = invocation[0];
|
|
232
|
-
const args = invocation.slice(1);
|
|
233
|
-
await new Promise((resolve2, reject) => {
|
|
234
|
-
const child = spawn(command, args, {
|
|
235
|
-
cwd: projectRoot,
|
|
236
|
-
stdio: "inherit"
|
|
237
|
-
});
|
|
238
|
-
child.on("close", (code) => {
|
|
239
|
-
if (code === 0) {
|
|
240
|
-
resolve2(void 0);
|
|
241
|
-
} else {
|
|
242
|
-
reject(new Error(`${definition.errorLabel} exited with ${code}`));
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
child.on("error", reject);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
function toPosixSlashes(value) {
|
|
249
|
-
return value.replaceAll("\\", "/");
|
|
250
|
-
}
|
|
251
|
-
var PACKAGE_MANIFEST_DISCOVERY_PATHS = /* @__PURE__ */ new Set([
|
|
252
|
-
"package.json",
|
|
253
|
-
"bun.lock",
|
|
254
|
-
"package-lock.json",
|
|
255
|
-
"pnpm-lock.yaml",
|
|
256
|
-
"yarn.lock"
|
|
257
|
-
]);
|
|
258
|
-
function resolveConfiguredBroadcastPath(project) {
|
|
259
|
-
const configuredPaths = project.config.paths;
|
|
260
|
-
return configuredPaths.broadcast ?? "server/broadcast";
|
|
261
|
-
}
|
|
262
|
-
function resolveConfiguredChannelsPath(project) {
|
|
263
|
-
const configuredPaths = project.config.paths;
|
|
264
|
-
return configuredPaths.channels ?? "server/channels";
|
|
265
|
-
}
|
|
266
|
-
function resolveConfiguredRealtimePath(project) {
|
|
267
|
-
const configuredPaths = project.config.paths;
|
|
268
|
-
return configuredPaths.realtime ?? "server/realtime";
|
|
269
|
-
}
|
|
270
|
-
function resolveConfiguredDiscoveryRoots(project) {
|
|
271
|
-
const authorizationPoliciesPath = project.config.paths.authorizationPolicies || "server/policies";
|
|
272
|
-
const authorizationAbilitiesPath = project.config.paths.authorizationAbilities || "server/abilities";
|
|
273
|
-
return [
|
|
274
|
-
project.config.paths.models,
|
|
275
|
-
project.config.paths.migrations,
|
|
276
|
-
project.config.paths.seeders,
|
|
277
|
-
project.config.paths.commands,
|
|
278
|
-
project.config.paths.jobs,
|
|
279
|
-
project.config.paths.events,
|
|
280
|
-
project.config.paths.listeners,
|
|
281
|
-
authorizationPoliciesPath,
|
|
282
|
-
authorizationAbilitiesPath,
|
|
283
|
-
resolveConfiguredBroadcastPath(project),
|
|
284
|
-
resolveConfiguredChannelsPath(project),
|
|
285
|
-
resolveConfiguredRealtimePath(project),
|
|
286
|
-
"config"
|
|
287
|
-
];
|
|
288
|
-
}
|
|
289
|
-
function isDiscoveryRelevantPath(filePath, project) {
|
|
290
|
-
const normalized = toPosixSlashes(filePath);
|
|
291
|
-
if (PACKAGE_MANIFEST_DISCOVERY_PATHS.has(normalized)) {
|
|
292
|
-
return true;
|
|
293
|
-
}
|
|
294
|
-
const generatedSchemaPath = toPosixSlashes(project.config.paths.generatedSchema ?? ".holo-js/generated/schema.generated.ts");
|
|
295
|
-
if (normalized === generatedSchemaPath) {
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
if (normalized === ".holo-js/generated" || normalized.startsWith(".holo-js/generated/")) {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
if (normalized === ".env" || normalized.startsWith(".env.")) {
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
return resolveConfiguredDiscoveryRoots(project).some((root) => normalized === root || normalized.startsWith(`${toPosixSlashes(root)}/`));
|
|
305
|
-
}
|
|
306
|
-
function isRecursiveWatchUnsupported(error) {
|
|
307
|
-
return error instanceof Error && (error.message.includes("recursive") || "code" in error && error.code === "ERR_FEATURE_UNAVAILABLE_ON_PLATFORM");
|
|
308
|
-
}
|
|
309
|
-
function isIgnorableWatchError(error) {
|
|
310
|
-
return error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "EPERM");
|
|
311
|
-
}
|
|
312
|
-
async function collectDirectoryTree(rootPath, directories) {
|
|
313
|
-
const rootStats = await stat(rootPath).catch(() => void 0);
|
|
314
|
-
if (!rootStats?.isDirectory()) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
directories.add(rootPath);
|
|
318
|
-
const entries = await readdir(rootPath, { withFileTypes: true }).catch(() => []);
|
|
319
|
-
for (const entry of entries) {
|
|
320
|
-
if (!entry.isDirectory()) {
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
await collectDirectoryTree(join(rootPath, entry.name), directories);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
async function collectDiscoveryWatchRoots(projectRoot, project) {
|
|
327
|
-
const directories = /* @__PURE__ */ new Set();
|
|
328
|
-
const roots = [
|
|
329
|
-
projectRoot,
|
|
330
|
-
...resolveConfiguredDiscoveryRoots(project).map((root) => resolve(projectRoot, root)),
|
|
331
|
-
resolve(projectRoot, dirname(project.config.paths.generatedSchema ?? ".holo-js/generated/schema.generated.ts"))
|
|
332
|
-
];
|
|
333
|
-
for (const rootPath of roots) {
|
|
334
|
-
await collectDirectoryTree(rootPath, directories);
|
|
335
|
-
}
|
|
336
|
-
return [...directories];
|
|
337
|
-
}
|
|
338
|
-
function normalizeWatchedFilePath(projectRoot, watchedRoot, fileName) {
|
|
339
|
-
return toPosixSlashes(relative(projectRoot, resolve(watchedRoot, fileName)));
|
|
340
|
-
}
|
|
341
|
-
async function runProjectDevServer(io, projectRoot, spawnProcess = spawn, createWatcher = watch, prepare = runProjectPrepare) {
|
|
342
|
-
let project = await ensureProjectConfig(projectRoot);
|
|
343
|
-
let refreshNonRecursiveWatchers;
|
|
344
|
-
let requestChildRestart;
|
|
345
|
-
const hotPrepare = prepare === runProjectPrepare ? runProjectHotPrepare : prepare;
|
|
346
|
-
const prepareDiscovery = async (syncFramework = false) => {
|
|
347
|
-
await (syncFramework ? prepare : hotPrepare)(projectRoot, io);
|
|
348
|
-
project = await ensureProjectConfig(projectRoot);
|
|
349
|
-
await refreshNonRecursiveWatchers?.();
|
|
350
|
-
};
|
|
351
|
-
await prepareDiscovery(true);
|
|
352
|
-
let pendingPrepare;
|
|
353
|
-
let queued = false;
|
|
354
|
-
let shuttingDown = false;
|
|
355
|
-
const rerunPrepare = () => {
|
|
356
|
-
if (shuttingDown) {
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
if (pendingPrepare) {
|
|
360
|
-
queued = true;
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
pendingPrepare = prepareDiscovery().then(() => {
|
|
364
|
-
requestChildRestart?.();
|
|
365
|
-
}).catch((error) => {
|
|
366
|
-
io.stderr.write(`${error instanceof Error ? error.message : String(error)}
|
|
367
|
-
`);
|
|
368
|
-
}).finally(() => {
|
|
369
|
-
pendingPrepare = void 0;
|
|
370
|
-
if (queued) {
|
|
371
|
-
queued = false;
|
|
372
|
-
rerunPrepare();
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
};
|
|
376
|
-
const closeWatchers = (() => {
|
|
377
|
-
try {
|
|
378
|
-
const watcher = createWatcher(projectRoot, { recursive: true }, (_eventType, fileName) => {
|
|
379
|
-
if (shuttingDown || typeof fileName !== "string" || !isDiscoveryRelevantPath(fileName, project)) {
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
rerunPrepare();
|
|
383
|
-
});
|
|
384
|
-
return () => watcher.close();
|
|
385
|
-
} catch (error) {
|
|
386
|
-
if (!isRecursiveWatchUnsupported(error)) {
|
|
387
|
-
throw error;
|
|
388
|
-
}
|
|
389
|
-
const watchers = [];
|
|
390
|
-
const closeAllWatchers = () => {
|
|
391
|
-
while (watchers.length > 0) {
|
|
392
|
-
watchers.pop()?.close();
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
refreshNonRecursiveWatchers = async () => {
|
|
396
|
-
closeAllWatchers();
|
|
397
|
-
const watchRoots = await collectDiscoveryWatchRoots(projectRoot, project);
|
|
398
|
-
for (const watchRoot of watchRoots) {
|
|
399
|
-
try {
|
|
400
|
-
watchers.push(createWatcher(watchRoot, { recursive: false }, (_eventType, fileName) => {
|
|
401
|
-
if (shuttingDown || typeof fileName !== "string") {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
const normalizedPath = normalizeWatchedFilePath(projectRoot, watchRoot, fileName);
|
|
405
|
-
if (!isDiscoveryRelevantPath(normalizedPath, project)) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
rerunPrepare();
|
|
409
|
-
}));
|
|
410
|
-
} catch (watchError) {
|
|
411
|
-
if (!isIgnorableWatchError(watchError)) {
|
|
412
|
-
throw watchError;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
return () => closeAllWatchers();
|
|
418
|
-
}
|
|
419
|
-
})();
|
|
420
|
-
await refreshNonRecursiveWatchers?.();
|
|
421
|
-
const invocation = resolveFrameworkRunnerInvocation(projectRoot, "dev");
|
|
422
|
-
while (!shuttingDown) {
|
|
423
|
-
const child = spawnProcess(invocation.command, [...invocation.args], {
|
|
424
|
-
cwd: projectRoot,
|
|
425
|
-
env: process.env,
|
|
426
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
427
|
-
});
|
|
428
|
-
child.stdout?.on("data", (chunk) => io.stdout.write(chunk));
|
|
429
|
-
child.stderr?.on("data", (chunk) => io.stderr.write(chunk));
|
|
430
|
-
if (child.stdin) {
|
|
431
|
-
io.stdin.pipe(child.stdin);
|
|
432
|
-
}
|
|
433
|
-
const result = await new Promise((resolvePromise) => {
|
|
434
|
-
let restartRequested = false;
|
|
435
|
-
requestChildRestart = () => {
|
|
436
|
-
if (restartRequested || shuttingDown || typeof child.kill !== "function") {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
restartRequested = true;
|
|
440
|
-
child.kill("SIGTERM");
|
|
441
|
-
};
|
|
442
|
-
child.on("error", (error) => {
|
|
443
|
-
if (child.stdin) {
|
|
444
|
-
io.stdin.unpipe(child.stdin);
|
|
445
|
-
}
|
|
446
|
-
requestChildRestart = void 0;
|
|
447
|
-
if (restartRequested) {
|
|
448
|
-
resolvePromise({ kind: "restart" });
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
resolvePromise({ kind: "error", error });
|
|
452
|
-
});
|
|
453
|
-
child.on("close", (code) => {
|
|
454
|
-
if (child.stdin) {
|
|
455
|
-
io.stdin.unpipe(child.stdin);
|
|
456
|
-
}
|
|
457
|
-
requestChildRestart = void 0;
|
|
458
|
-
if (restartRequested) {
|
|
459
|
-
resolvePromise({ kind: "restart" });
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
resolvePromise({ kind: "close", code });
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
if (result.kind === "restart") {
|
|
466
|
-
continue;
|
|
467
|
-
}
|
|
468
|
-
shuttingDown = true;
|
|
469
|
-
closeWatchers();
|
|
470
|
-
await Promise.resolve(pendingPrepare);
|
|
471
|
-
if (result.kind === "error") {
|
|
472
|
-
throw result.error;
|
|
473
|
-
}
|
|
474
|
-
if (result.code === 0) {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
throw new Error(`Project development server failed with exit code ${result.code ?? "unknown"}.`);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
export {
|
|
482
|
-
resolveProjectPackageManager,
|
|
483
|
-
resolvePackageManagerCommand,
|
|
484
|
-
resolvePackageManagerInstallInvocation,
|
|
485
|
-
runProjectBuild,
|
|
486
|
-
runProjectStartServer,
|
|
487
|
-
runProjectDependencyInstall,
|
|
488
|
-
runProjectPrepare,
|
|
489
|
-
toPosixSlashes,
|
|
490
|
-
isDiscoveryRelevantPath,
|
|
491
|
-
isRecursiveWatchUnsupported,
|
|
492
|
-
isIgnorableWatchError,
|
|
493
|
-
collectDirectoryTree,
|
|
494
|
-
collectDiscoveryWatchRoots,
|
|
495
|
-
normalizeWatchedFilePath,
|
|
496
|
-
runProjectDevServer
|
|
497
|
-
};
|