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
package/index.mjs
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
import module from 'module'
|
2
|
-
|
3
|
-
const require = module.createRequire(import.meta.url)
|
4
|
-
|
5
|
-
const cypress = require('./lib/cypress')
|
6
|
-
|
7
|
-
export default cypress
|
8
|
-
|
9
|
-
export const defineConfig = cypress.defineConfig
|
10
|
-
|
11
|
-
export const defineComponentFramework = cypress.defineComponentFramework
|
12
|
-
|
13
|
-
export const run = cypress.run
|
14
|
-
|
15
|
-
export const open = cypress.open
|
16
|
-
|
17
|
-
export const cli = cypress.cli
|
package/lib/exec/spawn.js
DELETED
@@ -1,285 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
19
|
-
var ownKeys = function(o) {
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
21
|
-
var ar = [];
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
23
|
-
return ar;
|
24
|
-
};
|
25
|
-
return ownKeys(o);
|
26
|
-
};
|
27
|
-
return function (mod) {
|
28
|
-
if (mod && mod.__esModule) return mod;
|
29
|
-
var result = {};
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
31
|
-
__setModuleDefault(result, mod);
|
32
|
-
return result;
|
33
|
-
};
|
34
|
-
})();
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
42
|
-
});
|
43
|
-
};
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
46
|
-
};
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
48
|
-
const lodash_1 = __importDefault(require("lodash"));
|
49
|
-
const os_1 = __importDefault(require("os"));
|
50
|
-
const child_process_1 = __importDefault(require("child_process"));
|
51
|
-
const path_1 = __importDefault(require("path"));
|
52
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
53
|
-
const debug_1 = __importDefault(require("debug"));
|
54
|
-
const util_1 = __importDefault(require("../util"));
|
55
|
-
const state_1 = __importDefault(require("../tasks/state"));
|
56
|
-
const xvfb_1 = __importDefault(require("./xvfb"));
|
57
|
-
const verify_1 = __importDefault(require("../tasks/verify"));
|
58
|
-
const errors_1 = require("../errors");
|
59
|
-
const readline_1 = __importDefault(require("readline"));
|
60
|
-
const debug = (0, debug_1.default)('cypress:cli');
|
61
|
-
function isPlatform(platform) {
|
62
|
-
return os_1.default.platform() === platform;
|
63
|
-
}
|
64
|
-
function needsStderrPiped(needsXvfb) {
|
65
|
-
return lodash_1.default.some([
|
66
|
-
isPlatform('darwin'),
|
67
|
-
(needsXvfb && isPlatform('linux')),
|
68
|
-
util_1.default.isPossibleLinuxWithIncorrectDisplay(),
|
69
|
-
]);
|
70
|
-
}
|
71
|
-
function needsEverythingPipedDirectly() {
|
72
|
-
return isPlatform('win32');
|
73
|
-
}
|
74
|
-
function getStdio(needsXvfb) {
|
75
|
-
if (needsEverythingPipedDirectly()) {
|
76
|
-
return 'pipe';
|
77
|
-
}
|
78
|
-
// https://github.com/cypress-io/cypress/issues/921
|
79
|
-
// https://github.com/cypress-io/cypress/issues/1143
|
80
|
-
// https://github.com/cypress-io/cypress/issues/1745
|
81
|
-
if (needsStderrPiped(needsXvfb)) {
|
82
|
-
// returning pipe here so we can massage stderr
|
83
|
-
// and remove garbage from Xlib and libuv
|
84
|
-
// due to starting the Xvfb process on linux
|
85
|
-
return ['inherit', 'inherit', 'pipe'];
|
86
|
-
}
|
87
|
-
return 'inherit';
|
88
|
-
}
|
89
|
-
const spawnModule = {
|
90
|
-
start(args, options = {}) {
|
91
|
-
const needsXvfb = xvfb_1.default.isNeeded();
|
92
|
-
let executable = state_1.default.getPathToExecutable(state_1.default.getBinaryDir());
|
93
|
-
if (util_1.default.getEnv('CYPRESS_RUN_BINARY')) {
|
94
|
-
executable = path_1.default.resolve(util_1.default.getEnv('CYPRESS_RUN_BINARY'));
|
95
|
-
}
|
96
|
-
debug('needs to start own Xvfb?', needsXvfb);
|
97
|
-
// Always push cwd into the args
|
98
|
-
// which additionally acts as a signal to the
|
99
|
-
// binary that it was invoked through the NPM module
|
100
|
-
args = args || [];
|
101
|
-
if (typeof args === 'string') {
|
102
|
-
args = [args];
|
103
|
-
}
|
104
|
-
args = [...args, '--cwd', process.cwd(), '--userNodePath', process.execPath, '--userNodeVersion', process.versions.node];
|
105
|
-
lodash_1.default.defaults(options, {
|
106
|
-
dev: false,
|
107
|
-
env: process.env,
|
108
|
-
detached: false,
|
109
|
-
stdio: getStdio(needsXvfb),
|
110
|
-
});
|
111
|
-
const spawn = (overrides = {}) => {
|
112
|
-
return new bluebird_1.default((resolve, reject) => {
|
113
|
-
lodash_1.default.defaults(overrides, {
|
114
|
-
onStderrData: false,
|
115
|
-
});
|
116
|
-
const { onStderrData } = overrides;
|
117
|
-
const envOverrides = util_1.default.getEnvOverrides(options);
|
118
|
-
const electronArgs = [];
|
119
|
-
const node11WindowsFix = isPlatform('win32');
|
120
|
-
let startScriptPath;
|
121
|
-
if (options.dev) {
|
122
|
-
executable = 'node';
|
123
|
-
// if we're in dev then reset
|
124
|
-
// the launch cmd to be 'npm run dev'
|
125
|
-
startScriptPath = path_1.default.resolve(__dirname, '..', '..', '..', 'scripts', 'start.js');
|
126
|
-
debug('in dev mode the args became %o', args);
|
127
|
-
}
|
128
|
-
if (!options.dev && verify_1.default.needsSandbox()) {
|
129
|
-
electronArgs.push('--no-sandbox');
|
130
|
-
}
|
131
|
-
// strip dev out of child process options
|
132
|
-
/**
|
133
|
-
* @type {import('child_process').ForkOptions}
|
134
|
-
*/
|
135
|
-
let stdioOptions = lodash_1.default.pick(options, 'env', 'detached', 'stdio');
|
136
|
-
// figure out if we're going to be force enabling or disabling colors.
|
137
|
-
// also figure out whether we should force stdout and stderr into thinking
|
138
|
-
// it is a tty as opposed to a pipe.
|
139
|
-
stdioOptions.env = lodash_1.default.extend({}, stdioOptions.env, envOverrides);
|
140
|
-
if (node11WindowsFix) {
|
141
|
-
stdioOptions = lodash_1.default.extend({}, stdioOptions, { windowsHide: false });
|
142
|
-
}
|
143
|
-
if (util_1.default.isPossibleLinuxWithIncorrectDisplay()) {
|
144
|
-
// make sure we use the latest DISPLAY variable if any
|
145
|
-
debug('passing DISPLAY', process.env.DISPLAY);
|
146
|
-
stdioOptions.env.DISPLAY = process.env.DISPLAY;
|
147
|
-
}
|
148
|
-
if (stdioOptions.env.ELECTRON_RUN_AS_NODE) {
|
149
|
-
// Since we are running electron as node, we need to add an entry point file.
|
150
|
-
startScriptPath = path_1.default.join(state_1.default.getBinaryPkgPath(path_1.default.dirname(executable)), '..', 'index.js');
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
// Start arguments with "--" so Electron knows these are OUR
|
154
|
-
// arguments and does not try to sanitize them. Otherwise on Windows
|
155
|
-
// an url in one of the arguments crashes it :(
|
156
|
-
// https://github.com/cypress-io/cypress/issues/5466
|
157
|
-
args = [...electronArgs, '--', ...args];
|
158
|
-
}
|
159
|
-
if (startScriptPath) {
|
160
|
-
args.unshift(startScriptPath);
|
161
|
-
}
|
162
|
-
if (process.env.CYPRESS_INTERNAL_DEV_DEBUG) {
|
163
|
-
args.unshift(process.env.CYPRESS_INTERNAL_DEV_DEBUG);
|
164
|
-
}
|
165
|
-
debug('spawn args %o %o', args, lodash_1.default.omit(stdioOptions, 'env'));
|
166
|
-
debug('spawning Cypress with executable: %s', executable);
|
167
|
-
const child = child_process_1.default.spawn(executable, args, stdioOptions);
|
168
|
-
function resolveOn(event) {
|
169
|
-
return function (code, signal) {
|
170
|
-
debug('child event fired %o', { event, code, signal });
|
171
|
-
if (code === null) {
|
172
|
-
const errorObject = errors_1.errors.childProcessKilled(event, signal);
|
173
|
-
return (0, errors_1.getError)(errorObject).then(reject);
|
174
|
-
}
|
175
|
-
resolve(code);
|
176
|
-
};
|
177
|
-
}
|
178
|
-
child.on('close', resolveOn('close'));
|
179
|
-
child.on('exit', resolveOn('exit'));
|
180
|
-
child.on('error', reject);
|
181
|
-
if (isPlatform('win32')) {
|
182
|
-
const rl = readline_1.default.createInterface({
|
183
|
-
input: process.stdin,
|
184
|
-
output: process.stdout,
|
185
|
-
});
|
186
|
-
// on windows, SIGINT does not propagate to the child process when ctrl+c is pressed
|
187
|
-
// this makes sure all nested processes are closed(ex: firefox inside the server)
|
188
|
-
rl.on('SIGINT', function () {
|
189
|
-
return __awaiter(this, void 0, void 0, function* () {
|
190
|
-
const kill = (yield Promise.resolve().then(() => __importStar(require('tree-kill')))).default;
|
191
|
-
kill(child.pid, 'SIGINT');
|
192
|
-
});
|
193
|
-
});
|
194
|
-
}
|
195
|
-
// if stdio options is set to 'pipe', then
|
196
|
-
// we should set up pipes:
|
197
|
-
// process STDIN (read stream) => child STDIN (writeable)
|
198
|
-
// child STDOUT => process STDOUT
|
199
|
-
// child STDERR => process STDERR with additional filtering
|
200
|
-
if (child.stdin) {
|
201
|
-
debug('piping process STDIN into child STDIN');
|
202
|
-
process.stdin.pipe(child.stdin);
|
203
|
-
}
|
204
|
-
if (child.stdout) {
|
205
|
-
debug('piping child STDOUT to process STDOUT');
|
206
|
-
child.stdout.pipe(process.stdout);
|
207
|
-
}
|
208
|
-
// if this is defined then we are manually piping for linux
|
209
|
-
// to filter out the garbage
|
210
|
-
if (child.stderr) {
|
211
|
-
debug('piping child STDERR to process STDERR');
|
212
|
-
child.stderr.on('data', (data) => {
|
213
|
-
const str = data.toString();
|
214
|
-
// if we have a callback and this explicitly returns
|
215
|
-
// false then bail
|
216
|
-
if (onStderrData && onStderrData(str)) {
|
217
|
-
return;
|
218
|
-
}
|
219
|
-
// else pass it along!
|
220
|
-
process.stderr.write(data);
|
221
|
-
});
|
222
|
-
}
|
223
|
-
// https://github.com/cypress-io/cypress/issues/1841
|
224
|
-
// https://github.com/cypress-io/cypress/issues/5241
|
225
|
-
// In some versions of node, it will throw on windows
|
226
|
-
// when you close the parent process after piping
|
227
|
-
// into the child process. unpiping does not seem
|
228
|
-
// to have any effect. so we're just catching the
|
229
|
-
// error here and not doing anything.
|
230
|
-
process.stdin.on('error', (err) => {
|
231
|
-
if (['EPIPE', 'ENOTCONN'].includes(err.code)) {
|
232
|
-
return;
|
233
|
-
}
|
234
|
-
throw err;
|
235
|
-
});
|
236
|
-
if (stdioOptions.detached) {
|
237
|
-
child.unref();
|
238
|
-
}
|
239
|
-
});
|
240
|
-
};
|
241
|
-
const spawnInXvfb = () => {
|
242
|
-
return xvfb_1.default
|
243
|
-
.start()
|
244
|
-
.then(userFriendlySpawn)
|
245
|
-
.finally(xvfb_1.default.stop);
|
246
|
-
};
|
247
|
-
const userFriendlySpawn = (linuxWithDisplayEnv) => {
|
248
|
-
debug('spawning, should retry on display problem?', Boolean(linuxWithDisplayEnv));
|
249
|
-
let brokenGtkDisplay;
|
250
|
-
const overrides = {};
|
251
|
-
if (linuxWithDisplayEnv) {
|
252
|
-
lodash_1.default.extend(overrides, {
|
253
|
-
electronLogging: true,
|
254
|
-
onStderrData(str) {
|
255
|
-
// if we receive a broken pipe anywhere
|
256
|
-
// then we know that's why cypress exited early
|
257
|
-
if (util_1.default.isBrokenGtkDisplay(str)) {
|
258
|
-
brokenGtkDisplay = true;
|
259
|
-
}
|
260
|
-
},
|
261
|
-
});
|
262
|
-
}
|
263
|
-
return spawn(overrides)
|
264
|
-
.then((code) => {
|
265
|
-
if (code !== 0 && brokenGtkDisplay) {
|
266
|
-
util_1.default.logBrokenGtkDisplayWarning();
|
267
|
-
return spawnInXvfb();
|
268
|
-
}
|
269
|
-
return code;
|
270
|
-
})
|
271
|
-
// we can format and handle an error message from the code above
|
272
|
-
// prevent wrapping error again by using "known: undefined" filter
|
273
|
-
.catch({ known: undefined }, (0, errors_1.throwFormErrorText)(errors_1.errors.unexpected));
|
274
|
-
};
|
275
|
-
if (needsXvfb) {
|
276
|
-
return spawnInXvfb();
|
277
|
-
}
|
278
|
-
// if we are on linux and there's already a DISPLAY
|
279
|
-
// set, then we may need to rerun cypress after
|
280
|
-
// spawning our own Xvfb server
|
281
|
-
const linuxWithDisplayEnv = util_1.default.isPossibleLinuxWithIncorrectDisplay();
|
282
|
-
return userFriendlySpawn(linuxWithDisplayEnv);
|
283
|
-
},
|
284
|
-
};
|
285
|
-
exports.default = spawnModule;
|
package/lib/exec/versions.js
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
7
|
-
const debug_1 = __importDefault(require("debug"));
|
8
|
-
const path_1 = __importDefault(require("path"));
|
9
|
-
const util_1 = __importDefault(require("../util"));
|
10
|
-
const state_1 = __importDefault(require("../tasks/state"));
|
11
|
-
const errors_1 = require("../errors");
|
12
|
-
const debug = (0, debug_1.default)('cypress:cli');
|
13
|
-
const getVersions = () => {
|
14
|
-
return bluebird_1.default.try(() => {
|
15
|
-
if (util_1.default.getEnv('CYPRESS_RUN_BINARY')) {
|
16
|
-
let envBinaryPath = path_1.default.resolve(util_1.default.getEnv('CYPRESS_RUN_BINARY'));
|
17
|
-
return state_1.default.parseRealPlatformBinaryFolderAsync(envBinaryPath)
|
18
|
-
.then((envBinaryDir) => {
|
19
|
-
if (!envBinaryDir) {
|
20
|
-
return (0, errors_1.throwFormErrorText)(errors_1.errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))();
|
21
|
-
}
|
22
|
-
debug('CYPRESS_RUN_BINARY has binaryDir:', envBinaryDir);
|
23
|
-
return envBinaryDir;
|
24
|
-
})
|
25
|
-
.catch({ code: 'ENOENT' }, (err) => {
|
26
|
-
return (0, errors_1.throwFormErrorText)(errors_1.errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))(err.message);
|
27
|
-
});
|
28
|
-
}
|
29
|
-
return state_1.default.getBinaryDir();
|
30
|
-
})
|
31
|
-
.then(state_1.default.getBinaryPkgAsync)
|
32
|
-
.then((pkg) => {
|
33
|
-
const versions = {
|
34
|
-
binary: state_1.default.getBinaryPkgVersion(pkg),
|
35
|
-
electronVersion: state_1.default.getBinaryElectronVersion(pkg),
|
36
|
-
electronNodeVersion: state_1.default.getBinaryElectronNodeVersion(pkg),
|
37
|
-
};
|
38
|
-
debug('binary versions %o', versions);
|
39
|
-
return versions;
|
40
|
-
})
|
41
|
-
.then((binaryVersions) => {
|
42
|
-
const buildInfo = util_1.default.pkgBuildInfo();
|
43
|
-
let packageVersion = util_1.default.pkgVersion();
|
44
|
-
if (!buildInfo)
|
45
|
-
packageVersion += ' (development)';
|
46
|
-
else if (!buildInfo.stable)
|
47
|
-
packageVersion += ' (pre-release)';
|
48
|
-
const versions = {
|
49
|
-
package: packageVersion,
|
50
|
-
binary: binaryVersions.binary || 'not installed',
|
51
|
-
electronVersion: binaryVersions.electronVersion || 'not found',
|
52
|
-
electronNodeVersion: binaryVersions.electronNodeVersion || 'not found',
|
53
|
-
};
|
54
|
-
debug('combined versions %o', versions);
|
55
|
-
return versions;
|
56
|
-
});
|
57
|
-
};
|
58
|
-
const versionsModule = {
|
59
|
-
getVersions,
|
60
|
-
};
|
61
|
-
exports.default = versionsModule;
|
package/lib/fs.js
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
7
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
8
|
-
exports.default = bluebird_1.default.promisifyAll(fs_extra_1.default);
|
package/lib/tasks/unzip.js
DELETED
@@ -1,198 +0,0 @@
|
|
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
|
-
};
|
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 lodash_1 = __importDefault(require("lodash"));
|
16
|
-
const lazy_ass_1 = __importDefault(require("lazy-ass"));
|
17
|
-
const check_more_types_1 = __importDefault(require("check-more-types"));
|
18
|
-
const child_process_1 = __importDefault(require("child_process"));
|
19
|
-
const os_1 = __importDefault(require("os"));
|
20
|
-
const yauzl_1 = __importDefault(require("yauzl"));
|
21
|
-
const debug_1 = __importDefault(require("debug"));
|
22
|
-
const extract_zip_1 = __importDefault(require("extract-zip"));
|
23
|
-
const bluebird_1 = __importDefault(require("bluebird"));
|
24
|
-
const readline_1 = __importDefault(require("readline"));
|
25
|
-
const errors_1 = require("../errors");
|
26
|
-
const fs_1 = __importDefault(require("../fs"));
|
27
|
-
const util_1 = __importDefault(require("../util"));
|
28
|
-
const debug = (0, debug_1.default)('cypress:cli:unzip');
|
29
|
-
const unzipTools = {
|
30
|
-
extract: extract_zip_1.default,
|
31
|
-
};
|
32
|
-
// expose this function for simple testing
|
33
|
-
const unzip = ({ zipFilePath, installDir, progress }) => {
|
34
|
-
debug('unzipping from %s', zipFilePath);
|
35
|
-
debug('into', installDir);
|
36
|
-
if (!zipFilePath) {
|
37
|
-
throw new Error('Missing zip filename');
|
38
|
-
}
|
39
|
-
const startTime = Date.now();
|
40
|
-
let yauzlDoneTime = 0;
|
41
|
-
return fs_1.default.ensureDirAsync(installDir)
|
42
|
-
.then(() => {
|
43
|
-
return new bluebird_1.default((resolve, reject) => {
|
44
|
-
return yauzl_1.default.open(zipFilePath, (err, zipFile) => {
|
45
|
-
yauzlDoneTime = Date.now();
|
46
|
-
if (err) {
|
47
|
-
debug('error using yauzl %s', err.message);
|
48
|
-
return reject(err);
|
49
|
-
}
|
50
|
-
const total = zipFile.entryCount;
|
51
|
-
debug('zipFile entries count', total);
|
52
|
-
const started = new Date();
|
53
|
-
let percent = 0;
|
54
|
-
let count = 0;
|
55
|
-
const notify = (percent) => {
|
56
|
-
const elapsed = +new Date() - +started;
|
57
|
-
const eta = util_1.default.calculateEta(percent, elapsed);
|
58
|
-
progress.onProgress(percent, util_1.default.secsRemaining(eta));
|
59
|
-
};
|
60
|
-
const tick = () => {
|
61
|
-
count += 1;
|
62
|
-
percent = ((count / total) * 100);
|
63
|
-
const displayPercent = percent.toFixed(0);
|
64
|
-
return notify(Number(displayPercent));
|
65
|
-
};
|
66
|
-
const unzipWithNode = () => {
|
67
|
-
debug('unzipping with node.js (slow)');
|
68
|
-
const opts = {
|
69
|
-
dir: installDir,
|
70
|
-
onEntry: tick,
|
71
|
-
};
|
72
|
-
debug('calling Node extract tool %s %o', zipFilePath, opts);
|
73
|
-
return unzipTools.extract(zipFilePath, opts)
|
74
|
-
.then(() => {
|
75
|
-
debug('node unzip finished');
|
76
|
-
return resolve();
|
77
|
-
})
|
78
|
-
.catch((err) => {
|
79
|
-
const error = err || new Error('Unknown error with Node extract tool');
|
80
|
-
debug('error %s', error.message);
|
81
|
-
return reject(error);
|
82
|
-
});
|
83
|
-
};
|
84
|
-
const unzipFallback = lodash_1.default.once(unzipWithNode);
|
85
|
-
const unzipWithUnzipTool = () => {
|
86
|
-
debug('unzipping via `unzip`');
|
87
|
-
const inflatingRe = /inflating:/;
|
88
|
-
const sp = child_process_1.default.spawn('unzip', ['-o', zipFilePath, '-d', installDir]);
|
89
|
-
sp.on('error', (err) => {
|
90
|
-
debug('unzip tool error: %s', err.message);
|
91
|
-
unzipFallback();
|
92
|
-
});
|
93
|
-
sp.on('close', (code) => {
|
94
|
-
debug('unzip tool close with code %d', code);
|
95
|
-
if (code === 0) {
|
96
|
-
percent = 100;
|
97
|
-
notify(percent);
|
98
|
-
return resolve();
|
99
|
-
}
|
100
|
-
debug('`unzip` failed %o', { code });
|
101
|
-
return unzipFallback();
|
102
|
-
});
|
103
|
-
sp.stdout.on('data', (data) => {
|
104
|
-
if (inflatingRe.test(data)) {
|
105
|
-
return tick();
|
106
|
-
}
|
107
|
-
});
|
108
|
-
sp.stderr.on('data', (data) => {
|
109
|
-
debug('`unzip` stderr %s', data);
|
110
|
-
});
|
111
|
-
};
|
112
|
-
// we attempt to first unzip with the native osx
|
113
|
-
// ditto because its less likely to have problems
|
114
|
-
// with corruption, symlinks, or icons causing failures
|
115
|
-
// and can handle resource forks
|
116
|
-
// http://automatica.com.au/2011/02/unzip-mac-os-x-zip-in-terminal/
|
117
|
-
const unzipWithOsx = () => {
|
118
|
-
debug('unzipping via `ditto`');
|
119
|
-
const copyingFileRe = /^copying file/;
|
120
|
-
const sp = child_process_1.default.spawn('ditto', ['-xkV', zipFilePath, installDir]);
|
121
|
-
// f-it just unzip with node
|
122
|
-
sp.on('error', (err) => {
|
123
|
-
debug(err.message);
|
124
|
-
unzipFallback();
|
125
|
-
});
|
126
|
-
sp.on('close', (code) => {
|
127
|
-
if (code === 0) {
|
128
|
-
// make sure we get to 100% on the progress bar
|
129
|
-
// because reading in lines is not really accurate
|
130
|
-
percent = 100;
|
131
|
-
notify(percent);
|
132
|
-
return resolve();
|
133
|
-
}
|
134
|
-
debug('`ditto` failed %o', { code });
|
135
|
-
return unzipFallback();
|
136
|
-
});
|
137
|
-
return readline_1.default.createInterface({
|
138
|
-
input: sp.stderr,
|
139
|
-
})
|
140
|
-
.on('line', (line) => {
|
141
|
-
if (copyingFileRe.test(line)) {
|
142
|
-
return tick();
|
143
|
-
}
|
144
|
-
});
|
145
|
-
};
|
146
|
-
switch (os_1.default.platform()) {
|
147
|
-
case 'darwin':
|
148
|
-
return unzipWithOsx();
|
149
|
-
case 'linux':
|
150
|
-
return unzipWithUnzipTool();
|
151
|
-
case 'win32':
|
152
|
-
return unzipWithNode();
|
153
|
-
default:
|
154
|
-
return;
|
155
|
-
}
|
156
|
-
});
|
157
|
-
})
|
158
|
-
.tap(() => {
|
159
|
-
debug('unzip completed %o', {
|
160
|
-
yauzlMs: yauzlDoneTime - startTime,
|
161
|
-
unzipMs: Date.now() - yauzlDoneTime,
|
162
|
-
});
|
163
|
-
});
|
164
|
-
});
|
165
|
-
};
|
166
|
-
function isMaybeWindowsMaxPathLengthError(err) {
|
167
|
-
return os_1.default.platform() === 'win32' && err.code === 'ENOENT' && err.syscall === 'realpath';
|
168
|
-
}
|
169
|
-
const start = (_a) => __awaiter(void 0, [_a], void 0, function* ({ zipFilePath, installDir, progress }) {
|
170
|
-
(0, lazy_ass_1.default)(check_more_types_1.default.unemptyString(installDir), 'missing installDir');
|
171
|
-
if (!progress) {
|
172
|
-
progress = { onProgress: () => {
|
173
|
-
return {};
|
174
|
-
} };
|
175
|
-
}
|
176
|
-
try {
|
177
|
-
const installDirExists = yield fs_1.default.pathExists(installDir);
|
178
|
-
if (installDirExists) {
|
179
|
-
debug('removing existing unzipped binary', installDir);
|
180
|
-
yield fs_1.default.removeAsync(installDir);
|
181
|
-
}
|
182
|
-
yield unzip({ zipFilePath, installDir, progress });
|
183
|
-
}
|
184
|
-
catch (err) {
|
185
|
-
const errorTemplate = isMaybeWindowsMaxPathLengthError(err) ?
|
186
|
-
errors_1.errors.failedUnzipWindowsMaxPathLength
|
187
|
-
: errors_1.errors.failedUnzip;
|
188
|
-
yield (0, errors_1.throwFormErrorText)(errorTemplate)(err);
|
189
|
-
}
|
190
|
-
});
|
191
|
-
const unzipModule = {
|
192
|
-
start,
|
193
|
-
utils: {
|
194
|
-
unzip,
|
195
|
-
unzipTools,
|
196
|
-
},
|
197
|
-
};
|
198
|
-
exports.default = unzipModule;
|
File without changes
|
File without changes
|
File without changes
|
/package/{lib → dist}/logger.js
RENAMED
File without changes
|