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