Skip to content

Commit 06c86ea

Browse files
authored
feat: add debug support (#94)
1 parent b14e054 commit 06c86ea

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@
2121
"node": ">=8.6"
2222
},
2323
"dependencies": {
24+
"debug": "^4.1.1",
2425
"env-paths": "^2.2.0",
2526
"fs-extra": "^7.0.1",
2627
"got": "^9.6.0",
2728
"sumchecker": "^3.0.0"
2829
},
2930
"devDependencies": {
3031
"@continuous-auth/semantic-release-npm": "^1.0.3",
32+
"@types/debug": "^4.1.4",
3133
"@types/fs-extra": "^7.0.0",
3234
"@types/got": "^9.4.4",
3335
"@types/jest": "^24.0.13",

src/Cache.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import debug from 'debug';
12
import envPaths from 'env-paths';
23
import * as fs from 'fs-extra';
34
import * as path from 'path';
45

6+
const d = debug('@electron/get:cache');
7+
58
const defaultCacheRoot = envPaths('electron', {
69
suffix: '',
710
}).cache;
@@ -24,7 +27,9 @@ export class Cache {
2427

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

src/index.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import debug from 'debug';
12
import * as path from 'path';
23

34
import { getArtifactFileName, getArtifactRemoteURL, FileNameUse } from './artifact-utils';
@@ -8,6 +9,7 @@ import { withTempDirectory, normalizeVersion, getHostArch, ensureIsTruthyString
89

910
export { getHostArch } from './utils';
1011

12+
const d = debug('@electron/get:index');
1113
const sumchecker: typeof import('sumchecker').default = require('sumchecker');
1214

1315
/**
@@ -47,9 +49,13 @@ export async function downloadArtifact(_artifactDetails: ElectronArtifactDetails
4749

4850
// Do not check if the file exists in the cache when force === true
4951
if (!artifactDetails.force) {
52+
d(`Checking the cache for ${fileName}`);
5053
const cachedPath = await cache.getPathForFileInCache(fileName);
5154

52-
if (cachedPath !== null) {
55+
if (cachedPath === null) {
56+
d('Cache miss');
57+
} else {
58+
d('Cache hit');
5359
return cachedPath;
5460
}
5561
}
@@ -61,11 +67,13 @@ export async function downloadArtifact(_artifactDetails: ElectronArtifactDetails
6167
);
6268

6369
const downloader = artifactDetails.downloader || (await getDownloaderForSystem());
64-
await downloader.download(
65-
getArtifactRemoteURL(artifactDetails),
66-
tempDownloadPath,
67-
artifactDetails.downloadOptions,
70+
const url = getArtifactRemoteURL(artifactDetails);
71+
d(
72+
`Downloading ${url} to ${tempDownloadPath} with options: ${JSON.stringify(
73+
artifactDetails.downloadOptions,
74+
)}`,
6875
);
76+
await downloader.download(url, tempDownloadPath, artifactDetails.downloadOptions);
6977

7078
// Don't try to verify the hash of the hash file itself
7179
if (

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@
504504
dependencies:
505505
"@babel/types" "^7.3.0"
506506

507+
"@types/debug@^4.1.4":
508+
version "4.1.4"
509+
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-4.1.4.tgz#56eec47706f0fd0b7c694eae2f3172e6b0b769da"
510+
integrity sha512-D9MyoQFI7iP5VdpEyPZyjjqIJ8Y8EDNQFIFVLOmeg1rI1xiHOChyUPMPRUVfqFCerxfE+yS3vMyj37F6IdtOoQ==
511+
507512
"@types/events@*":
508513
version "3.0.0"
509514
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"

0 commit comments

Comments
 (0)