From 32aa08fb5df908051f41d91cd56b00fa96fb5a32 Mon Sep 17 00:00:00 2001 From: Mat Groves Date: Mon, 29 Apr 2024 14:27:52 +0100 Subject: [PATCH] fix(cache buster): name tweak (#19) * cache bust at start of file * adjust cache naming --- packages/cache-buster/src/cacheBuster.ts | 18 ++++++++++++++++-- packages/spine/test/spineAtlasAll.test.ts | 16 ++++++++-------- .../test/texturePackerAll.test.ts | 12 ++++++------ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/packages/cache-buster/src/cacheBuster.ts b/packages/cache-buster/src/cacheBuster.ts index cc30d18..fe038e2 100644 --- a/packages/cache-buster/src/cacheBuster.ts +++ b/packages/cache-buster/src/cacheBuster.ts @@ -1,4 +1,4 @@ -import { createNewAssetAt, swapExt } from '@play-co/assetpack-core'; +import { createNewAssetAt, stripTags, swapExt } from '@play-co/assetpack-core'; import type { Asset, AssetPipe } from '@play-co/assetpack-core'; @@ -27,7 +27,21 @@ export function cacheBuster(): AssetPipe async transform(asset: Asset) { const hash = asset.hash; - const newFileName = swapExt(asset.filename, `-${hash}${asset.extension}`); + + // first try to stick the has on the end of the original file name + const originalFileName = swapExt(stripTags(asset.rootTransformAsset.filename), ''); + + let newFileName: string; + + if (asset.filename.includes(originalFileName)) + { + newFileName = asset.filename.replace(originalFileName, `${originalFileName}-${hash}`); + } + else + { + // failing that just stick it on the end! + newFileName = swapExt(asset.filename, `-${hash}${asset.extension}`); + } const newAsset = createNewAssetAt(asset, newFileName); diff --git a/packages/spine/test/spineAtlasAll.test.ts b/packages/spine/test/spineAtlasAll.test.ts index 0fe8030..6f4c95a 100644 --- a/packages/spine/test/spineAtlasAll.test.ts +++ b/packages/spine/test/spineAtlasAll.test.ts @@ -131,22 +131,22 @@ describe('Spine Atlas All', () => [ { - atlas: `dragon@0.5x.webp-gWXF6w.atlas`, - png1: `dragon@0.5x-7mmX8g.webp`, - png2: `dragon2@0.5x-k_22pw.webp` + atlas: `dragon-ZmGiUA@0.5x.webp.atlas`, + png1: `dragon-7mmX8g@0.5x.webp`, + png2: `dragon2-k_22pw@0.5x.webp` }, { - atlas: `dragon.webp-spj8.atlas`, + atlas: `dragon-spj8.webp.atlas`, png1: `dragon-rSwKOg.webp`, png2: `dragon2-ws3uhw.webp` }, { - atlas: `dragon@0.5x.png-jg5ydg.atlas`, - png1: `dragon@0.5x-3--s.png`, - png2: `dragon2@0.5x-vflfww.png` + atlas: `dragon-wstH@0.5x.png.atlas`, + png1: `dragon-3--s@0.5x.png`, + png2: `dragon2-vflfww@0.5x.png` }, { - atlas: `dragon.png-O471eg.atlas`, + atlas: `dragon-O471eg.png.atlas`, png1: `dragon-vezElA.png`, png2: `dragon2-3UnJNw.png` } diff --git a/packages/texture-packer/test/texturePackerAll.test.ts b/packages/texture-packer/test/texturePackerAll.test.ts index a73c09a..f5b44ab 100644 --- a/packages/texture-packer/test/texturePackerAll.test.ts +++ b/packages/texture-packer/test/texturePackerAll.test.ts @@ -79,20 +79,20 @@ describe('Texture Packer All', () => [ { - json: `sprites@0.5x.webp-1it4Qw.json`, - image: `sprites@0.5x-g_W8Sw.webp`, + json: `sprites-dvKKlQ@0.5x.webp.json`, + image: `sprites-g_W8Sw@0.5x.webp`, }, { - json: `sprites.webp-RCqjNQ.json`, + json: `sprites-RCqjNQ.webp.json`, image: `sprites-wXEUjA.webp`, }, { - json: `sprites@0.5x.png--5BuTA.json`, - image: `sprites@0.5x-TV3-Lg.png`, + json: `sprites-1Cv-Yg@0.5x.png.json`, + image: `sprites-TV3-Lg@0.5x.png`, }, { - json: `sprites.png-FYLGeg.json`, + json: `sprites-FYLGeg.png.json`, image: `sprites-Ef_oOA.png`, } ].forEach(({ json, image }) =>