Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Context {
[symbols.intercept]: Dict
/** @experimental */
root: this
baseUrl?: string
baseUrl: string | undefined
events: EventsService
logger: LoggerService
reflect: ReflectService
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class EventsService {

on(name: string | symbol, listener: (...args: any) => any, options?: boolean | EventOptions) {
if (typeof options !== 'object') {
options = { prepend: options }
options = options === undefined ? {} : { prepend: options }
}

// handle special events
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class LoggerService {
name ??= hyphenate(fiber.name)
return new Logger({
name,
level: config.level,
...(config.level === undefined ? {} : { level: config.level }),
meta: { fiber: new WeakRef(fiber) },
}, this)
}
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/reflect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ export class ReflectService {

this.ctx.root[symbols.isolate][name] ??= Symbol(name)
const key = this.ctx[symbols.isolate][name]
const impl: Impl = { name, value, fiber: this.ctx.fiber, check }
const impl: Impl = {
name,
fiber: this.ctx.fiber,
...(value === undefined ? {} : { value }),
...(check === undefined ? {} : { check }),
}
if (this.store[key]) {
throw new Error(`service "${name}" has been registered at <${this.store[key].fiber.name}>`)
}
Expand Down
15 changes: 13 additions & 2 deletions packages/core/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ export class RegistryService {
}

inject(inject: Inject, callback: Plugin.Function<void>) {
return this.plugin({ inject, apply: callback, name: callback.name })
const name = callback.name
return this.plugin({
inject,
apply: callback,
...(name === undefined ? {} : { name }),
})
}

plugin(plugin: Plugin, config?: any, getOuterStack = buildOuterStack()) {
Expand All @@ -200,7 +205,13 @@ export class RegistryService {
if (!runtime) {
let name = plugin.name
if (name === 'apply') name = undefined
runtime = { name, callback, fibers: new DisposableList(), Config: plugin.Config }
const Config = plugin.Config
runtime = {
callback,
fibers: new DisposableList(),
...(name === undefined ? {} : { name }),
...(Config === undefined ? {} : { Config }),
}
this._internal.set(callback, runtime)
}

Expand Down
12 changes: 9 additions & 3 deletions packages/hmr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ class Hmr extends Service {
if (!dependencies.some(dep => this.accepted.has(dep))) continue
dependencies.forEach(dep => this.accepted.add(dep))

const runtime = this.ctx.registry.get(plugin)
reloads.set(plugin, {
filename: job.url,
runtime: this.ctx.registry.get(plugin),
...(runtime === undefined ? {} : { runtime }),
})
}

Expand Down Expand Up @@ -332,8 +333,13 @@ class Hmr extends Service {
if (!runtime) return
for (const oldFiber of runtime.fibers) {
const fiber = oldFiber.parent.registry.plugin(plugin, oldFiber.config, this.getOuterStack)
fiber.entry = oldFiber.entry
if (fiber.entry) fiber.entry.fiber = fiber
const entry = oldFiber.entry
if (entry === undefined) {
delete fiber.entry
} else {
fiber.entry = entry
entry.fiber = fiber
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/include/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class Include extends EntryTree {
private writeFile(config: EntryOptions[]) {
clearTimeout(this.writeTask)
this.writeTask = setTimeout(() => {
this.writeTask = undefined
delete this.writeTask
this._writeFile(config)
}, 0)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/loader/src/config/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class Entry {
try {
await (this._initTask ??= this._init())
} finally {
this._initTask = undefined
delete this._initTask
}
this.fiber?.await().finally(() => {
if (this.loader.getTasks().length) return
Expand All @@ -163,7 +163,7 @@ export class Entry {
this.ctx.logger.error(error)
return
} finally {
this._initTask = undefined
delete this._initTask
}
const plugin = this.loader.unwrapExports(exports)
this._patchContext([])
Expand Down
2 changes: 1 addition & 1 deletion packages/logger-console/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('logger-console', () => {

it('format error', () => {
const inner = new Error('message')
inner.stack = undefined
delete inner.stack
const outer = new Error('outer')
;(outer as any).errors = [inner]
ctx.logger('test').error(outer)
Expand Down
1 change: 1 addition & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"skipLibCheck": true,
"allowImportingTsExtensions": true,
"strict": true,
"exactOptionalPropertyTypes": true,
"noImplicitAny": false,
"types": [
"node",
Expand Down