cypress 15.0.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.
@@ -1,99 +1,121 @@
1
1
  "use strict";
2
-
3
- const la = require('lazy-ass');
4
- const is = require('check-more-types');
5
- const os = require('os');
6
- const url = require('url');
7
- const path = require('path');
8
- const debug = require('debug')('cypress:cli');
9
- const request = require('@cypress/request');
10
- const Promise = require('bluebird');
11
- const requestProgress = require('request-progress');
12
- const {
13
- stripIndent
14
- } = require('common-tags');
15
- const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
16
- const {
17
- throwFormErrorText,
18
- errors
19
- } = require('../errors');
20
- const fs = require('../fs');
21
- const util = require('../util');
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
- return getProxyForUrl(url) || process.env.npm_config_https_proxy || process.env.npm_config_proxy || null;
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
- if (util.getEnv('CYPRESS_DOWNLOAD_MIRROR')) {
29
- let baseUrl = util.getEnv('CYPRESS_DOWNLOAD_MIRROR');
30
- if (!baseUrl.endsWith('/')) {
31
- baseUrl += '/';
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 baseUrl;
34
- }
35
- return defaultBaseUrl;
46
+ return defaultBaseUrl;
36
47
  };
37
48
  const getCA = () => {
38
- return new Promise(resolve => {
39
- if (process.env.npm_config_cafile) {
40
- fs.readFile(process.env.npm_config_cafile, 'utf8').then(cafileContent => {
41
- resolve(cafileContent);
42
- }).catch(() => {
43
- resolve();
44
- });
45
- } else if (process.env.npm_config_ca) {
46
- resolve(process.env.npm_config_ca);
47
- } else {
48
- resolve();
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
- const endpoint = url.resolve(getBaseUrl(), urlPath);
54
- const platform = os.platform();
55
- const pathTemplate = util.getEnv('CYPRESS_DOWNLOAD_PATH_TEMPLATE', true);
56
- if (platform === 'win32' && arch === 'arm64') {
57
- debug(`detected platform ${platform} architecture ${arch} combination`);
58
- arch = 'x64';
59
- debug(`overriding to download ${platform}-${arch} instead`);
60
- }
61
- return pathTemplate ? pathTemplate.replace(/\\?\$\{endpoint\}/g, endpoint).replace(/\\?\$\{platform\}/g, platform).replace(/\\?\$\{arch\}/g, arch).replace(/\\?\$\{version\}/g, version) : `${endpoint}?platform=${platform}&arch=${arch}`;
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
- if (is.url(version)) {
65
- debug('version is already an url', version);
66
- return version;
67
- }
68
- const urlPath = version ? `desktop/${version}` : 'desktop';
69
- return prepend(arch, urlPath, version);
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
- return err.statusCode ? [err.statusCode, err.statusMessage].join(' - ') : err.toString();
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
- const msg = stripIndent`
98
+ const msg = (0, common_tags_1.stripIndent) `
76
99
  URL: ${url}
77
100
  ${statusMessage(err)}
78
101
  `;
79
- debug(msg);
80
- return throwFormErrorText(errors.failedDownload)(msg);
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
- if (expectedSize && expectedChecksum) {
89
- debug('verifying checksum and file size');
90
- return Promise.join(util.getFileChecksum(filename), util.getFileSize(filename), (checksum, filesize) => {
91
- if (checksum === expectedChecksum && filesize === expectedSize) {
92
- debug('downloaded file has the expected checksum and size ✅');
93
- return;
94
- }
95
- debug('raising error: checksum or file size mismatch');
96
- const text = stripIndent`
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
- debug(text);
106
- throw new Error(text);
107
- });
108
- }
109
- if (expectedChecksum) {
110
- debug('only checking expected file checksum %d', expectedChecksum);
111
- return util.getFileChecksum(filename).then(checksum => {
112
- if (checksum === expectedChecksum) {
113
- debug('downloaded file has the expected checksum ✅');
114
- return;
115
- }
116
- debug('raising error: file checksum mismatch');
117
- const text = stripIndent`
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
- throw new Error(text);
124
- });
125
- }
126
- if (expectedSize) {
127
- // maybe we don't have a checksum, but at least CDN returns content length
128
- // which we can check against the file size
129
- debug('only checking expected file size %d', expectedSize);
130
- return util.getFileSize(filename).then(filesize => {
131
- if (filesize === expectedSize) {
132
- debug('downloaded file has the expected size ✅');
133
- return;
134
- }
135
- debug('raising error: file size mismatch');
136
- const text = stripIndent`
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
- throw new Error(text);
143
- });
144
- }
145
- debug('downloaded file lacks checksum or size to verify');
146
- return Promise.resolve();
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
- url,
154
- downloadDestination,
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
- const reqOptions = {
178
- uri: url,
179
- ...(proxy ? {
180
- proxy
181
- } : {}),
182
- ...(ca ? {
183
- agentOptions: {
184
- ca
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
- method: 'GET',
188
- followRedirect: false
189
- };
190
- const req = request(reqOptions);
191
-
192
- // closure
193
- let started = null;
194
- let expectedSize;
195
- let expectedChecksum;
196
- requestProgress(req, {
197
- throttle: progress.throttle
198
- }).on('response', response => {
199
- // we have computed checksum and filesize during test runner binary build
200
- // and have set it on the S3 object as user meta data, available via
201
- // these custom headers "x-amz-meta-..."
202
- // see https://github.com/cypress-io/cypress/pull/4092
203
- expectedSize = response.headers['x-amz-meta-size'] || response.headers['content-length'];
204
- expectedChecksum = response.headers['x-amz-meta-checksum'];
205
- if (expectedChecksum) {
206
- debug('expected checksum %s', expectedChecksum);
207
- }
208
- if (expectedSize) {
209
- // convert from string (all Amazon custom headers are strings)
210
- expectedSize = Number(expectedSize);
211
- debug('expected file size %d', expectedSize);
212
- }
213
-
214
- // start counting now once we've gotten
215
- // response headers
216
- started = new Date();
217
- if (/^3/.test(response.statusCode)) {
218
- const redirectVersion = response.headers['x-version'];
219
- const redirectUrl = response.headers.location;
220
- debug('redirect version:', redirectVersion);
221
- debug('redirect url:', redirectUrl);
222
- downloadFromUrl({
223
- url: redirectUrl,
224
- progress,
225
- ca,
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
- reject(err);
240
- // status codes here are all 2xx
241
- } else {
242
- // We only enable this pipe connection when we know we've got a successful return
243
- // and handle the completion with verify and resolve
244
- // there was a possible race condition between end of request and close of writeStream
245
- // that is made ordered with this Promise.all
246
- Promise.all([new Promise(r => {
247
- return response.pipe(fs.createWriteStream(downloadDestination).on('close', r));
248
- }), new Promise(r => response.on('end', r))]).then(() => {
249
- debug('downloading finished');
250
- verifyDownloadedFile(downloadDestination, expectedSize, expectedChecksum).then(() => debug('verified')).then(() => resolve(version)).catch(reject);
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 = async opts => {
278
- let {
279
- version,
280
- downloadDestination,
281
- progress,
282
- redirectTTL
283
- } = opts;
284
- if (!downloadDestination) {
285
- la(is.unemptyString(downloadDestination), 'missing download dir', opts);
286
- }
287
- if (!progress) {
288
- progress = {
289
- onProgress: () => {
290
- return {};
291
- }
292
- };
293
- }
294
- const arch = await util.getRealArch();
295
- const versionUrl = getUrl(arch, version);
296
- progress.throttle = 100;
297
- debug('needed Cypress version: %s', version);
298
- debug('source url %s', versionUrl);
299
- debug(`downloading cypress.zip to "${downloadDestination}"`);
300
-
301
- // ensure download dir exists
302
- return fs.ensureDirAsync(path.dirname(downloadDestination)).then(() => {
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
- }).catch(err => {
316
- return prettyDownloadErr(err, versionUrl);
317
- });
306
+ });
307
+ const downloadModule = {
308
+ start,
309
+ getUrl,
310
+ getProxyForUrlWithNpmConfig,
311
+ getCA,
318
312
  };
319
- module.exports = {
320
- start,
321
- getUrl,
322
- getProxyForUrlWithNpmConfig,
323
- getCA
324
- };
313
+ exports.default = downloadModule;
@@ -1,11 +1,20 @@
1
1
  "use strict";
2
-
3
- const fs = require('../fs');
4
- const {
5
- join
6
- } = require('path');
7
- const Bluebird = require('bluebird');
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
- async function getSize(path) {
19
- const stat = await fs.lstat(path);
20
- if (stat.isDirectory()) {
21
- const list = await fs.readdir(path);
22
- return Bluebird.resolve(list).reduce(async (prev, curr) => {
23
- const currPath = join(path, curr);
24
- const s = await fs.lstat(currPath);
25
- if (s.isDirectory()) {
26
- return prev + (await getSize(currPath));
27
- }
28
- return prev + s.size;
29
- }, 0);
30
- }
31
- return stat.size;
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
- module.exports = getSize;
44
+ exports.default = getSize;