@aippy/vite-plugins 0.2.0 → 0.2.1
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/dist/utils/index.js
CHANGED
|
@@ -1,40 +1,65 @@
|
|
|
1
|
-
import { existsSync as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
return e.match(/^https?:\/\//) || e.match(/^data:/) || e.match(/^blob:/) || e.startsWith("/") ? e : `/${e}`;
|
|
1
|
+
import { existsSync as h } from "fs";
|
|
2
|
+
import f from "path";
|
|
3
|
+
const u = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"], w = [".mp4", ".webm", ".mov", ".avi"], d = [".mp3", ".wav", ".ogg", ".m4a"];
|
|
4
|
+
function g(e) {
|
|
5
|
+
return e.match(/^https?:\/\//) || e.match(/^data:/) || e.match(/^blob:/) || e.startsWith("/") ? e : `/${e.replace(/^(\.\.\/)+/, "").replace(/^\.\//, "")}`;
|
|
6
6
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
7
|
+
function p(e) {
|
|
8
|
+
if (!e || e.length < 4 || e.includes("node_modules") || e.startsWith("./") && e.length < 10)
|
|
9
|
+
return !1;
|
|
10
|
+
let t;
|
|
11
|
+
if (e.match(/^https?:\/\//)) {
|
|
12
|
+
const n = e.split("/");
|
|
13
|
+
t = n[n.length - 1];
|
|
14
|
+
} else {
|
|
15
|
+
const n = e.split("/");
|
|
16
|
+
t = n[n.length - 1];
|
|
17
|
+
}
|
|
18
|
+
if (t = t.split("?")[0].split("#")[0], !t || t.startsWith("."))
|
|
19
|
+
return !1;
|
|
20
|
+
const r = t.split(".");
|
|
21
|
+
return !(r.length < 2 || r[0].length === 0 || r[r.length - 1].toLowerCase() === "json");
|
|
9
22
|
}
|
|
10
|
-
function
|
|
23
|
+
function A(e, t = /* @__PURE__ */ new Set()) {
|
|
11
24
|
let r = "ASSET";
|
|
12
|
-
|
|
25
|
+
u.some((s) => e.endsWith(s)) ? r = "IMAGE" : w.some((s) => e.endsWith(s)) ? r = "VIDEO" : d.some((s) => e.endsWith(s)) && (r = "AUDIO");
|
|
13
26
|
let o;
|
|
14
|
-
const
|
|
27
|
+
const n = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
15
28
|
do {
|
|
16
|
-
let
|
|
29
|
+
let s = "";
|
|
17
30
|
for (let c = 0; c < 4; c++)
|
|
18
|
-
|
|
19
|
-
o = `${r}_${
|
|
31
|
+
s += n[Math.floor(Math.random() * n.length)];
|
|
32
|
+
o = `${r}_${s}`;
|
|
20
33
|
} while (t.has(o));
|
|
21
34
|
return o;
|
|
22
35
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
36
|
+
function E(e) {
|
|
37
|
+
return e.replace(
|
|
38
|
+
/(["'])(?:(?=(\\?))\2.)*?\1|\/\*[\s\S]*?\*\/|\/\/.*/g,
|
|
39
|
+
(r) => r.startsWith('"') || r.startsWith("'") ? r : ""
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
function x(e) {
|
|
43
|
+
return e.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
44
|
+
}
|
|
45
|
+
function S(e, t, r = [".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".woff", ".woff2", ".ttf", ".eot"]) {
|
|
46
|
+
const o = /* @__PURE__ */ new Set();
|
|
47
|
+
let n = e;
|
|
48
|
+
t === "js" ? n = E(e) : t === "css" && (n = x(e));
|
|
49
|
+
const s = r.map((c) => c.replace(/^\./, "")).join("|");
|
|
25
50
|
if (t === "html")
|
|
26
51
|
[
|
|
27
52
|
// src/href attributes for img, script, link, video, audio tags
|
|
28
53
|
new RegExp(`(?:src|href)=["']([^"']*\\.(?:${s}))["']`, "g"),
|
|
29
54
|
// url() in CSS
|
|
30
55
|
new RegExp(`url\\(["']?([^"']*\\.(?:${s}))["']?\\)`, "g")
|
|
31
|
-
].forEach((
|
|
32
|
-
let
|
|
33
|
-
for (; (
|
|
34
|
-
|
|
35
|
-
}), (
|
|
36
|
-
const
|
|
37
|
-
|
|
56
|
+
].forEach((i) => {
|
|
57
|
+
let l;
|
|
58
|
+
for (; (l = i.exec(n)) !== null; )
|
|
59
|
+
l[1] && p(l[1]) && o.add(g(l[1]));
|
|
60
|
+
}), (n.match(/<script[^>]*>[\s\S]*?<\/script>/g) || []).forEach((i) => {
|
|
61
|
+
const l = i.replace(/<script[^>]*>/, "").replace(/<\/script>/, "");
|
|
62
|
+
S(l, "js", r).forEach((m) => o.add(m));
|
|
38
63
|
});
|
|
39
64
|
else if (t === "js")
|
|
40
65
|
[
|
|
@@ -54,26 +79,26 @@ function d(e, t, r = [".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".
|
|
|
54
79
|
new RegExp(`\\w+\\s*=\\s*["']([^"']*\\.(?:${s}))["']`, "g"),
|
|
55
80
|
// Resource paths in string literals (more precise matching)
|
|
56
81
|
new RegExp(`["']([^"']*\\.(?:${s}))["']`, "g")
|
|
57
|
-
].forEach((
|
|
58
|
-
let
|
|
59
|
-
for (; (
|
|
60
|
-
|
|
82
|
+
].forEach((a) => {
|
|
83
|
+
let i;
|
|
84
|
+
for (; (i = a.exec(n)) !== null; )
|
|
85
|
+
i[1] && p(i[1]) && o.add(g(i[1]));
|
|
61
86
|
});
|
|
62
87
|
else if (t === "css") {
|
|
63
|
-
const
|
|
64
|
-
let
|
|
65
|
-
for (; (
|
|
66
|
-
|
|
88
|
+
const c = new RegExp(`url\\(["']?([^"']*\\.(?:${s}))["']?\\)`, "g");
|
|
89
|
+
let a;
|
|
90
|
+
for (; (a = c.exec(n)) !== null; )
|
|
91
|
+
a[1] && p(a[1]) && o.add(g(a[1]));
|
|
67
92
|
}
|
|
68
93
|
return Array.from(o);
|
|
69
94
|
}
|
|
70
|
-
function
|
|
95
|
+
function I(e = process.cwd()) {
|
|
71
96
|
try {
|
|
72
97
|
let t = e, r = 0;
|
|
73
|
-
for (; t !==
|
|
74
|
-
if (
|
|
98
|
+
for (; t !== f.parse(t).root && r < 20; ) {
|
|
99
|
+
if (h(f.join(t, "package.json")))
|
|
75
100
|
return t;
|
|
76
|
-
t =
|
|
101
|
+
t = f.dirname(t), r++;
|
|
77
102
|
}
|
|
78
103
|
return process.cwd();
|
|
79
104
|
} catch (t) {
|
|
@@ -81,9 +106,9 @@ function S(e = process.cwd()) {
|
|
|
81
106
|
}
|
|
82
107
|
}
|
|
83
108
|
export {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
109
|
+
S as extractAssetsFromContent,
|
|
110
|
+
I as findProjectRoot,
|
|
111
|
+
A as generateConstantName,
|
|
112
|
+
p as isValidAsset,
|
|
113
|
+
g as processAssetURL
|
|
89
114
|
};
|