protected function resolveExtends()
    {
        $extend = [];
        foreach ($this->_targets as $name => $target) {
            if (empty($target['extend'])) {
                continue;
            }
            $parent = $target['extend'];
            if (empty($this->_targets[$parent])) {
                throw new RuntimeException("Invalid extend in '$name'. There is no '$parent' target defined.");
            }
            $extend[] = $name;
        }

        $expander = function ($target) use (&$expander, $extend) {
            $config = $this->_targets[$target];
            $parentConfig = false;

            // Recurse through parents to collect all config.
            if (in_array($target, $extend)) {
                $parentConfig = $expander($config['extend']);
            }
            if (!$parentConfig) {
                return $config;
            }
            $config['files'] = array_merge($parentConfig['files'], $config['files']);
            $config['filters'] = array_merge($parentConfig['filters'], $config['filters']);
            $config['theme'] = $parentConfig['theme'] || $config['theme'];
            return $config;
        };

        foreach ($extend as $target) {
            $this->_targets[$target] = $expander($target);
        }
    }