@automattic/vip 2.21.0 → 2.22.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  ## Changelog
2
2
 
3
+ ## 2.22.0 (2 Nov 2022)
4
+
5
+ #1165 Add caching type policy for `WPSite` data
6
+ #1164 Fix regExp to categorize multisite tables during SQL Imports
7
+ #1163 Pull correct environment's details from API when displaying Multisite SQL Import preflight details
8
+ #1159 chore(deps): Bump debug from 4.3.3 to 4.3.4
9
+ #1162 chore(deps): Bump update-notifier from 4.1.3 to 5.1.0
10
+ #1160 chore(deps): Bump json2csv from 5.0.6 to 5.0.7
11
+ #1158 chore(deps): Bump args from 5.0.1 to 5.0.3
12
+ #1157 chore(deps): Bump semver from 7.3.5 to 7.3.8
13
+ #1155 chore(deps): Bump uuid from 8.3.2 to 9.0.0
14
+ #1154 chore(deps): Update Babel-related packages
15
+ #1153 chore(deps): Fix security vulnerabilities in dependencies
16
+ #1152 ci: Update workflows
17
+ #1151 refactor(dev-env): Modify `verifyDNSResolution()` to use Promises API
18
+
3
19
  ### 2.21.0 (24 Oct 2022)
4
20
 
5
21
  - #1143 [dev-env] adds default for wordpress version prompt
@@ -27,7 +27,7 @@ services:
27
27
  ssl: true
28
28
  sslExpose: false
29
29
  services:
30
- image: ghcr.io/automattic/vip-container-images/nginx:1.21.6
30
+ image: ghcr.io/automattic/vip-container-images/nginx:1.23.2
31
31
  command: nginx -g "daemon off;"
32
32
  volumes:
33
33
  - ./nginx/extra.conf:/etc/nginx/conf.extra/extra.conf
