mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
fix: improve jsdoc types and remove excludes (#2107)
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
import { pathToFileURL } from 'url';
|
||||
import path from 'path';
|
||||
import {
|
||||
VERSION,
|
||||
@ -11,10 +10,17 @@ import {
|
||||
_collections,
|
||||
} from './svgo.js';
|
||||
|
||||
/**
|
||||
* @typedef {import('./svgo.js').Config} Config
|
||||
* @typedef {import('./svgo.js').Output} Output
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} configFile
|
||||
* @returns {Promise<Config>}
|
||||
*/
|
||||
const importConfig = async (configFile) => {
|
||||
// dynamic import expects file url instead of path and may fail
|
||||
// when windows path is provided
|
||||
const imported = await import(pathToFileURL(configFile));
|
||||
const imported = await import(path.resolve(configFile));
|
||||
const config = imported.default;
|
||||
|
||||
if (config == null || typeof config !== 'object' || Array.isArray(config)) {
|
||||
@ -23,6 +29,10 @@ const importConfig = async (configFile) => {
|
||||
return config;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} file
|
||||
* @returns {Promise<boolean>}
|
||||
*/
|
||||
const isFile = async (file) => {
|
||||
try {
|
||||
const stats = await fs.promises.stat(file);
|
||||
@ -40,6 +50,11 @@ export {
|
||||
_collections,
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} configFile
|
||||
* @param {string} cwd
|
||||
* @returns {Promise<?Config>}
|
||||
*/
|
||||
export const loadConfig = async (configFile, cwd = process.cwd()) => {
|
||||
if (configFile != null) {
|
||||
if (path.isAbsolute(configFile)) {
|
||||
@ -71,6 +86,11 @@ export const loadConfig = async (configFile, cwd = process.cwd()) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Config} config
|
||||
* @returns {Output}
|
||||
*/
|
||||
export const optimize = (input, config) => {
|
||||
if (config == null) {
|
||||
config = {};
|
||||
|
Reference in New Issue
Block a user