Skip to content

Commit

Permalink
feat: option to suppress value export (#673)
Browse files Browse the repository at this point in the history
Fixes #672
  • Loading branch information
lunsdorf authored and tivac committed Sep 23, 2019
1 parent ac8ea56 commit 97a5b1e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
12 changes: 12 additions & 0 deletions packages/processor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ new Processor({
*/
```

### `exportValues`

Enable exporting `@value` identifiers.

**Default**: `true`

```js
new Processor({
exportValues : false
});
```

## Properties

### `.files`
Expand Down
22 changes: 13 additions & 9 deletions packages/processor/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class Processor {
const options = Object.assign(
Object.create(null),
{
cwd : process.cwd(),
map : false,
rewrite : true,
verbose : false,
resolvers : [],
postcss : {},
dupewarn : true,
cwd : process.cwd(),
dupewarn : true,
exportValues : true,
map : false,
postcss : {},
resolvers : [],
rewrite : true,
verbose : false,
},
opts
);
Expand Down Expand Up @@ -379,8 +380,11 @@ class Processor {

file.exports = Object.assign(
Object.create(null),
// export @value entries
mapValues(file.values, ({ value }) => value),

// optionally export @value entries
this._options.exportValues ?
mapValues(file.values, ({ value }) => value) :
null,

// export classes
message(result, "classes"),
Expand Down
17 changes: 17 additions & 0 deletions packages/processor/test/__snapshots__/options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ Object {
}
`;

exports[`/processor.js options exportValues should not export @values by default 1`] = `
Object {
"a": "#F00",
"b": Array [
"mc61ce7a4a_b",
],
}
`;

exports[`/processor.js options exportValues should not export @values when exportValues is false 1`] = `
Object {
"b": Array [
"mc8df92ddf_b",
],
}
`;

exports[`/processor.js options lifecycle options after should run async postcss plugins 1`] = `
"/* packages/processor/test/specimens/relative.css */
.wooga {
Expand Down
32 changes: 32 additions & 0 deletions packages/processor/test/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,38 @@ describe("/processor.js", () => {
});
});

describe("exportValues", () => {
it("should export @values by default", async () => {
const processor = new Processor({});

const { exports } = await processor.string(
"./exportValues.css",
dedent(`
@value a: #F00;
.b {}
`)
);

expect(exports).toMatchSnapshot();
});

it("should not export @values when exportValues is false", async () => {
const processor = new Processor({
exportValues : false,
});

const { exports } = await processor.string(
"./exportGlobals.css",
dedent(`
@value a: #F00;
.b {}
`)
);

expect(exports).toMatchSnapshot();
});
});

describe("rewrite", () => {
it("should rewrite url() references by default", async () => {
const processor = new Processor();
Expand Down

0 comments on commit 97a5b1e

Please sign in to comment.