From 649fb8f21eaa21e548cf05c7edccd2988bf169f8 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Fri, 2 Aug 2019 08:07:42 -0400 Subject: [PATCH] Support passing config path via object --- __tests__/customConfig.test.js | 27 +++++++++++++++++++++++++++ src/index.js | 6 +++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/__tests__/customConfig.test.js b/__tests__/customConfig.test.js index 0d9cd1581..27ea05487 100644 --- a/__tests__/customConfig.test.js +++ b/__tests__/customConfig.test.js @@ -68,6 +68,33 @@ test('custom config can be passed as an object', () => { }) }) +test('custom config path can be passed using `config` property in an object', () => { + return postcss([tailwind({ config: path.resolve(`${__dirname}/fixtures/custom-config.js`) })]) + .process( + ` + @responsive { + .foo { + color: blue; + } + } + `, + { from: undefined } + ) + .then(result => { + const expected = ` + .foo { + color: blue; + } + @media (min-width: 400px) { + .mobile\\:foo { + color: blue; + } + } + ` + expect(result.css).toMatchCss(expected) + }) +}) + test('tailwind.config.js is picked up by default', () => { return inTempDirectory(() => { fs.writeFileSync( diff --git a/src/index.js b/src/index.js index 4c37432fb..d80ab8c2b 100644 --- a/src/index.js +++ b/src/index.js @@ -13,10 +13,14 @@ import { defaultConfigFile } from './constants' import defaultConfig from '../stubs/defaultConfig.stub.js' function resolveConfigPath(filePath) { - if (_.isObject(filePath)) { + if (_.isObject(filePath) && !_.has(filePath, 'config')) { return undefined } + if (_.isObject(filePath) && _.has(filePath, 'config')) { + return path.resolve(filePath.config) + } + if (!_.isUndefined(filePath)) { return path.resolve(filePath) }