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.
package/lib/util.js CHANGED
@@ -1,63 +1,69 @@
1
1
  "use strict";
2
-
3
- const _ = require('lodash');
4
- const arch = require('arch');
5
- const os = require('os');
6
- const ospath = require('ospath');
7
- const hasha = require('hasha');
8
- const la = require('lazy-ass');
9
- const is = require('check-more-types');
10
- const tty = require('tty');
11
- const path = require('path');
12
- const isCi = require('ci-info').isCI;
13
- const execa = require('execa');
14
- const getos = require('getos');
15
- const chalk = require('chalk');
16
- const Promise = require('bluebird');
17
- const cachedir = require('cachedir');
18
- const logSymbols = require('log-symbols');
19
- const executable = require('executable');
20
- const {
21
- stripIndent
22
- } = require('common-tags');
23
- const supportsColor = require('supports-color');
24
- const isInstalledGlobally = require('is-installed-globally');
25
- const logger = require('./logger');
26
- const debug = require('debug')('cypress:cli');
27
- const fs = require('./fs');
28
- const pkg = require(path.join(__dirname, '..', 'package.json'));
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 arch_1 = __importDefault(require("arch"));
17
+ const os_1 = __importDefault(require("os"));
18
+ const ospath_1 = __importDefault(require("ospath"));
19
+ const hasha_1 = __importDefault(require("hasha"));
20
+ const lazy_ass_1 = __importDefault(require("lazy-ass"));
21
+ const check_more_types_1 = __importDefault(require("check-more-types"));
22
+ const tty_1 = __importDefault(require("tty"));
23
+ const path_1 = __importDefault(require("path"));
24
+ const ci_info_1 = require("ci-info");
25
+ const execa_1 = __importDefault(require("execa"));
26
+ const systeminformation_1 = __importDefault(require("systeminformation"));
27
+ const chalk_1 = __importDefault(require("chalk"));
28
+ const bluebird_1 = __importDefault(require("bluebird"));
29
+ const cachedir_1 = __importDefault(require("cachedir"));
30
+ const log_symbols_1 = __importDefault(require("log-symbols"));
31
+ const executable_1 = __importDefault(require("executable"));
32
+ const common_tags_1 = require("common-tags");
33
+ const supports_color_1 = __importDefault(require("supports-color"));
34
+ const is_installed_globally_1 = __importDefault(require("is-installed-globally"));
35
+ const logger_1 = __importDefault(require("./logger"));
36
+ const debug_1 = __importDefault(require("debug"));
37
+ const fs_1 = __importDefault(require("./fs"));
38
+ const debug = (0, debug_1.default)('cypress:cli');
39
+ // Import package.json dynamically to avoid TypeScript JSON import issues
40
+ const pkg = require(path_1.default.join(__dirname, '..', 'package.json'));
29
41
  const issuesUrl = 'https://github.com/cypress-io/cypress/issues';
30
- const getosAsync = Promise.promisify(getos);
31
-
32
42
  /**
33
43
  * Returns SHA512 of a file
34
44
  */
