Skip to content

Commit 20a247c

Browse files
committed
feat: use cache dir per OS convention
1 parent eec5b32 commit 20a247c

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

circle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ machine:
55
dependencies:
66
cache_directories:
77
- "~/.electron"
8-
- "~/.cache"
8+
- "~/.cache/electron-builder"
99

1010
# https://discuss.circleci.com/t/installing-git-lfs/867
1111
# circleci doesn't cache after test, only after deps, so, we do test in this phase
@@ -14,7 +14,7 @@ dependencies:
1414
- sudo apt-get install git-lfs=1.3.0
1515
- ssh git@github.com git-lfs-authenticate $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME.git download
1616
- git lfs pull
17-
- docker run --rm --env-file ./test/docker-env.list -v ${PWD}:/project -v ~/.electron:/root/.electron -v ~/.cache:/root/.cache electronuserland/electron-builder:$([ "$CIRCLE_NODE_INDEX" == "2" ] && echo "4" || echo "wine") /test.sh
17+
- docker run --rm --env-file ./test/docker-env.list -v ${PWD}:/project -v ~/.electron:/root/.electron -v ~/.cache/electron-builder:/root/.cache/electron-builder electronuserland/electron-builder:$([ "$CIRCLE_NODE_INDEX" == "2" ] && echo "4" || echo "wine") /test.sh
1818

1919
test:
2020
override:

src/cleanup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#! /usr/bin/env node
22

3-
import { homedir } from "os"
43
import { readdir, lstat, Stats, remove, readFile } from "fs-extra-p"
54
import BluebirdPromise from "bluebird-lst-c"
65
import * as path from "path"
6+
import { getCacheDirectory } from "./util/util"
77

88
async function main() {
9-
const dir = path.join(homedir(), ".cache", "fpm")
9+
const dir = path.join(getCacheDirectory(), "fpm")
1010
let items: string[] | null = null
1111
try {
1212
items = await readdir(dir)

src/codeSign.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { exec, getTempName, isEmptyOrSpaces, isCi } from "./util/util"
1+
import { exec, getTempName, isEmptyOrSpaces, isCi, getCacheDirectory } from "./util/util"
22
import { deleteFile, outputFile, copy, rename } from "fs-extra-p"
33
import { download } from "./util/httpRequest"
44
import * as path from "path"
55
import { executeFinally, all } from "./util/promise"
66
import BluebirdPromise from "bluebird-lst-c"
77
import { randomBytes } from "crypto"
8-
import { homedir } from "os"
98
import { TmpDir } from "./util/tmp"
109

1110
const appleCertificatePrefixes = ["Developer ID Application:", "3rd Party Mac Developer Application:", "Developer ID Installer:", "3rd Party Mac Developer Installer:"]
@@ -39,8 +38,8 @@ let bundledCertKeychainAdded: Promise<any> | null = null
3938
// https://github.com/electron-userland/electron-builder/issues/398
4039
async function createCustomCertKeychain() {
4140
// copy to temp and then atomic rename to final path
42-
const tmpKeychainPath = path.join(homedir(), ".cache", getTempName("electron_builder_root_certs"))
43-
const keychainPath = path.join(homedir(), ".cache", "electron_builder_root_certs.keychain")
41+
const tmpKeychainPath = path.join(getCacheDirectory(), getTempName("electron-builder-root-certs"))
42+
const keychainPath = path.join(getCacheDirectory(), "electron-builder-root-certs.keychain")
4443
const results = await BluebirdPromise.all<string>([
4544
exec("security", ["list-keychains"]),
4645
copy(path.join(__dirname, "..", "certs", "root_certs.keychain"), tmpKeychainPath)

src/util/binDownload.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { statOrNull, spawn, debug, debug7zArgs, getTempName } from "./util"
1+
import { statOrNull, spawn, debug, debug7zArgs, getTempName, getCacheDirectory } from "./util"
22
import { rename, unlink, emptyDir } from "fs-extra-p"
33
import { download } from "./httpRequest"
44
import { path7za } from "7zip-bin"
55
import * as path from "path"
6-
import { homedir } from "os"
76
import BluebirdPromise from "bluebird-lst-c"
87

98
const versionToPromise = new Map<string, BluebirdPromise<string>>()
@@ -30,7 +29,7 @@ export function getBin(name: string, dirName: string, url: string, sha2: string)
3029
// * don't pollute user project dir (important in case of 1-package.json project structure)
3130
// * simplify/speed-up tests (don't download fpm for each test project)
3231
async function doGetBin(name: string, dirName: string, url: string, sha2: string): Promise<string> {
33-
const cachePath = path.join(homedir(), ".cache", name)
32+
const cachePath = path.join(getCacheDirectory(), name)
3433
const dirPath = path.join(cachePath, dirName)
3534

3635
const dirStat = await statOrNull(dirPath)

src/util/util.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,16 @@ export function asArray<T>(v: n | T | Array<T>): Array<T> {
312312
}
313313
export function isCi(): boolean {
314314
return (process.env.CI || "").toLowerCase() === "true"
315+
}
316+
317+
export function getCacheDirectory(): string {
318+
if (process.platform === "darwin") {
319+
return path.join(homedir(), "Library", "Caches", "electron-builder")
320+
}
321+
else if (process.platform === "win32" && process.env.LOCALAPPDATA != null) {
322+
return path.join(process.env.LOCALAPPDATA, "electron-builder", "cache")
323+
}
324+
else {
325+
return path.join(homedir(), ".cache", "electron-builder")
326+
}
315327
}

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,8 +2085,8 @@ globals@^9.0.0:
20852085
resolved "https://registry.yarnpkg.com/globals/-/globals-9.12.0.tgz#992ce90828c3a55fa8f16fada177adb64664cf9d"
20862086

20872087
globby@^6.0.0:
2088-
version "6.0.0"
2089-
resolved "https://registry.yarnpkg.com/globby/-/globby-6.0.0.tgz#8f5710eda32296ac53f011a97dccc70e936685dc"
2088+
version "6.1.0"
2089+
resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
20902090
dependencies:
20912091
array-union "^1.0.1"
20922092
glob "^7.0.3"
@@ -3449,8 +3449,8 @@ regenerate@^1.2.1:
34493449
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.1.tgz#0300203a5d2fdcf89116dce84275d011f5903f33"
34503450

34513451
regenerator-runtime@^0.9.5:
3452-
version "0.9.5"
3453-
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.5.tgz#403d6d40a4bdff9c330dd9392dcbb2d9a8bba1fc"
3452+
version "0.9.6"
3453+
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.6.tgz#d33eb95d0d2001a4be39659707c51b0cb71ce029"
34543454

34553455
regex-cache@^0.4.2:
34563456
version "0.4.3"
@@ -3986,8 +3986,8 @@ typedarray@~0.0.5:
39863986
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
39873987

39883988
typescript@^2.1.0-dev.20161101:
3989-
version "2.1.0-dev.20161104"
3990-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.0-dev.20161104.tgz#01ebabbc76b36c6fb56a77f9df34fc7fe5fe8512"
3989+
version "2.1.0-dev.20161105"
3990+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.0-dev.20161105.tgz#be261e6cfeccaad5026aeab22f938ae0d91f5897"
39913991

39923992
uc.micro@^1.0.1, uc.micro@^1.0.3:
39933993
version "1.0.3"

0 commit comments

Comments
 (0)