@aippy/vite-plugins 0.2.9-dev.0 → 0.4.0-dev.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/README.md CHANGED
@@ -15,7 +15,7 @@ pnpm add -D @aippy/vite-plugins
15
15
  Generates constant references for static assets and replaces hardcoded paths.
16
16
 
17
17
  ```typescript
18
- import { assetConstantsPlugin } from '@aippy/vite-plugins/asset-constants'
18
+ import { assetConstantsPlugin } from '@aippy/vite-plugins/asset-constants';
19
19
 
20
20
  export default defineConfig({
21
21
  plugins: [
@@ -23,10 +23,10 @@ export default defineConfig({
23
23
  extensions: ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.mp4', '.mp3'],
24
24
  srcDir: 'src',
25
25
  outputFile: 'src/config/assets.json',
26
- devMode: true
27
- })
28
- ]
29
- })
26
+ devMode: true,
27
+ }),
28
+ ],
29
+ });
30
30
  ```
31
31
 
32
32
  ### 2. Aippy Preload Plugin
@@ -34,17 +34,17 @@ export default defineConfig({
34
34
  Scans build output and generates preload meta tags for assets.
35
35
 
36
36
  ```typescript
37
- import { aippyPreloadPlugin } from '@aippy/vite-plugins/aippy-preload'
37
+ import { aippyPreloadPlugin } from '@aippy/vite-plugins/aippy-preload';
38
38
 
39
39
  export default defineConfig({
40
40
  plugins: [
41
41
  aippyPreloadPlugin({
42
42
  extensions: ['.js', '.css', '.png', '.jpg', '.svg'],
43
43
  outDir: 'dist',
44
- includeSubdirs: true
45
- })
46
- ]
47
- })
44
+ includeSubdirs: true,
45
+ }),
46
+ ],
47
+ });
48
48
  ```
49
49
 
50
50
  ### 3. Aippy Tagger Plugin
@@ -52,19 +52,21 @@ export default defineConfig({
52
52
  Tags React components with metadata for development tools and inspector.
53
53
 
54
54
  ```typescript
55
- import { aippyTaggerPlugin } from '@aippy/vite-plugins/aippy-tagger'
55
+ import { aippyTaggerPlugin } from '@aippy/vite-plugins/aippy-tagger';
56
56
 
57
57
  export default defineConfig({
58
- plugins: [
59
- aippyTaggerPlugin()
60
- ]
61
- })
58
+ plugins: [aippyTaggerPlugin()],
59
+ });
62
60
  ```
63
61
 
64
62
  ### All-in-One Import
65
63
 
66
64
  ```typescript
67
- import { assetConstantsPlugin, aippyPreloadPlugin, aippyTaggerPlugin } from '@aippy/vite-plugins'
65
+ import {
66
+ assetConstantsPlugin,
67
+ aippyPreloadPlugin,
68
+ aippyTaggerPlugin,
69
+ } from '@aippy/vite-plugins';
68
70
  ```
69
71
 
70
72
  ### Utility Functions
@@ -72,31 +74,36 @@ import { assetConstantsPlugin, aippyPreloadPlugin, aippyTaggerPlugin } from '@ai
72
74
  The package also exports utility functions that can be used independently:
73
75
 
74
76
  ```typescript
75
- import {
76
- processAssetURL,
77
- isValidAsset,
78
- generateConstantName,
77
+ import {
78
+ processAssetURL,
79
+ isValidAsset,
80
+ generateConstantName,
79
81
  extractAssetsFromContent,
80
- findProjectRoot
81
- } from '@aippy/vite-plugins/utils'
82
+ findProjectRoot,
83
+ } from '@aippy/vite-plugins/utils';
82
84
 
83
85
  // Process asset URLs
84
- const processedUrl = processAssetURL('./image.png') // '/image.png'
86
+ const processedUrl = processAssetURL('./image.png'); // '/image.png'
85
87
 
86
88
  // Validate asset paths
87
- const isValid = isValidAsset('./image.png') // true
89
+ const isValid = isValidAsset('./image.png'); // true
88
90
 
89
91
  // Generate constant names
90
- const constantName = generateConstantName('/image.png') // 'IMAGE_ABCD'
92
+ const constantName = generateConstantName('/image.png'); // 'IMAGE_ABCD'
91
93
 
92
94
  // Extract assets from content
93
- const assets = extractAssetsFromContent(htmlContent, 'html', ['.png', '.jpg'])
95
+ const assets = extractAssetsFromContent(htmlContent, 'html', ['.png', '.jpg']);
94
96
 
95
97
  // Find project root
96
- const projectRoot = findProjectRoot() // '/path/to/project'
98
+ const projectRoot = findProjectRoot(); // '/path/to/project'
97
99
  ```
98
100
 
99
101
  ## License
100
102
 
101
103
  UNLICENSED - Aippy Team
102
104
 
105
+ ## Asset manifest v1
106
+
107
+ Version 0.4.0-dev.1 reads both legacy flat URL inventories and `schemaVersion: 1` manifests. Assets Agent writes resource plans; development builds preserve their metadata and supplement resources discovered by the existing scanner. Invalid v1 inventories and manifest/wrapper write failures stop the build.
108
+
109
+ Import the generated flat URL map from `@/config/assets`. Only entries with usable URLs appear in that map; the existing `window.getReplacedAssets` hook still mutates it in place. Source-code assets and generated fallbacks with an exact `implementation.path` retain their original source references. Preload reads resource URLs rather than generation prompts or error text. The JSON schema is exported as `@aippy/vite-plugins/assets.schema.json`; parser checks also enforce byte, reference and semantic constraints.
@@ -1,2 +1,2 @@
1
- import { t as e } from "../aippy-preload-8BoWu90-.js";
1
+ import { t as e } from "../aippy-preload-QZY6fyKx.js";
2
2
  export { e as aippyPreloadPlugin, e as default };
@@ -1,86 +1,103 @@
1
1
  import { extractAssetsFromContent as e } from "./utils/index.js";
2
- import { r as t } from "./file-scanner-DT-LbrCa.js";
3
- import { promises as n } from "fs";
4
- import r from "path";
2
+ import { d as t, i as n, o as r, r as i, t as a } from "./manifest-CI1ALLzl.js";
3
+ import { promises as o } from "fs";
4
+ import s from "path";
5
5
  //#region src/aippy-preload/scanner-utils.ts
6
- async function i(t) {
7
- let i = [], a = [r.join(process.cwd(), "index.html")];
8
- for (let r of a) try {
9
- let a = await n.readFile(r, "utf-8"), o = e(a, "html", t);
10
- i.push(...o);
6
+ async function c(t) {
7
+ let n = [], r = [s.join(process.cwd(), "index.html")];
8
+ for (let i of r) try {
9
+ let r = await o.readFile(i, "utf-8"), a = e(r, "html", t);
10
+ n.push(...a);
11
11
  } catch {
12
12
  console.warn("⚠️ No index.html found in project root");
13
13
  }
14
- return i;
14
+ return n;
15
15
  }
16
- async function a(r, i) {
17
- let a = [], o = await t(r, [
16
+ async function l(a, c) {
17
+ let l = [], u = s.resolve(a, "config/assets.json"), d;
18
+ try {
19
+ let e = n(await o.readFile(u, "utf8"));
20
+ i(e) && (d = e);
21
+ } catch {}
22
+ let f = await t(a, [
18
23
  ".ts",
19
24
  ".tsx",
20
25
  ".js",
21
26
  ".jsx"
22
27
  ]);
23
- for (let t of o) try {
24
- let r = await n.readFile(t, "utf-8"), o = e(r, "js", i);
25
- a.push(...o);
28
+ for (let t of f) try {
29
+ if (d && s.resolve(t) === u.replace(/\.json$/, ".ts")) continue;
30
+ let n = await o.readFile(t, "utf-8"), i = e(n, "js", c);
31
+ d && i.some((e) => Object.hasOwn(d.assets, e)) && (i = e(r(n, t, a, u), "js", c)), l.push(...i);
26
32
  } catch (e) {
27
33
  console.warn(`⚠️ Failed to read JS file: ${t}`, e);
28
34
  }
29
- return a;
35
+ return l;
30
36
  }
31
- async function o(r, i) {
32
- let a = [], o = await t(r, [
37
+ async function u(n, r) {
38
+ let i = [], a = await t(n, [
33
39
  ".css",
34
40
  ".scss",
35
41
  ".sass",
36
42
  ".less"
37
43
  ]);
38
- for (let t of o) try {
39
- let r = await n.readFile(t, "utf-8"), o = e(r, "css", i);
40
- a.push(...o);
44
+ for (let t of a) try {
45
+ let n = await o.readFile(t, "utf-8"), a = e(n, "css", r);
46
+ i.push(...a);
41
47
  } catch (e) {
42
48
  console.warn(`⚠️ Failed to read CSS file: ${t}`, e);
43
49
  }
44
- return a;
50
+ return i;
45
51
  }
46
- async function s(r, i) {
47
- let a = [], o = await t(r, [".json"]);
48
- for (let t of o) try {
49
- let r = await n.readFile(t, "utf-8"), o = e(r, "js", i);
50
- a.push(...o);
52
+ async function d(r, c) {
53
+ let l = [], u = await t(r, [".json"]);
54
+ for (let t of u) try {
55
+ let r = await o.readFile(t, "utf-8");
56
+ if (s.basename(t) === "assets.json") {
57
+ let e = JSON.parse(r);
58
+ if (e && Object.prototype.hasOwnProperty.call(e, "schemaVersion")) {
59
+ let e = n(r);
60
+ if (i(e)) {
61
+ l.push(...Object.values(a(e)));
62
+ continue;
63
+ }
64
+ }
65
+ }
66
+ let u = e(r, "js", c);
67
+ l.push(...u);
51
68
  } catch (e) {
52
69
  console.warn(`⚠️ Failed to read JSON file: ${t}`, e);
53
70
  }
54
- return a;
71
+ return l;
55
72
  }
56
- async function c(e, t, n) {
73
+ async function f(e, t, n) {
57
74
  console.log("🔍 Scanning source files for static assets...");
58
75
  let r = [];
59
76
  if (n) {
60
77
  console.log("🔍 Deep scanning source file contents...");
61
- let [n, c, l, u] = await Promise.all([
62
- i(t),
63
- a(e, t),
64
- o(e, t),
65
- s(e, t)
78
+ let [n, i, a, o] = await Promise.all([
79
+ c(t),
80
+ l(e, t),
81
+ u(e, t),
82
+ d(e, t)
66
83
  ]);
67
- r.push(...n, ...c, ...l, ...u);
84
+ r.push(...n, ...i, ...a, ...o);
68
85
  }
69
86
  return [...new Set(r)];
70
87
  }
71
88
  //#endregion
72
89
  //#region src/aippy-preload/html-utils.ts
73
- var l = "<head>", u = 6;
74
- function d(e) {
90
+ var p = "<head>", m = 6;
91
+ function h(e) {
75
92
  return e.map((e) => ` <meta content="${e}" name="aippy:preload">`).join("\n");
76
93
  }
77
- function f(e, t) {
78
- let n = e.indexOf(l);
94
+ function g(e, t) {
95
+ let n = e.indexOf(p);
79
96
  if (n === -1) throw Error("Could not find <head> tag in HTML");
80
- let r = n + u;
97
+ let r = n + m;
81
98
  return e.slice(0, r) + "\n" + t + "\n" + e.slice(r);
82
99
  }
83
- function p(e) {
100
+ function _(e) {
84
101
  let t = e.length;
85
102
  if (console.log(`📁 Found ${t} static ${t === 1 ? "asset" : "assets"} in source files`), t === 0) {
86
103
  console.log("⚠️ No static assets found in source files.");
@@ -88,22 +105,22 @@ function p(e) {
88
105
  }
89
106
  console.log(`📋 ${t === 1 ? "Asset" : "Assets"} found:`), e.forEach((e) => console.log(` - ${e}`));
90
107
  }
91
- function m(e) {
108
+ function v(e) {
92
109
  console.log(`✅ Injected ${e} preload meta ${e === 1 ? "tag" : "tags"} into index.html`);
93
110
  }
94
111
  //#endregion
95
112
  //#region src/aippy-preload/index.ts
96
- var h = 3, g = 1e3;
97
- function _(e) {
113
+ var y = 3, b = 1e3;
114
+ function x(e) {
98
115
  return new Promise((t) => setTimeout(t, e));
99
116
  }
100
- async function v(e, t = h, r = g) {
101
- for (let i = 1; i <= t; i++) try {
102
- return await n.readFile(e, "utf-8");
117
+ async function S(e, t = y, n = b) {
118
+ for (let r = 1; r <= t; r++) try {
119
+ return await o.readFile(e, "utf-8");
103
120
  } catch (e) {
104
121
  if (e.code === "ENOENT") {
105
- if (i < t) {
106
- console.log(`⏳ index.html not found, waiting ${r}ms before retry (attempt ${i}/${t})...`), await _(r);
122
+ if (r < t) {
123
+ console.log(`⏳ index.html not found, waiting ${n}ms before retry (attempt ${r}/${t})...`), await x(n);
107
124
  continue;
108
125
  }
109
126
  return console.log(`⚠️ index.html not found after ${t} attempts, skipping preload injection.`), null;
@@ -112,7 +129,7 @@ async function v(e, t = h, r = g) {
112
129
  }
113
130
  return null;
114
131
  }
115
- function y(e = {}) {
132
+ function C(e = {}) {
116
133
  let t = {
117
134
  extensions: [
118
135
  ".png",
@@ -137,12 +154,12 @@ function y(e = {}) {
137
154
  enforce: "post",
138
155
  async writeBundle() {
139
156
  try {
140
- let e = await c(t.srcDir, t.extensions, t.deepScan);
141
- if (p(e), e.length === 0) return;
142
- let i = r.join(t.outDir, "index.html"), a = await v(i);
143
- if (a === null) return;
144
- let o = f(a, d(e));
145
- await n.writeFile(i, o, "utf-8"), m(e.length);
157
+ let e = await f(t.srcDir, t.extensions, t.deepScan);
158
+ if (_(e), e.length === 0) return;
159
+ let n = s.join(t.outDir, "index.html"), r = await S(n);
160
+ if (r === null) return;
161
+ let i = g(r, h(e));
162
+ await o.writeFile(n, i, "utf-8"), v(e.length);
146
163
  } catch (e) {
147
164
  console.error("❌ Error in aippy preload plugin:", e);
148
165
  }
@@ -150,4 +167,4 @@ function y(e = {}) {
150
167
  };
151
168
  }
152
169
  //#endregion
153
- export { y as t };
170
+ export { C as t };
@@ -1,11 +1,12 @@
1
1
  import { AssetInfo } from './types';
2
+ import { AssetDocument } from './manifest';
2
3
  /**
3
4
  * Generate assets.json file content from asset info
4
5
  * @param assets - Map of assets
5
6
  * @param existingAssets - Map of existing assets from previous runs
6
7
  * @returns JSON string
7
8
  */
8
- export declare function generateAssetsFileContent(assets: Map<string, AssetInfo>, existingAssets: Map<string, string>): string;
9
+ export declare function generateAssetsFileContent(assets: Map<string, AssetInfo>, existingAssets: Map<string, string>, document?: AssetDocument): string;
9
10
  /**
10
11
  * Parse existing assets.json file
11
12
  * @param content - File content
@@ -1,2 +1,2 @@
1
- import { t as e } from "../asset-constants-BvKclVVI.js";
1
+ import { t as e } from "../asset-constants-C59CLHCE.js";
2
2
  export { e as assetConstantsPlugin, e as default };
@@ -0,0 +1,51 @@
1
+ export interface AssetError {
2
+ stage: string;
3
+ code: string;
4
+ message: string;
5
+ retryable: boolean;
6
+ }
7
+ export interface AssetParams {
8
+ width?: number;
9
+ height?: number;
10
+ durationSeconds?: number;
11
+ loop?: boolean;
12
+ }
13
+ export interface AssetImplementation {
14
+ method: 'svg' | 'canvas' | 'css' | 'synth' | 'animation' | 'three';
15
+ description: string;
16
+ status: 'planned' | 'ready';
17
+ path?: string;
18
+ symbol?: string;
19
+ }
20
+ export interface AssetEntry {
21
+ type: string;
22
+ source: 'generated' | 'user' | 'existing' | 'code';
23
+ replaceable: boolean;
24
+ description: string;
25
+ params?: AssetParams;
26
+ generation?: {
27
+ action: 'generate' | 'reuse';
28
+ prompt: string;
29
+ };
30
+ status: 'planned' | 'ready' | 'failed' | 'skipped' | 'degraded';
31
+ url?: string;
32
+ output?: {
33
+ format?: string;
34
+ width?: number;
35
+ height?: number;
36
+ durationSeconds?: number;
37
+ };
38
+ error?: AssetError;
39
+ implementation?: AssetImplementation;
40
+ }
41
+ export interface AssetManifest {
42
+ schemaVersion: 1;
43
+ artStyle: string;
44
+ assets: Record<string, AssetEntry>;
45
+ planningError?: AssetError;
46
+ }
47
+ export type AssetDocument = AssetManifest | Record<string, string>;
48
+ export declare function isManifest(doc: AssetDocument): doc is AssetManifest;
49
+ export declare function parseAssetDocument(content: string): AssetDocument;
50
+ export declare function assetUrlMap(document: AssetDocument): Record<string, string>;
51
+ export declare function inferExistingType(uri: string): string;
@@ -0,0 +1,5 @@
1
+ import * as t from '@babel/types';
2
+ export declare function isDefaultImport(item: t.ImportDeclaration['specifiers'][number]): boolean;
3
+ export declare function wrapperKeyGuard(ast: t.File, importSources: Set<string>): (p: any) => boolean;
4
+ export declare function wrapperImportSources(filePath: string, srcDir: string, outputFile: string): Set<string>;
5
+ export declare function withoutWrapperKeys(content: string, filePath: string, srcDir: string, outputFile: string): string;