@simplysm/core-node 14.0.14 → 14.0.16

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 CHANGED
@@ -26,8 +26,8 @@ Namespace `fsx` -- Enhanced file system functions (sync and async pairs).
26
26
  | `copySync` | function | Copy file/directory with filter (sync) |
27
27
  | `read` | function | Read file as UTF-8 string (async) |
28
28
  | `readSync` | function | Read file as UTF-8 string (sync) |
29
- | `readBuffer` | function | Read file as Buffer (async) |
30
- | `readBufferSync` | function | Read file as Buffer (sync) |
29
+ | `readBytes` | function | Read file as Uint8Array (async) |
30
+ | `readBytesSync` | function | Read file as Uint8Array (sync) |
31
31
  | `readJson` | function | Read and parse JSON file (async) |
32
32
  | `readJsonSync` | function | Read and parse JSON file (sync) |
33
33
  | `write` | function | Write data to file (async) |
@@ -54,15 +54,14 @@ Namespace `cpx` -- Child process execution utilities.
54
54
 
55
55
  | API | Type | Description |
56
56
  |-----|------|-------------|
57
- | `ExecOptions` | interface | Options for `exec` |
58
- | `ExecSyncOptions` | type | Options for `execSync` (same as `ExecOptions` without `reject`) |
59
- | `ExecResult` | interface | Result of a child process execution |
60
- | `ExecProcess` | class | `PromiseLike<ExecResult>` wrapper with `kill()` support |
61
- | `exec` | function | Spawn a child process (async, returns `ExecProcess`) |
62
- | `execSync` | function | Spawn a child process (sync) |
57
+ | `SpawnResult` | interface | Result of a spawned child process |
58
+ | `SpawnProcess` | class | `PromiseLike<SpawnResult>` wrapper with `kill()` support |
59
+ | `spawn` | function | Spawn a child process (async, returns `SpawnProcess`) |
60
+ | `spawnSync` | function | Spawn a child process (sync) |
63
61
  | `codePageToEncoding` | function | Convert Windows code page number to encoding name |
64
62
  | `getSystemEncoding` | function | Detect system console encoding (cached) |
65
63
  | `resetEncodingCache` | function | Clear the cached system encoding |
64
+ | `resolveStdioPipe` | function | Determine which stdio channels are piped |
66
65
  | `decodeBytes` | function | Decode `Uint8Array` output with system encoding fallback |
67
66
 
68
67
  > See [docs/cpx.md](./docs/cpx.md) for details.
@@ -118,6 +117,9 @@ import { fsx } from "@simplysm/core-node";
118
117
  const content = await fsx.read("/path/to/file.txt");
119
118
  await fsx.write("/path/to/output.txt", "hello");
120
119
 
120
+ // Binary read
121
+ const rawBytes = await fsx.readBytes("/path/to/image.png");
122
+
121
123
  // JSON
122
124
  const data = await fsx.readJson<{ name: string }>("/path/to/config.json");
123
125
  await fsx.writeJson("/path/to/out.json", data, { space: 2 });
@@ -135,15 +137,18 @@ const tsFiles = await fsx.glob("/project/src/**/*.ts");
135
137
  import { cpx } from "@simplysm/core-node";
136
138
 
137
139
  // Await result
138
- const result = await cpx.exec("git", ["status"], { cwd: "/project" });
140
+ const result = await cpx.spawn("git", ["status"], { cwd: "/project" });
139
141
  // result: { stdout, stderr, exitCode }
140
142
 
141
143
  // Kill a running process
142
- const proc = cpx.exec("long-running-cmd", []);
144
+ const proc = cpx.spawn("long-running-cmd", []);
143
145
  proc.kill();
144
146
 
145
147
  // Inherit stdio, don't reject on non-zero exit
146
- await cpx.exec("make", ["build"], { stdio: "inherit", reject: false });
148
+ await cpx.spawn("make", ["build"], { stdio: "inherit", reject: false });
149
+
150
+ // Synchronous execution
151
+ const syncResult = cpx.spawnSync("node", ["--version"]);
147
152
  ```
148
153
 
149
154
  ### Path utilities
package/docs/cpx.md CHANGED
@@ -9,38 +9,10 @@ import { cpx } from "@simplysm/core-node";
9
9
 
10
10
  ## Types
11
11
 
12
- ### ExecOptions
12
+ ### SpawnResult
13
13
 
14
14
  ```ts
