Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 14, 2021
2 parents 46a1709 + 89d014f commit a8bfe85
Show file tree
Hide file tree
Showing 54 changed files with 462 additions and 294 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ dist
temp
.koishi

/build/*.js
/tsconfig.temp.json

/addons
Expand All @@ -16,8 +15,6 @@ temp
/test
/utsuho

/build/*.js

todo.md
yarn.lock
node_modules/
Expand Down
25 changes: 12 additions & 13 deletions build/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ const KOISHI_VERSION = JSON.stringify(version)
const base = `${root}/${name}`
const entryPoints = [base + '/src/index.ts']

if (name === 'koishi') {
entryPoints.push(base + '/src/worker.ts')
} else if (name === 'plugin-eval') {
const loaders = await readdir(base + '/src/loaders')
entryPoints.push(base + '/src/worker/index.ts')
entryPoints.push(base + '/src/transfer.ts')
entryPoints.push(...loaders.map(name => `${base}/src/loaders/${name}`))
} else if (name === 'plugin-eval-addons') {
entryPoints.push(base + '/src/worker.ts')
} else if (name === 'koishi-test-utils') {
await tasks[chai]
}

let filter = /^[@/\w-]+$/
const options: BuildOptions = {
entryPoints,
Expand All @@ -84,6 +71,18 @@ const KOISHI_VERSION = JSON.stringify(version)
}],
}

if (name === 'koishi') {
entryPoints.push(base + '/src/worker.ts')
} else if (name === 'plugin-eval') {
const loaders = await readdir(base + '/src/loaders')
entryPoints.push(base + '/src/worker/index.ts')
entryPoints.push(base + '/src/transfer.ts')
entryPoints.push(...loaders.map(name => `${base}/src/loaders/${name}`))
options.define.BUILTIN_LOADERS = JSON.stringify(loaders.map(name => name.slice(0, -3)))
} else if (name === 'koishi-test-utils') {
await tasks[chai]
}

if (name !== 'plugin-eval') {
return tasks[name] = bundle(options)
}
Expand Down
38 changes: 26 additions & 12 deletions build/register.ts → build/register.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { install } from 'source-map-support'
import { transformSync, Message } from 'esbuild'
import { readFileSync } from 'fs'
const { install } = require('source-map-support')
const { transformSync } = require('esbuild')
const { readFileSync, readdirSync } = require('fs')
const { resolve } = require('path')

// hack for tests
if (process.env.TS_NODE_PROJECT) {
Expand All @@ -14,7 +15,8 @@ const ignored = [
'Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)',
]

const cache: Record<string, string> = {}
/** @type { Record<string, string> } */
const cache = {}

