diff --git a/types/clean-css/clean-css-tests.ts b/types/clean-css/clean-css-tests.ts new file mode 100644 index 0000000000..5613f3a334 --- /dev/null +++ b/types/clean-css/clean-css-tests.ts @@ -0,0 +1,81 @@ + +import * as CleanCSS from 'clean-css'; + +var source = 'a{font-weight:bold;}'; +var minified = new CleanCSS().minify(source).styles; + +var source = '@import url(http://path/to/remote/styles);'; +new CleanCSS().minify(source, function (error, minified) { + console.log(minified.styles); +}); + +const pathToOutputDirectory = 'path'; + +new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }) + .minify(source, function (error, minified) { + // access minified.sourceMap for SourceMapGenerator object + // see https://github.com/mozilla/source-map/#sourcemapgenerator for more details + // see https://github.com/jakubpawlowicz/clean-css/blob/master/bin/cleancss#L114 on how it's used in clean-css' CLI + console.log(minified.sourceMap); +}); + +const inputSourceMapAsString = 'input'; +new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }) + .minify(source, inputSourceMapAsString, function (error, minified) { + // access minified.sourceMap to access SourceMapGenerator object + // see https://github.com/mozilla/source-map/#sourcemapgenerator for more details + // see https://github.com/jakubpawlowicz/clean-css/blob/master/bin/cleancss#L114 on how it's used in clean-css' CLI + console.log(minified.sourceMap); +}); + +new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }).minify({ + 'path/to/source/1': { + styles: '...styles...', + sourceMap: '...source-map...' + }, + 'path/to/source/2': { + styles: '...styles...', + sourceMap: '...source-map...' + } +}, function (error, minified) { + // access minified.sourceMap as above + console.log(minified.sourceMap); +}); + +new CleanCSS().minify(['path/to/file/one', 'path/to/file/two']); + +new CleanCSS().minify({ + 'path/to/file/one': { + styles: 'contents of file one' + }, + 'path/to/file/two': { + styles: 'contents of file two' + } +}); + +// new tests - promise resolution +new CleanCSS({ returnPromise: true, rebaseTo: pathToOutputDirectory }).minify(source) + .then((minified: CleanCSS.Output): void => { + console.log(minified.styles); + }).catch((error: any): void => { + console.log(error); + } +); + +new CleanCSS({ returnPromise: true, sourceMap: true }).minify(source) + .then((minified: CleanCSS.Output): void => { + // access minified.sourceMap as above + console.log(minified.sourceMap); + }).catch((error: any): void => { + console.log(error); + } +); + +new CleanCSS({ returnPromise: true, sourceMap: true }).minify(source, inputSourceMapAsString) + .then((minified: CleanCSS.Output): void => { + // access minified.sourceMap as above + console.log(minified.sourceMap); + }).catch((error: any): void => { + console.log(error); + } +); \ No newline at end of file diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index b8b52086f6..606b9ba951 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -1,7 +1,9 @@ // Type definitions for clean-css v4.2.1 // Project: https://github.com/jakubpawlowicz/clean-css -// Definitions by: Andrew Potter +// Definitions by: Tanguy Krotoff +// Andrew Potter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 /// import { RequestOptions as HttpsRequestOptions } from "https"; @@ -27,7 +29,7 @@ declare namespace CleanCSS { * Controls output CSS formatting; defaults to `false`. * Format hash exposes the following properties: `breaks`, `breakWith`, `indentBy`, `indentWith`, `spaces`, and `wrapAt`. */ - format?: "beautify" | "keep-breaks" | Format | false; + format?: "beautify" | "keep-breaks" | FormatOptions | false; /** * inline option whitelists which @import rules will be processed. Defaults to `'local'` @@ -55,7 +57,7 @@ declare namespace CleanCSS { * Controls optimization level used; defaults to `1`. * Level hash exposes `1`, and `2`. */ - level?: 0 | 1 | 2 | optimizationsOptions; + level?: 0 | 1 | 2 | OptimizationsOptions; /** * Controls URL rebasing; defaults to `true`; @@ -192,7 +194,7 @@ declare namespace CleanCSS { ieSuffixHack?: boolean; /** - * Controls property merging based on understandability; defaults to `true` + * Controls property merging based on understandably; defaults to `true` */ merging?: boolean; @@ -304,7 +306,7 @@ declare namespace CleanCSS { /** * Fine grained options for configuring the CSS formatting */ - interface Format { + interface FormatOptions { /** * Controls where to insert breaks */ @@ -398,7 +400,7 @@ declare namespace CleanCSS { /** * Fine grained options for configuring optimizations */ - interface optimizationsOptions { + interface OptimizationsOptions { 1?: { /** * Sets all optimizations at this level unless otherwise specified @@ -553,7 +555,7 @@ declare namespace CleanCSS { mergeSemantically?: boolean; /** - * Controls property overriding based on understandability; defaults to true + * Controls property overriding based on understandably; defaults to true */ overrideProperties?: boolean; @@ -599,31 +601,67 @@ declare namespace CleanCSS { } } + /** + * Hash of input source(s). Passing an array of hashes allows you to explicitly specify the order in which the input files + * are concatenated. Whereas when you use a single hash the order is determined by the traversal order of object properties + */ + interface Source { + /** + * Path to file + */ + [path: string]: { + /** + * The contents of the file, should be css + */ + styles: string; + + /** + * The source map of the file, if needed + */ + sourceMap?: string; + } + } + /** * Callback type when fetch is used */ type FetchCallback = (message: string | number, body: string) => void; /** - * Interface exposed when a new CleanCSS option is created + * Union of all types acceptable as input for the minify function */ - interface Function)> { - minify(sources: string | Array | Object, callback?: (error: any, output: T) => void): T; - minify(sources: string | Array | Object, inputSourceMap?: string): T; - minify(sources: string | Array | Object, inputSourceMap?: string, callback?: (error: any, output: T) => void): T; + type Sources = string | ReadonlyArray | Source | ReadonlyArray | Buffer; + + /** + * Union type for both types of minifier functions + */ + type Minifier = MinifierOutput | MinifierPromise; + + /** + * Interface exposed when a new CleanCSS object is created + */ + interface MinifierOutput { + minify(sources: Sources, callback?: (error: any, output: Output) => void): Output; + minify(sources: Sources, sourceMap: string, callback?: (error: any, output: Output) => void): Output; + } + /** + * Interface exposed when a new CleanCSS object is created with returnPromise set to true + */ + interface MinifierPromise { + minify(sources: Sources, sourceMap?: string): Promise; } /** * Constructor interface for CleanCSS */ interface Constructor { - new(options: CleanCSS.Options & { returnPromise: true }): Function>; - new(options?: CleanCSS.Options): Function; + new(options: Options & { returnPromise: true }): MinifierPromise; + new(options?: Options): MinifierOutput; } } /** - * Creates a new CleanCSS object + * Creates a new CleanCSS object which can be used to minify css */ declare const CleanCSS: CleanCSS.Constructor; diff --git a/types/clean-css/tsconfig.json b/types/clean-css/tsconfig.json index 82e6284376..fe65b21c11 100644 --- a/types/clean-css/tsconfig.json +++ b/types/clean-css/tsconfig.json @@ -18,6 +18,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "clean-css-tests.ts" ] } \ No newline at end of file diff --git a/types/clean-css/tslint.json b/types/clean-css/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/clean-css/tslint.json +++ b/types/clean-css/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } diff --git a/types/clean-css/v3/clean-css-tests.ts b/types/clean-css/v3/clean-css-tests.ts new file mode 100644 index 0000000000..b9b958d51b --- /dev/null +++ b/types/clean-css/v3/clean-css-tests.ts @@ -0,0 +1,54 @@ + +import * as CleanCSS from 'clean-css'; + +var source = 'a{font-weight:bold;}'; +var minified = new CleanCSS().minify(source).styles; + +var source = '@import url(http://path/to/remote/styles);'; +new CleanCSS().minify(source, function (error, minified) { + console.log(minified.styles); +}); + +const pathToOutputDirectory = 'path'; + +new CleanCSS({ sourceMap: true, target: pathToOutputDirectory }) + .minify(source, function (error, minified) { + // access minified.sourceMap for SourceMapGenerator object + // see https://github.com/mozilla/source-map/#sourcemapgenerator for more details + // see https://github.com/jakubpawlowicz/clean-css/blob/master/bin/cleancss#L114 on how it's used in clean-css' CLI + console.log(minified.sourceMap); +}); + +const inputSourceMapAsString = 'input'; +new CleanCSS({ sourceMap: inputSourceMapAsString, target: pathToOutputDirectory }) + .minify(source, function (error, minified) { + // access minified.sourceMap to access SourceMapGenerator object + // see https://github.com/mozilla/source-map/#sourcemapgenerator for more details + // see https://github.com/jakubpawlowicz/clean-css/blob/master/bin/cleancss#L114 on how it's used in clean-css' CLI + console.log(minified.sourceMap); +}); + +new CleanCSS({ sourceMap: true, target: pathToOutputDirectory }).minify({ + 'path/to/source/1': { + styles: '...styles...', + sourceMap: '...source-map...' + }, + 'path/to/source/2': { + styles: '...styles...', + sourceMap: '...source-map...' + } +}, function (error, minified) { + // access minified.sourceMap as above + console.log(minified.sourceMap); +}); + +new CleanCSS().minify(['path/to/file/one', 'path/to/file/two']); + +new CleanCSS().minify({ + 'path/to/file/one': { + styles: 'contents of file one' + }, + 'path/to/file/two': { + styles: 'contents of file two' + } +}); \ No newline at end of file diff --git a/types/clean-css/v3/index.d.ts b/types/clean-css/v3/index.d.ts new file mode 100644 index 0000000000..87fb7e7f6c --- /dev/null +++ b/types/clean-css/v3/index.d.ts @@ -0,0 +1,108 @@ +// Type definitions for clean-css v3.4.9 +// Project: https://github.com/jakubpawlowicz/clean-css +// Definitions by: Tanguy Krotoff +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +declare namespace CleanCSS { + interface Options { + // Set to false to disable advanced optimizations - selector & property merging, reduction, etc. + advanced?: boolean; + + // Set to false to disable aggressive merging of properties. + aggressiveMerging?: boolean; + + // Turns on benchmarking mode measuring time spent on cleaning up (run npm run bench to see example) + benchmark?: boolean; + + // Enables compatibility mode + compatibility?: Object; + + // Set to true to get minification statistics under stats property (see test/custom-test.js for examples) + debug?: boolean; + + // A hash of options for @import inliner, see test/protocol-imports-test.js for examples, or this comment for a proxy use case. + inliner?: Object; + + // Whether to keep line breaks (default is false) + keepBreaks?: boolean; + + // * for keeping all (default), 1 for keeping first one only, 0 for removing all + keepSpecialComments?: string | number; + + // Whether to merge @media at-rules (default is true) + mediaMerging?: boolean; + + // Whether to process @import rules + processImport?: boolean; + + // A list of @import rules, can be ['all'] (default), ['local'], ['remote'], or a blacklisted path e.g. ['!fonts.googleapis.com'] + processImportFrom?: Array; + + // Set to false to skip URL rebasing + rebase?: boolean; + + // Path to resolve relative @import rules and URLs + relativeTo?: string; + + // Set to false to disable restructuring in advanced optimizations + restructuring?: boolean; + + // Path to resolve absolute @import rules and rebase relative URLs + root?: string; + + // Rounding precision; defaults to 2; -1 disables rounding + roundingPrecision?: number; + + // Set to true to enable semantic merging mode which assumes BEM-like content (default is false as it's highly likely this will break your stylesheets - use with caution!) + semanticMerging?: boolean; + + // Set to false to skip shorthand compacting (default is true unless sourceMap is set when it's false) + shorthandCompacting?: boolean; + + // Exposes source map under sourceMap property, e.g. new CleanCSS().minify(source).sourceMap (default is false) If input styles are a product of CSS preprocessor (Less, Sass) an input source map can be passed as a string. + sourceMap?: boolean | string; + + // Set to true to inline sources inside a source map's sourcesContent field (defaults to false) It is also required to process inlined sources from input source maps. + sourceMapInlineSources?: boolean; + + // Path to a folder or an output file to which rebase all URLs + target?: string; + } + + interface Output { + // Optimized output CSS as a string + styles: string; + + // Output source map (if requested with sourceMap option) + sourceMap: string; + + // A list of errors raised + errors: Array; + + // A list of warnings raised + warnings: Array; + + // A hash of statistic information (if requested with debug option) + stats: { + // Original content size (after import inlining) + originalSize: number; + + // Optimized content size + minifiedSize: number; + + // Time spent on optimizations + timeSpent: number; + + // A ratio of output size to input size (e.g. 25% if content was reduced from 100 bytes to 75 bytes) + efficiency: number; + }; + } +} + +declare class CleanCSS { + constructor(options?: CleanCSS.Options); + minify(sources: string | Array | Object, callback?: (error: any, minified: CleanCSS.Output) => void): CleanCSS.Output; +} + +export = CleanCSS; \ No newline at end of file diff --git a/types/clean-css/v3/tsconfig.json b/types/clean-css/v3/tsconfig.json new file mode 100644 index 0000000000..8a2c2eae67 --- /dev/null +++ b/types/clean-css/v3/tsconfig.json @@ -0,0 +1,32 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "clean-css": [ + "clean-css/v3" + ], + "clean-css/*": [ + "clean-css/v3/*" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "clean-css-tests.ts" + ] +} \ No newline at end of file diff --git a/types/clean-css/v3/tslint.json b/types/clean-css/v3/tslint.json new file mode 100644 index 0000000000..a4c53997aa --- /dev/null +++ b/types/clean-css/v3/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +} \ No newline at end of file diff --git a/types/gulp-minify-css/index.d.ts b/types/gulp-minify-css/index.d.ts index d347cf0708..a826efcfb3 100644 --- a/types/gulp-minify-css/index.d.ts +++ b/types/gulp-minify-css/index.d.ts @@ -5,7 +5,7 @@ /// -import * as CleanCSS from 'clean-css'; +import * as CleanCSS from 'clean-css/v3'; declare function minifyCSS(options?: CleanCSS.Options): NodeJS.ReadWriteStream; diff --git a/types/html-minifier/v1/index.d.ts b/types/html-minifier/v1/index.d.ts index c1ff944e7e..a724bbd497 100644 --- a/types/html-minifier/v1/index.d.ts +++ b/types/html-minifier/v1/index.d.ts @@ -7,7 +7,7 @@ /// import * as UglifyJS from 'uglify-js'; -import * as CleanCSS from 'clean-css'; +import * as CleanCSS from 'clean-css/v3'; import * as RelateUrl from 'relateurl'; declare namespace HTMLMinifier {