@chengzhao-dev/dsh-cpp-workflow 0.7.9 → 0.7.11

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.
Files changed (126) hide show
  1. package/README.en.md +8 -7
  2. package/README.md +5 -4
  3. package/cordis.patch.yml +2 -2
  4. package/icon.svg +5 -5
  5. package/lib/client.js +542 -538
  6. package/lib/comment-policy.js +37 -33
  7. package/lib/workspace.js +8 -10
  8. package/locale/en.json +4 -4
  9. package/locale/zh.json +4 -4
  10. package/package.json +100 -100
  11. package/skills/building-cpp/SKILL.md +5 -5
  12. package/skills/building-cpp/assets/config/.clang-tidy +4 -5
  13. package/skills/building-cpp/assets/config/.clangd +5 -7
  14. package/skills/building-cpp/assets/config/.vscode/extensions.json +5 -5
  15. package/skills/building-cpp/assets/config/.vscode/settings.json +56 -58
  16. package/skills/building-cpp/examples/environment.md +13 -102
  17. package/skills/building-cpp/references/01-build-script.md +3 -3
  18. package/skills/building-cpp/references/02-environment.md +8 -8
  19. package/skills/building-cpp/scripts/checking-environment.mjs +424 -424
  20. package/skills/building-cpp/steps/01-build.md +10 -10
  21. package/skills/building-cpp/steps/02-tooling.md +6 -6
  22. package/skills/building-cpp/steps/03-check.md +2 -2
  23. package/skills/building-cpp/steps/04-vscode.md +4 -6
  24. package/skills/developing-cpp/SKILL.md +8 -9
  25. package/skills/developing-cpp/references/comments/01-comment-rules.md +50 -26
  26. package/skills/developing-cpp/references/comments/02-style.md +33 -25
  27. package/skills/developing-cpp/references/comments/examples/03-declaration-enum.md +14 -14
  28. package/skills/developing-cpp/references/comments/examples/04-declaration-file.md +12 -8
  29. package/skills/developing-cpp/references/comments/examples/05-declaration-function.md +20 -10
  30. package/skills/developing-cpp/references/comments/examples/06-declaration-member.md +4 -4
  31. package/skills/developing-cpp/references/comments/examples/07-declaration-predicate.md +2 -2
  32. package/skills/developing-cpp/references/comments/examples/08-declaration-struct.md +6 -6
  33. package/skills/developing-cpp/references/comments/examples/09-implementation-body.md +41 -41
  34. package/skills/developing-cpp/references/comments/glossary/01-comment-terms.md +17 -16
  35. package/skills/developing-cpp/references/design/01-project-design.md +21 -10
  36. package/skills/developing-cpp/references/design/02-raii.md +5 -4
  37. package/skills/developing-cpp/references/design/03-third-party.md +2 -2
  38. package/skills/developing-cpp/references/design/examples/02-coordinate-table.md +12 -12
  39. package/skills/developing-cpp/references/design/examples/03-header-place.md +1 -1
  40. package/skills/developing-cpp/references/design/examples/04-library-boundary.md +6 -6
  41. package/skills/developing-cpp/references/design/examples/06-move-result.md +29 -28
  42. package/skills/developing-cpp/references/design/examples/07-preview-read.md +24 -23
  43. package/skills/developing-cpp/references/design/examples/08-screen-enter-exit.md +19 -18
  44. package/skills/developing-cpp/references/design/examples/09-option-menu.md +6 -6
  45. package/skills/developing-cpp/references/design/session-layer.md +13 -22
  46. package/skills/developing-cpp/references/exceptions/01-exception-rules.md +57 -57
  47. package/skills/developing-cpp/references/exceptions/examples/01-throw-boundary.md +7 -20
  48. package/skills/developing-cpp/references/exceptions/examples/02-throw-build-mode.md +10 -11
  49. package/skills/developing-cpp/references/exceptions/examples/03-throw-catch.md +4 -4
  50. package/skills/developing-cpp/references/exceptions/examples/04-throw-destructor.md +9 -5
  51. package/skills/developing-cpp/references/exceptions/examples/07-throw-when.md +2 -2
  52. package/skills/developing-cpp/references/index.md +32 -35
  53. package/skills/developing-cpp/references/language/glossary/01-language-terms.md +3 -2
  54. package/skills/developing-cpp/references/language/language-basics/02-initialization.md +1 -1
  55. package/skills/developing-cpp/references/language/language-basics/05-expressions.md +9 -2
  56. package/skills/developing-cpp/references/language/language-basics/06-functions.md +2 -3
  57. package/skills/developing-cpp/references/language/language-basics/09-templates.md +3 -3
  58. package/skills/developing-cpp/references/language/language-basics/10-language-checklist.md +9 -9
  59. package/skills/developing-cpp/references/language/performance/03-memory.md +1 -1
  60. package/skills/developing-cpp/references/language/performance/07-checklist.md +6 -6
  61. package/skills/developing-cpp/references/language/standard-library/01-containers.md +4 -5
  62. package/skills/developing-cpp/references/language/standard-library/02-access.md +2 -5
  63. package/skills/developing-cpp/references/language/standard-library/05-string.md +1 -1
  64. package/skills/developing-cpp/references/language/standard-library/06-format.md +22 -20
  65. package/skills/developing-cpp/references/language/standard-library/{11-format-ecosystem.md → 07-format-ecosystem.md} +2 -11
  66. package/skills/developing-cpp/references/language/standard-library/{07-time.md → 08-time.md} +1 -1
  67. package/skills/developing-cpp/references/language/standard-library/{09-files.md → 10-files.md} +1 -1
  68. package/skills/developing-cpp/references/language/standard-library/11-library-checklist.md +8 -0
  69. package/skills/developing-cpp/references/language/value-types/02-signed.md +7 -7
  70. package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +14 -2
  71. package/skills/developing-cpp/references/language/value-types/05-strong-type.md +2 -2
  72. package/skills/developing-cpp/references/language/value-types/06-const-method.md +5 -5
  73. package/skills/developing-cpp/references/language/value-types/07-nodiscard.md +1 -1
  74. package/skills/developing-cpp/references/language/value-types/08-comparison.md +1 -1
  75. package/skills/developing-cpp/references/language/value-types/09-subscript.md +1 -1
  76. package/skills/developing-cpp/references/language/value-types/11-checklist.md +7 -7
  77. package/skills/developing-cpp/references/layout/01-source-layout.md +13 -13
  78. package/skills/developing-cpp/references/layout/02-file-template.md +10 -10
  79. package/skills/developing-cpp/references/layout/03-declaration-order.md +83 -42
  80. package/skills/developing-cpp/references/naming/01-identifier-names.md +32 -30
  81. package/skills/developing-cpp/references/naming/examples/06-naming-lower-layer.md +15 -15
  82. package/skills/developing-cpp/references/naming/examples/07-naming-multiple-return.md +2 -2
  83. package/skills/developing-cpp/references/naming/examples/13-naming-state-change.md +24 -23
  84. package/skills/developing-cpp/references/naming/glossary/01-naming-terms.md +3 -3
  85. package/skills/developing-cpp/references/naming/glossary/02-position.md +9 -9
  86. package/skills/developing-cpp/references/naming/glossary/03-selection.md +5 -1
  87. package/skills/developing-cpp/references/naming/glossary/04-square.md +3 -3
  88. package/skills/developing-cpp/references/naming/glossary/05-scoring.md +2 -2
  89. package/skills/developing-cpp/references/naming/glossary/06-difficulty.md +7 -7
  90. package/skills/developing-cpp/references/naming/glossary/07-stream.md +1 -1
  91. package/skills/developing-cpp/references/style/01-google-cpp-style.md +13 -23
  92. package/skills/developing-cpp/scripts/checking-comments.mjs +961 -755
  93. package/skills/developing-cpp/scripts/checking-declaration-order.mjs +512 -515
  94. package/skills/developing-cpp/steps/01-behavior.md +0 -1
  95. package/skills/developing-cpp/steps/02-boundary.md +2 -3
  96. package/skills/developing-cpp/steps/03-declaration.md +9 -10
  97. package/skills/developing-cpp/steps/04-implementation.md +7 -8
  98. package/skills/engineering/SKILL.md +9 -10
  99. package/skills/engineering/references/cmake/assets/LinkSettings.cmake +1 -1
  100. package/skills/engineering/references/cmake/linking/02-rpath.md +5 -6
  101. package/skills/engineering/references/cmake/modules/01-functions.md +9 -9
  102. package/skills/engineering/references/cmake/standards/01-cxx-standard.md +6 -6
  103. package/skills/engineering/references/cmake/standards/index.md +8 -29
  104. package/skills/engineering/references/cmake/targets/01-target-rules.md +14 -13
  105. package/skills/engineering/references/cmake/targets/examples/01-rpath.md +1 -1
  106. package/skills/engineering/references/cmake/testing/01-ctest.md +3 -3
  107. package/skills/engineering/references/formatting/01-encoding.md +5 -5
  108. package/skills/engineering/references/formatting/02-clang-format.md +2 -2
  109. package/skills/engineering/references/formatting/03-clang-tidy.md +5 -5
  110. package/skills/engineering/references/formatting/04-clangd.md +32 -39
  111. package/skills/engineering/references/formatting/05-config-comments.md +88 -0
  112. package/skills/engineering/references/formatting/examples/02-clang-tidy.md +6 -6
  113. package/skills/engineering/references/formatting/examples/03-clangd.md +17 -17
  114. package/skills/engineering/references/index.md +5 -4
  115. package/skills/engineering/scripts/checking-encoding.mjs +369 -369
  116. package/skills/engineering/steps/01-targets.md +3 -3
  117. package/skills/engineering/steps/02-modules.md +1 -2
  118. package/skills/engineering/steps/03-check.md +2 -3
  119. package/templates/cpp-workflow-project/SKILL.md +1 -1
  120. package/templates/cpp-workflow-project/environment.json +4 -4
  121. package/skills/developing-cpp/references/design/examples/05-library-split.md +0 -8
  122. package/skills/developing-cpp/references/language/standard-library/10-library-checklist.md +0 -10
  123. package/skills/developing-cpp/references/naming/examples/02-naming-basic.md +0 -4
  124. package/skills/developing-cpp/references/naming/examples/10-naming-rename.md +0 -6
  125. package/skills/engineering/references/formatting/examples/04-config-comments.md +0 -70
  126. /package/skills/developing-cpp/references/language/standard-library/{08-random.md → 09-random.md} +0 -0
