update
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package",
|
||||
"name": "@kevisual/router",
|
||||
"version": "0.0.61",
|
||||
"version": "0.0.62",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"main": "./dist/router.js",
|
||||
|
||||
@@ -614,8 +614,7 @@ export class QueryRouter {
|
||||
}
|
||||
/**
|
||||
* 等待程序运行, 获取到message的数据,就执行
|
||||
* params 是预设参数,默认path为main
|
||||
*
|
||||
* params 是预设参数
|
||||
* emitter = process
|
||||
* -- .exit
|
||||
* -- .on
|
||||
|
||||
@@ -3,7 +3,8 @@ import { Mini } from "../route.ts";
|
||||
const app = new Mini();
|
||||
|
||||
app.route({
|
||||
path: 'main'
|
||||
path: 'main',
|
||||
id: 'abc'
|
||||
}).define(async (ctx) => {
|
||||
ctx.body = {
|
||||
a: '123'
|
||||
|
||||
@@ -51,6 +51,7 @@ export const runCode = async (tsPath: string, params: RunCodeParams = {}): Promi
|
||||
import path from 'node:path'
|
||||
const res =await runCode(path.join(process.cwd(), './src/test/mini.ts'), {
|
||||
// path: 'main'
|
||||
// id: 'abc'
|
||||
})
|
||||
|
||||
console.log('res', res)
|
||||
@@ -71,12 +71,19 @@ export const listenProcess = async ({ app, mockProcess, params, timeout = 10 * 6
|
||||
* 如果不提供path,默认是main
|
||||
*/
|
||||
const {
|
||||
path = 'main',
|
||||
payload = {},
|
||||
...rest
|
||||
} = await getParams()
|
||||
const msg = { ...params, ...rest, payload: { ...params?.payload, ...payload } }
|
||||
/**
|
||||
* 如果没有提供path和id,默认取第一个路由, 而且路由path不是router的
|
||||
*/
|
||||
if (!msg.path && !msg.id) {
|
||||
const route = app.routes.find(r => r.path !== 'router')
|
||||
msg.id = route?.id
|
||||
}
|
||||
// 执行主要逻辑
|
||||
const result = await app.run({ path, ...params, ...rest, payload: { ...params?.payload, ...payload } })
|
||||
const result = await app.run(msg)
|
||||
// 发送结果回主进程
|
||||
const response = {
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user