cypress 15.2.0 → 15.3.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 +1 -1
- package/{lib → dist}/cli.js +219 -190
- package/{lib → dist}/cypress.js +29 -26
- package/{lib → dist}/errors.js +38 -26
- package/{lib → dist}/exec/open.js +14 -5
- package/{lib → dist}/exec/run.js +37 -26
- package/dist/exec/spawn.js +301 -0
- package/dist/exec/versions.js +67 -0
- package/{lib → dist}/exec/xvfb.js +47 -20
- package/{index.js → dist/index.js} +5 -5
- package/dist/index.mjs +9 -0
- package/{lib → dist}/tasks/cache.js +49 -52
- package/{lib → dist}/tasks/download.js +55 -64
- package/{lib → dist}/tasks/get-folder-size.js +4 -4
- package/{lib → dist}/tasks/install.js +41 -45
- package/{lib → dist}/tasks/state.js +55 -45
- package/dist/tasks/unzip.js +192 -0
- package/{lib → dist}/tasks/verify.js +121 -131
- package/{lib → dist}/util.js +38 -36
- package/package.json +10 -13
- package/types/cypress-automation.d.ts +2 -1
- package/types/cypress.d.ts +1 -0
- package/index.mjs +0 -17
- package/lib/exec/spawn.js +0 -285
- package/lib/exec/versions.js +0 -61
- package/lib/fs.js +0 -8
- package/lib/tasks/unzip.js +0 -198
- /package/{lib → dist}/VerboseRenderer.js +0 -0
- /package/{lib → dist}/exec/info.js +0 -0
- /package/{lib → dist}/exec/shared.js +0 -0
- /package/{lib → dist}/logger.js +0 -0
@@ -1,4 +1,13 @@
|
|
1
1
|
"use strict";
|
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
|
+
};
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
13
|
};
|
@@ -31,23 +40,35 @@ const xvfbModule = {
|
|
31
40
|
_xvfb: xvfb, // expose for testing
|
32
41
|
_xvfbOptions: xvfbOptions, // expose for testing
|
33
42
|
start() {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
44
|
+
debug('Starting Xvfb');
|
45
|
+
try {
|
46
|
+
yield xvfb.startAsync();
|
47
|
+
return null;
|
48
|
+
}
|
49
|
+
catch (e) {
|
50
|
+
if (e.nonZeroExitCode === true) {
|
51
|
+
const raiseErrorFn = (0, errors_1.throwFormErrorText)(errors_1.errors.nonZeroExitCodeXvfb);
|
52
|
+
yield raiseErrorFn(e);
|
53
|
+
}
|
54
|
+
if (e.known) {
|
55
|
+
throw e;
|
56
|
+
}
|
57
|
+
const raiseErrorFn = (0, errors_1.throwFormErrorText)(errors_1.errors.missingXvfb);
|
58
|
+
yield raiseErrorFn(e);
|
41
59
|
}
|
42
|
-
return (0, errors_1.throwFormErrorText)(errors_1.errors.missingXvfb)(err);
|
43
60
|
});
|
44
61
|
},
|
45
62
|
stop() {
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
63
|
+
return __awaiter(this, void 0, void 0, function* () {
|
64
|
+
debug('Stopping Xvfb');
|
65
|
+
try {
|
66
|
+
yield xvfb.stopAsync();
|
67
|
+
return null;
|
68
|
+
}
|
69
|
+
catch (e) {
|
70
|
+
return null;
|
71
|
+
}
|
51
72
|
});
|
52
73
|
},
|
53
74
|
isNeeded() {
|
@@ -79,13 +100,19 @@ const xvfbModule = {
|
|
79
100
|
},
|
80
101
|
// async method, resolved with Boolean
|
81
102
|
verify() {
|
82
|
-
return
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
104
|
+
try {
|
105
|
+
yield xvfb.startAsync();
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
catch (err) {
|
109
|
+
debug('Could not verify xvfb: %s', err.message);
|
110
|
+
return false;
|
111
|
+
}
|
112
|
+
finally {
|
113
|
+
yield xvfb.stopAsync();
|
114
|
+
}
|
115
|
+
});
|
89
116
|
},
|
90
117
|
};
|
91
118
|
exports.default = xvfbModule;
|
@@ -13,10 +13,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
13
|
};
|
14
14
|
const minimist_1 = __importDefault(require("minimist"));
|
15
15
|
const debug_1 = __importDefault(require("debug"));
|
16
|
-
const util_1 = __importDefault(require("./
|
17
|
-
const cypress_1 = __importDefault(require("./
|
18
|
-
const install_1 = __importDefault(require("./
|
19
|
-
const verify_1 =
|
16
|
+
const util_1 = __importDefault(require("./util"));
|
17
|
+
const cypress_1 = __importDefault(require("./cypress"));
|
18
|
+
const install_1 = __importDefault(require("./tasks/install"));
|
19
|
+
const verify_1 = require("./tasks/verify");
|
20
20
|
const debugCli = (0, debug_1.default)('cypress:cli');
|
21
21
|
const args = (0, minimist_1.default)(process.argv.slice(2));
|
22
22
|
// we're being used from the command line
|
@@ -32,7 +32,7 @@ function handleExec() {
|
|
32
32
|
case 'verify': {
|
33
33
|
// for simple testing in the monorepo
|
34
34
|
debugCli('verifying Cypress');
|
35
|
-
verify_1.
|
35
|
+
(0, verify_1.start)({ force: true }) // always force verification
|
36
36
|
.catch(util_1.default.logErrorExit1);
|
37
37
|
break;
|
38
38
|
}
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
import module from 'module';
|
2
|
+
const require = module.createRequire(import.meta.url);
|
3
|
+
const cypress = require('./cypress');
|
4
|
+
export default cypress;
|
5
|
+
export const defineConfig = cypress.defineConfig;
|
6
|
+
export const defineComponentFramework = cypress.defineComponentFramework;
|
7
|
+
export const run = cypress.run;
|
8
|
+
export const open = cypress.open;
|
9
|
+
export const cli = cypress.cli;
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
const state_1 = __importDefault(require("./state"));
|
16
16
|
const logger_1 = __importDefault(require("../logger"));
|
17
|
-
const
|
17
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
18
18
|
const util_1 = __importDefault(require("../util"));
|
19
19
|
const path_1 = require("path");
|
20
20
|
const cli_table3_1 = __importDefault(require("cli-table3"));
|
@@ -36,19 +36,19 @@ const logCachePath = () => {
|
|
36
36
|
return undefined;
|
37
37
|
};
|
38
38
|
const clear = () => {
|
39
|
-
return
|
39
|
+
return fs_extra_1.default.remove(state_1.default.getCacheDir());
|
40
40
|
};
|
41
41
|
const prune = () => __awaiter(void 0, void 0, void 0, function* () {
|
42
42
|
const cacheDir = state_1.default.getCacheDir();
|
43
43
|
const checkedInBinaryVersion = util_1.default.pkgVersion();
|
44
44
|
let deletedBinary = false;
|
45
45
|
try {
|
46
|
-
const versions = yield
|
46
|
+
const versions = yield fs_extra_1.default.readdir(cacheDir);
|
47
47
|
for (const version of versions) {
|
48
48
|
if (version !== checkedInBinaryVersion) {
|
49
49
|
deletedBinary = true;
|
50
50
|
const versionDir = (0, path_1.join)(cacheDir, version);
|
51
|
-
yield
|
51
|
+
yield fs_extra_1.default.remove(versionDir);
|
52
52
|
}
|
53
53
|
}
|
54
54
|
if (deletedBinary) {
|
@@ -73,70 +73,67 @@ const fileSizeInMB = (size) => {
|
|
73
73
|
* Collects all cached versions, finds when each was used
|
74
74
|
* and prints a table with results to the terminal
|
75
75
|
*/
|
76
|
-
const list = (showSize = false)
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
const list = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (showSize = false) {
|
77
|
+
const binaries = yield getCachedVersions(showSize);
|
78
|
+
const head = [colors.titles('version'), colors.titles('last used')];
|
79
|
+
if (showSize) {
|
80
|
+
head.push(colors.titles('size'));
|
81
|
+
}
|
82
|
+
const table = new cli_table3_1.default({
|
83
|
+
head,
|
84
|
+
});
|
85
|
+
binaries.forEach((binary) => {
|
86
|
+
const versionString = colors.values(binary.version);
|
87
|
+
const lastUsed = binary.accessed ? colors.dates(binary.accessed) : 'unknown';
|
88
|
+
const row = [versionString, lastUsed];
|
80
89
|
if (showSize) {
|
81
|
-
|
90
|
+
const size = colors.size(fileSizeInMB(binary.size));
|
91
|
+
row.push(size);
|
82
92
|
}
|
83
|
-
|
84
|
-
head,
|
85
|
-
});
|
86
|
-
binaries.forEach((binary) => {
|
87
|
-
const versionString = colors.values(binary.version);
|
88
|
-
const lastUsed = binary.accessed ? colors.dates(binary.accessed) : 'unknown';
|
89
|
-
const row = [versionString, lastUsed];
|
90
|
-
if (showSize) {
|
91
|
-
const size = colors.size(fileSizeInMB(binary.size));
|
92
|
-
row.push(size);
|
93
|
-
}
|
94
|
-
return table.push(row);
|
95
|
-
});
|
96
|
-
logger_1.default.always(table.toString());
|
93
|
+
return table.push(row);
|
97
94
|
});
|
98
|
-
|
99
|
-
|
95
|
+
logger_1.default.always(table.toString());
|
96
|
+
});
|
97
|
+
const getCachedVersions = (showSize) => __awaiter(void 0, void 0, void 0, function* () {
|
100
98
|
const cacheDir = state_1.default.getCacheDir();
|
101
|
-
|
102
|
-
|
103
|
-
.filter(util_1.default.isSemver)
|
104
|
-
.map((version) => {
|
99
|
+
const versions = yield fs_extra_1.default.readdir(cacheDir);
|
100
|
+
const filteredVersions = versions.filter(util_1.default.isSemver).map((version) => {
|
105
101
|
return {
|
106
102
|
version,
|
107
103
|
folderPath: (0, path_1.join)(cacheDir, version),
|
108
104
|
};
|
109
|
-
})
|
110
|
-
|
111
|
-
|
112
|
-
// on the Cypress binary
|
105
|
+
});
|
106
|
+
const binaries = [];
|
107
|
+
for (const binary of filteredVersions) {
|
113
108
|
const binaryDir = state_1.default.getBinaryDir(binary.version);
|
114
109
|
const executable = state_1.default.getPathToExecutable(binaryDir);
|
115
|
-
|
110
|
+
try {
|
111
|
+
const stat = yield fs_extra_1.default.stat(executable);
|
116
112
|
const lastAccessedTime = lodash_1.default.get(stat, 'atime');
|
117
|
-
if (
|
118
|
-
|
119
|
-
//
|
120
|
-
|
113
|
+
if (lastAccessedTime) {
|
114
|
+
const accessed = (0, dayjs_1.default)(lastAccessedTime).fromNow();
|
115
|
+
// @ts-expect-error - accessed is not defined in the type
|
116
|
+
binary.accessed = accessed;
|
121
117
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
}
|
118
|
+
// if no lastAccessedTime
|
119
|
+
// the test runner has never been opened
|
120
|
+
// or could be a test simulating missing timestamp
|
121
|
+
}
|
122
|
+
catch (e) {
|
126
123
|
// could not find the binary or gets its stats
|
127
|
-
|
128
|
-
}
|
129
|
-
})
|
130
|
-
.mapSeries((binary) => {
|
124
|
+
// no-op
|
125
|
+
}
|
131
126
|
if (showSize) {
|
132
127
|
const binaryDir = state_1.default.getBinaryDir(binary.version);
|
133
|
-
|
134
|
-
|
135
|
-
});
|
128
|
+
const size = yield (0, get_folder_size_1.default)(binaryDir);
|
129
|
+
binaries.push(Object.assign(Object.assign({}, binary), { size }));
|
136
130
|
}
|
137
|
-
|
138
|
-
|
139
|
-
}
|
131
|
+
else {
|
132
|
+
binaries.push(binary);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return binaries;
|
136
|
+
});
|
140
137
|
const cacheModule = {
|
141
138
|
path: logCachePath,
|
142
139
|
clear,
|
@@ -12,9 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
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
15
|
const os_1 = __importDefault(require("os"));
|
16
|
+
const assert_1 = __importDefault(require("assert"));
|
17
|
+
const lodash_1 = __importDefault(require("lodash"));
|
18
18
|
const url_1 = __importDefault(require("url"));
|
19
19
|
const path_1 = __importDefault(require("path"));
|
20
20
|
const debug_1 = __importDefault(require("debug"));
|
@@ -24,7 +24,7 @@ const request_progress_1 = __importDefault(require("request-progress"));
|
|
24
24
|
const common_tags_1 = require("common-tags");
|
25
25
|
const proxy_from_env_1 = require("proxy-from-env");
|
26
26
|
const errors_1 = require("../errors");
|
27
|
-
const
|
27
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
28
28
|
const util_1 = __importDefault(require("../util"));
|
29
29
|
const debug = (0, debug_1.default)('cypress:cli');
|
30
30
|
const defaultBaseUrl = 'https://download.cypress.io/';
|
@@ -45,25 +45,22 @@ const getBaseUrl = () => {
|
|
45
45
|
}
|
46
46
|
return defaultBaseUrl;
|
47
47
|
};
|
48
|
-
const getCA = () => {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
resolve(cafileContent);
|
54
|
-
})
|
55
|
-
.catch(() => {
|
56
|
-
resolve();
|
57
|
-
});
|
48
|
+
const getCA = () => __awaiter(void 0, void 0, void 0, function* () {
|
49
|
+
if (process.env.npm_config_cafile) {
|
50
|
+
try {
|
51
|
+
const caFileContent = yield fs_extra_1.default.readFile(process.env.npm_config_cafile, 'utf8');
|
52
|
+
return caFileContent;
|
58
53
|
}
|
59
|
-
|
60
|
-
|
54
|
+
catch (error) {
|
55
|
+
debug('error reading ca file', error);
|
56
|
+
return;
|
61
57
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
|
58
|
+
}
|
59
|
+
if (process.env.npm_config_ca) {
|
60
|
+
return process.env.npm_config_ca;
|
61
|
+
}
|
62
|
+
return;
|
63
|
+
});
|
67
64
|
const prepend = (arch, urlPath, version) => {
|
68
65
|
const endpoint = url_1.default.resolve(getBaseUrl(), urlPath);
|
69
66
|
const platform = os_1.default.platform();
|
@@ -82,12 +79,12 @@ const prepend = (arch, urlPath, version) => {
|
|
82
79
|
: `${endpoint}?platform=${platform}&arch=${arch}`;
|
83
80
|
};
|
84
81
|
const getUrl = (arch, version) => {
|
85
|
-
if (
|
82
|
+
if (lodash_1.default.isString(version) && version.match(/^https?:\/\/.*$/)) {
|
86
83
|
debug('version is already an url', version);
|
87
84
|
return version;
|
88
85
|
}
|
89
86
|
const urlPath = version ? `desktop/${version}` : 'desktop';
|
90
|
-
return prepend(arch, urlPath, version);
|
87
|
+
return prepend(arch, urlPath, version || '');
|
91
88
|
};
|
92
89
|
const statusMessage = (err) => {
|
93
90
|
return (err.statusCode
|
@@ -106,7 +103,7 @@ const prettyDownloadErr = (err, url) => {
|
|
106
103
|
* Checks checksum and file size for the given file. Allows both
|
107
104
|
* values or just one of them to be checked.
|
108
105
|
*/
|
109
|
-
const verifyDownloadedFile = (filename, expectedSize, expectedChecksum) => {
|
106
|
+
const verifyDownloadedFile = (filename, expectedSize, expectedChecksum) => __awaiter(void 0, void 0, void 0, function* () {
|
110
107
|
if (expectedSize && expectedChecksum) {
|
111
108
|
debug('verifying checksum and file size');
|
112
109
|
return bluebird_1.default.join(util_1.default.getFileChecksum(filename), util_1.default.getFileSize(filename), (checksum, filesize) => {
|
@@ -130,45 +127,41 @@ const verifyDownloadedFile = (filename, expectedSize, expectedChecksum) => {
|
|
130
127
|
}
|
131
128
|
if (expectedChecksum) {
|
132
129
|
debug('only checking expected file checksum %d', expectedChecksum);
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
Corrupted download
|
130
|
+
const checksum = yield util_1.default.getFileChecksum(filename);
|
131
|
+
if (checksum === expectedChecksum) {
|
132
|
+
debug('downloaded file has the expected checksum ✅');
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
debug('raising error: file checksum mismatch');
|
136
|
+
const text = (0, common_tags_1.stripIndent) `
|
137
|
+
Corrupted download
|
142
138
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
});
|
139
|
+
Expected downloaded file to have checksum: ${expectedChecksum}
|
140
|
+
Computed checksum: ${checksum}
|
141
|
+
`;
|
142
|
+
throw new Error(text);
|
148
143
|
}
|
149
144
|
if (expectedSize) {
|
150
145
|
// maybe we don't have a checksum, but at least CDN returns content length
|
151
146
|
// which we can check against the file size
|
152
147
|
debug('only checking expected file size %d', expectedSize);
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
Corrupted download
|
148
|
+
const filesize = yield util_1.default.getFileSize(filename);
|
149
|
+
if (filesize === expectedSize) {
|
150
|
+
debug('downloaded file has the expected size ✅');
|
151
|
+
return;
|
152
|
+
}
|
153
|
+
debug('raising error: file size mismatch');
|
154
|
+
const text = (0, common_tags_1.stripIndent) `
|
155
|
+
Corrupted download
|
162
156
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
});
|
157
|
+
Expected downloaded file to have size: ${expectedSize}
|
158
|
+
Computed size: ${filesize}
|
159
|
+
`;
|
160
|
+
throw new Error(text);
|
168
161
|
}
|
169
162
|
debug('downloaded file lacks checksum or size to verify');
|
170
|
-
return
|
171
|
-
};
|
163
|
+
return;
|
164
|
+
});
|
172
165
|
// downloads from given url
|
173
166
|
// return an object with
|
174
167
|
// {filename: ..., downloaded: true}
|
@@ -243,7 +236,7 @@ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redi
|
|
243
236
|
// there was a possible race condition between end of request and close of writeStream
|
244
237
|
// that is made ordered with this Promise.all
|
245
238
|
bluebird_1.default.all([new bluebird_1.default((r) => {
|
246
|
-
return response.pipe(
|
239
|
+
return response.pipe(fs_extra_1.default.createWriteStream(downloadDestination).on('close', r));
|
247
240
|
}), new bluebird_1.default((r) => response.on('end', r))])
|
248
241
|
.then(() => {
|
249
242
|
debug('downloading finished');
|
@@ -279,7 +272,7 @@ const downloadFromUrl = ({ url, downloadDestination, progress, ca, version, redi
|
|
279
272
|
const start = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
280
273
|
let { version, downloadDestination, progress, redirectTTL } = opts;
|
281
274
|
if (!downloadDestination) {
|
282
|
-
(
|
275
|
+
assert_1.default.ok(lodash_1.default.isString(downloadDestination) && !lodash_1.default.isEmpty(downloadDestination), 'missing download dir');
|
283
276
|
}
|
284
277
|
if (!progress) {
|
285
278
|
progress = { onProgress: () => {
|
@@ -292,17 +285,15 @@ const start = (opts) => __awaiter(void 0, void 0, void 0, function* () {
|
|
292
285
|
debug('needed Cypress version: %s', version);
|
293
286
|
debug('source url %s', versionUrl);
|
294
287
|
debug(`downloading cypress.zip to "${downloadDestination}"`);
|
295
|
-
|
296
|
-
|
297
|
-
.
|
298
|
-
|
299
|
-
})
|
300
|
-
.then((ca) => {
|
288
|
+
try {
|
289
|
+
// ensure download dir exists
|
290
|
+
yield fs_extra_1.default.ensureDir(path_1.default.dirname(downloadDestination));
|
291
|
+
const ca = yield getCA();
|
301
292
|
return downloadFromUrl(Object.assign({ url: versionUrl, downloadDestination, progress, ca, version }, (redirectTTL ? { redirectTTL } : {})));
|
302
|
-
}
|
303
|
-
|
293
|
+
}
|
294
|
+
catch (err) {
|
304
295
|
return prettyDownloadErr(err, versionUrl);
|
305
|
-
}
|
296
|
+
}
|
306
297
|
});
|
307
298
|
const downloadModule = {
|
308
299
|
start,
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const
|
15
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
16
16
|
const path_1 = require("path");
|
17
17
|
const bluebird_1 = __importDefault(require("bluebird"));
|
18
18
|
/**
|
@@ -26,12 +26,12 @@ const bluebird_1 = __importDefault(require("bluebird"));
|
|
26
26
|
*/
|
27
27
|
function getSize(path) {
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
29
|
-
const stat = yield
|
29
|
+
const stat = yield fs_extra_1.default.lstat(path);
|
30
30
|
if (stat.isDirectory()) {
|
31
|
-
const list = yield
|
31
|
+
const list = yield fs_extra_1.default.readdir(path);
|
32
32
|
return bluebird_1.default.resolve(list).reduce((prev, curr) => __awaiter(this, void 0, void 0, function* () {
|
33
33
|
const currPath = (0, path_1.join)(path, curr);
|
34
|
-
const s = yield
|
34
|
+
const s = yield fs_extra_1.default.lstat(currPath);
|
35
35
|
if (s.isDirectory()) {
|
36
36
|
return prev + (yield getSize(currPath));
|
37
37
|
}
|
@@ -18,10 +18,10 @@ const path_1 = __importDefault(require("path"));
|
|
18
18
|
const chalk_1 = __importDefault(require("chalk"));
|
19
19
|
const debug_1 = __importDefault(require("debug"));
|
20
20
|
const listr2_1 = require("listr2");
|
21
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
22
21
|
const log_symbols_1 = __importDefault(require("log-symbols"));
|
23
22
|
const common_tags_1 = require("common-tags");
|
24
|
-
const
|
23
|
+
const promises_1 = __importDefault(require("timers/promises"));
|
24
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
25
25
|
const download_1 = __importDefault(require("./download"));
|
26
26
|
const util_1 = __importDefault(require("../util"));
|
27
27
|
const state_1 = __importDefault(require("./state"));
|
@@ -90,20 +90,16 @@ const downloadAndUnzip = ({ version, installDir, downloadDir }) => {
|
|
90
90
|
const tasks = new listr2_1.Listr([
|
91
91
|
{
|
92
92
|
options: { title: util_1.default.titleize('Downloading Cypress') },
|
93
|
-
task: (ctx, task) => {
|
93
|
+
task: (ctx, task) => __awaiter(void 0, void 0, void 0, function* () {
|
94
94
|
// as our download progresses indicate the status
|
95
95
|
progress.onProgress = progessify(task, 'Downloading Cypress');
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
// save the download destination for unzipping
|
104
|
-
util_1.default.setTaskTitle(task, util_1.default.titleize(chalk_1.default.green('Downloaded Cypress')), rendererOptions.renderer);
|
105
|
-
});
|
106
|
-
},
|
96
|
+
const redirectVersion = yield download_1.default.start({ version, downloadDestination, progress });
|
97
|
+
if (redirectVersion)
|
98
|
+
version = redirectVersion;
|
99
|
+
debug(`finished downloading file: ${downloadDestination}`);
|
100
|
+
// save the download destination for unzipping
|
101
|
+
util_1.default.setTaskTitle(task, util_1.default.titleize(chalk_1.default.green('Downloaded Cypress')), rendererOptions.renderer);
|
102
|
+
}),
|
107
103
|
},
|
108
104
|
unzipTask({
|
109
105
|
progress,
|
@@ -113,27 +109,24 @@ const downloadAndUnzip = ({ version, installDir, downloadDir }) => {
|
|
113
109
|
}),
|
114
110
|
{
|
115
111
|
options: { title: util_1.default.titleize('Finishing Installation') },
|
116
|
-
task: (ctx, task) => {
|
117
|
-
const cleanup = () => {
|
112
|
+
task: (ctx, task) => __awaiter(void 0, void 0, void 0, function* () {
|
113
|
+
const cleanup = () => __awaiter(void 0, void 0, void 0, function* () {
|
118
114
|
debug('removing zip file %s', downloadDestination);
|
119
|
-
|
120
|
-
};
|
121
|
-
return cleanup()
|
122
|
-
.then(() => {
|
123
|
-
debug('finished installation in', installDir);
|
124
|
-
util_1.default.setTaskTitle(task, util_1.default.titleize(chalk_1.default.green('Finished Installation'), chalk_1.default.gray(installDir)), rendererOptions.renderer);
|
115
|
+
yield fs_extra_1.default.remove(downloadDestination);
|
125
116
|
});
|
126
|
-
|
117
|
+
yield cleanup();
|
118
|
+
debug('finished installation in', installDir);
|
119
|
+
util_1.default.setTaskTitle(task, util_1.default.titleize(chalk_1.default.green('Finished Installation'), chalk_1.default.gray(installDir)), rendererOptions.renderer);
|
120
|
+
}),
|
127
121
|
},
|
128
122
|
], { rendererOptions });
|
129
123
|
// start the tasks!
|
130
|
-
return
|
131
|
-
};
|
132
|
-
const validateOS = () => {
|
133
|
-
return util_1.default.getPlatformInfo().then((platformInfo) => {
|
134
|
-
return platformInfo.match(/(win32-x64|win32-arm64|linux-x64|linux-arm64|darwin-x64|darwin-arm64)/);
|
135
|
-
});
|
124
|
+
return tasks.run();
|
136
125
|
};
|
126
|
+
const validateOS = () => __awaiter(void 0, void 0, void 0, function* () {
|
127
|
+
const platformInfo = yield util_1.default.getPlatformInfo();
|
128
|
+
return platformInfo.match(/(win32-x64|win32-arm64|linux-x64|linux-arm64|darwin-x64|darwin-arm64)/);
|
129
|
+
});
|
137
130
|
/**
|
138
131
|
* Returns the version to install - either a string like `1.2.3` to be fetched
|
139
132
|
* from the download server or a file path or HTTP URL.
|
@@ -202,14 +195,19 @@ const start = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (o
|
|
202
195
|
if (!(yield validateOS())) {
|
203
196
|
return (0, errors_1.throwFormErrorText)(errors_1.errors.invalidOS)();
|
204
197
|
}
|
205
|
-
|
206
|
-
.
|
207
|
-
|
208
|
-
|
198
|
+
try {
|
199
|
+
yield fs_extra_1.default.ensureDir(cacheDir);
|
200
|
+
}
|
201
|
+
catch (err) {
|
202
|
+
if (err.code === 'EACCES') {
|
203
|
+
return (0, errors_1.throwFormErrorText)(errors_1.errors.invalidCacheDirectory)((0, common_tags_1.stripIndent) `
|
204
|
+
Failed to access ${chalk_1.default.cyan(cacheDir)}:
|
209
205
|
|
210
|
-
|
211
|
-
|
212
|
-
|
206
|
+
${err.message}
|
207
|
+
`);
|
208
|
+
}
|
209
|
+
throw err;
|
210
|
+
}
|
213
211
|
const binaryPkg = yield state_1.default.getBinaryPkgAsync(binaryDir);
|
214
212
|
const binaryVersion = yield state_1.default.getBinaryPkgVersion(binaryPkg);
|
215
213
|
const shouldInstall = () => {
|
@@ -251,14 +249,14 @@ const start = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (o
|
|
251
249
|
}
|
252
250
|
const getLocalFilePath = () => __awaiter(void 0, void 0, void 0, function* () {
|
253
251
|
// see if version supplied is a path to a binary
|
254
|
-
if (yield
|
252
|
+
if (yield fs_extra_1.default.pathExists(versionToInstall)) {
|
255
253
|
return path_1.default.extname(versionToInstall) === '.zip' ? versionToInstall : false;
|
256
254
|
}
|
257
255
|
const possibleFile = util_1.default.formAbsolutePath(versionToInstall);
|
258
256
|
debug('checking local file', possibleFile, 'cwd', process.cwd());
|
259
257
|
// if this exists return the path to it
|
260
258
|
// else false
|
261
|
-
if ((yield
|
259
|
+
if ((yield fs_extra_1.default.pathExists(possibleFile)) && path_1.default.extname(possibleFile) === '.zip') {
|
262
260
|
return possibleFile;
|
263
261
|
}
|
264
262
|
return false;
|
@@ -287,20 +285,18 @@ const start = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (o
|
|
287
285
|
const downloadDir = os_1.default.tmpdir();
|
288
286
|
yield downloadAndUnzip({ version: versionToInstall, installDir, downloadDir });
|
289
287
|
// delay 1 sec for UX, unless we are testing
|
290
|
-
yield
|
288
|
+
yield promises_1.default.setTimeout(1000);
|
291
289
|
displayCompletionMsg();
|
292
290
|
});
|
293
291
|
const unzipTask = ({ zipFilePath, installDir, progress, rendererOptions }) => {
|
294
292
|
return {
|
295
293
|
options: { title: util_1.default.titleize('Unzipping Cypress') },
|
296
|
-
task: (ctx, task) => {
|
294
|
+
task: (ctx, task) => __awaiter(void 0, void 0, void 0, function* () {
|
297
295
|
// as our unzip progresses indicate the status
|
298
296
|
progress.onProgress = progessify(task, 'Unzipping Cypress');
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
});
|
303
|
-
},
|
297
|
+
yield unzip_1.default.start({ zipFilePath, installDir, progress });
|
298
|
+
util_1.default.setTaskTitle(task, util_1.default.titleize(chalk_1.default.green('Unzipped Cypress')), rendererOptions.renderer);
|
299
|
+
}),
|
304
300
|
};
|
305
301
|
};
|
306
302
|
const progessify = (task, title) => {
|