Skip to content

Commit

Permalink
feat: ignore file with @ignore comment at the top of the file
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvtrinidad committed May 3, 2024
1 parent 48a62ea commit a14e22b
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/prefixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const prefixer = (options) => {
return {
postcssPlugin: 'postcss-prefixer',
Once(css) {
const first = css.nodes[0];


if (first && first.type === 'comment' && first.text.trim() === '@ignore') {
return;
}
if (!prefix.length) return;

css.walkRules((rule) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-prefixer",
"version": "3.0.0",
"version": "3.1.0",
"description": "postcss plugin to prefix all css selector classes and ids",
"main": "lib/prefixer.js",
"engines": {
Expand Down
62 changes: 62 additions & 0 deletions test/fixtures/ignore-file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* @ignore */

html, body {
padding: 0;
margin: 0;
}

* {
box-sizing: border-box;
}

#page {
overflow: hidden;
}

#page .page-header {
position: fixed
}

.btn {
display: flex;
}

.btn.btn--small {
display: flex;
}

.btn span {
display: inline;
}

.btn:hover, .btn:active, .btn:focus {
background-color: #fff;
}

.wrapper > .container {
display: flex;
}

.component .component--big {
width: 100%;
}

[class="icon-"],
[class*="icon-"],
[class^="icon-"],
[class~="icon-"],
[class|="icon-"],
[class$="icon-"] {
display: inline;
}

span:not(.icon),
button:not(.btn),
div:not(.container),
div:not([class^="col-"]) {
display: none;
}

.container[data-attr="some-value"] {
display: inline;
}
12 changes: 12 additions & 0 deletions test/prefixer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const DEFAULT_SOURCE_PATH = path.resolve(__dirname, 'fixtures/source.css');
const DEFAULT_EXPECTED_PATH = path.resolve(__dirname, 'fixtures/source.expected.css');
const IGNORE_SOURCE_PATH = path.resolve(__dirname, 'fixtures/ignore.css');
const IGNORE_EXPECTED_PATH = path.resolve(__dirname, 'fixtures/ignore.expected.css');
const IGNORE_FILE_SOURCE_PATH = path.resolve(__dirname, 'fixtures/ignore-file.css');

const mocks = {
default: {
Expand All @@ -18,6 +19,9 @@ const mocks = {
source: fs.readFileSync(IGNORE_SOURCE_PATH, 'utf8').trim(),
expected: fs.readFileSync(IGNORE_EXPECTED_PATH, 'utf8').trim(),
},
ignoreFile: {
source: fs.readFileSync(IGNORE_FILE_SOURCE_PATH, 'utf8').trim(),
},
};

describe('Prefixer', () => {
Expand Down Expand Up @@ -82,4 +86,12 @@ describe('Prefixer', () => {

expect(css).toEqual(mocks.ignore.expected);
});

test('should not prefix file with @ignore comment', () => {
const { css } = postcss()
.use(postcssPrefixer())
.process(mocks.ignoreFile.source);

expect(css).toEqual(mocks.ignoreFile.source);
});
});

0 comments on commit a14e22b

Please sign in to comment.