install({
handleUncaughtExceptions: true,
Expand All @@ -24,31 +26,43 @@ install({
},
})

const { version } = require('../packages/koishi-core/package.json')
const KOISHI_VERSION = JSON.stringify(version)

const prefix = '\u001B[35mwarning:\u001B[0m'

function reportWarnings({ location, text }: Message) {
/** @param { import('esbuild').Message } param0 */
function reportWarnings({ location, text }) {
if (ignored.includes(text)) return
if (!location) return console.log(prefix, text)
const { file, line, column } = location
console.log(`\u001B[34m${file}:${line}:${column}:\u001B[0m`, prefix, text)
}

// eslint-disable-next-line node/no-deprecated-api
const globalInjections = {
KOISHI_VERSION() {
return require('../packages/koishi-core/package.json').version
},
BUILTIN_LOADERS() {
const loaders = readdirSync(resolve(__dirname, '../packages/plugin-eval/src/loaders'))
return loaders.map(name => name.slice(0, -3))
},
}

require.extensions['.ts'] = (module, filename) => {
const source = readFileSync(filename, 'utf8')
/** @type { Record<string, string> } */
const define = {}
for (const key in globalInjections) {
if (source.includes(key)) {
define[key] = JSON.stringify(globalInjections[key]())
}
}
const { code, warnings } = transformSync(source, {
sourcefile: filename,
sourcemap: 'inline',
format: 'cjs',
loader: 'ts',
charset: 'utf8',
target: 'es2020',
define: {
KOISHI_VERSION,
},
define,
})
cache[filename] = code
warnings.forEach(reportWarnings)
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"scripts": {
"atri": "yarn workspace atri",
"addons": "yarn workspace addons",
"cli": "yarn workspace test koishi",
"cli": "yarn compile koishi && yarn workspace test koishi",
"build": "yarn compile && yarn dtsc",
"build:ci": "yarn build:reg && yarn build --listEmittedFiles && yarn build:web",
"build:reg": "esbuild build/register.ts --outdir=build --format=cjs --log-level=error",
"build:ci": "yarn compile && yarn compile && yarn compile && yarn dtsc --listEmittedFiles && yarn build:web",
"build:web": "node -r ./build/register packages/plugin-webui/build",
"dtsc": "node -r ./build/register build/dtsc",
"bump": "node -r ./build/register build/bump",
Expand All @@ -27,7 +26,6 @@
"test:json": "c8 -r json yarn test",
"test:html": "rimraf coverage && c8 -r html yarn test",
"test:text": "c8 -r text yarn test",
"test:reg": "yarn build:reg && yarn test:html",
"lint": "eslint packages/*/src/**/*.ts --fix --cache",
"pub": "yarn build && yarn build:web && node -r ./build/register build/publish",
"webui": "yarn workspace koishi-plugin-webui",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.8.0"
"koishi-core": "^3.9.0"
},
"devDependencies": {
"@types/ws": "^7.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-kaiheila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.8.0"
"koishi-core": "^3.9.0"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0-beta.11"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-onebot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.8.0"
"koishi-core": "^3.9.0"
},
"devDependencies": {
"@types/ws": "^7.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-telegram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.8.0"
"koishi-core": "^3.9.0"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0-beta.11"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-tomon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.8.0"
"koishi-core": "^3.9.0"
},
"devDependencies": {
"@types/pako": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-core",
"description": "Core features for Koishi",
"version": "3.8.0",
"version": "3.9.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion packages/koishi-core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ export class App extends Context {
this.options = merge(options, App.defaultConfig)
this.registry.set(null, {
parent: null,
context: null,
config: null,
children: [],
disposables: [],
dependencies: new Set(),
})

defineProperty(this, '_userCache', {})
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class Command<U extends User.Field = never, G extends Channel.Field = nev
const lastCall = this.app.options.prettyErrors && new Error().stack.split('\n', 4)[3]
try {
for (const validator of this._checkers) {
const result = validator.call(this, argv, ...args)
const result = await validator.call(this, argv, ...args)
if (typeof result === 'string') return result
}
const result = await this.app.serial(session, 'before-command', argv)
Expand Down
6 changes: 4 additions & 2 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ export namespace Plugin {

export interface State extends Meta {
parent: State
context: Context
config: Config<Plugin>
children: Plugin[]
disposables: Disposable[]
dependencies: Set<State>
}

export interface Packages {}
Expand Down Expand Up @@ -201,10 +202,11 @@ export class Context {
const ctx: this = Object.create(this)
defineProperty(ctx, '_plugin', plugin)
this.app.registry.set(plugin, {
context: this,
config: options,
parent: this.state,
children: [],
disposables: [],
dependencies: new Set([this.state]),
})

if (typeof plugin === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"koishi-core": "^3.8.0",
"koishi-core": "^3.9.0",
"koishi-utils": "^4.2.0"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/koishi/ecosystem.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"description": "COC / DND Tools for Koishi"
},
"koishi-plugin-eval": {
"version": "3.0.0-rc.1",
"version": "3.0.0",
"description": "Execute JavaScript in Koishi"
},
"koishi-plugin-github": {
Expand All @@ -56,14 +56,14 @@
"description": "Image searching plugin for Koishi"
},
"koishi-plugin-mongo": {
"version": "2.2.1",
"version": "2.2.2",
"description": "MongoDB support for Koishi"
},
"koishi-plugin-monitor": {
"version": "1.0.0-beta.29"
},
"koishi-plugin-mysql": {
"version": "3.3.0",
"version": "3.3.1",
"description": "MySQL support for Koishi"
},
"koishi-plugin-puppeteer": {
Expand All @@ -79,15 +79,15 @@
"description": "Schedule plugin for Koishi"
},
"koishi-plugin-teach": {
"version": "2.1.3",
"version": "2.1.4",
"description": "Teach plugin for Koishi"
},
"koishi-plugin-tools": {
"version": "2.1.1",
"description": "Some simple tools for Koishi"
},
"koishi-plugin-webui": {
"version": "4.2.0",
"version": "4.2.1",
"description": "Show Web UI of Koishi"
}
}
1 change: 1 addition & 0 deletions packages/koishi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface WatchConfig extends WatchOptions {
export interface AppConfig extends AppOptions {
plugins?: PluginConfig
logLevel?: LogLevel
logDiff?: boolean
logTime?: string | boolean
watch?: WatchConfig
}
6 changes: 4 additions & 2 deletions packages/koishi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi",
"description": "A QQ bot framework based on CQHTTP",
"version": "3.8.0",
"version": "3.9.0",
"main": "index.js",
"typings": "index.d.ts",
"engines": {
Expand Down Expand Up @@ -32,13 +32,15 @@
"koishi"
],
"devDependencies": {
"@types/js-yaml": "^4.0.0",
"@types/prompts": "^2.0.10"
},
"dependencies": {
"cac": "^6.7.2",
"chokidar": "^3.5.1",
"js-yaml": "^4.0.0",
"kleur": "^4.1.4",
"koishi-core": "^3.8.0",
"koishi-core": "^3.9.0",
"koishi-utils": "^4.2.0",
"prompts": "^2.4.1"
}
Expand Down
Loading

0 comments on commit a8bfe85

Please sign in to comment.