From c5f59f005162f409b5bca933c5514710b5fe7e4b Mon Sep 17 00:00:00 2001 From: Ruslan Hrabovyi Date: Thu, 2 Aug 2018 10:10:20 +0300 Subject: [PATCH] pass a filepath to svgo.optimize() in order to support prefixIds svgo rule. @see: https://github.com/svg/svgo/pull/700 --- packages/broccoli-svg-optimizer/index.js | 4 ++-- .../tests/index-test.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/broccoli-svg-optimizer/index.js b/packages/broccoli-svg-optimizer/index.js index eb70704f..fc856394 100644 --- a/packages/broccoli-svg-optimizer/index.js +++ b/packages/broccoli-svg-optimizer/index.js @@ -52,9 +52,9 @@ class SVGOFilter extends PersistentFilter { this.optionsHash = stringify(options); } - processString(svg) { + processString(svg, relativePath) { return svg - ? this.optimize(svg).then(({ data }) => data) + ? this.optimize(svg, { path: relativePath }).then(({ data }) => data) : Promise.resolve(''); } diff --git a/packages/broccoli-svg-optimizer/tests/index-test.js b/packages/broccoli-svg-optimizer/tests/index-test.js index 6c8e91b6..c04d3165 100644 --- a/packages/broccoli-svg-optimizer/tests/index-test.js +++ b/packages/broccoli-svg-optimizer/tests/index-test.js @@ -133,4 +133,24 @@ describe('broccoli-svg-optimizer', () => { let outputNode = fixture.build(new SVGOptimizer(inputNode, options)); return expect(outputNode).to.be.rejectedWith('promise error'); }); + + it('passes file to optimize', () => { + class CustomSVGO { + optimize(svg, options) { + return Promise.resolve({ data: options && options.path }); + } + } + + let options = { + svgoConfig: {}, + svgoModule: CustomSVGO, + persist: false + }; + + let outputNode = fixture.build(new SVGOptimizer(inputNode, options)); + + return expect(outputNode).to.eventually.deep.equal({ + 'test.svg': 'test.svg' + }); + }); });