1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.doesCallerOwnTemporaryOutput = exports.shouldWriteCache = exports.shouldTryReadCache = exports.effectiveCacheMode = exports.setEnv = exports.getEnv = exports.isOfficialLinuxIA32Download = exports.ensureIsTruthyString = exports.getHostArch = exports.getNodeArch = exports.uname = exports.normalizeVersion = exports.withTempDirectory = exports.withTempDirectoryIn = exports.TempDirCleanUpMode = exports.mkdtemp = void 0;
|
4 | const childProcess = require("child_process");
|
5 | const fs = require("fs-extra");
|
6 | const os = require("os");
|
7 | const path = require("path");
|
8 | const types_1 = require("./types");
|
9 | async function useAndRemoveDirectory(directory, fn) {
|
10 | let result;
|
11 | try {
|
12 | result = await fn(directory);
|
13 | }
|
14 | finally {
|
15 | await fs.remove(directory);
|
16 | }
|
17 | return result;
|
18 | }
|
19 | async function mkdtemp(parentDirectory = os.tmpdir()) {
|
20 | const tempDirectoryPrefix = 'electron-download-';
|
21 | return await fs.mkdtemp(path.resolve(parentDirectory, tempDirectoryPrefix));
|
22 | }
|
23 | exports.mkdtemp = mkdtemp;
|
24 | var TempDirCleanUpMode;
|
25 | (function (TempDirCleanUpMode) {
|
26 | TempDirCleanUpMode[TempDirCleanUpMode["CLEAN"] = 0] = "CLEAN";
|
27 | TempDirCleanUpMode[TempDirCleanUpMode["ORPHAN"] = 1] = "ORPHAN";
|
28 | })(TempDirCleanUpMode = exports.TempDirCleanUpMode || (exports.TempDirCleanUpMode = {}));
|
29 | async function withTempDirectoryIn(parentDirectory = os.tmpdir(), fn, cleanUp) {
|
30 | const tempDirectory = await mkdtemp(parentDirectory);
|
31 | if (cleanUp === TempDirCleanUpMode.CLEAN) {
|
32 | return useAndRemoveDirectory(tempDirectory, fn);
|
33 | }
|
34 | else {
|
35 | return fn(tempDirectory);
|
36 | }
|
37 | }
|
38 | exports.withTempDirectoryIn = withTempDirectoryIn;
|
39 | async function withTempDirectory(fn, cleanUp) {
|
40 | return withTempDirectoryIn(undefined, fn, cleanUp);
|
41 | }
|
42 | exports.withTempDirectory = withTempDirectory;
|
43 | function normalizeVersion(version) {
|
44 | if (!version.startsWith('v')) {
|
45 | return `v${version}`;
|
46 | }
|
47 | return version;
|
48 | }
|
49 | exports.normalizeVersion = normalizeVersion;
|
50 |
|
51 |
|
52 |
|
53 | function uname() {
|
54 | return childProcess
|
55 | .execSync('uname -m')
|
56 | .toString()
|
57 | .trim();
|
58 | }
|
59 | exports.uname = uname;
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | function getNodeArch(arch) {
|
65 | if (arch === 'arm') {
|
66 |
|
67 | switch (process.config.variables.arm_version) {
|
68 | case '6':
|
69 | return uname();
|
70 | case '7':
|
71 | default:
|
72 | return 'armv7l';
|
73 | }
|
74 | }
|
75 | return arch;
|
76 | }
|
77 | exports.getNodeArch = getNodeArch;
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | function getHostArch() {
|
85 | return getNodeArch(process.arch);
|
86 | }
|
87 | exports.getHostArch = getHostArch;
|
88 | function ensureIsTruthyString(obj, key) {
|
89 | if (!obj[key] || typeof obj[key] !== 'string') {
|
90 | throw new Error(`Expected property "${String(key)}" to be provided as a string but it was not`);
|
91 | }
|
92 | }
|
93 | exports.ensureIsTruthyString = ensureIsTruthyString;
|
94 | function isOfficialLinuxIA32Download(platform, arch, version, mirrorOptions) {
|
95 | return (platform === 'linux' &&
|
96 | arch === 'ia32' &&
|
97 | Number(version.slice(1).split('.')[0]) >= 4 &&
|
98 | typeof mirrorOptions === 'undefined');
|
99 | }
|
100 | exports.isOfficialLinuxIA32Download = isOfficialLinuxIA32Download;
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | function getEnv(prefix = '') {
|
106 | const envsLowerCase = {};
|
107 | for (const envKey in process.env) {
|
108 | envsLowerCase[envKey.toLowerCase()] = process.env[envKey];
|
109 | }
|
110 | return (name) => {
|
111 | return (envsLowerCase[`${prefix}${name}`.toLowerCase()] ||
|
112 | envsLowerCase[name.toLowerCase()] ||
|
113 | undefined);
|
114 | };
|
115 | }
|
116 | exports.getEnv = getEnv;
|
117 | function setEnv(key, value) {
|
118 |
|
119 |
|
120 | if (value !== void 0) {
|
121 | process.env[key] = value;
|
122 | }
|
123 | }
|
124 | exports.setEnv = setEnv;
|
125 | function effectiveCacheMode(artifactDetails) {
|
126 | if (artifactDetails.force) {
|
127 | if (artifactDetails.cacheMode) {
|
128 | throw new Error('Setting both "force" and "cacheMode" is not supported, please exclusively use "cacheMode"');
|
129 | }
|
130 | return types_1.ElectronDownloadCacheMode.WriteOnly;
|
131 | }
|
132 | return artifactDetails.cacheMode || types_1.ElectronDownloadCacheMode.ReadWrite;
|
133 | }
|
134 | exports.effectiveCacheMode = effectiveCacheMode;
|
135 | function shouldTryReadCache(cacheMode) {
|
136 | return (cacheMode === types_1.ElectronDownloadCacheMode.ReadOnly ||
|
137 | cacheMode === types_1.ElectronDownloadCacheMode.ReadWrite);
|
138 | }
|
139 | exports.shouldTryReadCache = shouldTryReadCache;
|
140 | function shouldWriteCache(cacheMode) {
|
141 | return (cacheMode === types_1.ElectronDownloadCacheMode.WriteOnly ||
|
142 | cacheMode === types_1.ElectronDownloadCacheMode.ReadWrite);
|
143 | }
|
144 | exports.shouldWriteCache = shouldWriteCache;
|
145 | function doesCallerOwnTemporaryOutput(cacheMode) {
|
146 | return (cacheMode === types_1.ElectronDownloadCacheMode.Bypass ||
|
147 | cacheMode === types_1.ElectronDownloadCacheMode.ReadOnly);
|
148 | }
|
149 | exports.doesCallerOwnTemporaryOutput = doesCallerOwnTemporaryOutput;
|
150 |
|
\ | No newline at end of file |