diff --git a/CHANGES.md b/CHANGES.md
index 4288b7e..c692dea 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,3 +1,9 @@
+## Version 0.3.2, 2017.11.21
+
+* Error being thrown caused by lost context for CLI [#24](https://github.com/NotNinja/convert-svg/issues/24)
+* Pass custom arguments to puppeteer [#25](https://github.com/NotNinja/convert-svg/issues/25) [#27](https://github.com/NotNinja/convert-svg/issues/27)
+* Bump puppeteer to v0.13.0 [#26](https://github.com/NotNinja/convert-svg/issues/26)
+
## Version 0.3.1, 2017.11.03
* Error thrown as context is lost for API methods when using destructuring imports [#22](https://github.com/NotNinja/convert-svg/issues/22)
diff --git a/lerna.json b/lerna.json
index 0989fdf..357ca4d 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,6 +1,6 @@
{
- "lerna": "2.4.0",
- "version": "0.3.1",
+ "lerna": "2.5.1",
+ "version": "0.3.2",
"packages": [
"packages/*"
],
diff --git a/package.json b/package.json
index 70409ec..65ecc05 100644
--- a/package.json
+++ b/package.json
@@ -2,9 +2,9 @@
"name": "convert-svg",
"license": "MIT",
"devDependencies": {
- "eslint": "^4.10.0",
+ "eslint": "^4.11.0",
"eslint-config-notninja": "^0.2.3",
- "lerna": "^2.4.0",
+ "lerna": "^2.5.1",
"mocha": "^4.0.1"
},
"scripts": {
diff --git a/packages/convert-svg-core/package.json b/packages/convert-svg-core/package.json
index 296ec5f..522ee8e 100644
--- a/packages/convert-svg-core/package.json
+++ b/packages/convert-svg-core/package.json
@@ -1,6 +1,6 @@
{
"name": "convert-svg-core",
- "version": "0.3.1",
+ "version": "0.3.2",
"description": "Supports converting SVG into another format using headless Chromium",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
@@ -30,15 +30,17 @@
"file-url": "^2.0.2",
"get-stdin": "^5.0.1",
"glob": "^7.1.2",
+ "lodash.omit": "^4.5.0",
+ "lodash.pick": "^4.4.0",
"pollock": "^0.1.0",
- "puppeteer": "^0.12.0",
+ "puppeteer": "^0.13.0",
"tmp": "0.0.33"
},
"devDependencies": {
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"mocha": "^4.0.1",
- "sinon": "^4.0.2"
+ "sinon": "^4.1.2"
},
"main": "src/index.js",
"engines": {
diff --git a/packages/convert-svg-core/src/API.js b/packages/convert-svg-core/src/API.js
index d9172ea..ae52038 100644
--- a/packages/convert-svg-core/src/API.js
+++ b/packages/convert-svg-core/src/API.js
@@ -22,6 +22,9 @@
'use strict';
+const omit = require('lodash.omit');
+const pick = require('lodash.pick');
+
const Converter = require('./Converter');
const _provider = Symbol('provider');
@@ -65,16 +68,16 @@ class API {
* provided and this information could not be derived from input
.
*
* @param {Buffer|string} input - the SVG input to be converted to another format
- * @param {Converter~ConvertOptions} [options] - the options to be used
+ * @param {API~ConvertOptions} [options] - the options to be used
* @return {Promise.} A Promise
that is resolved with the converted output buffer.
* @public
*/
async convert(input, options) {
- const converter = this.createConverter();
+ const converter = this.createConverter(pick(options, 'puppeteer'));
let output;
try {
- output = await converter.convert(input, options);
+ output = await converter.convert(input, omit(options, 'puppeteer'));
} finally {
await converter.destroy();
}
@@ -101,16 +104,16 @@ class API {
* writing the output file.
*
* @param {string} inputFilePath - the path of the SVG file to be converted to another file format
- * @param {Converter~ConvertFileOptions} [options] - the options to be used
+ * @param {API~ConvertFileOptions} [options] - the options to be used
* @return {Promise.} A Promise
that is resolved with the output file path.
* @public
*/
async convertFile(inputFilePath, options) {
- const converter = this.createConverter();
+ const converter = this.createConverter(pick(options, 'puppeteer'));
let outputFilePath;
try {
- outputFilePath = await converter.convertFile(inputFilePath, options);
+ outputFilePath = await converter.convertFile(inputFilePath, omit(options, 'puppeteer'));
} finally {
await converter.destroy();
}
@@ -119,7 +122,7 @@ class API {
}
/**
- * Creates an instance of {@link Converter}.
+ * Creates an instance of {@link Converter} using the options
provided.
*
* It is important to note that, after the first time either {@link Converter#convert} or
* {@link Converter#convertFile} are called, a headless Chromium instance will remain open until
@@ -130,11 +133,12 @@ class API {
* files in another format and then destroy it afterwards. It's not recommended to keep an instance around for too
* long, as it will use up resources.
*
+ * @param {API~CreateConverterOptions} [options] - the options to be used
* @return {Converter} A newly created {@link Converter} instance.
* @public
*/
- createConverter() {
- return new Converter(this.provider);
+ createConverter(options) {
+ return new Converter(this.provider, options);
}
/**
@@ -160,3 +164,27 @@ class API {
}
module.exports = API;
+
+/**
+ * The options that can be passed to {@link API#convertFile}.
+ *
+ * @typedef {Converter~ConvertFileOptions} API~ConvertFileOptions
+ * @property {Object} [puppeteer] - The options that are to be passed directly to puppeteer.launch
when
+ * creating the Browser
instance.
+ */
+
+/**
+ * The options that can be passed to {@link API#convert}.
+ *
+ * @typedef {Converter~ConvertOptions} API~ConvertOptions
+ * @property {Object} [puppeteer] - The options that are to be passed directly to puppeteer.launch
when
+ * creating the Browser
instance.
+ */
+
+/**
+ * The options that can be passed to {@link API#createConverter}.
+ *
+ * @typedef {Converter~Options} API~CreateConverterOptions
+ * @property {Object} [puppeteer] - The options that are to be passed directly to puppeteer.launch
when
+ * creating the Browser
instance.
+ */
diff --git a/packages/convert-svg-core/src/CLI.js b/packages/convert-svg-core/src/CLI.js
index f5f9de4..755b199 100644
--- a/packages/convert-svg-core/src/CLI.js
+++ b/packages/convert-svg-core/src/CLI.js
@@ -144,7 +144,7 @@ class CLI {
*/
async parse(args = []) {
const command = this[_command].parse(args);
- const converter = new Converter();
+ const converter = new Converter(this[_provider]);
const options = this[_parseOptions]();
try {
diff --git a/packages/convert-svg-core/src/Converter.js b/packages/convert-svg-core/src/Converter.js
index b599392..c462837 100644
--- a/packages/convert-svg-core/src/Converter.js
+++ b/packages/convert-svg-core/src/Converter.js
@@ -40,6 +40,7 @@ const _destroyed = Symbol('destroyed');
const _getDimensions = Symbol('getDimensions');
const _getPage = Symbol('getPage');
const _getTempFile = Symbol('getTempFile');
+const _options = Symbol('options');
const _page = Symbol('page');
const _parseOptions = Symbol('parseOptions');
const _provider = Symbol('provider');
@@ -71,13 +72,16 @@ const _validate = Symbol('validate');
class Converter {
/**
- * Creates an instance of {@link Converter} using the specified provider
.
+ * Creates an instance of {@link Converter} using the specified provider
and the options
+ * provided.
*
* @param {Provider} provider - the {@link Provider} to be used
+ * @param {Converter~Options} [options] - the options to be used
* @public
*/
- constructor(provider) {
+ constructor(provider, options) {
this[_provider] = provider;
+ this[_options] = Object.assign({}, options);
this[_destroyed] = false;
}
@@ -266,7 +270,7 @@ html { background-color: ${provider.getBackgroundColor(options)}; }
async [_getPage](html) {
if (!this[_browser]) {
- this[_browser] = await puppeteer.launch();
+ this[_browser] = await puppeteer.launch(this[_options].puppeteer);
this[_page] = await this[_browser].newPage();
}
@@ -417,3 +421,11 @@ module.exports = Converter;
* @property {number|string} [width] - The width of the output to be generated. If omitted, an attempt will be made to
* derive the width from the SVG input.
*/
+
+/**
+ * The options that can be passed to {@link Converter}.
+ *
+ * @typedef {Object} Converter~Options
+ * @property {Object} [puppeteer] - The options that are to be passed directly to puppeteer.launch
when
+ * creating the Browser
instance.
+ */
diff --git a/packages/convert-svg-test-helper/package.json b/packages/convert-svg-test-helper/package.json
index dc907cd..d752abb 100644
--- a/packages/convert-svg-test-helper/package.json
+++ b/packages/convert-svg-test-helper/package.json
@@ -1,6 +1,6 @@
{
"name": "convert-svg-test-helper",
- "version": "0.3.0",
+ "version": "0.3.2",
"description": "Helper for testing convert-svg-core implementations",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
@@ -33,7 +33,7 @@
"lodash.clonedeep": "^4.5.0",
"mocha": "^4.0.1",
"rimraf": "^2.6.2",
- "sinon": "^4.0.2"
+ "sinon": "^4.1.2"
},
"main": "src/index.js",
"engines": {
diff --git a/packages/convert-svg-to-jpeg/README.md b/packages/convert-svg-to-jpeg/README.md
index 1a80a9a..8eaf677 100644
--- a/packages/convert-svg-to-jpeg/README.md
+++ b/packages/convert-svg-to-jpeg/README.md
@@ -84,10 +84,14 @@ element or no `width` and/or `height` options were provided and this information
| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. |
| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. |
| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. |
+| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |
| `quality` | Number | `100` | Quality of the output to be generated. |
| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). |
| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. |
+The `puppeteer` option is not available when calling this method on a `Converter` instance created using
+`createConverter`.
+
#### Example
``` javascript
@@ -144,9 +148,9 @@ const { convertFile} = require('convert-svg-to-jpeg');
})();
```
-### `createConverter()`
+### `createConverter([options])`
-Creates an instance of `Converter`.
+Creates an instance of `Converter` using the `options` provided.
It is important to note that, after the first time either `Converter#convert` or `Converter#convertFile` are called, a
headless Chromium instance will remain open until `Converter#destroy` is called. This is done automatically when using
@@ -154,6 +158,12 @@ the `API` convert methods, however, when using `Converter` directly, it is the r
fact that creating browser instances is expensive, this level of control allows callers to reuse a browser for multiple
conversions. It's not recommended to keep an instance around for too long, as it will use up resources.
+#### Options
+
+| Option | Type | Default | Description |
+| ----------- | ------ | ------- | -------------------------------------------------------------------------------------------------- |
+| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |
+
#### Example
``` javascript
diff --git a/packages/convert-svg-to-jpeg/package.json b/packages/convert-svg-to-jpeg/package.json
index 00ab380..6ddd5cf 100644
--- a/packages/convert-svg-to-jpeg/package.json
+++ b/packages/convert-svg-to-jpeg/package.json
@@ -1,6 +1,6 @@
{
"name": "convert-svg-to-jpeg",
- "version": "0.3.1",
+ "version": "0.3.2",
"description": "Converts SVG to JPEG using headless Chromium",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
@@ -26,11 +26,11 @@
"url": "https://github.com/NotNinja/convert-svg.git"
},
"dependencies": {
- "convert-svg-core": "^0.3.1"
+ "convert-svg-core": "^0.3.2"
},
"devDependencies": {
"chai": "^4.1.2",
- "convert-svg-test-helper": "^0.3.0",
+ "convert-svg-test-helper": "^0.3.2",
"mocha": "^4.0.1"
},
"bin": {
diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg
index 96f2b1b..5b2f1d2 100644
Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/15.jpeg differ
diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg
index 5a31f01..33bda8c 100644
Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/16.jpeg differ
diff --git a/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg b/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg
index acf3586..17bb0d1 100644
Binary files a/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg and b/packages/convert-svg-to-jpeg/test/fixtures/expected/5.jpeg differ
diff --git a/packages/convert-svg-to-png/README.md b/packages/convert-svg-to-png/README.md
index a4d04d6..ee209c8 100644
--- a/packages/convert-svg-to-png/README.md
+++ b/packages/convert-svg-to-png/README.md
@@ -83,9 +83,13 @@ element or no `width` and/or `height` options were provided and this information
| `baseFile` | String | N/A | Path of the file to be converted into a file URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseUrl` option. |
| `baseUrl` | String | `"file:///path/to/cwd"` | Base URL to use for all relative URLs contained within the SVG. Cannot be used in conjunction with the `baseFile` option. |
| `height` | Number/String | N/A | Height of the output to be generated. Derived from SVG input if omitted. |
+| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |
| `scale` | Number | `1` | Scale to be applied to the width and height (specified as options or derived). |
| `width` | Number/String | N/A | Width of the output to be generated. Derived from SVG input if omitted. |
+The `puppeteer` option is not available when calling this method on a `Converter` instance created using
+`createConverter`.
+
#### Example
``` javascript
@@ -142,9 +146,9 @@ const { convertFile} = require('convert-svg-to-png');
})();
```
-### `createConverter()`
+### `createConverter([options])`
-Creates an instance of `Converter`.
+Creates an instance of `Converter` using the `options` provided.
It is important to note that, after the first time either `Converter#convert` or `Converter#convertFile` are called, a
headless Chromium instance will remain open until `Converter#destroy` is called. This is done automatically when using
@@ -152,6 +156,12 @@ the `API` convert methods, however, when using `Converter` directly, it is the r
fact that creating browser instances is expensive, this level of control allows callers to reuse a browser for multiple
conversions. It's not recommended to keep an instance around for too long, as it will use up resources.
+#### Options
+
+| Option | Type | Default | Description |
+| ----------- | ------ | ------- | -------------------------------------------------------------------------------------------------- |
+| `puppeteer` | Object | N/A | Options that are to be passed directly to `puppeteer.launch` when creating the `Browser` instance. |
+
#### Example
``` javascript
diff --git a/packages/convert-svg-to-png/package.json b/packages/convert-svg-to-png/package.json
index 9ba4b5d..09369a7 100644
--- a/packages/convert-svg-to-png/package.json
+++ b/packages/convert-svg-to-png/package.json
@@ -1,6 +1,6 @@
{
"name": "convert-svg-to-png",
- "version": "0.3.1",
+ "version": "0.3.2",
"description": "Converts SVG to PNG using headless Chromium",
"homepage": "https://github.com/NotNinja/convert-svg",
"bugs": {
@@ -25,11 +25,11 @@
"url": "https://github.com/NotNinja/convert-svg.git"
},
"dependencies": {
- "convert-svg-core": "^0.3.1"
+ "convert-svg-core": "^0.3.2"
},
"devDependencies": {
"chai": "^4.1.2",
- "convert-svg-test-helper": "^0.3.0",
+ "convert-svg-test-helper": "^0.3.2",
"mocha": "^4.0.1"
},
"bin": {
diff --git a/packages/convert-svg-to-png/test/fixtures/expected/15.png b/packages/convert-svg-to-png/test/fixtures/expected/15.png
index bb2674b..53689b9 100644
Binary files a/packages/convert-svg-to-png/test/fixtures/expected/15.png and b/packages/convert-svg-to-png/test/fixtures/expected/15.png differ
diff --git a/packages/convert-svg-to-png/test/fixtures/expected/16.png b/packages/convert-svg-to-png/test/fixtures/expected/16.png
index 5b362af..c468eb6 100644
Binary files a/packages/convert-svg-to-png/test/fixtures/expected/16.png and b/packages/convert-svg-to-png/test/fixtures/expected/16.png differ
diff --git a/packages/convert-svg-to-png/test/fixtures/expected/5.png b/packages/convert-svg-to-png/test/fixtures/expected/5.png
index 9ef3028..acb72eb 100644
Binary files a/packages/convert-svg-to-png/test/fixtures/expected/5.png and b/packages/convert-svg-to-png/test/fixtures/expected/5.png differ