On tailwind error prevent crash and show message (#156)
parent
906d3cfb4e
commit
a3d628af93
|
@ -17,17 +17,6 @@ import { getUtilityConfigMap } from './getUtilityConfigMap'
|
|||
import glob from 'fast-glob'
|
||||
import normalizePath from 'normalize-path'
|
||||
|
||||
function TailwindConfigError(error) {
|
||||
Error.call(this)
|
||||
Error.captureStackTrace(this, this.constructor)
|
||||
|
||||
this.name = this.constructor.name
|
||||
this.message = error.message
|
||||
this.stack = error.stack
|
||||
}
|
||||
|
||||
util.inherits(TailwindConfigError, Error)
|
||||
|
||||
function arraysEqual(arr1, arr2) {
|
||||
return (
|
||||
JSON.stringify(arr1.concat([]).sort()) ===
|
||||
|
@ -98,11 +87,17 @@ export default async function getClassNames(
|
|||
try {
|
||||
config = __non_webpack_require__(configPath)
|
||||
} catch (error) {
|
||||
throw new TailwindConfigError(error)
|
||||
hook.unwatch()
|
||||
hook.unhook()
|
||||
throw error
|
||||
}
|
||||
|
||||
hook.unwatch()
|
||||
|
||||
const [base, components, utilities] = await Promise.all(
|
||||
let postcssResult
|
||||
|
||||
try {
|
||||
postcssResult = await Promise.all(
|
||||
[
|
||||
semver.gte(version, '0.99.0') ? 'base' : 'preflight',
|
||||
'components',
|
||||
|
@ -113,8 +108,13 @@ export default async function getClassNames(
|
|||
})
|
||||
)
|
||||
)
|
||||
|
||||
} catch (error) {
|
||||
throw error
|
||||
} finally {
|
||||
hook.unhook()
|
||||
}
|
||||
|
||||
const [base, components, utilities] = postcssResult
|
||||
|
||||
if (typeof userSeperator !== 'undefined') {
|
||||
dset(config, sepLocation, userSeperator)
|
||||
|
@ -180,12 +180,7 @@ export default async function getClassNames(
|
|||
try {
|
||||
result = await run()
|
||||
} catch (error) {
|
||||
if (error instanceof TailwindConfigError) {
|
||||
onChange({ error })
|
||||
} else {
|
||||
unwatch()
|
||||
onChange(null)
|
||||
}
|
||||
return
|
||||
}
|
||||
const newDeps = [result.configPath, ...result.dependencies]
|
||||
|
|
Loading…
Reference in New Issue