Skip to content

Commit 867cbfe

Browse files
committed
Fix config resolution in Tailwind v0
1 parent 413de96 commit 867cbfe

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
"@babel/register": "^7.9.0",
241241
"@ctrl/tinycolor": "^3.1.0",
242242
"@types/debounce": "^1.2.0",
243+
"@types/lodash.clonedeep": "^4.5.6",
243244
"@types/mocha": "^5.2.0",
244245
"@types/moo": "^0.5.3",
245246
"@types/node": "^13.9.3",
@@ -261,6 +262,7 @@
261262
"import-from": "^3.0.0",
262263
"jest": "^25.5.4",
263264
"line-column": "^1.0.2",
265+
"lodash.clonedeep": "^4.5.0",
264266
"mitt": "^1.2.0",
265267
"moo": "^0.5.1",
266268
"normalize-path": "^3.0.0",

src/class-names/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { getUtilityConfigMap } from './getUtilityConfigMap'
1616
import glob from 'fast-glob'
1717
import normalizePath from 'normalize-path'
1818
import clearModule from 'clear-module'
19+
import clone from 'lodash.clonedeep'
1920

2021
function arraysEqual(arr1, arr2) {
2122
return (
@@ -24,6 +25,13 @@ function arraysEqual(arr1, arr2) {
2425
)
2526
}
2627

28+
function deletePropertyPath(obj, path) {
29+
for (let i = 0; i < path.length - 1; i++) {
30+
obj = obj[path[i]]
31+
}
32+
delete obj[path.pop()]
33+
}
34+
2735
const CONFIG_GLOB =
2836
'**/{tailwind,tailwind.config,tailwind-config,.tailwindrc}.js'
2937

@@ -87,7 +95,7 @@ export default async function getClassNames(
8795
hook.watch()
8896
let config
8997
try {
90-
config = __non_webpack_require__(configPath)
98+
config = clone(__non_webpack_require__(configPath))
9199
} catch (error) {
92100
hook.unwatch()
93101
hook.unhook()
@@ -121,7 +129,7 @@ export default async function getClassNames(
121129
if (typeof userSeperator !== 'undefined') {
122130
dset(config, sepLocation, userSeperator)
123131
} else {
124-
delete config[sepLocation]
132+
deletePropertyPath(config, sepLocation)
125133
}
126134
if (typeof userPurge !== 'undefined') {
127135
config.purge = userPurge

src/class-names/resolveConfig.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ export default function resolveConfig({ cwd, config }) {
3030
'./stubs/defaultConfig.stub.js'
3131
)
3232
resolve = (config) => resolveConfig([config, defaultConfig])
33-
} catch (_) {}
33+
} catch (_) {
34+
try {
35+
const resolveConfig = importFrom(
36+
tailwindBase,
37+
'./lib/util/mergeConfigWithDefaults.js'
38+
).default
39+
const defaultConfig = importFrom(tailwindBase, './defaultConfig.js')()
40+
resolve = (config) => resolveConfig(config, defaultConfig)
41+
} catch (_) {}
42+
}
3443
}
3544

3645
return resolve(config)

0 commit comments

Comments
 (0)