@ranger1/dx 0.1.113 → 0.1.114

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/README.md CHANGED
@@ -48,6 +48,7 @@ pnpm add -g @ranger1/dx@latest
48
48
 
49
49
  ```bash
50
50
  dx --help
51
+ dx --version
51
52
  dx status
52
53
  ```
53
54
 
@@ -202,6 +203,23 @@ dx 的命令由 `dx/config/commands.json` 驱动,并且内置了一些 interna
202
203
  - `internal: start-dev`:开发环境一键启动
203
204
  - `internal: pm2-stack`:PM2 交互式服务栈(支持端口清理/缓存清理配置)
204
205
 
206
+ 内置命令入口速览:
207
+
208
+ - `dx start [target]`:启动开发服务;未指定 target 时默认使用 `start.development`
209
+ - `dx build [target]`:按当前环境构建;未指定 target 时默认 `all`
210
+ - `dx test [unit|e2e] <target> [path...]`:运行测试;unit 自动使用 `--test` 环境,e2e 自动使用 `--e2e` 环境
211
+ - `dx db <generate|migrate|deploy|reset|seed|format|script>`:数据库相关命令;`migrate` 仅允许 `--dev`
212
+ - `dx deploy <target>`:部署目标;普通 Vercel target 默认 `--staging`,`backend-artifact-deploy` 默认 `--dev`
213
+ - `dx lint [--fix]`:运行 lint;`--fix` 会透传给下游 runner
214
+ - `dx install`:执行项目配置的安装命令
215
+ - `dx clean [target]` / `dx cache clear`:执行清理类命令,危险操作会要求确认
216
+ - `dx package backend [--skip-build]`:使用内置后端打包 runner
217
+ - `dx worktree <make|del|list|clean>`:管理 issue worktree;这是 dx 封装,不等同于原生 `git worktree`
218
+ - `dx export <target>`:执行配置化导出命令
219
+ - `dx contracts [generate|pull]`:导出 OpenAPI 并生成 `packages/api-contracts` 下的 Zod 合约(需要目标工程具备对应结构)
220
+ - `dx release version <version>`:同步更新常见 app 包版本号
221
+ - `dx initial`:同步包内 skills 到本机 agent 目录
222
+
205
223
  常用示例:
206
224
 
207
225
  ```bash
@@ -214,11 +232,25 @@ dx db migrate --dev --name init
214
232
  dx db deploy --prod -Y
215
233
  dx deploy front --staging
216
234
  dx deploy backend --prod
235
+ dx install
217
236
  dx lint
237
+ dx lint --fix
238
+ dx test unit backend apps/backend/src/modules/user/user.service.spec.ts
218
239
  dx test e2e backend apps/backend/e2e/auth
219
240
  dx test e2e quantify apps/quantify/e2e/health/health.e2e-spec.ts
241
+ dx db script fix-email-verified-status --dev -- --dry-run
242
+ dx package backend --prod --skip-build
243
+ dx worktree make 88 --base main
244
+ dx cache clear -Y
220
245
  ```
221
246
 
247
+ 测试命令默认并行度:
248
+
249
+ - `dx test unit ...` 会自动追加 `--maxWorkers=8`
250
+ - `dx test e2e ...` 会自动追加 `--workers=8`
251
+ - 如果命令配置或 `--` 透传参数里已经指定了对应 worker 参数,dx 不会重复追加;例如 `dx test e2e backend apps/backend/e2e/auth -- --workers=2`
252
+ - 如果 unit 命令或对应 `apps/<target>/package.json` 的 `scripts.test` 已使用 Jest `--runInBand`,dx 不会追加 `--maxWorkers=8`,避免触发 Jest 互斥参数错误
253
+
222
254
  关于 `dx initial`:
223
255
 
224
256
  - `dx initial` 会把 npm 包内置的 `skills/` 覆盖同步到 `~/.agents/skills`。
@@ -239,10 +271,15 @@ dx test e2e quantify apps/quantify/e2e/health/health.e2e-spec.ts
239
271
 
240
272
  - 对声明了 `requiresPath: true` 的 E2E target,`dx test e2e <target>` 必须提供文件或目录路径,禁止无路径或 `all` 全量执行
241
273
  - `dx test e2e all` 不受支持,必须显式指定 target 和路径
