From 83f62ea5189e772db699c65a5297def4c548a548 Mon Sep 17 00:00:00 2001 From: wherewhere Date: Tue, 3 Dec 2024 17:26:45 +0800 Subject: [PATCH] fix: function for after_generate return void --- lib/json.js | 8 ++++---- lib/svg.js | 6 +++--- lib/xml.js | 6 +++--- lib/zlib.js | 11 ++++++----- lib/zstd.js | 6 +++--- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/json.js b/lib/json.js index cd83658..287ceaf 100644 --- a/lib/json.js +++ b/lib/json.js @@ -8,10 +8,10 @@ function minifyJson() { const route = hexo.route /** @type {string[]} */ const routeList = route.list() - const { globOptions, include, verbose, useBigInt } = options + const { globOptions, include, verbose } = options return Promise.all((match(routeList, include, globOptions)).map(path => { - return new Promise((/** @type {(value: string) => void} */ resolve, reject) => { + return new Promise((/** @type {(value: void) => void} */ resolve, reject) => { const assetPath = route.get(path) let assetTxt = '' assetPath.on('data', chunk => (assetTxt += chunk)) @@ -20,12 +20,12 @@ function minifyJson() { try { const result = JSON.stringify(JSON.parse(assetTxt)) if (verbose) logFn.call(this, assetTxt, result, path, 'json') - resolve(route.set(path, result)) + route.set(path, result) } catch (err) { reject(new Error(`Path: ${path}\n${err}`)) } } - resolve(assetTxt) + resolve() }) }) })) diff --git a/lib/svg.js b/lib/svg.js index d1f60d6..f8d478a 100644 --- a/lib/svg.js +++ b/lib/svg.js @@ -20,7 +20,7 @@ function minifySvg() { }] return Promise.all((match(routeList, include, globOptions)).map(path => { - return new Promise((/** @type {(value: string) => void} */ resolve, reject) => { + return new Promise((/** @type {(value: void) => void} */ resolve, reject) => { const assetPath = route.get(path) let assetTxt = '' assetPath.on('data', chunk => (assetTxt += chunk)) @@ -29,12 +29,12 @@ function minifySvg() { try { const data = svgOptimize(assetTxt, { ...options, plugins }).data if (verbose) logFn.call(this, assetTxt, data, path, 'svg') - resolve(route.set(path, data)) + route.set(path, data) } catch (err) { reject(new Error(`Path: ${path}\n${err}`)) } } - resolve(assetTxt) + resolve() }) }) })) diff --git a/lib/xml.js b/lib/xml.js index 985e2df..264345d 100644 --- a/lib/xml.js +++ b/lib/xml.js @@ -12,7 +12,7 @@ function minifyXml() { const { globOptions, include, verbose } = options return Promise.all((match(routeList, include, globOptions)).map(path => { - return new Promise((/** @type {(value: string) => void} */ resolve, reject) => { + return new Promise((/** @type {(value: void) => void} */ resolve, reject) => { const assetPath = route.get(path) let assetTxt = '' assetPath.on('data', chunk => (assetTxt += chunk)) @@ -21,12 +21,12 @@ function minifyXml() { try { const result = compressXml(assetTxt, { ...options }) if (verbose) logFn.call(this, assetTxt, result, path, 'xml') - resolve(route.set(path, result)) + route.set(path, result) } catch (err) { reject(new Error(`Path: ${path}\n${err}`)) } } - resolve(assetTxt) + resolve() }) }) })) diff --git a/lib/zlib.js b/lib/zlib.js index 0b26a29..cf1c5c2 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -17,7 +17,7 @@ function gzipFn() { if (typeof level !== 'number') level = zlib.constants.Z_BEST_COMPRESSION return Promise.all((match(routeList, include, globOptions)).map(path => { - return new Promise((/** @type {(value: string) => void} */ resolve, reject) => { + return new Promise((/** @type {(value: void) => void} */ resolve, reject) => { const assetPath = route.get(path) let assetTxt = '' assetPath.on('data', chunk => (assetTxt += chunk)) @@ -27,11 +27,12 @@ function gzipFn() { const result = await gzip(assetTxt, { level }) if (verbose) logFn.call(this, assetTxt, result, path, 'gzip') resolve(route.set(path + '.gz', result)) + return } catch (err) { reject(new Error(`Path: ${path}\n${err}`)) } } - resolve(assetTxt) + resolve() }) }) })) @@ -48,7 +49,7 @@ function brotliFn() { if (typeof level !== 'number') level = zlib.constants.BROTLI_MAX_QUALITY return Promise.all((match(routeList, include, globOptions)).map(path => { - return new Promise((/** @type {(value: string) => void} */ resolve, reject) => { + return new Promise((/** @type {(value: void) => void} */ resolve, reject) => { const assetPath = route.get(path) let assetTxt = '' assetPath.on('data', chunk => (assetTxt += chunk)) @@ -57,12 +58,12 @@ function brotliFn() { try { const result = await br(assetTxt, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: level } }) if (verbose) logFn.call(this, assetTxt, result, path, 'brotli') - resolve(route.set(path + '.br', result)) + route.set(path + '.br', result) } catch (err) { reject(new Error(`Path: ${path}\n${err}`)) } } - resolve(assetTxt) + resolve() }) }) })) diff --git a/lib/zstd.js b/lib/zstd.js index 435381b..3b95bfd 100644 --- a/lib/zstd.js +++ b/lib/zstd.js @@ -14,7 +14,7 @@ function zstdFn() { if (typeof level !== 'number') level = undefined return Promise.all((match(routeList, include, globOptions)).map(path => { - return new Promise((/** @type {(value: string) => void} */ resolve, reject) => { + return new Promise((/** @type {(value: void) => void} */ resolve, reject) => { const assetPath = route.get(path) let assetTxt = '' assetPath.on('data', chunk => (assetTxt += chunk)) @@ -24,12 +24,12 @@ function zstdFn() { const input = Buffer.from(assetTxt, 'utf-8') const result = await zstd(input, level) if (verbose) logFn.call(this, assetTxt, result, path, 'zstd') - resolve(route.set(path + '.zst', result)) + route.set(path + '.zst', result) } catch (err) { reject(new Error(`Path: ${path}\n${err}`)) } } - resolve(assetTxt) + resolve() }) }) }))