@aippy/vite-plugins 0.4.0-dev.3 → 0.4.0-dev.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.
@@ -1,18 +1,15 @@
1
1
  import { extractAssetsFromContent as e, generateConstantName as t, processAssetURL as n } from "../utils/index.js";
2
- import { c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as g, u as _ } from "../generator-utils-CFYv7n_h.js";
3
- import { promises as v } from "fs";
4
- import y from "path";
5
- import { parse as b } from "@babel/parser";
6
- import x from "@babel/traverse";
7
- import * as S from "@babel/types";
8
- import C from "@babel/generator";
2
+ import { a as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as d, n as f, o as p, p as m, r as h, s as g, t as _, u as v } from "../generator-utils-VznlFF00.js";
3
+ import { promises as y } from "fs";
4
+ import b from "path";
5
+ import { parse as x } from "@babel/parser";
6
+ import S from "@babel/traverse";
7
+ import * as C from "@babel/types";
8
+ import w from "@babel/generator";
9
9
  //#region src/asset-constants/index.ts
10
- var w = typeof x == "function" ? x : x.default, T = typeof C == "function" ? C : C.default, E = class extends Error {}, D = class {
11
- isStructuredInventory() {
12
- return this.document !== void 0 && f(this.document);
13
- }
10
+ var T = typeof S == "function" ? S : S.default, E = typeof w == "function" ? w : w.default, D = class extends Error {}, O = class {
14
11
  constructor(e = {}) {
15
- o(this, "options", void 0), o(this, "assets", /* @__PURE__ */ new Map()), o(this, "existingAssets", /* @__PURE__ */ new Map()), o(this, "flat", {}), o(this, "fileCache", new a()), o(this, "document", void 0), o(this, "implementationPaths", /* @__PURE__ */ new Set()), this.options = {
12
+ s(this, "options", void 0), s(this, "assets", /* @__PURE__ */ new Map()), s(this, "existingAssets", /* @__PURE__ */ new Map()), s(this, "flat", {}), s(this, "fileCache", new o()), s(this, "planKeys", void 0), s(this, "implementationPaths", /* @__PURE__ */ new Set()), s(this, "keyRefFiles", /* @__PURE__ */ new Set()), this.options = {
16
13
  extensions: [
17
14
  ".png",
18
15
  ".jpg",
@@ -38,19 +35,23 @@ var w = typeof x == "function" ? x : x.default, T = typeof C == "function" ? C :
38
35
  let n = /* @__PURE__ */ new Set([
39
36
  ...Array.from(this.assets.values()).map((e) => e.constantName),
40
37
  ...Array.from(this.existingAssets.values()),
41
- ...this.document && f(this.document) ? Object.keys(this.document.assets) : []
38
+ ...this.planKeys ?? []
42
39
  ]);
43
40
  return t(e, n);
44
41
  }
45
42
  async scanTsFile(t) {
46
43
  try {
47
- let n = await this.fileCache.read(t), r = [], i = e(n, "js", this.options.extensions), a = /* @__PURE__ */ new Set([...Object.keys(this.flat), ...this.document && f(this.document) ? Object.keys(this.document.assets) : []]);
44
+ let n = await this.fileCache.read(t), r = [], i = e(n, "js", this.options.extensions), a = /* @__PURE__ */ new Set([...Object.keys(this.flat), ...this.planKeys ?? []]);
48
45
  if (i.some((e) => a.has(e))) {
49
- let r = l(n, t, this.options.srcDir, this.options.outputFile);
46
+ let r = u(n, t, this.options.srcDir, this.options.outputFile);
50
47
  i = e(r, "js", this.options.extensions);
51
48
  }
52
- let o = n.split("\n");
53
- return i.forEach((e) => {
49
+ let o = n.split("\n"), s = _(this.flat);
50
+ i = i.filter((e) => {
51
+ if (e.startsWith("aippy-asset:") || !n.includes(`"${e}"`) && !n.includes(`'${e}'`)) return !1;
52
+ let t = s.get(e);
53
+ return !t || t.length === 1;
54
+ }), i.forEach((e) => {
54
55
  if (this.isImplementationReference(t, e)) return;
55
56
  let n = this.generateConstantName(e), i = o.findIndex((t) => t.includes(e)) + 1;
56
57
  r.push({
@@ -60,7 +61,16 @@ var w = typeof x == "function" ? x : x.default, T = typeof C == "function" ? C :
60
61
  line: i,
61
62
  column: 1
62
63
  });
63
- }), r;
64
+ }), n.includes("aippy-asset:") && this.keyRefFiles.add(t);
65
+ let c = new Set(r.map((e) => e.originalUri));
66
+ for (let [e, i] of s) i.length !== 1 || c.has(e) || !n.includes(`"${e}"`) && !n.includes(`'${e}'`) || r.push({
67
+ originalUri: e,
68
+ constantName: i[0],
69
+ filePath: t,
70
+ line: 1,
71
+ column: 1
72
+ });
73
+ return r;
64
74
  } catch (e) {
65
75
  return console.warn(`Warning: Failed to scan ${t}:`, e), [];
66
76
  }
@@ -68,26 +78,32 @@ var w = typeof x == "function" ? x : x.default, T = typeof C == "function" ? C :
68
78
  async scanAllTsFiles() {
69
79
  let e = this.options.srcDir;
70
80
  try {
71
- let t = await u(e, [".ts", ".tsx"]);
72
- for (let e of t) e.endsWith("assets.json") || e.endsWith("assets.ts") || (await this.scanTsFile(e)).forEach((e) => {
73
- this.existingAssets.has(e.originalUri) && (e.constantName = this.existingAssets.get(e.originalUri));
74
- let t = e.originalUri;
75
- this.assets.has(t) || this.assets.set(t, e);
76
- });
81
+ let t = await d(e, [".ts", ".tsx"]);
82
+ for (let e of t) {
83
+ if (e.endsWith("assets.json") || e.endsWith("assets.ts")) continue;
84
+ let t = await this.scanTsFile(e), n = _(this.flat);
85
+ t.forEach((e) => {
86
+ let t = n.get(e.originalUri);
87
+ if (t && t.length > 1) return;
88
+ t && t.length === 1 ? e.constantName = t[0] : this.existingAssets.has(e.originalUri) && (e.constantName = this.existingAssets.get(e.originalUri));
89
+ let r = e.originalUri;
90
+ this.assets.has(r) || this.assets.set(r, e);
91
+ });
92
+ }
77
93
  } catch (e) {
78
94
  console.error("Error scanning TypeScript files:", e);
79
95
  }
80
96
  }
81
97
  async readExistingAssetsFile() {
82
98
  try {
83
- return await v.readFile(this.options.outputFile, "utf-8");
99
+ return await y.readFile(this.options.outputFile, "utf-8");
84
100
  } catch (e) {
85
101
  if (e.code === "ENOENT") return "";
86
- throw new E("Unable to read assets.json: " + String(e));
102
+ throw new D("Unable to read assets.json: " + String(e));
87
103
  }
88
104
  }
89
105
  sidecarPath() {
90
- return y.resolve(this.options.srcDir, "..", "assets-plan.json");
106
+ return b.resolve(this.options.srcDir, "..", "assets-plan.json");
91
107
  }
92
108
  async parseExistingAssets() {
93
109
  let e = await this.readExistingAssetsFile();
@@ -96,23 +112,23 @@ var w = typeof x == "function" ? x : x.default, T = typeof C == "function" ? C :
96
112
  try {
97
113
  t = JSON.parse(e);
98
114
  } catch {
99
- throw new E("assets: invalid JSON syntax");
115
+ throw new D("assets: invalid JSON syntax");
100
116
  }
101
- if (d(t)) throw new E("assets: single-file asset plan is not supported");
102
- if (!t || typeof t != "object" || Array.isArray(t)) throw new E("assets: URL dictionary object required");
117
+ if (h(t)) throw new D("assets: single-file asset plan is not supported");
118
+ if (!t || typeof t != "object" || Array.isArray(t)) throw new D("assets: URL dictionary object required");
103
119
  this.flat = { ...t };
104
120
  }
105
121
  try {
106
- this.existingAssets = c(e);
122
+ this.existingAssets = p(e);
107
123
  } catch (e) {
108
- throw new E(e instanceof Error ? e.message : "assets: invalid JSON syntax");
124
+ throw new D(e instanceof Error ? e.message : "assets: invalid JSON syntax");
109
125
  }
110
126
  await this.readSidecar();
111
127
  }
112
128
  async readSidecar() {
113
129
  let e = "";
114
130
  try {
115
- e = await v.readFile(this.sidecarPath(), "utf-8");
131
+ e = await y.readFile(this.sidecarPath(), "utf-8");
116
132
  } catch (e) {
117
133
  e.code !== "ENOENT" && console.warn("assets: unable to read assets-plan.json; continuing with the dictionary only");
118
134
  return;
@@ -125,34 +141,38 @@ var w = typeof x == "function" ? x : x.default, T = typeof C == "function" ? C :
125
141
  console.warn("assets: assets-plan.json is not valid JSON; continuing with the dictionary only");
126
142
  return;
127
143
  }
128
- if (!d(t)) {
144
+ if (!h(t)) {
129
145
  console.warn("assets: assets-plan.json is not a plan; continuing with the dictionary only");
130
146
  return;
131
147
  }
132
- try {
133
- this.document = h(e);
134
- } catch {
135
- console.warn("assets: assets-plan.json could not be read; continuing with the dictionary only");
136
- return;
148
+ let n = t.assets;
149
+ this.planKeys = Object.keys(n);
150
+ let r = b.resolve(this.options.srcDir, "..");
151
+ for (let e of Object.values(n)) {
152
+ let t = e?.implementation?.path;
153
+ typeof t == "string" && t && this.implementationPaths.add(b.resolve(r, t));
137
154
  }
138
- if (!f(this.document)) return;
139
- let n = y.resolve(this.options.srcDir, "..");
140
- this.implementationPaths = new Set(Object.values(this.document.assets).filter((e) => e.implementation?.path).map((e) => y.resolve(n, e.implementation.path)));
141
155
  }
142
156
  isImplementationReference(e, t) {
143
157
  if (!this.implementationPaths.size || /^[a-z][a-z0-9+.-]*:/i.test(t) || t.startsWith("//")) return !1;
144
- let n = t.split(/[?#]/)[0], r = n.startsWith("@/") ? y.resolve(this.options.srcDir, n.slice(2)) : y.resolve(y.dirname(e), n);
158
+ let n = t.split(/[?#]/)[0], r = n.startsWith("@/") ? b.resolve(this.options.srcDir, n.slice(2)) : b.resolve(b.dirname(e), n);
145
159
  return this.implementationPaths.has(r);
146
160
  }
147
161
  async generateAssetsFile() {
148
162
  await this.parseExistingAssets(), await this.scanAllTsFiles();
149
- let e = g(this.assets, this.existingAssets, this.flat), t = y.dirname(this.options.outputFile);
150
- await v.mkdir(t, { recursive: !0 }), await v.writeFile(this.options.outputFile, e, "utf-8"), await this.generateAssetsWrapper(), m(this.assets.size, this.existingAssets, this.assets, this.options.outputFile);
163
+ let e = f(this.assets, this.existingAssets, this.flat);
164
+ try {
165
+ let t = b.dirname(this.options.outputFile);
166
+ await y.mkdir(t, { recursive: !0 }), await y.writeFile(this.options.outputFile, e, "utf-8"), await this.generateAssetsWrapper();
167
+ } catch (e) {
168
+ throw new D("Unable to write the asset dictionary or wrapper: " + String(e));
169
+ }
170
+ l(this.assets.size, this.existingAssets, this.assets, this.options.outputFile);
151
171
  }
152
172
  async generateAssetsWrapper() {
153
173
  let e = this.options.outputFile.replace(/\.json$/, ".ts"), t = `// 🍎 Auto-generated wrapper for assets.json
154
174
  // This file handles iOS image replacement via asset-interceptor.js
155
- import assetsData from "./${y.basename(this.options.outputFile)}";
175
+ import assetsData from "./${b.basename(this.options.outputFile)}";
156
176
 
157
177
  // Batch process all asset URLs for potential replacements
158
178
  // sessionStorage may contain __aippy_asset_overrides__ with multiple image mappings
@@ -160,81 +180,94 @@ import assetsData from "./${y.basename(this.options.outputFile)}";
160
180
 
161
181
  export default assetsData;
162
182
  `;
163
- await v.writeFile(e, t, "utf-8"), console.log(` ✓ Generated assets wrapper: ${y.relative(process.cwd(), e)}`);
183
+ await y.writeFile(e, t, "utf-8"), console.log(` ✓ Generated assets wrapper: ${b.relative(process.cwd(), e)}`);
164
184
  }
165
185
  getAssets() {
166
186
  return Array.from(this.assets.values());
167
187
  }
188
+ isReplacementCandidate(e, t) {
189
+ let i = r(e);
190
+ return i && Object.hasOwn(this.flat, i.key) ? !0 : t.has(n(e));
191
+ }
192
+ replaceLiteral(e, t, n) {
193
+ let r = /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n), i = C.memberExpression(C.identifier(t), r ? C.identifier(n) : C.stringLiteral(n), !r);
194
+ if ((C.isObjectProperty(e.parent) || C.isObjectMethod(e.parent) || C.isClassProperty(e.parent) || C.isClassMethod(e.parent)) && e.key === "key" && (e.parent.computed = !0), e.parent && C.isJSXAttribute(e.parent)) return e.replaceWith(C.jsxExpressionContainer(i)), !0;
195
+ try {
196
+ C.validate(e.parent, e.key, i);
197
+ } catch {
198
+ return !1;
199
+ }
200
+ return e.replaceWith(i), !0;
201
+ }
168
202
  async replaceUrisInFile(e, t) {
169
203
  try {
170
- let a = await this.fileCache.read(e), o = b(a, {
204
+ let o = await this.fileCache.read(e), s = x(o, {
171
205
  sourceType: "module",
172
206
  plugins: [
173
207
  "typescript",
174
208
  "jsx",
175
209
  "decorators-legacy"
176
210
  ]
177
- }), s = !1, c = this.options.outputFile.replace(/\.json$/, ".ts"), l = p(c, this.options.srcDir), u = _(e, this.options.srcDir, this.options.outputFile), d = i(o, u), f = "assetsData", m = !1, h, g = /* @__PURE__ */ new Set();
178
- w(o, {
211
+ }), c = !1, l = this.options.outputFile.replace(/\.json$/, ".ts"), u = m(l, this.options.srcDir), d = v(e, this.options.srcDir, this.options.outputFile), f = a(s, d), p = "assetsData", h = !1, g, _ = /* @__PURE__ */ new Set();
212
+ T(s, {
179
213
  Identifier: (e) => {
180
- g.add(e.node.name);
214
+ _.add(e.node.name);
181
215
  },
182
216
  ImportDeclaration: (e) => {
183
- if (!(!u.has(e.node.source.value) || e.node.importKind === "type")) for (let t of e.node.specifiers) {
217
+ if (!(!d.has(e.node.source.value) || e.node.importKind === "type")) for (let t of e.node.specifiers) {
184
218
  if (t.importKind === "type") continue;
185
219
  let n = e.scope.getBinding(t.local.name);
186
- r(t) && (f = t.local.name, m = !0, h = n);
220
+ i(t) && (p = t.local.name, h = !0, g = n);
187
221
  }
188
222
  }
189
223
  });
190
- let x = !1;
191
- if (m && w(o, { StringLiteral: (r) => {
192
- !S.isImportDeclaration(r.parent) && !d(r) && !this.isImplementationReference(e, r.node.value) && t.has(n(r.node.value)) && r.scope.getBinding(f) !== h && (x = !0);
193
- } }), !m && g.has(f) || x) {
224
+ let S = !1;
225
+ if (h && T(s, { StringLiteral: (n) => {
226
+ !C.isImportDeclaration(n.parent) && !f(n) && !this.isImplementationReference(e, n.node.value) && this.isReplacementCandidate(n.node.value, t) && n.scope.getBinding(p) !== g && (S = !0);
227
+ } }), !h && _.has(p) || S) {
194
228
  let e = "aippyAssetsData";
195
- for (let t = 2; g.has(e); t++) e = `aippyAssetsData${t}`;
196
- x && h.scope.rename(f, e), f = e;
229
+ for (let t = 2; _.has(e); t++) e = `aippyAssetsData${t}`;
230
+ S && g.scope.rename(p, e), p = e;
197
231
  }
198
- if (w(o, { StringLiteral: (r) => {
199
- let i = r.node.value;
200
- if (this.isImplementationReference(e, i) || d(r) || S.isImportDeclaration(r.parent) || S.isExportNamedDeclaration(r.parent) || S.isExportAllDeclaration(r.parent) || r.findParent((e) => S.isTSType(e.node) || S.isTSInterfaceBody(e.node))) return;
201
- let a = n(i);
202
- if (t.has(a)) {
203
- let e = t.get(a), n = S.memberExpression(S.identifier(f), /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e) ? S.identifier(e) : S.stringLiteral(e), !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e));
204
- if ((S.isObjectProperty(r.parent) || S.isObjectMethod(r.parent) || S.isClassProperty(r.parent) || S.isClassMethod(r.parent)) && r.key === "key" && (r.parent.computed = !0), r.parent && S.isJSXAttribute(r.parent)) r.replaceWith(S.jsxExpressionContainer(n));
205
- else {
206
- try {
207
- S.validate(r.parent, r.key, n);
208
- } catch {
209
- return;
210
- }
211
- r.replaceWith(n);
212
- }
213
- r.skip(), s = !0;
232
+ if (T(s, { StringLiteral: (i) => {
233
+ let a = i.node.value;
234
+ if (this.isImplementationReference(e, a) || f(i) || C.isImportDeclaration(i.parent) || C.isExportNamedDeclaration(i.parent) || C.isExportAllDeclaration(i.parent) || i.findParent((e) => C.isTSType(e.node) || C.isTSInterfaceBody(e.node))) return;
235
+ let o = r(a);
236
+ if (o && Object.hasOwn(this.flat, o.key)) {
237
+ this.replaceLiteral(i, p, o.key) && (i.skip(), c = !0);
238
+ return;
214
239
  }
215
- } }), !s) return;
216
- if (!m) {
217
- let e = S.importDeclaration([S.importDefaultSpecifier(S.identifier(f))], S.stringLiteral(l));
218
- o.program.body.unshift(e);
240
+ let s = n(a);
241
+ if (t.has(s)) {
242
+ let e = t.get(s);
243
+ this.replaceLiteral(i, p, e) && (i.skip(), c = !0);
244
+ }
245
+ } }), !c) return;
246
+ if (!h) {
247
+ let e = C.importDeclaration([C.importDefaultSpecifier(C.identifier(p))], C.stringLiteral(u));
248
+ s.program.body.unshift(e);
219
249
  }
220
- let C = T(o, {
250
+ let w = E(s, {
221
251
  retainLines: !1,
222
252
  comments: !0,
223
253
  compact: !1
224
- }, a);
225
- await v.writeFile(e, C.code, "utf-8"), this.fileCache.invalidate(e), console.log(` ✓ Replaced URIs in ${y.relative(process.cwd(), e)}`);
254
+ }, o);
255
+ await y.writeFile(e, w.code, "utf-8"), this.fileCache.invalidate(e), console.log(` ✓ Replaced URIs in ${b.relative(process.cwd(), e)}`);
226
256
  } catch (t) {
227
- if (this.isStructuredInventory()) throw t;
228
257
  console.warn(`Warning: Failed to replace URIs in ${e}:`, t);
229
258
  }
230
259
  }
231
260
  async replaceAllUris() {
232
261
  let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set();
233
262
  for (let n of this.assets.values()) e.set(n.originalUri, n.constantName), t.add(n.filePath);
263
+ for (let e of this.keyRefFiles) t.add(e);
234
264
  for (let n of t) await this.replaceUrisInFile(n, e);
235
265
  }
266
+ needsRewrite() {
267
+ return this.assets.size > 0 || this.keyRefFiles.size > 0;
268
+ }
236
269
  async cleanupUnusedConstants() {
237
- if (!(this.document && f(this.document))) try {
270
+ if (!this.planKeys) try {
238
271
  let e = await this.readExistingAssetsFile();
239
272
  if (!e.trim()) return;
240
273
  let t = /* @__PURE__ */ new Map();
@@ -246,7 +279,7 @@ export default assetsData;
246
279
  return;
247
280
  }
248
281
  if (t.size === 0) return;
249
- let n = /* @__PURE__ */ new Set(), r = await u(this.options.srcDir, [".ts", ".tsx"]);
282
+ let n = /* @__PURE__ */ new Set(), r = await d(this.options.srcDir, [".ts", ".tsx"]);
250
283
  for (let e of r) if (!(e.endsWith("assets.json") || e.endsWith("assets.ts"))) try {
251
284
  let r = await this.fileCache.read(e);
252
285
  for (let e of t.keys()) r.includes(e) && n.add(e);
@@ -271,11 +304,11 @@ export default assetsData;
271
304
  }
272
305
  }
273
306
  async upgradeJsonImportsToTs() {
274
- let e = this.options.outputFile.replace(/\.json$/, ".ts"), t = p(e, this.options.srcDir), n = await u(this.options.srcDir, [".ts", ".tsx"]), r = 0;
307
+ let e = this.options.outputFile.replace(/\.json$/, ".ts"), t = m(e, this.options.srcDir), n = await d(this.options.srcDir, [".ts", ".tsx"]), r = 0;
275
308
  for (let i of n) if (!(i.endsWith("assets.ts") || i.endsWith("assets.json"))) try {
276
- let n = await this.fileCache.read(i), a = s(i, this.options.outputFile) + ".json", o = s(i, e), c = p(this.options.outputFile, this.options.srcDir) + ".json";
277
- if (!n.includes(a) && !n.includes(o) && !n.includes(c)) continue;
278
- let l = b(n, {
309
+ let n = await this.fileCache.read(i), a = c(i, this.options.outputFile) + ".json", o = c(i, e), s = m(this.options.outputFile, this.options.srcDir) + ".json";
310
+ if (!n.includes(a) && !n.includes(o) && !n.includes(s)) continue;
311
+ let l = x(n, {
279
312
  sourceType: "module",
280
313
  plugins: [
281
314
  "typescript",
@@ -283,43 +316,76 @@ export default assetsData;
283
316
  "decorators-legacy"
284
317
  ]
285
318
  }), u = !1;
286
- if (w(l, { ImportDeclaration: (e) => {
319
+ if (T(l, { ImportDeclaration: (e) => {
287
320
  let n = e.node.source.value;
288
- (n === a || n === o || n === c) && (e.node.source.value = t, u = !0);
321
+ (n === a || n === o || n === s) && (e.node.source.value = t, u = !0);
289
322
  } }), u) {
290
- let e = T(l, {
323
+ let e = E(l, {
291
324
  retainLines: !1,
292
325
  comments: !0,
293
326
  compact: !1
294
327
  }, n);
295
- await v.writeFile(i, e.code, "utf-8"), this.fileCache.invalidate(i), console.log(` ✓ Upgraded import in ${y.relative(process.cwd(), i)} → ${t}`), r++;
328
+ await y.writeFile(i, e.code, "utf-8"), this.fileCache.invalidate(i), console.log(` ✓ Upgraded import in ${b.relative(process.cwd(), i)} → ${t}`), r++;
296
329
  }
297
330
  } catch (e) {
298
- if (this.isStructuredInventory()) throw e;
299
331
  console.warn(`Warning: Failed to upgrade imports in ${i}:`, e);
300
332
  }
301
333
  r > 0 && console.log(`✅ Upgraded ${r} file(s) to use ${t}`);
302
334
  }
303
- };
304
- function O(e = {}) {
335
+ async stripUnresolvedTokens() {
336
+ let e = await d(this.options.srcDir, [...k]);
337
+ e.push(b.resolve(this.options.srcDir, "..", "index.html"));
338
+ let t = b.resolve(this.options.outputFile);
339
+ for (let n of e) if (b.resolve(n) !== t) try {
340
+ let e = await y.readFile(n, "utf-8"), t = g(e);
341
+ if (t === e) continue;
342
+ await y.writeFile(n, t, "utf-8"), this.fileCache.invalidate(n), console.log(` ✓ Kept plain asset urls in ${b.relative(process.cwd(), n)}`);
343
+ } catch (e) {
344
+ if (e.code === "ENOENT") continue;
345
+ console.warn(`Warning: Failed to clean asset tokens in ${n}:`, e);
346
+ }
347
+ }
348
+ }, k = [
349
+ ".ts",
350
+ ".tsx",
351
+ ".js",
352
+ ".jsx",
353
+ ".mjs",
354
+ ".css",
355
+ ".scss",
356
+ ".sass",
357
+ ".less",
358
+ ".html",
359
+ ".json"
360
+ ];
361
+ function A(e = {}) {
305
362
  return {
306
363
  name: "vite-plugin-asset-constants",
307
364
  apply: "build",
308
365
  enforce: "pre",
309
366
  async buildStart() {
310
367
  if (!e.devMode) return;
311
- let t = new D(e);
368
+ let t = new O(e);
312
369
  try {
313
370
  await t.generateAssetsFile();
314
371
  let e = t.getAssets();
315
- e.length > 0 && (console.log(`📦 Found ${e.length} asset references:`), e.forEach((e) => {
316
- console.log(` ${e.constantName} = '${e.originalUri}' (${y.relative(process.cwd(), e.filePath)}:${e.line})`);
317
- }), console.log("\n🔄 Replacing URIs with constants..."), await t.replaceAllUris(), console.log("✅ URI replacement completed!")), console.log("\n🧹 Checking for unused constants..."), await t.cleanupUnusedConstants(), await t.generateAssetsFile(), console.log("\n🔄 Upgrading assets.json imports to assets.ts..."), await t.upgradeJsonImportsToTs(), console.log("✅ Asset constants finalized!\n"), t.clearCache();
372
+ t.needsRewrite() && (console.log(`📦 Found ${e.length} asset references:`), e.forEach((e) => {
373
+ console.log(` ${e.constantName} = '${e.originalUri}' (${b.relative(process.cwd(), e.filePath)}:${e.line})`);
374
+ }), console.log("\n🔄 Replacing URIs with constants..."), await t.replaceAllUris(), console.log("✅ URI replacement completed!")), console.log("\n🧹 Checking for unused constants..."), await t.cleanupUnusedConstants(), await t.generateAssetsFile(), console.log("\n🔄 Upgrading assets.json imports to assets.ts..."), await t.upgradeJsonImportsToTs(), await t.stripUnresolvedTokens(), console.log("✅ Asset constants finalized!\n"), t.clearCache();
318
375
  } catch (e) {
319
- console.error("❌ Error in asset constants plugin:", e), (e instanceof E || t.isStructuredInventory()) && this.error(e instanceof Error ? e.message : String(e));
376
+ console.error("❌ Error in asset constants plugin:", e), e instanceof D && this.error(e.message);
320
377
  }
378
+ },
379
+ transform(e, t) {
380
+ return t.includes("/node_modules/") || !e.includes("aippy-asset:") ? null : {
381
+ code: g(e),
382
+ map: null
383
+ };
384
+ },
385
+ transformIndexHtml(e) {
386
+ return g(e);
321
387
  }
322
388
  };
323
389
  }
324
390
  //#endregion
325
- export { O as assetConstantsPlugin, O as default };
391
+ export { A as assetConstantsPlugin, A as default };
@@ -1,5 +1,6 @@
1
1
  import * as t from '@babel/types';
2
2
  export declare function isDefaultImport(item: t.ImportDeclaration['specifiers'][number]): boolean;
3
+ /** A string literal used as `assets['key']` on the wrapper's default import. */
3
4
  export declare function wrapperKeyGuard(ast: t.File, importSources: Set<string>): (p: any) => boolean;
4
5
  export declare function wrapperImportSources(filePath: string, srcDir: string, outputFile: string): Set<string>;
5
6
  export declare function withoutWrapperKeys(content: string, filePath: string, srcDir: string, outputFile: string): string;