vite-plugin-spire.officejs-test 1.0.3 → 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 +8 -8
- package/lib/utils/initserver.mjs +24 -23
- package/package.json +1 -1
package/lib/index.mjs
CHANGED
|
@@ -7,56 +7,56 @@ a(n(import.meta.url));
|
|
|
7
7
|
function v(s = {}) {
|
|
8
8
|
const i = [
|
|
9
9
|
{
|
|
10
|
-
package: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
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: "
|
|
59
|
+
package: "spire.officejs-fonts-test",
|
|
60
60
|
path: "/lib",
|
|
61
61
|
route: "/fontsweb",
|
|
62
62
|
name: "fontsweb",
|
package/lib/utils/initserver.mjs
CHANGED
|
@@ -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 = (
|
|
6
|
+
const A = (f, i, l, g) => {
|
|
7
7
|
var p;
|
|
8
8
|
let r;
|
|
9
|
-
r = P(async (
|
|
9
|
+
r = P(async (a, t) => {
|
|
10
10
|
var m;
|
|
11
|
-
const
|
|
12
|
-
let
|
|
13
|
-
if (
|
|
14
|
-
|
|
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
|
-
|
|
17
|
+
t.setHeader("Access-Control-Allow-Origin", "*");
|
|
18
18
|
try {
|
|
19
|
-
let
|
|
19
|
+
let e;
|
|
20
20
|
try {
|
|
21
|
-
const s = await import.meta.resolve(`${
|
|
22
|
-
|
|
21
|
+
const s = await import.meta.resolve(`${o.package}/package.json`);
|
|
22
|
+
e = x(s);
|
|
23
23
|
} catch {
|
|
24
|
-
|
|
24
|
+
e = y(process.cwd(), "node_modules", o.package);
|
|
25
25
|
}
|
|
26
|
-
|
|
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),
|
|
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
|
-
|
|
39
|
-
"Content-Type":
|
|
39
|
+
t.writeHead(200, {
|
|
40
|
+
"Content-Type": h && $[h] || "application/octet-stream",
|
|
40
41
|
"Content-Length": v.size
|
|
41
42
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
console.error(`Stream error for ${n}:`, s),
|
|
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 (
|
|
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
49
|
}
|
|
49
50
|
}), r.listen(l, () => {
|
|
50
|
-
console.log(`📦 [${
|
|
51
|
-
console.log(` - 映射 ${
|
|
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 =
|
|
54
|
+
}), (p = f.httpServer) == null || p.on("close", () => {
|
|
54
55
|
r == null || r.close();
|
|
55
56
|
});
|
|
56
57
|
};
|