@@ -22,404 +22,404 @@ const PROJECT_SKILL_DIR = PROJECT_SKILL_DIRS[0]
22
22
  const MAX_ASCENT = 64
23
23
 
24
24
  export const EXIT = {
25
- ok: 0,
26
- script: 1,
27
- declaration: 2,
28
- live: 3,
25
+ ok: 0,
26
+ script: 1,
27
+ declaration: 2,
28
+ live: 3,
29
29
  }
30
30
 
31
31
  function isRecord(value) {
32
- return value !== null && typeof value === 'object' && !Array.isArray(value)
32
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
33
33
  }
34
34
 
35
35
  function normalize(value) {
36
- return typeof value === 'string' ? value.trim() : value
36
+ return typeof value === 'string' ? value.trim() : value
37
37
  }
38
38
 
39
39
  /**
40
- * 校验三个环境轴、语言标准以及它们的组合。
41
- * 纯函数:不读文件系统,也不看 PATH。
42
- * @returns {{ok: boolean, issues: string[], notes: string[], axes: {host?: string, build_host?: string, compiler?: string, standard?: string}}}
43
- */
40
+ * 校验三个环境轴、语言标准以及它们的组合。
41
+ * 纯函数:不读文件系统,也不看 PATH。
42
+ * @returns {{ok: boolean, issues: string[], notes: string[], axes: {host?: string, build_host?: string, compiler?: string, standard?: string}}}
43
+ */
44
44
  export function validateEnvironment(value) {
45
- const issues = []
46
- const notes = []
47
- if (!isRecord(value)) {
48
- return {
49
- ok: false,
50
- issues: ['environment.json 必须是一个 JSON 对象'],
51
- notes,
52
- axes: {},
53
- }
54
- }
55
-
56
- const axes = {
57
- host: normalize(value.host),
58
- build_host: normalize(value.build_host),
59
- compiler: normalize(value.compiler),
60
- standard: normalize(value.standard),
61
- }
62
-
63
- if (axes.standard === undefined || axes.standard === null || axes.standard === '') {
64
- axes.standard = DEFAULT_STANDARD
65
- notes.push(`standard 未声明或为空;按默认 ${DEFAULT_STANDARD} 处理,请在 environment.json 中显式写出`)
66
- } else if (Array.isArray(axes.standard)) {
67
- issues.push(`standard 只能声明一个值,当前是数组 [${axes.standard.join(', ')}]`)
68
- } else if (typeof axes.standard !== 'string') {
69
- issues.push(`standard 必须是字符串,当前是 ${typeof axes.standard}`)
70
- } else if (!STANDARDS.includes(axes.standard)) {
71
- issues.push(`standard 的值 "${axes.standard}" 非法;允许:${STANDARDS.join(' / ')}`)
72
- }
73
-
74
- for (const [key, allowed] of [
75
- ['host', HOSTS],
76
- ['build_host', BUILD_HOSTS],
77
- ['compiler', COMPILERS],
78
- ]) {
79
- const current = axes[key]
80
- if (current === undefined || current === null || current === '') {
81
- issues.push(`${key} 不能为空;请显式声明,例如 ${allowed[0]}`)
82
- continue
83
- }
84
- if (Array.isArray(current)) {
85
- issues.push(`${key} 只能声明一个值,当前是数组 [${current.join(', ')}]`)
86
- continue
87
- }
88
- if (typeof current !== 'string') {
89
- issues.push(`${key} 必须是字符串,当前是 ${typeof current}`)
90
- continue
91
- }
92
- if (!allowed.includes(current)) {
93
- issues.push(`${key} 的值 "${current}" 非法;允许:${allowed.join(' / ')}`)
94
- }
95
- }
96
-
97
- if (axes.host === 'linux' || axes.host === 'macos') {
98
- if (axes.build_host === 'wsl') {
99
- issues.push('build_host=wsl 只允许 host=windows;Linux/macOS 请用 build_host=native')
100
- }
101
- }
102
-
103
- if (axes.host === 'windows' && axes.build_host === 'native') {
104
- issues.push('本版本不能在 Windows 原生壳里构建')
105
- }
106
-
107
- for (const key of Object.keys(value)) {
108
- if (!['host', 'build_host', 'compiler', 'standard'].includes(key)) {
109
- notes.push(`忽略未知键 "${key}";环境只认 host / build_host / compiler / standard`)
110
- }
111
- }
112
-
113
- return { ok: issues.length === 0, issues, notes, axes }
45
+ const issues = []
46
+ const notes = []
47
+ if (!isRecord(value)) {
48
+ return {
49
+ ok: false,
50
+ issues: ['environment.json 必须是一个 JSON 对象'],
51
+ notes,
52
+ axes: {},
53
+ }
54
+ }
55
+
56
+ const axes = {
57
+ host: normalize(value.host),
58
+ build_host: normalize(value.build_host),
59
+ compiler: normalize(value.compiler),
60
+ standard: normalize(value.standard),
61
+ }
62
+
63
+ if (axes.standard === undefined || axes.standard === null || axes.standard === '') {
64
+ axes.standard = DEFAULT_STANDARD
65
+ notes.push(`standard 未声明或为空;按默认 ${DEFAULT_STANDARD} 处理,请在 environment.json 中显式写出`)
66
+ } else if (Array.isArray(axes.standard)) {
67
+ issues.push(`standard 只能声明一个值,当前是数组 [${axes.standard.join(', ')}]`)
68
+ } else if (typeof axes.standard !== 'string') {
69
+ issues.push(`standard 必须是字符串,当前是 ${typeof axes.standard}`)
70
+ } else if (!STANDARDS.includes(axes.standard)) {
71
+ issues.push(`standard 的值 "${axes.standard}" 非法;允许:${STANDARDS.join(' / ')}`)
72
+ }
73
+
74
+ for (const [key, allowed] of [
75
+ ['host', HOSTS],
76
+ ['build_host', BUILD_HOSTS],
77
+ ['compiler', COMPILERS],
78
+ ]) {
79
+ const current = axes[key]
80
+ if (current === undefined || current === null || current === '') {
81
+ issues.push(`${key} 不能为空;请显式声明,例如 ${allowed[0]}`)
82
+ continue
83
+ }
84
+ if (Array.isArray(current)) {
85
+ issues.push(`${key} 只能声明一个值,当前是数组 [${current.join(', ')}]`)
86
+ continue
87
+ }
88
+ if (typeof current !== 'string') {
89
+ issues.push(`${key} 必须是字符串,当前是 ${typeof current}`)
90
+ continue
91
+ }
92
+ if (!allowed.includes(current)) {
93
+ issues.push(`${key} 的值 "${current}" 非法;允许:${allowed.join(' / ')}`)
94
+ }
95
+ }
96
+
97
+ if (axes.host === 'linux' || axes.host === 'macos') {
98
+ if (axes.build_host === 'wsl') {
99
+ issues.push('build_host=wsl 只允许 host=windows;Linux/macOS 请用 build_host=native')
100
+ }
101
+ }
102
+
103
+ if (axes.host === 'windows' && axes.build_host === 'native') {
104
+ issues.push('本版本不能在 Windows 原生壳里构建')
105
+ }
106
+
107
+ for (const key of Object.keys(value)) {
108
+ if (!['host', 'build_host', 'compiler', 'standard'].includes(key)) {
109
+ notes.push(`忽略未知键 "${key}";环境只认 host / build_host / compiler / standard`)
110
+ }
111
+ }
112
+
113
+ return { ok: issues.length === 0, issues, notes, axes }
114
114
  }
