Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed V3.3.0 Common JS missing loadConfig and optimize exports #1984

Merged
merged 8 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();