Skip to content

Commit 3b54a32

Browse files
author
Brad Cornes
committed
Merge branch 'next' into config-explorer
2 parents cfa6f12 + 14ffaf4 commit 3b54a32

File tree

25 files changed

+6169
-303
lines changed

25 files changed

+6169
-303
lines changed

packages/tailwindcss-class-names/package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/tailwindcss-class-names/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"devDependencies": {
2828
"@zeit/ncc": "^0.21.1",
2929
"esm": "^3.2.25",
30-
"jest": "^25.1.0"
30+
"jest": "^25.1.0",
31+
"postcss": "^7.0.27"
3132
}
3233
}

packages/tailwindcss-class-names/src/extractClassNames.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ async function process(ast) {
5555

5656
const decls = {}
5757
rule.walkDecls((decl) => {
58-
decls[decl.prop] = decl.value
58+
if (decls[decl.prop]) {
59+
decls[decl.prop] = [
60+
...(Array.isArray(decls[decl.prop])
61+
? decls[decl.prop]
62+
: [decls[decl.prop]]),
63+
decl.value,
64+
]
65+
} else {
66+
decls[decl.prop] = decl.value
67+
}
5968
})
6069

6170
let p = rule

packages/tailwindcss-class-names/src/getPlugins.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ import stackTrace from 'stack-trace'
33
import pkgUp from 'pkg-up'
44
import { glob } from './glob'
55
import { isObject } from './isObject'
6+
import importFrom from 'import-from'
67

7-
export async function getBuiltInPlugins(cwd) {
8+
export async function getBuiltInPlugins({ cwd, resolvedConfig }) {
89
try {
9-
return (
10-
await glob(path.resolve(cwd, 'node_modules/tailwindcss/lib/plugins/*.js'))
11-
)
12-
.map((x) => {
13-
try {
14-
const mod = __non_webpack_require__(x)
15-
return mod.default ? mod.default() : mod()
16-
} catch (_) {}
17-
})
18-
.filter(Boolean)
10+
// TODO: add v0 support ("generators")
11+
return importFrom(cwd, 'tailwindcss/lib/corePlugins.js').default({
12+
corePlugins: resolvedConfig.corePlugins,
13+
})
1914
} catch (_) {
2015
return []
2116
}

packages/tailwindcss-class-names/src/getUtilityConfigMap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const proxyHandler = (base = []) => ({
1919
})
2020

2121
export async function getUtilityConfigMap({ cwd, resolvedConfig, postcss }) {
22-
const builtInPlugins = await getBuiltInPlugins(cwd)
22+
const builtInPlugins = await getBuiltInPlugins({ cwd, resolvedConfig })
2323
const userPlugins = Array.isArray(resolvedConfig.plugins)
2424
? resolvedConfig.plugins
2525
: []

packages/tailwindcss-class-names/src/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import getPlugins from './getPlugins'
1010
import getVariants from './getVariants'
1111
import resolveConfig from './resolveConfig'
1212
import * as util from 'util'
13+
import * as path from 'path'
1314
import { glob } from './glob'
1415
import { getUtilityConfigMap } from './getUtilityConfigMap'
1516

@@ -51,9 +52,10 @@ export default async function getClassNames(
5152
})
5253
invariant(configPath.length === 1, 'No Tailwind CSS config found.')
5354
configPath = configPath[0]
54-
postcss = importFrom(cwd, 'postcss')
55-
tailwindcss = importFrom(cwd, 'tailwindcss')
56-
version = importFrom(cwd, 'tailwindcss/package.json').version
55+
const configDir = path.dirname(configPath)
56+
postcss = importFrom(configDir, 'postcss')
57+
tailwindcss = importFrom(configDir, 'tailwindcss')
58+
version = importFrom(configDir, 'tailwindcss/package.json').version
5759

5860
const sepLocation = semver.gte(version, '0.99.0')
5961
? ['separator']
@@ -90,9 +92,10 @@ export default async function getClassNames(
9092
delete config[sepLocation]
9193
}
9294

93-
const resolvedConfig = resolveConfig({ cwd, config })
95+
const resolvedConfig = resolveConfig({ cwd: configDir, config })
9496

9597
return {
98+
version,
9699
configPath,
97100
config: resolvedConfig,
98101
separator: typeof userSeperator === 'undefined' ? ':' : userSeperator,
@@ -101,7 +104,7 @@ export default async function getClassNames(
101104
plugins: getPlugins(config),
102105
variants: getVariants({ config, version, postcss }),
103106
utilityConfigMap: await getUtilityConfigMap({
104-
cwd,
107+
cwd: configDir,
105108
resolvedConfig,
106109
postcss,
107110
}),
@@ -112,7 +115,7 @@ export default async function getClassNames(
112115
function watch(files = []) {
113116
if (watcher) watcher.close()
114117
watcher = chokidar
115-
.watch([CONFIG_GLOB, ...files])
118+
.watch([CONFIG_GLOB, ...files], { cwd })
116119
.on('change', handleChange)
117120
.on('unlink', handleChange)
118121
}

packages/tailwindcss-class-names/tests/extractClassNames.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ test('foo', async () => {
121121
})
122122
})
123123

124-
test.only('processes basic css', async () => {
124+
test('processes basic css', async () => {
125125
const result = await processCss(`
126-
.bg-red\\:foo {
126+
.bg-red {
127127
background-color: red;
128128
}
129129
`)
@@ -350,3 +350,24 @@ test('processes multiple scopes for the same class name', async () => {
350350
},
351351
})
352352
})
353+
354+
test('processes multiple properties of the same name', async () => {
355+
const result = await processCss(`
356+
.bg-red {
357+
background-color: blue;
358+
background-color: red;
359+
}
360+
`)
361+
362+
expect(result).toEqual({
363+
context: {},
364+
classNames: {
365+
'bg-red': {
366+
__rule: true,
367+
__context: [],
368+
__scope: null,
369+
'background-color': ['blue', 'red'],
370+
},
371+
},
372+
})
373+
})

0 commit comments

Comments
 (0)