115
115
 
116
116
  /** 读取并解析 environment.json;成功给声明,失败给结构化错误。 */
117
117
  export async function readEnvironmentFile(file) {
118
- let text
119
- try {
120
- text = await readFile(file, 'utf8')
121
- } catch {
122
- return { ok: false, file, issues: [`找不到环境声明:${file}`] }
123
- }
124
- let value
125
- try {
126
- value = JSON.parse(text)
127
- } catch (error) {
128
- return { ok: false, file, issues: [`environment.json 不是合法 JSON:${error.message}`] }
129
- }
130
- return { ok: true, file, value }
118
+ let text
119
+ try {
120
+ text = await readFile(file, 'utf8')
121
+ } catch {
122
+ return { ok: false, file, issues: [`找不到环境声明:${file}`] }
123
+ }
124
+ let value
125
+ try {
126
+ value = JSON.parse(text)
127
+ } catch (error) {
128
+ return { ok: false, file, issues: [`environment.json 不是合法 JSON:${error.message}`] }
129
+ }
130
+ return { ok: true, file, value }
131
131
  }
132
132
 
133
133
  /** 从 startDir 向上走到 git 根(或文件系统根),找 environment.json。 */
134
134
  export async function findProjectEnvironment(startDir) {
135
- let cursor
136
- try {
137
- cursor = path.resolve(startDir)
138
- } catch {
135
+ let cursor
136
+ try {
137
+ cursor = path.resolve(startDir)
138
+ } catch {
139
+ return undefined
140
+ }
141
+
142
+ // 允许直接指向项目技能目录(下划线或连字符命名)。
143
+ if (SKILL_DIR_NAMES.includes(path.basename(cursor))) {
144
+ const direct = path.join(cursor, 'environment.json')
145
+ if (await exists(direct)) return direct
146
+ }
147
+
148
+ for (let depth = 0; depth < MAX_ASCENT; depth += 1) {
149
+ for (const dir of PROJECT_SKILL_DIRS) {
150
+ const candidate = path.join(cursor, dir, 'environment.json')
151
+ if (await exists(candidate)) return candidate
152
+ }
153
+ if (await exists(path.join(cursor, '.git'))) return undefined
154
+ const parent = path.dirname(cursor)
155
+ if (parent === cursor) return undefined
156
+ cursor = parent
157
+ }
139
158
  return undefined
140
- }
141
-
142
- // 允许直接指向项目技能目录(下划线或连字符命名)。
143
- if (SKILL_DIR_NAMES.includes(path.basename(cursor))) {
144
- const direct = path.join(cursor, 'environment.json')
145
- if (await exists(direct)) return direct
146
- }
147
-
148
- for (let depth = 0; depth < MAX_ASCENT; depth += 1) {
149
- for (const dir of PROJECT_SKILL_DIRS) {
150
- const candidate = path.join(cursor, dir, 'environment.json')
151
- if (await exists(candidate)) return candidate
152
- }
153
- if (await exists(path.join(cursor, '.git'))) return undefined
154
- const parent = path.dirname(cursor)
155
- if (parent === cursor) return undefined
156
- cursor = parent
157
- }
158
- return undefined
159
159
  }
