Skip to content

Commit

Permalink
pass a filepath to svgo.optimize()
Browse files Browse the repository at this point in the history
in order to support prefixIds svgo rule.

@see: svg/svgo#700
  • Loading branch information
Ruslan Hrabovyi committed Aug 2, 2018
1 parent 9131619 commit c5f59f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/broccoli-svg-optimizer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}

Expand Down
20 changes: 20 additions & 0 deletions packages/broccoli-svg-optimizer/tests/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
});
});

0 comments on commit c5f59f0

Please sign in to comment.