From ad45ea8a0b9733dac463f55ff3d99ec17d410896 Mon Sep 17 00:00:00 2001 From: Tancredi Trugenberger Date: Mon, 8 Feb 2021 19:30:56 +0000 Subject: [PATCH 1/2] Pass default null (timestamp) option to 'tts' generator to avoid creating unnecessary builds --- src/generators/asset-types/__tests__/ttf.ts | 9 ++++++--- src/generators/asset-types/ttf.ts | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/generators/asset-types/__tests__/ttf.ts b/src/generators/asset-types/__tests__/ttf.ts index 291e7f98..e11255f7 100644 --- a/src/generators/asset-types/__tests__/ttf.ts +++ b/src/generators/asset-types/__tests__/ttf.ts @@ -25,15 +25,18 @@ describe('`TTF` font generator', () => { const result = await ttfGen.generate(mockOptions(), svg); expect(svg2ttf).toHaveBeenCalledTimes(1); - expect(svg2ttf).toHaveBeenCalledWith(svg, { __mock: 'options__' }); + expect(svg2ttf).toHaveBeenCalledWith(svg, { + ts: null, + __mock: 'options__' + }); expect(result).toEqual(Buffer.from(`::ttf(${svg})::`)); }); - test('passes correctly format options to `svg2ttf`', async () => { + test('passes correctly format options to `svg2ttf` and sets `ts` (timestamp) to `null` by default to avoid generating unnecessary diffs', async () => { const formatOptions = { foo: 'bar' }; await ttfGen.generate(mockOptions(formatOptions), svg); expect(svg2ttf).toHaveBeenCalledTimes(1); - expect(svg2ttf.mock.calls[0][1]).toEqual(formatOptions); + expect(svg2ttf.mock.calls[0][1]).toEqual({ ts: null, ...formatOptions }); }); }); diff --git a/src/generators/asset-types/ttf.ts b/src/generators/asset-types/ttf.ts index 4e7a23db..74fdaf97 100644 --- a/src/generators/asset-types/ttf.ts +++ b/src/generators/asset-types/ttf.ts @@ -6,7 +6,7 @@ const generator: FontGenerator = { dependsOn: FontAssetType.SVG, async generate({ formatOptions }, svg) { - const font = svg2ttf(svg, formatOptions?.ttf); + const font = svg2ttf(svg, { ts: null, ...(formatOptions?.ttf || {}) }); return Buffer.from(font.buffer); } }; From ea4ad73640b44c73cd566c75d30361dc35c15a92 Mon Sep 17 00:00:00 2001 From: Tancredi Trugenberger Date: Mon, 8 Feb 2021 20:14:16 +0000 Subject: [PATCH 2/2] Use '0', not 'null' --- src/generators/asset-types/__tests__/ttf.ts | 6 +++--- src/generators/asset-types/ttf.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generators/asset-types/__tests__/ttf.ts b/src/generators/asset-types/__tests__/ttf.ts index e11255f7..f756d171 100644 --- a/src/generators/asset-types/__tests__/ttf.ts +++ b/src/generators/asset-types/__tests__/ttf.ts @@ -26,17 +26,17 @@ describe('`TTF` font generator', () => { expect(svg2ttf).toHaveBeenCalledTimes(1); expect(svg2ttf).toHaveBeenCalledWith(svg, { - ts: null, + ts: 0, __mock: 'options__' }); expect(result).toEqual(Buffer.from(`::ttf(${svg})::`)); }); - test('passes correctly format options to `svg2ttf` and sets `ts` (timestamp) to `null` by default to avoid generating unnecessary diffs', async () => { + test('passes correctly format options to `svg2ttf` and sets `ts` (timestamp) to `0` by default to avoid generating unnecessary diffs', async () => { const formatOptions = { foo: 'bar' }; await ttfGen.generate(mockOptions(formatOptions), svg); expect(svg2ttf).toHaveBeenCalledTimes(1); - expect(svg2ttf.mock.calls[0][1]).toEqual({ ts: null, ...formatOptions }); + expect(svg2ttf.mock.calls[0][1]).toEqual({ ts: 0, ...formatOptions }); }); }); diff --git a/src/generators/asset-types/ttf.ts b/src/generators/asset-types/ttf.ts index 74fdaf97..69662f09 100644 --- a/src/generators/asset-types/ttf.ts +++ b/src/generators/asset-types/ttf.ts @@ -6,7 +6,7 @@ const generator: FontGenerator = { dependsOn: FontAssetType.SVG, async generate({ formatOptions }, svg) { - const font = svg2ttf(svg, { ts: null, ...(formatOptions?.ttf || {}) }); + const font = svg2ttf(svg, { ts: 0, ...(formatOptions?.ttf || {}) }); return Buffer.from(font.buffer); } };