Skip to content
Permalink
Browse files
feat: add option to use output filepath for json (#460)
Adds an option to postcss-modular-css to automatically use the same
output file path and file name for JSON with the configuration
`{ json: true }`. See #459.
  • Loading branch information
morewry authored and tivac committed Jul 25, 2018
1 parent 290a2f7 commit 037f93346c9c9eb5290bc1c4c6aec066b4ee4965
Showing with 39 additions and 1 deletion.
  1. +7 −1 packages/postcss/postcss.js
  2. +23 −0 packages/postcss/test/__snapshots__/postcss.test.js.snap
  3. +9 −0 packages/postcss/test/postcss.test.js
@@ -25,13 +25,19 @@ module.exports = postcss.plugin("modular-css", (opts) =>
})
.then((output) => {
var { json } = processor.options;

result.messages.push({
type : "modular-css-exports",
exports : classes,
});

if(json) {
if(typeof json !== "string") {
const { opts: { to } } = result;

json = `${path.join(path.dirname(to), path.basename(to, path.extname(to)))}.json`;
}

mkdirp.sync(path.dirname(json));

fs.writeFileSync(

Some generated files are not rendered by default. Learn more.

@@ -54,6 +54,15 @@ describe("/postcss.js", () => {
)
.then(() => expect(read("classes.json")).toMatchSnapshot()));

it("should use output filepath for json if a custom path isn't provided", () => process(
"./packages/postcss/test/specimens/start.css",
{
json : true,
to : "./packages/postcss/test/output/start.css",
}
)
.then(() => expect(read("start.json")).toMatchSnapshot()));

it("should be usable like a normal postcss plugin", () => {
var processor = postcss([
plugin({

0 comments on commit 037f933

Please sign in to comment.