Skip to content

Commit

Permalink
fix: v3.3.0 Common JS missing loadConfig and optimize exports (#1984)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuintun authored May 8, 2024
1 parent 6b162fb commit 3964d64
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
17 changes: 17 additions & 0 deletions lib/svgo-node.d.ts
Original file line number Diff line number Diff line change
@@ -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<Config>;
export declare function loadConfig(
configFile?: null,
cwd?: string,
): Promise<Config | null>;
14 changes: 0 additions & 14 deletions lib/svgo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config>;
export declare function loadConfig(
configFile?: null,
cwd?: string,
): Promise<Config | null>;
23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
},
Expand Down
5 changes: 3 additions & 2 deletions test/svgo.cjs
Original file line number Diff line number Diff line change
@@ -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 = `<svg xmlns="http://www.w3.org/2000/svg">
Expand All @@ -23,11 +23,12 @@ const expected = `<svg xmlns="http://www.w3.org/2000/svg">
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();

0 comments on commit 3964d64

Please sign in to comment.