vite-plugin-spire.officejs-test 1.0.2 → 1.0.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.

Potentially problematic release.


This version of vite-plugin-spire.officejs-test might be problematic. Click here for more details.

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