Skip to content

Commit

Permalink
fix(console): fix console.config collision, fix koishijs#275
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Dec 24, 2023
1 parent a0f458e commit 682d030
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 0 additions & 12 deletions packages/console/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ export abstract class Console extends Service {
ctx.plugin(SchemaProvider)
ctx.plugin(PermissionProvider)
this.addListener('ping', () => 'pong')
return new Proxy(this, {
get(target, key) {
if (typeof key === 'symbol' || key in target) return Reflect.get(target, key)
if (ctx[Context.internal][`console.${key}`]) return ctx.get(`console.${key}`)
return Reflect.get(target, key)
},
set(target, key, value) {
if (typeof key === 'symbol' || key in target) return Reflect.set(target, key, value)
if (ctx[Context.internal][`console.${key}`]) return Reflect.set(ctx, `console.${key}`, value)
return Reflect.set(target, key, value)
},
})
}

protected accept(socket: Universal.WebSocket, request?: IncomingMessage) {
Expand Down
14 changes: 13 additions & 1 deletion plugins/console/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ interface HeartbeatConfig {
class NodeConsole extends Console {
static inject = ['server']

// workaround for edge case (collision with @koishijs/plugin-config)
private _config: NodeConsole.Config

public vite: ViteDevServer
public root: string
public layer: WebSocketLayer

constructor(public ctx: Context, public config: NodeConsole.Config) {
constructor(public ctx: Context, config: NodeConsole.Config) {
super(ctx)
this.config = config

this.layer = ctx.server.ws(config.apiPath, (socket, request) => {
// @types/ws does not provide typings for `dispatchEvent`
Expand All @@ -54,6 +58,14 @@ class NodeConsole extends Console {
: resolve(__dirname, '../../dist'))
}

get config() {
return this._config
}

set config(value) {
this._config = value
}

createGlobal() {
const global = {} as ClientConfig
const { devMode, uiPath, apiPath, selfUrl, heartbeat } = this.config
Expand Down
6 changes: 3 additions & 3 deletions plugins/market/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ export function apply(ctx: Context, config: Config) {

ctx.console.addListener('market/install', async (deps, forced) => {
const code = await ctx.installer.install(deps, forced)
ctx.console.dependencies?.refresh()
ctx.console.registry?.refresh()
ctx.console.packages?.refresh()
ctx.get('console.dependencies')?.refresh()
ctx.get('console.registry')?.refresh()
ctx.get('console.packages')?.refresh()
return code
}, { authority: 4 })

Expand Down

0 comments on commit 682d030

Please sign in to comment.