@automattic/vip 3.0.0 → 3.1.1-dev.1

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.
@@ -31,11 +31,11 @@ const examples = [{
31
31
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
32
32
  await (0, _devEnvironmentCli.validateDependencies)(lando, slug);
33
33
  const startProcessing = new Date();
34
- const versions = await lando.engine.daemon.getVersions();
35
34
  const trackingInfo = (0, _devEnvironmentCli.getEnvTrackingInfo)(slug);
36
35
  trackingInfo.vscode = Boolean(opt.vscode);
37
- trackingInfo.docker = versions.engine;
38
- trackingInfo.docker_compose = versions.compose;
36
+ trackingInfo.docker = lando.config.versions.engine;
37
+ trackingInfo.docker_compose = lando.config.versions.compose;
38
+ trackingInfo.compose_plugin = lando.config.versions.composePlugin;
39
39
  await (0, _tracker.trackEvent)('dev_env_start_command_execute', trackingInfo);
40
40
  debug('Args: ', arg, 'Options: ', opt);
41
41
  const options = {
@@ -13,6 +13,7 @@ var _tracker = require("../lib/tracker");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
14
  // eslint-disable-next-line no-duplicate-imports
15
15
 
16
+ const API_VERSION = 'v2';
16
17
  const appQuery = `
17
18
  id,
18
19
  name,
@@ -116,7 +117,8 @@ Importing Media into your App...
116
117
  environmentId: env.id,
117
118
  archiveUrl: url,
118
119
  overwriteExistingFiles,
119
- importIntermediateImages
120
+ importIntermediateImages,
121
+ apiVersion: API_VERSION
120
122
  }
121
123
  }
122
124
  });
@@ -126,7 +126,6 @@ const verifyDNSResolution = async slug => {
126
126
  const validateDependencies = async (lando, slug) => {
127
127
  const now = new Date();
128
128
  (0, _devEnvironmentLando.validateDockerInstalled)(lando);
129
- await (0, _devEnvironmentLando.validateDockerAccess)(lando);
130
129
  if (slug) {
131
130
  await verifyDNSResolution(slug);
132
131
  }
@@ -12,7 +12,6 @@ exports.landoRebuild = landoRebuild;
12
12
  exports.landoShell = landoShell;
13
13
  exports.landoStart = landoStart;
14
14
  exports.landoStop = landoStop;
15
- exports.validateDockerAccess = validateDockerAccess;
16
15
  exports.validateDockerInstalled = validateDockerInstalled;
17
16
  var _chalk = _interopRequireDefault(require("chalk"));
18
17
  var _debug = _interopRequireDefault(require("debug"));
@@ -24,6 +23,7 @@ var _promises = require("node:dns/promises");
24
23
  var _promises2 = require("node:fs/promises");
25
24
  var _nodeOs = require("node:os");
26
25
  var _nodePath = _interopRequireWildcard(require("node:path"));
26
+ var _semver = require("semver");
27
27
  var _xdgBasedir = _interopRequireDefault(require("xdg-basedir"));
28
28
  var _devEnvironmentCore = require("./dev-environment-core");
29
29
  var _dockerUtils = require("./docker-utils");
@@ -180,11 +180,13 @@ async function bootstrapLando() {
180
180
  registryResolvable = false;
181
181
  }
182
182
  const pull = registryResolvable && (instanceData.pullAfter ?? 0) < Date.now();
183
+ console.log(pull);
183
184
  if (Array.isArray(data.opts.pullable) && Array.isArray(data.opts.local) && data.opts.local.length === 0 && !pull) {
184
185
  // Setting `data.opts.pullable` to an empty array prevents Lando from pulling images with `docker pull`.
185
186
  // Note that if some of the images are not available, they will still be pulled by `docker-compose`.
186
187
  data.opts.local = data.opts.pullable;
187
188
  data.opts.pullable = [];
189
+ console.log(data.opts);
188
190
  }
189
191
  if (pull || !instanceData.pullAfter) {
190
192
  instanceData.pullAfter = Date.now() + 7 * 24 * 60 * 60 * 1000;
@@ -534,21 +536,26 @@ async function ensureNoOrphantProxyContainer(lando) {
534
536
  await proxyContainer.remove();
535
537
  }
536
538
  function validateDockerInstalled(lando) {
537
- lando.log.verbose('docker-engine exists: %s', lando.engine.dockerInstalled);
538
- if (!lando.engine.dockerInstalled) {
539
- throw new _userError.default('docker could not be located! Please follow the following instructions to install it - https://docs.docker.com/engine/install/');
540
- }
541
- lando.log.verbose('docker-compose exists: %s', lando.engine.composeInstalled);
542
- if (!lando.engine.composeInstalled) {
543
- throw Error('docker-compose could not be located! Please follow the following instructions to install it - https://docs.docker.com/compose/install/');
544
- }
545
- }
546
- async function validateDockerAccess(lando) {
547
- const docker = lando.engine.docker;
548
- lando.log.verbose('Fetching docker info to verify Docker connection');
549
- try {
550
- await docker.info();
551
- } catch (error) {
539
+ const {
540
+ engine,
541
+ composePlugin,
542
+ compose
543
+ } = lando.config.versions;
544
+ lando.log.verbose('docker-engine version: %s', engine);
545
+ if (!engine) {
546
+ if (!lando.config.dockerBin) {
547
+ throw new _userError.default('docker binary could not be located! Please follow the following instructions to install it - https://docs.docker.com/engine/install/');
548
+ }
552
549
  throw new _userError.default('Failed to connect to Docker. Please verify that Docker engine (service) is running and follow the troubleshooting instructions for your platform.');
553
550
  }
551
+ lando.log.verbose('docker-compose version: %s', compose);
552
+ lando.log.verbose('compose plugin version: %s', composePlugin);
553
+ if (!composePlugin) {
554
+ if (!compose) {
555
+ throw new Error('docker-compose binary could not be located! Please follow the following instructions to install it - https://docs.docker.com/compose/install/');
556
+ }
557
+ if (!(0, _semver.satisfies)(compose, '^2.0.0')) {
558
+ throw new Error(`docker-compose version ${compose} is not supported. Please upgrade to version 2.0.0 or higher - https://docs.docker.com/compose/install/`);
559
+ }
560
+ }
554
561
  }
