Skip to content

Commit

Permalink
fix: Errors resulting from identical TPS file names in different dir
Browse files Browse the repository at this point in the history
  • Loading branch information
h1ve2 committed Jan 24, 2025
1 parent 57aeca9 commit e2e7004
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/assetpack/src/texture-packer/texturePackerCacheBuster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function texturePackerCacheBuster(): AssetPipe<any, 'tps'>
return [asset];
},

async finish(asset: Asset)
async finish(asset: Asset, options, pipeSystem)
{
// first we retrieve the final transformed children - so the atlas files that have been copied
// to the output folder.
Expand All @@ -59,8 +59,21 @@ export function texturePackerCacheBuster(): AssetPipe<any, 'tps'>

const texture = json.meta.image;

const textureAssets = findAssets((asset) =>
asset.filename === texture, asset, true);
const textureAssets = findAssets((assetObj) =>
{
if (assetObj.filename !== texture) return false;

// check json & image file directory
let jsonDir = jsonAsset.directory.replaceAll(pipeSystem.outputPath, '');

jsonDir = jsonDir.replaceAll(/(^[\\\/])|([\\\/]$)/ig, '');

let dirName = assetObj.directory.replaceAll(/^.*(texture-packer|compress)[\/\\]?/ig, '');

dirName = dirName.replaceAll(/{.*}/ig, '');

return jsonDir === dirName;
}, asset, true);

// last transformed child is the renamed texture
const cacheBustedTexture = textureAssets[0].getFinalTransformedChildren()[0];
Expand Down

0 comments on commit e2e7004

Please sign in to comment.