@clazic/kordoc 2.6.1 → 2.7.0

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.
@@ -7,7 +7,7 @@ import {
7
7
  precheckZipSize,
8
8
  sanitizeHref,
9
9
  toArrayBuffer
10
- } from "./chunk-4X5JCZFZ.js";
10
+ } from "./chunk-USE7IDLV.js";
11
11
  import {
12
12
  parsePageRange
13
13
  } from "./chunk-MOL7MDBG.js";
@@ -9842,6 +9842,7 @@ import { join as join2, delimiter } from "path";
9842
9842
  import { mkdir, access, symlink, rm } from "fs/promises";
9843
9843
  import { createWriteStream } from "fs";
9844
9844
  import { spawn } from "child_process";
9845
+ var installInFlight = null;
9845
9846
  var CACHE_DIR = join2(homedir(), ".cache", "kordoc", "libreoffice");
9846
9847
  var VERSION_FILE = join2(CACHE_DIR, "version");
9847
9848
  var PACKAGES = {
@@ -9862,13 +9863,11 @@ var PACKAGES = {
9862
9863
  }
9863
9864
  };
9864
9865
  async function findInPath() {
9865
- try {
9866
- const { runCommand } = await import("./utils-56QT5C33.js");
9867
- await runCommand("soffice", ["--version"]);
9868
- return "soffice";
9869
- } catch {
9870
- return null;
9871
- }
9866
+ return new Promise((resolve2) => {
9867
+ const child = spawn("soffice", ["--version"], { stdio: "ignore" });
9868
+ child.on("close", (code) => resolve2(code === 0 ? "soffice" : null));
9869
+ child.on("error", () => resolve2(null));
9870
+ });
9872
9871
  }
9873
9872
  async function findInCache() {
9874
9873
  const cachedBin = join2(CACHE_DIR, "bin", "soffice");
@@ -9879,6 +9878,38 @@ async function findInCache() {
9879
9878
  return null;
9880
9879
  }
9881
9880
  }
9881
+ async function findInDefaultPaths() {
9882
+ const platform = process.platform;
9883
+ const paths = [];
9884
+ if (platform === "darwin") {
9885
+ paths.push(
9886
+ "/Applications/LibreOffice.app/Contents/MacOS/soffice",
9887
+ "/opt/homebrew/bin/soffice",
9888
+ "/usr/local/bin/soffice"
9889
+ );
9890
+ } else if (platform === "linux") {
9891
+ paths.push(
9892
+ "/usr/bin/soffice",
9893
+ "/usr/lib/libreoffice/program/soffice"
9894
+ );
9895
+ } else if (platform === "win32") {
9896
+ const pf = process.env["ProgramFiles"] ?? "C:\\Program Files";
9897
+ const pf86 = process.env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)";
9898
+ paths.push(
9899
+ join2(pf, "LibreOffice", "program", "soffice.exe"),
9900
+ join2(pf86, "LibreOffice", "program", "soffice.exe")
9901
+ );
9902
+ }
9903
+ for (const p of paths) {
9904
+ try {
9905
+ await access(p);
9906
+ return p;
9907
+ } catch {
9908
+ continue;
9909
+ }
9910
+ }
9911
+ return null;
9912
+ }
9882
9913
  async function downloadWithProgress(url, dest, totalBytes, onProgress) {
9883
9914
  const response = await fetch(url);
9884
9915
  if (!response.body) throw new Error("\uB2E4\uC6B4\uB85C\uB4DC \uC2E4\uD328: response body \uC5C6\uC74C");
@@ -10006,6 +10037,11 @@ async function resolveSoffice(emitter, autoInstall = true) {
10006
10037
  emitter.validate("soffice_found", "\uCE90\uC2DC\uB41C LibreOffice \uBC1C\uACAC", { sofficePath: inCache });
10007
10038
  return inCache;
10008
10039
  }
10040
+ const inDefault = await findInDefaultPaths();
10041
+ if (inDefault) {
10042
+ emitter.validate("soffice_found", "\uAE30\uBCF8 \uACBD\uB85C\uC5D0\uC11C LibreOffice \uBC1C\uACAC", { sofficePath: inDefault });
10043
+ return inDefault;
10044
+ }
10009
10045
  if (!autoInstall) {
10010
10046
  emitter.error(
10011
10047
  "validate",
@@ -10015,23 +10051,31 @@ async function resolveSoffice(emitter, autoInstall = true) {
10015
10051
  );
10016
10052
  throw new ConvertError("SOFFICE_NOT_FOUND", "LibreOffice\uAC00 \uC124\uCE58\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4");
10017
10053
  }
10054
+ if (installInFlight) {
10055
+ return installInFlight;
10056
+ }
10018
10057
  emitter.install("install_start", "LibreOffice \uC790\uB3D9 \uC124\uCE58\uB97C \uC2DC\uC791\uD569\uB2C8\uB2E4...");
10019
- try {
10020
- const installed = await installLibreOffice((downloaded, total) => {
10021
- const percent = Math.round(downloaded / total * 100);
10022
- emitter.install("download_progress", `\uB2E4\uC6B4\uB85C\uB4DC \uC911... ${percent}%`, {
10023
- percent,
10024
- downloadedBytes: downloaded,
10025
- totalBytes: total
10058
+ installInFlight = (async () => {
10059
+ try {
10060
+ const installed = await installLibreOffice((downloaded, total) => {
10061
+ const percent = Math.round(downloaded / total * 100);
10062
+ emitter.install("download_progress", `\uB2E4\uC6B4\uB85C\uB4DC \uC911... ${percent}%`, {
10063
+ percent,
10064
+ downloadedBytes: downloaded,
10065
+ totalBytes: total
10066
+ });
10026
10067
  });
10027
- });
10028
- emitter.install("install_complete", "\uC124\uCE58 \uC644\uB8CC", { installedPath: installed });
10029
- return installed;
10030
- } catch (err) {
10031
- const errorMsg = err instanceof Error ? err.message : String(err);
10032
- emitter.install("install_failed", "\uC124\uCE58 \uC2E4\uD328", { error: errorMsg });
10033
- throw err;
10034
- }
10068
+ emitter.install("install_complete", "\uC124\uCE58 \uC644\uB8CC", { installedPath: installed });
10069
+ return installed;
10070
+ } catch (err) {
10071
+ const errorMsg = err instanceof Error ? err.message : String(err);
10072
+ emitter.install("install_failed", "\uC124\uCE58 \uC2E4\uD328", { error: errorMsg });
10073
+ throw err;
10074
+ } finally {
10075
+ installInFlight = null;
10076
+ }
10077
+ })();
10078
+ return installInFlight;
10035
10079
  }
10036
10080
 
10037
10081
  // src/convert/libreoffice.ts
@@ -10641,4 +10685,4 @@ export {
10641
10685
  cfb/cfb.js:
10642
10686
  (*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com *)
10643
10687
  */
10644
- //# sourceMappingURL=chunk-BZPZXI66.js.map
10688
+ //# sourceMappingURL=chunk-3FTA6V7S.js.map