vite-plugin-spire.officejs-test 1.0.10 → 1.0.11

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/lib/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { fileURLToPath as n } from "node:url";
1
+ import { fileURLToPath as t } from "node:url";
2
2
  import { dirname as a } from "node:path";
3
3
  import c from "path";
4
- import f from "./utils/initserver.mjs";
5
- import p from "./utils/bundle.mjs";
6
- a(n(import.meta.url));
7
- function v(s = {}) {
4
+ import n from "./utils/initserver.mjs";
5
+ import f from "./utils/bundle.mjs";
6
+ a(t(import.meta.url));
7
+ function v(p = {}) {
8
8
  const i = [
9
9
  {
10
10
  package: "spire.officejs-web-word",
@@ -62,7 +62,10 @@ function v(s = {}) {
62
62
  name: "fontsweb",
63
63
  build: "/fontsweb"
64
64
  }
65
- ], { port: t = 8e3, name: o = "vite-plugin-spire.officejs" } = s;
65
+ ], {
66
+ port: s = 7e3,
67
+ name: o = "vite-plugin-spire.officejs"
68
+ } = p;
66
69
  let r = "";
67
70
  return {
68
71
  name: o,
@@ -72,12 +75,12 @@ function v(s = {}) {
72
75
  // 开发环境
73
76
  // 创建一个子进程来提供officeJS的静态资源
74
77
  configureServer(e) {
75
- f(e, i, t, o);
78
+ n(e, i, s, o);
76
79
  },
77
80
  // 生产环境
78
81
  // 将officeJS的静态资源拷贝到输出目录中
79
- async writeBundle(e, l) {
80
- console.log("bundle", p), await p(e, r, i);
82
+ async writeBundle(e, m) {
83
+ await f(e, r, i);
81
84
  }
82
85
  };
83
86
  }
@@ -1,16 +1,16 @@
1
- import { createServer as P } from "node:http";
2
- import { fileURLToPath as S } from "node:url";
3
- import { dirname as j, resolve as x, join as y } from "node:path";
4
- import { access as k } from "node:fs/promises";
5
- import { statSync as T, createReadStream as C } from "node:fs";
1
+ import { createServer as j } from "node:http";
2
+ import { fileURLToPath as x } from "node:url";
3
+ import { dirname as y, resolve as P, join as k } from "node:path";
4
+ import { access as S } from "node:fs/promises";
5
+ import { statSync as C, createReadStream as H } from "node:fs";
6
6
  const A = (f, i, c, g) => {
7
7
  var p;
8
- let n;
9
- n = P(async (a, t) => {
10
- var h;
11
- const l = new URL(a.url, `http://${a.headers.host}`).pathname;
12
- let o = {};
13
- if (l.includes("Spire.Pdf.Base") ? o = i.find((e) => e.name == "pdf") : o = i.find((e) => l.startsWith(e.route)), !o) {
8
+ let r;
9
+ r = j(async (o, t) => {
10
+ var m;
11
+ const l = new URL(o.url, `http://${o.headers.host}`).pathname;
12
+ let a = {};
13
+ if (l.includes("Spire.Pdf.Base") ? a = i.find((e) => e.name == "pdf") : a = i.find((e) => l.startsWith(e.route)), !a) {
14
14
  t.writeHead(404, { "Content-Type": "text/plain" }), t.end("Resource not found");
15
15
  return;
16
16
  }
@@ -18,15 +18,15 @@ const A = (f, i, c, g) => {
18
18
  try {
19
19
  let e;
20
20
  try {
21
- const s = await import.meta.resolve(`${o.package}/package.json`);
22
- e = j(s);
21
+ const s = await import.meta.resolve(`${a.package}/package.json`);
22
+ e = y(s);
23
23
  } catch {
24
- e = x(process.cwd(), "node_modules", o.package);
24
+ e = P(process.cwd(), "node_modules", a.package);
25
25
  }
26
26
  e.startsWith("file://") || (e.startsWith("/") || e.match(/^[A-Za-z]:/)) && (e = "file://" + (e.startsWith("/") ? "" : "/") + e);
27
- const u = S(e), v = l.replace(o.route, "") || "/index.html", r = y(u, o.path, v);
28
- console.log("fullPath", r), await k(r);
29
- const w = T(r), d = (h = r.split(".").pop()) == null ? void 0 : h.toLowerCase(), $ = {
27
+ const u = x(e), w = l.replace(a.route, "") || "/index.html", n = k(u, a.path, w);
28
+ await S(n);
29
+ const v = C(n), h = (m = n.split(".").pop()) == null ? void 0 : m.toLowerCase(), $ = {
30
30
  html: "text/html",
31
31
  js: "application/javascript",
32
32
  css: "text/css",
@@ -37,22 +37,22 @@ const A = (f, i, c, g) => {
37
37
  wasm: "application/wasm"
38
38
  };
39
39
  t.writeHead(200, {
40
- "Content-Type": d && $[d] || "application/octet-stream",
41
- "Content-Length": w.size
40
+ "Content-Type": h && $[h] || "application/octet-stream",
41
+ "Content-Length": v.size
42
42
  });
43
- const m = C(r);
44
- m.pipe(t), m.on("error", (s) => {
45
- console.error(`Stream error for ${r}:`, s), t.writeHead(500), t.end("Internal server error");
43
+ const d = H(n);
44
+ d.pipe(t), d.on("error", (s) => {
45
+ console.error(`Stream error for ${n}:`, s), t.writeHead(500), t.end("Internal server error");
46
46
  });
47
47
  } catch (e) {
48
- e.code === "ENOENT" ? (t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`File not found: ${a.url}`)) : (console.error(`Error serving ${a.url}:`, e), t.writeHead(500), t.end("Internal server error"));
48
+ e.code === "ENOENT" ? (t.writeHead(404, { "Content-Type": "text/plain" }), t.end(`File not found: ${o.url}`)) : (console.error(`Error serving ${o.url}:`, e), t.writeHead(500), t.end("Internal server error"));
49
49
  }
50
- }), n.listen(c, () => {
51
- console.log(`📦 [${g}] The Spire.OfficeJS static resource service has been started.`), console.log(` - server address: http://localhost:${c}`), i.forEach((a) => {
52
- console.log(` - mapping ${a.package}${a.path} -> http://localhost:${c}${a.route}`);
50
+ }), r.listen(c, () => {
51
+ console.log(`📦 [${g}] spire.officejs静态资源服务已启动:`), console.log(` - 服务地址: http://localhost:${c}`), i.forEach((o) => {
52
+ console.log(` - 映射 ${o.package}${o.path} -> http://localhost:${c}${o.route}`);
53
53
  });
54
54
  }), (p = f.httpServer) == null || p.on("close", () => {
55
- n == null || n.close();
55
+ r == null || r.close();
56
56
  });
57
57
  };
58
58
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-spire.officejs-test",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "./lib/index.mjs",
6
6
  "files": [