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