Skip to content

Commit 4f71c05

Browse files
authored
Merge pull request #192 from hqwlkj/main
build(cli): 重构构建流程并内联核心及依赖
2 parents 91e7524 + f291919 commit 4f71c05

14 files changed

Lines changed: 617 additions & 116 deletions

.deepcode/AGENTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ dist/ # Bundled CLI output (gitignored)
6868
| `npm run format` | Prettier on all `src/**/*.{ts,tsx}` |
6969
| `npm run format:check` | Prettier in check-only mode |
7070
| `npm run check` | Runs typecheck + lint + format:check together |
71-
| `npm run bundle` | esbuild bundles `src/cli.tsx` `dist/cli.js` (ESM, Node 18) |
72-
| `npm run build` | `check` + `bundle` + chmod 755 — full CI gate before publish |
71+
| `npm run bundle` | esbuild bundles cli + core + all deps `dist/cli.js` (ESM, Node 22) |
72+
| `npm run build` | build core (tsc) + rewrite ESM imports + bundle CLI (esbuild) |
7373
| `npm test` | Runs all tests via `node src/tests/run-tests.mjs` |
7474
| `npm run test:single -- <file>` | Run a single test file via `tsx --test` (e.g., `npm run test:single -- src/tests/session.test.ts`) |
7575

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# VS Code Marketplace publish token
2+
# Generate at: https://dev.azure.com/vegamo/_usersSettings/tokens
3+
# Permission required: Marketplace → Publish
4+
VSCE_PAT=

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ out/
2020
# TypeScript build info files
2121
*.tsbuildinfo
2222

23+
# Environment variables
24+
.env
25+
.env.local
26+
2327
# Generated files
2428
packages/cli/src/generated/
2529
packages/core/src/generated/

RELEASE.md

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# 版本发布
22

3-
Deep Code 使用两个脚本管理 monorepo 的版本发布流程:
3+
Deep Code 使用三个脚本管理 monorepo 的版本发布流程:
44

55
| 脚本 | 命令 | 用途 |
66
|------|------|------|
77
| `scripts/version.js` | `npm run release:version` | 升级所有 workspace 包的版本号 + 重新生成 lockfile |
8-
| `scripts/prepare-package.js` | `npm run prepare:package` | 构建 + 质量检查 + 发布到 npm + git commit & tag |
8+
| `scripts/prepare-package.js` | `npm run prepare:package` | 构建 CLI + 质量检查 + 发布到 npm + git commit & tag |
9+
| `scripts/prepare-vscode.js` | `npm run prepare:vscode` | 构建 VSCode 扩展 + 质量检查 + 发布到 VS Code 市场 + git commit & tag |
910

10-
两者配合使用,先升版本号,再发布
11+
发布流程:先升版本号,再分别发布 CLI 和 VSCode 扩展
1112

1213
---
1314

@@ -105,7 +106,7 @@ git tag v0.1.32
105106

106107
## prepare:package — 构建并发布到 npm
107108

108-
完成质量检查、构建、发布两个 npm 包,并自动创建 git commit 和 tag。
109+
完成质量检查、构建、发布 CLI 到 npm,并自动创建 git commit 和 tag。
109110

110111
### 基本用法
111112

@@ -122,7 +123,7 @@ npm run prepare:package -- <version> [options]
122123
| `--dry-run` | 预演模式,不实际执行任何写操作 |
123124
| `--force` | 跳过 main 分支检查,允许从其他分支发布 |
124125

125-
### 执行流程(9 步)
126+
### 执行流程(8 步)
126127

