From 4f3ddd0a47ec29cf8a723bd68ebc4b724e03dc7e Mon Sep 17 00:00:00 2001 From: Floriel Date: Wed, 23 Feb 2022 19:31:10 +0000 Subject: [PATCH] fix: wrong path import - fix wrong path import (was importing path/posix instead of path - add vinyl-sourcempas-apply to external (rollup config) - run prettier --- packages/gulp-purgecss/build.ts | 1 + packages/gulp-purgecss/src/index.ts | 4 +-- packages/postcss-purgecss/src/index.ts | 6 ++-- packages/postcss-purgecss/src/types/index.ts | 10 +++---- packages/purgecss-from-html/src/index.ts | 4 +-- packages/purgecss-from-jsx/src/index.ts | 4 +-- packages/purgecss-from-pug/src/index.ts | 4 +-- packages/purgecss-from-tsx/src/index.ts | 4 +-- .../src/types/index.ts | 16 +++++----- packages/purgecss/__tests__/sourcemap.test.ts | 24 ++++++++------- packages/purgecss/src/types/index.ts | 30 +++++++++---------- packages/rollup-plugin-purgecss/src/index.ts | 6 ++-- scripts/build.ts | 4 +-- types/vinyl-sourcemaps-apply/index.d.ts | 2 +- 14 files changed, 63 insertions(+), 56 deletions(-) diff --git a/packages/gulp-purgecss/build.ts b/packages/gulp-purgecss/build.ts index f36ef0bd..0b109b0a 100644 --- a/packages/gulp-purgecss/build.ts +++ b/packages/gulp-purgecss/build.ts @@ -16,6 +16,7 @@ import * as path from "path"; "plugin-error", "purgecss", "glob", + "vinyl-sourcemaps-apply", ]); await buildRollup(rollupConfig); await extractAPI(__dirname); diff --git a/packages/gulp-purgecss/src/index.ts b/packages/gulp-purgecss/src/index.ts index f0ad2c37..cbb89f34 100644 --- a/packages/gulp-purgecss/src/index.ts +++ b/packages/gulp-purgecss/src/index.ts @@ -40,7 +40,7 @@ function gulpPurgeCSS(options: UserDefinedOptions): internal.Transform { }, ], stdin: true, - sourceMap: !!file.sourceMap + sourceMap: !!file.sourceMap, }; const purgedCSSResults = await new PurgeCSS().purge(optionsGulp); const purge = purgedCSSResults[0]; @@ -77,7 +77,7 @@ function gulpPurgeCSS(options: UserDefinedOptions): internal.Transform { raw: css, }, ], - sourceMap: !!file.sourceMap + sourceMap: !!file.sourceMap, }; const purgedCSSResults = await new PurgeCSS().purge(optionsGulp); diff --git a/packages/postcss-purgecss/src/index.ts b/packages/postcss-purgecss/src/index.ts index d89d08ec..2461f0a1 100644 --- a/packages/postcss-purgecss/src/index.ts +++ b/packages/postcss-purgecss/src/index.ts @@ -73,10 +73,10 @@ async function purgeCSS( } /** - * + * * @param opts - opts - * @returns - * + * @returns + * * @public */ const purgeCSSPlugin: postcss.PluginCreator = function ( diff --git a/packages/postcss-purgecss/src/types/index.ts b/packages/postcss-purgecss/src/types/index.ts index d330fe78..4f1b885c 100644 --- a/packages/postcss-purgecss/src/types/index.ts +++ b/packages/postcss-purgecss/src/types/index.ts @@ -1,15 +1,15 @@ import { UserDefinedOptions as PurgeCSSUserDefinedOptions, - RawContent + RawContent, } from "purgecss"; - /** * {@inheritDoc purgecss#UserDefinedOptions} - * + * * @public */ -export interface UserDefinedOptions extends Omit { - content?: PurgeCSSUserDefinedOptions['content']; +export interface UserDefinedOptions + extends Omit { + content?: PurgeCSSUserDefinedOptions["content"]; contentFunction?: (sourceFile: string) => Array; } diff --git a/packages/purgecss-from-html/src/index.ts b/packages/purgecss-from-html/src/index.ts index 9018ca8d..7db44bff 100644 --- a/packages/purgecss-from-html/src/index.ts +++ b/packages/purgecss-from-html/src/index.ts @@ -95,10 +95,10 @@ const getSelectorsInNodes = ( /** * Get the potential selectors from HTML code - * + * * @param content - HTML code * @returns the attributes, classes, ids, and tags from the HTML code - * + * * @public */ const purgecssFromHtml = (content: string): ExtractorResultDetailed => { diff --git a/packages/purgecss-from-jsx/src/index.ts b/packages/purgecss-from-jsx/src/index.ts index 69748ab6..b627e4c7 100644 --- a/packages/purgecss-from-jsx/src/index.ts +++ b/packages/purgecss-from-jsx/src/index.ts @@ -18,10 +18,10 @@ extend(walk.base); /** * Create function to extract selectors from jsx code - * + * * @param options - acorn options * @returns function to extract selectors from jsx code - * + * * @public */ function purgeFromJsx(options?: acorn.Options) { diff --git a/packages/purgecss-from-pug/src/index.ts b/packages/purgecss-from-pug/src/index.ts index ebc4f5ec..7db17add 100644 --- a/packages/purgecss-from-pug/src/index.ts +++ b/packages/purgecss-from-pug/src/index.ts @@ -2,10 +2,10 @@ import lex from "pug-lexer"; /** * Get the potential selectors from Pug code - * + * * @param content - Pug code * @returns the attributes, classes, ids, and tags from the Pug code - * + * * @public */ const purgeFromPug = (content: string): string[] => { diff --git a/packages/purgecss-from-tsx/src/index.ts b/packages/purgecss-from-tsx/src/index.ts index 2c74ba3a..5ebfb034 100644 --- a/packages/purgecss-from-tsx/src/index.ts +++ b/packages/purgecss-from-tsx/src/index.ts @@ -4,10 +4,10 @@ import * as ts from "typescript"; /** * Create function to extract selectors from tsx code - * + * * @param options - acorn options * @returns the function to extract selectors from tsx code - * + * * @public */ function purgeFromTsx(options?: { diff --git a/packages/purgecss-webpack-plugin/src/types/index.ts b/packages/purgecss-webpack-plugin/src/types/index.ts index aa22add1..eac456a9 100644 --- a/packages/purgecss-webpack-plugin/src/types/index.ts +++ b/packages/purgecss-webpack-plugin/src/types/index.ts @@ -1,12 +1,11 @@ import type { ComplexSafelist, StringRegExpArray, - UserDefinedOptions as PurgeCSSUserDefinedOptions + UserDefinedOptions as PurgeCSSUserDefinedOptions, } from "purgecss"; - /** - * @public + * @public */ export type PathFunction = () => string[]; /** @@ -28,11 +27,14 @@ export type PurgedStats = { /** * @public */ -export type UserDefinedOptions = Omit & { +export type UserDefinedOptions = Omit< + PurgeCSSUserDefinedOptions, + "css" | "content" | "safelist" | "blocklist" | "sourceMap" +> & { paths: string[] | PathFunction; moduleExtensions?: string[]; verbose?: boolean; - safelist: PurgeCSSUserDefinedOptions['safelist'] | SafelistFunction; - blocklist: PurgeCSSUserDefinedOptions['blocklist'] | BlocklistFunction; + safelist: PurgeCSSUserDefinedOptions["safelist"] | SafelistFunction; + blocklist: PurgeCSSUserDefinedOptions["blocklist"] | BlocklistFunction; only?: string[]; -} +}; diff --git a/packages/purgecss/__tests__/sourcemap.test.ts b/packages/purgecss/__tests__/sourcemap.test.ts index d8703811..608b0976 100644 --- a/packages/purgecss/__tests__/sourcemap.test.ts +++ b/packages/purgecss/__tests__/sourcemap.test.ts @@ -1,26 +1,30 @@ -import { PurgeCSS } from '../src/' -import { ROOT_TEST_EXAMPLES } from './utils'; +import { PurgeCSS } from "../src/"; +import { ROOT_TEST_EXAMPLES } from "./utils"; describe("source map option", () => { - it('contains the source map inlined in the CSS file', async () => { + it("contains the source map inlined in the CSS file", async () => { const resultsPurge = await new PurgeCSS().purge({ content: [`${ROOT_TEST_EXAMPLES}others/remove_unused.js`], css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`], - sourceMap: true + sourceMap: true, }); - expect(resultsPurge[0].css).toContain('sourceMappingURL=data:application/json;base64'); + expect(resultsPurge[0].css).toContain( + "sourceMappingURL=data:application/json;base64" + ); }); - it('contains the source map separately when setting inline to false', async () => { + it("contains the source map separately when setting inline to false", async () => { const resultsPurge = await new PurgeCSS().purge({ content: [`${ROOT_TEST_EXAMPLES}others/remove_unused.js`], css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`], sourceMap: { - inline: false - } + inline: false, + }, }); - expect(resultsPurge[0].sourceMap).toContain('sources":["__tests__/test_examples/others/remove_unused.css"]'); - }) + expect(resultsPurge[0].sourceMap).toContain( + 'sources":["__tests__/test_examples/others/remove_unused.css"]' + ); + }); }); diff --git a/packages/purgecss/src/types/index.ts b/packages/purgecss/src/types/index.ts index 5081ee5f..ff5a9d02 100644 --- a/packages/purgecss/src/types/index.ts +++ b/packages/purgecss/src/types/index.ts @@ -83,9 +83,9 @@ export type ComplexSafelist = { /** * You can safelist selectors and their children based on a regular * expression with `safelist.deep` - * + * * @example - * + * * ```ts * const purgecss = await new PurgeCSS().purge({ * content: [], @@ -95,10 +95,10 @@ export type ComplexSafelist = { * } * }) * ``` - * - * In this example, selectors such as `.bg-red .child-of-bg` will be left + * + * In this example, selectors such as `.bg-red .child-of-bg` will be left * in the final CSS, even if `child-of-bg` is not found. - * + * */ deep?: RegExp[]; greedy?: RegExp[]; @@ -113,7 +113,7 @@ export type UserDefinedSafelist = StringRegExpArray | ComplexSafelist; /** * Options used by PurgeCSS to remove unused CSS - * + * * @public */ export interface UserDefinedOptions { @@ -136,7 +136,7 @@ export interface UserDefinedOptions { /** {@inheritDoc Options.rejectedCss} */ rejectedCss?: boolean; /** {@inheritDoc Options.sourceMap } */ - sourceMap?: boolean | postcss.SourceMapOptions & { to?: string } + sourceMap?: boolean | (postcss.SourceMapOptions & { to?: string }); /** {@inheritDoc Options.stdin} */ stdin?: boolean; /** {@inheritDoc Options.stdout} */ @@ -157,29 +157,29 @@ export interface UserDefinedOptions { * Options used by PurgeCSS to remove unused CSS * Those options are used internally * @see {@link UserDefinedOptions} for the options defined by the user - * + * * @public */ export interface Options { /** * You can specify content that should be analyzed by PurgeCSS with an * array of filenames or globs. The files can be HTML, Pug, Blade, etc. - * + * * @example - * + * * ```ts * await new PurgeCSS().purge({ * content: ['index.html', '*.js', '*.html', '*.vue'], * css: ['css/app.css'] * }) * ``` - * + * * @example * PurgeCSS also works with raw content. To do this, you need to pass an * object with the `raw` property instead of a filename. To work properly * with custom extractors you need to pass the `extension` property along * with the raw content. - * + * * ```ts * await new PurgeCSS().purge({ * content: [ @@ -211,9 +211,9 @@ export interface Options { /** * If there are any unused \@font-face rules in your css, you can remove * them by setting the `fontFace` option to `true`. - * + * * @defaultValue `false` - * + * * @example * ```ts * await new PurgeCSS().purge({ @@ -229,7 +229,7 @@ export interface Options { rejected: boolean; rejectedCss: boolean; /** {@inheritDoc postcss#SourceMapOptions} */ - sourceMap: boolean | postcss.SourceMapOptions & { to?: string } + sourceMap: boolean | (postcss.SourceMapOptions & { to?: string }); stdin: boolean; stdout: boolean; variables: boolean; diff --git a/packages/rollup-plugin-purgecss/src/index.ts b/packages/rollup-plugin-purgecss/src/index.ts index 1628013c..c009ec66 100644 --- a/packages/rollup-plugin-purgecss/src/index.ts +++ b/packages/rollup-plugin-purgecss/src/index.ts @@ -7,10 +7,10 @@ import { UserDefinedOptions } from "./types"; export * from "./types"; /** - * + * * @param options - options - * @returns - * + * @returns + * * @public */ function pluginPurgeCSS(options: UserDefinedOptions): Plugin { diff --git a/scripts/build.ts b/scripts/build.ts index feac62f1..616ade05 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -7,7 +7,7 @@ import { } from "@microsoft/api-extractor"; import typescript from "@rollup/plugin-typescript"; import { terser } from "rollup-plugin-terser"; -import path from "path/posix"; +import * as path from "path"; const rollupBaseConfig: RollupOptions = { input: "./src/index.ts", @@ -95,7 +95,7 @@ const extractorAPIBaseConfig: IExtractorConfigPrepareOptions = { }, "ae-internal-missing-underscore": { logLevel: ExtractorLogLevel.None, - } + }, }, tsdocMessageReporting: { default: { diff --git a/types/vinyl-sourcemaps-apply/index.d.ts b/types/vinyl-sourcemaps-apply/index.d.ts index f9846d69..78d5df2a 100644 --- a/types/vinyl-sourcemaps-apply/index.d.ts +++ b/types/vinyl-sourcemaps-apply/index.d.ts @@ -1 +1 @@ -declare module 'vinyl-sourcemaps-apply'; \ No newline at end of file +declare module "vinyl-sourcemaps-apply";