160
160
 
161
161
  async function exists(target) {
162
- try {
163
- await access(target)
164
- return true
165
- } catch {
166
- return false
167
- }
162
+ try {
163
+ await access(target)
164
+ return true
165
+ } catch {
166
+ return false
167
+ }
168
168
  }
169
169
 
170
170
  function findExecutable(command, pathValue = process.env.PATH ?? '') {
171
- if (!command || command.includes(path.sep) || command.includes('/')) {
172
- return existsSync(command) ? command : undefined
173
- }
174
- for (const dir of pathValue.split(path.delimiter)) {
175
- if (!dir) continue
176
- const candidate = path.join(dir, command)
177
- try {
178
- accessSync(candidate, constants.X_OK)
179
- return candidate
180
- } catch {
181
- // 继续向上找
171
+ if (!command || command.includes(path.sep) || command.includes('/')) {
172
+ return existsSync(command) ? command : undefined
173
+ }
174
+ for (const dir of pathValue.split(path.delimiter)) {
175
+ if (!dir) continue
176
+ const candidate = path.join(dir, command)
177
+ try {
178
+ accessSync(candidate, constants.X_OK)
179
+ return candidate
180
+ } catch {
181
+ // 继续向上找
182
+ }
182
183
  }
183
- }
184
- return undefined
184
+ return undefined
185
185
  }
186
186
 
187
187
  function run(command, args, options = {}) {
188
- const result = spawnSync(command, args, {
189
- encoding: 'utf8',
190
- timeout: options.timeout ?? 15000,
191
- cwd: options.cwd,
192
- env: options.env ?? process.env,
193
- })
194
- return {
195
- status: typeof result.status === 'number' ? result.status : -1,
196
- signal: result.signal ?? null,
197
- stdout: result.stdout ?? '',
198
- stderr: result.stderr ?? '',
199
- error: result.error,
200
- }
188
+ const result = spawnSync(command, args, {
189
+ encoding: 'utf8',
190
+ timeout: options.timeout ?? 15000,
191
+ cwd: options.cwd,
192
+ env: options.env ?? process.env,
193
+ })
194
+ return {
195
+ status: typeof result.status === 'number' ? result.status : -1,
196
+ signal: result.signal ?? null,
197
+ stdout: result.stdout ?? '',
198
+ stderr: result.stderr ?? '',
199
+ error: result.error,
200
+ }
201
201
  }
202
202
 
203
203
  function firstLines(text, count = 3) {
204
- return text
205
- .split(/\r?\n/)
206
- .map((line) => line.trim())
207
- .filter(Boolean)
208
- .slice(0, count)
209
- .join(' | ')
204
+ return text
205
+ .split(/\r?\n/)
206
+ .map((line) => line.trim())
207
+ .filter(Boolean)
208
+ .slice(0, count)
209
+ .join(' | ')
210
210
  }
211
211
 
212
212
  /** Clang 16 等旧主版本只认 c++2b 拼写;其余情况原样返回。 */
213
213
  export function standardFlag(compiler, major, standard) {
214
- const level = Number.parseInt(String(standard).replace(/^c\+\+/, ''), 10)
215
- if (compiler === 'clang' && Number.isFinite(major) && major < 17 && level === 23) return 'c++2b'
216
- return standard
214
+ const level = Number.parseInt(String(standard).replace(/^c\+\+/, ''), 10)
215
+ if (compiler === 'clang' && Number.isFinite(major) && major < 17 && level === 23) return 'c++2b'
216
+ return standard
217
217
  }
218
218
 
219
219
  function parseVersion(text) {
220
- const apple = /Apple clang version\s+(\d+)\.(\d+)(?:\.(\d+))?/i.exec(text)
221
- if (apple) {
222
- return { apple: true, major: Number(apple[1]), minor: Number(apple[2]), patch: Number(apple[3] ?? 0) }
223
- }
224
- const clang = /\bclang(?:d|-format|-tidy)? version\s+(\d+)\.(\d+)(?:\.(\d+))?/i.exec(text)
225
- if (clang) {
226
- return { apple: false, major: Number(clang[1]), minor: Number(clang[2]), patch: Number(clang[3] ?? 0) }
227
- }
228
- const llvm = /LLVM version\s+(\d+)\.(\d+)(?:\.(\d+))?/i.exec(text)
229
- if (llvm) {
230
- return { apple: false, major: Number(llvm[1]), minor: Number(llvm[2]), patch: Number(llvm[3] ?? 0) }
231
- }
232
- const gcc = /\b(\d+)\.(\d+)\.(\d+)\b/.exec(text)
233
- if (gcc) {
234
- return { apple: false, major: Number(gcc[1]), minor: Number(gcc[2]), patch: Number(gcc[3]) }
235
- }
236
- return undefined
220
+ const apple = /Apple clang version\s+(\d+)\.(\d+)(?:\.(\d+))?/i.exec(text)
221
+ if (apple) {
222
+ return { apple: true, major: Number(apple[1]), minor: Number(apple[2]), patch: Number(apple[3] ?? 0) }
223
+ }
224
+ const clang = /\bclang(?:d|-format|-tidy)? version\s+(\d+)\.(\d+)(?:\.(\d+))?/i.exec(text)
225
+ if (clang) {
226
+ return { apple: false, major: Number(clang[1]), minor: Number(clang[2]), patch: Number(clang[3] ?? 0) }
227
+ }
228
+ const llvm = /LLVM version\s+(\d+)\.(\d+)(?:\.(\d+))?/i.exec(text)
229
+ if (llvm) {
230
+ return { apple: false, major: Number(llvm[1]), minor: Number(llvm[2]), patch: Number(llvm[3] ?? 0) }
231
+ }
232
+ const gcc = /\b(\d+)\.(\d+)\.(\d+)\b/.exec(text)
233
+ if (gcc) {
234
+ return { apple: false, major: Number(gcc[1]), minor: Number(gcc[2]), patch: Number(gcc[3]) }
235
+ }
236
+ return undefined
237
237
  }
238
238
 
239
239
  function versionText(version) {
240
- if (!version) return '未知'
241
- return `${version.major}.${version.minor}.${version.patch}${version.apple ? ' (Apple clang)' : ''}`
240
+ if (!version) return '未知'
241
+ return `${version.major}.${version.minor}.${version.patch}${version.apple ? ' (Apple clang)' : ''}`
242
242
  }
243
243
 
244
244
  function isWsl(env = process.env) {
245
- if (env.WSL_DISTRO_NAME || env.WSL_INTEROP) return true
246
- try {
247
- return /microsoft/i.test(readFileSync('/proc/version', 'utf8'))
248
- } catch {
249
- return false
250
- }
245
+ if (env.WSL_DISTRO_NAME || env.WSL_INTEROP) return true
246
+ try {
247
+ return /microsoft/i.test(readFileSync('/proc/version', 'utf8'))
248
+ } catch {
249
+ return false
250
+ }
251
251
  }
252
252
 
253
253
  /**
254
- * 实时检查。依赖可注入,测试不必真的调用编译器就能走主机与 PATH 分支。
255
- */
254
+ * 实时检查。依赖可注入,测试不必真的调用编译器就能走主机与 PATH 分支。
255
+ */
256
256
  export function checkLive(declaration, options = {}) {
257
- const platform = options.platform ?? process.platform
258
- const env = options.env ?? process.env
259
- const pathValue = options.pathValue ?? env.PATH ?? ''
260
- const resolveExecutable = options.resolveExecutable ?? findExecutable
261
- const runVersion = options.runVersion ?? ((command) => run(command, ['--version']))
262
- const issues = []
263
- const notes = []
264
- const checks = []
265
-
266
- const validation = validateEnvironment(declaration)
267
- if (!validation.ok) {
268
- return { ok: false, issues: validation.issues, notes: validation.notes, checks }
269
- }
270
- const { host, build_host: buildHost, compiler } = validation.axes
271
-
272
- if (buildHost === 'wsl') {
273
- if (platform !== 'linux' || !isWsl(env)) {
274
- issues.push('声明 build_host=wsl,但当前进程不在 WSL 内;请在 WSL 里运行 --live')
275
- }
276
- } else if (host === 'linux' && platform !== 'linux') {
277
- issues.push(`声明 host=linux,但当前平台是 ${platform};请在 Linux 上运行 --live`)
278
- } else if (host === 'macos' && platform !== 'darwin') {
279
- issues.push(`声明 host=macos,但当前平台是 ${platform};请在 macOS 上运行 --live`)
280
- }
281
-
282
- if (issues.length > 0) {
283
- return { ok: false, issues, notes: validation.notes.concat(notes), checks }
284
- }
285
-
286
- const compilerCommand = compiler === 'clang' ? 'clang++' : 'g++'
287
- const roles = [
288
- { role: 'compiler', command: compilerCommand },
289
- { role: 'clang-format', command: 'clang-format' },
290
- { role: 'clang-tidy', command: 'clang-tidy' },
291
- { role: 'clangd', command: 'clangd' },
292
- { role: 'cmake', command: 'cmake' },
293
- { role: 'ninja', command: 'ninja' },
294
- { role: 'ctest', command: 'ctest' },
295
- ]
296
-
297
- const resolved = new Map()
298
- for (const item of roles) {
299
- const executable = resolveExecutable(item.command, pathValue)
300
- if (!executable) {
301
- issues.push(`${item.role}: PATH 中找不到 ${item.command}`)
302
- checks.push({ role: item.role, command: item.command, status: 'missing' })
303
- continue
304
- }
305
- resolved.set(item.role, executable)
306
- checks.push({ role: item.role, command: item.command, executable, status: 'found' })
307
- }
308
-
309
- if (issues.length > 0) {
310
- return { ok: false, issues, notes: validation.notes.concat(notes), checks }
311
- }
312
-
313
- const versions = new Map()
314
- for (const item of roles) {
315
- if (item.role === 'ninja' || item.role === 'ctest') continue
316
- if (compiler === 'gcc' && item.role === 'clangd') continue
317
- const executable = resolved.get(item.role)
318
- const result = runVersion(executable, ['--version'])
319
- const text = `${result.stdout}\n${result.stderr}`
320
- const version = parseVersion(text)
321
- versions.set(item.role, version)
322
- const check = checks.find((entry) => entry.role === item.role)
323
- if (check) {
324
- check.version = versionText(version)
325
- check.status = version ? 'found' : 'unknown-version'
326
- }
327
- if (!version) {
328
- issues.push(`${item.role}: 无法解析版本;输出:${firstLines(text) || '(空)'}`)
329
- }
330
- }
331
-
332
- const cmakeVersion = versions.get('cmake')
333
- if (cmakeVersion && (cmakeVersion.major < 3 || (cmakeVersion.major === 3 && cmakeVersion.minor < 20))) {
334
- issues.push(`cmake ${versionText(cmakeVersion)} 过旧;需要 >= 3.20`)
335
- }
336
-
337
- const compilerVersion = versions.get('compiler')
338
- const compilerExecutable = resolved.get('compiler')
339
- if (compilerExecutable && !options.runVersion) {
340
- const flag = `-std=${standardFlag(compiler, compilerVersion?.major, validation.axes.standard)}`
341
- const probe = run(compilerExecutable, ['-x', 'c++', flag, '-fsyntax-only', '-'], {})
342
- if (probe.status !== 0) {
343
- issues.push(
344
- `compiler 不接受 ${flag};输出:${firstLines(`${probe.stdout}\n${probe.stderr}`) || '(空)'}。升级编译器或把 standard 降到实际可用的档位`,
345
- )
346
- }
347
- }
348
- const formatVersion = versions.get('clang-format')
349
- const tidyVersion = versions.get('clang-tidy')
350
- const clangdVersion = versions.get('clangd')
351
-
352
- if (compiler === 'gcc' && compilerVersion?.apple === true) {
353
- issues.push('声明 compiler=gcc,但 g++ 实际是 Apple clang;请安装真正的 GCC,或把 compiler 改成 clang')
354
- }
355
-
356
- if (compiler === 'clang' && compilerVersion) {
257
+ const platform = options.platform ?? process.platform
258
+ const env = options.env ?? process.env
259
+ const pathValue = options.pathValue ?? env.PATH ?? ''
260
+ const resolveExecutable = options.resolveExecutable ?? findExecutable
261
+ const runVersion = options.runVersion ?? ((command) => run(command, ['--version']))
262
+ const issues = []
263
+ const notes = []
264
+ const checks = []
265
+
266
+ const validation = validateEnvironment(declaration)
267
+ if (!validation.ok) {
268
+ return { ok: false, issues: validation.issues, notes: validation.notes, checks }
269
+ }
270
+ const { host, build_host: buildHost, compiler } = validation.axes
271
+
272
+ if (buildHost === 'wsl') {
273
+ if (platform !== 'linux' || !isWsl(env)) {
274
+ issues.push('声明 build_host=wsl,但当前进程不在 WSL 内;请在 WSL 里运行 --live')
275
+ }
276
+ } else if (host === 'linux' && platform !== 'linux') {
277
+ issues.push(`声明 host=linux,但当前平台是 ${platform};请在 Linux 上运行 --live`)
278
+ } else if (host === 'macos' && platform !== 'darwin') {
279
+ issues.push(`声明 host=macos,但当前平台是 ${platform};请在 macOS 上运行 --live`)
280
+ }
281
+
282
+ if (issues.length > 0) {
283
+ return { ok: false, issues, notes: validation.notes.concat(notes), checks }
284
+ }
285
+
286
+ const compilerCommand = compiler === 'clang' ? 'clang++' : 'g++'
287
+ const roles = [
288
+ { role: 'compiler', command: compilerCommand },
289
+ { role: 'clang-format', command: 'clang-format' },
290
+ { role: 'clang-tidy', command: 'clang-tidy' },
291
+ { role: 'clangd', command: 'clangd' },
292
+ { role: 'cmake', command: 'cmake' },
293
+ { role: 'ninja', command: 'ninja' },
294
+ { role: 'ctest', command: 'ctest' },
295
+ ]
296
+
297
+ const resolved = new Map()
298
+ for (const item of roles) {
299
+ const executable = resolveExecutable(item.command, pathValue)
300
+ if (!executable) {
301
+ issues.push(`${item.role}: PATH 中找不到 ${item.command}`)
302
+ checks.push({ role: item.role, command: item.command, status: 'missing' })
303
+ continue
304
+ }
305
+ resolved.set(item.role, executable)
306
+ checks.push({ role: item.role, command: item.command, executable, status: 'found' })
307
+ }
308
+
309
+ if (issues.length > 0) {
310
+ return { ok: false, issues, notes: validation.notes.concat(notes), checks }
311
+ }
312
+
313
+ const versions = new Map()
314
+ for (const item of roles) {
315
+ if (item.role === 'ninja' || item.role === 'ctest') continue
316
+ if (compiler === 'gcc' && item.role === 'clangd') continue
317
+ const executable = resolved.get(item.role)
318
+ const result = runVersion(executable, ['--version'])
319
+ const text = `${result.stdout}\n${result.stderr}`
320
+ const version = parseVersion(text)
321
+ versions.set(item.role, version)
322
+ const check = checks.find((entry) => entry.role === item.role)
323
+ if (check) {
324
+ check.version = versionText(version)
325
+ check.status = version ? 'found' : 'unknown-version'
326
+ }
327
+ if (!version) {
328
+ issues.push(`${item.role}: 无法解析版本;输出:${firstLines(text) || '(空)'}`)
329
+ }
330
+ }
331
+
332
+ const cmakeVersion = versions.get('cmake')
333
+ if (cmakeVersion && (cmakeVersion.major < 3 || (cmakeVersion.major === 3 && cmakeVersion.minor < 20))) {
334
+ issues.push(`cmake ${versionText(cmakeVersion)} 过旧;需要 >= 3.20`)
335
+ }
336
+
337
+ const compilerVersion = versions.get('compiler')
338
+ const compilerExecutable = resolved.get('compiler')
339
+ if (compilerExecutable && !options.runVersion) {
340
+ const flag = `-std=${standardFlag(compiler, compilerVersion?.major, validation.axes.standard)}`
341
+ const probe = run(compilerExecutable, ['-x', 'c++', flag, '-fsyntax-only', '-'], {})
342
+ if (probe.status !== 0) {
343
+ issues.push(
344
+ `compiler 不接受 ${flag};输出:${firstLines(`${probe.stdout}\n${probe.stderr}`) || '(空)'}。升级编译器或把 standard 降到实际可用的档位`,
345
+ )
346
+ }
347
+ }
348
+ const formatVersion = versions.get('clang-format')
349
+ const tidyVersion = versions.get('clang-tidy')
350
+ const clangdVersion = versions.get('clangd')
351
+
352
+ if (compiler === 'gcc' && compilerVersion?.apple === true) {
353
+ issues.push('声明 compiler=gcc,但 g++ 实际是 Apple clang;请安装真正的 GCC,或把 compiler 改成 clang')
354
+ }
355
+
356
+ if (compiler === 'clang' && compilerVersion) {
357
+ for (const [role, version] of [
358
+ ['clang-format', formatVersion],
359
+ ['clang-tidy', tidyVersion],
360
+ ['clangd', clangdVersion],
361
+ ]) {
362
+ if (version && version.major !== compilerVersion.major) {
363
+ issues.push(
364
+ `${role} ${versionText(version)} 与 clang++ ${versionText(compilerVersion)} 主版本不一致;clang 模式要求同一 LLVM 主版本`,
365
+ )
366
+ }
367
+ }
368
+ if (compilerVersion.apple) {
369
+ notes.push(
370
+ 'clang++ 是 Apple Clang;clangd 需能经 xcrun 找到 SDK。不要混用 Homebrew LLVM 与 Xcode 资源目录,也不要把 Homebrew 路径写死。',
371
+ )
372
+ }
373
+ }
374
+
357
375
  for (const [role, version] of [
358
- ['clang-format', formatVersion],
359
- ['clang-tidy', tidyVersion],
360
- ['clangd', clangdVersion],
376
+ ['clang-format', formatVersion],
377
+ ['clang-tidy', tidyVersion],
361
378
  ]) {
362
- if (version && version.major !== compilerVersion.major) {
363
- issues.push(
364
- `${role} ${versionText(version)} 与 clang++ ${versionText(compilerVersion)} 主版本不一致;clang 模式要求同一 LLVM 主版本`,
365
- )
366
- }
367
- }
368
- if (compilerVersion.apple) {
369
- notes.push(
370
- 'clang++ 是 Apple Clang;clangd 需能经 xcrun 找到 SDK。不要混用 Homebrew LLVM 与 Xcode 资源目录,也不要把 Homebrew 路径写死。',
371
- )
372
- }
373
- }
374
-
375
- for (const [role, version] of [
376
- ['clang-format', formatVersion],
377
- ['clang-tidy', tidyVersion],
378
- ]) {
379
- if (version && version.major < 16) {
380
- issues.push(`${role} ${versionText(version)} 过旧;本工作流要求 >= 16`)
381
- }
382
- }
383
-
384
- return {
385
- ok: issues.length === 0,
386
- issues,
387
- notes: validation.notes.concat(notes),
388
- checks,
389
- environment: validation.axes,
390
- }
379
+ if (version && version.major < 16) {
380
+ issues.push(`${role} ${versionText(version)} 过旧;本工作流要求 >= 16`)
381
+ }
382
+ }
383
+
384
+ return {
385
+ ok: issues.length === 0,
386
+ issues,
387
+ notes: validation.notes.concat(notes),
388
+ checks,
389
+ environment: validation.axes,
390
+ }
391
391
  }
