Skip to content

Commit

Permalink
test: more hacks into tsconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 25, 2020
1 parent 5c56bc2 commit 8bf16d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions packages/plugin-eval/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ export class MainAPI {
}
}

process.env.WORKER_ENTRY = resolve(__dirname, 'worker.js')
process.env.WORKER_CODE = `\
process.env.KOISHI_WORKER_ENTRY = resolve(__dirname, 'worker.js')

process.env.KOISHI_WORKER_LOADER = `\
const { workerData } = require('worker_threads');
require(workerData.entry);`

Expand All @@ -97,10 +98,10 @@ export function apply(ctx: Context, config: Config = {}) {
async function createWorker() {
await app.parallel('worker/start')

const worker = app.evalWorker = new Worker(process.env.WORKER_CODE, {
const worker = app.evalWorker = new Worker(process.env.KOISHI_WORKER_LOADER, {
eval: true,
workerData: {
entry: process.env.WORKER_ENTRY,
entry: process.env.KOISHI_WORKER_ENTRY,
logLevels: Logger.levels,
...omit(config, ['maxLogs', 'resourceLimits', 'timeout', 'prohibitedCommands']),
},
Expand Down
8 changes: 5 additions & 3 deletions packages/plugin-eval/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { inspect } from 'util'
import { resolve } from 'path'
import * as _eval from 'koishi-plugin-eval'

process.env.WORKER_ENTRY = resolve(__dirname, '../src/worker.ts')
process.env.WORKER_CODE = [
process.env.KOISHI_WORKER_ENTRY = resolve(__dirname, '../src/worker.ts')

process.env.KOISHI_WORKER_LOADER = [
'require("ts-node/register/transpile-only");',
'require("tsconfig-paths/register");',
process.env.WORKER_CODE,
process.env.KOISHI_WORKER_LOADER,
].join('\n')

const app = new App()

app.plugin(_eval, {
setupFiles: {
'test-worker': resolve(__dirname, 'worker.ts'),
Expand Down
1 change: 1 addition & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"baseUrl": ".",
"paths": {
"koishi-plugin-*": ["packages/plugin-*/src"],
"koishi-plugin-eval/dist/worker": ["packages/plugin-eval/src/worker"],
"koishi-adapter-*": ["packages/adapter-*/src"],
"koishi-*": ["packages/koishi-*/src"],
},
Expand Down

0 comments on commit 8bf16d6

Please sign in to comment.