mirror of
https://github.com/svg/svgo.git
synced 2025-08-09 02:22:08 +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:
@@ -1,13 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const os = require('os');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const {
|
const {
|
||||||
extendDefaultPlugins,
|
extendDefaultPlugins,
|
||||||
optimize,
|
optimize: optimizeAgnostic,
|
||||||
createContentItem,
|
createContentItem,
|
||||||
} = require('./svgo.js');
|
} = require('./svgo.js');
|
||||||
|
|
||||||
|
exports.extendDefaultPlugins = extendDefaultPlugins;
|
||||||
|
exports.createContentItem = createContentItem;
|
||||||
|
|
||||||
const importConfig = async (configFile) => {
|
const importConfig = async (configFile) => {
|
||||||
const config = require(configFile);
|
const config = require(configFile);
|
||||||
if (config == null || typeof config !== 'object' || Array.isArray(config)) {
|
if (config == null || typeof config !== 'object' || Array.isArray(config)) {
|
||||||
@@ -47,8 +51,19 @@ const loadConfig = async (configFile, cwd = process.cwd()) => {
|
|||||||
dir = parent;
|
dir = parent;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.loadConfig = loadConfig;
|
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.optimize = optimize;
|
||||||
exports.createContentItem = createContentItem;
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var platformEOL = require('os').EOL,
|
const { textElems } = require('../../plugins/_collections.js');
|
||||||
textElems = require('../../plugins/_collections.js').textElems;
|
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
doctypeStart: '<!DOCTYPE',
|
doctypeStart: '<!DOCTYPE',
|
||||||
@@ -28,7 +27,7 @@ var defaults = {
|
|||||||
encodeEntity: encodeEntity,
|
encodeEntity: encodeEntity,
|
||||||
pretty: false,
|
pretty: false,
|
||||||
useShortTags: true,
|
useShortTags: true,
|
||||||
eol: platformEOL === '\r\n' ? 'crlf' : 'lf',
|
eol: 'lf',
|
||||||
finalNewline: false,
|
finalNewline: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -15,19 +15,11 @@ export default {
|
|||||||
plugins: [
|
plugins: [
|
||||||
{
|
{
|
||||||
resolveId(importee, importer) {
|
resolveId(importee, importer) {
|
||||||
if (importee === 'os') {
|
|
||||||
return importee;
|
|
||||||
}
|
|
||||||
// see https://github.com/csstree/csstree/pull/152
|
// see https://github.com/csstree/csstree/pull/152
|
||||||
if (importee === 'css-tree') {
|
if (importee === 'css-tree') {
|
||||||
return this.resolve('css-tree/dist/csstree.min.js', importer);
|
return this.resolve('css-tree/dist/csstree.min.js', importer);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
load(id) {
|
|
||||||
if (id === 'os') {
|
|
||||||
return `export var EOL = '\\n'`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
nodeResolve({ browser: true, preferBuiltins: false }),
|
nodeResolve({ browser: true, preferBuiltins: false }),
|
||||||
commonjs(),
|
commonjs(),
|
||||||
|
Reference in New Issue
Block a user