@ranger1/dx 0.1.102 → 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/exec.js +12 -0
- package/lib/nx-ignore.js +45 -0
- package/package.json +1 -1
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
|
+
}
|