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