274
+ - `dx test unit ...` 默认使用 8 个 worker;`dx test e2e ...` 默认使用 8 个 worker;可通过 `--` 透传参数覆盖;unit 检测到 Jest `--runInBand` 时不会追加 `--maxWorkers`
275
+ - `dx db migrate --dev` 必须通过 `--name` 或 `-n` 指定迁移名,禁止依赖 Prisma 交互式输入
242
276
  - `dx db migrate` 仅允许在 `--dev` 环境创建迁移;非开发环境请使用 `dx db deploy`
277
+ - `dx db generate/migrate/deploy/reset/seed/script` 会禁用 Nx 缓存,避免命中缓存后未实际执行
278
+ - `dx deploy` 仅支持 `--dev`、`--staging`、`--prod`,不支持 `--test` / `--e2e`
243
279
  - `dx start` 未指定服务时默认是开发套件,仅允许 `--dev`
244
280
  - `dx start` 下的单层目标(如 `stagewise-front`)默认仅支持 `--dev`
245
281
  - `dx build` 显式传入环境标志时,必须是该 target 实际支持的环境
282
+ - `dx worktree` 是 dx 的 issue worktree 封装,与原生 `git worktree` 行为不同,不要混用
246
283
 
247
284
  ### `dx start stack` 配置详解(PM2 交互式服务栈)
248
285
 
@@ -181,7 +181,7 @@ export async function handleTest(cli, args) {
181
181
 
182
182
  testConfig = {
183
183
  ...testConfig,
184
- command: appendDefaultTestWorkers(testConfig.command, type),
184
+ command: appendDefaultTestWorkers(cli, testConfig.command, type),
185
185
  }
186
186
 
187
187
  await cli.executeCommand(testConfig)
@@ -215,12 +215,13 @@ function shouldUseDirectPathArg(command) {
215
215
  )
216
216
  }
217
217
 
218
- function appendDefaultTestWorkers(command, type) {
218
+ function appendDefaultTestWorkers(cli, command, type) {
219
219
  const flag = getDefaultWorkerFlag(type)
220
220
  if (!flag) return command
221
221
 
222
222
  const text = String(command || '').trim()
223
223
  if (!text || hasWorkerFlag(text, flag)) return command
224
+ if (type === 'unit' && commandUsesRunInBand(cli, text)) return command
224
225
 
225
226
  if (isNodeEvalCommandWithoutArgSeparator(text)) {
226
227
  return `${text} -- ${flag}=${DEFAULT_TEST_WORKERS}`
@@ -240,6 +241,33 @@ function hasWorkerFlag(command, flag) {
240
241
  return new RegExp(`(^|[\\s'"])${escapedFlag}(=|\\s|['"]|$)`).test(String(command || ''))
241
242
  }
242
243
 
244
+ function hasRunInBandFlag(command) {
245
+ return /(^|[\s'"])(--runInBand|--run-in-band|-i)(=|\s|['"]|$)/.test(String(command || ''))
246
+ }
247
+
248
+ function commandUsesRunInBand(cli, command) {
249
+ if (hasRunInBandFlag(command)) return true
250
+
251
+ const script = resolveNxUnitPackageTestScript(cli, command)
252
+ return hasRunInBandFlag(script)
253
+ }
254
+
255
+ function resolveNxUnitPackageTestScript(cli, command) {
256
+ const projectRoot = cli?.projectRoot || process.cwd()
257
+ const nxResolution = extractNxTarget(command, ['test'])
258
+ if (!nxResolution?.project) return null
259
+
260
+ const packagePath = join(projectRoot, 'apps', nxResolution.project, 'package.json')
261
+ if (!existsSync(packagePath)) return null
262
+
263
+ try {
264
+ const pkg = JSON.parse(readFileSync(packagePath, 'utf8'))
265
+ return typeof pkg?.scripts?.test === 'string' ? pkg.scripts.test : null
266
+ } catch {
267
+ return null
268
+ }
269
+ }
270
+
243
271
  function isNodeEvalCommandWithoutArgSeparator(command) {
244
272
  return /(^|\s)node\s+-e\s/.test(String(command || '')) && !/\s--(\s|$)/.test(String(command || ''))
245
273
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.113",
3
+ "version": "0.1.114",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {