-
-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
13,140 additions
and
12,025 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# `purgecss-from-tsx` | ||
|
||
> TODO: description | ||
## Usage | ||
|
||
``` | ||
const purgecssFromTsx = require('purgecss-from-tsx'); | ||
// TODO: DEMONSTRATE API | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
export const TEST_1_CONTENT = ` | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
type MyComponentProps = { | ||
login: any; | ||
}; | ||
type MyComponentState = { | ||
username: string; | ||
password: string; | ||
}; | ||
class MyComponent extends React.Component<MyComponentProps, MyComponentState> { | ||
static propTypes: any; | ||
render() { | ||
return ( | ||
<React.Fragment> | ||
<div className="test-container">Well</div> | ||
<div className="test-footer" id="an-id"></div> | ||
<a href="#" id="a-link" className="a-link"></a> | ||
<input id="blo" type="text" disabled/> | ||
</React.Fragment> | ||
); | ||
} | ||
} | ||
MyComponent.propTypes = { | ||
login: PropTypes.func.isRequired | ||
}; | ||
export default MyComponent; | ||
`; | ||
|
||
export const TEST_1_TAG = ["div", "a", "input"]; | ||
|
||
export const TEST_1_CLASS = ["test-container", "test-footer", "a-link"]; | ||
|
||
export const TEST_1_ID = ["a-link", "blo"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import purgeTsx from "../src/index"; | ||
|
||
import { TEST_1_CONTENT, TEST_1_TAG, TEST_1_CLASS, TEST_1_ID } from "./data"; | ||
|
||
const plugin = purgeTsx(); | ||
|
||
describe("purgeTsx", () => { | ||
describe("from a normal html document", () => { | ||
it("finds tag selectors", () => { | ||
const received = plugin(TEST_1_CONTENT); | ||
for (const item of TEST_1_TAG) { | ||
expect(received.includes(item)).toBe(true); | ||
} | ||
}); | ||
|
||
it("finds classes selectors", () => { | ||
const received = plugin(TEST_1_CONTENT); | ||
for (const item of TEST_1_CLASS) { | ||
expect(received.includes(item)).toBe(true); | ||
} | ||
}); | ||
|
||
it("finds id selectors", () => { | ||
const received = plugin(TEST_1_CONTENT); | ||
for (const item of TEST_1_ID) { | ||
expect(received.includes(item)).toBe(true); | ||
} | ||
}); | ||
|
||
it("finds all selectors", () => { | ||
const received = plugin(TEST_1_CONTENT); | ||
const selectors = [...TEST_1_TAG, ...TEST_1_CLASS, ...TEST_1_ID]; | ||
for (const item of selectors) { | ||
expect(received.includes(item)).toBe(true); | ||
} | ||
}); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "purgecss-from-tsx", | ||
"version": "4.0.3", | ||
"description": "TSX extractor for PurgeCSS", | ||
"author": "Ffloriel", | ||
"homepage": "https://github.com/FullHuman/purgecss#readme", | ||
"license": "ISC", | ||
"main": "./lib/purgecss-from-tsx.js", | ||
"module": "./lib/purgecss-from-tsx.esm.js", | ||
"types": "./lib/purgecss-from-tsx.d.ts", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "__tests__" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/FullHuman/purgecss.git" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/FullHuman/purgecss/issues" | ||
}, | ||
"dependencies": { | ||
"acorn": "^7.4.0", | ||
"purgecss-from-jsx": "^4.0.3", | ||
"typescript": "^4.3.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import acorn from "acorn"; | ||
import * as ts from "typescript"; | ||
import purgeFromJsx from "purgecss-from-jsx"; | ||
|
||
function purgeFromTsx(options?: { | ||
acornOptions?: acorn.Options, | ||
tsOptions?: ts.CompilerOptions | ||
}): (content: string) => string[] { | ||
return (content: string): string[] => { | ||
return purgeFromJsx(options?.acornOptions)( | ||
ts.transpileModule(content, { | ||
compilerOptions: { | ||
jsx: ts.JsxEmit.Preserve, | ||
...options?.tsOptions | ||
} | ||
}).outputText | ||
); | ||
}; | ||
} | ||
|
||
export default purgeFromTsx; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters