diff --git a/package.json b/package.json index 205708fc..26fd9023 100644 --- a/package.json +++ b/package.json @@ -4,50 +4,17 @@ "license": "MIT", "type": "module", "exports": { - ".": { - "import": "./dist/core/index.js", - "types": "./dist/core/index.d.ts" - }, - "./cache-buster": { - "import": "./dist/cache-buster/index.js", - "types": "./dist/cache-buster/index.d.ts" - }, - "./cli": { - "import": "./dist/cli/index.js", - "types": "./dist/cli/index.d.ts" - }, - "./ffmpeg": { - "import": "./dist/ffmpeg/index.js", - "types": "./dist/ffmpeg/index.d.ts" - }, - "./image": { - "import": "./dist/image/index.js", - "types": "./dist/image/index.d.ts" - }, - "./json": { - "import": "./dist/json/index.js", - "types": "./dist/json/index.d.ts" - }, - "./manifest": { - "import": "./dist/manifest/index.js", - "types": "./dist/manifest/index.d.ts" - }, - "./pixi": { - "import": "./dist/pixi/index.js", - "types": "./dist/pixi/index.d.ts" - }, - "./spine": { - "import": "./dist/spine/index.js", - "types": "./dist/spine/index.d.ts" - }, - "./texture-packer": { - "import": "./dist/texture-packer/index.js", - "types": "./dist/texture-packer/index.d.ts" - }, - "./webfont": { - "import": "./dist/webfont/index.js", - "types": "./dist/webfont/index.d.ts" - } + ".": "./dist/core/index.js", + "./cache-buster": "./dist/cache-buster/index.js", + "./cli": "./dist/cli/index.js", + "./ffmpeg": "./dist/ffmpeg/index.js", + "./image": "./dist/image/index.js", + "./json": "./dist/json/index.js", + "./manifest": "./dist/manifest/index.js", + "./pixi": "./dist/pixi/index.js", + "./spine": "./dist/spine/index.js", + "./texture-packer": "./dist/texture-packer/index.js", + "./webfont": "./dist/webfont/index.js" }, "main": "dist/core/index.js", "module": "dist/core/index.js", diff --git a/src/core/Asset.ts b/src/core/Asset.ts index 8766a6e7..77e9f432 100644 --- a/src/core/Asset.ts +++ b/src/core/Asset.ts @@ -237,5 +237,17 @@ export class Asset this.transformChildren[i].releaseBuffers(); } } + + /** + * Release all buffers from this asset and its children + */ + releaseChildrenBuffers() + { + this.releaseBuffers(); + for (let i = 0; i < this.children.length; i++) + { + this.children[i].releaseChildrenBuffers(); + } + } } diff --git a/src/core/AssetPack.ts b/src/core/AssetPack.ts index 100603c3..89a54880 100644 --- a/src/core/AssetPack.ts +++ b/src/core/AssetPack.ts @@ -130,6 +130,9 @@ export class AssetPack // write back to the cache... await (assetCache as AssetCache).write(root); + // release the buffers from the cache + root.releaseChildrenBuffers(); + Logger.info('cache updated.'); } } diff --git a/src/core/pipes/PipeSystem.ts b/src/core/pipes/PipeSystem.ts index 9961c55d..2e8e55f6 100644 --- a/src/core/pipes/PipeSystem.ts +++ b/src/core/pipes/PipeSystem.ts @@ -59,9 +59,6 @@ export class PipeSystem async transform(asset: Asset): Promise { await this._transform(asset, 0); - - // clean up any buffers still held for gc! - asset.releaseBuffers(); } private async _transform(asset: Asset, pipeIndex = 0): Promise diff --git a/test/core/Assetpack.test.ts b/test/core/Assetpack.test.ts index 7879611e..3fa84e3a 100644 --- a/test/core/Assetpack.test.ts +++ b/test/core/Assetpack.test.ts @@ -93,7 +93,7 @@ describe('Core', () => const assetpack = new AssetPack({ entry: inputDir, cacheLocation: getCacheDir(pkg, testName), output: outputDir, - cache: false, + cache: true, }); await assetpack.watch(); @@ -109,6 +109,7 @@ describe('Core', () => expect(existsSync(join(outputDir, 'new-json-file.json'))).toBe(true); expect(existsSync(join(outputDir, 'json.json'))).toBe(true); + fs.writeJSONSync(join(inputDir, 'json.json'), { nice: 'test' }); fs.removeSync(testFile); @@ -121,6 +122,7 @@ describe('Core', () => expect(existsSync(join(outputDir, 'new-json-file.json'))).toBe(false); expect(existsSync(join(outputDir, 'json.json'))).toBe(true); + expect(fs.readJSONSync(join(outputDir, 'json.json'))).toStrictEqual({ nice: 'test' }); }); it('should ignore specified files when watching', async () =>