@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.
- package/dist/aippy-preload/index.js +92 -66
- package/dist/asset-constants/index.js +2 -0
- package/package.json +12 -2
|
@@ -1,114 +1,140 @@
|
|
|
1
|
-
import { promises as
|
|
1
|
+
import { promises as c } from "fs";
|
|
2
2
|
import u from "path";
|
|
3
|
-
import { extractAssetsFromContent as
|
|
3
|
+
import { extractAssetsFromContent as a } from "../utils/index.js";
|
|
4
4
|
import { g as l } from "../file-scanner-DHkDSQm8.js";
|
|
5
|
-
async function
|
|
6
|
-
const
|
|
7
|
-
for (const
|
|
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
|
|
10
|
-
|
|
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
|
|
14
|
+
return s;
|
|
15
15
|
}
|
|
16
|
-
async function g(
|
|
17
|
-
const n = [],
|
|
18
|
-
for (const
|
|
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
|
|
21
|
-
n.push(...
|
|
22
|
-
} catch (
|
|
23
|
-
console.warn(`⚠️ Failed to read JS file: ${
|
|
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
|
|
28
|
-
const n = [],
|
|
29
|
-
for (const
|
|
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
|
|
32
|
-
n.push(...
|
|
33
|
-
} catch (
|
|
34
|
-
console.warn(`⚠️ Failed to read CSS file: ${
|
|
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
|
|
39
|
-
const n = [],
|
|
40
|
-
for (const
|
|
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
|
|
43
|
-
n.push(...
|
|
44
|
-
} catch (
|
|
45
|
-
console.warn(`⚠️ Failed to read JSON file: ${
|
|
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
|
|
49
|
+
async function w(t, s, n) {
|
|
50
50
|
console.log("🔍 Scanning source files for static assets...");
|
|
51
|
-
const
|
|
51
|
+
const e = [];
|
|
52
52
|
if (n) {
|
|
53
53
|
console.log("🔍 Deep scanning source file contents...");
|
|
54
|
-
const [
|
|
55
|
-
|
|
56
|
-
g(
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
60
|
+
e.push(...o, ...r, ...i, ...d);
|
|
61
61
|
}
|
|
62
|
-
return [...new Set(
|
|
62
|
+
return [...new Set(e)];
|
|
63
63
|
}
|
|
64
|
-
const f = "<head>",
|
|
65
|
-
function
|
|
66
|
-
return
|
|
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(
|
|
70
|
-
const n =
|
|
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
|
|
74
|
-
return
|
|
75
|
-
` +
|
|
76
|
-
` +
|
|
73
|
+
const e = n + j;
|
|
74
|
+
return t.slice(0, e) + `
|
|
75
|
+
` + s + `
|
|
76
|
+
` + t.slice(e);
|
|
77
77
|
}
|
|
78
|
-
function A(
|
|
79
|
-
|
|
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("
|
|
84
|
+
console.log(`📋 ${s === 1 ? "Asset" : "Assets"} found:`), t.forEach((n) => console.log(` - ${n}`));
|
|
84
85
|
}
|
|
85
|
-
function
|
|
86
|
-
console.log(`✅ Injected ${
|
|
86
|
+
function E(t) {
|
|
87
|
+
console.log(`✅ Injected ${t} preload meta ${t === 1 ? "tag" : "tags"} into index.html`);
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
...
|
|
115
|
+
...t
|
|
95
116
|
};
|
|
96
117
|
return {
|
|
97
118
|
name: "vite-plugin-aippy-preload",
|
|
98
119
|
apply: "build",
|
|
99
|
-
|
|
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
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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.
|
|
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
|
}
|