@ranger1/dx 0.1.106 → 0.1.107
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/commands/core.js +46 -1
- package/lib/cli/dx-cli.js +1 -0
- package/lib/env.js +7 -3
- package/lib/exec.js +4 -1
- package/package.json +1 -1
package/lib/cli/commands/core.js
CHANGED
|
@@ -76,6 +76,7 @@ export async function handleTest(cli, args) {
|
|
|
76
76
|
// 解析 -t 参数用于指定特定测试用例(使用原始参数列表)
|
|
77
77
|
const allArgs = cli.args // 使用原始参数列表包含所有标志
|
|
78
78
|
const testNamePattern = resolveTestNamePattern(allArgs)
|
|
79
|
+
const passthroughArgs = resolvePassthroughArgs(allArgs)
|
|
79
80
|
|
|
80
81
|
// 根据测试类型自动设置环境标志
|
|
81
82
|
if (type === 'e2e' && !cli.flags.e2e) {
|
|
@@ -108,16 +109,24 @@ export async function handleTest(cli, args) {
|
|
|
108
109
|
process.exit(1)
|
|
109
110
|
}
|
|
110
111
|
|
|
112
|
+
const directTarget = resolveNxTargetDirectCommand(cli, fileCommand, ['test:e2e'])
|
|
111
113
|
const normalizedTestPath = normalizeE2eTestPathForCommand(cli, fileCommand, testPath)
|
|
112
|
-
let command =
|
|
114
|
+
let command = directTarget
|
|
115
|
+
? `${directTarget.command} ${shellEscape(normalizedTestPath)}`
|
|
116
|
+
: fileCommand.replace('{TEST_PATH}', shellEscape(normalizedTestPath))
|
|
113
117
|
|
|
114
118
|
if (testNamePattern) {
|
|
115
119
|
command += ` -t ${shellEscape(testNamePattern)}`
|
|
116
120
|
}
|
|
117
121
|
|
|
122
|
+
if (passthroughArgs.length > 0) {
|
|
123
|
+
command += ` ${passthroughArgs.map(shellEscape).join(' ')}`
|
|
124
|
+
}
|
|
125
|
+
|
|
118
126
|
testConfig = {
|
|
119
127
|
...testConfig,
|
|
120
128
|
command: command,
|
|
129
|
+
...(directTarget?.cwd ? { cwd: directTarget.cwd } : {}),
|
|
121
130
|
description: testNamePattern
|
|
122
131
|
? `运行单个E2E测试文件的特定用例: ${testPath} -> ${testNamePattern}`
|
|
123
132
|
: `运行单个E2E测试文件: ${testPath}`
|
|
@@ -142,6 +151,10 @@ export async function handleTest(cli, args) {
|
|
|
142
151
|
forwardedArgs.push(`-t ${shellEscape(testNamePattern)}`)
|
|
143
152
|
}
|
|
144
153
|
|
|
154
|
+
if (passthroughArgs.length > 0) {
|
|
155
|
+
forwardedArgs.push(...passthroughArgs.map(shellEscape))
|
|
156
|
+
}
|
|
157
|
+
|
|
145
158
|
command += ` ${forwardedArgs.join(' ')}`
|
|
146
159
|
|
|
147
160
|
testConfig = {
|
|
@@ -177,6 +190,12 @@ function resolveTestNamePattern(args = []) {
|
|
|
177
190
|
return null
|
|
178
191
|
}
|
|
179
192
|
|
|
193
|
+
function resolvePassthroughArgs(args = []) {
|
|
194
|
+
const index = args.indexOf('--')
|
|
195
|
+
if (index === -1) return []
|
|
196
|
+
return args.slice(index + 1)
|
|
197
|
+
}
|
|
198
|
+
|
|
180
199
|
function shouldUseDirectPathArg(command) {
|
|
181
200
|
const text = String(command || '')
|
|
182
201
|
return (
|
|
@@ -228,6 +247,32 @@ function normalizeE2eTestPathForCommand(cli, command, testPath) {
|
|
|
228
247
|
return relativePath
|
|
229
248
|
}
|
|
230
249
|
|
|
250
|
+
function resolveNxTargetDirectCommand(cli, command, targetNames = []) {
|
|
251
|
+
const projectRoot = cli?.projectRoot || process.cwd()
|
|
252
|
+
const nxResolution = extractNxTarget(command, targetNames)
|
|
253
|
+
if (!nxResolution) return null
|
|
254
|
+
|
|
255
|
+
const projectDir = join(projectRoot, 'apps', nxResolution.project)
|
|
256
|
+
const projectConfigPath = join(projectDir, 'project.json')
|
|
257
|
+
if (!existsSync(projectConfigPath)) return null
|
|
258
|
+
|
|
259
|
+
try {
|
|
260
|
+
const projectConfig = JSON.parse(readFileSync(projectConfigPath, 'utf8'))
|
|
261
|
+
const resolvedTarget = projectConfig?.targets?.[nxResolution.target]
|
|
262
|
+
const directCommand = resolvedTarget?.options?.command
|
|
263
|
+
if (typeof directCommand !== 'string' || directCommand.trim().length === 0) {
|
|
264
|
+
return null
|
|
265
|
+
}
|
|
266
|
+
const cwd = resolvedTarget?.options?.cwd
|
|
267
|
+
return {
|
|
268
|
+
command: directCommand.trim(),
|
|
269
|
+
cwd: typeof cwd === 'string' && cwd.trim().length > 0 ? cwd.trim() : null,
|
|
270
|
+
}
|
|
271
|
+
} catch {
|
|
272
|
+
return null
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
231
276
|
function resolveNxTargetProjectCwd(cli, command, targetNames = []) {
|
|
232
277
|
const projectRoot = cli?.projectRoot || process.cwd()
|
|
233
278
|
const nxResolution = extractNxTarget(command, targetNames)
|
package/lib/cli/dx-cli.js
CHANGED
package/lib/env.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
2
|
+
import { isAbsolute, join } from 'node:path'
|
|
3
3
|
|
|
4
4
|
function resolveProjectRoot() {
|
|
5
5
|
return process.env.DX_PROJECT_ROOT || process.cwd()
|
|
@@ -101,9 +101,13 @@ export class EnvManager {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
// 构建dotenv命令参数
|
|
104
|
-
buildEnvFlags(app, environment) {
|
|
104
|
+
buildEnvFlags(app, environment, options = {}) {
|
|
105
|
+
const absolute = Boolean(options.absolute)
|
|
105
106
|
return this.getResolvedEnvLayers(app, environment)
|
|
106
|
-
.map(layer =>
|
|
107
|
+
.map(layer => {
|
|
108
|
+
const envFile = absolute && !isAbsolute(layer) ? join(this.projectRoot, layer) : layer
|
|
109
|
+
return `-e ${envFile}`
|
|
110
|
+
})
|
|
107
111
|
.join(' ')
|
|
108
112
|
}
|
|
109
113
|
|
package/lib/exec.js
CHANGED
|
@@ -163,7 +163,10 @@ export class ExecManager {
|
|
|
163
163
|
logger.info(`dotenv层 ${envLabel}: ${layerSummary}`, '🌱')
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
const
|
|
166
|
+
const commandCwd = cwd || process.cwd()
|
|
167
|
+
const envFlags = envManager.buildEnvFlags(app, environment, {
|
|
168
|
+
absolute: commandCwd !== process.cwd(),
|
|
169
|
+
})
|
|
167
170
|
if (envFlags) {
|
|
168
171
|
// 对 build 命令禁用 dotenv 的 --override,避免覆盖我们显式传入的 NODE_ENV
|
|
169
172
|
const overrideFlag = isBuildCmdForWrapping ? '' : '--override'
|