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.
@@ -1,200 +1,198 @@
1
1
  "use strict";
2
-
3
- const _ = require('lodash');
4
- const la = require('lazy-ass');
5
- const is = require('check-more-types');
6
- const cp = require('child_process');
7
- const os = require('os');
8
- const yauzl = require('yauzl');
9
- const debug = require('debug')('cypress:cli:unzip');
10
- const extract = require('extract-zip');
11
- const Promise = require('bluebird');
12
- const readline = require('readline');
13
- const {
14
- throwFormErrorText,
15
- errors
16
- } = require('../errors');
17
- const fs = require('../fs');
18
- 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 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');
19
29
  const unzipTools = {
20
- extract
30
+ extract: extract_zip_1.default,
21
31
  };
22
-
23
32
  // expose this function for simple testing
24
- const unzip = ({
25
- zipFilePath,
26
- installDir,
27
- progress
28
- }) => {
29
- debug('unzipping from %s', zipFilePath);
30
- debug('into', installDir);
31
- if (!zipFilePath) {
32
- throw new Error('Missing zip filename');
33
- }
34
- const startTime = Date.now();
35
- let yauzlDoneTime = 0;
36
- return fs.ensureDirAsync(installDir).then(() => {
37
- return new Promise((resolve, reject) => {
38
- return yauzl.open(zipFilePath, (err, zipFile) => {
39
- yauzlDoneTime = Date.now();
40
- if (err) {
41
- debug('error using yauzl %s', err.message);
42
- return reject(err);
43
- }
44
- const total = zipFile.entryCount;
45
- debug('zipFile entries count', total);
46
- const started = new Date();
47
- let percent = 0;
48
- let count = 0;
49
- const notify = percent => {
50
- const elapsed = +new Date() - +started;
51
- const eta = util.calculateEta(percent, elapsed);
52
- progress.onProgress(percent, util.secsRemaining(eta));
53
- };
54
- const tick = () => {
55
- count += 1;
56
- percent = count / total * 100;
57
- const displayPercent = percent.toFixed(0);
58
- return notify(displayPercent);
59
- };
60
- const unzipWithNode = () => {
61
- debug('unzipping with node.js (slow)');
62
- const opts = {
63
- dir: installDir,
64
- onEntry: tick
65
- };
66
- debug('calling Node extract tool %s %o', zipFilePath, opts);
67
- return unzipTools.extract(zipFilePath, opts).then(() => {
68
- debug('node unzip finished');
69
- return resolve();
70
- }).catch(err => {
71
- const error = err || new Error('Unknown error with Node extract tool');
72
- debug('error %s', error.message);
73
- return reject(error);
74
- });
75
- };
76
- const unzipFallback = _.once(unzipWithNode);
77
- const unzipWithUnzipTool = () => {
78
- debug('unzipping via `unzip`');
79
- const inflatingRe = /inflating:/;
80
- const sp = cp.spawn('unzip', ['-o', zipFilePath, '-d', installDir]);
81
- sp.on('error', err => {
82
- debug('unzip tool error: %s', err.message);
83
- unzipFallback();
84
- });
85
- sp.on('close', code => {
86
- debug('unzip tool close with code %d', code);
87
- if (code === 0) {
88
- percent = 100;
89
- notify(percent);
90
- return resolve();
91
- }
92
- debug('`unzip` failed %o', {
93
- code
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
+ }
94
156
  });
95
- return unzipFallback();
96
- });
97
- sp.stdout.on('data', data => {
98
- if (inflatingRe.test(data)) {
99
- return tick();
100
- }
101
- });
102
- sp.stderr.on('data', data => {
103
- debug('`unzip` stderr %s', data);
104
- });
105
- };
106
-
107
- // we attempt to first unzip with the native osx
108
- // ditto because its less likely to have problems
109
- // with corruption, symlinks, or icons causing failures
110
- // and can handle resource forks
111
- // http://automatica.com.au/2011/02/unzip-mac-os-x-zip-in-terminal/
112
- const unzipWithOsx = () => {
113
- debug('unzipping via `ditto`');
114
- const copyingFileRe = /^copying file/;
115
- const sp = cp.spawn('ditto', ['-xkV', zipFilePath, installDir]);
116
-
117
- // f-it just unzip with node
118
- sp.on('error', err => {
119
- debug(err.message);
120
- unzipFallback();
121
- });
122
- sp.on('close', code => {
123
- if (code === 0) {
124
- // make sure we get to 100% on the progress bar
125
- // because reading in lines is not really accurate
126
- percent = 100;
127
- notify(percent);
128
- return resolve();
129
- }
130
- debug('`ditto` failed %o', {
131
- code
157
+ })
158
+ .tap(() => {
159
+ debug('unzip completed %o', {
160
+ yauzlMs: yauzlDoneTime - startTime,
161
+ unzipMs: Date.now() - yauzlDoneTime,
132
162
  });
133
- return unzipFallback();
134
- });
135
- return readline.createInterface({
136
- input: sp.stderr
137
- }).on('line', line => {
138
- if (copyingFileRe.test(line)) {
139
- return tick();
140
- }
141
- });
142
- };
143
- switch (os.platform()) {
144
- case 'darwin':
145
- return unzipWithOsx();
146
- case 'linux':
147
- return unzipWithUnzipTool();
148
- case 'win32':
149
- return unzipWithNode();
150
- default:
151
- return;
152
- }
153
- });
154
- }).tap(() => {
155
- debug('unzip completed %o', {
156
- yauzlMs: yauzlDoneTime - startTime,
157
- unzipMs: Date.now() - yauzlDoneTime
158
- });
163
+ });
159
164
  });
160
- });
161
165
  };
162
166
  function isMaybeWindowsMaxPathLengthError(err) {
163
- return os.platform() === 'win32' && err.code === 'ENOENT' && err.syscall === 'realpath';
167
+ return os_1.default.platform() === 'win32' && err.code === 'ENOENT' && err.syscall === 'realpath';
164
168
  }
165
- const start = async ({
166
- zipFilePath,
167
- installDir,
168
- progress
169
- }) => {
170
- la(is.unemptyString(installDir), 'missing installDir');
171
- if (!progress) {
172
- progress = {
173
- onProgress: () => {
174
- return {};
175
- }
176
- };
177
- }
178
- try {
179
- const installDirExists = await fs.pathExists(installDir);
180
- if (installDirExists) {
181
- debug('removing existing unzipped binary', installDir);
182
- await fs.removeAsync(installDir);
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
+ } };
183
175
  }
184
- await unzip({
185
- zipFilePath,
186
- installDir,
187
- progress
188
- });
189
- } catch (err) {
190
- const errorTemplate = isMaybeWindowsMaxPathLengthError(err) ? errors.failedUnzipWindowsMaxPathLength : errors.failedUnzip;
191
- await throwFormErrorText(errorTemplate)(err);
192
- }
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
+ },
193
197
  };
194
- module.exports = {
195
- start,
196
- utils: {
197
- unzip,
198
- unzipTools
199
- }
200
- };
198
+ exports.default = unzipModule;