soda-nodejs 0.8.2 → 0.8.4

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,20 +1,20 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
2
- import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
3
- import * as __WEBPACK_EXTERNAL_MODULE_tar__ from "tar";
1
+ import { existsSync, mkdirSync } from "fs";
2
+ import { basename, dirname, resolve } from "path";
3
+ import { create } from "tar";
4
4
  async function compress({ input, output }) {
5
- input = (0, __WEBPACK_EXTERNAL_MODULE_path__.resolve)(input);
6
- if (!(0, __WEBPACK_EXTERNAL_MODULE_fs__.existsSync)(input)) throw new Error("Source folder does not exist");
7
- const outputDir = (0, __WEBPACK_EXTERNAL_MODULE_path__.dirname)(output);
8
- if (!(0, __WEBPACK_EXTERNAL_MODULE_fs__.existsSync)(outputDir)) (0, __WEBPACK_EXTERNAL_MODULE_fs__.mkdirSync)(outputDir, {
5
+ input = resolve(input);
6
+ if (!existsSync(input)) throw new Error("Source folder does not exist");
7
+ const outputDir = dirname(output);
8
+ if (!existsSync(outputDir)) mkdirSync(outputDir, {
9
9
  recursive: true
10
10
  });
11
- await (0, __WEBPACK_EXTERNAL_MODULE_tar__.create)({
11
+ await create({
12
12
  gzip: true,
13
13
  file: output,
14
- cwd: (0, __WEBPACK_EXTERNAL_MODULE_path__.dirname)(input)
14
+ cwd: dirname(input)
15
15
  }, [
16
- (0, __WEBPACK_EXTERNAL_MODULE_path__.basename)(input)
16
+ basename(input)
17
17
  ]);
18
- return (0, __WEBPACK_EXTERNAL_MODULE_path__.resolve)(output);
18
+ return resolve(output);
19
19
  }
20
20
  export { compress };
@@ -43,10 +43,7 @@ async function copy({ input, output, mode }) {
43
43
  });
44
44
  const status = await (0, promises_namespaceObject.stat)(input);
45
45
  const { base } = (0, external_path_namespaceObject.parse)(input);
46
- if (status.isFile()) {
47
- await (0, promises_namespaceObject.copyFile)(input, (0, external_path_namespaceObject.join)(output, base), mode);
48
- return;
49
- }
46
+ if (status.isFile()) return void await (0, promises_namespaceObject.copyFile)(input, (0, external_path_namespaceObject.join)(output, base), mode);
50
47
  if (status.isDirectory()) {
51
48
  await (0, promises_namespaceObject.mkdir)((0, external_path_namespaceObject.join)(output, base), {
52
49
  recursive: true
@@ -1,6 +1,6 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
2
- import * as __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__ from "fs/promises";
3
- import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
1
+ import { existsSync } from "fs";
2
+ import { copyFile, mkdir, readdir, stat } from "fs/promises";
3
+ import { join, parse } from "path";
4
4
  async function copy({ input, output, mode }) {
5
5
  if (Array.isArray(input)) {
6
6
  for (const item of input)await copy({
@@ -10,25 +10,22 @@ async function copy({ input, output, mode }) {
10
10
  });
11
11
  return;
12
12
  }
13
- if (!(0, __WEBPACK_EXTERNAL_MODULE_fs__.existsSync)(output)) await (0, __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir)(output, {
13
+ if (!existsSync(output)) await mkdir(output, {
14
14
  recursive: true
15
15
  });
16
- const status = await (0, __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.stat)(input);
17
- const { base } = (0, __WEBPACK_EXTERNAL_MODULE_path__.parse)(input);
18
- if (status.isFile()) {
19
- await (0, __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.copyFile)(input, (0, __WEBPACK_EXTERNAL_MODULE_path__.join)(output, base), mode);
20
- return;
21
- }
16
+ const status = await stat(input);
17
+ const { base } = parse(input);
18
+ if (status.isFile()) return void await copyFile(input, join(output, base), mode);
22
19
  if (status.isDirectory()) {
23
- await (0, __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.mkdir)((0, __WEBPACK_EXTERNAL_MODULE_path__.join)(output, base), {
20
+ await mkdir(join(output, base), {
24
21
  recursive: true
25
22
  });
26
- const entries = await (0, __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__.readdir)(input, {
23
+ const entries = await readdir(input, {
27
24
  withFileTypes: true
28
25
  });
29
26
  for (const entry of entries)await copy({
30
- input: (0, __WEBPACK_EXTERNAL_MODULE_path__.join)(input, entry.name),
31
- output: (0, __WEBPACK_EXTERNAL_MODULE_path__.join)(output, base),
27
+ input: join(input, entry.name),
28
+ output: join(output, base),
32
29
  mode
33
30
  });
34
31
  }
@@ -39,7 +39,7 @@ const external_child_process_namespaceObject = require("child_process");
39
39
  const external_iconv_lite_namespaceObject = require("iconv-lite");
40
40
  var external_iconv_lite_default = /*#__PURE__*/ __webpack_require__.n(external_iconv_lite_namespaceObject);
41
41
  async function execAsync(command, options) {
42
- const decode = options?.decode;
42
+ const decode = null == options ? void 0 : options.decode;
43
43
  if ("object" == typeof options && null !== options && options.decode) {
44
44
  const { decode, ...rest } = options;
45
45
  options = rest;
@@ -1,15 +1,15 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
2
- import * as __WEBPACK_EXTERNAL_MODULE_iconv_lite_e3756a92__ from "iconv-lite";
1
+ import { exec } from "child_process";
2
+ import iconv_lite from "iconv-lite";
3
3
  async function execAsync(command, options) {
4
- const decode = options?.decode;
4
+ const decode = null == options ? void 0 : options.decode;
5
5
  if ("object" == typeof options && null !== options && options.decode) {
6
6
  const { decode, ...rest } = options;
7
7
  options = rest;
8
8
  }
9
9
  return await new Promise((resolve, reject)=>{
10
- (0, __WEBPACK_EXTERNAL_MODULE_child_process__.exec)(command, options, (error, stdout, stderr)=>{
10
+ exec(command, options, (error, stdout, stderr)=>{
11
11
  if (error) return reject(error);
12
- if (decode && stdout instanceof Buffer) return resolve(__WEBPACK_EXTERNAL_MODULE_iconv_lite_e3756a92__["default"].decode(stdout, decode.encoding, decode.options));
12
+ if (decode && stdout instanceof Buffer) return resolve(iconv_lite.decode(stdout, decode.encoding, decode.options));
13
13
  resolve(stdout);
14
14
  });
15
15
  });
@@ -1,9 +1,9 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
2
- import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
1
+ import { createWriteStream } from "fs";
2
+ import { Readable } from "stream";
3
3
  async function saveFile({ input, output }) {
4
4
  await new Promise((resolve, reject)=>{
5
- const writeAble = (0, __WEBPACK_EXTERNAL_MODULE_fs__.createWriteStream)(output);
6
- __WEBPACK_EXTERNAL_MODULE_stream__.Readable.fromWeb(input.stream()).pipe(writeAble).on("finish", resolve).on("error", reject);
5
+ const writeAble = createWriteStream(output);
6
+ Readable.fromWeb(input.stream()).pipe(writeAble).on("finish", resolve).on("error", reject);
7
7
  });
8
8
  }
9
9
  export { saveFile };
@@ -1,7 +1,7 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
2
- import * as __WEBPACK_EXTERNAL_MODULE_stream__ from "stream";
1
+ import { createWriteStream } from "fs";
2
+ import { Readable } from "stream";
3
3
  async function saveResponse(response, file) {
4
- const writeable = (0, __WEBPACK_EXTERNAL_MODULE_fs__.createWriteStream)(file);
5
- await new Promise((resolve, reject)=>__WEBPACK_EXTERNAL_MODULE_stream__.Readable.fromWeb(response.body).pipe(writeable).on("close", resolve).on("error", reject));
4
+ const writeable = createWriteStream(file);
5
+ await new Promise((resolve, reject)=>Readable.fromWeb(response.body).pipe(writeable).on("close", resolve).on("error", reject));
6
6
  }
7
7
  export { saveResponse };
@@ -25,8 +25,8 @@ var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
27
  getDefaultOptions: ()=>getDefaultOptions,
28
- spawnAsync: ()=>spawnAsync,
29
- setDefaultOptions: ()=>setDefaultOptions
28
+ setDefaultOptions: ()=>setDefaultOptions,
29
+ spawnAsync: ()=>spawnAsync
30
30
  });
31
31
  const external_child_process_namespaceObject = require("child_process");
32
32
  let defaultOptions = {};
@@ -1,4 +1,4 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
1
+ import { spawn } from "child_process";
2
2
  let defaultOptions = {};
3
3
  function getDefaultOptions() {
4
4
  return defaultOptions;
@@ -22,7 +22,7 @@ function spawnAsync(command, args, options) {
22
22
  ...defaultOptions,
23
23
  ...args
24
24
  };
25
- child = (0, __WEBPACK_EXTERNAL_MODULE_child_process__.spawn)(command, args, options);
25
+ child = spawn(command, args, options);
26
26
  child.on("exit", (code)=>{
27
27
  if (0 === code) return resolve(child);
28
28
  if (Array.isArray(args)) {
@@ -1,8 +1,8 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_which__ from "which";
2
- import * as __WEBPACK_EXTERNAL_MODULE__execAsync_js_bec93fa3__ from "./execAsync.js";
1
+ import which from "which";
2
+ import { execAsync } from "./execAsync.js";
3
3
  async function unzip({ input, output, cwd }) {
4
- await (0, __WEBPACK_EXTERNAL_MODULE_which__["default"])("7z");
5
- return await (0, __WEBPACK_EXTERNAL_MODULE__execAsync_js_bec93fa3__.execAsync)(`7z x ${input} -o${output}`, {
4
+ await which("7z");
5
+ return await execAsync(`7z x ${input} -o${output}`, {
6
6
  cwd
7
7
  });
8
8
  }
@@ -39,11 +39,14 @@ const external_os_namespaceObject = require("os");
39
39
  const external_which_namespaceObject = require("which");
40
40
  var external_which_default = /*#__PURE__*/ __webpack_require__.n(external_which_namespaceObject);
41
41
  const external_execAsync_cjs_namespaceObject = require("./execAsync.cjs");
42
- async function zip({ input, output, thread = "auto", level, password, cwd }) {
42
+ async function zip({ input, output, thread = "auto", level, password, cwd, filter }) {
43
43
  await external_which_default()("7z");
44
+ filter = Array.isArray(filter) ? filter : "string" == typeof filter ? [
45
+ filter
46
+ ] : [];
44
47
  input = Array.isArray(input) ? input.join(" ") : input;
45
48
  if ("max" === thread) thread = (0, external_os_namespaceObject.cpus)().length;
46
- return await (0, external_execAsync_cjs_namespaceObject.execAsync)(`7z a ${output} ${input} -mmt=${"auto" === thread ? "on" : thread}${"number" == typeof level ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`, {
49
+ return await (0, external_execAsync_cjs_namespaceObject.execAsync)(`7z a ${output} ${input} -mmt=${"auto" === thread ? "on" : thread}${"number" == typeof level ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}${filter.length > 0 ? ` ${filter.map((item)=>`-x!${item}`).join(" ")}` : ""}`, {
47
50
  cwd
48
51
  });
49
52
  }
@@ -23,6 +23,10 @@ export type ZipOptions = {
23
23
  * 压缩文件时的工作目录
24
24
  */
25
25
  cwd?: string;
26
+ /**
27
+ * 过滤
28
+ */
29
+ filter?: string | string[];
26
30
  };
27
31
  /**
28
32
  * 使用 7z 命令压缩文件
@@ -35,4 +39,4 @@ export type ZipOptions = {
35
39
  * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
36
40
  * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
37
41
  */
38
- export declare function zip({ input, output, thread, level, password, cwd }: ZipOptions): Promise<string>;
42
+ export declare function zip({ input, output, thread, level, password, cwd, filter }: ZipOptions): Promise<string>;
package/dist/utils/zip.js CHANGED
@@ -1,11 +1,14 @@
1
- import * as __WEBPACK_EXTERNAL_MODULE_os__ from "os";
2
- import * as __WEBPACK_EXTERNAL_MODULE_which__ from "which";
3
- import * as __WEBPACK_EXTERNAL_MODULE__execAsync_js_bec93fa3__ from "./execAsync.js";
4
- async function zip({ input, output, thread = "auto", level, password, cwd }) {
5
- await (0, __WEBPACK_EXTERNAL_MODULE_which__["default"])("7z");
1
+ import { cpus } from "os";
2
+ import which from "which";
3
+ import { execAsync } from "./execAsync.js";
4
+ async function zip({ input, output, thread = "auto", level, password, cwd, filter }) {
5
+ await which("7z");
6
+ filter = Array.isArray(filter) ? filter : "string" == typeof filter ? [
7
+ filter
8
+ ] : [];
6
9
  input = Array.isArray(input) ? input.join(" ") : input;
7
- if ("max" === thread) thread = (0, __WEBPACK_EXTERNAL_MODULE_os__.cpus)().length;
8
- return await (0, __WEBPACK_EXTERNAL_MODULE__execAsync_js_bec93fa3__.execAsync)(`7z a ${output} ${input} -mmt=${"auto" === thread ? "on" : thread}${"number" == typeof level ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`, {
10
+ if ("max" === thread) thread = cpus().length;
11
+ return await execAsync(`7z a ${output} ${input} -mmt=${"auto" === thread ? "on" : thread}${"number" == typeof level ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}${filter.length > 0 ? ` ${filter.map((item)=>`-x!${item}`).join(" ")}` : ""}`, {
9
12
  cwd
10
13
  });
11
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soda-nodejs",
3
- "version": "0.8.2",
3
+ "version": "0.8.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -40,15 +40,15 @@
40
40
  "which": "^5.0.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@types/node": "^22.16.3",
43
+ "@types/node": "^22.17.0",
44
44
  "@types/which": "^3.0.4",
45
- "typescript": "^5.8.3"
45
+ "typescript": "^5.9.2"
46
46
  },
47
47
  "peerDependencies": {},
48
48
  "scripts": {
49
49
  "dev": "rslib build --watch",
50
50
  "build": "rslib build",
51
- "prebuild": "tsx scripts/export.ts",
51
+ "prebuild": "bun scripts/export.ts",
52
52
  "lint": "prettier --write ."
53
53
  }
54
54
  }
@@ -1,5 +1,5 @@
1
- import { PathLike } from "fs"
2
-
3
- export function isPathLike(path: unknown): path is PathLike {
4
- return typeof path === "string" || path instanceof Buffer || path instanceof URL
5
- }
1
+ import { PathLike } from "fs"
2
+
3
+ export function isPathLike(path: unknown): path is PathLike {
4
+ return typeof path === "string" || path instanceof Buffer || path instanceof URL
5
+ }
package/src/utils/zip.ts CHANGED
@@ -1,52 +1,57 @@
1
- import { cpus } from "os"
2
- import which from "which"
3
-
4
- import { execAsync } from "./execAsync"
5
-
6
- export type ZipOptions = {
7
- /**
8
- * 要压缩的文件
9
- */
10
- input: string | string[]
11
- /**
12
- * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z
13
- */
14
- output: string
15
- /**
16
- * 线程数
17
- */
18
- thread?: number | "auto" | "max"
19
- /**
20
- * 压缩等级,0-9
21
- */
22
- level?: number
23
- /**
24
- * 是否加密
25
- */
26
- password?: string
27
- /**
28
- * 压缩文件时的工作目录
29
- */
30
- cwd?: string
31
- }
32
-
33
- /**
34
- * 使用 7z 命令压缩文件
35
- * - 如果没有安装 7z,请先安装 7z 后再执行
36
- * - 下载地址:https://www.7-zip.org/download.html
37
- * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
38
- * 1. 设置 → 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
39
- * 2. 在系统变量中找到并选中 Path,点击编辑
40
- * 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
41
- * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
42
- * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
43
- */
44
- export async function zip({ input, output, thread = "auto", level, password, cwd }: ZipOptions) {
45
- await which("7z")
46
- input = Array.isArray(input) ? input.join(" ") : input
47
- if (thread === "max") thread = cpus().length
48
- return await execAsync(
49
- `7z a ${output} ${input} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}`,
50
- { cwd },
51
- )
52
- }
1
+ import { cpus } from "os"
2
+ import which from "which"
3
+
4
+ import { execAsync } from "./execAsync"
5
+
6
+ export type ZipOptions = {
7
+ /**
8
+ * 要压缩的文件
9
+ */
10
+ input: string | string[]
11
+ /**
12
+ * 压缩到的目标位置,文件名的后缀就是压缩格式,例如:.zip、.7z
13
+ */
14
+ output: string
15
+ /**
16
+ * 线程数
17
+ */
18
+ thread?: number | "auto" | "max"
19
+ /**
20
+ * 压缩等级,0-9
21
+ */
22
+ level?: number
23
+ /**
24
+ * 是否加密
25
+ */
26
+ password?: string
27
+ /**
28
+ * 压缩文件时的工作目录
29
+ */
30
+ cwd?: string
31
+ /**
32
+ * 过滤
33
+ */
34
+ filter?: string | string[]
35
+ }
36
+
37
+ /**
38
+ * 使用 7z 命令压缩文件
39
+ * - 如果没有安装 7z,请先安装 7z 后再执行
40
+ * - 下载地址:https://www.7-zip.org/download.html
41
+ * - 如果已经安装,请按照以下步骤将 7z 添加到环境变量中
42
+ * 1. 设置 系统 → 右侧系统信息 → 高级系统设置 → 环境变量
43
+ * 2. 在系统变量中找到并选中 Path,点击编辑
44
+ * 3. 点击新建,输入 7z 的安装路径(默认是 C:\Program Files\7-Zip),点击确定
45
+ * 4. 重启终端,输入 7z,如果出现 7z 的版本信息,则安装成功
46
+ * 5. 如果没有出现版本信息,请重启电脑,或者检查 7z 的安装路径是否正确
47
+ */
48
+ export async function zip({ input, output, thread = "auto", level, password, cwd, filter }: ZipOptions) {
49
+ await which("7z")
50
+ filter = Array.isArray(filter) ? filter : typeof filter === "string" ? [filter] : []
51
+ input = Array.isArray(input) ? input.join(" ") : input
52
+ if (thread === "max") thread = cpus().length
53
+ return await execAsync(
54
+ `7z a ${output} ${input} -mmt=${thread === "auto" ? "on" : thread}${typeof level === "number" ? ` -mx=${level}` : ""}${password ? ` -p${password}` : ""}${filter.length > 0 ? ` ${filter.map(item => `-x!${item}`).join(" ")}` : ""}`,
55
+ { cwd },
56
+ )
57
+ }