New:Socket for Asana Is Now Available.Learn more
Get Started

cssnano

Package Overview
Dependencies
Maintainers
8
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cssnano - npm Package Compare versions

Comparing version
8.0.10
to
9.0.0
+7
-11
package.json
{
"name": "cssnano",
"version": "8.0.10",
"version": "9.0.0",
"description": "A modular CSS minifier, built on top of the PostCSS ecosystem.",

@@ -9,7 +9,3 @@ "exports": {

"default": "./src/index.js"
},
"./src": "./src/index.js",
"./src/index": "./src/index.js",
"./src/index.js": "./src/index.js",
"./package.json": "./package.json"
}
},

@@ -31,4 +27,3 @@ "funding": {

"dependencies": {
"cssnano-preset-default": "^8.0.10",
"lilconfig": "^3.1.3"
"cssnano-preset-default": "^9.0.0"
},

@@ -54,8 +49,8 @@ "homepage": "https://github.com/cssnano/cssnano",

"engines": {
"node": "^22.11.0 || ^24.11.0 || >=26.0"
"node": "^22.22.3 || ^24.15.0 || >=26.0"
},
"devDependencies": {
"autoprefixer": "^10.5.4",
"cssnano-preset-advanced": "^8.0.10",
"cssnano-preset-lite": "^5.0.6",
"cssnano-preset-advanced": "^9.0.0",
"cssnano-preset-lite": "^6.0.0",
"postcss": "^8.5.26",

@@ -67,2 +62,3 @@ "postcss-font-magician": "^4.0.0"

},
"type": "module",
"scripts": {

@@ -69,0 +65,0 @@ "test": "node --test"

@@ -1,9 +0,11 @@

'use strict';
const path = require('node:path');
const postcss = require('postcss');
const { lilconfigSync } = require('lilconfig');
const defaultPreset = require('cssnano-preset-default');
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
import postcss from 'postcss';
import defaultPreset from 'cssnano-preset-default';
const cssnano = 'cssnano';
const require = createRequire(import.meta.url);
const configFileNames = ['.cssnanorc.json', 'cssnano.config.js'];
/** @typedef {boolean | { exclude?: boolean } | void | undefined} PluginOptions */

@@ -51,3 +53,3 @@ /** @typedef {import('postcss').PluginCreator<any>} PluginCreator */

// For JS setups where we invoked the preset already
if (fn.plugins) {
if (typeof fn === 'object' && fn !== null && 'plugins' in fn) {
return fn.plugins;

@@ -71,7 +73,9 @@ }

const sugar = `cssnano-preset-${fn}`;
// Try loading a preset from node_modules (sugar)
if (isResolvable(sugar)) {
return require(sugar)(options).plugins;
// Only the built-in preset names support shorthand resolution. Other
// strings must be passed to the module resolver unchanged.
if (fn === 'lite' || fn === 'advanced') {
const sugar = `cssnano-preset-${fn}`;
if (isResolvable(sugar)) {
return require(sugar)(options).plugins;
}
}

@@ -86,44 +90,69 @@

/**
* cssnano will look for configuration firstly as options passed
* directly to it, and failing this it will use lilconfig to
* load an external file.
* @param {string} filePath
* @returns {unknown}
*/
function loadConfigFile(filePath) {
if (filePath.endsWith('.json')) {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
}
const config = createRequire(filePath)(filePath);
if (
config !== null &&
typeof config === 'object' &&
Object.prototype.toString.call(config) === '[object Module]' &&
'default' in config
) {
return config.default;
}
return config;
}
/**
* @param {string} [configFile]
* @returns {unknown | null}
*/
function loadDiscoveredConfig(configFile) {
if (configFile) {
const configPath = path.resolve(process.cwd(), configFile);
if (!fs.existsSync(configPath)) {
throw new Error(
`Cannot find cssnano configuration file "${configFile}".`
);
}
return loadConfigFile(configPath);
}
for (const fileName of configFileNames) {
const configPath = path.join(process.cwd(), fileName);
if (!fs.existsSync(configPath)) continue;
return loadConfigFile(configPath);
}
return null;
}
/**
* @param {Options} options
* @returns {PresetPlugin[]}
*/
function resolveConfig(options) {
if (options.preset) {
if (
Array.isArray(options.preset) &&
/** @type {unknown[]} */ (options.preset).length === 0
) {
return [];
}
return resolvePreset(options.preset);
}
if (Array.isArray(options.plugins)) return [];
/** @type {string | undefined} */
let searchPath = process.cwd();
let configPath = undefined;
if (options.configFile) {
searchPath = undefined;
configPath = path.resolve(process.cwd(), options.configFile);
}
const configExplorer = lilconfigSync(cssnano, {
searchPlaces: [
'package.json',
'.cssnanorc',
'.cssnanorc.json',
'.cssnanorc.js',
'cssnano.config.js',
],
});
const config = configPath
? configExplorer.load(configPath)
: configExplorer.search(searchPath);
if (config === null) {
return resolvePreset('default');
}
return resolvePreset(config.config.preset || config.config);
const config = loadDiscoveredConfig(options.configFile);
const preset =
config !== null && typeof config === 'object' && 'preset' in config
? config.preset
: config;
return resolvePreset(config === null ? 'default' : preset);
}
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options=} options

@@ -133,14 +162,6 @@ * @return {import('postcss').Processor}

function cssnanoPlugin(options = {}) {
/** @typedef {Options & { preset: { plugins: PresetPlugin[] } }} MutableOptions */
if (Array.isArray(/** @type {MutableOptions} */ (options).plugins)) {
if (
!(/** @type {MutableOptions} */ (options).preset) ||
!(/** @type {MutableOptions} */ (options).preset.plugins)
) {
/** @type {MutableOptions} */ (options).preset = { plugins: [] };
}
const inputPlugins = /** @type {PluginSpec[]} */ (
/** @type {MutableOptions} */ (options).plugins
);
let nanoPlugins = resolveConfig(options);
if (Array.isArray(options.plugins)) {
nanoPlugins = nanoPlugins.slice();
const inputPlugins = options.plugins;
for (const plugin of inputPlugins) {

@@ -150,22 +171,13 @@ if (Array.isArray(plugin)) {

if (typeof pluginDef === 'string' && isResolvable(pluginDef)) {
/** @type {MutableOptions} */ (options).preset.plugins.push([
require(pluginDef),
nanoPlugins.push([
/** @type {PluginCreator} */ (require(pluginDef)),
opts,
]);
} else {
/** @type {MutableOptions} */ (options).preset.plugins.push([
/** @type {PluginCreator} */ (pluginDef),
opts,
]);
nanoPlugins.push([/** @type {PluginCreator} */ (pluginDef), opts]);
}
} else if (typeof plugin === 'string' && isResolvable(plugin)) {
/** @type {MutableOptions} */ (options).preset.plugins.push([
require(plugin),
{},
]);
nanoPlugins.push([/** @type {PluginCreator} */ (require(plugin)), {}]);
} else {
/** @type {MutableOptions} */ (options).preset.plugins.push([
/** @type {PluginCreator} */ (plugin),
{},
]);
nanoPlugins.push([/** @type {PluginCreator} */ (plugin), {}]);
}

@@ -175,3 +187,2 @@ }

const plugins = [];
const nanoPlugins = resolveConfig(options);
for (const nanoPlugin of nanoPlugins) {

@@ -194,3 +205,5 @@ if (Array.isArray(nanoPlugin)) {

/** @type {true} */
cssnanoPlugin.postcss = true;
module.exports = cssnanoPlugin;
export { cssnanoPlugin as default, cssnanoPlugin as 'module.exports' };

@@ -1,3 +0,1 @@

export = cssnanoPlugin;
import postcss = require('postcss');
export type PluginOptions = boolean | {

@@ -21,7 +19,11 @@ exclude?: boolean;

/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options=} options
* @return {import('postcss').Processor}
*/
declare function cssnanoPlugin(options?: {}): postcss.Processor;
declare function cssnanoPlugin(options?: Options | undefined): import('postcss').Processor;
declare namespace cssnanoPlugin {
var _a: true;
export { _a as postcss };
}
export { cssnanoPlugin as default, cssnanoPlugin as 'module.exports' };
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"SA4LiB,aAAa;OA1LxB,OAAO,WAAW,SAAS;AAM7B,YAA8D,aAAa,GAAjE,OAAO,GAAG;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS,CAAe;AAC3E,YAAgD,aAAa,GAAnD,OAAO,SAAS,EAAE,aAAa,CAAC,GAAG,CAAC,CAAe;AAC7D,YAA0C,YAAY,GAA5C,CAAC,aAAa,EAAE,aAAa,CAAC,CAAc;AACtD,YAA0D,aAAa,GAA7D,CAAC,OAAO,CAAC,EAAE,GAAG,KAAK;IAAE,OAAO,EAAE,YAAY,EAAE,CAAA;CAAE,CAAe;AACvE,YAAmG,UAAU,GAAnG,MAAM,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,aAAa,EAAE,MAAM,CAAC,GAAG;IAAE,OAAO,EAAE,YAAY,EAAE,CAAA;CAAE,CAAY;AAC7G,YAAsE,UAAU,GAAtE,MAAM,GAAG,aAAa,GAAG,CAAC,MAAM,GAAG,aAAa,EAAE,MAAM,CA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