ai-extension-preview 0.1.6 → 0.1.7
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/index.js +0 -0
- package/dist/plugins/BrowserPlugin.js +47 -10
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
File without changes
|
|
@@ -40,6 +40,7 @@ export const BrowserPlugin = {
|
|
|
40
40
|
const STAGING_DIR = isWSL ? '/mnt/c/Temp/ai-ext-preview' : path.join(config.workDir, '../staging');
|
|
41
41
|
const WIN_PROFILE_DIR = 'C:/Temp/ai-ext-profile';
|
|
42
42
|
// For native windows/linux, use local staging path
|
|
43
|
+
// Note: We will evaluate actual extension root later, but base is STAGING_DIR
|
|
43
44
|
const EXTENSION_PATH = isWSL ? 'C:/Temp/ai-ext-preview' : STAGING_DIR;
|
|
44
45
|
// --- SYNC FUNCTION ---
|
|
45
46
|
const syncToStaging = async () => {
|
|
@@ -49,7 +50,7 @@ export const BrowserPlugin = {
|
|
|
49
50
|
}
|
|
50
51
|
fs.ensureDirSync(STAGING_DIR);
|
|
51
52
|
fs.copySync(DIST_DIR, STAGING_DIR);
|
|
52
|
-
await ctx.actions.runAction('core:log', { level: 'info', message: `Synced code to Staging
|
|
53
|
+
await ctx.actions.runAction('core:log', { level: 'info', message: `Synced code to Staging` });
|
|
53
54
|
// Emit staged event for ServerPlugin (optional for now, but good practice)
|
|
54
55
|
ctx.events.emit('browser:staged', { path: STAGING_DIR });
|
|
55
56
|
}
|
|
@@ -57,8 +58,38 @@ export const BrowserPlugin = {
|
|
|
57
58
|
await ctx.actions.runAction('core:log', { level: 'error', message: `Failed to sync to staging: ${err.message}` });
|
|
58
59
|
}
|
|
59
60
|
};
|
|
61
|
+
// --- Helper to find actual extension root (handle nested folder in zip) ---
|
|
62
|
+
const findExtensionRoot = (dir) => {
|
|
63
|
+
if (fs.existsSync(path.join(dir, 'manifest.json')))
|
|
64
|
+
return dir;
|
|
65
|
+
// Check immediate subdirectories (depth 1)
|
|
66
|
+
try {
|
|
67
|
+
const items = fs.readdirSync(dir);
|
|
68
|
+
for (const item of items) {
|
|
69
|
+
const fullPath = path.join(dir, item);
|
|
70
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
71
|
+
if (fs.existsSync(path.join(fullPath, 'manifest.json'))) {
|
|
72
|
+
return fullPath;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
// Dir might be empty or invalid
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
60
82
|
// Initial Sync
|
|
61
83
|
await syncToStaging();
|
|
84
|
+
// Resolve proper root AFTER sync
|
|
85
|
+
let extensionRoot = findExtensionRoot(STAGING_DIR) || STAGING_DIR;
|
|
86
|
+
// Check if we found a valid root
|
|
87
|
+
if (!fs.existsSync(path.join(extensionRoot, 'manifest.json'))) {
|
|
88
|
+
await ctx.actions.runAction('core:log', { level: 'error', message: `[CRITICAL] manifest.json not found in ${STAGING_DIR}. Extension will not load.` });
|
|
89
|
+
}
|
|
90
|
+
else if (extensionRoot !== STAGING_DIR) {
|
|
91
|
+
await ctx.actions.runAction('core:log', { level: 'info', message: `Detected nested extension at: ${path.basename(extensionRoot)}` });
|
|
92
|
+
}
|
|
62
93
|
// Listen for updates and re-sync
|
|
63
94
|
ctx.events.on('downloader:updated', async (data) => {
|
|
64
95
|
await ctx.actions.runAction('core:log', { level: 'info', message: 'Update detected. Syncing to staging...' });
|
|
@@ -71,12 +102,20 @@ export const BrowserPlugin = {
|
|
|
71
102
|
const winChromePath = chromePath
|
|
72
103
|
.replace(new RegExp(`^/mnt/${driveLetter}/`), `${driveLetter.toUpperCase()}:\\`)
|
|
73
104
|
.replace(/\//g, '\\');
|
|
74
|
-
|
|
105
|
+
// Calculate Windows path for the extension root
|
|
106
|
+
// Base Win: C:\Temp\ai-ext-preview
|
|
107
|
+
// Base Linux: /mnt/c/Temp/ai-ext-preview
|
|
108
|
+
// If extensionRoot is /mnt/c/Temp/ai-ext-preview/subdir => C:\Temp\ai-ext-preview\subdir
|
|
109
|
+
// Use relative path logic to be safe
|
|
110
|
+
const baseLinux = '/mnt/c/Temp/ai-ext-preview';
|
|
111
|
+
const relative = path.relative(baseLinux, extensionRoot);
|
|
112
|
+
const winDistRoot = relative ? `C:\\Temp\\ai-ext-preview\\${relative}` : 'C:\\Temp\\ai-ext-preview';
|
|
113
|
+
const finalWinDist = winDistRoot.replace(/\//g, '\\');
|
|
75
114
|
const winProfile = 'C:\\Temp\\ai-ext-profile';
|
|
76
115
|
const batContent = `@echo off
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
116
|
+
start "" "${winChromePath}" --load-extension="${finalWinDist}" --user-data-dir="${winProfile}" --no-first-run --no-default-browser-check --disable-gpu about:blank
|
|
117
|
+
exit
|
|
118
|
+
`;
|
|
80
119
|
const batPath = path.join(STAGING_DIR, 'launch.bat');
|
|
81
120
|
const winBatPath = 'C:\\Temp\\ai-ext-preview\\launch.bat';
|
|
82
121
|
try {
|
|
@@ -84,8 +123,6 @@ export const BrowserPlugin = {
|
|
|
84
123
|
}
|
|
85
124
|
catch (e) {
|
|
86
125
|
// Fallback if staging writes fail inside WSL mount for some reason?
|
|
87
|
-
// Should satisfy since we verified interop before?
|
|
88
|
-
// Actually verification was removed in this block, let's assume it works or fail.
|
|
89
126
|
}
|
|
90
127
|
const cli = 'cmd.exe';
|
|
91
128
|
const subprocess = spawn(cli, ['/c', winBatPath], {
|
|
@@ -98,11 +135,11 @@ export const BrowserPlugin = {
|
|
|
98
135
|
}
|
|
99
136
|
else {
|
|
100
137
|
// Native Windows / Linux
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// We need a stable profile path for native too to keep Detached session alive/resuable
|
|
138
|
+
// Use extensionRoot which points to the detected subfolder or root
|
|
139
|
+
const safeDist = path.resolve(extensionRoot);
|
|
104
140
|
const safeProfile = path.join(path.dirname(config.workDir), 'profile'); // ~/.ai-extension-preview/profile
|
|
105
141
|
await ctx.actions.runAction('core:log', { level: 'info', message: `SPAWN: ${executable}` });
|
|
142
|
+
await ctx.actions.runAction('core:log', { level: 'info', message: `EXT PATH: ${safeDist}` });
|
|
106
143
|
const cleanArgs = [
|
|
107
144
|
`--load-extension=${safeDist}`,
|
|
108
145
|
`--user-data-dir=${safeProfile}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-extension-preview",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Local preview tool for AI Extension Builder",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"author": "AI Extension Builder",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"scripts": {
|
|
23
|
-
"build": "shx rm -rf dist && tsc -b",
|
|
23
|
+
"build": "shx rm -rf dist && tsc -b && shx chmod +x dist/index.js",
|
|
24
24
|
"start": "tsx src/index.ts",
|
|
25
25
|
"dev": "tsx watch src/index.ts",
|
|
26
26
|
"preview": "node dist/index.js"
|
|
@@ -49,4 +49,4 @@
|
|
|
49
49
|
"tsx": "^4.21.0",
|
|
50
50
|
"typescript": "^5.7.2"
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|