@orkestrel/process 0.0.10 → 0.0.12

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.
@@ -274,15 +274,15 @@ function isFile(target) {
274
274
  *
275
275
  * @remarks
276
276
  * Windows alone needs this list: the host searches the working directory before `PATH` and applies
277
- * `PATHEXT`, and Node reproduces neither for a direct spawn. Within each searched directory the
278
- * literal name is tried first and each `PATHEXT` candidate after it, whether or not the name already
279
- * carries an extension — so `report.txt` resolves to a `report.txt` file where one exists and to
280
- * `report.txt.cmd` where none does. The lookup reads the child's effective environment, so an
281
- * overridden `PATH` selects the executable the child would have found. A POSIX host resolves the
282
- * file itself, so the candidate list there is empty. An appended extension is spelled the way
283
- * `PATHEXT` spells it rather than the way the directory entry does, which the case-insensitive host
284
- * treats as the same file. A non-Windows platform returns an empty list because `execvp` performs
285
- * its own lookup.
277
+ * `PATHEXT`, and Node reproduces neither for a direct spawn. Within each searched directory,
278
+ * {@link buildExecutableCandidates} enumerates `PATHEXT` candidates for an extensionless name. For
279
+ * an extension-bearing name, it enumerates the literal path before `PATHEXT` candidates, so
280
+ * `report.txt` resolves to a `report.txt` file where one exists and to `report.txt.cmd` where none
281
+ * does. The lookup reads the child's effective environment, so an overridden `PATH` selects the
282
+ * executable the child would have found. A POSIX host resolves the file itself, so the candidate
283
+ * list there is empty. A `PATHEXT` candidate keeps the extension spelling from `PATHEXT`, which the
284
+ * case-insensitive host treats as the same file. A non-Windows platform returns an empty list
285
+ * because `execvp` performs its own lookup.
286
286
  *
287
287
  * @param file - The command executable name or path
288
288
  * @param workspace - The directory searched first
@@ -297,7 +297,8 @@ function isFile(target) {
297
297
  */
298
298
  function buildExecutableCandidates(file, workspace, environment, platform) {
299
299
  if (platform !== "win32") return Object.freeze([]);
300
- const candidates = [file, ...(readPlatformVariable(environment, "PATHEXT", platform) ?? _src_core.PROCESS_PATHEXT).split(";").filter((extension) => extension.length > 0).map((extension) => `${file}${extension}`)];
300
+ const extensions = (readPlatformVariable(environment, "PATHEXT", platform) ?? _src_core.PROCESS_PATHEXT).split(";").filter((extension) => extension.length > 0);
301
+ const candidates = node_path.win32.extname(file).length === 0 ? extensions.map((extension) => `${file}${extension}`) : [file, ...extensions.map((extension) => `${file}${extension}`)];
301
302
  const directories = file.includes("/") || file.includes("\\") ? [workspace] : [workspace, ...(readPlatformVariable(environment, "PATH", platform) ?? "").split(";")];
302
303
  const targets = [];
303
304
  for (const directory of directories) {
@@ -307,7 +308,12 @@ function buildExecutableCandidates(file, workspace, environment, platform) {
307
308
  return Object.freeze(targets);
308
309
  }
309
310
  /**
310
- * Resolves a command file to the executable path the host would launch.
311
+ * Resolves a command file to the executable path the host would launch, or to `undefined` on a POSIX
312
+ * host, which performs its own lookup.
313
+ *
314
+ * @remarks
315
+ * A Windows lookup miss also returns `undefined`. {@link buildSpawn} preserves the command file as
316
+ * written for native spawning.
311
317
  *
312
318
  * @param file - The command executable name or path
313
319
  * @param options - The directory searched first and the child's effective environment
@@ -393,6 +399,10 @@ function buildPlatformSpawn(command, file, environment, platform) {
393
399
  /**
394
400
  * Builds the resolved spawn form of one command for the current host.
395
401
  *
402
+ * @remarks
403
+ * When executable lookup returns no regular-file candidate, {@link buildSpawn} preserves the
404
+ * command file as written for native spawning.
405
+ *
396
406
  * @param command - The executable and its argument vector
397
407
  * @param options - The directory searched first and the child's effective environment
398
408
  * @returns The file, argument vector, and verbatim flag to spawn with
@@ -1446,7 +1456,8 @@ var Supervisor = class {
1446
1456
  //#endregion
1447
1457
  //#region src/server/processes/Process.ts
1448
1458
  /**
1449
- * Supervises one child while keeping every observation channel aligned at termination.
1459
+ * Supervises one child, frames its standard output into lines under a bounded backlog, and keeps
1460
+ * every observation channel aligned at termination.
1450
1461
  *
1451
1462
  * @remarks
1452
1463
  * The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
@@ -1735,7 +1746,8 @@ var Process = class {
1735
1746
  //#endregion
1736
1747
  //#region src/server/processes/ProcessManager.ts
1737
1748
  /**
1738
- * Represents a keyed registry of live supervised child processes.
1749
+ * Launches supervised children under caller-chosen ids, evicts each one as it settles, and destroys
1750
+ * every live child on teardown.
1739
1751
  *
1740
1752
  * @remarks
1741
1753
  * A child launched under an id joins the registry and emits `launch`; when it settles it removes
@@ -2081,27 +2093,37 @@ var Session = class {
2081
2093
  //#endregion
2082
2094
  //#region src/server/factories.ts
2083
2095
  /**
2084
- * Creates one supervised child process.
2096
+ * Creates one supervised child process and returns it as a {@link ProcessInterface}, so a caller
2097
+ * holds the published contract rather than the `Process` class.
2085
2098
  *
2086
2099
  * @param options - Command, workspace, termination, evidence, stdin, and observation settings
2087
2100
  * @returns The launched {@link ProcessInterface}
2088
2101
  *
2089
- * @example
2102
+ * @example Supervise a child and read its lines
2090
2103
  * ```ts
2091
2104
  * import { createProcess } from '@orkestrel/process/server'
2092
2105
  *
2093
2106
  * const child = createProcess({
2094
- * command: { file: 'node', arguments: ['--version'] },
2107
+ * command: { file: 'node', arguments: ['-e', 'console.log("ready"); console.log("done")'] },
2095
2108
  * workspace: process.cwd(),
2096
- * grace: 5000,
2109
+ * grace: 5_000, // POSIX only: the window between SIGTERM and SIGKILL
2097
2110
  * })
2111
+ *
2112
+ * const lines: string[] = []
2113
+ * for await (const line of child.lines) lines.push(line)
2114
+ * lines // ['ready', 'done']
2115
+ *
2116
+ * const exit = await child.exit
2117
+ * exit.code // 0
2118
+ * await child.destroy()
2098
2119
  * ```
2099
2120
  */
2100
2121
  function createProcess(options) {
2101
2122
  return new Process(options);
2102
2123
  }
2103
2124
  /**
2104
- * Creates one raw byte session over a supervised child process.
2125
+ * Creates one raw byte session over a supervised child process and returns it as a
2126
+ * {@link SessionInterface}, so a caller holds the published contract rather than the `Session` class.
2105
2127
  *
2106
2128
  * @param options - Command, workspace, termination, evidence, stdin, and observation settings
2107
2129
  * @returns The launched {@link SessionInterface}
@@ -2121,7 +2143,9 @@ function createSession(options) {
2121
2143
  return new Session(options);
2122
2144
  }
2123
2145
  /**
2124
- * Creates one keyed registry of supervised child processes.
2146
+ * Creates one empty keyed registry of supervised child processes and returns it as a
2147
+ * {@link ProcessManagerInterface}, so a caller holds the published contract rather than the
2148
+ * `ProcessManager` class.
2125
2149
  *
2126
2150
  * @param options - Initial fleet-level observation hooks and listener-error handling
2127
2151
  * @returns The {@link ProcessManagerInterface} registry