Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tailwind config files in ESM/TS format + Update prettier #794

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,11 @@
"eslint-plugin-unicorn": "^44.0.2",
"glob-all": "^3.3.0",
"husky": "4.3.8",
"import-fresh": "^3.3.0",
"jest": "^29.2.2",
"lint-staged": "^13.0.3",
"microbundle": "^0.15.1",
"nodemon": "^2.0.20",
"prettier": "^2.7.1",
"prettier": "^2.8.7",
"react": "^18.2.0",
"string-similarity": "^4.0.4",
"styled-components": "^5.3.6",
Expand Down
4 changes: 2 additions & 2 deletions src/core/lib/configHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { resolve, dirname } from 'path'
import { existsSync } from 'fs'
import escalade from 'escalade/sync'
import requireFresh from 'import-fresh'
import { configTwinValidators, configDefaultsTwin } from './twinConfig'
import defaultTwinConfig from './defaultTailwindConfig'
import { resolveTailwindConfig, getAllConfigs } from './util/twImports'
Expand All @@ -15,6 +14,7 @@ import type {
Assert,
AssertContext,
} from 'core/types'
import loadConfig from 'tailwindcss/loadConfig'

type Validator = [(value: unknown) => boolean, string]

Expand Down Expand Up @@ -76,7 +76,7 @@ function getTailwindConfig({

const configs = [
// User config
...(configExists ? getAllConfigs(requireFresh(configPath as string)) : []),
...(configExists ? getAllConfigs(loadConfig(configPath as string)) : []),
// Default config
...getAllConfigs(defaultTwinConfig),
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import type { Config } from 'tailwindcss'

export default {
theme: {
animation: {
'zoom-.5': 'zoom-.5 2s',
Expand Down Expand Up @@ -50,4 +52,4 @@ module.exports = {
customFontWeightAsNumber: 800,
},
},
}
} satisfies Config
5 changes: 5 additions & 0 deletions tests/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ pluginTester({
) && {
config: path.join(path.dirname(file), 'tailwind.config.js'),
}),
...(fs.existsSync(
path.join(path.dirname(file), 'tailwind.config.ts')
) && {
config: path.join(path.dirname(file), 'tailwind.config.ts'),
}),
...(fs.existsSync(configFile(file)) &&
JSON.parse(fs.readFileSync(configFile(file), 'utf8'))),
},
Expand Down
52 changes: 52 additions & 0 deletions types/tests/__fixtures__/config/tailwind.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
declare const _default: {
theme: {
animation: {
'zoom-.5': string
}
colors: {
number: number
purple: string
'purple-hyphen': string
mycolors: {
DEFAULT: string
'a-purple': string
'a-number': number
}
'my-blue': {
100: string
}
'color-opacity': ({ opacityVariable }: { opacityVariable: any }) => string
color: {
deep: {
config: {
500: string
}
}
}
blue: {
DEFAULT: string
gray: {
200: string
}
}
'blue-gray': {
DEFAULT: string
200: string
}
'blue-gray-green': {
DEFAULT: string
200: string
'deep-dish': {
DEFAULT: string
200: string
}
}
'blue-gray-green-pink': string
}
fontWeight: {
customFontWeightAsString: string
customFontWeightAsNumber: number
}
}
}
export default _default