protected function updatePackages($packagesFile = '')
    {
        $packagesFile = $packagesFile ?: "{$this->sageRoot}/package.json";
        $packages = json_decode(file_get_contents($packagesFile), true);
        if (!$this->addOn) {
            $packages = $this->removePresetsFromPackagesArray($packages);
        }
        $packages = $this->updatePackagesArray($packages);
        ksort($packages['devDependencies']);
        ksort($packages['dependencies']);
        file_put_contents(
            $packagesFile,
            preg_replace_callback('/^ +/m', function ($matches) {
                return str_repeat(' ', strlen($matches[0]) / 2);
            }, json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).PHP_EOL)
        );
    }