diff --git a/lib/svgo-node.d.ts b/lib/svgo-node.d.ts new file mode 100644 index 000000000..a7a222b87 --- /dev/null +++ b/lib/svgo-node.d.ts @@ -0,0 +1,17 @@ +import { Config, optimize } from './svgo'; + +export { optimize }; + +/** + * If you write a tool on top of svgo you might need a way to load svgo config. + * + * You can also specify relative or absolute path and customize current working directory. + */ +export declare function loadConfig( + configFile: string, + cwd?: string, +): Promise; +export declare function loadConfig( + configFile?: null, + cwd?: string, +): Promise; diff --git a/lib/svgo.d.ts b/lib/svgo.d.ts index adf2a0144..a9693f4a6 100644 --- a/lib/svgo.d.ts +++ b/lib/svgo.d.ts @@ -54,17 +54,3 @@ type Output = { /** The core of SVGO */ export declare function optimize(input: string, config?: Config): Output; - -/** - * If you write a tool on top of svgo you might need a way to load svgo config. - * - * You can also specify relative or absolute path and customize current working directory. - */ -export declare function loadConfig( - configFile: string, - cwd?: string, -): Promise; -export declare function loadConfig( - configFile?: null, - cwd?: string, -): Promise; diff --git a/package.json b/package.json index d386c70cc..64e664027 100644 --- a/package.json +++ b/package.json @@ -52,10 +52,27 @@ }, "main": "./lib/svgo-node.js", "bin": "./bin/svgo.js", - "types": "./lib/svgo.d.ts", + "types": "./lib/svgo-node.d.ts", "exports": { - "require": "./dist/svgo-node.cjs", - "default": "./lib/svgo-node.js" + ".": { + "import": "./lib/svgo-node.js", + "require": "./dist/svgo-node.cjs", + "types": "./lib/svgo-node.d.ts" + }, + "./browser": { + "import": "./dist/svgo.browser.js", + "types": "./lib/svgo.d.ts" + } + }, + "typesVersions": { + "*": { + ".": [ + "./lib/svgo-node.d.ts" + ], + "browser": [ + "./lib/svgo.d.ts" + ] + } }, "files": [ "bin", diff --git a/rollup.config.js b/rollup.config.js index 01b4bba30..038d1e3e2 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -35,12 +35,12 @@ const terserOptions = { export default [ { - input: './lib/svgo.js', + input: './lib/svgo-node.js', output: { file: './dist/svgo-node.cjs', format: 'cjs', }, - external: Object.keys(PKG.dependencies), + external: ['os', 'fs', 'url', 'path', ...Object.keys(PKG.dependencies)], onwarn(warning) { throw Error(warning.toString()); }, diff --git a/test/svgo.cjs b/test/svgo.cjs index 2e661a0bc..7adc1b733 100644 --- a/test/svgo.cjs +++ b/test/svgo.cjs @@ -1,4 +1,4 @@ -const { optimize } = require('../dist/svgo-node.cjs'); +const { loadConfig, optimize } = require('../dist/svgo-node.cjs'); const assert = require('assert'); const fixture = ` @@ -23,11 +23,12 @@ const expected = ` const runTest = () => { const result = optimize(fixture, { plugins: [], - js2svg: { pretty: true, indent: 2 }, + js2svg: { pretty: true, indent: 2, eol: 'lf' }, }); const actual = result.data; assert.equal(actual, expected); + assert.notEqual(loadConfig, undefined); }; runTest();