From ec27f386ec53f0b9bfbd0f23262ff69d53e65d65 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Tue, 22 Jan 2019 16:25:48 -0700 Subject: [PATCH 01/14] Updated clean-css to use 4.2.1 --- types/clean-css/clean-css-tests.ts | 10 +- types/clean-css/index.d.ts | 645 ++++++++++++++++++++++++++--- 2 files changed, 586 insertions(+), 69 deletions(-) diff --git a/types/clean-css/clean-css-tests.ts b/types/clean-css/clean-css-tests.ts index 1ba3953cfd..7333424f11 100644 --- a/types/clean-css/clean-css-tests.ts +++ b/types/clean-css/clean-css-tests.ts @@ -11,7 +11,7 @@ new CleanCSS().minify(source, function (error, minified) { const pathToOutputDirectory = 'path'; -new CleanCSS({ sourceMap: true, target: pathToOutputDirectory }) +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 @@ -20,15 +20,15 @@ new CleanCSS({ sourceMap: true, target: pathToOutputDirectory }) }); const inputSourceMapAsString = 'input'; -new CleanCSS({ sourceMap: inputSourceMapAsString, target: pathToOutputDirectory }) - .minify(source, function (error, minified) { +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); + console.log(); }); -new CleanCSS({ sourceMap: true, target: pathToOutputDirectory }).minify({ +new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }).minify({ 'path/to/source/1': { styles: '...styles...', sourceMap: '...source-map...' diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index 012977f035..9c32ba8396 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -1,108 +1,625 @@ -// Type definitions for clean-css v3.4.9 +// Type definitions for clean-css v4.2.1 // Project: https://github.com/jakubpawlowicz/clean-css -// Definitions by: Tanguy Krotoff +// Definitions by: Andrew Potter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// +import { RequestOptions as HttpsRequestOptions } from "https"; +import { RequestOptions as HttpRequestOptions } from "http"; declare namespace CleanCSS { + /** + * Options passed when initializing a new instance of CleanCSS + */ interface Options { - // Set to false to disable advanced optimizations - selector & property merging, reduction, etc. - advanced?: boolean; + /** + * Controls compatibility mode used; defaults to ie10+ using `'*'` + */ + compatibility?: "*" | "ie9" | "ie8" | "ie7" | CompatibilityOptions; - // Set to false to disable aggressive merging of properties. - aggressiveMerging?: boolean; + /** + * Controls a function for handling remote requests; Defaults to the build in `loadRemoteResource` function + */ + fetch?: (uri: string, inlineRequest: HttpRequestOptions | HttpsRequestOptions, inlineTimeout: number, callback: FetchCallback) => void; - // Turns on benchmarking mode measuring time spent on cleaning up (run npm run bench to see example) - benchmark?: boolean; + /** + * Controls output CSS formatting; defaults to `false` + */ + format?: "beautify" | "keep-breaks" | Format | false; - // Enables compatibility mode - compatibility?: Object; + /** + * inline option whitelists which @import rules will be processed. Defaults to `'local'` + * Accepts the following values: + * 'local': enables local inlining; + * 'remote': enables remote inlining; + * 'none': disables all inlining; + * 'all': enables all inlining, same as ['local', 'remote']; + * '[uri]': enables remote inlining from the specified uri; + * '![url]': disables remote inlining from the specified uri; + */ + inline?: string[] | false; - // Set to true to get minification statistics under stats property (see test/custom-test.js for examples) - debug?: boolean; + /** + * Controls extra options for inlining remote @import rules + */ + inlineRequest?: HttpRequestOptions | HttpsRequestOptions; - // 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; + /** + * Controls number of milliseconds after which inlining a remote @import fails; defaults to `5000`; + */ + inlineTimeout?: number; - // Whether to keep line breaks (default is false) - keepBreaks?: boolean; + /** + * Controls optimization level used; defaults to `1` + */ + level?: 0 | 1 | 2 | optimizationsOptions; - // * 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 + /** + * Controls URL rebasing; defaults to `true`; + */ rebase?: boolean; - // Path to resolve relative @import rules and URLs - relativeTo?: string; + /** + * controls a directory to which all URLs are rebased, most likely the directory under which the output file + * will live; defaults to the current directory; + */ + rebaseTo?: string; - // Set to false to disable restructuring in advanced optimizations - restructuring?: boolean; + /** + * If you prefer clean-css to return a Promise object then you need to explicitely ask for it; defaults to `false` + */ + returnPromise?: boolean; - // Path to resolve absolute @import rules and rebase relative URLs - root?: string; + /** + * Controls whether an output source map is built; defaults to `false` + */ + sourceMap?: boolean; - // 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. + /** + * Controls embedding sources inside a source map's `sourcesContent` field; defaults to `false` + */ sourceMapInlineSources?: boolean; - - // Path to a folder or an output file to which rebase all URLs - target?: string; } + /** + * Output returned when calling minify functions + */ interface Output { - // Optimized output CSS as a string + /** + * Optimized output CSS as a string + */ styles: string; - // Output source map (if requested with sourceMap option) + /** + * Output source map if requested with `sourceMap` option + */ sourceMap: string; - // A list of errors raised + /** + * A list of errors raised + */ errors: Array; - // A list of warnings raised + /** + * A list of warnings raised + */ warnings: Array; - // A hash of statistic information (if requested with debug option) + /** + * Contains statistics on the minify process + */ stats: { - // Original content size (after import inlining) + /** + * Original content size after import inlining + */ originalSize: number; - // Optimized content size + /** + * Optimized content size + */ minifiedSize: number; - // Time spent on optimizations + /** + * Time spent on optimizations in milliseconds + */ timeSpent: number; - // A ratio of output size to input size (e.g. 25% if content was reduced from 100 bytes to 75 bytes) + /** + * `(originalSize - minifiedSize) / originalSize`, e.g. 0.25 if size is reduced from 100 bytes to 75 bytes + */ efficiency: number; }; } + + /** + * Fine grained configuration for compatibility option + */ + interface CompatibilityOptions { + /** + * A hash of compatibility options related to color + */ + colors?: { + /** + * Controls `rgba()` / `hsla()` color support; defaults to `true` + */ + opacity?: boolean; + }, + /** + * A hash of properties that can be set with compatibility + */ + properties?: { + /** + * Controls background-clip merging into shorthand; defaults to `true` + */ + backgroundClipMerging?: boolean; + + /** + * Controls background-origin merging into shorthand; defaults to `true` + */ + backgroundOriginMerging?: boolean; + + /** + * Controls background-size merging into shorthand; defaults to `true` + */ + backgroundSizeMerging?: boolean; + + /** + * controls color optimizations; defaults to `true` + */ + colors?: boolean, // + + /** + * Controls keeping IE bang hack; defaults to `false` + */ + ieBangHack?: boolean; + + /** + * Controls keeping IE `filter` / `-ms-filter`; defaults to `false` + */ + ieFilters?: boolean; + + /** + * Controls keeping IE prefix hack; defaults to `false` + */ + iePrefixHack?: boolean; + + /** + * Controls keeping IE suffix hack; defaults to `false` + */ + ieSuffixHack?: boolean; + + /** + * Controls property merging based on understandability; defaults to `true` + */ + merging?: boolean; + + /** + * Controls shortening pixel units into `pc`, `pt`, or `in` units; defaults to `false` + */ + shorterLengthUnits?: false; + + /** + * Controls keeping space after closing brace - `url() no-repeat` into `url()no-repeat`; defaults to `true` + */ + spaceAfterClosingBrace?: true; + + /** + * Controls keeping quoting inside `url()`; defaults to `false` + */ + urlQuotes?: boolean; + + /** + * Controls removal of units `0` value; defaults to `true` + */ + zeroUnits?: boolean; + }, + /** + * A hash of options related to compatibility of selectors + */ + selectors?: { + /** + * Controls extra space before `nav` element; defaults to `false` + */ + adjacentSpace?: boolean; + + /** + * Controls removal of IE7 selector hacks, e.g. `*+html...`; defaults to `true` + */ + ie7Hack?: boolean; + + /** + * Controls a whitelist of mergeable pseudo classes; defaults to `[':active', ...]` + */ + mergeablePseudoClasses?: string[]; + + /** + * Controls a whitelist of mergeable pseudo elements; defaults to `['::after', ...]` + */ + mergeablePseudoElements: string[]; + + /** + * Controls maximum number of selectors in a single rule (since 4.1.0); defaults to `8191` + */ + mergeLimit: number; + + /** + * Controls merging of rules with multiple pseudo classes / elements (since 4.1.0); defaults to `true` + */ + multiplePseudoMerging: boolean; + }, + /** + * A hash of options related to comparability of supported units + */ + units?: { + /** + * Controls treating `ch` as a supported unit; defaults to `true` + */ + ch?: boolean; + + /** + * Controls treating `in` as a supported unit; defaults to `true` + */ + in?: boolean; + + /** + * Controls treating `pc` as a supported unit; defaults to `true` + */ + pc?: boolean; + + /** + * Controls treating `pt` as a supported unit; defaults to `true` + */ + pt?: boolean; + + /** + * Controls treating `rem` as a supported unit; defaults to `true` + */ + rem?: boolean; + + /** + * Controls treating `vh` as a supported unit; defaults to `true` + */ + vh?: boolean; + + /** + * Controls treating `vm` as a supported unit; defaults to `true` + */ + vm?: boolean; + + /** + * Controls treating `vmax` as a supported unit; defaults to `true` + */ + vmax?: boolean; + + /** + * Controls treating `vmin` as a supported unit; defaults to `true` + */ + vmin?: boolean; + } + } + + /** + * Fine grained options for configuring the CSS formatting + */ + interface Format { + /** + * Controls where to insert breaks + */ + breaks?: { + /** + * Controls if a line break comes after an at-rule; e.g. `@charset`; defaults to `false` + */ + afterAtRule?: boolean; + + /** + * Controls if a line break comes after a block begins; e.g. `@media`; defaults to `false` + */ + afterBlockBegins?: boolean; + + /** + * Controls if a line break comes after a block ends, defaults to `false` + */ + afterBlockEnds?: boolean; + + /** + * Controls if a line break comes after a comment; defaults to `false` + */ + afterComment?: boolean; + + /** + * Controls if a line break comes after a property; defaults to `false` + */ + afterProperty?: boolean; + + /** + * Controls if a line break comes after a rule begins; defaults to `false` + */ + afterRuleBegins?: boolean; + + /** + * Controls if a line break comes after a rule ends; defaults to `false` + */ + afterRuleEnds?: boolean; + + /** + * Controls if a line break comes before a block ends; defaults to `false` + */ + beforeBlockEnds?: boolean; + + /** + * Controls if a line break comes between selectors; defaults to `false` + */ + betweenSelectors?: boolean; + }, + /** + * Controls the new line character, can be `'\r\n'` or `'\n'`(aliased as `'windows'` and `'unix'` + * or `'crlf'` and `'lf'`); defaults to system one, so former on Windows and latter on Unix + */ + breakWith?: string; + + /** + * Controls number of characters to indent with; defaults to `0` + */ + indentBy?: number; + + /** + * Controls a character to indent with, can be `'space'` or `'tab'`; defaults to `'space'` + */ + indentWith?: "space" | "tab"; + + /** + * Controls where to insert spaces + */ + spaces?: { + /** + * Controls if spaces come around selector relations; e.g. `div > a`; defaults to `false` + */ + aroundSelectorRelation?: boolean; + + /** + * Controls if a space comes before a block begins; e.g. `.block {`; defaults to `false` + */ + beforeBlockBegins?: boolean; + + /** + * Controls if a space comes before a value; e.g. `width: 1rem`; defaults to `false` + */ + beforeValue?: boolean; + }, + /** + * Controls maximum line length; defaults to `false` + */ + wrapAt?: false | number; + } + + /** + * Fine grained options for configuring optimizations + */ + interface optimizationsOptions { + 1?: { + /** + * Sets all optimizations at this level unless otherwise specified + */ + all?: boolean; + + /** + * Controls `@charset` moving to the front of a stylesheet; defaults to `true` + */ + cleanupCharsets?: boolean; + + /** + * Controls URL normalization; defaults to `true` + */ + normalizeUrls?: boolean; + + /** + * Controls `background` property optimizations; defaults to `true` + */ + optimizeBackground?: boolean; + + /** + * Controls `border-radius` property optimizations; defaults to `true` + */ + optimizeBorderRadius?: boolean; + + /** + * Controls `filter` property optimizations; defaults to `true` + */ + optimizeFilter?: boolean; + + /** + * Controls `font` property optimizations; defaults to `true` + */ + optimizeFont?: boolean; + + /** + * Controls `font-weight` property optimizations; defaults to `true` + */ + optimizeFontWeight?: boolean; + + /** + * Controls `outline` property optimizations; defaults to `true` + */ + optimizeOutline?: boolean; + + /** + * Controls removing empty rules and nested blocks; defaults to `true` + */ + removeEmpty?: boolean; + + /** + * Controls removing negative paddings; defaults to `true` + */ + removeNegativePaddings?: boolean; + + /** + * Controls removing quotes when unnecessary; defaults to `true` + */ + removeQuotes?: boolean; + + /** + * Controls removing unused whitespace; defaults to `true` + */ + removeWhitespace?: boolean; + + /** + * Contols removing redundant zeros; defaults to `true` + */ + replaceMultipleZeros?: boolean; + + /** + * Controls replacing time units with shorter values; defaults to `true` + */ + replaceTimeUnits?: boolean; + + /** + * Controls replacing zero values with units; defaults to `true` + */ + replaceZeroUnits?: boolean; + + /** + * Rounds pixel values to `N` decimal places; `false` disables rounding; defaults to `false` + */ + roundingPrecision?: boolean; + + /** + * denotes selector sorting method; can be `'natural'` or `'standard'`, `'none'`, or false (the last two + * since 4.1.0); defaults to `'standard'` + */ + selectorsSortingMethod?: "standard" | "natural" | "none"; + + /** + * denotes a number of /*! ... * / comments preserved; defaults to `all` + */ + specialComments?: string; + + /** + * Controls at-rules (e.g. `@charset`, `@import`) optimizing; defaults to `true` + */ + tidyAtRules?: boolean; + + /** + * Controls block scopes (e.g. `@media`) optimizing; defaults to `true` + */ + tidyBlockScopes?: boolean; + + /** + * Controls selectors optimizing; defaults to `true` + */ + tidySelectors?: boolean; + + /** + * Controls removing trailing semicolons in rule; defaults to `false` - means remove + */ + semicolonAfterLastProperty?: boolean; + + /** + * Defines a callback for fine-grained property optimization; defaults to no-op + */ + transform?: (propertyName: string, propertyValue: string, selector: string) => string; + }, + 2?: { + /** + * Sets all optimizations at this level unless otherwise specified + */ + all?: boolean; + + /** + * Controls adjacent rules merging; defaults to true + */ + mergeAdjacentRules?: boolean; + + /** + * Controls merging properties into shorthands; defaults to true + */ + mergeIntoShorthands?: boolean; + + /** + * Controls `@media` merging; defaults to true + */ + mergeMedia?: boolean; + + /** + * Controls non-adjacent rule merging; defaults to true + */ + mergeNonAdjacentRules?: boolean; + + /** + * Controls semantic merging; defaults to false + */ + mergeSemantically?: boolean; + + /** + * Controls property overriding based on understandability; defaults to true + */ + overrideProperties?: boolean; + + /** + * Controls removing empty rules and nested blocks; defaults to `true` + */ + removeEmpty?: boolean; + + /** + * Controls non-adjacent rule reducing; defaults to true + */ + reduceNonAdjacentRules?: boolean; + + /** + * Controls duplicate `@font-face` removing; defaults to true + */ + removeDuplicateFontRules?: boolean; + + /** + * Controls duplicate `@media` removing; defaults to true + */ + removeDuplicateMediaBlocks?: boolean; + + /** + * Controls duplicate rules removing; defaults to true + */ + removeDuplicateRules?: boolean; + + /** + * Controls unused at rule removing; defaults to false (available since 4.1.0) + */ + removeUnusedAtRules?: boolean; + + /** + * Controls rule restructuring; defaults to false + */ + restructureRules?: boolean; + + /** + * Controls which properties won't be optimized, defaults to `[]` which means all will be optimized (since 4.1.0) + */ + skipProperties?: string[]; + } + } + + /** + * Callback type when fetch is used + */ + type FetchCallback = (message: string | number, body: string) => void; + + /** + * + */ + 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; + } + + interface Constructor { + new(options: CleanCSS.Options & { returnPromise?: false }): Function; + new(options: CleanCSS.Options & { returnPromise: true }): Function>; + new(): Function; + } } -declare class CleanCSS { - constructor(options?: CleanCSS.Options); - minify(sources: string | Array | Object, callback?: (error: any, minified: CleanCSS.Output) => void): CleanCSS.Output; -} +/** + * + */ +declare const CleanCSS: CleanCSS.Constructor; export = CleanCSS; From 284308ed72340b9b750f70034a3f680712aadf2d Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 10:25:08 -0700 Subject: [PATCH 02/14] Updated documentation on clean-css type definitions Change Array to string[] as part of P&P update Removed empty constructor as existing constructor meets requirement Removed unneeded testing file --- types/clean-css/clean-css-tests.ts | 54 ------------------------------ types/clean-css/index.d.ts | 27 +++++++++------ types/clean-css/tsconfig.json | 3 +- 3 files changed, 17 insertions(+), 67 deletions(-) delete mode 100644 types/clean-css/clean-css-tests.ts diff --git a/types/clean-css/clean-css-tests.ts b/types/clean-css/clean-css-tests.ts deleted file mode 100644 index 7333424f11..0000000000 --- a/types/clean-css/clean-css-tests.ts +++ /dev/null @@ -1,54 +0,0 @@ - -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(); -}); - -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' - } -}); diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index 9c32ba8396..b8b52086f6 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -13,17 +13,19 @@ declare namespace CleanCSS { */ interface Options { /** - * Controls compatibility mode used; defaults to ie10+ using `'*'` + * Controls compatibility mode used; defaults to ie10+ using `'*'`. + * Compatibility hash exposes the following properties: `colors`, `properties`, `selectors`, and `units` */ compatibility?: "*" | "ie9" | "ie8" | "ie7" | CompatibilityOptions; /** * Controls a function for handling remote requests; Defaults to the build in `loadRemoteResource` function */ - fetch?: (uri: string, inlineRequest: HttpRequestOptions | HttpsRequestOptions, inlineTimeout: number, callback: FetchCallback) => void; + fetch?: (uri: string, inlineRequest: HttpRequestOptions | HttpsRequestOptions, inlineTimeout: number, done: (message: string | number, body: string) => void) => void; /** - * Controls output CSS formatting; defaults to `false` + * 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; @@ -50,7 +52,8 @@ declare namespace CleanCSS { inlineTimeout?: number; /** - * Controls optimization level used; defaults to `1` + * Controls optimization level used; defaults to `1`. + * Level hash exposes `1`, and `2`. */ level?: 0 | 1 | 2 | optimizationsOptions; @@ -98,12 +101,12 @@ declare namespace CleanCSS { /** * A list of errors raised */ - errors: Array; + errors: string[]; /** * A list of warnings raised */ - warnings: Array; + warnings: string[]; /** * Contains statistics on the minify process @@ -516,7 +519,7 @@ declare namespace CleanCSS { /** * Defines a callback for fine-grained property optimization; defaults to no-op */ - transform?: (propertyName: string, propertyValue: string, selector: string) => string; + transform?: (propertyName: string, propertyValue: string, selector?: string) => string; }, 2?: { /** @@ -602,7 +605,7 @@ declare namespace CleanCSS { type FetchCallback = (message: string | number, body: string) => void; /** - * + * Interface exposed when a new CleanCSS option is created */ interface Function)> { minify(sources: string | Array | Object, callback?: (error: any, output: T) => void): T; @@ -610,15 +613,17 @@ declare namespace CleanCSS { minify(sources: string | Array | Object, inputSourceMap?: string, callback?: (error: any, output: T) => void): T; } + /** + * Constructor interface for CleanCSS + */ interface Constructor { - new(options: CleanCSS.Options & { returnPromise?: false }): Function; new(options: CleanCSS.Options & { returnPromise: true }): Function>; - new(): Function; + new(options?: CleanCSS.Options): Function; } } /** - * + * Creates a new CleanCSS object */ declare const CleanCSS: CleanCSS.Constructor; diff --git a/types/clean-css/tsconfig.json b/types/clean-css/tsconfig.json index fe65b21c11..82e6284376 100644 --- a/types/clean-css/tsconfig.json +++ b/types/clean-css/tsconfig.json @@ -18,7 +18,6 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts", - "clean-css-tests.ts" + "index.d.ts" ] } \ No newline at end of file From 7e2d67fba7c1218fb82818313033aed939041fb3 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:17:21 -0700 Subject: [PATCH 03/14] Fixed dependance on v3 for definitons which use v3 clean-css Added sources to replace object definition Updated tests --- types/clean-css/clean-css-tests.ts | 81 +++++++++++++++++++ types/clean-css/index.d.ts | 68 ++++++++++++---- types/clean-css/tsconfig.json | 3 +- types/clean-css/tslint.json | 78 +------------------ types/clean-css/v3/clean-css-tests.ts | 54 +++++++++++++ types/clean-css/v3/index.d.ts | 108 ++++++++++++++++++++++++++ types/clean-css/v3/tsconfig.json | 32 ++++++++ types/clean-css/v3/tslint.json | 79 +++++++++++++++++++ types/gulp-minify-css/index.d.ts | 2 +- types/html-minifier/v1/index.d.ts | 2 +- 10 files changed, 412 insertions(+), 95 deletions(-) create mode 100644 types/clean-css/clean-css-tests.ts create mode 100644 types/clean-css/v3/clean-css-tests.ts create mode 100644 types/clean-css/v3/index.d.ts create mode 100644 types/clean-css/v3/tsconfig.json create mode 100644 types/clean-css/v3/tslint.json 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 { From 1cacaa5f8f0941b2bede45b8f45969d5517425f1 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:23:28 -0700 Subject: [PATCH 04/14] Updated typescript declaration --- types/clean-css/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index 606b9ba951..3bb32e9100 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -3,7 +3,6 @@ // Definitions by: Tanguy Krotoff // Andrew Potter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.2 /// import { RequestOptions as HttpsRequestOptions } from "https"; From 703573fab6b1e67f54726bb8816c5e8989a493a5 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:37:18 -0700 Subject: [PATCH 05/14] Bug fixes --- types/clean-css/clean-css-tests.ts | 16 ++++++------- types/clean-css/index.d.ts | 36 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/types/clean-css/clean-css-tests.ts b/types/clean-css/clean-css-tests.ts index 5613f3a334..f87d2f222e 100644 --- a/types/clean-css/clean-css-tests.ts +++ b/types/clean-css/clean-css-tests.ts @@ -1,18 +1,18 @@ import * as CleanCSS from 'clean-css'; -var source = 'a{font-weight:bold;}'; -var minified = new CleanCSS().minify(source).styles; +let source = 'a{font-weight:bold;}'; +console.log(new CleanCSS().minify(source).styles); -var source = '@import url(http://path/to/remote/styles);'; -new CleanCSS().minify(source, function (error, minified) { +source = '@import url(http://path/to/remote/styles);'; +new CleanCSS().minify(source, (error: any, minified: CleanCSS.Output): void => { console.log(minified.styles); }); const pathToOutputDirectory = 'path'; new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }) - .minify(source, function (error, minified) { + .minify(source, (error: any, minified: CleanCSS.Output): void => { // 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 @@ -21,7 +21,7 @@ new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }) const inputSourceMapAsString = 'input'; new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }) - .minify(source, inputSourceMapAsString, function (error, minified) { + .minify(source, inputSourceMapAsString, (error: any, minified: CleanCSS.Output): void => { // 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 @@ -37,7 +37,7 @@ new CleanCSS({ sourceMap: true, rebaseTo: pathToOutputDirectory }).minify({ styles: '...styles...', sourceMap: '...source-map...' } -}, function (error, minified) { +}, (error: any, minified: CleanCSS.Output): void => { // access minified.sourceMap as above console.log(minified.sourceMap); }); @@ -78,4 +78,4 @@ new CleanCSS({ returnPromise: true, sourceMap: true }).minify(source, inputSourc }).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 3bb32e9100..888e226ea6 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for clean-css v4.2.1 +// Type definitions for clean-css v4.2 // Project: https://github.com/jakubpawlowicz/clean-css // Definitions by: Tanguy Krotoff // Andrew Potter @@ -32,13 +32,13 @@ declare namespace CleanCSS { /** * inline option whitelists which @import rules will be processed. Defaults to `'local'` - * Accepts the following values: - * 'local': enables local inlining; - * 'remote': enables remote inlining; - * 'none': disables all inlining; - * 'all': enables all inlining, same as ['local', 'remote']; - * '[uri]': enables remote inlining from the specified uri; - * '![url]': disables remote inlining from the specified uri; + * Accepts the following values: + * 'local': enables local inlining; + * 'remote': enables remote inlining; + * 'none': disables all inlining; + * 'all': enables all inlining, same as ['local', 'remote']; + * '[uri]': enables remote inlining from the specified uri; + * '![url]': disables remote inlining from the specified uri; */ inline?: string[] | false; @@ -147,7 +147,7 @@ declare namespace CleanCSS { * Controls `rgba()` / `hsla()` color support; defaults to `true` */ opacity?: boolean; - }, + }; /** * A hash of properties that can be set with compatibility */ @@ -216,7 +216,7 @@ declare namespace CleanCSS { * Controls removal of units `0` value; defaults to `true` */ zeroUnits?: boolean; - }, + }; /** * A hash of options related to compatibility of selectors */ @@ -250,7 +250,7 @@ declare namespace CleanCSS { * Controls merging of rules with multiple pseudo classes / elements (since 4.1.0); defaults to `true` */ multiplePseudoMerging: boolean; - }, + }; /** * A hash of options related to comparability of supported units */ @@ -299,7 +299,7 @@ declare namespace CleanCSS { * Controls treating `vmin` as a supported unit; defaults to `true` */ vmin?: boolean; - } + }; } /** @@ -354,7 +354,7 @@ declare namespace CleanCSS { * Controls if a line break comes between selectors; defaults to `false` */ betweenSelectors?: boolean; - }, + }; /** * Controls the new line character, can be `'\r\n'` or `'\n'`(aliased as `'windows'` and `'unix'` * or `'crlf'` and `'lf'`); defaults to system one, so former on Windows and latter on Unix @@ -389,7 +389,7 @@ declare namespace CleanCSS { * Controls if a space comes before a value; e.g. `width: 1rem`; defaults to `false` */ beforeValue?: boolean; - }, + }; /** * Controls maximum line length; defaults to `false` */ @@ -521,7 +521,7 @@ declare namespace CleanCSS { * Defines a callback for fine-grained property optimization; defaults to no-op */ transform?: (propertyName: string, propertyValue: string, selector?: string) => string; - }, + }; 2?: { /** * Sets all optimizations at this level unless otherwise specified @@ -597,7 +597,7 @@ declare namespace CleanCSS { * Controls which properties won't be optimized, defaults to `[]` which means all will be optimized (since 4.1.0) */ skipProperties?: string[]; - } + }; } /** @@ -618,7 +618,7 @@ declare namespace CleanCSS { * The source map of the file, if needed */ sourceMap?: string; - } + }; } /** @@ -636,7 +636,7 @@ declare namespace CleanCSS { */ type Minifier = MinifierOutput | MinifierPromise; - /** + /** * Interface exposed when a new CleanCSS object is created */ interface MinifierOutput { From bbcd8b448616568b78cf3f53001946122789884b Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:43:06 -0700 Subject: [PATCH 06/14] fixed paths for dependant modules --- types/gulp-minify-css/index.d.ts | 2 +- types/gulp-minify-css/tsconfig.json | 8 ++++++++ types/html-minifier/v1/index.d.ts | 2 +- types/html-minifier/v1/tsconfig.json | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/types/gulp-minify-css/index.d.ts b/types/gulp-minify-css/index.d.ts index a826efcfb3..d347cf0708 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/v3'; +import * as CleanCSS from 'clean-css'; declare function minifyCSS(options?: CleanCSS.Options): NodeJS.ReadWriteStream; diff --git a/types/gulp-minify-css/tsconfig.json b/types/gulp-minify-css/tsconfig.json index ccb2e4b319..0742a43568 100644 --- a/types/gulp-minify-css/tsconfig.json +++ b/types/gulp-minify-css/tsconfig.json @@ -12,6 +12,14 @@ "typeRoots": [ "../" ], + "paths": { + "clean-css": [ + "clean-css/v3" + ], + "clean-css/*": [ + "clean-css/v3/*" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/types/html-minifier/v1/index.d.ts b/types/html-minifier/v1/index.d.ts index a724bbd497..c1ff944e7e 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/v3'; +import * as CleanCSS from 'clean-css'; import * as RelateUrl from 'relateurl'; declare namespace HTMLMinifier { diff --git a/types/html-minifier/v1/tsconfig.json b/types/html-minifier/v1/tsconfig.json index 846fa3a1f6..1b6d4e41ea 100644 --- a/types/html-minifier/v1/tsconfig.json +++ b/types/html-minifier/v1/tsconfig.json @@ -21,6 +21,12 @@ ], "html-minifier/*": [ "html-minifier/v1/*" + ], + "clean-css": [ + "clean-css/v3" + ], + "clean-css/*": [ + "clean-css/v3/*" ] }, "types": [], From ef680a4b1beec13c0bbae55a7124bb4f397a732e Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:47:41 -0700 Subject: [PATCH 07/14] additional bug fixes --- types/clean-css/clean-css-tests.ts | 3 ++- types/clean-css/index.d.ts | 32 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/types/clean-css/clean-css-tests.ts b/types/clean-css/clean-css-tests.ts index f87d2f222e..0fa7f01034 100644 --- a/types/clean-css/clean-css-tests.ts +++ b/types/clean-css/clean-css-tests.ts @@ -1,4 +1,5 @@ - +// Original by Tanguy Krotoff +// Updated by Andrew Potter import * as CleanCSS from 'clean-css'; let source = 'a{font-weight:bold;}'; diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index 888e226ea6..0c1ec07937 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for clean-css v4.2 +// Type definitions for clean-css 4.2.1 // Project: https://github.com/jakubpawlowicz/clean-css // Definitions by: Tanguy Krotoff // Andrew Potter @@ -170,7 +170,7 @@ declare namespace CleanCSS { /** * controls color optimizations; defaults to `true` */ - colors?: boolean, // + colors?: boolean, /** * Controls keeping IE bang hack; defaults to `false` @@ -314,42 +314,42 @@ declare namespace CleanCSS { * Controls if a line break comes after an at-rule; e.g. `@charset`; defaults to `false` */ afterAtRule?: boolean; - + /** * Controls if a line break comes after a block begins; e.g. `@media`; defaults to `false` */ afterBlockBegins?: boolean; - + /** * Controls if a line break comes after a block ends, defaults to `false` */ afterBlockEnds?: boolean; - + /** * Controls if a line break comes after a comment; defaults to `false` */ afterComment?: boolean; - + /** * Controls if a line break comes after a property; defaults to `false` */ afterProperty?: boolean; - + /** * Controls if a line break comes after a rule begins; defaults to `false` */ afterRuleBegins?: boolean; - + /** * Controls if a line break comes after a rule ends; defaults to `false` */ afterRuleEnds?: boolean; - + /** * Controls if a line break comes before a block ends; defaults to `false` */ beforeBlockEnds?: boolean; - + /** * Controls if a line break comes between selectors; defaults to `false` */ @@ -360,17 +360,17 @@ declare namespace CleanCSS { * or `'crlf'` and `'lf'`); defaults to system one, so former on Windows and latter on Unix */ breakWith?: string; - + /** * Controls number of characters to indent with; defaults to `0` */ indentBy?: number; - + /** * Controls a character to indent with, can be `'space'` or `'tab'`; defaults to `'space'` */ indentWith?: "space" | "tab"; - + /** * Controls where to insert spaces */ @@ -379,12 +379,12 @@ declare namespace CleanCSS { * Controls if spaces come around selector relations; e.g. `div > a`; defaults to `false` */ aroundSelectorRelation?: boolean; - + /** * Controls if a space comes before a block begins; e.g. `.block {`; defaults to `false` */ beforeBlockBegins?: boolean; - + /** * Controls if a space comes before a value; e.g. `width: 1rem`; defaults to `false` */ @@ -460,7 +460,7 @@ declare namespace CleanCSS { * Controls removing quotes when unnecessary; defaults to `true` */ removeQuotes?: boolean; - + /** * Controls removing unused whitespace; defaults to `true` */ From 462214dcff5ddde443b661114cadf8d4f55aa4ed Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:49:34 -0700 Subject: [PATCH 08/14] fixed paths on gulp-useref --- types/gulp-useref/tsconfig.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/gulp-useref/tsconfig.json b/types/gulp-useref/tsconfig.json index b8a3dc7bba..4dc6f70464 100644 --- a/types/gulp-useref/tsconfig.json +++ b/types/gulp-useref/tsconfig.json @@ -12,6 +12,14 @@ "typeRoots": [ "../" ], + "paths": { + "clean-css": [ + "clean-css/v3" + ], + "clean-css/*": [ + "clean-css/v3/*" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true From 25f2a9c7f93542e14f954ff0a5c5bcfb2ce23af6 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:50:55 -0700 Subject: [PATCH 09/14] fixed paths for gulp-rev-replace --- types/gulp-rev-replace/tsconfig.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/types/gulp-rev-replace/tsconfig.json b/types/gulp-rev-replace/tsconfig.json index d6b9abe0ba..736d44e64d 100644 --- a/types/gulp-rev-replace/tsconfig.json +++ b/types/gulp-rev-replace/tsconfig.json @@ -12,6 +12,14 @@ "typeRoots": [ "../" ], + "paths": { + "clean-css": [ + "clean-css/v3" + ], + "clean-css/*": [ + "clean-css/v3/*" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true From 55aec8aeee69aef074cb1a8fc6d92df9bc9e96f2 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:56:08 -0700 Subject: [PATCH 10/14] version update --- types/clean-css/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index 0c1ec07937..aca3a0242d 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -3,8 +3,8 @@ // Definitions by: Tanguy Krotoff // Andrew Potter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - /// + import { RequestOptions as HttpsRequestOptions } from "https"; import { RequestOptions as HttpRequestOptions } from "http"; From 141c38ba8767f62417d0cb43744f14544479d271 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 14:58:14 -0700 Subject: [PATCH 11/14] Fixed version number --- types/clean-css/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index aca3a0242d..c2a1ac0b4b 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -1,10 +1,10 @@ -// Type definitions for clean-css 4.2.1 +// Type definitions for clean-css 4.2 // Project: https://github.com/jakubpawlowicz/clean-css // Definitions by: Tanguy Krotoff // Andrew Potter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +/// import { RequestOptions as HttpsRequestOptions } from "https"; import { RequestOptions as HttpRequestOptions } from "http"; From fea4f48e28efe890cbc4ad1fcfbe4757890a1d11 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 15:03:42 -0700 Subject: [PATCH 12/14] version update --- types/clean-css/clean-css-tests.ts | 1 + types/clean-css/index.d.ts | 2 +- types/gulp-minify-css/tsconfig.json | 2 +- types/gulp-rev-replace/tsconfig.json | 2 +- types/gulp-useref/tsconfig.json | 2 +- types/html-minifier/v1/tsconfig.json | 6 +++--- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/types/clean-css/clean-css-tests.ts b/types/clean-css/clean-css-tests.ts index 0fa7f01034..9c856d40a1 100644 --- a/types/clean-css/clean-css-tests.ts +++ b/types/clean-css/clean-css-tests.ts @@ -1,5 +1,6 @@ // Original by Tanguy Krotoff // Updated by Andrew Potter + import * as CleanCSS from 'clean-css'; let source = 'a{font-weight:bold;}'; diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index c2a1ac0b4b..d45257f71d 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -3,8 +3,8 @@ // Definitions by: Tanguy Krotoff // Andrew Potter // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - /// + import { RequestOptions as HttpsRequestOptions } from "https"; import { RequestOptions as HttpRequestOptions } from "http"; diff --git a/types/gulp-minify-css/tsconfig.json b/types/gulp-minify-css/tsconfig.json index 0742a43568..9842b6f37f 100644 --- a/types/gulp-minify-css/tsconfig.json +++ b/types/gulp-minify-css/tsconfig.json @@ -19,7 +19,7 @@ "clean-css/*": [ "clean-css/v3/*" ] - }, + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/types/gulp-rev-replace/tsconfig.json b/types/gulp-rev-replace/tsconfig.json index 736d44e64d..ecdd847306 100644 --- a/types/gulp-rev-replace/tsconfig.json +++ b/types/gulp-rev-replace/tsconfig.json @@ -19,7 +19,7 @@ "clean-css/*": [ "clean-css/v3/*" ] - }, + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/types/gulp-useref/tsconfig.json b/types/gulp-useref/tsconfig.json index 4dc6f70464..9011065709 100644 --- a/types/gulp-useref/tsconfig.json +++ b/types/gulp-useref/tsconfig.json @@ -19,7 +19,7 @@ "clean-css/*": [ "clean-css/v3/*" ] - }, + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/types/html-minifier/v1/tsconfig.json b/types/html-minifier/v1/tsconfig.json index 1b6d4e41ea..2ea7965d25 100644 --- a/types/html-minifier/v1/tsconfig.json +++ b/types/html-minifier/v1/tsconfig.json @@ -16,12 +16,12 @@ "html-minifier": [ "html-minifier/v1" ], - "uglify-js": [ - "uglify-js/v2" - ], "html-minifier/*": [ "html-minifier/v1/*" ], + "uglify-js": [ + "uglify-js/v2" + ], "clean-css": [ "clean-css/v3" ], From 9b56cd699b55b5c2b83d5b1617465e229f51fae3 Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 15:06:08 -0700 Subject: [PATCH 13/14] version update --- types/gulp-minify-css/tsconfig.json | 2 +- types/gulp-rev-replace/tsconfig.json | 2 +- types/gulp-useref/tsconfig.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/gulp-minify-css/tsconfig.json b/types/gulp-minify-css/tsconfig.json index 9842b6f37f..0742a43568 100644 --- a/types/gulp-minify-css/tsconfig.json +++ b/types/gulp-minify-css/tsconfig.json @@ -19,7 +19,7 @@ "clean-css/*": [ "clean-css/v3/*" ] - }, + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/types/gulp-rev-replace/tsconfig.json b/types/gulp-rev-replace/tsconfig.json index ecdd847306..736d44e64d 100644 --- a/types/gulp-rev-replace/tsconfig.json +++ b/types/gulp-rev-replace/tsconfig.json @@ -19,7 +19,7 @@ "clean-css/*": [ "clean-css/v3/*" ] - }, + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true diff --git a/types/gulp-useref/tsconfig.json b/types/gulp-useref/tsconfig.json index 9011065709..4dc6f70464 100644 --- a/types/gulp-useref/tsconfig.json +++ b/types/gulp-useref/tsconfig.json @@ -19,7 +19,7 @@ "clean-css/*": [ "clean-css/v3/*" ] - }, + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true From 2a1fd4d9996cdac913a69979ec7c6508d5cf02ed Mon Sep 17 00:00:00 2001 From: Andrew Potter Date: Thu, 24 Jan 2019 15:26:47 -0700 Subject: [PATCH 14/14] Changed a few string[] to ReadonlyArray --- types/clean-css/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/clean-css/index.d.ts b/types/clean-css/index.d.ts index d45257f71d..244c585e53 100644 --- a/types/clean-css/index.d.ts +++ b/types/clean-css/index.d.ts @@ -40,7 +40,7 @@ declare namespace CleanCSS { * '[uri]': enables remote inlining from the specified uri; * '![url]': disables remote inlining from the specified uri; */ - inline?: string[] | false; + inline?: ReadonlyArray | false; /** * Controls extra options for inlining remote @import rules @@ -234,12 +234,12 @@ declare namespace CleanCSS { /** * Controls a whitelist of mergeable pseudo classes; defaults to `[':active', ...]` */ - mergeablePseudoClasses?: string[]; + mergeablePseudoClasses?: ReadonlyArray; /** * Controls a whitelist of mergeable pseudo elements; defaults to `['::after', ...]` */ - mergeablePseudoElements: string[]; + mergeablePseudoElements: ReadonlyArray; /** * Controls maximum number of selectors in a single rule (since 4.1.0); defaults to `8191` @@ -596,7 +596,7 @@ declare namespace CleanCSS { /** * Controls which properties won't be optimized, defaults to `[]` which means all will be optimized (since 4.1.0) */ - skipProperties?: string[]; + skipProperties?: ReadonlyArray; }; }