1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-29 20:21:14 +03:00

Move platform specific eol to svgo-node entry point (#1565)

`os` package in js2svg module bothered me for a long time.
We had to hack rollup to mock it for browser.

Thanks to https://github.com/svg/svgo/pull/1546 we now can pass eol from
svgo-node entry point and simplify build.
This commit is contained in:
Bogdan Chadkin
2021-09-12 16:40:21 +03:00
committed by GitHub
parent 1f5ea7e610
commit 23c7f48130
3 changed files with 21 additions and 15 deletions

View File

@ -1,13 +1,17 @@
'use strict';
const os = require('os');
const fs = require('fs');
const path = require('path');
const {
extendDefaultPlugins,
optimize,
optimize: optimizeAgnostic,
createContentItem,
} = require('./svgo.js');
exports.extendDefaultPlugins = extendDefaultPlugins;
exports.createContentItem = createContentItem;
const importConfig = async (configFile) => {
const config = require(configFile);
if (config == null || typeof config !== 'object' || Array.isArray(config)) {
@ -47,8 +51,19 @@ const loadConfig = async (configFile, cwd = process.cwd()) => {
dir = parent;
}
};
exports.loadConfig = loadConfig;
exports.extendDefaultPlugins = extendDefaultPlugins;
const optimize = (input, config) => {
if (typeof config !== 'object') {
throw Error('Config should be an object');
}
return optimizeAgnostic(input, {
...config,
js2svg: {
// platform specific default for end of line
eol: os.EOL === '\r\n' ? 'crlf' : 'lf',
...(config == null ? null : config.js2svg),
},
});
};
exports.optimize = optimize;
exports.createContentItem = createContentItem;