Skip to content

Commit

Permalink
chore: add debug support
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed May 29, 2019
1 parent 0a64fd4 commit 496fe53
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
"node": ">=8.6"
},
"dependencies": {
"debug": "^4.1.1",
"env-paths": "^2.1.0",
"fs-extra": "^8.0.1",
"got": "^9.6.0",
"sumchecker": "^3.0.0"
},
"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",
Expand Down Expand Up @@ -58,4 +60,4 @@
"artifact",
"release"
]
}
}
5 changes: 5 additions & 0 deletions src/Cache.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,7 +27,9 @@ export class Cache {

public async putFileInCache(currentPath: string, fileName: string): Promise<string> {
const cachePath = this.getCachePath(fileName);
d(`Moving ${currentPath} to ${cachePath}`);
if (await fs.pathExists(cachePath)) {
d('* Replacing existing file');
await fs.remove(cachePath);
}

Expand Down
18 changes: 13 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debug from 'debug';
import * as path from 'path';

import { getArtifactFileName, getArtifactRemoteURL, FileNameUse } from './artifact-utils';
Expand All @@ -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');

/**
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 (
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 496fe53

Please sign in to comment.