Skip to content

Commit

Permalink
Merge branch 'albohlabs-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-rogerson committed Apr 11, 2023
2 parents f2b425d + 8280bc8 commit 7fc2d62
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 19 deletions.
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
16 changes: 7 additions & 9 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 @@ -48,14 +48,12 @@ function getTailwindConfig({
const configPath = userTailwindConfig
? resolve(sourceRoot, userTailwindConfig)
: escalade(baseDirectory, (_, names) => {
if (names.includes('tailwind.config.js')) {
return 'tailwind.config.js'
}
if (names.includes('tailwind.config.js')) return 'tailwind.config.js'

if (names.includes('tailwind.config.cjs')) {
return 'tailwind.config.cjs'
}
})
if (names.includes('tailwind.config.cjs')) return 'tailwind.config.cjs'

if (names.includes('tailwind.config.ts')) return 'tailwind.config.ts'
}) ?? ''

const configExists = Boolean(configPath && existsSync(configPath))

Expand All @@ -76,7 +74,7 @@ function getTailwindConfig({

const configs = [
// User config
...(configExists ? getAllConfigs(requireFresh(configPath as string)) : []),
...(configExists ? getAllConfigs(loadConfig(configPath)) : []),
// Default config
...getAllConfigs(defaultTwinConfig),
]
Expand Down
8 changes: 8 additions & 0 deletions tests/__fixtures__/configTS/configTS.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-nocheck
import tw from '../macro'

/**
* Test the config matching is working correctly
*/

tw`text-purple`
10 changes: 10 additions & 0 deletions tests/__fixtures__/configTS/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Config } from 'tailwindcss'

export default {
content: [],
theme: {
colors: {
purple: 'custom',
},
},
} satisfies Config
25 changes: 25 additions & 0 deletions tests/__snapshots__/plugin.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21426,6 +21426,31 @@ tw\`font-customFontWeightAsNumber\`
})


`;

exports[`twin.macro configTS.tsx: configTS.tsx 1`] = `

// @ts-nocheck
import tw from '../macro'

/**
* Test the config matching is working correctly
*/

tw\`text-purple\`

↓ ↓ ↓ ↓ ↓ ↓

// @ts-nocheck

/**
* Test the config matching is working correctly
*/
;({
color: 'custom',
})


`;

exports[`twin.macro container.tsx: container.tsx 1`] = `
Expand Down
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
9 changes: 9 additions & 0 deletions types/tests/__fixtures__/configTS/tailwind.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare const _default: {
content: never[]
theme: {
colors: {
purple: string
}
}
}
export default _default

0 comments on commit 7fc2d62

Please sign in to comment.