127128
| 步骤 | 操作 | 说明 |
128129
|------|------|------|
@@ -131,10 +132,9 @@ npm run prepare:package -- <version> [options]
131132
| 3 | 更新版本号 | 同时更新 `packages/core``packages/cli` 的 version |
132133
| 4 | 质量检查 | `npm run check`(typecheck + eslint + prettier) |
133134
| 5 | 测试 | `npm run test --workspaces` |
134-
| 6 | 构建 | `npm run build`(core tsc + cli esbuild bundle) |
135-
| 7 | 发布 core | `npm publish --workspace=@vegamo/deepcode-core --access public` |
136-
| 8 | 发布 cli | 将 cli 的 `@vegamo/deepcode-core` 依赖从 `file:../core` 临时改为 `^<version>`,发布后恢复 |
137-
| 9 | Git commit & tag | `chore(release): v<version>` + `git tag v<version>` |
135+
| 6 | 构建 | `npm run build`(core tsc + esbuild 将 core 及所有依赖内联到 `dist/cli.js`|
136+
| 7 | 发布 CLI |`dist/` 写入 `dependencies: {}` 的 package.json,从 `dist/` 目录执行 `npm publish` |
137+
| 8 | Git commit & tag | `chore(release): v<version>` + `git tag v<version>` |
138138

139139
### 完整示例
140140

@@ -152,9 +152,9 @@ npm run prepare:package -- 0.1.32 --dry-run
152152
npm run prepare:package -- 0.1.32 --force
153153
```
154154

155-
### 关于 file:../core 依赖
155+
### 关于 Core 打包策略
156156

157-
CLI 包的 `@vegamo/deepcode-core` 依赖在开发时使用 `"file:../core"`monorepo 本地链接)。发布到 npm 时,脚本会自动将其替换为 `"^<version>"`,发布完成后恢复为 `file:../core`。这个过程对用户透明,无需手动处理
157+
CLI `package.json` 中保留 `"@vegamo/deepcode-core": "file:../core"` 用于本地开发(IDE 类型检查、monorepo 工作区解析)。构建时 esbuild 使用 `packages: "bundle"` 将 core 的全部代码及其运行时依赖(`openai``ejs``zod` 等)内联到单个 `dist/cli.js` 文件中。发布时脚本往 `dist/` 写入 `dependencies: {}``package.json`,从 `dist/` 目录发布,因此发布的 CLI 包零运行时依赖。`@vegamo/deepcode-core` 不再作为独立 npm 包发布
158158

159159
### 发布后
160160

@@ -173,6 +173,58 @@ npx @vegamo/deepcode-cli --version
173173

174174
---
175175

176+
## prepare:vscode — 构建并发布 VSCode 扩展到市场
177+
178+
完成质量检查、构建、发布 VSCode 扩展到 VS Code Marketplace,并自动创建 git commit 和 tag。
179+
180+
### 前置条件
181+
182+
需要 Azure DevOps Personal Access Token(PAT)用于市场认证:
183+
184+
1. 访问 https://dev.azure.com/vegamo/_usersSettings/tokens 生成 token
185+
2. 设置环境变量 `VSCE_PAT=<token>`
186+
187+
### 基本用法
188+
189+
```bash
190+
VSCE_PAT=<token> npm run prepare:vscode -- <version> [options]
191+
```
192+
193+
### 参数
194+
195+
| 参数 | 说明 |
196+
|------|------|
197+
| `<version>` | **必填**,要发布的 semver 版本号 |
198+
| `--dry-run` | 预演模式,不实际执行任何写操作 |
199+
| `--force` | 跳过 main 分支检查,允许从其他分支发布 |
200+
201+
### 执行流程(7 步)
202+
203+
| 步骤 | 操作 | 说明 |
204+
|------|------|------|
205+
| 1 | Git 检查 | 工作区必须 clean,必须在 main 分支 |
206+
| 2 | VSCE_PAT 检查 | 环境变量必须已设置 |
207+
| 3 | 更新版本号 | 同时更新 `packages/core``packages/cli``packages/vscode-ide-companion` 的 version |
208+
| 4 | 质量检查 | `npm run check`(typecheck + eslint + prettier) |
209+
| 5 | 测试 | `npm run test --workspaces` |
210+
| 6 | 构建 | `npm run build:vscode`(core tsc + esbuild 打包扩展 + 拷贝模板 + vsce package) |
211+
| 7 | 发布 | `vsce publish <version> --no-dependencies` 发布到 VS Code Marketplace |
212+
213+
### 完整示例
214+
215+
```bash
216+
# 发布正式版
217+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32
218+
219+
# 发布预发布版
220+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32-beta.1
221+
222+
# 预演(不实际发布)
223+
npm run prepare:vscode -- 0.1.32 --dry-run
224+
```
225+
226+
---
227+
176228
## 典型发布流程
177229

178230
一个完整的版本发布通常按以下步骤进行:
@@ -191,18 +243,22 @@ git diff
191243
git add -A
192244
git commit -m "chore(release): v0.1.32"
193245

194-
# 5. 构建 + 质量检查 + 发布
246+
# 5. 构建 + 质量检查 + 发布 CLI
195247
npm run prepare:package -- 0.1.32
196248

197-
# 6. 推送到 remote
249+
# 6. 发布 VSCode 扩展
250+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32
251+
252+
# 7. 推送到 remote
198253
git push && git push --tags
199254
```
200255

201-
也可以简化为两步`prepare:package` 会自动 commit 和 tag):
256+
也可以简化为三步`prepare:package` `prepare:vscode` 各自自动 commit 和 tag):
202257

