@ranger1/dx 0.1.101 → 0.1.103
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/lib/cli/dx-cli.js +7 -2
- package/lib/cli/nx-command.js +13 -0
- package/lib/exec.js +12 -0
- package/lib/nx-ignore.js +45 -0
- package/package.json +1 -1
package/lib/cli/dx-cli.js
CHANGED
|
@@ -14,6 +14,7 @@ import { FLAG_DEFINITIONS, parseFlags } from './flags.js'
|
|
|
14
14
|
import { getCleanArgs, getCleanArgsWithConsumedValues } from './args.js'
|
|
15
15
|
import { showHelp, showCommandHelp } from './help.js'
|
|
16
16
|
import { buildStrictHelpValidationContext, validateHelpConfig } from './help-schema.js'
|
|
17
|
+
import { appendNxVerboseFlag } from './nx-command.js'
|
|
17
18
|
import { getPackageVersion } from '../version.js'
|
|
18
19
|
import {
|
|
19
20
|
handleHelp,
|
|
@@ -900,11 +901,15 @@ class DxCli {
|
|
|
900
901
|
return
|
|
901
902
|
}
|
|
902
903
|
|
|
903
|
-
const
|
|
904
|
+
const effectiveFlags = overrideFlags || this.flags
|
|
905
|
+
let rawCommand = String(config.command).trim()
|
|
906
|
+
if (effectiveFlags.verbose) {
|
|
907
|
+
rawCommand = appendNxVerboseFlag(rawCommand)
|
|
908
|
+
}
|
|
904
909
|
|
|
905
910
|
const options = {
|
|
906
911
|
app: config.app,
|
|
907
|
-
flags:
|
|
912
|
+
flags: effectiveFlags,
|
|
908
913
|
ports: config.ports || [],
|
|
909
914
|
// 允许上游在 config.env 中注入环境变量(例如 NX_CACHE=false)
|
|
910
915
|
env: config.env || {},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function appendNxVerboseFlag(command) {
|
|
2
|
+
const text = String(command || '').trim()
|
|
3
|
+
if (!text) return text
|
|
4
|
+
if (!/\bnx(?:\.js)?\b/.test(text)) return text
|
|
5
|
+
if (/(?:^|\s)--verbose(?:\s|$)/.test(text)) return text
|
|
6
|
+
|
|
7
|
+
const passthroughIndex = text.indexOf(' -- ')
|
|
8
|
+
if (passthroughIndex === -1) {
|
|
9
|
+
return `${text} --verbose`
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return `${text.slice(0, passthroughIndex)} --verbose${text.slice(passthroughIndex)}`
|
|
13
|
+
}
|
package/lib/exec.js
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
resolveTargetRequiredVars,
|
|
10
10
|
} from './env-policy.js'
|
|
11
11
|
import { confirmManager } from './confirm.js'
|
|
12
|
+
import { ensureNxIgnoreToolDirs, isNxCommand } from './nx-ignore.js'
|
|
12
13
|
|
|
13
14
|
const execPromise = promisify(nodeExec)
|
|
14
15
|
|
|
@@ -171,6 +172,17 @@ export class ExecManager {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
if (isNxCommand(fullCommand)) {
|
|
176
|
+
try {
|
|
177
|
+
const result = ensureNxIgnoreToolDirs(cwd || process.cwd())
|
|
178
|
+
if (result.changed) {
|
|
179
|
+
logger.info(`已更新 .nxignore,排除工具元数据目录: ${result.added.join(', ')}`)
|
|
180
|
+
}
|
|
181
|
+
} catch (error) {
|
|
182
|
+
logger.warn(`自动更新 .nxignore 失败: ${error?.message || String(error)}`)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
174
186
|
logger.command(fullCommand)
|
|
175
187
|
|
|
176
188
|
// 执行命令(可能重试)
|
package/lib/nx-ignore.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
export const NX_IGNORE_TOOL_DIR_PATTERNS = [
|
|
5
|
+
'.cache/',
|
|
6
|
+
'.claude/',
|
|
7
|
+
'.codex/',
|
|
8
|
+
'.idea/',
|
|
9
|
+
'.omc/',
|
|
10
|
+
'.omx/',
|
|
11
|
+
'.opencode/',
|
|
12
|
+
'.pytest_cache/',
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const MANAGED_BLOCK_START = '# dx managed tool metadata ignores'
|
|
16
|
+
|
|
17
|
+
export function isNxCommand(command) {
|
|
18
|
+
return /\bnx(?:\.js)?\b/.test(String(command || ''))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function ensureNxIgnoreToolDirs(projectRoot = process.cwd()) {
|
|
22
|
+
const root = String(projectRoot || process.cwd())
|
|
23
|
+
const nxIgnorePath = join(root, '.nxignore')
|
|
24
|
+
const existing = existsSync(nxIgnorePath) ? readFileSync(nxIgnorePath, 'utf8') : ''
|
|
25
|
+
const existingLines = new Set(
|
|
26
|
+
existing
|
|
27
|
+
.split(/\r?\n/)
|
|
28
|
+
.map(line => line.trim())
|
|
29
|
+
.filter(Boolean),
|
|
30
|
+
)
|
|
31
|
+
const missing = NX_IGNORE_TOOL_DIR_PATTERNS.filter(pattern => !existingLines.has(pattern))
|
|
32
|
+
|
|
33
|
+
if (missing.length === 0) {
|
|
34
|
+
return { changed: false, path: nxIgnorePath, added: [] }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const prefix = existing.trimEnd()
|
|
38
|
+
const blockLines = existingLines.has(MANAGED_BLOCK_START)
|
|
39
|
+
? missing
|
|
40
|
+
: [MANAGED_BLOCK_START, ...missing]
|
|
41
|
+
const next = `${prefix ? `${prefix}\n\n` : ''}${blockLines.join('\n')}\n`
|
|
42
|
+
|
|
43
|
+
writeFileSync(nxIgnorePath, next)
|
|
44
|
+
return { changed: true, path: nxIgnorePath, added: missing }
|
|
45
|
+
}
|