@automattic/vip 2.9.1 → 2.9.2

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/README.md CHANGED
@@ -26,6 +26,13 @@ For help with contributing to this project, including instructions for local dev
26
26
  By default, we record information about the usage of this tool using an in-house analytics sytem. If you would prefer to opt-out of this data collection, you can do so via the `DO_NOT_TRACK` environment variable. You may either export it in your shell configuration or specify it on the command line (e.g. `DO_NOT_TRACK=1 vip app list`).
27
27
 
28
28
  ## Changelog
29
+ ### 2.9.2 (9 March 2022)
30
+ - #980 [dev-env] Fix/tag formatting on stapled images
31
+ - #986 Clean the build folder prior to rebuilding it
32
+ - #985 Adding webP to the list of accepted extensions for files
33
+ - #972 Run tests in Windows Env
34
+
35
+ https://github.com/Automattic/vip/releases/tag/v2.9.2
29
36
 
30
37
  ### 2.9.1 (2 March 2022)
31
38
  - #982 Remove unused dependencies - Fixes Error: Cannot find module 'core-js'
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DEV_ENVIRONMENT_WORDPRESS_VERSION_FILE = exports.DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY = exports.DEV_ENVIRONMENT_WORDPRESS_VERSIONS_URI = exports.DEV_ENVIRONMENT_RAW_GITHUB_HOST = exports.DEV_ENVIRONMENT_COMPONENTS = exports.DEV_ENVIRONMENT_NOT_FOUND = exports.DEV_ENVIRONMENT_PROMPT_INTRO = exports.DEV_ENVIRONMENT_DEFAULTS = exports.DEV_ENVIRONMENT_FULL_COMMAND = exports.DEV_ENVIRONMENT_SUBCOMMAND = void 0;
6
+ exports.DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY = exports.DEV_ENVIRONMENT_WORDPRESS_VERSIONS_URI = exports.DEV_ENVIRONMENT_RAW_GITHUB_HOST = exports.DEV_ENVIRONMENT_COMPONENTS = exports.DEV_ENVIRONMENT_NOT_FOUND = exports.DEV_ENVIRONMENT_PROMPT_INTRO = exports.DEV_ENVIRONMENT_DEFAULTS = exports.DEV_ENVIRONMENT_FULL_COMMAND = exports.DEV_ENVIRONMENT_SUBCOMMAND = void 0;
7
7
  const DEV_ENVIRONMENT_SUBCOMMAND = 'dev-env';
8
8
  exports.DEV_ENVIRONMENT_SUBCOMMAND = DEV_ENVIRONMENT_SUBCOMMAND;
9
9
  const DEV_ENVIRONMENT_FULL_COMMAND = `vip ${DEV_ENVIRONMENT_SUBCOMMAND}`;
@@ -26,6 +26,4 @@ exports.DEV_ENVIRONMENT_RAW_GITHUB_HOST = DEV_ENVIRONMENT_RAW_GITHUB_HOST;
26
26
  const DEV_ENVIRONMENT_WORDPRESS_VERSIONS_URI = '/Automattic/vip-container-images/master/wordpress/versions.json';
27
27
  exports.DEV_ENVIRONMENT_WORDPRESS_VERSIONS_URI = DEV_ENVIRONMENT_WORDPRESS_VERSIONS_URI;
28
28
  const DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY = 'worpress-versions.json';
