From 03f76371a2802cd3920bd6e17ecfe830a0e3c116 Mon Sep 17 00:00:00 2001 From: shulandmimi Date: Fri, 24 May 2024 16:26:22 +0800 Subject: [PATCH 1/2] chore: bump version --- .changeset/fresh-eagles-check.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fresh-eagles-check.md diff --git a/.changeset/fresh-eagles-check.md b/.changeset/fresh-eagles-check.md new file mode 100644 index 0000000..b97091c --- /dev/null +++ b/.changeset/fresh-eagles-check.md @@ -0,0 +1,5 @@ +--- +'farmup': patch +--- + +optimize build performance From c593603af37692c71fc649423fa654f0ae6008c3 Mon Sep 17 00:00:00 2001 From: shulandmimi Date: Fri, 24 May 2024 19:11:22 +0800 Subject: [PATCH 2/2] fix: config restart failed --- src/core/proxyCompiler/index.ts | 22 ++++++++++++++++++++-- src/core/proxyCompiler/util.ts | 4 +++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/core/proxyCompiler/index.ts b/src/core/proxyCompiler/index.ts index 7222fb9..4f20c28 100644 --- a/src/core/proxyCompiler/index.ts +++ b/src/core/proxyCompiler/index.ts @@ -10,8 +10,10 @@ export class ProxyCompiler { private lastResources: string[] = []; private _preProxyFnList: (keyof Compiler)[] = []; + private alreadyProxyFnList: Set = new Set(); start(compiler: Compiler) { + const isRestart = !!this.compiler; this.compiler = compiler; if (this._preProxyFnList.length) { @@ -21,6 +23,15 @@ export class ProxyCompiler { this._preProxyFnList = []; } + + if (isRestart) { + const proxyFnList = this.alreadyProxyFnList; + this.alreadyProxyFnList = new Set(); + for (const fnName of proxyFnList) { + this.proxyCompiler(fnName); + } + } + this.on('resources', (r) => { this.lastResources = Object.keys(r.result); }); @@ -30,11 +41,18 @@ export class ProxyCompiler { return this.lastResources; } - proxyCompiler(fnName: K) { + private proxyCompiler(fnName: K) { if (!this.compiler) { this._preProxyFnList.push(fnName); return; } + + if (this.alreadyProxyFnList.has(fnName)) { + return; + } + + this.alreadyProxyFnList.add(fnName); + // biome-ignore lint/suspicious/noExplicitAny: proxyCompilerFn(this.compiler, fnName, (...args: any[]) => this.event.emit(fnName, ...args)); } @@ -46,7 +64,7 @@ export class ProxyCompiler { OFT extends Record any> = { // biome-ignore lint/suspicious/noExplicitAny: [KK in keyof T]: T[KK] extends (...args: any[]) => any ? T[KK] : never; - }, + } >(fnName: K, fn: (context: FnContext, ReturnType>) => void) { this.proxyCompiler(fnName as keyof Compiler); this.event.on(fnName.toString(), fn); diff --git a/src/core/proxyCompiler/util.ts b/src/core/proxyCompiler/util.ts index 1109630..d790b36 100644 --- a/src/core/proxyCompiler/util.ts +++ b/src/core/proxyCompiler/util.ts @@ -3,8 +3,10 @@ import type { Compiler } from '@farmfe/core'; export function defineProperty(obj: O, key: K, value: V): V { const origin = obj[key]; + const descriptor = Object.getOwnPropertyDescriptor(obj, key); Object.defineProperty(obj, key, { value, + ...descriptor, }); return origin as V; @@ -19,7 +21,7 @@ export function proxyCompilerFn< }, K extends keyof OFT = keyof OFT, // biome-ignore lint/suspicious/noExplicitAny: - F extends (...args: any) => any = OFT[K], + F extends (...args: any) => any = OFT[K] >(compiler: T, fnName: K, callback: F) { const handler = ((...args: Parameters) => { const r = origin.bind(compiler)(...args);