vite-plugin-opencode-assistant 1.1.22 → 1.1.23
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/es/core/opencode-web.mjs +19 -19
- package/lib/core/opencode-web.cjs +19 -19
- package/package.json +5 -5
package/es/core/opencode-web.mjs
CHANGED
|
@@ -21,24 +21,25 @@ import { execa } from "execa";
|
|
|
21
21
|
import fs from "fs";
|
|
22
22
|
import { createRequire } from "module";
|
|
23
23
|
import path from "path";
|
|
24
|
+
import { pathToFileURL } from "url";
|
|
24
25
|
import { createLogger, getProcessLogBuffer } from "@vite-plugin-opencode-assistant/shared/node";
|
|
25
26
|
const require2 = createRequire(path.join(process.cwd(), "package.json"));
|
|
26
27
|
const packageDir = resolvePackageDir();
|
|
27
28
|
const log = createLogger("OpenCodeWeb");
|
|
28
29
|
function prepareOpenCodeRuntime(cwd) {
|
|
29
30
|
const cacheDir = path.join(cwd, "node_modules", ".cache", "opencode");
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
fs.mkdirSync(pluginsDir, { recursive: true });
|
|
31
|
+
log.debug("Setting up OpenCode runtime", { cacheDir });
|
|
32
|
+
if (!fs.existsSync(cacheDir)) {
|
|
33
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
34
34
|
}
|
|
35
35
|
const sourcePluginsDir = resolveSourcePluginsDir();
|
|
36
|
-
|
|
37
|
-
const
|
|
36
|
+
const plugins = resolvePluginEntries(sourcePluginsDir);
|
|
37
|
+
const opencodeConfigPath = path.join(cacheDir, "opencode.json");
|
|
38
38
|
fs.writeFileSync(
|
|
39
|
-
|
|
39
|
+
opencodeConfigPath,
|
|
40
40
|
JSON.stringify(
|
|
41
41
|
{
|
|
42
|
+
plugin: plugins,
|
|
42
43
|
mcp: {
|
|
43
44
|
"chrome-devtools": {
|
|
44
45
|
type: "local",
|
|
@@ -53,8 +54,8 @@ function prepareOpenCodeRuntime(cwd) {
|
|
|
53
54
|
);
|
|
54
55
|
log.debug("OpenCode runtime ready", {
|
|
55
56
|
cacheDir,
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
opencodeConfigPath,
|
|
58
|
+
pluginCount: plugins.length
|
|
58
59
|
});
|
|
59
60
|
return cacheDir;
|
|
60
61
|
}
|
|
@@ -126,22 +127,21 @@ function resolveSourcePluginsDir() {
|
|
|
126
127
|
}
|
|
127
128
|
return candidatePaths[0];
|
|
128
129
|
}
|
|
129
|
-
function
|
|
130
|
-
const files = fs.readdirSync(sourceDir).filter((f) => f.endsWith(".js")
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
log.debug("All plugin files copied", { count: files.length, files });
|
|
130
|
+
function resolvePluginEntries(sourceDir) {
|
|
131
|
+
const files = fs.readdirSync(sourceDir).filter((f) => f.endsWith(".js"));
|
|
132
|
+
const entries = files.map((file) => {
|
|
133
|
+
const absolutePath = path.join(sourceDir, file);
|
|
134
|
+
return pathToFileURL(absolutePath).href;
|
|
135
|
+
});
|
|
136
|
+
log.debug("Resolved plugin entries", { count: entries.length, entries });
|
|
137
|
+
return entries;
|
|
138
138
|
}
|
|
139
139
|
function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, logFilesJson) {
|
|
140
140
|
const env = __spreadProps(__spreadValues({}, Object.fromEntries(
|
|
141
141
|
Object.entries(process.env).filter(([, v]) => v !== void 0)
|
|
142
142
|
)), {
|
|
143
143
|
XDG_STATE_HOME: stateDir,
|
|
144
|
-
// 指向缓存目录,OpenCode
|
|
144
|
+
// 指向缓存目录,OpenCode 通过 opencode.json 中 plugins 字段加载插件
|
|
145
145
|
OPENCODE_CONFIG_DIR: stateDir
|
|
146
146
|
});
|
|
147
147
|
if (configDir) {
|
|
@@ -52,24 +52,25 @@ var import_execa = require("execa");
|
|
|
52
52
|
var import_fs = __toESM(require("fs"));
|
|
53
53
|
var import_module = require("module");
|
|
54
54
|
var import_path = __toESM(require("path"));
|
|
55
|
+
var import_url = require("url");
|
|
55
56
|
var import_node = require("@vite-plugin-opencode-assistant/shared/node");
|
|
56
57
|
const require2 = (0, import_module.createRequire)(import_path.default.join(process.cwd(), "package.json"));
|
|
57
58
|
const packageDir = resolvePackageDir();
|
|
58
59
|
const log = (0, import_node.createLogger)("OpenCodeWeb");
|
|
59
60
|
function prepareOpenCodeRuntime(cwd) {
|
|
60
61
|
const cacheDir = import_path.default.join(cwd, "node_modules", ".cache", "opencode");
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
import_fs.default.mkdirSync(pluginsDir, { recursive: true });
|
|
62
|
+
log.debug("Setting up OpenCode runtime", { cacheDir });
|
|
63
|
+
if (!import_fs.default.existsSync(cacheDir)) {
|
|
64
|
+
import_fs.default.mkdirSync(cacheDir, { recursive: true });
|
|
65
65
|
}
|
|
66
66
|
const sourcePluginsDir = resolveSourcePluginsDir();
|
|
67
|
-
|
|
68
|
-
const
|
|
67
|
+
const plugins = resolvePluginEntries(sourcePluginsDir);
|
|
68
|
+
const opencodeConfigPath = import_path.default.join(cacheDir, "opencode.json");
|
|
69
69
|
import_fs.default.writeFileSync(
|
|
70
|
-
|
|
70
|
+
opencodeConfigPath,
|
|
71
71
|
JSON.stringify(
|
|
72
72
|
{
|
|
73
|
+
plugin: plugins,
|
|
73
74
|
mcp: {
|
|
74
75
|
"chrome-devtools": {
|
|
75
76
|
type: "local",
|
|
@@ -84,8 +85,8 @@ function prepareOpenCodeRuntime(cwd) {
|
|
|
84
85
|
);
|
|
85
86
|
log.debug("OpenCode runtime ready", {
|
|
86
87
|
cacheDir,
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
opencodeConfigPath,
|
|
89
|
+
pluginCount: plugins.length
|
|
89
90
|
});
|
|
90
91
|
return cacheDir;
|
|
91
92
|
}
|
|
@@ -157,22 +158,21 @@ function resolveSourcePluginsDir() {
|
|
|
157
158
|
}
|
|
158
159
|
return candidatePaths[0];
|
|
159
160
|
}
|
|
160
|
-
function
|
|
161
|
-
const files = import_fs.default.readdirSync(sourceDir).filter((f) => f.endsWith(".js")
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
log.debug("All plugin files copied", { count: files.length, files });
|
|
161
|
+
function resolvePluginEntries(sourceDir) {
|
|
162
|
+
const files = import_fs.default.readdirSync(sourceDir).filter((f) => f.endsWith(".js"));
|
|
163
|
+
const entries = files.map((file) => {
|
|
164
|
+
const absolutePath = import_path.default.join(sourceDir, file);
|
|
165
|
+
return (0, import_url.pathToFileURL)(absolutePath).href;
|
|
166
|
+
});
|
|
167
|
+
log.debug("Resolved plugin entries", { count: entries.length, entries });
|
|
168
|
+
return entries;
|
|
169
169
|
}
|
|
170
170
|
function buildProcessEnv(stateDir, configDir, contextApiUrl, logsApiUrl, logFilesJson) {
|
|
171
171
|
const env = __spreadProps(__spreadValues({}, Object.fromEntries(
|
|
172
172
|
Object.entries(process.env).filter(([, v]) => v !== void 0)
|
|
173
173
|
)), {
|
|
174
174
|
XDG_STATE_HOME: stateDir,
|
|
175
|
-
// 指向缓存目录,OpenCode
|
|
175
|
+
// 指向缓存目录,OpenCode 通过 opencode.json 中 plugins 字段加载插件
|
|
176
176
|
OPENCODE_CONFIG_DIR: stateDir
|
|
177
177
|
});
|
|
178
178
|
if (configDir) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-opencode-assistant",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.23",
|
|
4
4
|
"description": "Embed OpenCode Web UI in your Vite dev server for real-time code modification and preview",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"unplugin-vue-inspector": "^3.0.0",
|
|
39
39
|
"execa": "^9.6.1",
|
|
40
|
-
"@vite-plugin-opencode-assistant/
|
|
41
|
-
"@vite-plugin-opencode-assistant/
|
|
42
|
-
"@vite-plugin-opencode-assistant/
|
|
40
|
+
"@vite-plugin-opencode-assistant/components": "1.1.23",
|
|
41
|
+
"@vite-plugin-opencode-assistant/opencode": "1.1.23",
|
|
42
|
+
"@vite-plugin-opencode-assistant/shared": "1.1.23"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"vite": ">=5.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@vite-plugin-opencode-assistant/client": "1.1.
|
|
48
|
+
"@vite-plugin-opencode-assistant/client": "1.1.23"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "pagoda-cli build && vite build -c vite.client.config.ts",
|