@aippy/vite-plugins 0.2.5 → 0.2.6-dev.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.
Files changed (2) hide show
  1. package/dist/utils/index.js +46 -45
  2. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
- import { existsSync as g } from "fs";
1
+ import { existsSync as m } from "fs";
2
2
  import f from "path";
3
- const u = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"], d = [".mp4", ".webm", ".mov", ".avi"], w = [".mp3", ".wav", ".ogg", ".m4a"];
4
- function m(t) {
3
+ const g = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".webp"], d = [".mp4", ".webm", ".mov", ".avi"], w = [".mp3", ".wav", ".ogg", ".m4a"];
4
+ function p(t) {
5
5
  return t = t.trim(), t.match(/^https?:\/\//) || t.match(/^data:/) || t.match(/^blob:/), t;
6
6
  }
7
7
  function h(t) {
@@ -9,29 +9,30 @@ function h(t) {
9
9
  return !1;
10
10
  let e;
11
11
  if (t.match(/^https?:\/\//)) {
12
- const r = t.split("/");
13
- e = r[r.length - 1];
12
+ const c = t.split("?")[0].split("#")[0].split("/");
13
+ e = c[c.length - 1];
14
14
  } else {
15
- const r = t.split("/");
16
- e = r[r.length - 1];
15
+ const n = t.split("/");
16
+ e = n[n.length - 1], e = e.split("?")[0].split("#")[0];
17
17
  }
18
- if (e = e.split("?")[0].split("#")[0], !e || e.startsWith("."))
18
+ if (!e || e.startsWith("."))
19
19
  return !1;
20
20
  const s = e.split(".");
21
21
  return !(s.length < 2 || s[0].length === 0 || s[s.length - 1].toLowerCase() === "json");
22
22
  }
23
- function C(t, e = /* @__PURE__ */ new Set()) {
23
+ function I(t, e = /* @__PURE__ */ new Set()) {
24
24
  let s = "ASSET";
25
- u.some((n) => t.endsWith(n)) ? s = "IMAGE" : d.some((n) => t.endsWith(n)) ? s = "VIDEO" : w.some((n) => t.endsWith(n)) && (s = "AUDIO");
26
- let o;
27
- const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
25
+ const i = t.split("?")[0].split("#")[0];
26
+ g.some((r) => i.endsWith(r)) ? s = "IMAGE" : d.some((r) => i.endsWith(r)) ? s = "VIDEO" : w.some((r) => i.endsWith(r)) && (s = "AUDIO");
27
+ let n;
28
+ const c = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
28
29
  do {
29
- let n = "";
30
- for (let i = 0; i < 4; i++)
31
- n += r[Math.floor(Math.random() * r.length)];
32
- o = `${s}_${n}`;
33
- } while (e.has(o));
34
- return o;
30
+ let r = "";
31
+ for (let o = 0; o < 4; o++)
32
+ r += c[Math.floor(Math.random() * c.length)];
33
+ n = `${s}_${r}`;
34
+ } while (e.has(n));
35
+ return n;
35
36
  }
36
37
  function E(t) {
37
38
  return t.replace(
@@ -43,42 +44,42 @@ function S(t) {
43
44
  return t.replace(/\/\*[\s\S]*?\*\//g, "");
44
45
  }
45
46
  function j(t, e, s = [".js", ".css", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".woff", ".woff2", ".ttf", ".eot"]) {
46
- const o = /* @__PURE__ */ new Set();
47
- let r = t;
48
- e === "js" ? r = E(t) : e === "css" && (r = S(t));
49
- const n = s.map((i) => i.replace(/^\./, "")).join("|");
47
+ const i = /* @__PURE__ */ new Set();
48
+ let n = t;
49
+ e === "js" ? n = E(t) : e === "css" && (n = S(t));
50
+ const c = s.map((r) => r.replace(/^\./, "")).join("|");
50
51
  if (e === "html")
51
52
  [
52
53
  // src/href attributes for img, script, link, video, audio tags
53
- new RegExp(`(?:src|href)=["']([^"']*\\.(?:${n}))["']`, "g"),
54
+ new RegExp(`(?:src|href)=["']([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']`, "g"),
54
55
  // url() in CSS
55
- new RegExp(`url\\(["']?([^"']*\\.(?:${n}))["']?\\)`, "g")
56
- ].forEach((l) => {
57
- let a;
58
- for (; (a = l.exec(r)) !== null; )
59
- a[1] && h(a[1]) && o.add(m(a[1]));
60
- }), (r.match(/<script[^>]*>[\s\S]*?<\/script>/g) || []).forEach((l) => {
61
- const a = l.replace(/<script[^>]*>/, "").replace(/<\/script>/, "");
62
- j(a, "js", s).forEach((p) => o.add(p));
56
+ new RegExp(`url\\(["']?([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']?\\)`, "g")
57
+ ].forEach((a) => {
58
+ let l;
59
+ for (; (l = a.exec(n)) !== null; )
60
+ l[1] && h(l[1]) && i.add(p(l[1]));
61
+ }), (n.match(/<script[^>]*>[\s\S]*?<\/script>/g) || []).forEach((a) => {
62
+ const l = a.replace(/<script[^>]*>/, "").replace(/<\/script>/, "");
63
+ j(l, "js", s).forEach((u) => i.add(u));
63
64
  });
64
65
  else if (e === "js") {
65
- const i = new RegExp(`["']([^"']*\\.(?:${n}))["']`, "g");
66
- let c;
67
- for (; (c = i.exec(r)) !== null; )
68
- c[1] && h(c[1]) && o.add(m(c[1]));
66
+ const r = new RegExp(`["']([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']`, "g");
67
+ let o;
68
+ for (; (o = r.exec(n)) !== null; )
69
+ o[1] && h(o[1]) && i.add(p(o[1]));
69
70
  } else if (e === "css") {
70
- const i = new RegExp(`url\\(["']?([^"']*\\.(?:${n}))["']?\\)`, "g");
71
- let c;
72
- for (; (c = i.exec(r)) !== null; )
73
- c[1] && h(c[1]) && o.add(m(c[1]));
71
+ const r = new RegExp(`url\\(["']?([^"']*\\.(?:${c})(?:[?#][^"']*)?)["']?\\)`, "g");
72
+ let o;
73
+ for (; (o = r.exec(n)) !== null; )
74
+ o[1] && h(o[1]) && i.add(p(o[1]));
74
75
  }
75
- return Array.from(o);
76
+ return Array.from(i);
76
77
  }
77
- function N(t = process.cwd()) {
78
+ function C(t = process.cwd()) {
78
79
  try {
79
80
  let e = t, s = 0;
80
81
  for (; e !== f.parse(e).root && s < 20; ) {
81
- if (g(f.join(e, "package.json")))
82
+ if (m(f.join(e, "package.json")))
82
83
  return e;
83
84
  e = f.dirname(e), s++;
84
85
  }
@@ -89,8 +90,8 @@ function N(t = process.cwd()) {
89
90
  }
90
91
  export {
91
92
  j as extractAssetsFromContent,
92
- N as findProjectRoot,
93
- C as generateConstantName,
93
+ C as findProjectRoot,
94
+ I as generateConstantName,
94
95
  h as isValidAsset,
95
- m as processAssetURL
96
+ p as processAssetURL
96
97
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/vite-plugins",
3
- "version": "0.2.5",
3
+ "version": "0.2.6-dev.0",
4
4
  "description": "Vite plugins for Aippy projects - Asset management and component tagging",
5
5
  "private": false,
6
6
  "type": "module",