Skip to content

Commit

Permalink
add new extractor format
Browse files Browse the repository at this point in the history
- add new extractor format for better accuracy
- add attributes purge
  • Loading branch information
Ffloriel committed Oct 27, 2019
1 parent f9d8667 commit d7f719d
Show file tree
Hide file tree
Showing 30 changed files with 715 additions and 274 deletions.
21 changes: 21 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": [
"--runInBand"
],
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
]
}
2 changes: 1 addition & 1 deletion lerna.json
Expand Up @@ -2,5 +2,5 @@
"packages": [
"packages/*"
],
"version": "2.0.1-alpha.0"
"version": "2.0.0"
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"@types/node": "^12.7.11",
"@wessberg/rollup-plugin-ts": "^1.1.65",
"jest": "^24.9.0",
"lerna": "^3.14.1",
"lerna": "^3.18.0",
"lint-staged": "^9.4.2",
"prettier": "^1.18.2",
"rollup": "^1.23.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-purgecss/__tests__/index.test.ts
@@ -1,7 +1,7 @@
const fs = require("fs");
const postcss = require("postcss");

import purgeCSSPlugin from "./../src/";
import purgeCSSPlugin from "../src";

describe("Purgecss postcss plugin", () => {
const files = ["simple", "font-keyframes"];
Expand Down
57 changes: 37 additions & 20 deletions packages/postcss-purgecss/lib/postcss-purgecss.d.ts
@@ -1,31 +1,48 @@
import postcss from "postcss";
interface RawContent {
extension: string;
raw: string;
extension: string;
raw: string;
}
interface RawCSS {
raw: string;
raw: string;
}
declare type ExtractorFunction = (content: string) => string[];
interface Extractors {
extensions: string[];
extractor: ExtractorFunction;
extensions: string[];
extractor: ExtractorFunction;
}
interface UserDefinedOptions {
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
whitelist?: string[];
whitelistPatterns?: Array<RegExp>;
whitelistPatternsChildren?: Array<RegExp>;
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
whitelist?: string[];
whitelistPatterns?: Array<RegExp>;
whitelistPatternsChildren?: Array<RegExp>;
}
declare const purgeCSSPlugin: postcss.Plugin<Pick<UserDefinedOptions, "content" | "defaultExtractor" | "extractors" | "fontFace" | "keyframes" | "output" | "rejected" | "stdin" | "stdout" | "variables" | "whitelist" | "whitelistPatterns" | "whitelistPatternsChildren">>;
declare const purgeCSSPlugin: postcss.Plugin<
Pick<
UserDefinedOptions,
| "content"
| "defaultExtractor"
| "extractors"
| "fontFace"
| "keyframes"
| "output"
| "rejected"
| "stdin"
| "stdout"
| "variables"
| "whitelist"
| "whitelistPatterns"
| "whitelistPatternsChildren"
>
>;
export default purgeCSSPlugin;
57 changes: 37 additions & 20 deletions packages/postcss-purgecss/lib/postcss-purgecss.esm.d.ts
@@ -1,31 +1,48 @@
import postcss from "postcss";
interface RawContent {
extension: string;
raw: string;
extension: string;
raw: string;
}
interface RawCSS {
raw: string;
raw: string;
}
declare type ExtractorFunction = (content: string) => string[];
interface Extractors {
extensions: string[];
extractor: ExtractorFunction;
extensions: string[];
extractor: ExtractorFunction;
}
interface UserDefinedOptions {
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
whitelist?: string[];
whitelistPatterns?: Array<RegExp>;
whitelistPatternsChildren?: Array<RegExp>;
content: Array<string | RawContent>;
css: Array<string | RawCSS>;
defaultExtractor?: ExtractorFunction;
extractors?: Array<Extractors>;
fontFace?: boolean;
keyframes?: boolean;
output?: string;
rejected?: boolean;
stdin?: boolean;
stdout?: boolean;
variables?: boolean;
whitelist?: string[];
whitelistPatterns?: Array<RegExp>;
whitelistPatternsChildren?: Array<RegExp>;
}
declare const purgeCSSPlugin: postcss.Plugin<Pick<UserDefinedOptions, "content" | "defaultExtractor" | "extractors" | "fontFace" | "keyframes" | "output" | "rejected" | "stdin" | "stdout" | "variables" | "whitelist" | "whitelistPatterns" | "whitelistPatternsChildren">>;
declare const purgeCSSPlugin: postcss.Plugin<
Pick<
UserDefinedOptions,
| "content"
| "defaultExtractor"
| "extractors"
| "fontFace"
| "keyframes"
| "output"
| "rejected"
| "stdin"
| "stdout"
| "variables"
| "whitelist"
| "whitelistPatterns"
| "whitelistPatternsChildren"
>
>;
export default purgeCSSPlugin;
7 changes: 2 additions & 5 deletions packages/postcss-purgecss/package.json
@@ -1,6 +1,6 @@
{
"name": "postcss-purgecss",
"version": "2.0.1-alpha.0",
"version": "2.0.0",
"description": "> TODO: description",
"author": "Ffloriel <florielfedry@gmail.com>",
"homepage": "https://github.com/FullHuman/purgecss#readme",
Expand All @@ -27,9 +27,6 @@
},
"dependencies": {
"postcss": "^7.0.18",
"purgecss": "^2.0.1-alpha.0"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
"purgecss": "file:../purgecss"
}
}
5 changes: 1 addition & 4 deletions packages/postcss-purgecss/src/index.ts
Expand Up @@ -10,10 +10,7 @@ import {
selectorsRemoved
} from "purgecss";

import {
RawContent,
UserDefinedOptions
} from './types'
import { RawContent, UserDefinedOptions } from "./types";

type PurgeCSSPostCSSOptions = Omit<UserDefinedOptions, "css">;

Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-purgecss/src/types/index.ts
Expand Up @@ -25,4 +25,4 @@ export interface UserDefinedOptions {
whitelist?: string[];
whitelistPatterns?: Array<RegExp>;
whitelistPatternsChildren?: Array<RegExp>;
}
}
36 changes: 36 additions & 0 deletions packages/purgecss-from-blade/__tests__/data.ts
@@ -0,0 +1,36 @@
export const TEST_1_CONTENT = `
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="test-container">
@yield('content')
</div>
@if (count($records) === 1)
<a href="#" id="a-link" class="a-link"></a>
@else
<input id="blo" type="text" disabled/>
@endif
<div class="test-footer"></div>
</body>
</html>
`;

