@automattic/vip 2.33.0 → 2.35.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.
@@ -9,18 +9,13 @@ var _chalk = _interopRequireDefault(require("chalk"));
9
9
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
10
10
  var _debug = _interopRequireDefault(require("debug"));
11
11
  var _api = _interopRequireDefault(require("../../lib/api"));
12
- var _dbFileImport = require("../../lib/site-import/db-file-import");
13
- var _progress = require("../../lib/cli/progress");
14
12
  var exit = _interopRequireWildcard(require("../../lib/cli/exit"));
15
13
  var _format = require("../../lib/cli/format");
14
+ var _dbFileImport = require("./db-file-import");
16
15
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- /**
20
- *
21
- * @format
22
- */
23
-
18
+ /* eslint-disable complexity */
24
19
  /**
25
20
  * External dependencies
26
21
  */
@@ -72,6 +67,7 @@ const IMPORT_SQL_PROGRESS_QUERY = (0, _graphqlTag.default)`
72
67
  }
73
68
  `;
74
69
  async function getStatus(api, appId, envId) {
70
+ var _response$data$app;
75
71
  const response = await api.query({
76
72
  query: IMPORT_SQL_PROGRESS_QUERY,
77
73
  variables: {
@@ -80,17 +76,11 @@ async function getStatus(api, appId, envId) {
80
76
  },
81
77
  fetchPolicy: 'network-only'
82
78
  });
83
- const {
84
- data: {
85
- app: {
86
- environments
87
- }
88
- }
89
- } = response;
90
- if (!(environments !== null && environments !== void 0 && environments.length)) {
79
+ const environments = ((_response$data$app = response.data.app) === null || _response$data$app === void 0 ? void 0 : _response$data$app.environments) ?? [];
80
+ if (!environments.length) {
91
81
  throw new Error('Unable to determine import status from environment');
92
82
  }
93
- const [environment] = environments;
83
+ const environment = environments[0] ?? {};
94
84
  const {
95
85
  importStatus,
96
86
  jobs,
@@ -99,7 +89,7 @@ async function getStatus(api, appId, envId) {
99
89
  if (!environment.isK8sResident && !(jobs !== null && jobs !== void 0 && jobs.length)) {
100
90
  return {};
101
91
  }
102
- const [importJob] = jobs;
92
+ const [importJob] = jobs ?? [];
103
93
  return {
104
94
  importStatus,
105
95
  importJob,
@@ -178,6 +168,7 @@ async function importSqlCheckStatus({
178
168
  let completedAt;
179
169
  let overallStatus = 'Checking...';
180
170
  const setProgressTrackerSuffix = () => {
171
+ var _env$primaryDomain;
181
172
  const sprite = (0, _format.getGlyphForStatus)(overallStatus, progressTracker.runningSprite);
182
173
  const formattedCreatedAt = createdAt ? `${new Date(createdAt).toLocaleString()} (${createdAt})` : 'TBD';
183
174
  const formattedCompletedAt = createdAt && completedAt ? `${new Date(completedAt).toLocaleString()} (${completedAt})` : 'TBD';
@@ -185,7 +176,7 @@ async function importSqlCheckStatus({
185
176
  let statusMessage;
186
177
  switch (overallStatus) {
187
178
  case 'success':
188
- statusMessage = `Success ${sprite} imported data should be visible on your site ${env.primaryDomain.name}.`;
179
+ statusMessage = `Success ${sprite} imported data should be visible on your site ${((_env$primaryDomain = env.primaryDomain) === null || _env$primaryDomain === void 0 ? void 0 : _env$primaryDomain.name) ?? 'N/A'}.`;
189
180
  break;
190
181
  case 'running':
191
182
  if (progressTracker.allStepsSucceeded()) {
@@ -205,7 +196,7 @@ SQL Import Completed: ${formattedCompletedAt}`;
205
196
  const suffix = `
206
197
  =============================================================
207
198
  Status: ${statusMessage}
208
- Site: ${app.name} (${(0, _format.formatEnvironment)(env.type)})${maybeTimestamps}
199
+ Site: ${app.name ?? 'N/A'} (${(0, _format.formatEnvironment)(env.type ?? 'N/A')})${maybeTimestamps}
209
200
  =============================================================
210
201
  ${maybeExitPrompt}
211
202
  `;
@@ -221,7 +212,7 @@ ${maybeExitPrompt}
221
212
  var _importJob$progress, _importJob$progress2;
222
213
  let status;
223
214
  try {
224
- status = await getStatus(api, app.id, env.id);
215
+ status = await getStatus(api, app.id ?? -1, env.id ?? -1);
225
216
  } catch (error) {
226
217
  return reject({
227
218
  error
@@ -246,13 +237,15 @@ ${maybeExitPrompt}
246
237
 
247
238
  // if the progress meta isn't filled out yet, wait until it is.
248
239
  if (!statusSteps) {
249
- return setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL); // NOSONAR
240
+ return setTimeout(() => {
241
+ void checkStatus();
242
+ }, IMPORT_SQL_PROGRESS_POLL_INTERVAL);
250
243
  }
251
-
252
244
  jobSteps = statusSteps.map(step => {
245
+ var _step$name;
253
246
  return {
254
247
  id: step.name,
255
- name: (0, _format.capitalize)(step.name.replace(/_/g, ' ')),
248
+ name: (0, _format.capitalize)((_step$name = step.name) === null || _step$name === void 0 ? void 0 : _step$name.replace(/_/g, ' ')),
256
249
  status: step.result
257
250
  };
258
251
  });
@@ -267,7 +260,8 @@ ${maybeExitPrompt}
267
260
  result
268
261
  }) => result === 'success')) {
269
262
  jobStatus = 'success';
270
- importJob.completedAt = new Date(Math.max(...statusSteps.map(step => step.finished_at), 0) * 1000).toUTCString();
263
+ const timestamps = statusSteps.map(step => step.finished_at).filter(Boolean);
264
+ importJob.completedAt = new Date(Math.max(...timestamps, 0) * 1000).toUTCString();
271
265
  }
272
266
  if (importStatus !== null && importStatus !== void 0 && (_importStatus$progres2 = importStatus.progress) !== null && _importStatus$progres2 !== void 0 && _importStatus$progres2.started_at) {
273
267
  importJob.createdAt = new Date(importStatus.progress.started_at * 1000).toUTCString();
@@ -288,7 +282,7 @@ ${maybeExitPrompt}
288
282
  dbOperationInProgress,
289
283
  importInProgress,
290
284
  progress: importStepProgress
291
- } = importStatus;
285
+ } = importStatus ?? {};
292
286
  debug({
293
287
  jobStatus,
294
288
  completedAt,
@@ -299,14 +293,15 @@ ${maybeExitPrompt}
299
293
  });
300
294
  let jobCreationTime;
301
295
  try {
302
- jobCreationTime = new Date(createdAt).getTime();
296
+ jobCreationTime = new Date(createdAt ?? '').getTime();
303
297
  } catch (err) {
304
298
  debug('Unable to parse createdAt to a Date');
305
299
  }
306
300
  let failedImportStep;
307
- if (jobCreationTime && (importStepProgress === null || importStepProgress === void 0 ? void 0 : importStepProgress.started_at) * 1000 >= jobCreationTime) {
301
+ if (jobCreationTime && ((importStepProgress === null || importStepProgress === void 0 ? void 0 : importStepProgress.started_at) ?? 0) * 1000 >= jobCreationTime) {
302
+ var _importStepProgress$s;
308
303
  // The contents of the `import_progress` meta are pertinent to the most recent import job
309
- failedImportStep = importStepProgress.steps.find(step => (step === null || step === void 0 ? void 0 : step.result) === 'failed' && 1000 * (step === null || step === void 0 ? void 0 : step.started_at) > new Date(createdAt).getTime());
304
+ failedImportStep = importStepProgress === null || importStepProgress === void 0 || (_importStepProgress$s = importStepProgress.steps) === null || _importStepProgress$s === void 0 ? void 0 : _importStepProgress$s.find(step => (step === null || step === void 0 ? void 0 : step.result) === 'failed' && 1000 * (step.started_at ?? 0) > new Date(createdAt ?? '').getTime());
310
305
  }
311
306
  if (!jobSteps.length) {
312
307
  return reject({
@@ -317,9 +312,7 @@ ${maybeExitPrompt}
317
312
  if (failedImportStep) {
318
313
  // The server marks the step as a success as per the host action, demote it to 'failed'
319
314
  const _jobSteps = [...jobSteps];
320
- const failedJobStepIndex = _jobSteps.findIndex(({
321
- id
322
- }) => id === 'import');
315
+ const failedJobStepIndex = _jobSteps.findIndex(step => (step === null || step === void 0 ? void 0 : step.id) === 'import');
323
316
  _jobSteps[failedJobStepIndex] = {
324
317
  ..._jobSteps[failedJobStepIndex],
325
318
  status: 'failed'
@@ -332,7 +325,6 @@ ${maybeExitPrompt}
332
325
  commandOutput: failedImportStep.output,
333
326
  error: 'Import step failed',
334
327
  stepName: failedImportStep.name,
335
- errorText: failedImportStep.error,
336
328
  launched
337
329
  });
338
330
  }
@@ -349,7 +341,9 @@ ${maybeExitPrompt}
349
341
  return resolve(importJob);
350
342
  }
351
343
  overallStatus = 'running';
352
- setTimeout(checkStatus, IMPORT_SQL_PROGRESS_POLL_INTERVAL); // NOSONAR
344
+ setTimeout(() => {
345
+ void checkStatus();
346
+ }, IMPORT_SQL_PROGRESS_POLL_INTERVAL);
353
347
  };
354
348
 
355
349
  // Kick off the check
@@ -361,7 +355,7 @@ ${maybeExitPrompt}
361
355
  overallStatus = results;
362
356
  } else {
363
357
  var _results$progress;
364
- overallStatus = (results === null || results === void 0 || (_results$progress = results.progress) === null || _results$progress === void 0 ? void 0 : _results$progress.status) || 'unknown';
358
+ overallStatus = ((_results$progress = results.progress) === null || _results$progress === void 0 ? void 0 : _results$progress.status) ?? 'unknown';
365
359
  // This shouldn't be 'unknown'...what should we do here?
366
360
  }
367
361
 
package/dist/lib/utils.js CHANGED
@@ -56,11 +56,16 @@ function makeTempDir(prefix = 'vip-cli') {
56
56
  const tempDir = _fs.default.mkdtempSync(_path.default.join(_os.default.tmpdir(), `${prefix}-`));
57
57
  debug(`Created a directory to hold temporary files: ${tempDir}`);
58
58
  process.on('exit', () => {
59
- _fs.default.rmSync(tempDir, {
60
- recursive: true,
61
- force: true
62
- });
63
- debug(`Removed temporary directory: ${tempDir}`);
59
+ try {
60
+ _fs.default.rmSync(tempDir, {
61
+ recursive: true,
62
+ force: true,
63
+ maxRetries: 10
64
+ });
65
+ debug(`Removed temporary directory: ${tempDir}`);
66
+ } catch (err) {
67
+ console.warn(`Failed to remove temporary directory ${tempDir} (${err.message})`);
68
+ }
64
69
  });
65
70
  return tempDir;
66
71
  }
@@ -69,7 +69,7 @@ async function isMultiSiteInSiteMeta(appId, envId) {
69
69
  }
70
70
  if (Array.isArray((_res$data$app = res.data.app) === null || _res$data$app === void 0 ? void 0 : _res$data$app.environments)) {
71
71
  const environments = res.data.app.environments;
72
- if (!environments.length) {
72
+ if (!(environments !== null && environments !== void 0 && environments.length)) {
73
73
  isMultiSite.set(args, false);
74
74
  return false;
75
75
  }
@@ -119,7 +119,7 @@ async function isMultisitePrimaryDomainMapped(appId, envId, primaryDomain) {
119
119
  return false;
120
120
  }
121
121
  const environments = res.data.app.environments;
122
- if (!environments.length) {
122
+ if (!(environments !== null && environments !== void 0 && environments.length)) {
123
123
  return false;
124
124
  }
125
125
  const mappedDomains = ((_environments$ = environments[0]) === null || _environments$ === void 0 || (_environments$ = _environments$.domains) === null || _environments$ === void 0 || (_environments$ = _environments$.nodes) === null || _environments$ === void 0 ? void 0 : _environments$.map(domain => domain === null || domain === void 0 ? void 0 : domain.name)) ?? [];
@@ -1,5 +1,4 @@
1
- const util = require( 'node:util' );
2
- const check = util.promisify( require( 'check-node-version' ) );
1
+ const { minVersion, satisfies, valid } = require( 'semver' );
3
2
  const { exec } = require( 'node:child_process' );
4
3
  const { EOL } = require( 'node:os' );
5
4
  const packageJSON = require( '../package.json' );
@@ -34,11 +33,15 @@ const releaseTag = process.env.npm_config_tag ?? 'latest';
34
33
  }
35
34
 
36
35
  if ( config.nodeEnforceVersion ) {
37
- const { isSatisfied, versions } = await check( { node: config.nodeEnforceVersion } );
36
+ const supported = packageJSON.engines.node;
37
+ const current = process.versions.node ?? process.version;
38
+ const isSatisfied = satisfies( current, supported );
38
39
 
39
40
  if ( ! isSatisfied ) {
40
41
  return bail(
41
- `Node version ${ versions.node.version } is not supported. Please use Node version ${ config.nodeEnforceVersion } or higher.`
42
+ `Node version ${ valid( current ) } is not supported. Please use Node version ${ valid(
43
+ minVersion( supported )
44
+ ) } or higher.`
42
45
  );
43
46
  }
44
47
  }