'use-strict';

const path = require('path');
const postcss = require('postcss');
const cssImport = require('postcss-import');
const url = require('postcss-url');
const atVariables = require('postcss-at-rules-variables');
const each = require('postcss-each');
const mixins = require('postcss-mixins');
const nested = require('postcss-nested');
const customProperties = require('postcss-custom-properties');
const conditionals = require('postcss-conditionals');
const customMedia = require('postcss-custom-media');
const calc = require('postcss-calc');
const colorFunction = require('postcss-color-function');
const mediaQueryPacker = require('css-mqpacker');
const autoprefixer = require('autoprefixer');

const mixinsPath = path.join(
  path.dirname(require.resolve('@wearegenki/css')),
  'src/mixins',
);

module.exports = postcss.plugin('ui-postcss', (opts = {}) => {
  const mixinsDir = opts.mixinsDir ? [opts.mixinsDir] : [];
  mixinsDir.push(mixinsPath);

  return postcss()
    .use(cssImport({ path: opts.importPath || ['src'] }))
    .use(atVariables)
    .use(atVariables) // listed twice as a workaround to bug: https://github.com/GitScrum/postcss-at-rules-variables/issues/181
    .use(each)
    .use(mixins({ mixinsDir }))
    .use(nested)
    .use(customProperties)
    .use(conditionals)
    .use(customMedia)
    .use(calc({ warnWhenCannotResolve: opts.verbose }))
    .use(colorFunction)
    .use(mediaQueryPacker)
    .use(autoprefixer({ remove: false, flexbox: 'no-2009' }))
    .use(url);
});

'use-strict';

const path = require('path');
const postcss = require('postcss');
const cssImport = require('postcss-import');
const url = require('postcss-url');
const atVariables = require('postcss-at-rules-variables');
const each = require('postcss-each');
const mixins = require('postcss-mixins');
const nested = require('postcss-nested');
const customProperties = require('postcss-custom-properties');
const conditionals = require('postcss-conditionals');
const customMedia = require('postcss-custom-media');
const calc = require('postcss-calc');
const colorFunction = require('postcss-color-function');
const mediaQueryPacker = require('css-mqpacker');
const autoprefixer = require('autoprefixer');

const mixinsPath = path.join(
  path.dirname(require.resolve('@wearegenki/css')),
  'src/mixins',
);

module.exports = postcss.plugin('ui-postcss', (opts = {}) => {
  const mixinsDir = opts.mixinsDir ? [opts.mixinsDir] : [];
  mixinsDir.push(mixinsPath);

  return postcss()
    .use(cssImport({ path: opts.importPath || ['src'] }))
    .use(atVariables)
    .use(each)
    .use(mixins({ mixinsDir }))
    .use(nested)
    .use(customProperties)
    .use(conditionals)
    .use(customMedia)
    .use(calc({ warnWhenCannotResolve: opts.verbose }))
    .use(colorFunction)
    .use(mediaQueryPacker)
    .use(autoprefixer({ remove: false, flexbox: 'no-2009' }))
    .use(url);
});

Remove unnecessary postcss workaround