On tailwind error prevent crash and show message (#156)

master
Brad Cornes 2020-08-25 16:59:13 +01:00
parent 906d3cfb4e
commit a3d628af93
1 changed files with 25 additions and 30 deletions

View File

@ -17,17 +17,6 @@ import { getUtilityConfigMap } from './getUtilityConfigMap'
import glob from 'fast-glob' import glob from 'fast-glob'
import normalizePath from 'normalize-path' 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) { function arraysEqual(arr1, arr2) {
return ( return (
JSON.stringify(arr1.concat([]).sort()) === JSON.stringify(arr1.concat([]).sort()) ===
@ -98,11 +87,17 @@ export default async function getClassNames(
try { try {
config = __non_webpack_require__(configPath) config = __non_webpack_require__(configPath)
} catch (error) { } catch (error) {
throw new TailwindConfigError(error) hook.unwatch()
hook.unhook()
throw error
} }
hook.unwatch() hook.unwatch()
const [base, components, utilities] = await Promise.all( let postcssResult
try {
postcssResult = await Promise.all(
[ [
semver.gte(version, '0.99.0') ? 'base' : 'preflight', semver.gte(version, '0.99.0') ? 'base' : 'preflight',
'components', 'components',
@ -113,8 +108,13 @@ export default async function getClassNames(
}) })
) )
) )
} catch (error) {
throw error
} finally {
hook.unhook() hook.unhook()
}
const [base, components, utilities] = postcssResult
if (typeof userSeperator !== 'undefined') { if (typeof userSeperator !== 'undefined') {
dset(config, sepLocation, userSeperator) dset(config, sepLocation, userSeperator)
@ -180,12 +180,7 @@ export default async function getClassNames(
try { try {
result = await run() result = await run()
} catch (error) { } catch (error) {
if (error instanceof TailwindConfigError) {
onChange({ error }) onChange({ error })
} else {
unwatch()
onChange(null)
}
return return
} }
const newDeps = [result.configPath, ...result.dependencies] const newDeps = [result.configPath, ...result.dependencies]