Skip to content

Commit

Permalink
Support passing empty object to signal 'use default config path'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Aug 2, 2019
1 parent 649fb8f commit 5cad391
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
39 changes: 39 additions & 0 deletions __tests__/customConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,42 @@ test('tailwind.config.js is picked up by default', () => {
})
})
})

test('tailwind.config.js is picked up by default when passing an empty object', () => {
return inTempDirectory(() => {
fs.writeFileSync(
path.resolve(defaultConfigFile),
`module.exports = {
theme: {
screens: {
mobile: '400px',
},
},
}`
)

return postcss([tailwind({})])
.process(
`
@responsive {
.foo {
color: blue;
}
}
`,
{ from: undefined }
)
.then(result => {
expect(result.css).toMatchCss(`
.foo {
color: blue;
}
@media (min-width: 400px) {
.mobile\\:foo {
color: blue;
}
}
`)
})
})
})
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { defaultConfigFile } from './constants'
import defaultConfig from '../stubs/defaultConfig.stub.js'

function resolveConfigPath(filePath) {
if (_.isObject(filePath) && !_.has(filePath, 'config')) {
if (_.isObject(filePath) && !_.has(filePath, 'config') && !_.isEmpty(filePath)) {
return undefined
}

if (_.isObject(filePath) && _.has(filePath, 'config')) {
return path.resolve(filePath.config)
}

if (!_.isUndefined(filePath)) {
if (_.isString(filePath)) {
return path.resolve(filePath)
}

Expand Down

0 comments on commit 5cad391

Please sign in to comment.