diff --git a/src/class-names/index.js b/src/class-names/index.js index c456d5bdd640dc47f80cbcc4fa49cde3697d206f..83a15b11a214b931a6e04f569b3d5da5295eda55 100644 --- a/src/class-names/index.js +++ b/src/class-names/index.js @@ -17,6 +17,17 @@ 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()) === @@ -87,34 +98,23 @@ let config try { config = __non_webpack_require__(configPath) } catch (error) { - hook.unwatch() - hook.unhook() - throw error + throw new TailwindConfigError(error) } - hook.unwatch() - let postcssResult - - try { - postcssResult = await Promise.all( - [ - semver.gte(version, '0.99.0') ? 'base' : 'preflight', - 'components', - 'utilities', - ].map((group) => - postcss([tailwindcss(configPath)]).process(`@tailwind ${group};`, { - from: undefined, - }) - ) + const [base, components, utilities] = await Promise.all( + [ + semver.gte(version, '0.99.0') ? 'base' : 'preflight', + 'components', + 'utilities', + ].map((group) => + postcss([tailwindcss(configPath)]).process(`@tailwind ${group};`, { + from: undefined, + }) ) - } catch (error) { - throw error - } finally { - hook.unhook() - } + ) - const [base, components, utilities] = postcssResult + hook.unhook() if (typeof userSeperator !== 'undefined') { dset(config, sepLocation, userSeperator) @@ -180,7 +180,12 @@ const prevDeps = result ? [result.configPath, ...result.dependencies] : [] try { result = await run() } catch (error) { - onChange({ error }) + if (error instanceof TailwindConfigError) { + onChange({ error }) + } else { + unwatch() + onChange(null) + } return } const newDeps = [result.configPath, ...result.dependencies]