export const TEST_1_TAG = [
"html",
"head",
"title",
"body",
"div",
"a",
"input"
];

export const TEST_1_CLASS = ["test-container", "test-footer", "a-link"];

export const TEST_1_ID = ["a-link", "blo"];
36 changes: 36 additions & 0 deletions packages/purgecss-from-blade/__tests__/index.testu.ts
@@ -0,0 +1,36 @@
import purgeBlade from "../src/index";

import { TEST_1_CONTENT, TEST_1_TAG, TEST_1_CLASS, TEST_1_ID } from "./data";

describe("purge-from-blade", () => {
describe("from a normal blade document", () => {
it("finds tag selectors", () => {
const received = purgeBlade(TEST_1_CONTENT);
for (let item of TEST_1_TAG) {
expect(received.includes(item)).toBe(true);
}
});

it("finds classes selectors", () => {
const received = purgeBlade(TEST_1_CONTENT);
for (let item of TEST_1_CLASS) {
expect(received.includes(item)).toBe(true);
}
});

it("finds id selectors", () => {
const received = purgeBlade(TEST_1_CONTENT);
for (let item of TEST_1_ID) {
expect(received.includes(item)).toBe(true);
}
});

it("finds all selectors", () => {
const received = purgeBlade(TEST_1_CONTENT);
const selectors = [...TEST_1_TAG, ...TEST_1_CLASS, ...TEST_1_ID];
for (let item of selectors) {
expect(received.includes(item)).toBe(true);
}
});
});
});

This file was deleted.

7 changes: 0 additions & 7 deletions packages/purgecss-from-blade/lib/purgecss-from-blade.js

This file was deleted.

5 changes: 4 additions & 1 deletion packages/purgecss-from-blade/package.json
@@ -1,6 +1,6 @@
{
"name": "purgecss-from-blade",
"version": "2.0.1-alpha.0",
"version": "2.0.0",
"description": "> TODO: description",
"author": "Ffloriel <florielfedry@gmail.com>",
"homepage": "https://github.com/FullHuman/purgecss#readme",
Expand All @@ -22,5 +22,8 @@
},
"bugs": {
"url": "https://github.com/FullHuman/purgecss/issues"
},
"dependencies": {
"@tarik02/bladejs-compiler": "^2.1.0"
}
}
1 change: 1 addition & 0 deletions packages/purgecss-from-blade/src/index.ts
@@ -0,0 +1 @@
import { Compiler, Source } from "@tarik02/bladejs-compiler";
2 changes: 1 addition & 1 deletion packages/purgecss-from-html/package.json
@@ -1,6 +1,6 @@
{
"name": "purgecss-from-html",
"version": "2.0.1-alpha.0",
"version": "2.0.0",
"description": "> TODO: description",
"author": "Ffloriel <florielfedry@gmail.com>",
"homepage": "https://github.com/FullHuman/purgecss#readme",
Expand Down
1 change: 1 addition & 0 deletions packages/purgecss-from-html/src/index.ts
Expand Up @@ -31,6 +31,7 @@ const getSelectorsInNodes = (
break;
case "root":
selectors.push(...getSelectorsInNodes(element));
break;
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/purgecss-from-pug/package.json
@@ -1,6 +1,6 @@
{
"name": "purgecss-from-pug",
"version": "2.0.1-alpha.0",
"version": "2.0.0",
"description": "> TODO: description",
"author": "Ffloriel <florielfedry@gmail.com>",
"homepage": "https://github.com/FullHuman/purgecss#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/purgecss-from-twig/package.json
@@ -1,6 +1,6 @@
{
"name": "purgecss-from-twig",
"version": "2.0.1-alpha.0",
"version": "2.0.0",
"description": "> TODO: description",
"author": "Ffloriel <florielfedry@gmail.com>",
"homepage": "https://github.com/FullHuman/purgecss#readme",
Expand Down

0 comments on commit d7f719d

Please sign in to comment.