Skip to content

Commit 950847a

Browse files
authored
Fix filename template #77 (#78)
If the algorithm has a known name, pass it to the filename function Signed-off-by: solonovamax <[email protected]>
1 parent 0223cce commit 950847a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ function compression(
181181
let root: string = process.cwd()
182182

183183
const zlibs = algorithms.map(([algorithm, options]) => ({
184-
algorithm: typeof algorithm === 'string' ? ensureAlgorithm(algorithm).algorithm : algorithm,
184+
algorithm,
185+
algorithmFunction: typeof algorithm === 'string' ? ensureAlgorithm(algorithm).algorithm : algorithm,
185186
options,
186187
filename: filename ??
187188
(algorithm === 'brotliCompress' ? '[path][base].br' : algorithm === 'zstd' ? '[path][base].zst' : '[path][base].gz')
@@ -201,7 +202,7 @@ function compression(
201202
const z = zlibs[i]
202203
const flag = i === zlibs.length - 1
203204
const name = replaceFileName(fileName, z.filename, { options: z.options, algorithm: z.algorithm })
204-
const compressed = await compress(source, z.algorithm, z.options)
205+
const compressed = await compress(source, z.algorithmFunction, z.options)
205206
if (skipIfLargerOrEqual && len(compressed) >= size) { return }
206207
// #issue 30 31
207208
// https://rollupjs.org/plugin-development/#this-emitfile
@@ -270,7 +271,7 @@ function compression(
270271
for (let i = 0; i < zlibs.length; i++) {
271272
const z = zlibs[i]
272273
const flag = i === zlibs.length - 1
273-
const compressed = await compress(buf, z.algorithm, z.options)
274+
const compressed = await compress(buf, z.algorithmFunction, z.options)
274275
if (skipIfLargerOrEqual && len(compressed) >= len(buf)) {
275276
if (!pluginContext.staticOutputs.has(file)) { pluginContext.staticOutputs.add(file) }
276277
return

0 commit comments

Comments
 (0)