@cordisjs/core
Advanced tools
Comparing version 3.17.9 to 3.18.0
@@ -120,3 +120,3 @@ import { Awaitable, Dict, Promisify } from 'cosmokit'; | ||
inject(inject: Inject, callback: Plugin.Function<C, void>): ForkScope<C>; | ||
plugin(plugin: Plugin<C>, config?: any): ForkScope<C>; | ||
plugin(plugin: Plugin<C>, config?: any, error?: any): ForkScope<C>; | ||
} | ||
@@ -123,0 +123,0 @@ export interface Context { |
{ | ||
"name": "@cordisjs/core", | ||
"description": "Meta-Framework for Modern JavaScript Applications", | ||
"version": "3.17.9", | ||
"version": "3.18.0", | ||
"sideEffects": false, | ||
@@ -6,0 +6,0 @@ "type": "module", |
@@ -46,3 +46,3 @@ import { defineProperty, Dict, isNullable } from 'cosmokit' | ||
static handler: ProxyHandler<Context> = { | ||
get(target, prop, ctx: Context) { | ||
get: (target, prop, ctx: Context) => { | ||
if (typeof prop !== 'string') return Reflect.get(target, prop, ctx) | ||
@@ -54,3 +54,3 @@ | ||
const [name, internal] = ReflectService.resolveInject(ctx, prop) | ||
const [name, internal] = ReflectService.resolveInject(target, prop) | ||
// trace caller | ||
@@ -72,6 +72,6 @@ const error = new Error(`property ${name} is not registered, declare it as \`inject\` to suppress this warning`) | ||
set(target, prop, value, ctx: Context) { | ||
set: (target, prop, value, ctx: Context) => { | ||
if (typeof prop !== 'string') return Reflect.set(target, prop, value, ctx) | ||
const [name, internal] = ReflectService.resolveInject(ctx, prop) | ||
const [name, internal] = ReflectService.resolveInject(target, prop) | ||
if (!internal) { | ||
@@ -90,2 +90,9 @@ // TODO warning | ||
}, | ||
has: (target, prop) => { | ||
if (typeof prop !== 'string') return Reflect.has(target, prop) | ||
if (Reflect.has(target, prop)) return true | ||
const [, internal] = ReflectService.resolveInject(target, prop) | ||
return !!internal | ||
}, | ||
} | ||
@@ -143,3 +150,6 @@ | ||
if (isObject(value)) { | ||
defineProperty(value, symbols.source, ctx) | ||
try { | ||
// Frozen objects cannot be modified | ||
defineProperty(value, symbols.source, ctx) | ||
} catch {} | ||
} | ||
@@ -146,0 +156,0 @@ ctx.emit(self, 'internal/service', name, oldValue) |
@@ -164,3 +164,3 @@ import { defineProperty, Dict } from 'cosmokit' | ||
plugin(plugin: Plugin<C>, config?: any) { | ||
plugin(plugin: Plugin<C>, config?: any, error?: any) { | ||
// check if it's a valid plugin | ||
@@ -171,9 +171,10 @@ this.resolve(plugin, true) | ||
// resolve plugin config | ||
let error: any | ||
try { | ||
config = resolveConfig(plugin, config) | ||
} catch (reason) { | ||
this.context.emit(this.ctx, 'internal/error', reason) | ||
error = reason | ||
config = null | ||
if (!error) { | ||
try { | ||
config = resolveConfig(plugin, config) | ||
} catch (reason) { | ||
this.context.emit(this.ctx, 'internal/error', reason) | ||
error = reason | ||
config = null | ||
} | ||
} | ||
@@ -180,0 +181,0 @@ |
@@ -290,3 +290,9 @@ import { deepEqual, defineProperty, Dict, isNullable, remove } from 'cosmokit' | ||
if (state.config !== oldConfig) return | ||
const resolved = resolveConfig(this.runtime.plugin, config) | ||
let resolved: any | ||
try { | ||
resolved = resolveConfig(this.runtime.plugin, config) | ||
} catch (error) { | ||
this.context.emit('internal/error', error) | ||
return this.cancel(error) | ||
} | ||
const [hasUpdate, shouldRestart] = state.checkUpdate(resolved, forced) | ||
@@ -397,3 +403,9 @@ this.context.emit('internal/before-update', this, config) | ||
const oldConfig = this.config | ||
const resolved = resolveConfig(this.runtime.plugin || this.context.constructor, config) | ||
let resolved: any | ||
try { | ||
resolved = resolveConfig(this.runtime.plugin || this.context.constructor, config) | ||
} catch (error) { | ||
this.context.emit('internal/error', error) | ||
return this.cancel(error) | ||
} | ||
const [hasUpdate, shouldRestart] = this.checkUpdate(resolved, forced) | ||
@@ -400,0 +412,0 @@ const state = this.children.find(fork => fork.config === oldConfig) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
238192
4182