async function download(options = {}) {
    let version = options === null || options === void 0 ? void 0 : options.version;
    const { platform = util_2.systemDefaultPlatform, architecture = util_2.systemDefaultArchitecture, cachePath = exports.defaultCachePath, reporter = new progress_1.ConsoleReporter(process.stdout.isTTY), extractSync = false, } = options;
    if (version) {
        if (version === 'stable') {
            version = await fetchLatestStableVersion();
        }
        else {
            /**
             * Only validate version against server when no local download that matches version exists
             */
            if (!fs.existsSync(path.resolve(cachePath, `vscode-${platform}-${version}`))) {
                if (!(await isValidVersion(version))) {
                    throw Error(`Invalid version ${version}`);
                }
            }
        }
    }
    else {
        version = await fetchLatestStableVersion();
    }
    reporter.report({ stage: progress_1.ProgressReportStage.ResolvedVersion, version });
    const downloadedPath = path.resolve(cachePath, `vscode-${platform}-${version}`);
    if (fs.existsSync(downloadedPath)) {
        if (version === 'insiders') {
            reporter.report({ stage: progress_1.ProgressReportStage.FetchingInsidersMetadata });
            const { version: currentHash, date: currentDate } = util_2.insidersDownloadDirMetadata(downloadedPath, platform);
            const { version: latestHash, timestamp: latestTimestamp } = await util_2.getLatestInsidersMetadata(util_2.systemDefaultPlatform);
            if (currentHash === latestHash) {
                reporter.report({ stage: progress_1.ProgressReportStage.FoundMatchingInstall, downloadedPath });
                return Promise.resolve(util_2.insidersDownloadDirToExecutablePath(downloadedPath, platform));
            }
            else {
                try {
                    reporter.report({
                        stage: progress_1.ProgressReportStage.ReplacingOldInsiders,
                        downloadedPath,
                        oldDate: currentDate,
                        oldHash: currentHash,
                        newDate: new Date(latestTimestamp),
                        newHash: latestHash,
                    });
                    await del.rmdir(downloadedPath);
                }
                catch (err) {
                    reporter.error(err);
                    throw Error(`Failed to remove outdated Insiders at ${downloadedPath}.`);
                }
            }
        }
        else {
            reporter.report({ stage: progress_1.ProgressReportStage.FoundMatchingInstall, downloadedPath });
            return Promise.resolve(util_2.downloadDirToExecutablePath(downloadedPath, platform));
        }
    }
    try {
        const { stream, format } = await downloadVSCodeArchive({ version, architecture, platform, cachePath, reporter });
        await unzipVSCode(reporter, downloadedPath, extractSync, stream, format);
        reporter.report({ stage: progress_1.ProgressReportStage.NewInstallComplete, downloadedPath });
    }
    catch (err) {
        reporter.error(err);
        throw Error(`Failed to download and unzip VS Code ${version}`);
    }
    if (version === 'insiders') {
        return Promise.resolve(util_2.insidersDownloadDirToExecutablePath(downloadedPath, platform));
    }
    else {
        return util_2.downloadDirToExecutablePath(downloadedPath, platform);
    }
}
/**
 * Download and unzip a copy of VS Code.
 * @returns Promise of `vscodeExecutablePath`.
 */
