@spaceflow/core 0.2.0 → 0.4.0

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.
@@ -318,6 +318,20 @@ export interface Issue {
318
318
  /** PR Review 事件类型 */
319
319
  export type ReviewStateType = "APPROVE" | "REQUEST_CHANGES" | "COMMENT" | "PENDING";
320
320
 
321
+ /** PR Review 事件常量 */
322
+ export const REVIEW_STATE = {
323
+ APPROVE: "APPROVE",
324
+ REQUEST_CHANGES: "REQUEST_CHANGES",
325
+ COMMENT: "COMMENT",
326
+ PENDING: "PENDING",
327
+ } as const;
328
+
329
+ /** PR Review 行级评论 Diff 方向 */
330
+ export const DIFF_SIDE = {
331
+ RIGHT: "RIGHT",
332
+ LEFT: "LEFT",
333
+ } as const;
334
+
321
335
  /** PR Review 行级评论 */
322
336
  export interface CreatePullReviewComment {
323
337
  /** 文件路径 */
@@ -381,6 +395,19 @@ export interface PullReviewComment {
381
395
  html_url?: string;
382
396
  }
383
397
 
398
+ /** PR Review Thread 已解决信息 */
399
+ export interface ResolvedThread {
400
+ /** 文件路径 */
401
+ path?: string;
402
+ /** 行号(新文件中的行号) */
403
+ line?: number;
404
+ /** 解决者 */
405
+ resolvedBy?: {
406
+ id?: number;
407
+ login?: string;
408
+ } | null;
409
+ }
410
+
384
411
  /** 用户信息 */
385
412
  export interface User {
386
413
  id?: number;
@@ -22,6 +22,7 @@ export function isGitUrl(source: string): boolean {
22
22
  */
23
23
  export function isLocalPath(source: string): boolean {
24
24
  return (
25
+ source.startsWith("workspace:") ||
25
26
  source.startsWith("link:") ||
26
27
  source.startsWith("./") ||
27
28
  source.startsWith("../") ||
@@ -2,7 +2,6 @@ import { existsSync, readFileSync, mkdirSync, writeFileSync } from "fs";
2
2
  import { join } from "path";
3
3
  import { homedir } from "os";
4
4
  import { SPACEFLOW_DIR, PACKAGE_JSON } from "../../extension-system/extension.interface";
5
- import { isPnpmWorkspace } from "../package-manager";
6
5
 
7
6
  /**
8
7
  * 获取 .spaceflow 目录路径
@@ -36,86 +35,65 @@ config-schema.json
36
35
  writeFileSync(gitignorePath, gitignoreContent);
37
36
  }
38
37
 
39
- // 创建空的 pnpm-workspace.yaml,防止被父级 workspace 接管
40
- const workspaceYamlPath = join(spaceflowDir, "pnpm-workspace.yaml");
41
- if (!existsSync(workspaceYamlPath)) {
42
- writeFileSync(workspaceYamlPath, "packages: []\n");
43
- }
44
38
  }
45
39
 
46
40
  /**
47
- * 获取 @spaceflow/cli 的路径
48
- * @param isGlobal 是否为全局安装
49
- * @param cwd 工作目录,默认为 process.cwd()
41
+ * 获取 @spaceflow/core 的版本号
42
+ * 从 process.argv[1](cli 入口)向上找到 @spaceflow/cli package.json
43
+ * 读取其中声明的 @spaceflow/core 依赖版本,保证 cli 和 core 版本一致
50
44
  */
51
- export function getSpaceflowCliPath(isGlobal: boolean = false, cwd?: string): string {
52
- const workDir = cwd || process.cwd();
53
-
54
- if (isGlobal) {
55
- // 全局安装:尝试找到 @spaceflow/cli 的实际路径进行 link
56
- // 优先从当前项目的 cli 目录 link
57
- const cliPath = join(workDir, "packages", "cli");
58
- if (existsSync(join(cliPath, PACKAGE_JSON))) {
45
+ export function getSpaceflowCoreVersion(): string {
46
+ const cliEntryPath = process.argv[1];
47
+ if (cliEntryPath) {
48
+ // cli 入口: .../node_modules/@spaceflow/cli/dist/cli.js → 往上两级是包根目录
49
+ const cliDir = join(cliEntryPath, "..", "..");
50
+ const cliPkgPath = join(cliDir, PACKAGE_JSON);
51
+ if (existsSync(cliPkgPath)) {
59
52
  try {
60
- const content = readFileSync(join(cliPath, PACKAGE_JSON), "utf-8");
61
- const pkg = JSON.parse(content);
62
- if (pkg.name === "@spaceflow/cli") {
63
- return `link:${cliPath}`;
53
+ const cliPkg = JSON.parse(readFileSync(cliPkgPath, "utf-8"));
54
+ if (cliPkg.name === "@spaceflow/cli") {
55
+ const coreVersion = cliPkg.dependencies?.["@spaceflow/core"];
56
+ if (coreVersion) {
57
+ return coreVersion;
58
+ }
64
59
  }
65
60
  } catch {
66
61
  // ignore
67
62
  }
68
63
  }
69
- // 回退到 latest
70
- return "latest";
71
- }
72
-
73
- // 本地安装:检查是否在 monorepo 中
74
- if (isPnpmWorkspace(workDir)) {
75
- return "workspace:*";
76
64
  }
77
-
78
- // 尝试从项目 package.json 获取版本
79
- const projectPkgPath = join(workDir, PACKAGE_JSON);
80
- if (existsSync(projectPkgPath)) {
81
- try {
82
- const content = readFileSync(projectPkgPath, "utf-8");
83
- const pkg = JSON.parse(content);
84
- const version =
85
- pkg.dependencies?.["@spaceflow/core"] || pkg.devDependencies?.["@spaceflow/core"];
86
- if (version) return version;
87
- } catch {
88
- // ignore
89
- }
90
- }
91
-
92
65
  return "latest";
93
66
  }
94
67
 
95
68
  /**
96
- * 确保 .spaceflow/package.json 存在
97
- * 包含 @spaceflow/cli 作为依赖
69
+ * 确保 .spaceflow 目录及 package.json 存在,并保持 @spaceflow/core 版本与 cli 一致
98
70
  * @param spaceflowDir .spaceflow 目录路径
99
- * @param isGlobal 是否为全局安装
100
- * @param cwd 工作目录,默认为 process.cwd()
101
71
  */
102
- export function ensureSpaceflowPackageJson(
103
- spaceflowDir: string,
104
- isGlobal: boolean = false,
105
- cwd?: string,
106
- ): void {
107
- // 确保目录存在
72
+ export function ensureSpaceflowPackageJson(spaceflowDir: string): void {
108
73
  ensureSpaceflowDir(spaceflowDir);
109
74
 
110
- // 确保 package.json 存在
111
75
  const packageJsonPath = join(spaceflowDir, PACKAGE_JSON);
112
- if (!existsSync(packageJsonPath)) {
113
- const cliPath = getSpaceflowCliPath(isGlobal, cwd);
76
+ const coreVersion = getSpaceflowCoreVersion();
77
+
78
+ if (existsSync(packageJsonPath)) {
79
+ // 已存在:检查并更新 @spaceflow/core 版本
80
+ try {
81
+ const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
82
+ if (pkg.dependencies?.["@spaceflow/core"] !== coreVersion) {
83
+ pkg.dependencies = pkg.dependencies || {};
84
+ pkg.dependencies["@spaceflow/core"] = coreVersion;
85
+ writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2) + "\n");
86
+ }
87
+ } catch {
88
+ // ignore
89
+ }
90
+ } else {
91
+ // 不存在:创建
114
92
  const packageJson = {
115
93
  name: "spaceflow",
116
94
  private: true,
117
95
  dependencies: {
118
- "@spaceflow/core": cliPath,
96
+ "@spaceflow/core": coreVersion,
119
97
  },
120
98
  };
121
99
  writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");