Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support postcss process options #551

Merged
merged 4 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"rollup": "^1.1.2",
"rollup-plugin-svelte": "^5.0.1",
"shelljs": "^0.8.3",
"sugarss": "^2.0.0",
"svelte": "^2.16.0",
"watchify": "3.11.0",
"webpack": "^4.29.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ new Processor({
});
```

### `postcss`

Specify an object that contains any of the [PostCSS `.process()` Options](http://api.postcss.org/global.html#processOptions). Note that `from` and `to` will usally **be overwritten** to match the files being processed. This feature allows for the use of custom `parser`, `stringifier`, and `syntax` settings.

### `resolvers`

If you want to provide your own file resolution logic you can pass an array of resolver functions. Each resolver function receives three arguments:
Expand Down
3 changes: 3 additions & 0 deletions packages/processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@
"resolve-from": "^4.0.0",
"true-case-path": "^1.0.2",
"unique-slug": "^2.0.0"
},
"peerDependencies": {
"postcss": "^7.0.0"
}
}
2 changes: 2 additions & 0 deletions packages/processor/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const noop = () => true;
const params = ({ _options, _files, _graph, _resolve }, args) => Object.assign(
Object.create(null),
_options,
_options.postcss,
{
from : null,
files : _files,
Expand All @@ -40,6 +41,7 @@ class Processor {
rewrite : true,
verbose : false,
resolvers : [],
postcss : {},
},
opts
);
Expand Down
7 changes: 7 additions & 0 deletions packages/processor/test/__snapshots__/options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ Object {
}
`;

exports[`/processor.js options postcss options should support custom parsers 1`] = `
"/* packages/processor/test/specimens/parser.css */
.mce1d18d5d_a {
color: blue
}"
`;

exports[`/processor.js options rewrite should not rewrite url() references when falsey 1`] = `
"/* packages/processor/test/specimens/rewrite.css */
.mc20ca2799_a {
Expand Down
14 changes: 7 additions & 7 deletions packages/processor/test/__snapshots__/unicode.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ exports[`/processor.js unicode should support unicode classes & ids 1`] = `
#\\\\31 a2b3c { background: lime; }
#\\\\<p\\\\> { background: lime; }
#\\\\<\\\\>\\\\<\\\\<\\\\<\\\\>\\\\>\\\\<\\\\> { background: lime; }
#\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\[\\\\>\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\>\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\>\\\\+\\\\+\\\\+\\\\>\\\\+\\\\<\\\\<\\\\<\\\\<\\\\-\\\\]\\\\>\\\\+\\\\+\\\\.\\\\>\\\\+\\\\\\\\.\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\\\\\.\\\\\\\\.\\\\+\\\\+\\\\+\\\\\\\\.\\\\>\\\\+\\\\+\\\\\\\\.\\\\<\\\\<\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\\\\\.\\\\>\\\\\\\\.\\\\+\\\\+\\\\+\\\\\\\\.\\\\------\\\\\\\\.\\\\--------\\\\\\\\.\\\\>\\\\+\\\\\\\\.\\\\>\\\\\\\\. { background: lime; }
#\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\[\\\\>\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\>\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\>\\\\+\\\\+\\\\+\\\\>\\\\+\\\\<\\\\<\\\\<\\\\<\\\\-\\\\]\\\\>\\\\+\\\\+\\\\.\\\\>\\\\+\\\\.\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\.\\\\.\\\\+\\\\+\\\\+\\\\.\\\\>\\\\+\\\\+\\\\.\\\\<\\\\<\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\+\\\\.\\\\>\\\\.\\\\+\\\\+\\\\+\\\\.\\\\-\\\\-\\\\-\\\\-\\\\-\\\\-\\\\.\\\\-\\\\-\\\\-\\\\-\\\\-\\\\-\\\\-\\\\-\\\\.\\\\>\\\\+\\\\.\\\\>\\\\. { background: lime; }
#\\\\# { background: lime; }
#\\\\#\\\\# { background: lime; }
#\\\\#\\\\.\\\\\\\\#\\\\.\\\\\\\\# { background: lime; }
#\\\\#\\\\.\\\\#\\\\.\\\\# { background: lime; }
#\\\\_ { background: lime; }
#\\\\{\\\\} { background: lime; }
#\\\\.fake-class { background: lime; }
#\\\\.fake\\\\-class { background: lime; }
#foo\\\\.bar { background: lime; }
#\\\\3A hover { background: lime; }
#\\\\3A hover\\\\3A focus\\\\3A active { background: lime; }
Expand All @@ -46,21 +46,21 @@ exports[`/processor.js unicode should support unicode classes & ids 1`] = `
.\\\\1F4A9 { background: lime; }
.\\\\? { background: lime; }
.\\\\@ { background: lime; }
.\\\\\\\\. { background: lime; }
.\\\\. { background: lime; }
.\\\\3A\\\\) { background: lime; }
.\\\\3A\\\\\`\\\\( { background: lime; }
.\\\\31 23 { background: lime; }
.\\\\31 a2b3c {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\+\\\\+\\\\+\\\\+\\\\+\\\\.\\\\>\\\\.\\\\+\\\\+\\\\+\\\\.------\\\\.--------\\\\.\\\\>\\\\+\\\\.\\\\>\\\\. { background: lime; }
.\\\\\\\\# { background: lime; }
.\\\\\\\\#\\\\# { background: lime; }
.\\\\\\\\#\\\\.\\\\\\\\#\\\\.\\\\\\\\# { background: lime; }
.\\\\\\\\#\\\\.\\\\#\\\\.\\\\# { background: lime; }
.\\\\_ { background: lime; }
.\\\\{\\\\} { background: lime; }
.\\\\\\\\#fake\\\\-id { background: lime; }
.foo\\\\\\\\.bar { background: lime; }
.foo\\\\.bar { background: lime; }
.\\\\3Ahover { background: lime; }
.\\\\3Ahover\\\\3A focus\\\\3A active { background: lime; }
.\\\\[attr\\\\=value\\\\] { background: lime; }
Expand Down
27 changes: 27 additions & 0 deletions packages/processor/test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,33 @@ describe("/processor.js", () => {
});
});

describe("postcss options", () => {
it("should support custom parsers", async () => {
const parser = require("sugarss");

const processor = new Processor({
postcss : {
parser,
}
});

await processor.string(
"packages/processor/test/specimens/parser.css",
dedent(`
.a
color: blue
`)
);

const { css } = await processor.output({
from : "packages/processor/test/specimens/parser.css",
to : "./packages/processor/test/output/parser.css",
});

expect(css).toMatchSnapshot();
});
});

describe("lifecycle options", () => {
describe("before", () => {
it("should run sync postcss plugins before processing", async () => {
Expand Down