@@ -279,6 +279,7 @@ const displayPlaybook = ({
279
279
  fileName,
280
280
  domain,
281
281
  formattedEnvironment,
282
+ unformattedEnvironment,
282
283
  isMultiSite,
283
284
  app
284
285
  }) => {
@@ -299,11 +300,12 @@ const displayPlaybook = ({
299
300
  let siteArray = [];
300
301
 
301
302
  if (isMultiSite) {
302
- var _app$environments$, _app$environments$$wp;
303
+ var _app$environments, _selectedEnvironmentO;
303
304
 
304
305
  // eslint-disable-next-line no-multi-spaces
305
306
  console.log(` multisite: ${isMultiSite.toString()}`);
306
- siteArray = app === null || app === void 0 ? void 0 : (_app$environments$ = app.environments[0]) === null || _app$environments$ === void 0 ? void 0 : (_app$environments$$wp = _app$environments$.wpSites) === null || _app$environments$$wp === void 0 ? void 0 : _app$environments$$wp.nodes;
307
+ const selectedEnvironmentObj = app === null || app === void 0 ? void 0 : (_app$environments = app.environments) === null || _app$environments === void 0 ? void 0 : _app$environments.find(env => unformattedEnvironment === env.type);
308
+ siteArray = selectedEnvironmentObj === null || selectedEnvironmentObj === void 0 ? void 0 : (_selectedEnvironmentO = selectedEnvironmentObj.wpSites) === null || _selectedEnvironmentO === void 0 ? void 0 : _selectedEnvironmentO.nodes;
307
309
  }
308
310
 
309
311
  if (!tableNames.length) {
@@ -330,9 +332,9 @@ const displayPlaybook = ({
330
332
  let siteRegex;
331
333
 
332
334
  if (wpSite.id === 1) {
333
- siteRegex = /wp_[a-z]+/i;
335
+ siteRegex = /^wp_[a-z]+/i;
334
336
  } else {
335
- siteRegex = new RegExp(`wp_${wpSite.id}_[a-z]+`, 'i');
337
+ siteRegex = new RegExp(`^wp_${wpSite.id}_[a-z]+`, 'i');
336
338
  }
337
339
 
338
340
  const tableNamesInGroup = tableNames.filter(name => siteRegex.test(name));
@@ -417,6 +419,7 @@ const displayPlaybook = ({
417
419
  fileName,
418
420
  domain,
419
421
  formattedEnvironment,
422
+ unformattedEnvironment: opts.env.type,
420
423
  isMultiSite,
421
424
  app
422
425
  }); // PROMPT TO PROCEED WITH THE IMPORT
package/dist/lib/api.js CHANGED
@@ -108,6 +108,15 @@ async function API({
108
108
  });
109
109
  return new _core.ApolloClient({
110
110
  link: _core2.ApolloLink.from([withToken, errorLink, authLink, httpLink]),
111
- cache: new _core.InMemoryCache()
111
+ cache: new _core.InMemoryCache({
112
+ typePolicies: {
113
+ WPSite: {
114
+ // By default the cache key is assumed to be `id` which is not globally unique.
115
+ // So we are using `id` + `homeUrl` to prevent clashing keys.
116
+ // Change this to `blogId` + `homeUrl` when we switch to using wpSitesSDS
117
+ keyFields: ['id', 'homeUrl']
118
+ }
119
+ }
120
+ })
112
121
  });
113
122
  }
@@ -35,6 +35,8 @@ var _path = _interopRequireDefault(require("path"));
35
35
 
36
36
  var _os = _interopRequireDefault(require("os"));
37
37
 
38
+ var _dns = _interopRequireDefault(require("dns"));
39
+
38
40
  var _progress = require("../cli/progress");
39
41
 
40
42
  var _tracker = require("../tracker");
@@ -62,7 +64,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
62
64
  * Internal dependencies
63
65
  */
64
66
  const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
65
- const DEFAULT_SLUG = 'vip-local';
67
+ const DEFAULT_SLUG = 'vip-local'; // Forward declaratrion to avoid no-use-before-define
66
68
 
67
69
  async function handleCLIException(exception, trackKey, trackBaseInfo = {}) {
68
70
  const errorPrefix = _chalk.default.red('Error:');
@@ -103,28 +105,23 @@ async function handleCLIException(exception, trackKey, trackBaseInfo = {}) {
103
105
  }
104
106
  }
105
107
 
106
- const verifyDNSResolution = slug => {
107
- const dns = require('dns');
108
-
108
+ const verifyDNSResolution = async slug => {
109
109
  const expectedIP = '127.0.0.1';
110
110
  const testDomain = `${slug}.vipdev.lndo.site`;
111
111
  const advice = `Please add following line to hosts file on your system:\n${expectedIP} ${testDomain}`;
112
112
  debug(`Verifying DNS resolution for ${testDomain}`);
113
- return new Promise((resolve, reject) => {
114
- dns.lookup(testDomain, (error, address) => {
115
- debug(`Got DNS response ${address}`);
116
-
117
- if (error) {
118
- reject(new _userError.default(`DNS resolution for ${testDomain} failed. ${advice}`));
119
- }
113
+ let address;
120
114
 
121
- if (address !== expectedIP) {
122
- reject(new _userError.default(`DNS resolution for ${testDomain} returned unexpected IP ${address}. Expected value is ${expectedIP}. ${advice}`));
123
- }
115
+ try {
116
+ address = await _dns.default.promises.lookup(testDomain, 4);
117
+ debug(`Got DNS response ${address.address}`);
118
+ } catch (error) {
119
+ throw new _userError.default(`DNS resolution for ${testDomain} failed. ${advice}`);
120
+ }
124
121
 
125
- resolve();
126
- });
127
- });
122
+ if (address.address !== expectedIP) {
123
+ throw new _userError.default(`DNS resolution for ${testDomain} returned unexpected IP ${address.address}. Expected value is ${expectedIP}. ${advice}`);
124
+ }
128
125
  };
129
126
 
130
127
  const VALIDATION_STEPS = [{
@@ -243,15 +240,15 @@ function getOptionsFromAppInfo(appInfo) {
243
240
  * Prompt for arguments
244
241
  * @param {InstanceOptions} preselectedOptions - options to be used without prompt
245
242
  * @param {InstanceOptions} defaultOptions - options to be used as default values for prompt
246
- * @param {boolean} supressPrompts - supress prompts and use default values where needed
243
+ * @param {boolean} suppressPrompts - supress prompts and use default values where needed
247
244
  * @returns {any} instance data
248
245
  */
249
246
 
250
247
 
251
- async function promptForArguments(preselectedOptions, defaultOptions, supressPrompts = false) {
248
+ async function promptForArguments(preselectedOptions, defaultOptions, suppressPrompts = false) {
252
249
  debug('Provided preselected', preselectedOptions, 'and default', defaultOptions);
253
250
 
254
- if (supressPrompts) {
251
+ if (suppressPrompts) {
255
252
  preselectedOptions = { ...defaultOptions,
256
253
  ...preselectedOptions
257
254
  };
@@ -275,7 +272,8 @@ async function promptForArguments(preselectedOptions, defaultOptions, supressPro
275
272
  mariadb: preselectedOptions.mariadb || defaultOptions.mariadb || _devEnvironment.DEV_ENVIRONMENT_DEFAULTS.mariadbVersion,
276
273
  mediaRedirectDomain: preselectedOptions.mediaRedirectDomain || '',
277
274
  wordpress: {
278
- mode: 'image'
275
+ mode: 'image',
276
+ tag: ''
279
277
  },
280
278
  muPlugins: {
281
279
  mode: 'image'
@@ -324,7 +322,7 @@ async function promptForArguments(preselectedOptions, defaultOptions, supressPro
324
322
  if ('elasticsearch' in preselectedOptions) {
325
323
  instanceData.elasticsearch = !!preselectedOptions.elasticsearch;
326
324
  } else {
327
- instanceData.elasticsearch = await promptForBoolean('Enable Elasticsearch (needed by Enterprise Search)?', defaultOptions.elasticsearch);
325
+ instanceData.elasticsearch = await promptForBoolean('Enable Elasticsearch (needed by Enterprise Search)?', !!defaultOptions.elasticsearch);
328
326
  }
329
327
 
330
328
  if (instanceData.elasticsearch) {
@@ -500,7 +498,7 @@ const componentDisplayNames = {
500
498
  const componentDemoyNames = {
501
499
  muPlugins: 'vip-go-mu-plugins',
502
500
  appCode: 'vip-go-skeleton'
503
- };
501
+ }; // eslint-disable-next-line no-redeclare
504
502
 
505
503
  async function promptForComponent(component, allowLocal, defaultObject) {
506
504
  debug(`Prompting for ${component} with default:`, defaultObject);
@@ -563,7 +561,7 @@ async function promptForComponent(component, allowLocal, defaultObject) {
563
561
  });
564
562
  const option = await selectTag.run();
565
563
  return {
566
- mode: modeResult,
564
+ mode: 'image',
567
565
  tag: option
568
566
  };
569
567
  } // image
@@ -595,10 +593,28 @@ function addDevEnvConfigurationOptions(command) {
595
593
 
596
594
 
597
595
  async function getTagChoices() {
598
- const versions = await (0, _devEnvironmentCore.getVersionList)();
596
+ let versions = await (0, _devEnvironmentCore.getVersionList)();
599
597
 
600
598
  if (versions.length < 1) {
601
- return ['5.9', '5.8', '5.7', '5.6', '5.5'];
599
+ versions = [{
600
+ ref: '5.9.5',
601
+ tag: '5.9',
602
+ cacheable: true,
603
+ locked: true,
604
+ prerelease: false
605
+ }, {
606
+ ref: '5.8.6',
607
+ tag: '5.8',
608
+ cacheable: true,
609
+ locked: true,
610
+ prerelease: false
611
+ }, {
612
+ ref: '5.7.8',
613
+ tag: '5.7',
614
+ cacheable: true,
615
+ locked: true,
616
+ prerelease: false
617
+ }];
602
618
  }
603
619
 
604
620
  return versions.map(version => {
@@ -320,20 +320,13 @@ async function prepareLandoEnv(instanceData, instancePath) {
320
320
 
321
321
  const instanceDataTargetPath = _path.default.join(instancePath, instanceDataFileName);
322
322
 
323
- _fs.default.mkdirSync(instancePath, {
323
+ await _fs.default.promises.mkdir(instancePath, {
324
324
  recursive: true
325
325
  });
326
-
327
- _fs.default.mkdirSync(nginxFolderPath, {
326
+ await _fs.default.promises.mkdir(nginxFolderPath, {
328
327
  recursive: true
329
328
  });
330
-
331
- _fs.default.writeFileSync(landoFileTargetPath, landoFile);
332
-
333
- _fs.default.writeFileSync(nginxFileTargetPath, nginxFile);
334
-
335
- _fs.default.writeFileSync(instanceDataTargetPath, instanceDataFile);
336
-
329
+ await Promise.all([_fs.default.promises.writeFile(landoFileTargetPath, landoFile), _fs.default.promises.writeFile(nginxFileTargetPath, nginxFile), _fs.default.promises.writeFile(instanceDataTargetPath, instanceDataFile)]);
337
330
  debug(`Lando file created in ${landoFileTargetPath}`);
338
331
  debug(`Nginx file created in ${nginxFileTargetPath}`);
339
332
  debug(`Instance data file created in ${instanceDataTargetPath}`);
@@ -588,7 +581,7 @@ async function updateWordPressImage(slug) {
588
581
  } else {
589
582
  console.log('Environment WordPress version is: ' + _chalk.default.yellow(`${match.tag} (${match.ref})`));
590
583
 
591
- if (envData.wordpress.doNotUpgrade || false) {
584
+ if (envData.wordpress.doNotUpgrade) {
592
585
  return false;
593
586
  }
594
587
  } // Prompt the user to select a new WordPress Version
@@ -604,7 +597,7 @@ async function updateWordPressImage(slug) {
604
597
  if (confirm.upgrade === 'yes') {
605
598
  console.log('Upgrading from: ' + _chalk.default.yellow(currentWordPressTag) + ' to:'); // Select a new image
606
599
 
607
- const choice = await (0, _devEnvironmentCli.promptForComponent)('wordpress');
600
+ const choice = await (0, _devEnvironmentCli.promptForComponent)('wordpress', false, null);
608
601
  const version = versions.find(({
609
602
  tag
610
603
  }) => tag.trim() === choice.tag.trim()); // Write new data and stage for rebuild
@@ -663,17 +656,10 @@ async function getVersionList() {
663
656
 
664
657
  try {
665
658
  // If the cache doesn't exist, create it
666
- if (!_fs.default.existsSync(cacheFile)) {
659
+ // If the cache is expired, refresh it
660
+ if (!_fs.default.existsSync(cacheFile) || isVersionListExpired(cacheFile, _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSION_TTL)) {
667
661
  res = await fetchVersionList();
668
-
669
- _fs.default.writeFileSync(cacheFile, res);
670
- } // If the cache is expired, refresh it
671
-
672
-
673
- if (isVersionListExpired(cacheFile, _devEnvironment.DEV_ENVIRONMENT_WORDPRESS_VERSION_TTL)) {
674
- res = await fetchVersionList();
675
-
676
- _fs.default.writeFileSync(cacheFile, res);
662
+ await _fs.default.promises.writeFile(cacheFile, res);
677
663
  }
678
664
  } catch (err) {
679
665
  // Soft error handling here, since it's still possible to use a previously cached file.
@@ -683,7 +669,8 @@ async function getVersionList() {
683
669
 
684
670
 
685
671
  try {
686
- return JSON.parse(_fs.default.readFileSync(cacheFile));
672
+ const data = await _fs.default.promises.readFile(cacheFile, 'utf8');
673
+ return JSON.parse(data);
687
674
  } catch (err) {
688
675
  debug(err);
689
676
  return [];