Skip to content

Commit

Permalink
feat(loader): rename fullReload to exit
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 19, 2024
1 parent f77fb13 commit d280231
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/hmr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ 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)
this.ctx.emit('config')
}
} 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()
Expand Down
4 changes: 3 additions & 1 deletion packages/loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace NodeLoader {
}

class NodeLoader extends Loader<NodeLoader.Options> {
static readonly exitCode = 51

async readConfig() {
// restore process.env
for (const key in process.env) {
Expand Down Expand Up @@ -50,7 +52,7 @@ class NodeLoader extends Loader<NodeLoader.Options> {
}
}

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')
Expand Down
5 changes: 2 additions & 3 deletions packages/loader/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ export namespace Loader {
}
}

static readonly exitCode = 51

export abstract class Loader<T extends Loader.Options = Loader.Options> extends Service<Entry[]> {
// process
public baseDir = process.cwd()
Expand All @@ -86,7 +84,6 @@ export abstract class Loader<T extends Loader.Options = Loader.Options> extends
private store = new WeakMap<any, string>()

abstract import(name: string): Promise<any>
abstract fullReload(code?: number): void

constructor(public app: Context, public options: T) {
super(app, 'loader', true)
Expand Down Expand Up @@ -278,6 +275,8 @@ export abstract class Loader<T extends Loader.Options = Loader.Options> extends
unwrapExports(module: any) {
return module?.default || module
}

exit() {}
}

export function group(ctx: Context, config: Entry[]) {
Expand Down

0 comments on commit d280231

Please sign in to comment.