soda-nodejs 0.8.5 → 0.8.7

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.
@@ -1,4 +1,4 @@
1
- import { ChildProcess, ChildProcessByStdio, ChildProcessWithoutNullStreams, SpawnOptions, SpawnOptionsWithStdioTuple, SpawnOptionsWithoutStdio, StdioNull, StdioPipe } from "child_process";
1
+ import { ChildProcess, ChildProcessByStdio, ChildProcessWithoutNullStreams, SpawnOptions, SpawnOptionsWithoutStdio, SpawnOptionsWithStdioTuple, StdioNull, StdioPipe } from "child_process";
2
2
  import { Readable, Writable } from "stream";
3
3
  export interface PromiseWithChildProcess<T> extends Promise<T> {
4
4
  child: T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soda-nodejs",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,15 +36,14 @@
36
36
  "homepage": "https://github.com/1adybug/deepsea/tree/main/packages/soda-nodejs",
37
37
  "dependencies": {
38
38
  "iconv-lite": "^0.7.0",
39
- "tar": "^7.5.1",
39
+ "tar": "^7.5.2",
40
40
  "which": "^5.0.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^24.7.0",
43
+ "@types/node": ">=24.10.1",
44
44
  "@types/which": "^3.0.4",
45
- "typescript": "^5.9.3"
45
+ "typescript": ">=5.8.3"
46
46
  },
47
- "peerDependencies": {},
48
47
  "scripts": {
49
48
  "dev": "rslib build --watch",
50
49
  "build": "rslib build",
@@ -1,5 +1,6 @@
1
1
  import { existsSync, mkdirSync } from "fs"
2
2
  import { basename, dirname, resolve } from "path"
3
+
3
4
  import { create } from "tar"
4
5
 
5
6
  export interface CompressionParams {
@@ -21,6 +22,7 @@ export async function compress({ input, output }: CompressionParams) {
21
22
 
22
23
  // 确保输出目录存在
23
24
  const outputDir = dirname(output)
25
+
24
26
  if (!existsSync(outputDir)) mkdirSync(outputDir, { recursive: true })
25
27
 
26
28
  // 执行压缩
package/src/utils/copy.ts CHANGED
@@ -16,16 +16,20 @@ export async function copy({ input, output, mode }: CopyOptions) {
16
16
  for (const item of input) await copy({ input: item, output, mode })
17
17
  return
18
18
  }
19
+
19
20
  if (!existsSync(output)) await mkdir(output, { recursive: true })
20
21
  const status = await stat(input)
21
22
  const { base } = parse(input)
23
+
22
24
  if (status.isFile()) {
23
25
  await copyFile(input, join(output, base), mode)
24
26
  return
25
27
  }
28
+
26
29
  if (status.isDirectory()) {
27
30
  await mkdir(join(output, base), { recursive: true })
28
31
  const entries = await readdir(input, { withFileTypes: true })
32
+
29
33
  for (const entry of entries) {
30
34
  await copy({
31
35
  input: join(input, entry.name),
@@ -1,5 +1,6 @@
1
- import { ExecOptions, exec } from "child_process"
1
+ import { exec, ExecOptions } from "child_process"
2
2
  import { ObjectEncodingOptions } from "fs"
3
+
3
4
  import iconv, { Options } from "iconv-lite"
4
5
 
5
6
  export type IconvDecodeOptions = {
@@ -21,15 +22,19 @@ export async function execAsync(
21
22
  ): Promise<string>
22
23
  export async function execAsync(command: string, options?: any) {
23
24
  const decode = options?.decode as IconvDecodeOptions | undefined
25
+
24
26
  if (typeof options === "object" && options !== null && options.decode) {
25
27
  const { decode, ...rest } = options as { decode: IconvDecodeOptions }
26
28
  options = rest
27
29
  }
30
+
28
31
  return await new Promise<string | Buffer>((resolve, reject) => {
29
32
  exec(command, options, (error, stdout, stderr) => {
30
33
  if (error) return reject(error)
34
+
31
35
  // if (stderr) console.warn(stderr)
32
36
  if (decode && stdout instanceof Buffer) return resolve(iconv.decode(stdout, decode.encoding, decode.options))
37
+
33
38
  resolve(stdout)
34
39
  })
35
40
  })
@@ -14,6 +14,7 @@ export type SaveFileOptions = {
14
14
  export async function saveFile({ input, output }: SaveFileOptions) {
15
15
  await new Promise<void>((resolve, reject) => {
16
16
  const writeAble = createWriteStream(output)
17
+
17
18
  Readable.fromWeb(input.stream() as any)
18
19
  .pipe(writeAble)
19
20
  .on("finish", resolve)
@@ -12,6 +12,5 @@ export async function saveResponse(response: Response, file: string) {
12
12
  Readable.fromWeb(response.body! as any)
13
13
  .pipe(writeable)
14
14
  .on("close", resolve)
15
- .on("error", reject),
16
- )
15
+ .on("error", reject))
17
16
  }
@@ -2,12 +2,12 @@ import {
2
2
  ChildProcess,
3
3
  ChildProcessByStdio,
4
4
  ChildProcessWithoutNullStreams,
5
+ spawn,
5
6
  SpawnOptions,
6
- SpawnOptionsWithStdioTuple,
7
7
  SpawnOptionsWithoutStdio,
8
+ SpawnOptionsWithStdioTuple,
8
9
  StdioNull,
9
10
  StdioPipe,
10
- spawn,
11
11
  } from "child_process"
12
12
  import { Readable, Writable } from "stream"
13
13
 
@@ -46,6 +46,7 @@ export function setDefaultOptions(options: Options | ((prev: Options) => Options
46
46
  defaultOptions = options(defaultOptions)
47
47
  return
48
48
  }
49
+
49
50
  defaultOptions = options
50
51
  return defaultOptions
51
52
  }
@@ -140,13 +141,17 @@ export function spawnAsync(command: string, args?: any, options?: any): Promise<
140
141
  const promise = new Promise<any>((resolve, reject) => {
141
142
  if (Array.isArray(args)) options = { ...defaultOptions, ...options }
142
143
  else args = { ...defaultOptions, ...args }
144
+
143
145
  child = spawn(command, args, options)
146
+
144
147
  child.on("exit", (code: number) => {
145
148
  if (code === 0) return resolve(child)
149
+
146
150
  if (Array.isArray(args)) {
147
151
  const args2 = args.map((item: string) => item.trim()).filter(Boolean)
148
152
  if (args2.length > 0) command = `${command} ${args2.join(" ")}`
149
153
  }
154
+
150
155
  reject(new Error(`spawn "${command}" failed with code ${code}`))
151
156
  return
152
157
  })
package/src/utils/zip.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { cpus } from "os"
2
+
2
3
  import which from "which"
3
4
 
4
5
  import { execAsync } from "./execAsync"