Skip to content

Commit

Permalink
feat: expose export tokens to other plugins (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and madyankin committed Sep 28, 2018
1 parent 16fc4ac commit cb9c31e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Expand Up @@ -76,6 +76,12 @@ module.exports = postcss.plugin(PLUGIN_NAME, (opts = {}) => {
});
}

result.messages.push({
type: "export",
plugin: "postcss-modules",
exportTokens: parser.exportTokens
});

// getJSON may return a promise
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
};
Expand Down
32 changes: 32 additions & 0 deletions test/test.js
Expand Up @@ -166,3 +166,35 @@ test("getJSON with outputFileName", async t => {
t.deepEqual(jsonFileName, `${expectedFile}.json`);
t.deepEqual(resultJson, JSON.parse(expectedJSON));
});

test("expose export tokens for other plugins", async t => {
const sourceFile = path.join(fixturesPath, "in", "values.css");
const expectedFile = path.join(fixturesPath, "out", "test", "values.css");
const source = fs.readFileSync(sourceFile).toString();

const plugins = [
plugin({
generateScopedName,
getJSON: () => {}
})
];

const result = await postcss(plugins).process(source, {
from: sourceFile,
to: `${expectedFile}.css`
});

t.deepEqual(result.messages, [
{
type: "export",
plugin: "postcss-modules",
exportTokens: {
article: "_values_article",
colors: '"./values.colors.css"',
primary: "green",
secondary: "blue",
title: "_values_title"
}
}
]);
});

0 comments on commit cb9c31e

Please sign in to comment.