Download and unzip a copy of VS Code.
@returns Promise of `vscodeExecutablePath`.
Download and unzip a copy of VS Code . @returns Promise of ` vscodeExecutablePath ` .
async function download(options = {}) {
    let version = options === null || options === void 0 ? void 0 : options.version;
    const { platform = util_2.systemDefaultPlatform, architecture = util_2.systemDefaultArchitecture, cachePath = exports.defaultCachePath, reporter = new progress_1.ConsoleReporter(process.stdout.isTTY), extractSync = false, } = options;
    if (version) {
        if (version === 'stable') {
            version = await fetchLatestStableVersion();
        }
        else {
            if (!fs.existsSync(path.resolve(cachePath, `vscode-${platform}-${version}`))) {
                if (!(await isValidVersion(version))) {
                    throw Error(`Invalid version ${version}`);
                }
            }
        }
    }
    else {
        version = await fetchLatestStableVersion();
    }
    reporter.report({ stage: progress_1.ProgressReportStage.ResolvedVersion, version });
    const downloadedPath = path.resolve(cachePath, `vscode-${platform}-${version}`);
    if (fs.existsSync(downloadedPath)) {
        if (version === 'insiders') {
            reporter.report({ stage: progress_1.ProgressReportStage.FetchingInsidersMetadata });
            const { version: currentHash, date: currentDate } = util_2.insidersDownloadDirMetadata(downloadedPath, platform);
            const { version: latestHash, timestamp: latestTimestamp } = await util_2.getLatestInsidersMetadata(util_2.systemDefaultPlatform);
            if (currentHash === latestHash) {
                reporter.report({ stage: progress_1.ProgressReportStage.FoundMatchingInstall, downloadedPath });
                return Promise.resolve(util_2.insidersDownloadDirToExecutablePath(downloadedPath, platform));
            }
            else {
                try {
                    reporter.report({
                        stage: progress_1.ProgressReportStage.ReplacingOldInsiders,
                        downloadedPath,
                        oldDate: currentDate,
                        oldHash: currentHash,
                        newDate: new Date(latestTimestamp),
                        newHash: latestHash,
                    });
                    await del.rmdir(downloadedPath);
                }
                catch (err) {
                    reporter.error(err);
                    throw Error(`Failed to remove outdated Insiders at ${downloadedPath}.`);
                }
            }
        }
        else {
            reporter.report({ stage: progress_1.ProgressReportStage.FoundMatchingInstall, downloadedPath });
            return Promise.resolve(util_2.downloadDirToExecutablePath(downloadedPath, platform));
        }
    }
    try {
        const { stream, format } = await downloadVSCodeArchive({ version, architecture, platform, cachePath, reporter });
        await unzipVSCode(reporter, downloadedPath, extractSync, stream, format);
        reporter.report({ stage: progress_1.ProgressReportStage.NewInstallComplete, downloadedPath });
    }
    catch (err) {
        reporter.error(err);
        throw Error(`Failed to download and unzip VS Code ${version}`);
    }
    if (version === 'insiders') {
        return Promise.resolve(util_2.insidersDownloadDirToExecutablePath(downloadedPath, platform));
    }
    else {
        return util_2.downloadDirToExecutablePath(downloadedPath, platform);
    }
}
async function download ( options = { } ) { let version = options === null || options === void 0 ? void 0 : options . version ; const { platform = util_2 . systemDefaultPlatform , architecture = util_2 . systemDefaultArchitecture , cachePath = exports . defaultCachePath , reporter = new progress_1 . ConsoleReporter ( process . stdout . isTTY ) , extractSync = false , } = options ; if ( version ) { if ( version === 'stable' ) { version = await fetchLatestStableVersion ( ) ; } else { if ( ! fs . existsSync ( path . resolve ( cachePath , ` ${ platform } ${ version } ` ) ) ) { if ( ! ( await isValidVersion ( version ) ) ) { throw Error ( ` ${ version } ` ) ; } } } } else { version = await fetchLatestStableVersion ( ) ; } reporter . report ( { stage : progress_1 . ProgressReportStage . ResolvedVersion , version } ) ; const downloadedPath = path . resolve ( cachePath , ` ${ platform } ${ version } ` ) ; if ( fs . existsSync ( downloadedPath ) ) { if ( version === 'insiders' ) { reporter . report ( { stage : progress_1 . ProgressReportStage . FetchingInsidersMetadata } ) ; const { version : currentHash , date : currentDate } = util_2 . insidersDownloadDirMetadata ( downloadedPath , platform ) ; const { version : latestHash , timestamp : latestTimestamp } = await util_2 . getLatestInsidersMetadata ( util_2 . systemDefaultPlatform ) ; if ( currentHash === latestHash ) { reporter . report ( { stage : progress_1 . ProgressReportStage . FoundMatchingInstall , downloadedPath } ) ; return Promise . resolve ( util_2 . insidersDownloadDirToExecutablePath ( downloadedPath , platform ) ) ; } else { try { reporter . report ( { stage : progress_1 . ProgressReportStage . ReplacingOldInsiders , downloadedPath , oldDate : currentDate , oldHash : currentHash , newDate : new Date ( latestTimestamp ) , newHash : latestHash , } ) ; await del . rmdir ( downloadedPath ) ; } catch ( err ) { reporter . error ( err ) ; throw Error ( ` ${ downloadedPath } ` ) ; } } } else { reporter . report ( { stage : progress_1 . ProgressReportStage . FoundMatchingInstall , downloadedPath } ) ; return Promise . resolve ( util_2 . downloadDirToExecutablePath ( downloadedPath , platform ) ) ; } } try { const { stream , format } = await downloadVSCodeArchive ( { version , architecture , platform , cachePath , reporter } ) ; await unzipVSCode ( reporter , downloadedPath , extractSync , stream , format ) ; reporter . report ( { stage : progress_1 . ProgressReportStage . NewInstallComplete , downloadedPath } ) ; } catch ( err ) { reporter . error ( err ) ; throw Error ( ` ${ version } ` ) ; } if ( version === 'insiders' ) { return Promise . resolve ( util_2 . insidersDownloadDirToExecutablePath ( downloadedPath , platform ) ) ; } else { return util_2 . downloadDirToExecutablePath ( downloadedPath , platform ) ; } }
Download and unzip a copy of VS Code.
Download and unzip a copy of VS Code .
/**
             * Only validate version against server when no local download that matches version exists
             */