Skip to content

Commit

Permalink
cache bust at start of file
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodBoyDigital committed Apr 29, 2024
1 parent c74d163 commit d00397d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
18 changes: 16 additions & 2 deletions packages/cache-buster/src/cacheBuster.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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);

Expand Down
16 changes: 8 additions & 8 deletions packages/spine/test/spineAtlasAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,22 @@ describe('Spine Atlas All', () =>

[
{
atlas: `[email protected]-gWXF6w.atlas`,
png1: `[email protected]-7mmX8g.webp`,
png2: `[email protected]-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: `[email protected]-jg5ydg.atlas`,
png1: `dragon@0.5x-3--s.png`,
png2: `[email protected]-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`
}
Expand Down
12 changes: 6 additions & 6 deletions packages/texture-packer/test/texturePackerAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ describe('Texture Packer All', () =>

[
{
json: `[email protected]-1it4Qw.json`,
image: `[email protected]-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: `[email protected]--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 }) =>
Expand Down

0 comments on commit d00397d

Please sign in to comment.