Skip to content

Commit

Permalink
Support passing config path via object
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Aug 2, 2019
1 parent 7877ffa commit 649fb8f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions __tests__/customConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 649fb8f

Please sign in to comment.