@aippy/vite-plugins 0.2.2 → 0.2.5-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.
@@ -1,114 +1,140 @@
1
- import { promises as i } from "fs";
1
+ import { promises as c } from "fs";
2
2
  import u from "path";
3
- import { extractAssetsFromContent as r } from "../utils/index.js";
3
+ import { extractAssetsFromContent as a } from "../utils/index.js";
4
4
  import { g as l } from "../file-scanner-DHkDSQm8.js";
5
- async function d(s) {
6
- const t = [], n = [u.join(process.cwd(), "index.html")];
7
- for (const c of n)
5
+ async function p(t) {
6
+ const s = [], n = [u.join(process.cwd(), "index.html")];
7
+ for (const e of n)
8
8
  try {
9
- const e = await i.readFile(c, "utf-8"), o = r(e, "html", s);
10
- t.push(...o);
9
+ const o = await c.readFile(e, "utf-8"), r = a(o, "html", t);
10
+ s.push(...r);
11
11
  } catch {
12
12
  console.warn("⚠️ No index.html found in project root");
13
13
  }
14
- return t;
14
+ return s;
15
15
  }
16
- async function g(s, t) {
17
- const n = [], c = await l(s, [".ts", ".tsx", ".js", ".jsx"]);
18
- for (const e of c)
16
+ async function g(t, s) {
17
+ const n = [], e = await l(t, [".ts", ".tsx", ".js", ".jsx"]);
18
+ for (const o of e)
19
19
  try {
20
- const o = await i.readFile(e, "utf-8"), a = r(o, "js", t);
21
- n.push(...a);
22
- } catch (o) {
23
- console.warn(`⚠️ Failed to read JS file: ${e}`, o);
20
+ const r = await c.readFile(o, "utf-8"), i = a(r, "js", s);
21
+ n.push(...i);
22
+ } catch (r) {
23
+ console.warn(`⚠️ Failed to read JS file: ${o}`, r);
24
24
  }
25
25
  return n;
26
26
  }
27
- async function h(s, t) {
28
- const n = [], c = await l(s, [".css", ".scss", ".sass", ".less"]);
29
- for (const e of c)
27
+ async function m(t, s) {
28
+ const n = [], e = await l(t, [".css", ".scss", ".sass", ".less"]);
29
+ for (const o of e)
30
30
  try {
31
- const o = await i.readFile(e, "utf-8"), a = r(o, "css", t);
32
- n.push(...a);
33
- } catch (o) {
34
- console.warn(`⚠️ Failed to read CSS file: ${e}`, o);
31
+ const r = await c.readFile(o, "utf-8"), i = a(r, "css", s);
32
+ n.push(...i);
33
+ } catch (r) {
34
+ console.warn(`⚠️ Failed to read CSS file: ${o}`, r);
35
35
  }
36
36
  return n;
37
37
  }
38
- async function m(s, t) {
39
- const n = [], c = await l(s, [".json"]);
40
- for (const e of c)
38
+ async function h(t, s) {
39
+ const n = [], e = await l(t, [".json"]);
40
+ for (const o of e)
41
41
  try {
42
- const o = await i.readFile(e, "utf-8"), a = r(o, "js", t);
43
- n.push(...a);
44
- } catch (o) {
45
- console.warn(`⚠️ Failed to read JSON file: ${e}`, o);
42
+ const r = await c.readFile(o, "utf-8"), i = a(r, "js", s);
43
+ n.push(...i);
44
+ } catch (r) {
45
+ console.warn(`⚠️ Failed to read JSON file: ${o}`, r);
46
46
  }
47
47
  return n;
48
48
  }
49
- async function j(s, t, n) {
49
+ async function w(t, s, n) {
50
50
  console.log("🔍 Scanning source files for static assets...");
51
- const c = [];
51
+ const e = [];
52
52
  if (n) {
53
53
  console.log("🔍 Deep scanning source file contents...");
54
- const [e, o, a, p] = await Promise.all([
55
- d(t),
56
- g(s, t),
57
- h(s, t),
58
- m(s, t)
54
+ const [o, r, i, d] = await Promise.all([
55
+ p(s),
56
+ g(t, s),
57
+ m(t, s),
58
+ h(t, s)
59
59
  ]);
60
- c.push(...e, ...o, ...a, ...p);
60
+ e.push(...o, ...r, ...i, ...d);
61
61
  }
62
- return [...new Set(c)];
62
+ return [...new Set(e)];
63
63
  }
64
- const f = "<head>", F = f.length;
65
- function w(s) {
66
- return s.map((t) => ` <meta content="${t}" name="aippy:preload">`).join(`
64
+ const f = "<head>", j = f.length;
65
+ function F(t) {
66
+ return t.map((s) => ` <meta content="${s}" name="aippy:preload">`).join(`
67
67
  `);
68
68
  }
69
- function y(s, t) {
70
- const n = s.indexOf(f);
69
+ function y(t, s) {
70
+ const n = t.indexOf(f);
71
71
  if (n === -1)
72
72
  throw new Error("Could not find <head> tag in HTML");
73
- const c = n + F;
74
- return s.slice(0, c) + `
75
- ` + t + `
76
- ` + s.slice(c);
73
+ const e = n + j;
74
+ return t.slice(0, e) + `
75
+ ` + s + `
76
+ ` + t.slice(e);
77
77
  }
78
- function A(s) {
79
- if (console.log(`📁 Found ${s.length} static assets in source files`), s.length === 0) {
78
+ function A(t) {
79
+ const s = t.length;
80
+ if (console.log(`📁 Found ${s} static ${s === 1 ? "asset" : "assets"} in source files`), s === 0) {
80
81
  console.log("⚠️ No static assets found in source files.");
81
82
  return;
82
83
  }
83
- console.log("📋 Assets found:"), s.forEach((t) => console.log(` - ${t}`));
84
+ console.log(`📋 ${s === 1 ? "Asset" : "Assets"} found:`), t.forEach((n) => console.log(` - ${n}`));
84
85
  }
85
- function x(s) {
86
- console.log(`✅ Injected ${s} preload meta tags into index.html`);
86
+ function E(t) {
87
+ console.log(`✅ Injected ${t} preload meta ${t === 1 ? "tag" : "tags"} into index.html`);
87
88
  }
88
- function C(s = {}) {
89
- const t = {
89
+ const $ = 3, S = 1e3;
90
+ function x(t) {
91
+ return new Promise((s) => setTimeout(s, t));
92
+ }
93
+ async function T(t, s = $, n = S) {
94
+ for (let e = 1; e <= s; e++)
95
+ try {
96
+ return await c.readFile(t, "utf-8");
97
+ } catch (o) {
98
+ if (o.code === "ENOENT") {
99
+ if (e < s) {
100
+ console.log(`⏳ index.html not found, waiting ${n}ms before retry (attempt ${e}/${s})...`), await x(n);
101
+ continue;
102
+ }
103
+ return console.log(`⚠️ index.html not found after ${s} attempts, skipping preload injection.`), null;
104
+ } else
105
+ return console.error("❌ Error reading index.html:", o), null;
106
+ }
107
+ return null;
108
+ }
109
+ function P(t = {}) {
110
+ const s = {
90
111
  extensions: [".png", ".jpg", ".jpeg", ".gif", ".svg", ".mp4", ".mp3", ".wav", ".ogg", ".webm"],
91
112
  srcDir: "src",
92
113
  outDir: "dist",
93
114
  deepScan: !0,
94
- ...s
115
+ ...t
95
116
  };
96
117
  return {
97
118
  name: "vite-plugin-aippy-preload",
98
119
  apply: "build",
99
- async closeBundle() {
120
+ // Ensure this plugin runs after other plugins (like viteSingleFile)
121
+ enforce: "post",
122
+ // Use writeBundle instead of closeBundle for more reliable execution order
123
+ // writeBundle is called sequentially after files are written, respecting plugin order
124
+ async writeBundle() {
100
125
  try {
101
- const n = await j(
102
- t.srcDir,
103
- t.extensions,
104
- t.deepScan
126
+ const n = await w(
127
+ s.srcDir,
128
+ s.extensions,
129
+ s.deepScan
105
130
  );
106
131
  if (A(n), n.length === 0)
107
132
  return;
108
- const c = u.join(t.outDir, "index.html");
109
- let e = await i.readFile(c, "utf-8");
110
- const o = w(n);
111
- e = y(e, o), await i.writeFile(c, e, "utf-8"), x(n.length);
133
+ const e = u.join(s.outDir, "index.html"), o = await T(e);
134
+ if (o === null)
135
+ return;
136
+ const r = F(n), i = y(o, r);
137
+ await c.writeFile(e, i, "utf-8"), E(n.length);
112
138
  } catch (n) {
113
139
  console.error("❌ Error in aippy preload plugin:", n);
114
140
  }
@@ -116,6 +142,6 @@ function C(s = {}) {
116
142
  };
117
143
  }
118
144
  export {
119
- C as aippyPreloadPlugin,
120
- C as default
145
+ P as aippyPreloadPlugin,
146
+ P as default
121
147
  };
@@ -220,6 +220,8 @@ function q(a = {}) {
220
220
  return {
221
221
  name: "vite-plugin-asset-constants",
222
222
  apply: "build",
223
+ // Ensure this plugin runs before other plugins to modify source files before build
224
+ enforce: "pre",
223
225
  async buildStart() {
224
226
  if (a.devMode)
225
227
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/vite-plugins",
3
- "version": "0.2.2",
3
+ "version": "0.2.5-dev.0",
4
4
  "description": "Vite plugins for Aippy projects - Asset management and component tagging",
5
5
  "private": false,
6
6
  "type": "module",
@@ -92,6 +92,16 @@
92
92
  "clean": "rm -rf dist",
93
93
  "publish:patch": "pnpm version patch && pnpm publish --no-git-checks",
94
94
  "publish:minor": "pnpm version minor && pnpm publish --no-git-checks",
95
- "publish:major": "pnpm version major && pnpm publish --no-git-checks"
95
+ "publish:major": "pnpm version major && pnpm publish --no-git-checks",
96
+ "publish:alpha": "pnpm prepublishOnly && pnpm version prerelease --preid=alpha && pnpm publish --tag alpha --no-git-checks",
97
+ "publish:beta": "pnpm prepublishOnly && pnpm version prerelease --preid=beta && pnpm publish --tag beta --no-git-checks",
98
+ "publish:rc": "pnpm prepublishOnly && pnpm version prerelease --preid=rc && pnpm publish --tag rc --no-git-checks",
99
+ "publish:dev": "pnpm prepublishOnly && pnpm version prerelease --preid=dev && pnpm publish --tag dev --no-git-checks",
100
+ "audit": "pnpm audit --audit-level moderate",
101
+ "audit:fix": "pnpm audit --fix",
102
+ "security:check": "pnpm audit && pnpm outdated",
103
+ "prerelease": "pnpm run audit && pnpm run type-check && pnpm run lint && pnpm run build",
104
+ "release:dry": "npm publish --dry-run",
105
+ "test:build": "node -e \"require('./dist/index.js')\""
96
106
  }
97
107
  }