From ae2ae5fcfd7a81a65f05a98c7c43787dec821c2c Mon Sep 17 00:00:00 2001 From: jmestxr Date: Thu, 17 Aug 2023 23:53:12 +0800 Subject: [PATCH 1/5] Implement Site.Prototype methods in ES6 syntax --- packages/core/src/Site/index.ts | 89 ++++++++++++--------------------- 1 file changed, 32 insertions(+), 57 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 9f2bc1684e..e518f8990c 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -191,9 +191,9 @@ export class Site { currentOpenedPages: string[]; toRebuild: Set; externalManager!: ExternalManager; - buildAsset?: (this: any, arg: unknown) => Bluebird; - rebuildAffectedSourceFiles?: (this: any, arg: unknown) => Bluebird; - rebuildSourceFiles?: (this: any, arg: unknown) => Bluebird; + // buildAsset?: (this: any, arg: unknown) => Bluebird; + // rebuildAffectedSourceFiles?: (this: any, arg: unknown) => Bluebird; + // rebuildSourceFiles?: (this: any, arg: unknown) => Bluebird; // TODO: add LayoutManager when it has been migrated layoutManager: any; @@ -690,6 +690,7 @@ export class Site { await this.writeSiteData(); this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString); if (this.backgroundBuildMode) { + // @ts-ignore this.backgroundBuildNotViewedFiles(); } } catch (error) { @@ -783,6 +784,7 @@ export class Site { await this.regenerateAffectedPages(uniquePaths); await fs.remove(this.tempPath); if (this.backgroundBuildMode) { + // @ts-ignore this.backgroundBuildNotViewedFiles(); } } catch (error) { @@ -870,6 +872,7 @@ export class Site { await this.removeAsset(removedPageFilePaths); await this.rebuildRequiredPages(); if (this.backgroundBuildMode) { + // @ts-ignore this.backgroundBuildNotViewedFiles(); } } catch (error) { @@ -947,6 +950,7 @@ export class Site { await this.handlePageReload(oldAddressablePages, oldPagesSrc, oldSiteConfig); await this.handleStyleReload(oldSiteConfig.style); if (this.backgroundBuildMode) { + // @ts-ignore this.backgroundBuildNotViewedFiles(); } } @@ -1678,58 +1682,29 @@ export class Site { this.variableProcessor.addUserDefinedVariableForAllSites('timestamp', time); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this - async rebuildPagesBeingViewed(_currentPageViewed: string) { - throw new Error('Method not implemented.'); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this - async removeAsset(_removedPageFilePaths: string | string[]) { - throw new Error('Method not implemented.'); - } - - // eslint-disable-next-line @typescript-eslint/no-unused-vars, class-methods-use-this - async backgroundBuildNotViewedFiles(_arg0?: any, _arg1?: any) { - throw new Error('Method not implemented.'); - } + /** + * Build/copy assets that are specified in filePaths + * @param filePaths a single path or an array of paths corresponding to the assets to build + */ + buildAsset = delay(this._buildMultipleAssets as () => Bluebird, 1000); + /** + * Remove assets that are specified in filePaths + * @param filePaths a single path or an array of paths corresponding to the assets to remove + */ + removeAsset = delay(this._removeMultipleAssets as () => Bluebird, 1000); + rebuildPagesBeingViewed = delay(this._rebuildPagesBeingViewed as () => Bluebird, 1000); + /** + * Rebuild pages that are affected by changes in filePaths + * @param filePaths a single path or an array of paths corresponding to the files that have changed + */ + rebuildAffectedSourceFiles = delay(this._rebuildAffectedSourceFiles as () => Bluebird, 1000); + /** + * Rebuild all pages + * @param filePaths a single path or an array of paths corresponding to the files that have changed + */ + rebuildSourceFiles = delay(this._rebuildSourceFiles as () => Bluebird, 1000); + /** + * Builds pages that are yet to build/rebuild in the background + */ + backgroundBuildNotViewedFiles = delay(this._backgroundBuildNotViewedFiles as () => Bluebird, 1000); } - -/** - * Below are functions that are not compatible with the ES6 class syntax. - */ - -/** - * Build/copy assets that are specified in filePaths - * @param filePaths a single path or an array of paths corresponding to the assets to build - */ -Site.prototype.buildAsset = delay(Site.prototype._buildMultipleAssets as () => Bluebird, 1000); - -Site.prototype.rebuildPagesBeingViewed = delay( - Site.prototype._rebuildPagesBeingViewed as () => Bluebird, 1000); - -/** - * Rebuild pages that are affected by changes in filePaths - * @param filePaths a single path or an array of paths corresponding to the files that have changed - */ -Site.prototype.rebuildAffectedSourceFiles = delay( - Site.prototype._rebuildAffectedSourceFiles as () => Bluebird, 1000); - -/** - * Rebuild all pages - * @param filePaths a single path or an array of paths corresponding to the files that have changed - */ -Site.prototype.rebuildSourceFiles = delay( - Site.prototype._rebuildSourceFiles as () => Bluebird, 1000); - -/** - * Remove assets that are specified in filePaths - * @param filePaths a single path or an array of paths corresponding to the assets to remove - */ -Site.prototype.removeAsset = delay( - Site.prototype._removeMultipleAssets as () => Bluebird, 1000); - -/** - * Builds pages that are yet to build/rebuild in the background - */ -Site.prototype.backgroundBuildNotViewedFiles = delay( - Site.prototype._backgroundBuildNotViewedFiles as () => Bluebird, 1000); From 3636f5eccca84d0eb3b68330b642b7f734f14732 Mon Sep 17 00:00:00 2001 From: jmestxr Date: Fri, 18 Aug 2023 00:03:37 +0800 Subject: [PATCH 2/5] Remove commented out code --- packages/core/src/Site/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index e518f8990c..9b30411d21 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -191,9 +191,6 @@ export class Site { currentOpenedPages: string[]; toRebuild: Set; externalManager!: ExternalManager; - // buildAsset?: (this: any, arg: unknown) => Bluebird; - // rebuildAffectedSourceFiles?: (this: any, arg: unknown) => Bluebird; - // rebuildSourceFiles?: (this: any, arg: unknown) => Bluebird; // TODO: add LayoutManager when it has been migrated layoutManager: any; From 979afbf33d0c0e4d61d019fb7df83f280c638502 Mon Sep 17 00:00:00 2001 From: jmestxr Date: Sat, 2 Sep 2023 14:56:00 +0800 Subject: [PATCH 3/5] Add explicit type casting to backgroundBuildNotViewedFiles --- packages/core/src/Site/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 9b30411d21..d01dc80a54 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -687,7 +687,6 @@ export class Site { await this.writeSiteData(); this.calculateBuildTimeForGenerate(startTime, lazyWebsiteGenerationString); if (this.backgroundBuildMode) { - // @ts-ignore this.backgroundBuildNotViewedFiles(); } } catch (error) { @@ -781,7 +780,6 @@ export class Site { await this.regenerateAffectedPages(uniquePaths); await fs.remove(this.tempPath); if (this.backgroundBuildMode) { - // @ts-ignore this.backgroundBuildNotViewedFiles(); } } catch (error) { @@ -869,7 +867,6 @@ export class Site { await this.removeAsset(removedPageFilePaths); await this.rebuildRequiredPages(); if (this.backgroundBuildMode) { - // @ts-ignore this.backgroundBuildNotViewedFiles(); } } catch (error) { @@ -947,7 +944,6 @@ export class Site { await this.handlePageReload(oldAddressablePages, oldPagesSrc, oldSiteConfig); await this.handleStyleReload(oldSiteConfig.style); if (this.backgroundBuildMode) { - // @ts-ignore this.backgroundBuildNotViewedFiles(); } } @@ -1703,5 +1699,6 @@ export class Site { /** * Builds pages that are yet to build/rebuild in the background */ - backgroundBuildNotViewedFiles = delay(this._backgroundBuildNotViewedFiles as () => Bluebird, 1000); + backgroundBuildNotViewedFiles + = delay(this._backgroundBuildNotViewedFiles as () => Bluebird, 1000) as () => Bluebird; } From 53b98a33fa79ffe46de6285f2b8d1eb3d25631da Mon Sep 17 00:00:00 2001 From: jmestxr Date: Sat, 2 Sep 2023 15:01:22 +0800 Subject: [PATCH 4/5] Amend calls to rebuildSourceFiles in serveUtil.js --- packages/cli/src/util/serveUtil.js | 4 ++-- packages/core/src/Site/index.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/util/serveUtil.js b/packages/cli/src/util/serveUtil.js index 7be339ca22..efede50764 100755 --- a/packages/cli/src/util/serveUtil.js +++ b/packages/cli/src/util/serveUtil.js @@ -26,7 +26,7 @@ const addHandler = (site, onePagePath) => (filePath) => { } Promise.resolve('').then(async () => { if (site.isFilepathAPage(filePath) || site.isDependencyOfPage(filePath)) { - return site.rebuildSourceFiles(filePath); + return site.rebuildSourceFiles(); } return site.buildAsset(filePath); }).catch((err) => { @@ -59,7 +59,7 @@ const removeHandler = (site, onePagePath) => (filePath) => { } Promise.resolve('').then(async () => { if (site.isFilepathAPage(filePath) || site.isDependencyOfPage(filePath)) { - return site.rebuildSourceFiles(filePath); + return site.rebuildSourceFiles(); } return site.removeAsset(filePath); }).catch((err) => { diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index d01dc80a54..3ea71b5ea8 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -1680,22 +1680,26 @@ export class Site { * @param filePaths a single path or an array of paths corresponding to the assets to build */ buildAsset = delay(this._buildMultipleAssets as () => Bluebird, 1000); + /** * Remove assets that are specified in filePaths * @param filePaths a single path or an array of paths corresponding to the assets to remove */ removeAsset = delay(this._removeMultipleAssets as () => Bluebird, 1000); rebuildPagesBeingViewed = delay(this._rebuildPagesBeingViewed as () => Bluebird, 1000); + /** * Rebuild pages that are affected by changes in filePaths * @param filePaths a single path or an array of paths corresponding to the files that have changed */ rebuildAffectedSourceFiles = delay(this._rebuildAffectedSourceFiles as () => Bluebird, 1000); + /** * Rebuild all pages - * @param filePaths a single path or an array of paths corresponding to the files that have changed */ - rebuildSourceFiles = delay(this._rebuildSourceFiles as () => Bluebird, 1000); + rebuildSourceFiles + = delay(this._rebuildSourceFiles as () => Bluebird, 1000) as () => Bluebird; + /** * Builds pages that are yet to build/rebuild in the background */ From b18857af2c38fbe4c0f9c862620e9828b3b361dd Mon Sep 17 00:00:00 2001 From: tlylt Date: Sat, 2 Sep 2023 20:42:27 +0800 Subject: [PATCH 5/5] add newline --- packages/core/src/Site/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/Site/index.ts b/packages/core/src/Site/index.ts index 3ea71b5ea8..02105a2a6e 100644 --- a/packages/core/src/Site/index.ts +++ b/packages/core/src/Site/index.ts @@ -1686,6 +1686,7 @@ export class Site { * @param filePaths a single path or an array of paths corresponding to the assets to remove */ removeAsset = delay(this._removeMultipleAssets as () => Bluebird, 1000); + rebuildPagesBeingViewed = delay(this._rebuildPagesBeingViewed as () => Bluebird, 1000); /**