specflow-dev-service 0.0.0-beta.2 → 0.0.0-beta.4
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/dist/runner/client.js +27 -2
- package/dist/runner/client.js.map +1 -1
- package/package.json +1 -1
package/dist/runner/client.js
CHANGED
|
@@ -3,13 +3,38 @@
|
|
|
3
3
|
var node_path = require('node:path');
|
|
4
4
|
var spawn = require('cross-spawn');
|
|
5
5
|
|
|
6
|
+
/** 常见前端 dev 工具及其 --port 参数名 */
|
|
7
|
+
const DEV_TOOLS = [['rspkify', '--port'], ['rspack', '--port'], ['vite', '--port'], ['webpack-dev-server', '--port'], ['webpack serve', '--port']];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 自动注入 port 参数到 dev 命令
|
|
11
|
+
* - 已含 ${PORT} / --port 的不重复注入
|
|
12
|
+
*/
|
|
13
|
+
function injectDevPort(cmd, port) {
|
|
14
|
+
// 替换 ${PORT} 占位符
|
|
15
|
+
let result = cmd.replace(/\$\{PORT\}/g, String(port));
|
|
16
|
+
// 已有 --port 参数,不重复注入
|
|
17
|
+
if (/\b--port\b/.test(result)) return result;
|
|
18
|
+
// 匹配已知工具 → 追加 --port <port>
|
|
19
|
+
for (const [tool, flag] of DEV_TOOLS) {
|
|
20
|
+
if (result.includes(tool)) {
|
|
21
|
+
return `${result} ${flag} ${port}`;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
6
26
|
function startClient(config) {
|
|
7
27
|
const cwd = node_path.resolve(config.dir || 'client');
|
|
8
|
-
const
|
|
28
|
+
const port = config.port ?? 3000;
|
|
29
|
+
const cmd = injectDevPort(config.dev || 'npm run dev', port);
|
|
9
30
|
const child = spawn(cmd, [], {
|
|
10
31
|
cwd,
|
|
11
32
|
stdio: 'inherit',
|
|
12
|
-
shell: true
|
|
33
|
+
shell: true,
|
|
34
|
+
env: {
|
|
35
|
+
...process.env,
|
|
36
|
+
PORT: String(port)
|
|
37
|
+
}
|
|
13
38
|
});
|
|
14
39
|
return {
|
|
15
40
|
child,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sources":["../../src/runner/client.ts"],"sourcesContent":["import { resolve } from 'node:path';\n\nimport spawn from 'cross-spawn';\n\nimport type { ClientConfig } from '../config/schema';\nimport type { ChildProcess } from 'node:child_process';\n\nexport interface ClientHandle {\n child: ChildProcess;\n stop: () => void;\n}\n\nexport function startClient(config: ClientConfig): ClientHandle {\n const cwd = resolve(config.dir || 'client');\n const cmd = config.dev || 'npm run dev';\n\n const child = spawn(cmd, [], {\n cwd,\n stdio: 'inherit',\n shell: true,\n });\n\n return {\n child,\n stop: () => child.kill(),\n };\n}\n\nexport function stopClient(handle: ClientHandle): void {\n handle.stop();\n}\n"],"names":["startClient","config","cwd","resolve","dir","
|
|
1
|
+
{"version":3,"file":"client.js","sources":["../../src/runner/client.ts"],"sourcesContent":["import { resolve } from 'node:path';\n\nimport spawn from 'cross-spawn';\n\nimport type { ClientConfig } from '../config/schema';\nimport type { ChildProcess } from 'node:child_process';\n\nexport interface ClientHandle {\n child: ChildProcess;\n stop: () => void;\n}\n\n/** 常见前端 dev 工具及其 --port 参数名 */\nconst DEV_TOOLS: [string, string][] = [\n ['rspkify', '--port'],\n ['rspack', '--port'],\n ['vite', '--port'],\n ['webpack-dev-server', '--port'],\n ['webpack serve', '--port'],\n];\n\n/**\n * 自动注入 port 参数到 dev 命令\n * - 已含 ${PORT} / --port 的不重复注入\n */\nfunction injectDevPort(cmd: string, port: number): string {\n // 替换 ${PORT} 占位符\n let result = cmd.replace(/\\$\\{PORT\\}/g, String(port));\n // 已有 --port 参数,不重复注入\n if (/\\b--port\\b/.test(result)) return result;\n // 匹配已知工具 → 追加 --port <port>\n for (const [tool, flag] of DEV_TOOLS) {\n if (result.includes(tool)) {\n return `${result} ${flag} ${port}`;\n }\n }\n return result;\n}\n\nexport function startClient(config: ClientConfig): ClientHandle {\n const cwd = resolve(config.dir || 'client');\n const port = config.port ?? 3000;\n\n const cmd = injectDevPort(config.dev || 'npm run dev', port);\n\n const child = spawn(cmd, [], {\n cwd,\n stdio: 'inherit',\n shell: true,\n env: {\n ...process.env,\n PORT: String(port),\n },\n });\n\n return {\n child,\n stop: () => child.kill(),\n };\n}\n\nexport function stopClient(handle: ClientHandle): void {\n handle.stop();\n}\n"],"names":["DEV_TOOLS","injectDevPort","cmd","port","result","replace","String","test","tool","flag","includes","startClient","config","cwd","resolve","dir","dev","child","spawn","stdio","shell","env","process","PORT","stop","kill","stopClient","handle"],"mappings":";;;;;AAYA;AACA,MAAMA,SAA6B,GAAG,CACpC,CAAC,SAAS,EAAE,QAAQ,CAAC,EACrB,CAAC,QAAQ,EAAE,QAAQ,CAAC,EACpB,CAAC,MAAM,EAAE,QAAQ,CAAC,EAClB,CAAC,oBAAoB,EAAE,QAAQ,CAAC,EAChC,CAAC,eAAe,EAAE,QAAQ,CAAC,CAC5B;;AAED;AACA;AACA;AACA;AACA,SAASC,aAAaA,CAACC,GAAW,EAAEC,IAAY,EAAU;AACxD;AACA,EAAA,IAAIC,MAAM,GAAGF,GAAG,CAACG,OAAO,CAAC,aAAa,EAAEC,MAAM,CAACH,IAAI,CAAC,CAAC;AACrD;EACA,IAAI,YAAY,CAACI,IAAI,CAACH,MAAM,CAAC,EAAE,OAAOA,MAAM;AAC5C;EACA,KAAK,MAAM,CAACI,IAAI,EAAEC,IAAI,CAAC,IAAIT,SAAS,EAAE;AACpC,IAAA,IAAII,MAAM,CAACM,QAAQ,CAACF,IAAI,CAAC,EAAE;AACzB,MAAA,OAAO,GAAGJ,MAAM,CAAA,CAAA,EAAIK,IAAI,CAAA,CAAA,EAAIN,IAAI,CAAA,CAAE;AACpC,IAAA;AACF,EAAA;AACA,EAAA,OAAOC,MAAM;AACf;AAEO,SAASO,WAAWA,CAACC,MAAoB,EAAgB;EAC9D,MAAMC,GAAG,GAAGC,iBAAO,CAACF,MAAM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