203258
```bash
204259
npm run release:version -- patch
205260
npm run prepare:package -- 0.1.32
261+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32
206262
git push && git push --tags
207263
```
208264

RELEASE_en.md

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Release
22

3-
Deep Code uses two scripts to manage version releases in the monorepo:
3+
Deep Code uses three scripts to manage version releases in the monorepo:
44

55
| Script | Command | Purpose |
66
|--------|---------|---------|
77
| `scripts/version.js` | `npm run release:version` | Bump all workspace package versions + regenerate lockfile |
8-
| `scripts/prepare-package.js` | `npm run prepare:package` | Build + quality checks + publish to npm + git commit & tag |
8+
| `scripts/prepare-package.js` | `npm run prepare:package` | Build CLI + quality checks + publish to npm + git commit & tag |
9+
| `scripts/prepare-vscode.js` | `npm run prepare:vscode` | Build VSCode extension + quality checks + publish to VS Code Marketplace + git commit & tag |
910

10-
Use them together: bump version first, then publish.
11+
Release flow: bump version first, then publish CLI and VSCode extension separately.
1112

1213
---
1314

@@ -105,7 +106,7 @@ git tag v0.1.32
105106

106107
## prepare:package — Build and Publish to npm
107108

108-
Runs quality checks, builds, publishes both npm packages, and automatically creates a git commit with tag.
109+
Runs quality checks, builds, publishes the CLI to npm, and automatically creates a git commit with tag.
109110

110111
### Basic Usage
111112

@@ -122,7 +123,7 @@ npm run prepare:package -- <version> [options]
122123
| `--dry-run` | Preview mode, no actual writes |
123124
| `--force` | Skip main branch check, allow publishing from other branches |
124125

125-
### Execution Flow (9 Steps)
126+
### Execution Flow (8 Steps)
126127

127128
| Step | Action | Description |
128129
|------|--------|-------------|
@@ -131,10 +132,9 @@ npm run prepare:package -- <version> [options]
131132
| 3 | Update versions | Updates `packages/core` and `packages/cli` version fields |
132133
| 4 | Quality checks | `npm run check` (typecheck + eslint + prettier) |
133134
| 5 | Tests | `npm run test --workspaces` |
134-
| 6 | Build | `npm run build` (core tsc + cli esbuild bundle) |
135-
| 7 | Publish core | `npm publish --workspace=@vegamo/deepcode-core --access public` |
136-
| 8 | Publish cli | Temporarily changes cli's `@vegamo/deepcode-core` dep from `file:../core` to `^<version>`, restores after publish |
137-
| 9 | Git commit & tag | `chore(release): v<version>` + `git tag v<version>` |
135+
| 6 | Build | `npm run build` (core tsc + esbuild inlines core and all deps into `dist/cli.js`) |
136+
| 7 | Publish CLI | Writes `dist/package.json` with `dependencies: {}`, runs `npm publish` from `dist/` |
137+
| 8 | Git commit & tag | `chore(release): v<version>` + `git tag v<version>` |
138138

139139
### Examples
140140

