Skip to content

Commit

Permalink
added css exports
Browse files Browse the repository at this point in the history
  • Loading branch information
mightyaleksey committed Mar 5, 2017
1 parent c2c46a4 commit c394131
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ into:

## Options

`explicitExports` `boolean`

`resolve` `object`

`resolve.alias` `object`
Expand Down
17 changes: 16 additions & 1 deletion sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ module.exports = plugin('postcss-modules-resolve-imports', resolveImportsPlugin)

/**
* dangerouslyPrevailCyclicDepsWarnings
* explicitExports
* resolve.alias
* resolve.extensions
* resolve.modules
*/
function resolveImportsPlugin({resolve = {}} = {}) {
function resolveImportsPlugin({explicitExports, resolve = {}} = {}) {
return resolveImports;

function resolveImports(ast, result) {
Expand All @@ -32,6 +34,19 @@ function resolveImportsPlugin({resolve = {}} = {}) {

resolveDeps(ast, {opts: {from: rootPath, graph, resolve, rootPath, rootTree}, processor});

if (explicitExports) {
const exportRule = postcss.rule({selector: ':export'});

for (const className in ast.exports)
exportRule.append({
prop: className,
value: ast.exports[className],
raws: {before: '\n '},
});

rootTree.prepend(exportRule);
}

rootTree.exports = ast.exports;
result.root = rootTree;
}
Expand Down
10 changes: 10 additions & 0 deletions test/case/opts-explicit-exports/expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:export {
continueButton: _source_continueButton;
userInput: _source_userInput
}
._source_continueButton {
color: green
}
._source_userInput {
/**/
}
9 changes: 9 additions & 0 deletions test/case/opts-explicit-exports/source.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.continueButton
{
color: green;
}

.userInput
{
/**/
}
21 changes: 21 additions & 0 deletions test/case/opts-explicit-exports/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const resolveImports = require('../../../index');
const setup = require('../../setup');
const test = require('tape');

test('resolve-readme-example', t => {
const {expected, resulting, exports: tokens} = setup(
'local-by-default',
'extract-imports',
'scope',
resolveImports({explicitExports: true})
)(__dirname);

t.equal(resulting.trim(), expected.trim());
t.deepEqual(tokens, {
continueButton: '_source_continueButton',
userInput: '_source_userInput',
});
t.end();
});

0 comments on commit c394131

Please sign in to comment.