392
392
 
393
393
  function parseArgs(argv) {
394
- const options = { project: process.cwd(), live: false, json: false, help: false, environment: undefined }
395
- for (let index = 0; index < argv.length; index += 1) {
396
- const arg = argv[index]
397
- if (arg === '--live') {
398
- options.live = true
399
- } else if (arg === '--json') {
400
- options.json = true
401
- } else if (arg === '--help' || arg === '-h') {
402
- options.help = true
403
- } else if (arg === '--project') {
404
- const value = argv[index + 1]
405
- if (!value) throw new Error('--project 需要一个目录')
406
- options.project = value
407
- index += 1
408
- } else if (arg.startsWith('--project=')) {
409
- options.project = arg.slice('--project='.length)
410
- } else if (arg === '--environment') {
411
- const value = argv[index + 1]
412
- if (!value) throw new Error('--environment 需要一个文件路径')
413
- options.environment = value
414
- index += 1
415
- } else if (arg.startsWith('--environment=')) {
416
- options.environment = arg.slice('--environment='.length)
417
- if (!options.environment) throw new Error('--environment 不能为空')
418
- } else {
419
- throw new Error(`未知参数:${arg}`)
394
+ const options = { project: process.cwd(), live: false, json: false, help: false, environment: undefined }
395
+ for (let index = 0; index < argv.length; index += 1) {
396
+ const arg = argv[index]
397
+ if (arg === '--live') {
398
+ options.live = true
399
+ } else if (arg === '--json') {
400
+ options.json = true
401
+ } else if (arg === '--help' || arg === '-h') {
402
+ options.help = true
403
+ } else if (arg === '--project') {
404
+ const value = argv[index + 1]
405
+ if (!value) throw new Error('--project 需要一个目录')
406
+ options.project = value
407
+ index += 1
408
+ } else if (arg.startsWith('--project=')) {
409
+ options.project = arg.slice('--project='.length)
410
+ } else if (arg === '--environment') {
411
+ const value = argv[index + 1]
412
+ if (!value) throw new Error('--environment 需要一个文件路径')
413
+ options.environment = value
414
+ index += 1
415
+ } else if (arg.startsWith('--environment=')) {
416
+ options.environment = arg.slice('--environment='.length)
417
+ if (!options.environment) throw new Error('--environment 不能为空')
418
+ } else {
419
+ throw new Error(`未知参数:${arg}`)
420
+ }
420
421
  }
421
- }
422
- return options
422
+ return options
423
423
  }
424
424
 
425
425
  const USAGE = `用法: node checking-environment.mjs [--project <dir>] [--environment <file>] [--live] [--json]
@@ -433,96 +433,96 @@ const USAGE = `用法: node checking-environment.mjs [--project <dir>] [--enviro
433
433
  --help 显示本帮助`
434
434
 
435
435
  async function main(argv) {
436
- let options
437
- try {
438
- options = parseArgs(argv)
439
- } catch (error) {
440
- process.stderr.write(`${error.message}\n\n${USAGE}\n`)
441
- return EXIT.script
442
- }
443
- if (options.help) {
444
- process.stdout.write(`${USAGE}\n`)
445
- return EXIT.ok
446
- }
447
-
448
- const start = path.resolve(options.project)
449
- const file = options.environment
450
- ? path.resolve(options.environment)
451
- : await findProjectEnvironment(start)
452
- if (!file) {
453
- process.stderr.write(
454
- `找不到环境声明:${path.join(start, PROJECT_SKILL_DIR, 'environment.json')}(或它的任一上层目录;项目技能目录名也接受 cpp_workflow_project);也可用 --environment <file> 指定\n`,
455
- )
456
- return EXIT.declaration
457
- }
458
-
459
- const read = await readEnvironmentFile(file)
460
- if (!read.ok) {
461
- process.stderr.write(`${read.issues.join('\n')}\n`)
462
- return EXIT.declaration
463
- }
464
-
465
- const validation = validateEnvironment(read.value)
466
- if (!validation.ok) {
467
- if (options.json) {
468
- process.stdout.write(
469
- `${JSON.stringify({ ok: false, mode: 'static', file, issues: validation.issues, notes: validation.notes }, null, 2)}\n`,
470
- )
471
- } else {
472
- process.stderr.write(`环境声明无效:${file}\n${validation.issues.map((issue) => `- ${issue}`).join('\n')}\n`)
436
+ let options
437
+ try {
438
+ options = parseArgs(argv)
439
+ } catch (error) {
440
+ process.stderr.write(`${error.message}\n\n${USAGE}\n`)
441
+ return EXIT.script
442
+ }
443
+ if (options.help) {
444
+ process.stdout.write(`${USAGE}\n`)
445
+ return EXIT.ok
446
+ }
447
+
448
+ const start = path.resolve(options.project)
449
+ const file = options.environment
450
+ ? path.resolve(options.environment)
451
+ : await findProjectEnvironment(start)
452
+ if (!file) {
453
+ process.stderr.write(
454
+ `找不到环境声明:${path.join(start, PROJECT_SKILL_DIR, 'environment.json')}(或它的任一上层目录;项目技能目录名也接受 cpp_workflow_project);也可用 --environment <file> 指定\n`,
455
+ )
456
+ return EXIT.declaration
457
+ }
458
+
459
+ const read = await readEnvironmentFile(file)
460
+ if (!read.ok) {
461
+ process.stderr.write(`${read.issues.join('\n')}\n`)
462
+ return EXIT.declaration
463
+ }
464
+
465
+ const validation = validateEnvironment(read.value)
466
+ if (!validation.ok) {
467
+ if (options.json) {
468
+ process.stdout.write(
469
+ `${JSON.stringify({ ok: false, mode: 'static', file, issues: validation.issues, notes: validation.notes }, null, 2)}\n`,
470
+ )
471
+ } else {
472
+ process.stderr.write(`环境声明无效:${file}\n${validation.issues.map((issue) => `- ${issue}`).join('\n')}\n`)
473
+ }
474
+ return EXIT.declaration
473
475
  }
474
- return EXIT.declaration
475
- }
476
476
 
477
- if (!options.live) {
477
+ if (!options.live) {
478
+ if (options.json) {
479
+ process.stdout.write(
480
+ `${JSON.stringify({ ok: true, mode: 'static', file, environment: validation.axes, notes: validation.notes }, null, 2)}\n`,
481
+ )
482
+ } else {
483
+ process.stdout.write(
484
+ `环境声明合法:${file}\nhost=${validation.axes.host} build_host=${validation.axes.build_host} compiler=${validation.axes.compiler}\n`,
485
+ )
486
+ for (const note of validation.notes) process.stdout.write(`提示:${note}\n`)
487
+ }
488
+ return EXIT.ok
489
+ }
490
+
491
+ const live = checkLive(read.value, { platform: process.platform, env: process.env })
478
492
  if (options.json) {
479
- process.stdout.write(
480
- `${JSON.stringify({ ok: true, mode: 'static', file, environment: validation.axes, notes: validation.notes }, null, 2)}\n`,
481
- )
493
+ process.stdout.write(
494
+ `${JSON.stringify({ mode: 'live', file, ...live }, null, 2)}\n`,
495
+ )
482
496
  } else {
483
- process.stdout.write(
484
- `环境声明合法:${file}\nhost=${validation.axes.host} build_host=${validation.axes.build_host} compiler=${validation.axes.compiler}\n`,
485
- )
486
- for (const note of validation.notes) process.stdout.write(`提示:${note}\n`)
487
- }
488
- return EXIT.ok
489
- }
490
-
491
- const live = checkLive(read.value, { platform: process.platform, env: process.env })
492
- if (options.json) {
493
- process.stdout.write(
494
- `${JSON.stringify({ mode: 'live', file, ...live }, null, 2)}\n`,
495
- )
496
- } else {
497
- process.stdout.write(
498
- `环境活动校验:${file}\nhost=${validation.axes.host} build_host=${validation.axes.build_host} compiler=${validation.axes.compiler}\n`,
499
- )
500
- for (const check of live.checks) {
501
- const detail = check.version ?? check.detail ?? check.executable ?? ''
502
- process.stdout.write(`[${check.status}] ${check.role}${detail ? `: ${detail}` : ''}\n`)
503
- }
504
- for (const note of live.notes) process.stdout.write(`提示:${note}\n`)
505
- if (!live.ok) {
506
- process.stderr.write(`${live.issues.map((issue) => `- ${issue}`).join('\n')}\n`)
507
- }
508
- }
509
-
510
- return live.ok ? EXIT.ok : EXIT.live
497
+ process.stdout.write(
498
+ `环境活动校验:${file}\nhost=${validation.axes.host} build_host=${validation.axes.build_host} compiler=${validation.axes.compiler}\n`,
499
+ )
500
+ for (const check of live.checks) {
501
+ const detail = check.version ?? check.detail ?? check.executable ?? ''
502
+ process.stdout.write(`[${check.status}] ${check.role}${detail ? `: ${detail}` : ''}\n`)
503
+ }
504
+ for (const note of live.notes) process.stdout.write(`提示:${note}\n`)
505
+ if (!live.ok) {
506
+ process.stderr.write(`${live.issues.map((issue) => `- ${issue}`).join('\n')}\n`)
507
+ }
508
+ }
509
+
510
+ return live.ok ? EXIT.ok : EXIT.live
511
511
  }
512
512
 
513
513
  const isDirectRun =
514
- process.argv[1] !== undefined &&
515
- import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
514
+ process.argv[1] !== undefined &&
515
+ import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
516
516
 
517
517
  if (isDirectRun) {
518
- main(process.argv.slice(2))
519
- .then((code) => {
520
- process.exitCode = code
521
- })
522
- .catch((error) => {
523
- process.stderr.write(`检查器内部错误:${error.stack ?? error.message}\n`)
524
- process.exitCode = EXIT.script
525
- })
518
+ main(process.argv.slice(2))
519
+ .then((code) => {
520
+ process.exitCode = code
521
+ })
522
+ .catch((error) => {
523
+ process.stderr.write(`检查器内部错误:${error.stack ?? error.message}\n`)
524
+ process.exitCode = EXIT.script
525
+ })
526
526
  }
527
527
 
528
528
  export { main }