@@ -152,9 +152,9 @@ npm run prepare:package -- 0.1.32 --dry-run
152152
npm run prepare:package -- 0.1.32 --force
153153
```
154154

155-
### About the file:../core Dependency
155+
### About the Core Bundling Strategy
156156

157-
The CLI package uses `"file:../core"` for the `@vegamo/deepcode-core` dependency during development (monorepo local link). When publishing to npm, the script automatically replaces it with `"^<version>"` and restores it after publishing. This is transparent — no manual handling required.
157+
The CLI's `package.json` keeps `"@vegamo/deepcode-core": "file:../core"` for local development (IDE type checking, monorepo workspace resolution). At build time, esbuild uses `packages: "bundle"` to inline all of core's code and its runtime dependencies (`openai`, `ejs`, `zod`, etc.) into a single `dist/cli.js` file. At publish time, the script writes a `dist/package.json` with `dependencies: {}` and publishes from the `dist/` directory, so the published CLI package has zero runtime dependencies. `@vegamo/deepcode-core` is no longer published as a separate npm package.
158158

159159
### After Publishing
160160

@@ -173,6 +173,58 @@ npx @vegamo/deepcode-cli --version
173173

174174
---
175175

176+
## prepare:vscode — Build and Publish VSCode Extension to Marketplace
177+
178+
Runs quality checks, builds, publishes the VSCode extension to the VS Code Marketplace, and automatically creates a git commit with tag.
179+
180+
### Prerequisites
181+
182+
Requires an Azure DevOps Personal Access Token (PAT) for marketplace authentication:
183+
184+
1. Generate a token at https://dev.azure.com/vegamo/_usersSettings/tokens
185+
2. Set the environment variable `VSCE_PAT=<token>`
186+
187+
### Basic Usage
188+
189+
```bash
190+
VSCE_PAT=<token> npm run prepare:vscode -- <version> [options]
191+
```
192+
193+
### Arguments
194+
195+
| Argument | Description |
196+
|----------|-------------|
197+
| `<version>` | **Required**. Semver version to publish |
198+
| `--dry-run` | Preview mode, no actual writes |
199+
| `--force` | Skip main branch check, allow publishing from other branches |
200+
201+
### Execution Flow (7 Steps)
202+
203+
| Step | Action | Description |
204+
|------|--------|-------------|
205+
| 1 | Git check | Working tree must be clean, must be on main branch |
206+
| 2 | VSCE_PAT check | Environment variable must be set |
207+
| 3 | Update versions | Updates `packages/core`, `packages/cli`, and `packages/vscode-ide-companion` version fields |
208+
| 4 | Quality checks | `npm run check` (typecheck + eslint + prettier) |
209+
| 5 | Tests | `npm run test --workspaces` |
210+
| 6 | Build | `npm run build:vscode` (core tsc + esbuild bundle extension + copy templates + vsce package) |
211+
| 7 | Publish | `vsce publish <version> --no-dependencies` to VS Code Marketplace |
212+
213+
### Examples
214+
215+
```bash
216+
# Publish stable release
217+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32
218+
219+
# Publish pre-release
220+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32-beta.1
221+
222+
# Dry run (no actual publish)
223+
npm run prepare:vscode -- 0.1.32 --dry-run
224+
```
225+
226+
---
227+
176228
## Typical Release Flow
177229

178230
A complete version release follows these steps:
@@ -191,18 +243,22 @@ git diff
191243
git add -A
192244
git commit -m "chore(release): v0.1.32"
193245

194-
# 5. Build + quality check + publish
246+
# 5. Build + quality check + publish CLI
195247
npm run prepare:package -- 0.1.32
196248

197-
# 6. Push to remote
249+
# 6. Publish VSCode extension
250+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32
251+
252+
# 7. Push to remote
198253
git push && git push --tags
199254
```
200255

201-
Or simplified to two steps (`prepare:package` auto-commits and tags):
256+
Or simplified to three steps (`prepare:package` and `prepare:vscode` each auto-commit and tag):
202257

203258
```bash
204259
npm run release:version -- patch
205260
npm run prepare:package -- 0.1.32
261+
VSCE_PAT=xxx npm run prepare:vscode -- 0.1.32
206262
git push && git push --tags
207263
```
208264

package-lock.json

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)