From d2802318de2e9e8e3f0e16bfd4c678ac4f45817e Mon Sep 17 00:00:00 2001 From: Shigma Date: Tue, 20 Feb 2024 00:58:13 +0800 Subject: [PATCH] feat(loader): rename `fullReload` to exit --- packages/hmr/src/index.ts | 4 ++-- packages/loader/src/index.ts | 4 +++- packages/loader/src/shared.ts | 5 ++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/hmr/src/index.ts b/packages/hmr/src/index.ts index 07312f5..24eca1c 100644 --- a/packages/hmr/src/index.ts +++ b/packages/hmr/src/index.ts @@ -106,7 +106,7 @@ class Watcher extends Service { if (isEntry) { if (this.ctx.loader.internal!.loadCache.has(filename)) { - this.ctx.loader.fullReload() + this.ctx.loader.exit() } else { const config = await loader.readConfig() this.ctx.root.state.update(config) @@ -114,7 +114,7 @@ class Watcher extends Service { } } else { if (this.externals.has(filename)) { - this.ctx.loader.fullReload() + this.ctx.loader.exit() } else if (this.ctx.loader.internal!.loadCache.has(filename)) { this.stashed.add(filename) triggerLocalReload() diff --git a/packages/loader/src/index.ts b/packages/loader/src/index.ts index 5b54f59..ea354af 100644 --- a/packages/loader/src/index.ts +++ b/packages/loader/src/index.ts @@ -14,6 +14,8 @@ namespace NodeLoader { } class NodeLoader extends Loader { + static readonly exitCode = 51 + async readConfig() { // restore process.env for (const key in process.env) { @@ -50,7 +52,7 @@ class NodeLoader extends Loader { } } - fullReload(code = Loader.exitCode) { + exit(code = NodeLoader.exitCode) { const body = JSON.stringify(this.envData) process.send?.({ type: 'shared', body }, (err: any) => { if (err) this.app.emit('internal/error', 'failed to send shared data') diff --git a/packages/loader/src/shared.ts b/packages/loader/src/shared.ts index 2dfa938..b51796c 100644 --- a/packages/loader/src/shared.ts +++ b/packages/loader/src/shared.ts @@ -63,8 +63,6 @@ export namespace Loader { } } - static readonly exitCode = 51 - export abstract class Loader extends Service { // process public baseDir = process.cwd() @@ -86,7 +84,6 @@ export abstract class Loader extends private store = new WeakMap() abstract import(name: string): Promise - abstract fullReload(code?: number): void constructor(public app: Context, public options: T) { super(app, 'loader', true) @@ -278,6 +275,8 @@ export abstract class Loader extends unwrapExports(module: any) { return module?.default || module } + + exit() {} } export function group(ctx: Context, config: Entry[]) {