vite-plugin-aipanel 1.3.7 → 1.3.9

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.
@@ -23,8 +23,14 @@ module.exports = __toCommonJS(context_exports);
23
23
  var import_core = require("@aipanel/core");
24
24
  var import_node = require("@aipanel/core/node");
25
25
  var import_core2 = require("@aipanel/core");
26
+ var import_source_path = require("../utils/source-path.cjs");
26
27
  const log = (0, import_node.createLogger)("Endpoints:Context");
27
28
  function setupContextEndpoint(server, ctx) {
29
+ const sourcePathBases = {
30
+ cwd: process.cwd(),
31
+ root: server.config.root,
32
+ gitRoot: (0, import_source_path.findGitRoot)(server.config.root)
33
+ };
28
34
  server.middlewares.use(import_core.CONTEXT_API_PATH, async (req, res) => {
29
35
  const reqCtx = new import_node.RequestContext(req.method || "GET", import_core.CONTEXT_API_PATH);
30
36
  res.setHeader("Content-Type", "application/json");
@@ -81,7 +87,9 @@ function setupContextEndpoint(server, ctx) {
81
87
  const existing = ctx.getPageContext();
82
88
  const selectedElements = data.selectedElements || [];
83
89
  selectedElements.forEach((el) => {
84
- if (el && typeof el === "object") (0, import_core2.ensureNodeId)(el);
90
+ if (!el || typeof el !== "object") return;
91
+ if (el.filePath) el.filePath = (0, import_source_path.resolveSourceFilePath)(el.filePath, sourcePathBases);
92
+ (0, import_core2.ensureNodeId)(el);
85
93
  });
86
94
  const newCtx = {
87
95
  url: data.url || "",
@@ -0,0 +1,63 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var source_path_exports = {};
29
+ __export(source_path_exports, {
30
+ findGitRoot: () => findGitRoot,
31
+ resolveSourceFilePath: () => resolveSourceFilePath
32
+ });
33
+ module.exports = __toCommonJS(source_path_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_path = __toESM(require("path"));
36
+ const GIT_ROOT_MAX_DEPTH = 32;
37
+ function resolveSourceFilePath(raw, bases) {
38
+ if (!raw || import_path.default.isAbsolute(raw)) return raw;
39
+ const exists = bases.exists ?? import_fs.default.existsSync;
40
+ const candidates = [bases.cwd, bases.root, bases.gitRoot].filter(
41
+ (base) => Boolean(base)
42
+ );
43
+ for (const base of candidates) {
44
+ const candidate = import_path.default.resolve(base, raw);
45
+ if (exists(candidate)) return candidate;
46
+ }
47
+ return import_path.default.resolve(bases.cwd, raw);
48
+ }
49
+ function findGitRoot(startDir, exists = import_fs.default.existsSync) {
50
+ let current = import_path.default.resolve(startDir);
51
+ for (let depth = 0; depth < GIT_ROOT_MAX_DEPTH; depth += 1) {
52
+ if (exists(import_path.default.join(current, ".git"))) return current;
53
+ const parent = import_path.default.dirname(current);
54
+ if (parent === current) return null;
55
+ current = parent;
56
+ }
57
+ return null;
58
+ }
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ findGitRoot,
62
+ resolveSourceFilePath
63
+ });
@@ -0,0 +1,30 @@
1
+ /** 归一化所需的宿主基准与探测函数(全部可注入,便于单测脱离真实文件系统) */
2
+ export interface SourcePathBases {
3
+ /** Vite 进程工作目录(unplugin-vue-inspector 标记的基准) */
4
+ cwd: string;
5
+ /** Vite root(`server.config.root`,react-dev-inspector 兼容属性的基准) */
6
+ root: string;
7
+ /** git 仓库根(code-inspector `pathType: "relative"` 的基准);未找到为 null */
8
+ gitRoot?: string | null;
9
+ /** 文件存在性探测(默认 fs.existsSync) */
10
+ exists?: (candidate: string) => boolean;
11
+ }
12
+ /**
13
+ * 把浏览器上报的源码路径归一化为绝对路径。
14
+ *
15
+ * 绝对路径原样返回(幂等);相对路径按 `cwd → root → gitRoot` 顺序取第一个真实存在的候选,
16
+ * 都不存在时回退到 cwd 基准——输出的契约是「恒为绝对路径」,不回退成相对值(相对值的基准对
17
+ * 消费方不可知,只会把问题推给下游)。
18
+ *
19
+ * @param raw - 浏览器上报的路径
20
+ * @param bases - 宿主基准与探测函数
21
+ * @returns 绝对路径
22
+ */
23
+ export declare function resolveSourceFilePath(raw: string, bases: SourcePathBases): string;
24
+ /**
25
+ * 自 `startDir` 向上查找 git 仓库根(纯 fs 探测,不 spawn git)。
26
+ * @param startDir - 起始目录
27
+ * @param exists - 文件存在性探测(默认 fs.existsSync)
28
+ * @returns 仓库根绝对路径;未找到返回 null
29
+ */
30
+ export declare function findGitRoot(startDir: string, exists?: (candidate: string) => boolean): string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-aipanel",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
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",
@@ -35,8 +35,8 @@
35
35
  "author": "",
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@aipanel/core": "1.3.7",
39
- "@aipanel/provider-opencode": "1.3.7",
38
+ "@aipanel/core": "1.3.9",
39
+ "@aipanel/provider-opencode": "1.3.9",
40
40
  "@code-inspector/core": "^2.0.9",
41
41
  "@vue/devtools-kit": "^8.0.0",
42
42
  "@vue/language-server": "^3.3.7",
@@ -47,7 +47,7 @@
47
47
  "unplugin-vue-inspector": "^3.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@aipanel/provider-deepseek": "1.3.7",
50
+ "@aipanel/provider-deepseek": "1.3.9",
51
51
  "vite": ">=5.0.0"
52
52
  },
53
53
  "peerDependenciesMeta": {
@@ -56,7 +56,7 @@
56
56
  }
57
57
  },
58
58
  "devDependencies": {
59
- "@aipanel/client": "1.3.7",
59
+ "@aipanel/client": "1.3.9",
60
60
  "@types/picomatch": "^4.0.0",
61
61
  "sharp": "^0.34.5"
62
62
  },