@@ -5,6 +5,7 @@ exports.default = void 0;
5
5
  exports.getGlyphForStatus = getGlyphForStatus;
6
6
  exports.mediaImportCheckStatus = mediaImportCheckStatus;
7
7
  var _chalk = _interopRequireDefault(require("chalk"));
8
+ var _enquirer = require("enquirer");
8
9
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
9
10
  var _promises = require("node:fs/promises");
10
11
  var _nodePath = require("node:path");
@@ -36,6 +37,7 @@ const IMPORT_MEDIA_PROGRESS_QUERY = (0, _graphqlTag.default)`
36
37
  fileName
37
38
  errors
38
39
  }
40
+ fileErrorsUrl
39
41
  }
40
42
  }
41
43
  }
@@ -216,25 +218,83 @@ ${maybeExitPrompt}
216
218
  // Kick off the check
217
219
  void checkStatus(IMPORT_MEDIA_PROGRESS_POLL_INTERVAL);
218
220
  });
221
+ async function exportFailureDetails(fileErrors) {
222
+ const formattedData = buildFileErrors(fileErrors, exportFileErrorsToJson);
223
+ const errorsFile = `media-import-${app.name ?? ''}-${Date.now()}${exportFileErrorsToJson ? '.json' : '.txt'}`;
224
+ try {
225
+ await (0, _promises.writeFile)(errorsFile, formattedData);
226
+ progressTracker.suffix += `${_chalk.default.yellow(`⚠️ All errors have been exported to ${_chalk.default.bold((0, _nodePath.resolve)(errorsFile))}\n`)}`;
227
+ } catch (writeFileErr) {
228
+ progressTracker.suffix += `${_chalk.default.red(`Could not export errors to file\n${writeFileErr.message}`)}`;
229
+ }
230
+ }
231
+ async function fetchFailureDetails(fileErrorsUrl) {
232
+ progressTracker.suffix += `
233
+ =============================================================
234
+ Downloading errors details from ${fileErrorsUrl}
235
+ \n`;
236
+ progressTracker.print({
237
+ clearAfter: true
238
+ });
239
+ try {
240
+ const response = await fetch(fileErrorsUrl);
241
+ return await response.json();
242
+ } catch (err) {
243
+ progressTracker.suffix += `${_chalk.default.red(`Could not download import errors report\n${err.message}`)}`;
244
+ throw err;
245
+ }
246
+ }
247
+ async function promptFailureDetailsDownload(fileErrorsUrl) {
248
+ const failureDetails = await (0, _enquirer.prompt)({
249
+ type: 'confirm',
250
+ name: 'download',
251
+ message: 'Download import errors report now? (Report will be downloadable for up to 7 days from the completion of the import)'
252
+ });
253
+ if (!failureDetails.download) {
254
+ progressTracker.suffix += `${_chalk.default.yellow(`⚠️ An error report file has been generated for this media import. Access it within the next 15 minutes by clicking on the URL below.`)}`;
255
+ progressTracker.suffix += `\n${_chalk.default.yellow(`Or, generate a new URL by running the ${_chalk.default.bgYellow('vip import media status')} command.`)} `;
256
+ progressTracker.suffix += `\n${_chalk.default.yellow('The report will be downloadable for up to 7 days after the completion of the import or until a new media import is performed.')}`;
257
+ progressTracker.suffix += `\n\n${_chalk.default.underline(fileErrorsUrl)}\n`;
258
+ progressTracker.print({
259
+ clearAfter: true
260
+ });
261
+ return;
262
+ }
263
+ const failureDetailsErrors = await fetchFailureDetails(fileErrorsUrl);
264
+ await exportFailureDetails(failureDetailsErrors);
265
+ }
266
+ function printFileErrorsReportLinkExpiredError(results) {
267
+ if (results.filesTotal && results.filesProcessed && results.filesTotal !== results.filesProcessed) {
268
+ const errorsFound = results.filesTotal - results.filesProcessed;
269
+ progressTracker.suffix += `${_chalk.default.yellow(`⚠️ ${errorsFound} error(s) were found. File import errors report link expired.`)}`;
270
+ }
271
+ }
272
+ async function printFailureDetails(fileErrors, results) {
273
+ progressTracker.suffix += `${_chalk.default.yellow(`⚠️ ${fileErrors.length} file import error(s) were found`)}`;
274
+ if ((results.filesTotal ?? 0) - (results.filesProcessed ?? 0) !== fileErrors.length) {
275
+ progressTracker.suffix += `. ${_chalk.default.italic.yellow('File import errors report size threshold reached.')}`;
276
+ }
277
+ await exportFailureDetails(fileErrors);
278
+ }
219
279
  try {
220
280
  const results = await getResults();
221
281
  overallStatus = results.status ?? 'unknown';
222
282
  progressTracker.stopPrinting();
223
283
  setProgressTrackerSuffix();
224
284
  progressTracker.print();
225
- const fileErrors = results.failureDetails?.fileErrors ?? [];
226
- if (fileErrors.length > 0) {
227
- progressTracker.suffix += `${_chalk.default.yellow(`⚠️ ${fileErrors.length} file error(s) have been extracted`)}`;
228
- if ((results.filesTotal ?? 0) - (results.filesProcessed ?? 0) !== fileErrors.length) {
229
- progressTracker.suffix += `. ${_chalk.default.italic.yellow('File-errors report size threshold reached.')}`;
230
- }
231
- const formattedData = buildFileErrors(fileErrors, exportFileErrorsToJson);
232
- const errorsFile = `media-import-${app.name ?? ''}-${Date.now()}${exportFileErrorsToJson ? '.json' : '.txt'}`;
233
- try {
234
- await (0, _promises.writeFile)(errorsFile, formattedData);
235
- progressTracker.suffix += `\n\n${_chalk.default.yellow(`All errors have been exported to ${_chalk.default.bold((0, _nodePath.resolve)(errorsFile))}`)}\n\n`;
236
- } catch (writeFileErr) {
237
- progressTracker.suffix += `\n\n${_chalk.default.red(`Could not export errors to file\n${writeFileErr.message}`)}\n\n`;
285
+ if (results.failureDetails?.fileErrorsUrl) {
286
+ await promptFailureDetailsDownload(results.failureDetails.fileErrorsUrl);
287
+ } else {
288
+ const fileErrors = results.failureDetails?.fileErrors ?? [];
289
+ if (fileErrors.length > 0) {
290
+ // Errors were observed and are present in the dto
291
+ // Fall back to exporting errors to local file
292
+ await printFailureDetails(fileErrors, results);
293
+ } else if ('ABORTED' !== overallStatus) {
294
+ // Errors are not present in the dto
295
+ // And file error details report link is not available
296
+ // do not print this message if the import was aborted
297
+ printFileErrorsReportLinkExpiredError(results);
238
298
  }
239
299
  }
240
300
 
package/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  ## Changelog
2
2
 
3
+ ### 3.1.0
4
+
5
+ * Integrate Media Import v2 flow and expand on media import error report messaging
6
+
7
+ **Full Changelog**: https://github.com/Automattic/vip-cli/compare/3.0.0...3.1.0
8
+
9
+ ### 3.0.0
10
+
11
+ * fix(dev-env): demo code is displayed as `[demo-image]`
12
+ * build(deps-dev): bump @types/node from 18.19.33 to 18.19.34
13
+ * build(deps): bump debug from 4.3.4 to 4.3.5
14
+ * ci: remove duplicate check
15
+ * Update the dev-env commands to follow the VIP-CLI style guide
16
+ * build(deps-dev): bump the babel group with 4 updates
17
+ * ci: add publish prerelease workflow
18
+ * build(deps): bump step-security/harden-runner from 2.7.1 to 2.8.0
19
+ * build(deps): bump ini from 4.1.2 to 4.1.3
20
+
21
+ **Full Changelog**: https://github.com/Automattic/vip-cli/compare/2.39.7...3.0.0
22
+
3
23
  ### 2.39.7
4
24
 
5
25
  * Fix promptForBoolean to display the default initial value capitalized