29
- exports.DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY = DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY;
30
- const DEV_ENVIRONMENT_WORDPRESS_VERSION_FILE = 'wordpress/wp-includes/version.php';
31
- exports.DEV_ENVIRONMENT_WORDPRESS_VERSION_FILE = DEV_ENVIRONMENT_WORDPRESS_VERSION_FILE;
29
+ exports.DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY = DEV_ENVIRONMENT_WORDPRESS_CACHE_KEY;
@@ -338,16 +338,21 @@ async function promptForComponent(component, allowLocal, defaultObject) {
338
338
 
339
339
  if (component === 'wordpress') {
340
340
  const message = `${messagePrefix}Which version would you like`;
341
- const tagChoices = await getTagChoices(); // First tag not: "Pre-Release"
341
+ const tagChoices = await getTagChoices(); // Tag strings come back from the api with excess whitespace
342
+ // This strips the whitespace for matching to the defaultObject.tag
342
343
 
343
- const firstNonPreRelease = tagChoices.find(tag => {
344
- return !tag.match(/Pre\-Release/g);
344
+ const formatted = tagChoices.map(elm => {
345
+ return elm.trim();
346
+ }); // First tag not: "Pre-Release"
347
+
348
+ const firstNonPreRelease = formatted.find(img => {
349
+ return !img.match(/Pre\-Release/g);
345
350
  }); // Set initialTagIndex as the first non Pre-Release
346
351
 
347
- let initialTagIndex = tagChoices.indexOf(firstNonPreRelease);
352
+ let initialTagIndex = formatted.indexOf(firstNonPreRelease);
348
353
 
349
354
  if (defaultObject !== null && defaultObject !== void 0 && defaultObject.tag) {
350
- const defaultTagIndex = tagChoices.indexOf(defaultObject.tag);
355
+ const defaultTagIndex = formatted.indexOf(defaultObject.tag);
351
356
 
352
357
  if (defaultTagIndex !== -1) {
353
358
  initialTagIndex = defaultTagIndex;
@@ -356,10 +361,21 @@ async function promptForComponent(component, allowLocal, defaultObject) {
356
361
 
357
362
  const selectTag = new _enquirer.Select({
358
363
  message,
359
- choices: tagChoices,
364
+ choices: formatted,
360
365
  initial: initialTagIndex
361
366
  });
362
- const tag = await selectTag.run();
367
+ const option = await selectTag.run(); // Validate the input
368
+ // Some of the options are like: '5.7 → 5.7.5'
369
+ // Extract first occurrence of something that looks like a tag
370
+
371
+ const tagRgx = new RegExp(/(\d+\.\d+(?:\.\d+)?)/);
372
+ const match = tagRgx.exec(option);
373
+
374
+ if (!Array.isArray(match) || match.length < 2) {
375
+ throw new Error(`Invalid WordPress selection: ${option}`);
376
+ }
377
+
378
+ const tag = match[1];
363
379
  return {
364
380
  mode: modeResult,
365
381
  tag
@@ -88,9 +88,9 @@ async function startEnvironment(slug, options) {
88
88
  throw new Error(_devEnvironment.DEV_ENVIRONMENT_NOT_FOUND);
89
89
  }
90
90
 
91
- await updateWordPressImage(instancePath, options);
91
+ const updated = await updateWordPressImage(slug);
92
92
 
93
- if (options.skipRebuild) {
93
+ if (options.skipRebuild && !updated) {
94
94
  await (0, _devEnvironmentLando.landoStart)(instancePath);
95
95
  } else {
96
96
  await (0, _devEnvironmentLando.landoRebuild)(instancePath);
@@ -466,20 +466,29 @@ async function importMediaPath(slug, filePath) {
466
466
  * - If there is a newer version of the WordPress version currently used
467
467
  * - A choice to use a different image
468
468
  *
469
- * @param {Object=} instancePath Path to local profile
470
- * @param {Object=} options options
469
+ * @param {Object=} slug slug
470
+ * @return {boolean} boolean
471
471
  */
472
472
 
473
473
 
474
- async function updateWordPressImage(instancePath, options) {
474
+ async function updateWordPressImage(slug) {
475
475
  const versions = await getVersionList();
476
476
  const refRgx = new RegExp(/\d+\.\d+(?:\.\d+)?/);
477
- const vsnRgx = new RegExp(/\$wp_version \= \'(.*)\'\;/);
478
- const landoFile = `${instancePath}/.lando.yml`;
479
- const versionFile = `${instancePath}/${_devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSION_FILE}`; // If versionFile doesn't exist it means that the environment has not been initiated.
477
+ let message, envData, currentWordPressTag; // Get the current environment configuration
480
478
 
481
- if (!_fs.default.existsSync(versionFile)) {
482
- return;
479
+ try {
480
+ envData = readEnvironmentData(slug);
481
+ currentWordPressTag = envData.wordpress.tag;
482
+ } catch (error) {
483
+ // This can throw an exception if the env is build with older vip version
484
+ if ('ENOENT' === error.code) {
485
+ message = 'Environment was created before update was supported.\n\n';
486
+ message += 'To update environment please destroy it and create a new one.';
487
+ } else {
488
+ message = `An error prevented reading the configuration of: ${slug}\n\n ${error}`;
489
+ }
490
+
491
+ (0, _devEnvironmentCli.handleCLIException)(new Error(message));
483
492
  } // filter
484
493
 
485
494
 
@@ -490,32 +499,20 @@ async function updateWordPressImage(instancePath, options) {
490
499
  filteredVersions.sort((before, after) => before.tag < after.tag ? 1 : -1); // Newest WordPress Image
491
500
 
492
501
  const newestWordPressImage = filteredVersions[0];
493
- console.log('The most recent WordPress version available is: ' + _chalk.default.green(newestWordPressImage.tag)); // Currently Used WordPress Version
494
-
495
- const code = _fs.default.readFileSync(versionFile).toString();
496
-
497
- const versionCode = vsnRgx.exec(code);
498
- let currentWordPressVersion = null;
499
-
500
- if (null === versionCode) {
501
- console.log('Cannot determine the currently installed WordPress version.');
502
- } else {
503
- currentWordPressVersion = versionCode[1];
504
- } // If the currently used version is the most up to date: exit.
505
-
502
+ console.log('The most recent WordPress version available is: ' + _chalk.default.green(newestWordPressImage.tag)); // If the currently used version is the most up to date: exit.
506
503
 
507
- if (currentWordPressVersion === newestWordPressImage.ref) {
508
- console.log('Environment WordPress version is: ' + _chalk.default.green(currentWordPressVersion) + ' ... 😎 nice! ');
509
- return;
504
+ if (currentWordPressTag === newestWordPressImage.ref) {
505
+ console.log('Environment WordPress version is: ' + _chalk.default.green(currentWordPressTag) + ' ... 😎 nice! ');
506
+ return false;
510
507
  } // Determine if there is an image available for the current WordPress version
511
508
 
512
509
 
513
510
  const match = filteredVersions.find(({
514
511
  ref
515
- }) => ref === currentWordPressVersion); // If there is no available image for the currently installed version, give user a path to change
512
+ }) => ref === currentWordPressTag); // If there is no available image for the currently installed version, give user a path to change
516
513
 
517
514
  if (typeof match === 'undefined') {
518
- console.log(`Installed WordPress: ${currentWordPressVersion} has no available container image in repository. `);
515
+ console.log(`Installed WordPress: ${currentWordPressTag} has no available container image in repository. `);
519
516
  console.log('You must select a new WordPress image to continue... ');
520
517
  } else {
521
518
  console.log('Environment WordPress version is: ' + _chalk.default.yellow(match.ref));
@@ -529,28 +526,19 @@ async function updateWordPressImage(instancePath, options) {
529
526
  }); // If the user takes the new WP version path
530
527
 
531
528
  if (confirm.upgrade) {
532
- console.log('Upgrading from: ' + _chalk.default.yellow(match.ref) + ' to:'); // Select a new image
529
+ console.log('Upgrading from: ' + _chalk.default.yellow(currentWordPressTag) + ' to:'); // Select a new image
533
530
 
534
531
  const choice = await (0, _devEnvironmentCli.promptForComponent)('wordpress');
535
532
  const version = filteredVersions.find(({
536
533
  tag
537
- }) => tag.trim() === choice.tag.trim());
538
- const selectedImage = `ghcr.io/automattic/vip-container-images/wordpress:${version.tag}`; // Change the lando file and rebuild.
539
-
540
- const data = _fs.default.readFileSync(landoFile, {
541
- encoding: 'utf8',
542
- flag: 'r'
543
- });
544
-
545
- const edit = data.replace(/ghcr\.io\/.*wordpress\:.*\d+\.\d+(?:\.\d+)?/g, selectedImage);
546
-
547
- _fs.default.writeFileSync(landoFile, edit); // Stage for rebuild
548
-
534
+ }) => tag.trim() === choice.tag.trim()); // Write new data and stage for rebuild
549
535
 
550
- options.skipRebuild = false;
536
+ envData.wordpress.tag = version.tag;
537
+ await updateEnvironment(envData);
538
+ return true;
551
539
  }
552
540
 
553
- return;
541
+ return false;
554
542
  }
555
543
  /**
556
544
  * Makes a web call to raw.githubusercontent.com
@@ -17,7 +17,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
17
17
  * External dependencies
18
18
  */
19
19
  // Accepted media file extensions
20
- const acceptedExtensions = ['jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'svg', 'tiff', 'tif', 'ico', 'asf', 'asx', 'wmv', 'wmx', 'wm', 'avi', 'divx', 'mov', 'qt', 'mpeg', 'mpg', 'mpe', 'mp4', 'm4v', 'ogv', 'webm', 'mkv', '3gp', '3gpp', '3g2', '3gp2', 'txt', 'asc', 'c', 'cc', 'h', 'srt', 'csv', 'tsv', 'ics', 'rtx', 'css', 'vtt', 'dfxp', 'mp3', 'm4a', 'm4b', 'ra', 'ram', 'wav', 'ogg', 'oga', 'mid', 'midi', 'wma', 'wax', 'mka', 'rtf', 'js', 'pdf', 'class', 'psd', 'xcf', 'doc', 'pot', 'pps', 'ppt', 'wri', 'xla', 'xls', 'xlt', 'xlw', 'mdb', 'mpp', 'docx', 'docm', 'dotx', 'dotm', 'xlsx', 'xlsm', 'xlsb', 'xltx', 'xltm', 'xlam', 'pptx', 'pptm', 'ppsx', 'ppsm', 'potx', 'potm', 'ppam', 'sldx', 'sldm', 'onetoc', ' onetoc2', 'onetmp', 'onepkg', 'oxps', 'xps', 'odt', 'odp', 'ods', 'odg', 'odc', 'odb', 'odf', 'wp', 'wpd', 'key', 'numbers', 'pages'];
20
+ const acceptedExtensions = ['jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'svg', 'tiff', 'tif', 'ico', 'asf', 'asx', 'wmv', 'wmx', 'wm', 'avi', 'divx', 'mov', 'qt', 'mpeg', 'mpg', 'mpe', 'mp4', 'm4v', 'ogv', 'webm', 'mkv', '3gp', '3gpp', '3g2', '3gp2', 'txt', 'asc', 'c', 'cc', 'h', 'srt', 'csv', 'tsv', 'ics', 'rtx', 'css', 'vtt', 'dfxp', 'mp3', 'm4a', 'm4b', 'ra', 'ram', 'wav', 'ogg', 'oga', 'mid', 'midi', 'wma', 'wax', 'mka', 'rtf', 'js', 'pdf', 'class', 'psd', 'xcf', 'doc', 'pot', 'pps', 'ppt', 'wri', 'xla', 'xls', 'xlt', 'xlw', 'mdb', 'mpp', 'docx', 'docm', 'dotx', 'dotm', 'xlsx', 'xlsm', 'xlsb', 'xltx', 'xltm', 'xlam', 'pptx', 'pptm', 'ppsx', 'ppsm', 'potx', 'potm', 'ppam', 'sldx', 'sldm', 'onetoc', ' onetoc2', 'onetmp', 'onepkg', 'oxps', 'xps', 'odt', 'odp', 'ods', 'odg', 'odc', 'odb', 'odf', 'webp', 'wp', 'wpd', 'key', 'numbers', 'pages'];
21
21
  /**
22
22
  * Character validation global variables
23
23
  *
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
@@ -5392,8 +5392,8 @@
5392
5392
  }
5393
5393
  },
5394
5394
  "cli-table": {
5395
- "version": "github:automattic/cli-table#7b14232ba779929e1859b267bf753c150d90a618",
5396
- "from": "github:automattic/cli-table#7b14232",
5395
+ "version": "git+ssh://git@github.com/automattic/cli-table.git#7b14232ba779929e1859b267bf753c150d90a618",
5396
+ "from": "cli-table@github:automattic/cli-table#7b14232",
5397
5397
  "requires": {
5398
5398
  "chalk": "^2.4.1",
5399
5399
  "wcwidth": "^1.0.1"
@@ -6602,8 +6602,8 @@
6602
6602
  "dev": true
6603
6603
  },
6604
6604
  "eslint-config-wpvip": {
6605
- "version": "github:automattic/eslint-config-wpvip#c6605d1c3a545d43ac2149cd464ec3c38ebc58d5",
6606
- "from": "github:automattic/eslint-config-wpvip#c6605d1",
6605
+ "version": "git+ssh://git@github.com/automattic/eslint-config-wpvip.git#c6605d1c3a545d43ac2149cd464ec3c38ebc58d5",
6606
+ "from": "eslint-config-wpvip@github:automattic/eslint-config-wpvip#c6605d1",
6607
6607
  "dev": true,
6608
6608
  "requires": {
6609
6609
  "eslint-config-wpcalypso": "^4.0.0"
@@ -10021,8 +10021,8 @@
10021
10021
  "dev": true
10022
10022
  },
10023
10023
  "lando": {
10024
- "version": "git+https://github.com/Automattic/lando-cli.git#57d2cd8a23e73b3e5165c3e2862b42aa0881ef2f",
10025
- "from": "git+https://github.com/Automattic/lando-cli.git#v3.5.1-patch2021_12_06",
10024
+ "version": "git+ssh://git@github.com/Automattic/lando-cli.git#57d2cd8a23e73b3e5165c3e2862b42aa0881ef2f",
10025
+ "from": "lando@git+https://github.com/Automattic/lando-cli.git#v3.5.1-patch2021_12_06",
10026
10026
  "requires": {
10027
10027
  "@lando/platformsh": "^0.6.0",
10028
10028
  "axios": "0.21.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip",
3
- "version": "2.9.1",
3
+ "version": "2.9.2",
4
4
  "description": "The VIP Javascript library & CLI",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -42,7 +42,8 @@
42
42
  },
43
43
  "scripts": {
44
44
  "test": "npm run lint && npm run flow && jest --coverage",
45
- "prepare": "npm run build",
45
+ "clean": "rimraf dist",
46
+ "prepare": "npm run clean && npm run build",
46
47
  "prepack": "npm run prepareConfig:publish",
47
48
  "postinstall": "node ./helpers/check-version.js",
48
49
  "build": "npm run prepareConfig:local && babel src -d dist",
@@ -100,7 +101,8 @@
100
101
  "jest": "27.2.1",
101
102
  "nock": "13.0.11",
102
103
  "prettier": "npm:wp-prettier@2.0.5",
103
- "publish-please": "5.5.2"
104
+ "publish-please": "5.5.2",
105
+ "rimraf": "3.0.2"
104
106
  },
105
107
  "dependencies": {
106
108
  "@apollo/client": "^3.3.6",