Skip to content

Commit

Permalink
fix: wrong path import
Browse files Browse the repository at this point in the history
- fix wrong path import (was importing path/posix instead of path
- add vinyl-sourcempas-apply to external (rollup config)
- run prettier
  • Loading branch information
Ffloriel committed Feb 23, 2022
1 parent 55c26d2 commit 4f3ddd0
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 56 deletions.
1 change: 1 addition & 0 deletions packages/gulp-purgecss/build.ts
Expand Up @@ -16,6 +16,7 @@ import * as path from "path";
"plugin-error",
"purgecss",
"glob",
"vinyl-sourcemaps-apply",
]);
await buildRollup(rollupConfig);
await extractAPI(__dirname);
Expand Down
4 changes: 2 additions & 2 deletions packages/gulp-purgecss/src/index.ts
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/postcss-purgecss/src/index.ts
Expand Up @@ -73,10 +73,10 @@ async function purgeCSS(
}

/**
*
*
* @param opts - opts
* @returns
*
* @returns
*
* @public
*/
const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions> = function (
Expand Down
10 changes: 5 additions & 5 deletions 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<PurgeCSSUserDefinedOptions,"content" | "css"> {
content?: PurgeCSSUserDefinedOptions['content'];
export interface UserDefinedOptions
extends Omit<PurgeCSSUserDefinedOptions, "content" | "css"> {
content?: PurgeCSSUserDefinedOptions["content"];
contentFunction?: (sourceFile: string) => Array<string | RawContent>;
}
4 changes: 2 additions & 2 deletions packages/purgecss-from-html/src/index.ts
Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions packages/purgecss-from-jsx/src/index.ts
Expand Up @@ -18,10 +18,10 @@ extend<NodeState>(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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/purgecss-from-pug/src/index.ts
Expand Up @@ -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[] => {
Expand Down
4 changes: 2 additions & 2 deletions packages/purgecss-from-tsx/src/index.ts
Expand Up @@ -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?: {
Expand Down
16 changes: 9 additions & 7 deletions 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[];
/**
Expand All @@ -28,11 +27,14 @@ export type PurgedStats = {
/**
* @public
*/
export type UserDefinedOptions = Omit<PurgeCSSUserDefinedOptions, "css" | "content" | "safelist" | "blocklist" | "sourceMap"> & {
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[];
}
};
24 changes: 14 additions & 10 deletions 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"]'
);
});
});
30 changes: 15 additions & 15 deletions packages/purgecss/src/types/index.ts
Expand Up @@ -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: [],
Expand All @@ -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[];
Expand All @@ -113,7 +113,7 @@ export type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;

/**
* Options used by PurgeCSS to remove unused CSS
*
*
* @public
*/
export interface UserDefinedOptions {
Expand All @@ -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} */
Expand All @@ -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: [
Expand Down Expand Up @@ -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({
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions packages/rollup-plugin-purgecss/src/index.ts
Expand Up @@ -7,10 +7,10 @@ import { UserDefinedOptions } from "./types";
export * from "./types";

/**
*
*
* @param options - options
* @returns
*
* @returns
*
* @public
*/
function pluginPurgeCSS(options: UserDefinedOptions): Plugin {
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.ts
Expand Up @@ -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",
Expand Down Expand Up @@ -95,7 +95,7 @@ const extractorAPIBaseConfig: IExtractorConfigPrepareOptions = {
},
"ae-internal-missing-underscore": {
logLevel: ExtractorLogLevel.None,
}
},
},
tsdocMessageReporting: {
default: {
Expand Down
2 changes: 1 addition & 1 deletion types/vinyl-sourcemaps-apply/index.d.ts
@@ -1 +1 @@
declare module 'vinyl-sourcemaps-apply';
declare module "vinyl-sourcemaps-apply";

0 comments on commit 4f3ddd0

Please sign in to comment.