35
- const getFileChecksum = filename => {
36
- la(is.unemptyString(filename), 'expected filename', filename);
37
- return hasha.fromFile(filename, {
38
- algorithm: 'sha512'
39
- });
45
+ const getFileChecksum = (filename) => {
46
+ (0, lazy_ass_1.default)(check_more_types_1.default.unemptyString(filename), 'expected filename', filename);
47
+ return hasha_1.default.fromFile(filename, { algorithm: 'sha512' });
40
48
  };
41
- const getFileSize = filename => {
42
- la(is.unemptyString(filename), 'expected filename', filename);
43
- return fs.statAsync(filename).get('size');
49
+ const getFileSize = (filename) => {
50
+ (0, lazy_ass_1.default)(check_more_types_1.default.unemptyString(filename), 'expected filename', filename);
51
+ return fs_1.default.statAsync(filename).get('size');
44
52
  };
45
53
  const isBrokenGtkDisplayRe = /Gtk: cannot open display/;
46
- const stringify = val => {
47
- return _.isObject(val) ? JSON.stringify(val) : val;
54
+ const stringify = (val) => {
55
+ return lodash_1.default.isObject(val) ? JSON.stringify(val) : val;
48
56
  };
49
57
  function normalizeModuleOptions(options = {}) {
50
- return _.mapValues(options, stringify);
58
+ return lodash_1.default.mapValues(options, stringify);
51
59
  }
52
-
53
60
  /**
54
61
  * Returns true if the platform is Linux. We do a lot of different
55
62
  * stuff on Linux (like Xvfb) and it helps to has readable code
56
63
  */
57
64
  const isLinux = () => {
58
- return os.platform() === 'linux';
65
+ return os_1.default.platform() === 'linux';
59
66
  };
60
-
61
67
  /**
62
68
  * If the DISPLAY variable is set incorrectly, when trying to spawn
63
69
  * Cypress executable we get an error like this:
@@ -65,19 +71,18 @@ const isLinux = () => {
65
71
  [1005:0509/184205.663837:WARNING:browser_main_loop.cc(258)] Gtk: cannot open display: 99
66
72
  ```
67
73
  */
68
- const isBrokenGtkDisplay = str => {
69
- return isBrokenGtkDisplayRe.test(str);
74
+ const isBrokenGtkDisplay = (str) => {
75
+ return isBrokenGtkDisplayRe.test(str);
70
76
  };
71
77
  const isPossibleLinuxWithIncorrectDisplay = () => {
72
- return isLinux() && process.env.DISPLAY;
78
+ return isLinux() && !!process.env.DISPLAY;
73
79
  };
74
80
  const logBrokenGtkDisplayWarning = () => {
75
- debug('Cypress exited due to a broken gtk display because of a potential invalid DISPLAY env... retrying after starting Xvfb');
76
-
77
- // if we get this error, we are on Linux and DISPLAY is set
78
- logger.warn(stripIndent`
81
+ debug('Cypress exited due to a broken gtk display because of a potential invalid DISPLAY env... retrying after starting Xvfb');
82
+ // if we get this error, we are on Linux and DISPLAY is set
83
+ logger_1.default.warn((0, common_tags_1.stripIndent) `
79
84
 
80
- ${logSymbols.warning} Warning: Cypress failed to start.
85
+ ${log_symbols_1.default.warning} Warning: Cypress failed to start.
81
86
 
82
87
  This is likely due to a misconfigured DISPLAY environment variable.
83
88
 
@@ -85,13 +90,12 @@ const logBrokenGtkDisplayWarning = () => {
85
90
 
86
91
  Cypress will attempt to fix the problem and rerun.
87
92
  `);
88
- logger.warn();
93
+ logger_1.default.warn();
89
94
  };
90
95
  function stdoutLineMatches(expectedLine, stdout) {
91
- const lines = stdout.split('\n').map(val => val.trim());
92
- return lines.some(line => line === expectedLine);
96
+ const lines = stdout.split('\n').map((val) => val.trim());
97
+ return lines.some((line) => line === expectedLine);
93
98
  }
94
-
95
99
  /**
96
100
  * Confirms if given value is a valid CYPRESS_INTERNAL_ENV value. Undefined values
97
101
  * are valid, because the system can set the default one.
@@ -100,16 +104,14 @@ function stdoutLineMatches(expectedLine, stdout) {
100
104
  * @example util.isValidCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
101
105
  */
102
106
  function isValidCypressInternalEnvValue(value) {
103
- if (_.isUndefined(value)) {
104
- // will get default value
105
- return true;
106
- }
107
-
108
- // names of config environments, see "packages/server/config/app.json"
109
- const names = ['development', 'test', 'staging', 'production'];
110
- return _.includes(names, value);
107
+ if (lodash_1.default.isUndefined(value)) {
108
+ // will get default value
109
+ return true;
110
+ }
111
+ // names of config environments, see "packages/server/config/app.json"
112
+ const names = ['development', 'test', 'staging', 'production'];
113
+ return lodash_1.default.includes(names, value);
111
114
  }
112
-
113
115
  /**
114
116
  * Confirms if given value is a non-production CYPRESS_INTERNAL_ENV value.
115
117
  * Undefined values are valid, because the system can set the default one.
@@ -118,24 +120,23 @@ function isValidCypressInternalEnvValue(value) {
118
120
  * @example util.isNonProductionCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
119
121
  */
120
122
  function isNonProductionCypressInternalEnvValue(value) {
121
- return !_.isUndefined(value) && value !== 'production';
123
+ return !lodash_1.default.isUndefined(value) && value !== 'production';
122
124
  }
123
-
124
125
  /**
125
126
  * Prints NODE_OPTIONS using debug() module, but only
126
127
  * if DEBUG=cypress... is set
127
128
  */
128
129
  function printNodeOptions(log = debug) {
129
- if (!log.enabled) {
130
- return;
131
- }
132
- if (process.env.NODE_OPTIONS) {
133
- log('NODE_OPTIONS=%s', process.env.NODE_OPTIONS);
134
- } else {
135
- log('NODE_OPTIONS is not set');
136
- }
130
+ if (!log.enabled) {
131
+ return;
132
+ }
133
+ if (process.env.NODE_OPTIONS) {
134
+ log('NODE_OPTIONS=%s', process.env.NODE_OPTIONS);
135
+ }
136
+ else {
137
+ log('NODE_OPTIONS is not set');
138
+ }
137
139
  }
138
-
139
140
  /**
140
141
  * Removes double quote characters
141
142
  * from the start and end of the given string IF they are both present
@@ -150,300 +151,300 @@ function printNodeOptions(log = debug) {
150
151
  // returns string 'foo'
151
152
  ```
152
153
  */
153
- const dequote = str => {
154
- la(is.string(str), 'expected a string to remove double quotes', str);
155
- if (str.length > 1 && str[0] === '"' && str[str.length - 1] === '"') {
156
- return str.substr(1, str.length - 2);
157
- }
158
- return str;
154
+ const dequote = (str) => {
155
+ // @ts-expect-error method exists but is not typed
156
+ (0, lazy_ass_1.default)(check_more_types_1.default.string(str), 'expected a string to remove double quotes', str);
157
+ if (str.length > 1 && str[0] === '"' && str[str.length - 1] === '"') {
158
+ return str.substr(1, str.length - 2);
159
+ }
160
+ return str;
159
161
  };
160
- const parseOpts = opts => {
161
- opts = _.pick(opts, 'autoCancelAfterFailures', 'browser', 'cachePath', 'cacheList', 'cacheClear', 'cachePrune', 'ciBuildId', 'ct', 'component', 'config', 'configFile', 'cypressVersion', 'destination', 'detached', 'dev', 'e2e', 'exit', 'env', 'force', 'global', 'group', 'headed', 'headless', 'inspect', 'inspectBrk', 'key', 'path', 'parallel', 'port', 'project', 'quiet', 'reporter', 'reporterOptions', 'record', 'runnerUi', 'runProject', 'spec', 'tag');
162
- if (opts.exit) {
163
- opts = _.omit(opts, 'exit');
164
- }
165
-
166
- // some options might be quoted - which leads to unexpected results
167
- // remove double quotes from certain options
168
- const cleanOpts = {
169
- ...opts
170
- };
171
- const toDequote = ['group', 'ciBuildId'];
172
- for (const prop of toDequote) {
173
- if (_.has(opts, prop)) {
174
- cleanOpts[prop] = dequote(opts[prop]);
162
+ const parseOpts = (opts) => {
163
+ opts = lodash_1.default.pick(opts, 'autoCancelAfterFailures', 'browser', 'cachePath', 'cacheList', 'cacheClear', 'cachePrune', 'ciBuildId', 'ct', 'component', 'config', 'configFile', 'cypressVersion', 'destination', 'detached', 'dev', 'e2e', 'exit', 'env', 'force', 'global', 'group', 'headed', 'headless', 'inspect', 'inspectBrk', 'key', 'path', 'parallel', 'port', 'project', 'quiet', 'reporter', 'reporterOptions', 'record', 'runnerUi', 'runProject', 'spec', 'tag');
164
+ if (opts.exit) {
165
+ opts = lodash_1.default.omit(opts, 'exit');
166
+ }
167
+ // some options might be quoted - which leads to unexpected results
168
+ // remove double quotes from certain options
169
+ const cleanOpts = Object.assign({}, opts);
170
+ const toDequote = ['group', 'ciBuildId'];
171
+ for (const prop of toDequote) {
172
+ if (lodash_1.default.has(opts, prop)) {
173
+ cleanOpts[prop] = dequote(opts[prop]);
174
+ }
175
175
  }
176
- }
177
- debug('parsed cli options %o', cleanOpts);
178
- return cleanOpts;
176
+ debug('parsed cli options %o', cleanOpts);
177
+ return cleanOpts;
179
178
  };
180
-
181
179
  /**
182
180
  * Copy of packages/server/lib/browsers/utils.ts
183
181
  * because we need same functionality in CLI to show the path :(
184
182
  */
185
183
  const getApplicationDataFolder = (...paths) => {
186
- const {
187
- env
188
- } = process;
189
-
190
- // allow overriding the app_data folder
191
- let folder = env.CYPRESS_CONFIG_ENV || env.CYPRESS_INTERNAL_ENV || 'development';
192
- const PRODUCT_NAME = pkg.productName || pkg.name;
193
- const OS_DATA_PATH = ospath.data();
194
- const ELECTRON_APP_DATA_PATH = path.join(OS_DATA_PATH, PRODUCT_NAME);
195
- if (process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF) {
196
- folder = `${folder}-e2e-test`;
197
- }
198
- const p = path.join(ELECTRON_APP_DATA_PATH, 'cy', folder, ...paths);
199
- return p;
184
+ const { env } = process;
185
+ // allow overriding the app_data folder
186
+ let folder = env.CYPRESS_CONFIG_ENV || env.CYPRESS_INTERNAL_ENV || 'development';
187
+ const PRODUCT_NAME = pkg.productName || pkg.name;
188
+ const OS_DATA_PATH = ospath_1.default.data();
189
+ const ELECTRON_APP_DATA_PATH = path_1.default.join(OS_DATA_PATH, PRODUCT_NAME);
190
+ if (process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF) {
191
+ folder = `${folder}-e2e-test`;
192
+ }
193
+ const p = path_1.default.join(ELECTRON_APP_DATA_PATH, 'cy', folder, ...paths);
194
+ return p;
200
195
  };
201
196
  const util = {
202
- normalizeModuleOptions,
203
- parseOpts,
204
- isValidCypressInternalEnvValue,
205
- isNonProductionCypressInternalEnvValue,
206
- printNodeOptions,
207
- isCi() {
208
- return isCi;
209
- },
210
- getEnvOverrides(options = {}) {
211
- return _.chain({}).extend(util.getEnvColors()).extend(util.getForceTty()).omitBy(_.isUndefined) // remove undefined values
212
- .mapValues(value => {
213
- // stringify to 1 or 0
214
- return value ? '1' : '0';
215
- }).extend(util.getOriginalNodeOptions()).value();
216
- },
217
- getOriginalNodeOptions() {
218
- const opts = {};
219
- if (process.env.NODE_OPTIONS) {
220
- opts.ORIGINAL_NODE_OPTIONS = process.env.NODE_OPTIONS;
221
- }
222
- return opts;
223
- },
224
- getForceTty() {
225
- return {
226
- FORCE_STDIN_TTY: util.isTty(process.stdin.fd),
227
- FORCE_STDOUT_TTY: util.isTty(process.stdout.fd),
228
- FORCE_STDERR_TTY: util.isTty(process.stderr.fd)
229
- };
230
- },
231
- getEnvColors() {
232
- const sc = util.supportsColor();
233
- return {
234
- FORCE_COLOR: sc,
235
- DEBUG_COLORS: sc,
236
- MOCHA_COLORS: sc ? true : undefined
237
- };
238
- },
239
- isTty(fd) {
240
- return tty.isatty(fd);
241
- },
242
- supportsColor() {
243
- // if we've been explicitly told not to support
244
- // color then turn this off
245
- if (process.env.NO_COLOR) {
246
- return false;
247
- }
248
-
249
- // https://github.com/cypress-io/cypress/issues/1747
250
- // always return true in CI providers
251
- if (process.env.CI) {
252
- return true;
253
- }
254
-
255
- // ensure that both stdout and stderr support color
256
- return Boolean(supportsColor.stdout) && Boolean(supportsColor.stderr);
257
- },
258
- cwd() {
259
- return process.cwd();
260
- },
261
- pkgBuildInfo() {
262
- return pkg.buildInfo;
263
- },
264
- pkgVersion() {
265
- return pkg.version;
266
- },
267
- exit(code) {
268
- process.exit(code);
269
- },
270
- logErrorExit1(err) {
271
- logger.error(err.message);
272
- process.exit(1);
273
- },
274
- dequote,
275
- titleize(...args) {
276
- // prepend first arg with space
277
- // and pad so that all messages line up
278
- args[0] = _.padEnd(` ${args[0]}`, 24);
279
-
280
- // get rid of any falsy values
281
- args = _.compact(args);
282
- return chalk.blue(...args);
283
- },
284
- calculateEta(percent, elapsed) {
285
- // returns the number of seconds remaining
286
-
287
- // if we're at 100% already just return 0
288
- if (percent === 100) {
289
- return 0;
290
- }
291
-
292
- // take the percentage and divide by one
293
- // and multiple that against elapsed
294
- // subtracting what's already elapsed
295
- return elapsed * (1 / (percent / 100)) - elapsed;
296
- },
297
- convertPercentToPercentage(num) {
298
- // convert a percent with values between 0 and 1
299
- // with decimals, so that it is between 0 and 100
300
- // and has no decimal places
301
- return Math.round(_.isFinite(num) ? num * 100 : 0);
302
- },
303
- secsRemaining(eta) {
304
- // calculate the seconds reminaing with no decimal places
305
- return (_.isFinite(eta) ? eta / 1000 : 0).toFixed(0);
306
- },
307
- setTaskTitle(task, title, renderer) {
308
- // only update the renderer title when not running in CI
309
- if (renderer === 'default' && task.title !== title) {
310
- task.title = title;
311
- }
312
- },
313
- isInstalledGlobally() {
314
- return isInstalledGlobally;
315
- },
316
- isSemver(str) {
317
- return /^(\d+\.)?(\d+\.)?(\*|\d+)$/.test(str);
318
- },
319
- isExecutableAsync(filePath) {
320
- return Promise.resolve(executable(filePath));
321
- },
322
- isLinux,
323
- getOsVersionAsync() {
324
- return Promise.try(() => {
325
- if (isLinux()) {
326
- return getosAsync().then(osInfo => {
327
- return [osInfo.dist, osInfo.release].join(' - ');
328
- }).catch(() => {
329
- return os.release();
197
+ normalizeModuleOptions,
198
+ parseOpts,
199
+ isValidCypressInternalEnvValue,
200
+ isNonProductionCypressInternalEnvValue,
201
+ printNodeOptions,
202
+ isCi() {
203
+ return ci_info_1.isCI;
204
+ },
205
+ getEnvOverrides(options = {}) {
206
+ return lodash_1.default
207
+ .chain({})
208
+ .extend(util.getEnvColors())
209
+ .extend(util.getForceTty())
210
+ .omitBy(lodash_1.default.isUndefined) // remove undefined values
211
+ .mapValues((value) => {
212
+ return value ? '1' : '0';
213
+ })
214
+ .extend(util.getOriginalNodeOptions())
215
+ .value();
216
+ },
217
+ getOriginalNodeOptions() {
218
+ const opts = {};
219
+ if (process.env.NODE_OPTIONS) {
220
+ opts.ORIGINAL_NODE_OPTIONS = process.env.NODE_OPTIONS;
221
+ }
222
+ return opts;
223
+ },
224
+ getForceTty() {
225
+ return {
226
+ FORCE_STDIN_TTY: util.isTty(process.stdin.fd),
227
+ FORCE_STDOUT_TTY: util.isTty(process.stdout.fd),
228
+ FORCE_STDERR_TTY: util.isTty(process.stderr.fd),
229
+ };
230
+ },
231
+ getEnvColors() {
232
+ const sc = util.supportsColor();
233
+ return {
234
+ FORCE_COLOR: sc,
235
+ DEBUG_COLORS: sc,
236
+ MOCHA_COLORS: sc ? true : undefined,
237
+ };
238
+ },
239
+ isTty(fd) {
240
+ return tty_1.default.isatty(fd);
241
+ },
242
+ supportsColor() {
243
+ // if we've been explicitly told not to support
244
+ // color then turn this off
245
+ if (process.env.NO_COLOR) {
246
+ return false;
247
+ }
248
+ // https://github.com/cypress-io/cypress/issues/1747
249
+ // always return true in CI providers
250
+ if (process.env.CI) {
251
+ return true;
252
+ }
253
+ // ensure that both stdout and stderr support color
254
+ return Boolean(supports_color_1.default.stdout) && Boolean(supports_color_1.default.stderr);
255
+ },
256
+ cwd() {
257
+ return process.cwd();
258
+ },
259
+ pkgBuildInfo() {
260
+ return pkg.buildInfo;
261
+ },
262
+ pkgVersion() {
263
+ return pkg.version;
264
+ },
265
+ exit(code) {
266
+ process.exit(code);
267
+ },
268
+ logErrorExit1(err) {
269
+ logger_1.default.error(err.message);
270
+ process.exit(1);
271
+ },
272
+ dequote,
273
+ titleize(...args) {
274
+ // prepend first arg with space
275
+ // and pad so that all messages line up
276
+ args[0] = lodash_1.default.padEnd(` ${args[0]}`, 24);
277
+ // get rid of any falsy values
278
+ args = lodash_1.default.compact(args);
279
+ return chalk_1.default.blue(...args);
280
+ },
281
+ calculateEta(percent, elapsed) {
282
+ // returns the number of seconds remaining
283
+ // if we're at 100% already just return 0
284
+ if (percent === 100) {
285
+ return 0;
286
+ }
287
+ // take the percentage and divide by one
288
+ // and multiple that against elapsed
289
+ // subtracting what's already elapsed
290
+ return elapsed * (1 / (percent / 100)) - elapsed;
291
+ },
292
+ convertPercentToPercentage(num) {
293
+ // convert a percent with values between 0 and 1
294
+ // with decimals, so that it is between 0 and 100
295
+ // and has no decimal places
296
+ return Math.round(lodash_1.default.isFinite(num) ? (num * 100) : 0);
297
+ },
298
+ secsRemaining(eta) {
299
+ // calculate the seconds reminaing with no decimal places
300
+ return (lodash_1.default.isFinite(eta) ? (eta / 1000) : 0).toFixed(0);
301
+ },
302
+ setTaskTitle(task, title, renderer) {
303
+ // only update the renderer title when not running in CI
304
+ if (renderer === 'default' && task.title !== title) {
305
+ task.title = title;
306
+ }
307
+ },
308
+ isInstalledGlobally() {
309
+ return is_installed_globally_1.default;
310
+ },
311
+ isSemver(str) {
312
+ return /^(\d+\.)?(\d+\.)?(\*|\d+)$/.test(str);
313
+ },
314
+ isExecutableAsync(filePath) {
315
+ return bluebird_1.default.resolve((0, executable_1.default)(filePath));
316
+ },
317
+ isLinux,
318
+ getOsVersionAsync() {
319
+ return bluebird_1.default.try(() => {
320
+ return systeminformation_1.default.osInfo()
321
+ .then((osInfo) => {
322
+ if (osInfo.distro && osInfo.release) {
323
+ return `${osInfo.distro} - ${osInfo.release}`;
324
+ }
325
+ return os_1.default.release();
326
+ }).catch(() => {
327
+ return os_1.default.release();
328
+ });
330
329
  });
331
- }
332
- return os.release();
333
- });
334
- },
335
- async getPlatformInfo() {
336
- const [version, osArch] = await Promise.all([util.getOsVersionAsync(), this.getRealArch()]);
337
- return stripIndent`
338
- Platform: ${os.platform()}-${osArch} (${version})
330
+ },
331
+ getPlatformInfo() {
332
+ return __awaiter(this, void 0, void 0, function* () {
333
+ const [version, osArch] = yield bluebird_1.default.all([
334
+ util.getOsVersionAsync(),
335
+ this.getRealArch(),
336
+ ]);
337
+ return (0, common_tags_1.stripIndent) `
338
+ Platform: ${os_1.default.platform()}-${osArch} (${version})
339
339
  Cypress Version: ${util.pkgVersion()}
340
340
  `;
341
- },
342
- _cachedArch: undefined,
343
- /**
344
- * Attempt to return the real system arch (not process.arch, which is only the Node binary's arch)
345
- */
346
- async getRealArch() {
347
- if (this._cachedArch) return this._cachedArch;
348
- async function _getRealArch() {
349
- const osPlatform = os.platform();
350
- // eslint-disable-next-line no-restricted-syntax
351
- const osArch = os.arch();
352
- debug('detecting arch %o', {
353
- osPlatform,
354
- osArch
355
- });
356
- if (osArch === 'arm64') return 'arm64';
357
- if (osPlatform === 'darwin') {
358
- // could possibly be x64 node on arm64 darwin, check if we are being translated by Rosetta
359
- // https://stackoverflow.com/a/65347893/3474615
360
- const {
361
- stdout
362
- } = await execa('sysctl', ['-n', 'sysctl.proc_translated']).catch(() => '');
363
- debug('rosetta check result: %o', {
364
- stdout
365
341
  });
366
- if (stdout === '1') return 'arm64';
367
- }
368
- if (osPlatform === 'linux') {
369
- // could possibly be x64 node on arm64 linux, check the "machine hardware name"
370
- // list of names for reference: https://stackoverflow.com/a/45125525/3474615
371
- const {
372
- stdout
373
- } = await execa('uname', ['-m']).catch(() => '');
374
- debug('arm uname -m result: %o ', {
375
- stdout
342
+ },
343
+ _cachedArch: undefined,
344
+ /**
345
+ * Attempt to return the real system arch (not process.arch, which is only the Node binary's arch)
346
+ */
347
+ getRealArch() {
348
+ return __awaiter(this, void 0, void 0, function* () {
349
+ if (this._cachedArch)
350
+ return this._cachedArch;
351
+ function _getRealArch() {
352
+ return __awaiter(this, void 0, void 0, function* () {
353
+ const osPlatform = os_1.default.platform();
354
+ // eslint-disable-next-line no-restricted-syntax
355
+ const osArch = os_1.default.arch();
356
+ debug('detecting arch %o', { osPlatform, osArch });
357
+ if (osArch === 'arm64')
358
+ return 'arm64';
359
+ if (osPlatform === 'darwin') {
360
+ // could possibly be x64 node on arm64 darwin, check if we are being translated by Rosetta
361
+ // https://stackoverflow.com/a/65347893/3474615
362
+ const { stdout } = yield (0, execa_1.default)('sysctl', ['-n', 'sysctl.proc_translated']).catch(() => ({ stdout: '' }));
363
+ debug('rosetta check result: %o', { stdout });
364
+ if (stdout === '1')
365
+ return 'arm64';
366
+ }
367
+ if (osPlatform === 'linux') {
368
+ // could possibly be x64 node on arm64 linux, check the "machine hardware name"
369
+ // list of names for reference: https://stackoverflow.com/a/45125525/3474615
370
+ const { stdout } = yield (0, execa_1.default)('uname', ['-m']).catch(() => ({ stdout: '' }));
371
+ debug('arm uname -m result: %o ', { stdout });
372
+ if (['aarch64_be', 'aarch64', 'armv8b', 'armv8l'].includes(stdout))
373
+ return 'arm64';
374
+ }
375
+ // eslint-disable-next-line no-restricted-syntax
376
+ const pkgArch = (0, arch_1.default)();
377
+ if (pkgArch === 'x86')
378
+ return 'ia32';
379
+ return pkgArch;
380
+ });
381
+ }
382
+ return (this._cachedArch = yield _getRealArch());
376
383
  });
377
- if (['aarch64_be', 'aarch64', 'armv8b', 'armv8l'].includes(stdout)) return 'arm64';
378
- }
379
-
380
- // eslint-disable-next-line no-restricted-syntax
381
- const pkgArch = arch();
382
- if (pkgArch === 'x86') return 'ia32';
383
- return pkgArch;
384
- }
385
- return this._cachedArch = await _getRealArch();
386
- },
387
- // attention:
388
- // when passing relative path to NPM post install hook, the current working
389
- // directory is set to the `node_modules/cypress` folder
390
- // the user is probably passing relative path with respect to root package folder
391
- formAbsolutePath(filename) {
392
- if (path.isAbsolute(filename)) {
393
- return filename;
394
- }
395
- return path.join(process.cwd(), '..', '..', filename);
396
- },
397
- getEnv(varName, trim) {
398
- la(is.unemptyString(varName), 'expected environment variable name, not', varName);
399
- const configVarName = `npm_config_${varName}`;
400
- const configVarNameLower = configVarName.toLowerCase();
401
- const packageConfigVarName = `npm_package_config_${varName}`;
402
- let result;
403
- if (process.env.hasOwnProperty(varName)) {
404
- debug(`Using ${varName} from environment variable`);
405
- result = process.env[varName];
406
- } else if (process.env.hasOwnProperty(configVarName)) {
407
- debug(`Using ${varName} from npm config`);
408
- result = process.env[configVarName];
409
- } else if (process.env.hasOwnProperty(configVarNameLower)) {
410
- debug(`Using ${varName.toLowerCase()} from npm config`);
411
- result = process.env[configVarNameLower];
412
- } else if (process.env.hasOwnProperty(packageConfigVarName)) {
413
- debug(`Using ${varName} from package.json config`);
414
- result = process.env[packageConfigVarName];
415
- }
416
-
417
- // environment variables are often set double quotes to escape characters
418
- // and on Windows it can lead to weird things: for example
419
- // set FOO="C:\foo.txt" && node -e "console.log('>>>%s<<<', process.env.FOO)"
420
- // will print
421
- // >>>"C:\foo.txt" <<<
422
- // see https://github.com/cypress-io/cypress/issues/4506#issuecomment-506029942
423
- // so for sanity sake we should first trim whitespace characters and remove
424
- // double quotes around environment strings if the caller is expected to
425
- // use this environment string as a file path
426
- return trim ? dequote(_.trim(result)) : result;
427
- },
428
- getCacheDir() {
429
- return cachedir('Cypress');
430
- },
431
- isPostInstall() {
432
- return process.env.npm_lifecycle_event === 'postinstall';
433
- },
434
- exec: execa,
435
- stdoutLineMatches,
436
- issuesUrl,
437
- isBrokenGtkDisplay,
438
- logBrokenGtkDisplayWarning,
439
- isPossibleLinuxWithIncorrectDisplay,
440
- getGitHubIssueUrl(number) {
441
- la(is.positive(number), 'github issue should be a positive number', number);
442
- la(_.isInteger(number), 'github issue should be an integer', number);
443
- return `${issuesUrl}/${number}`;
444
- },
445
- getFileChecksum,
446
- getFileSize,
447
- getApplicationDataFolder
384
+ },
385
+ // attention:
386
+ // when passing relative path to NPM post install hook, the current working
387
+ // directory is set to the `node_modules/cypress` folder
388
+ // the user is probably passing relative path with respect to root package folder
389
+ formAbsolutePath(filename) {
390
+ if (path_1.default.isAbsolute(filename)) {
391
+ return filename;
392
+ }
393
+ return path_1.default.join(process.cwd(), '..', '..', filename);
394
+ },
395
+ getEnv(varName, trim) {
396
+ (0, lazy_ass_1.default)(check_more_types_1.default.unemptyString(varName), 'expected environment variable name, not', varName);
397
+ const configVarName = `npm_config_${varName}`;
398
+ const configVarNameLower = configVarName.toLowerCase();
399
+ const packageConfigVarName = `npm_package_config_${varName}`;
400
+ let result;
401
+ if (process.env.hasOwnProperty(varName)) {
402
+ debug(`Using ${varName} from environment variable`);
403
+ result = process.env[varName];
404
+ }
405
+ else if (process.env.hasOwnProperty(configVarName)) {
406
+ debug(`Using ${varName} from npm config`);
407
+ result = process.env[configVarName];
408
+ }
409
+ else if (process.env.hasOwnProperty(configVarNameLower)) {
410
+ debug(`Using ${varName.toLowerCase()} from npm config`);
411
+ result = process.env[configVarNameLower];
412
+ }
413
+ else if (process.env.hasOwnProperty(packageConfigVarName)) {
414
+ debug(`Using ${varName} from package.json config`);
415
+ result = process.env[packageConfigVarName];
416
+ }
417
+ // environment variables are often set double quotes to escape characters
418
+ // and on Windows it can lead to weird things: for example
419
+ // set FOO="C:\foo.txt" && node -e "console.log('>>>%s<<<', process.env.FOO)"
420
+ // will print
421
+ // >>>"C:\foo.txt" <<<
422
+ // see https://github.com/cypress-io/cypress/issues/4506#issuecomment-506029942
423
+ // so for sanity sake we should first trim whitespace characters and remove
424
+ // double quotes around environment strings if the caller is expected to
425
+ // use this environment string as a file path
426
+ return trim && (result !== null && result !== undefined) ? dequote(lodash_1.default.trim(result)) : result;
427
+ },
428
+ getCacheDir() {
429
+ return (0, cachedir_1.default)('Cypress');
430
+ },
431
+ isPostInstall() {
432
+ return process.env.npm_lifecycle_event === 'postinstall';
433
+ },
434
+ exec: execa_1.default,
435
+ stdoutLineMatches,
436
+ issuesUrl,
437
+ isBrokenGtkDisplay,
438
+ logBrokenGtkDisplayWarning,
439
+ isPossibleLinuxWithIncorrectDisplay,
440
+ getGitHubIssueUrl(number) {
441
+ // @ts-expect-error method exists but is not typed
442
+ (0, lazy_ass_1.default)(check_more_types_1.default.positive(number), 'github issue should be a positive number', number);
443
+ (0, lazy_ass_1.default)(lodash_1.default.isInteger(number), 'github issue should be an integer', number);
444
+ return `${issuesUrl}/${number}`;
445
+ },
446
+ getFileChecksum,
447
+ getFileSize,
448
+ getApplicationDataFolder,
448
449
  };
449
- module.exports = util;
450
+ exports.default = util;