cypress 15.1.0 → 15.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cypress +3 -1
- package/index.js +49 -24
- package/lib/VerboseRenderer.js +50 -47
- package/lib/cli.js +455 -351
- package/lib/cypress.js +93 -90
- package/lib/errors.js +181 -194
- package/lib/exec/info.js +85 -74
- package/lib/exec/open.js +77 -73
- package/lib/exec/run.js +144 -154
- package/lib/exec/shared.js +37 -44
- package/lib/exec/spawn.js +270 -232
- package/lib/exec/versions.js +57 -49
- package/lib/exec/xvfb.js +79 -81
- package/lib/fs.js +7 -3
- package/lib/logger.js +37 -32
- package/lib/tasks/cache.js +128 -113
- package/lib/tasks/download.js +247 -258
- package/lib/tasks/get-folder-size.js +33 -22
- package/lib/tasks/install.js +274 -312
- package/lib/tasks/state.js +132 -143
- package/lib/tasks/unzip.js +186 -188
- package/lib/tasks/verify.js +274 -261
- package/lib/util.js +357 -355
- package/package.json +3 -3
package/lib/tasks/download.js
CHANGED
@@ -1,99 +1,121 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
const
|
16
|
-
const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
const
|
21
|
-
const
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
const lazy_ass_1 = __importDefault(require("lazy-ass"));
|
16
|
+
const check_more_types_1 = __importDefault(require("check-more-types"));
|
17
|
+
const os_1 = __importDefault(require("os"));
|
18
|
+
const url_1 = __importDefault(require("url"));
|
19
|
+
const path_1 = __importDefault(require("path"));
|
20
|
+
const debug_1 = __importDefault(require("debug"));
|
21
|
+
const request_1 = __importDefault(require("@cypress/request"));
|
22
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
23
|
+
const request_progress_1 = __importDefault(require("request-progress"));
|
24
|
+
const common_tags_1 = require("common-tags");
|
25
|
+
const proxy_from_env_1 = require("proxy-from-env");
|
26
|
+
const errors_1 = require("../errors");
|
27
|
+
const fs_1 = __importDefault(require("../fs"));
|
28
|
+
const util_1 = __importDefault(require("../util"));
|
29
|
+
const debug = (0, debug_1.default)('cypress:cli');
|
22
30
|
const defaultBaseUrl = 'https://download.cypress.io/';
|
23
31
|
const defaultMaxRedirects = 10;
|
24
|
-
const getProxyForUrlWithNpmConfig = url => {
|
25
|
-
|
32
|
+
const getProxyForUrlWithNpmConfig = (url) => {
|
33
|
+
return (0, proxy_from_env_1.getProxyForUrl)(url) ||
|
34
|
+
process.env.npm_config_https_proxy ||
|
35
|
+
process.env.npm_config_proxy ||
|
36
|
+
null;
|
26
37
|
};
|
27
38
|
const getBaseUrl = () => {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
39
|
+
if (util_1.default.getEnv('CYPRESS_DOWNLOAD_MIRROR')) {
|
40
|
+
let baseUrl = util_1.default.getEnv('CYPRESS_DOWNLOAD_MIRROR');
|
41
|
+
if (!(baseUrl === null || baseUrl === void 0 ? void 0 : baseUrl.endsWith('/'))) {
|
42
|
+
baseUrl += '/';
|
43
|
+
}
|
44
|
+
return baseUrl || defaultBaseUrl;
|
32
45
|
}
|
33
|
-
return
|
34
|
-
}
|
35
|
-
return defaultBaseUrl;
|
46
|
+
return defaultBaseUrl;
|
36
47
|
};
|
37
48
|
const getCA = () => {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
return new bluebird_1.default((resolve) => {
|
50
|
+
if (process.env.npm_config_cafile) {
|
51
|
+
fs_1.default.readFile(process.env.npm_config_cafile, 'utf8')
|
52
|
+
.then((cafileContent) => {
|
53
|
+
resolve(cafileContent);
|
54
|
+
})
|
55
|
+
.catch(() => {
|
56
|
+
resolve();
|
57
|
+
});
|
58
|
+
}
|
59
|
+
else if (process.env.npm_config_ca) {
|
60
|
+
resolve(process.env.npm_config_ca);
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
resolve();
|
64
|
+
}
|
65
|
+
});
|
51
66
|
};
|
52
67
|
const prepend = (arch, urlPath, version) => {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
68
|
+
const endpoint = url_1.default.resolve(getBaseUrl(), urlPath);
|
69
|
+
const platform = os_1.default.platform();
|
70
|
+
const pathTemplate = util_1.default.getEnv('CYPRESS_DOWNLOAD_PATH_TEMPLATE', true);
|
71
|
+
if ((platform === 'win32') && (arch === 'arm64')) {
|
72
|
+
debug(`detected platform ${platform} architecture ${arch} combination`);
|
73
|
+
arch = 'x64';
|
74
|
+
debug(`overriding to download ${platform}-${arch} instead`);
|
75
|
+
}
|
76
|
+
return pathTemplate
|
77
|
+
? (pathTemplate
|
78
|
+
.replace(/\\?\$\{endpoint\}/g, endpoint)
|
79
|
+
.replace(/\\?\$\{platform\}/g, platform)
|
80
|
+
.replace(/\\?\$\{arch\}/g, arch)
|
81
|
+
.replace(/\\?\$\{version\}/g, version))
|
82
|
+
: `${endpoint}?platform=${platform}&arch=${arch}`;
|
62
83
|
};
|
63
84
|
const getUrl = (arch, version) => {
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
85
|
+
if (check_more_types_1.default.webUrl(version)) {
|
86
|
+
debug('version is already an url', version);
|
87
|
+
return version;
|
88
|
+
}
|
89
|
+
const urlPath = version ? `desktop/${version}` : 'desktop';
|
90
|
+
return prepend(arch, urlPath, version);
|
70
91
|
};
|
71
|
-
const statusMessage = err => {
|
72
|
-
|
92
|
+
const statusMessage = (err) => {
|
93
|
+
return (err.statusCode
|
94
|
+
? [err.statusCode, err.statusMessage].join(' - ')
|
95
|
+
: err.toString());
|
73
96
|
};
|
74
97
|
const prettyDownloadErr = (err, url) => {
|
75
|
-
|
98
|
+
const msg = (0, common_tags_1.stripIndent) `
|
76
99
|
URL: ${url}
|
77
100
|
${statusMessage(err)}
|
78
101
|
`;
|
79
|
-
|
80
|
-
|
102
|
+
debug(msg);
|
103
|
+
return (0, errors_1.throwFormErrorText)(errors_1.errors.failedDownload)(msg);
|
81
104
|
};
|
82
|
-
|
83
105
|
/**
|
84
106
|
* Checks checksum and file size for the given file. Allows both
|
85
107
|
* values or just one of them to be checked.
|
86
108
|
*/
|
87
109
|
const verifyDownloadedFile = (filename, expectedSize, expectedChecksum) => {
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
110
|
+
if (expectedSize && expectedChecksum) {
|
111
|
+
debug('verifying checksum and file size');
|
112
|
+
return bluebird_1.default.join(util_1.default.getFileChecksum(filename), util_1.default.getFileSize(filename), (checksum, filesize) => {
|
113
|
+
if (checksum === expectedChecksum && filesize === expectedSize) {
|
114
|
+
debug('downloaded file has the expected checksum and size ✅');
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
debug('raising error: checksum or file size mismatch');
|
118
|
+
const text = (0, common_tags_1.stripIndent) `
|
97
119
|
Corrupted download
|
98
120
|
|
99
121
|
Expected downloaded file to have checksum: ${expectedChecksum}
|
@@ -102,223 +124,190 @@ const verifyDownloadedFile = (filename, expectedSize, expectedChecksum) => {
|
|
102
124
|
Expected downloaded file to have size: ${expectedSize}
|
103
125
|
Computed size: ${filesize}
|
104
126
|
`;
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
127
|
+
debug(text);
|
128
|
+
throw new Error(text);
|
129
|
+
});
|
130
|
+
}
|
131
|
+
if (expectedChecksum) {
|
132
|
+
debug('only checking expected file checksum %d', expectedChecksum);
|
133
|
+
return util_1.default.getFileChecksum(filename)
|
134
|
+
.then((checksum) => {
|
135
|
+
if (checksum === expectedChecksum) {
|
136
|
+
debug('downloaded file has the expected checksum ✅');
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
debug('raising error: file checksum mismatch');
|
140
|
+
const text = (0, common_tags_1.stripIndent) `
|
118
141
|
Corrupted download
|
119
142
|
|
120
143
|
Expected downloaded file to have checksum: ${expectedChecksum}
|
121
144
|
Computed checksum: ${checksum}
|
122
145
|
`;
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
146
|
+
throw new Error(text);
|
147
|
+
});
|
148
|
+
}
|
149
|
+
if (expectedSize) {
|
150
|
+
// maybe we don't have a checksum, but at least CDN returns content length
|
151
|
+
// which we can check against the file size
|
152
|
+
debug('only checking expected file size %d', expectedSize);
|
153
|
+
return util_1.default.getFileSize(filename)
|
154
|
+
.then((filesize) => {
|
155
|
+
if (filesize === expectedSize) {
|
156
|
+
debug('downloaded file has the expected size ✅');
|
157
|
+
return;
|
158
|
+
}
|
159
|
+
debug('raising error: file size mismatch');
|
160
|
+
const text = (0, common_tags_1.stripIndent) `
|
137
161
|
Corrupted download
|
138
162
|
|
139
163
|
Expected downloaded file to have size: ${expectedSize}
|
140
164
|
Computed size: ${filesize}
|
141
165
|
`;
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
166
|
+
throw new Error(text);
|
167
|
+
});
|
168
|
+
}
|
169
|
+
debug('downloaded file lacks checksum or size to verify');
|
170
|
+
return bluebird_1.default.resolve();
|
147
171
|
};
|
148
|
-
|
149
172
|
// downloads from given url
|
150
173
|
// return an object with
|
151
174
|
// {filename: ..., downloaded: true}
|
152
|
-
const downloadFromUrl = ({
|
153
|
-
|
154
|
-
|
155
|
-
progress,
|
156
|
-
ca,
|
157
|
-
version,
|
158
|
-
redirectTTL = defaultMaxRedirects
|
159
|
-
}) => {
|
160
|
-
if (redirectTTL <= 0) {
|
161
|
-
return Promise.reject(new Error(stripIndent`
|
175
|
+
const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redirectTTL = defaultMaxRedirects }) => {
|
176
|
+
if (redirectTTL <= 0) {
|
177
|
+
return bluebird_1.default.reject(new Error((0, common_tags_1.stripIndent) `
|
162
178
|
Failed downloading the Cypress binary.
|
163
179
|
There were too many redirects. The default allowance is ${defaultMaxRedirects}.
|
164
180
|
Maybe you got stuck in a redirect loop?
|
165
181
|
`));
|
166
|
-
}
|
167
|
-
return new Promise((resolve, reject) => {
|
168
|
-
const proxy = getProxyForUrlWithNpmConfig(url);
|
169
|
-
debug('Downloading package', {
|
170
|
-
url,
|
171
|
-
proxy,
|
172
|
-
downloadDestination
|
173
|
-
});
|
174
|
-
if (ca) {
|
175
|
-
debug('using custom CA details from npm config');
|
176
182
|
}
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
183
|
+
return new bluebird_1.default((resolve, reject) => {
|
184
|
+
const proxy = getProxyForUrlWithNpmConfig(url);
|
185
|
+
debug('Downloading package', {
|
186
|
+
url,
|
187
|
+
proxy,
|
188
|
+
downloadDestination,
|
189
|
+
});
|
190
|
+
if (ca) {
|
191
|
+
debug('using custom CA details from npm config');
|
185
192
|
}
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
downloadDestination,
|
227
|
-
version: redirectVersion,
|
228
|
-
redirectTTL: redirectTTL - 1
|
229
|
-
}).then(resolve).catch(reject);
|
230
|
-
|
231
|
-
// if our status code does not start with 200
|
232
|
-
} else if (!/^2/.test(response.statusCode)) {
|
233
|
-
debug('response code %d', response.statusCode);
|
234
|
-
const err = new Error(stripIndent`
|
193
|
+
const reqOptions = Object.assign(Object.assign(Object.assign({ uri: url }, (proxy ? { proxy } : {})), (ca ? { agentOptions: { ca } } : {})), { method: 'GET', followRedirect: false });
|
194
|
+
const req = (0, request_1.default)(reqOptions);
|
195
|
+
// closure
|
196
|
+
let started = null;
|
197
|
+
let expectedSize;
|
198
|
+
let expectedChecksum;
|
199
|
+
(0, request_progress_1.default)(req, {
|
200
|
+
throttle: progress.throttle,
|
201
|
+
})
|
202
|
+
.on('response', (response) => {
|
203
|
+
// we have computed checksum and filesize during test runner binary build
|
204
|
+
// and have set it on the S3 object as user meta data, available via
|
205
|
+
// these custom headers "x-amz-meta-..."
|
206
|
+
// see https://github.com/cypress-io/cypress/pull/4092
|
207
|
+
expectedSize = response.headers['x-amz-meta-size'] ||
|
208
|
+
response.headers['content-length'];
|
209
|
+
expectedChecksum = response.headers['x-amz-meta-checksum'];
|
210
|
+
if (expectedChecksum) {
|
211
|
+
debug('expected checksum %s', expectedChecksum);
|
212
|
+
}
|
213
|
+
if (expectedSize) {
|
214
|
+
// convert from string (all Amazon custom headers are strings)
|
215
|
+
expectedSize = Number(expectedSize);
|
216
|
+
debug('expected file size %d', expectedSize);
|
217
|
+
}
|
218
|
+
// start counting now once we've gotten
|
219
|
+
// response headers
|
220
|
+
started = new Date();
|
221
|
+
if (/^3/.test(response.statusCode)) {
|
222
|
+
const redirectVersion = response.headers['x-version'];
|
223
|
+
const redirectUrl = response.headers.location;
|
224
|
+
debug('redirect version:', redirectVersion);
|
225
|
+
debug('redirect url:', redirectUrl);
|
226
|
+
downloadFromUrl({ url: redirectUrl, progress, ca, downloadDestination, version: redirectVersion, redirectTTL: redirectTTL - 1 })
|
227
|
+
.then(resolve).catch(reject);
|
228
|
+
// if our status code does not start with 200
|
229
|
+
}
|
230
|
+
else if (!/^2/.test(response.statusCode)) {
|
231
|
+
debug('response code %d', response.statusCode);
|
232
|
+
const err = new Error((0, common_tags_1.stripIndent) `
|
235
233
|
Failed downloading the Cypress binary.
|
236
234
|
Response code: ${response.statusCode}
|
237
235
|
Response message: ${response.statusMessage}
|
238
236
|
`);
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
237
|
+
reject(err);
|
238
|
+
// status codes here are all 2xx
|
239
|
+
}
|
240
|
+
else {
|
241
|
+
// We only enable this pipe connection when we know we've got a successful return
|
242
|
+
// and handle the completion with verify and resolve
|
243
|
+
// there was a possible race condition between end of request and close of writeStream
|
244
|
+
// that is made ordered with this Promise.all
|
245
|
+
bluebird_1.default.all([new bluebird_1.default((r) => {
|
246
|
+
return response.pipe(fs_1.default.createWriteStream(downloadDestination).on('close', r));
|
247
|
+
}), new bluebird_1.default((r) => response.on('end', r))])
|
248
|
+
.then(() => {
|
249
|
+
debug('downloading finished');
|
250
|
+
verifyDownloadedFile(downloadDestination, expectedSize, expectedChecksum)
|
251
|
+
.then(() => debug('verified'))
|
252
|
+
.then(() => resolve(version))
|
253
|
+
.catch(reject);
|
254
|
+
});
|
255
|
+
}
|
256
|
+
})
|
257
|
+
.on('error', (e) => {
|
258
|
+
if (e.code === 'ECONNRESET')
|
259
|
+
return; // sometimes proxies give ECONNRESET but we don't care
|
260
|
+
reject(e);
|
261
|
+
})
|
262
|
+
.on('progress', (state) => {
|
263
|
+
// total time we've elapsed
|
264
|
+
// starting on our first progress notification
|
265
|
+
const elapsed = +new Date() - +started;
|
266
|
+
// request-progress sends a value between 0 and 1
|
267
|
+
const percentage = util_1.default.convertPercentToPercentage(state.percent);
|
268
|
+
const eta = util_1.default.calculateEta(percentage, elapsed);
|
269
|
+
// send up our percent and seconds remaining
|
270
|
+
progress.onProgress(percentage, util_1.default.secsRemaining(eta));
|
251
271
|
});
|
252
|
-
}
|
253
|
-
}).on('error', e => {
|
254
|
-
if (e.code === 'ECONNRESET') return; // sometimes proxies give ECONNRESET but we don't care
|
255
|
-
|
256
|
-
reject(e);
|
257
|
-
}).on('progress', state => {
|
258
|
-
// total time we've elapsed
|
259
|
-
// starting on our first progress notification
|
260
|
-
const elapsed = new Date() - started;
|
261
|
-
|
262
|
-
// request-progress sends a value between 0 and 1
|
263
|
-
const percentage = util.convertPercentToPercentage(state.percent);
|
264
|
-
const eta = util.calculateEta(percentage, elapsed);
|
265
|
-
|
266
|
-
// send up our percent and seconds remaining
|
267
|
-
progress.onProgress(percentage, util.secsRemaining(eta));
|
268
272
|
});
|
269
|
-
});
|
270
273
|
};
|
271
|
-
|
272
274
|
/**
|
273
275
|
* Download Cypress.zip from external versionUrl to local file.
|
274
276
|
* @param [string] version Could be "3.3.0" or full URL
|
275
277
|
* @param [string] downloadDestination Local filename to save as
|
276
278
|
*/
|
277
|
-
const start =
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
};
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
return getCA();
|
304
|
-
}).then(ca => {
|
305
|
-
return downloadFromUrl({
|
306
|
-
url: versionUrl,
|
307
|
-
downloadDestination,
|
308
|
-
progress,
|
309
|
-
ca,
|
310
|
-
version,
|
311
|
-
...(redirectTTL ? {
|
312
|
-
redirectTTL
|
313
|
-
} : {})
|
279
|
+
const start = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
280
|
+
let { version, downloadDestination, progress, redirectTTL } = opts;
|
281
|
+
if (!downloadDestination) {
|
282
|
+
(0, lazy_ass_1.default)(check_more_types_1.default.unemptyString(downloadDestination), 'missing download dir', opts);
|
283
|
+
}
|
284
|
+
if (!progress) {
|
285
|
+
progress = { onProgress: () => {
|
286
|
+
return {};
|
287
|
+
} };
|
288
|
+
}
|
289
|
+
const arch = yield util_1.default.getRealArch();
|
290
|
+
const versionUrl = getUrl(arch, version);
|
291
|
+
progress.throttle = 100;
|
292
|
+
debug('needed Cypress version: %s', version);
|
293
|
+
debug('source url %s', versionUrl);
|
294
|
+
debug(`downloading cypress.zip to "${downloadDestination}"`);
|
295
|
+
// ensure download dir exists
|
296
|
+
return fs_1.default.ensureDirAsync(path_1.default.dirname(downloadDestination))
|
297
|
+
.then(() => {
|
298
|
+
return getCA();
|
299
|
+
})
|
300
|
+
.then((ca) => {
|
301
|
+
return downloadFromUrl(Object.assign({ url: versionUrl, downloadDestination, progress, ca, version }, (redirectTTL ? { redirectTTL } : {})));
|
302
|
+
})
|
303
|
+
.catch((err) => {
|
304
|
+
return prettyDownloadErr(err, versionUrl);
|
314
305
|
});
|
315
|
-
|
316
|
-
|
317
|
-
|
306
|
+
});
|
307
|
+
const downloadModule = {
|
308
|
+
start,
|
309
|
+
getUrl,
|
310
|
+
getProxyForUrlWithNpmConfig,
|
311
|
+
getCA,
|
318
312
|
};
|
319
|
-
|
320
|
-
start,
|
321
|
-
getUrl,
|
322
|
-
getProxyForUrlWithNpmConfig,
|
323
|
-
getCA
|
324
|
-
};
|
313
|
+
exports.default = downloadModule;
|
@@ -1,11 +1,20 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
}
|
7
|
-
|
8
|
-
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
const fs_1 = __importDefault(require("../fs"));
|
16
|
+
const path_1 = require("path");
|
17
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
9
18
|
/**
|
10
19
|
* Get the size of a folder or a file.
|
11
20
|
*
|
@@ -15,19 +24,21 @@ const Bluebird = require('bluebird');
|
|
15
24
|
*
|
16
25
|
* @param {string} path path to the file or the folder.
|
17
26
|
*/
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
function getSize(path) {
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
29
|
+
const stat = yield fs_1.default.lstat(path);
|
30
|
+
if (stat.isDirectory()) {
|
31
|
+
const list = yield fs_1.default.readdir(path);
|
32
|
+
return bluebird_1.default.resolve(list).reduce((prev, curr) => __awaiter(this, void 0, void 0, function* () {
|
33
|
+
const currPath = (0, path_1.join)(path, curr);
|
34
|
+
const s = yield fs_1.default.lstat(currPath);
|
35
|
+
if (s.isDirectory()) {
|
36
|
+
return prev + (yield getSize(currPath));
|
37
|
+
}
|
38
|
+
return prev + s.size;
|
39
|
+
}), 0);
|
40
|
+
}
|
41
|
+
return stat.size;
|
42
|
+
});
|
32
43
|
}
|
33
|
-
|
44
|
+
exports.default = getSize;
|