15
- interface ExecOptions {
16
- cwd?: string;
17
- env?: Record<string, string>;
18
- stdio?: "pipe" | "inherit";
19
- shell?: boolean;
20
- reject?: boolean;
21
- }
22
- ```
23
-
24
- | Field | Type | Default | Description |
25
- |-------|------|---------|-------------|
26
- | `cwd` | `string` | `undefined` | Working directory for the child process |
27
- | `env` | `Record<string, string>` | `undefined` | Extra environment variables (merged with `process.env`) |
28
- | `stdio` | `"pipe" \| "inherit"` | `"pipe"` | `"pipe"` captures stdout/stderr; `"inherit"` passes them through |
29
- | `shell` | `boolean` | `false` | Run the command in a shell |
30
- | `reject` | `boolean` | `true` | If `false`, the promise resolves even on non-zero exit codes |
31
-
32
- ### ExecSyncOptions
33
-
34
- ```ts
35
- type ExecSyncOptions = Omit<ExecOptions, "reject">
36
- ```
37
-
38
- Same as `ExecOptions` without the `reject` field. `execSync` always returns a result regardless of exit code.
39
-
40
- ### ExecResult
41
-
42
- ```ts
43
- interface ExecResult {
15
+ interface SpawnResult {
44
16
  stdout: string;
45
17
  stderr: string;
46
18
  exitCode: number;
@@ -49,27 +21,27 @@ interface ExecResult {
49
21
 
50
22
  | Field | Type | Description |
51
23
  |-------|------|-------------|
52
- | `stdout` | `string` | Captured standard output (empty when `stdio: "inherit"`) |
53
- | `stderr` | `string` | Captured standard error (empty when `stdio: "inherit"`) |
24
+ | `stdout` | `string` | Captured standard output (empty when stdio is not `"pipe"`) |
25
+ | `stderr` | `string` | Captured standard error (empty when stdio is not `"pipe"`) |
54
26
  | `exitCode` | `number` | Process exit code |
55
27
 
56
- ## ExecProcess
28
+ ## SpawnProcess
57
29
 
58
30
  ```ts
59
- class ExecProcess implements PromiseLike<ExecResult> {
31
+ class SpawnProcess implements PromiseLike<SpawnResult> {
60
32
  get pid(): number | undefined;
61
33
  then<TResult1, TResult2>(
62
- onfulfilled?: ((value: ExecResult) => TResult1 | PromiseLike<TResult1>) | null,
34
+ onfulfilled?: ((value: SpawnResult) => TResult1 | PromiseLike<TResult1>) | null,
63
35
  onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,
64
36
  ): Promise<TResult1 | TResult2>;
65
37
  catch<TResult>(
66
38
  onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null,
67
- ): Promise<ExecResult | TResult>;
39
+ ): Promise<SpawnResult | TResult>;
68
40
  kill(signal?: NodeJS.Signals | number): boolean;
69
41
  }
70
42
  ```
71
43
 
72
- A `PromiseLike<ExecResult>` wrapper around `ChildProcess`. Can be `await`ed for the result or `kill()`ed to terminate the process.
44
+ A `PromiseLike<SpawnResult>` wrapper around `ChildProcess`. Can be `await`ed for the result or `kill()`ed to terminate the process.
73
45
 
74
46
  | Property/Method | Description |
75
47
  |-----------------|-------------|
@@ -80,35 +52,61 @@ A `PromiseLike<ExecResult>` wrapper around `ChildProcess`. Can be `await`ed for
80
52
 
81
53
  ## Functions
82
54
 
83
- ### exec
55
+ ### spawn
84
56
 
85
57
  ```ts
86
- function exec(cmd: string, args: string[], options?: ExecOptions): ExecProcess
58
+ function spawn(
59
+ cmd: string,
60
+ args: string[],
61
+ options?: SpawnOptions & { reject?: boolean },
62
+ ): SpawnProcess
87
63
  ```
88
64
 
89
- Spawn a child process asynchronously. Returns an `ExecProcess` that can be awaited or killed.
65
+ Spawn a child process asynchronously. Returns a `SpawnProcess` that can be awaited or killed. Options extend Node.js `SpawnOptions` with an additional `reject` field.
90
66
 
91
67
  | Parameter | Type | Description |
92
68
  |-----------|------|-------------|
93
69
  | `cmd` | `string` | Command to execute |
94
70
  | `args` | `string[]` | Command arguments |
95
- | `options` | `ExecOptions` | Execution options |
71
+ | `options` | `SpawnOptions & { reject?: boolean }` | Node.js spawn options plus `reject` (default `true`) |
96
72
 
97
- By default, rejects if exit code is non-zero. Set `options.reject: false` to always resolve. Output is decoded using system encoding detection (UTF-8 with fallback).
73
+ By default, rejects if exit code is non-zero. Set `options.reject: false` to always resolve. The `env` option is merged with `process.env`. Output is decoded using system encoding detection (UTF-8 with fallback).
98
74
 
99
- ### execSync
75
+ ### spawnSync
100
76
 
101
77
  ```ts
102
- function execSync(cmd: string, args: string[], options?: ExecSyncOptions): ExecResult
78
+ function spawnSync(
79
+ cmd: string,
80
+ args: string[],
81
+ options?: SpawnSyncOptions & { reject?: boolean },
82
+ ): SpawnResult
103
83
  ```
104
84
 
105
- Spawn a child process synchronously. Always returns an `ExecResult` regardless of exit code.
85
+ Spawn a child process synchronously. Options extend Node.js `SpawnSyncOptions` with an additional `reject` field.
106
86
 
107
87
  | Parameter | Type | Description |
108
88
  |-----------|------|-------------|
109
89
  | `cmd` | `string` | Command to execute |
110
90
  | `args` | `string[]` | Command arguments |
111
- | `options` | `ExecSyncOptions` | Execution options |
91
+ | `options` | `SpawnSyncOptions & { reject?: boolean }` | Node.js spawn sync options plus `reject` (default `true`) |
92
+
93
+ By default, throws if exit code is non-zero. Set `options.reject: false` to always return the result.
94
+
95
+ ### resolveStdioPipe
96
+
97
+ ```ts
98
+ function resolveStdioPipe(
99
+ stdio: SpawnOptions["stdio"],
100
+ ): { stdout: boolean; stderr: boolean }
101
+ ```
102
+
103
+ Determine whether stdout and stderr are piped based on the `stdio` option value.
104
+
105
+ | Parameter | Type | Description |
106
+ |-----------|------|-------------|
107
+ | `stdio` | `SpawnOptions["stdio"]` | The stdio configuration (string or array) |
108
+
109
+ Returns `{ stdout: true, stderr: true }` when `stdio` is `"pipe"` or `undefined`. For array form, checks `stdio[1]` and `stdio[2]` individually.
112
110
 
113
111
  ### codePageToEncoding
114
112
 
@@ -155,19 +153,19 @@ Decode a `Uint8Array` to a string. First tries UTF-8 (with `fatal: true`); if th
155
153
  import { cpx } from "@simplysm/core-node";
156
154
 
157
155
  // Basic execution
158
- const result = await cpx.exec("git", ["status"], { cwd: "/project" });
156
+ const result = await cpx.spawn("git", ["status"], { cwd: "/project" });
159
157
  // result.stdout, result.stderr, result.exitCode
160
158
 
161
159
  // Inherit stdio
162
- await cpx.exec("make", ["build"], { stdio: "inherit" });
160
+ await cpx.spawn("make", ["build"], { stdio: "inherit" });
163
161
 
164
162
  // Don't reject on failure
165
- const { exitCode } = await cpx.exec("test-cmd", [], { reject: false });
163
+ const { exitCode } = await cpx.spawn("test-cmd", [], { reject: false });
166
164
 
167
165
  // Kill a long-running process
168
- const proc = cpx.exec("long-cmd", []);
166
+ const proc = cpx.spawn("long-cmd", []);
169
167
  proc.kill();
170
168
 
171
169
  // Synchronous execution
172
- const syncResult = cpx.execSync("node", ["--version"]);
170
+ const syncResult = cpx.spawnSync("node", ["--version"]);
173
171
  ```
package/docs/fsx.md CHANGED
@@ -111,21 +111,21 @@ async function read(targetPath: string): Promise<string>
111
111
 
112
112
  Read a file as a UTF-8 string (async).
113
113
 
114
- ### readBufferSync
114
+ ### readBytesSync
115
115
 
116
116
  ```ts
117
- function readBufferSync(targetPath: string): Buffer
117
+ function readBytesSync(targetPath: string): Uint8Array
118
118
  ```
119
119
 
120
- Read a file as a Buffer (sync).
120
+ Read a file as a Uint8Array (sync).
121
121
 
122
- ### readBuffer
122
+ ### readBytes
123
123
 
124
124
  ```ts
125
- async function readBuffer(targetPath: string): Promise<Buffer>
125
+ async function readBytes(targetPath: string): Promise<Uint8Array>
126
126
  ```
127
127
 
128
- Read a file as a Buffer (async).
128
+ Read a file as a Uint8Array (async).
129
129
 
130
130
  ### readJsonSync
131
131
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/core-node",
3
- "version": "14.0.14",
3
+ "version": "14.0.16",
4
4
  "description": "심플리즘 패키지 - 코어 (node)",
5
5
  "author": "심플리즘",
6
6
  "license": "Apache-2.0",
@@ -25,7 +25,7 @@
25
25
  "glob": "^13.0.6",
26
26
  "minimatch": "^10.2.5",
27
27
  "tsx": "^4.21.0",
28
- "@simplysm/core-common": "14.0.14"
28
+ "@simplysm/core-common": "14.0.16"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^20.19.37"