From c8f620588d1900354d10f00cc4e176ab42690077 Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Tue, 28 May 2019 21:17:56 -0700 Subject: [PATCH] feat: add debug support --- package.json | 2 ++ src/Cache.ts | 5 +++++ src/index.ts | 18 +++++++++++++----- yarn.lock | 5 +++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 8acd7d921..019c11015 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "node": ">=8.6" }, "dependencies": { + "debug": "^4.1.1", "env-paths": "^2.1.0", "fs-extra": "^7.0.1", "got": "^9.6.0", @@ -27,6 +28,7 @@ }, "devDependencies": { "@continuous-auth/semantic-release-npm": "^1.0.3", + "@types/debug": "^4.1.4", "@types/fs-extra": "^7.0.0", "@types/got": "^9.4.4", "@types/jest": "^24.0.13", diff --git a/src/Cache.ts b/src/Cache.ts index c83ca4b7a..a4cdc2945 100644 --- a/src/Cache.ts +++ b/src/Cache.ts @@ -1,7 +1,10 @@ +import debug from 'debug'; import envPaths from 'env-paths'; import * as fs from 'fs-extra'; import * as path from 'path'; +const d = debug('@electron/get:cache'); + const defaultCacheRoot = envPaths('electron', { suffix: '', }).cache; @@ -24,7 +27,9 @@ export class Cache { public async putFileInCache(currentPath: string, fileName: string): Promise { const cachePath = this.getCachePath(fileName); + d(`Moving ${currentPath} to ${cachePath}`); if (await fs.pathExists(cachePath)) { + d('* Replacing existing file'); await fs.remove(cachePath); } diff --git a/src/index.ts b/src/index.ts index 5dd16fae6..8129d567c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import debug from 'debug'; import * as path from 'path'; import { getArtifactFileName, getArtifactRemoteURL, FileNameUse } from './artifact-utils'; @@ -8,6 +9,7 @@ import { withTempDirectory, normalizeVersion, getHostArch, ensureIsTruthyString export { getHostArch } from './utils'; +const d = debug('@electron/get:index'); const sumchecker: typeof import('sumchecker').default = require('sumchecker'); /** @@ -47,9 +49,13 @@ export async function downloadArtifact(_artifactDetails: ElectronArtifactDetails // Do not check if the file exists in the cache when force === true if (!artifactDetails.force) { + d(`Checking the cache for ${fileName}`); const cachedPath = await cache.getPathForFileInCache(fileName); - if (cachedPath !== null) { + if (cachedPath === null) { + d('Cache miss'); + } else { + d('Cache hit'); return cachedPath; } } @@ -61,11 +67,13 @@ export async function downloadArtifact(_artifactDetails: ElectronArtifactDetails ); const downloader = artifactDetails.downloader || (await getDownloaderForSystem()); - await downloader.download( - getArtifactRemoteURL(artifactDetails), - tempDownloadPath, - artifactDetails.downloadOptions, + const url = getArtifactRemoteURL(artifactDetails); + d( + `Downloading ${url} to ${tempDownloadPath} with options: ${JSON.stringify( + artifactDetails.downloadOptions, + )}`, ); + await downloader.download(url, tempDownloadPath, artifactDetails.downloadOptions); // Don't try to verify the hash of the hash file itself if ( diff --git a/yarn.lock b/yarn.lock index 9b71b95f7..2f2881b4f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -504,6 +504,11 @@ dependencies: "@babel/types" "^7.3.0" +"@types/debug@^4.1.4": + version "4.1.4" + resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.4.tgz#56eec47706f0fd0b7c694eae2f3172e6b0b769da" + integrity sha512-D9MyoQFI7iP5VdpEyPZyjjqIJ8Y8EDNQFIFVLOmeg1rI1xiHOChyUPMPRUVfqFCerxfE+yS3vMyj37F6IdtOoQ== + "@types/events@*": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"