Skip to content

Commit

Permalink
feat: add CSS types to remaining packages (#1340)
Browse files Browse the repository at this point in the history
* feat: add TypeScript checking

* feat(postcss-reduce-initial): add types

* feat(postcss-minify-gradients): add types

* feat(postcss-svgo): add types

* feat(postcss-reduce-transforms): add types

* feat(postcss-convert-values): add types

* feat(postcss-colormin): add types

* feat(postcss-ordered-values): add types

* feat(postcss-minify-selectors): add types

* feat(postcss-minify-params): add types

* feat(postcss-normalize-charset): add types

* feat(postcss-minify-font-values): add types

* feat(postcss-normalize-url): add types

* feat(postcss-merge-longhand): add types

* feat(postcss-discard-duplicates): add types

* feat(postcss-discard-overridden): add types

* feat(postcss-normalize-repeat-style): add types

* feat(postcss-merge-rules): add types

* feat(postcss-unique-selectors): add types

* feat(postcss-normalize-string): add types

* feat(postcss-normalize-positions): add types

* feat(postcss-normalize-unicode): add types

* feat(postcss-normalize-display-values): add types

* feat(postcss-normalize-timing-functions): add types

* feat(cssnano-preset-default): add types

* feat(stylehacks): add types

* feat(postcss-discard-unused): add types

* feat(postcss-merge-idents): add types

* feat(postcss-reduce-idents): add types

* feat(postcss-zindex): add types

* feat(cssnano-preset-advanced): add types

* feat(cssnano): add types

* chore: fix lockfile
  • Loading branch information
ludofischer committed Mar 1, 2022
1 parent b6892b9 commit b3551cc
Show file tree
Hide file tree
Showing 274 changed files with 3,511 additions and 331 deletions.
4 changes: 3 additions & 1 deletion packages/cssnano-preset-advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"name": "cssnano-preset-advanced",
"version": "5.1.12",
"main": "src/index.js",
"types": "types/index.d.ts",
"description": "Advanced optimisations for cssnano; may or may not break your CSS!",
"files": [
"LICENSE-MIT",
"src"
"src",
"types"
],
"license": "MIT",
"dependencies": {
Expand Down
11 changes: 11 additions & 0 deletions packages/cssnano-preset-advanced/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ const postcssReduceIdents = require('postcss-reduce-idents');
const postcssZindex = require('postcss-zindex');
const autoprefixer = require('autoprefixer');

/** @typedef {
{autoprefixer?: autoprefixer.Options,
discardUnused?: false | import('postcss-discard-unused').Options & { exclude?: true},
mergeIdents?: false | { exclude?: true},
reduceIdents?:false | import('postcss-reduce-idents').Options & { exclude?: true},
zindex?: false | import('postcss-zindex').Options & { exclude?: true},
}} AdvancedOptions */
/** @typedef {import('cssnano-preset-default').Options & AdvancedOptions} Options */

/** @type {Options} */
const defaultOpts = {
autoprefixer: {
add: false,
Expand All @@ -15,6 +25,7 @@ const defaultOpts = {
module.exports = function advancedPreset(opts = {}) {
const options = Object.assign({}, defaultOpts, opts);

/** @type {[import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]} */
const plugins = [
...defaultPreset(options).plugins,
[autoprefixer, options.autoprefixer],
Expand Down
9 changes: 9 additions & 0 deletions packages/cssnano-preset-advanced/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"include": ["src/*"],
"compilerOptions": {
"composite": true,
"rootDir": "src/",
"declarationDir": "types"
}
}
21 changes: 21 additions & 0 deletions packages/cssnano-preset-advanced/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare function _exports(opts?: {}): {
plugins: [import("postcss").PluginCreator<any>, boolean | Record<string, any> | undefined][];
};
export = _exports;
export type AdvancedOptions = {
autoprefixer?: autoprefixer.Options;
discardUnused?: false | import('postcss-discard-unused').Options & {
exclude?: true;
};
mergeIdents?: false | {
exclude?: true;
};
reduceIdents?: false | import('postcss-reduce-idents').Options & {
exclude?: true;
};
zindex?: false | import('postcss-zindex').Options & {
exclude?: true;
};
};
export type Options = import('cssnano-preset-default').Options & AdvancedOptions;
import autoprefixer = require("autoprefixer");
7 changes: 5 additions & 2 deletions packages/cssnano-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
"name": "cssnano-preset-default",
"version": "5.1.12",
"main": "src/index.js",
"types": "types/index.d.ts",
"description": "Safe defaults for cssnano which require minimal configuration.",
"files": [
"LICENSE-MIT",
"src"
"src",
"types"
],
"license": "MIT",
"dependencies": {
"css-declaration-sorter": "^6.0.3",
"cssnano-utils": "^3.0.2",
"postcss-calc": "^8.2.0",
"postcss-calc": "^8.2.3",
"postcss-colormin": "^5.2.5",
"postcss-convert-values": "^5.0.4",
"postcss-discard-comments": "^5.0.3",
Expand Down Expand Up @@ -53,6 +55,7 @@
"node": "^10 || ^12 || >=14.0"
},
"devDependencies": {
"@types/css-declaration-sorter": "^6.0.1",
"postcss": "^8.2.15"
},
"peerDependencies": {
Expand Down
41 changes: 39 additions & 2 deletions packages/cssnano-preset-default/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ const postcssNormalizeDisplayValues = require('postcss-normalize-display-values'
const postcssNormalizeTimingFunctions = require('postcss-normalize-timing-functions');
const { rawCache } = require('cssnano-utils');

/** @typedef {{
discardComments?: false | import('postcss-discard-comments').Options & { exclude?: true},
reduceInitial?: false | { exclude?: true}
minifyGradients?: false | { exclude?: true}
svgo?: false | import('postcss-svgo').Options & { exclude?: true},
reduceTransforms?: false | { exclude?: true}
convertValues?: false | import('postcss-convert-values').Options & { exclude?: true},
calc?: false | import('postcss-calc').PostCssCalcOptions & { exclude?: true},
colormin?: false | Record<string, any> & { exclude?: true},
orderedValues?: false | { exclude?: true},
minifySelectors?: false | { exclude?: true},
minifyParams?: false | { exclude?: true},
normalizeCharset?: false | import('postcss-normalize-charset').Options & { exclude?: true},
minifyFontValues?: false | import('postcss-minify-font-values').Options & { exclude?: true},
normalizeUrl?: false | import('postcss-normalize-url').Options & { exclude?: true},
mergeLonghand?: false | { exclude?: true},
discardDuplicates?: false | { exclude?: true},
discardOverridden?: false | { exclude?: true},
normalizeRepeatStyle?: false | { exclude?: true},
mergeRules?: false | { exclude?: true},
discardEmpty?: false | { exclude?: true},
uniqueSelectors?: false | { exclude?: true},
normalizeString?: false | import('postcss-normalize-string').Options & { exclude?: true},
normalizePositions?: false | { exclude?: true},
normalizeWhitespace?: false| { exclude?: true},
normalizeUnicode?: false | { exclude?: true},
normalizeDisplayValues?: false | { exclude?: true},
normalizeTimingFunctions?: false | { exclude?: true},
rawCache?: false | { exclude?: true}}} Options */

const defaultOpts = {
convertValues: {
length: false,
Expand All @@ -55,9 +85,14 @@ const defaultOpts = {
},
};

module.exports = function defaultPreset(opts = {}) {
/**
* @param {Options} opts
* @return {{plugins: [import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]}}
*/
function defaultPreset(opts = {}) {
const options = Object.assign({}, defaultOpts, opts);

/** @type {[import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]} **/
const plugins = [
[postcssDiscardComments, options.discardComments],
[postcssMinifyGradients, options.minifyGradients],
Expand Down Expand Up @@ -91,4 +126,6 @@ module.exports = function defaultPreset(opts = {}) {
];

return { plugins };
};
}

module.exports = defaultPreset;
9 changes: 9 additions & 0 deletions packages/cssnano-preset-default/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"include": ["src/*"],
"compilerOptions": {
"composite": true,
"rootDir": "src/",
"declarationDir": "types"
}
}
98 changes: 98 additions & 0 deletions packages/cssnano-preset-default/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
export = defaultPreset;
/**
* @param {Options} opts
* @return {{plugins: [import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]}}
*/
declare function defaultPreset(opts?: Options): {
plugins: [import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][];
};
declare namespace defaultPreset {
export { Options };
}
type Options = {
discardComments?: false | import('postcss-discard-comments').Options & {
exclude?: true;
};
reduceInitial?: false | {
exclude?: true;
};
minifyGradients?: false | {
exclude?: true;
};
svgo?: false | import('postcss-svgo').Options & {
exclude?: true;
};
reduceTransforms?: false | {
exclude?: true;
};
convertValues?: false | import('postcss-convert-values').Options & {
exclude?: true;
};
calc?: false | import('postcss-calc').PostCssCalcOptions & {
exclude?: true;
};
colormin?: false | (Record<string, any> & {
exclude?: true;
});
orderedValues?: false | {
exclude?: true;
};
minifySelectors?: false | {
exclude?: true;
};
minifyParams?: false | {
exclude?: true;
};
normalizeCharset?: false | import('postcss-normalize-charset').Options & {
exclude?: true;
};
minifyFontValues?: false | import('postcss-minify-font-values').Options & {
exclude?: true;
};
normalizeUrl?: false | import('postcss-normalize-url').Options & {
exclude?: true;
};
mergeLonghand?: false | {
exclude?: true;
};
discardDuplicates?: false | {
exclude?: true;
};
discardOverridden?: false | {
exclude?: true;
};
normalizeRepeatStyle?: false | {
exclude?: true;
};
mergeRules?: false | {
exclude?: true;
};
discardEmpty?: false | {
exclude?: true;
};
uniqueSelectors?: false | {
exclude?: true;
};
normalizeString?: false | import('postcss-normalize-string').Options & {
exclude?: true;
};
normalizePositions?: false | {
exclude?: true;
};
normalizeWhitespace?: false | {
exclude?: true;
};
normalizeUnicode?: false | {
exclude?: true;
};
normalizeDisplayValues?: false | {
exclude?: true;
};
normalizeTimingFunctions?: false | {
exclude?: true;
};
rawCache?: false | {
exclude?: true;
};
};
import { rawCache } from "cssnano-utils";
4 changes: 3 additions & 1 deletion packages/cssnano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "5.0.17",
"description": "A modular minifier, built on top of the PostCSS ecosystem.",
"main": "src/index.js",
"types": "types/index.d.ts",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/cssnano"
Expand Down Expand Up @@ -31,7 +32,8 @@
"repository": "cssnano/cssnano",
"files": [
"src",
"LICENSE-MIT"
"LICENSE-MIT",
"types"
],
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
Expand Down
21 changes: 16 additions & 5 deletions packages/cssnano/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';
const path = require('path');
/** @type {any} */
const postcss = require('postcss');
const yaml = require('yaml');
const { lilconfigSync } = require('lilconfig');

const cssnano = 'cssnano';

/*
/** @typedef {{preset?: any, plugins?: any[], configFile?: string}} Options */
/**
* @param {string} moduleId
* @returns {boolean}
*/
Expand All @@ -19,14 +21,16 @@ function isResolvable(moduleId) {
}
}

/*
/**
* preset can be one of four possibilities:
* preset = 'default'
* preset = ['default', {}]
* preset = function <- to be invoked
* preset = {plugins: []} <- already invoked function
*
* @param {any} preset
* @return {[import('postcss').PluginCreator<any>, boolean | Record<string, any> | undefined][]}}
*/

function resolvePreset(preset) {
let fn, options;

Expand Down Expand Up @@ -71,17 +75,19 @@ function resolvePreset(preset) {
);
}

/*
/**
* 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 {Options} options
*/
function resolveConfig(options) {
if (options.preset) {
return resolvePreset(options.preset);
}

/** @type {string | undefined} */
let searchPath = process.cwd();
let configPath = undefined;

Expand Down Expand Up @@ -116,6 +122,11 @@ function resolveConfig(options) {
return resolvePreset(config.config.preset || config.config);
}

/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options=} options
* @return {import('postcss').Plugin}
*/
function cssnanoPlugin(options = {}) {
if (Array.isArray(options.plugins)) {
if (!options.preset || !options.preset.plugins) {
Expand Down
9 changes: 9 additions & 0 deletions packages/cssnano/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"include": ["src/*"],
"compilerOptions": {
"composite": true,
"rootDir": "src/",
"declarationDir": "types"
}
}
16 changes: 16 additions & 0 deletions packages/cssnano/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export = cssnanoPlugin;
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options=} options
* @return {import('postcss').Plugin}
*/
declare function cssnanoPlugin(options?: Options | undefined): import('postcss').Plugin;
declare namespace cssnanoPlugin {
export { postcss, Options };
}
type Options = {
preset?: any;
plugins?: any[];
configFile?: string;
};
declare var postcss: true;
Loading

0 comments on commit b3551cc

Please sign in to comment.