@scandipwa/magento-scripts 1.14.1-alpha.0 → 1.14.1-alpha.11

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.
Files changed (146) hide show
  1. package/index.js +13 -0
  2. package/lib/commands/cli.js +28 -1
  3. package/lib/commands/execute.js +2 -1
  4. package/lib/commands/logs.js +1 -0
  5. package/lib/commands/start.js +18 -5
  6. package/lib/config/dependencies-for-platforms.js +12 -2
  7. package/lib/config/docker.js +89 -15
  8. package/lib/config/get-port-config.js +9 -3
  9. package/lib/config/index.js +2 -1
  10. package/lib/config/php/extensions/libsodium.js +2 -1
  11. package/lib/config/port-config.js +3 -1
  12. package/lib/config/scandipwa-versions.js +2 -1
  13. package/lib/config/ssl-terminator/index.js +10 -0
  14. package/lib/config/system-config.js +34 -5
  15. package/lib/config/templates/magentorc.template +3 -5
  16. package/lib/config/templates/nginx.template.conf +0 -14
  17. package/lib/config/templates/php.template.ini +6 -4
  18. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  19. package/lib/config/templates/varnish.template.vcl +250 -0
  20. package/lib/config/varnish/varnish-6-0.js +11 -0
  21. package/lib/config/varnish/varnish-6-6.js +11 -0
  22. package/lib/config/varnish/varnish-7-0.js +11 -0
  23. package/lib/config/versions/magento-2.3.0.js +9 -1
  24. package/lib/config/versions/magento-2.3.1.js +9 -1
  25. package/lib/config/versions/magento-2.3.2-p2.js +9 -1
  26. package/lib/config/versions/magento-2.3.2.js +9 -1
  27. package/lib/config/versions/magento-2.3.3-p1.js +9 -1
  28. package/lib/config/versions/magento-2.3.3.js +9 -1
  29. package/lib/config/versions/magento-2.3.4-p2.js +9 -1
  30. package/lib/config/versions/magento-2.3.4.js +9 -1
  31. package/lib/config/versions/magento-2.3.5-p1.js +9 -1
  32. package/lib/config/versions/magento-2.3.5-p2.js +9 -1
  33. package/lib/config/versions/magento-2.3.5.js +9 -1
  34. package/lib/config/versions/magento-2.3.6-p1.js +9 -1
  35. package/lib/config/versions/magento-2.3.6.js +9 -1
  36. package/lib/config/versions/magento-2.3.7-p1.js +9 -1
  37. package/lib/config/versions/magento-2.3.7-p2.js +9 -1
  38. package/lib/config/versions/magento-2.3.7-p3.js +9 -1
  39. package/lib/config/versions/magento-2.3.7.js +9 -1
  40. package/lib/config/versions/magento-2.4.0-p1.js +9 -1
  41. package/lib/config/versions/magento-2.4.0.js +9 -1
  42. package/lib/config/versions/magento-2.4.1-p1.js +9 -1
  43. package/lib/config/versions/magento-2.4.1.js +9 -1
  44. package/lib/config/versions/magento-2.4.2-p1.js +9 -1
  45. package/lib/config/versions/magento-2.4.2-p2.js +9 -1
  46. package/lib/config/versions/magento-2.4.2.js +9 -1
  47. package/lib/config/versions/magento-2.4.3-p1.js +9 -1
  48. package/lib/config/versions/magento-2.4.3-p2.js +9 -1
  49. package/lib/config/versions/magento-2.4.3.js +9 -1
  50. package/lib/config/versions/magento-2.4.4.js +9 -1
  51. package/lib/errors/known-error.js +15 -0
  52. package/lib/errors/unknown-error.js +15 -0
  53. package/lib/tasks/cli/create-bashrc-config.js +7 -3
  54. package/lib/tasks/composer/index.js +5 -3
  55. package/lib/tasks/composer/local-auth-json.js +4 -2
  56. package/lib/tasks/docker/containers.js +13 -8
  57. package/lib/tasks/docker/network.js +2 -1
  58. package/lib/tasks/docker/volumes.js +4 -4
  59. package/lib/tasks/file-system/create-nginx-config.js +9 -40
  60. package/lib/tasks/file-system/create-php-config.js +2 -1
  61. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  62. package/lib/tasks/file-system/create-php-storm-config.js +6 -5
  63. package/lib/tasks/file-system/create-ssl-terminator-config.js +96 -0
  64. package/lib/tasks/file-system/create-varnish-config.js +53 -0
  65. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  66. package/lib/tasks/file-system/index.js +5 -1
  67. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  68. package/lib/tasks/magento/install-magento.js +7 -5
  69. package/lib/tasks/magento/setup-magento/configure-elasticsearch.js +1 -1
  70. package/lib/tasks/magento/setup-magento/disable-2fa.js +4 -12
  71. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +20 -0
  72. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  73. package/lib/tasks/magento/setup-magento/increase-admin-session-lifetime.js +14 -16
  74. package/lib/tasks/magento/setup-magento/index.js +3 -1
  75. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  76. package/lib/tasks/magento/setup-magento/migrate-database.js +24 -11
  77. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  78. package/lib/tasks/magento/setup-magento/upgrade-magento.js +27 -3
  79. package/lib/tasks/magento/setup-magento/varnish-config.js +69 -0
  80. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  81. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  82. package/lib/tasks/mysql/fix-db.js +2 -2
  83. package/lib/tasks/mysql/import-dump-to-mysql.js +4 -2
  84. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  85. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  86. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  87. package/lib/tasks/php/bundled-extensions.js +28 -0
  88. package/lib/tasks/php/compile-options.js +18 -48
  89. package/lib/tasks/php/compile.js +4 -3
  90. package/lib/tasks/php/configure.js +7 -66
  91. package/lib/tasks/php/extensions/index.js +71 -0
  92. package/lib/tasks/php/index.js +8 -7
  93. package/lib/tasks/php/update-env-php.js +16 -1
  94. package/lib/tasks/php/update-env.php +56 -12
  95. package/lib/tasks/php/update-phpbrew.js +2 -1
  96. package/lib/tasks/php/validate-php.js +67 -0
  97. package/lib/tasks/php-fpm/start-php-fpm.js +2 -1
  98. package/lib/tasks/requirements/composer.js +5 -3
  99. package/lib/tasks/requirements/dependency/arch.js +2 -1
  100. package/lib/tasks/requirements/dependency/centos.js +2 -1
  101. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  102. package/lib/tasks/requirements/docker/index.js +7 -4
  103. package/lib/tasks/requirements/docker/install.js +13 -12
  104. package/lib/tasks/requirements/docker/running-status.js +138 -0
  105. package/lib/tasks/requirements/docker/version.js +3 -0
  106. package/lib/tasks/requirements/index.js +5 -5
  107. package/lib/tasks/requirements/node-version.js +2 -1
  108. package/lib/tasks/requirements/php-version.js +8 -4
  109. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  110. package/lib/tasks/requirements/phpbrew/install.js +2 -1
  111. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  112. package/lib/tasks/requirements/platform.js +3 -2
  113. package/lib/tasks/start.js +11 -10
  114. package/lib/tasks/status/index.js +25 -9
  115. package/lib/tasks/theme/build-theme.js +27 -8
  116. package/lib/tasks/theme/install-theme.js +18 -5
  117. package/lib/tasks/theme/link-theme.js +2 -2
  118. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  119. package/lib/tasks/theme/setup-persisted-query.js +5 -4
  120. package/lib/tasks/theme/setup-themes.js +5 -3
  121. package/lib/tasks/theme/symlink-theme.js +20 -4
  122. package/lib/util/analytics.js +337 -0
  123. package/lib/util/config-file-validator.js +14 -2
  124. package/lib/util/config-php-json.js +20 -0
  125. package/lib/util/env-php-json.js +3 -2
  126. package/lib/util/get-installed-magento-version.js +3 -2
  127. package/lib/util/get-jsonfile-data.js +2 -1
  128. package/lib/util/install-dependencies-task.js +4 -4
  129. package/lib/util/instance-metadata.js +11 -4
  130. package/lib/util/ip.js +45 -1
  131. package/lib/util/is-running-root.js +3 -0
  132. package/lib/util/magento-task.js +20 -9
  133. package/lib/util/match-filesystem.js +2 -1
  134. package/lib/util/php-task.js +6 -2
  135. package/lib/util/request.js +0 -0
  136. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  137. package/lib/util/run-composer.js +3 -2
  138. package/lib/util/run-magento.js +3 -2
  139. package/lib/util/run-php.js +10 -3
  140. package/lib/util/systemctl.js +46 -0
  141. package/lib/util/wait-for-it.js +3 -2
  142. package/package.json +4 -3
  143. package/typings/context.d.ts +5 -1
  144. package/typings/index.d.ts +32 -1
  145. package/lib/tasks/magento/setup-magento/adjust-magento-configuration.js +0 -27
  146. package/lib/tasks/magento/setup-magento/disable-page-cache.js +0 -11
@@ -1,10 +1,9 @@
1
1
  const magentoTask = require('../../../util/magento-task');
2
2
  const runMagentoCommand = require('../../../util/run-magento');
3
- const adjustMagentoConfiguration = require('./adjust-magento-configuration');
4
3
  const configureElasticsearch = require('./configure-elasticsearch');
5
4
  const installMagento = require('./install-magento');
6
5
  const upgradeMagento = require('./upgrade-magento');
7
- const setupPersistedQuery = require('../../theme/setup-persisted-query');
6
+ const varnishConfigSetup = require('./varnish-config');
8
7
 
9
8
  /**
10
9
  * @type {({ onlyInstallMagento: boolean }) => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
@@ -25,6 +24,7 @@ const migrateDatabase = (options = {}) => ({
25
24
 
26
25
  if (tableCount === 0) {
27
26
  if (options.onlyInstallMagento) {
27
+ ctx.isSetupUpgradeNeeded = false;
28
28
  return task.newListr(
29
29
  installMagento({ isDbEmpty: true })
30
30
  );
@@ -32,14 +32,17 @@ const migrateDatabase = (options = {}) => ({
32
32
 
33
33
  return task.newListr([
34
34
  installMagento({ isDbEmpty: true }),
35
- setupPersistedQuery(),
36
35
  upgradeMagento(),
37
36
  magentoTask('cache:enable'),
37
+ varnishConfigSetup(),
38
38
  configureElasticsearch()
39
39
  ], {
40
40
  concurrent: false,
41
41
  exitOnError: true,
42
- ctx
42
+ ctx,
43
+ rendererOptions: {
44
+ collapse: false
45
+ }
43
46
  });
44
47
  }
45
48
  const { code } = await runMagentoCommand('setup:db:status', {
@@ -49,18 +52,23 @@ const migrateDatabase = (options = {}) => ({
49
52
 
50
53
  switch (code) {
51
54
  case 0: {
55
+ ctx.isSetupUpgradeNeeded = false;
52
56
  // no setup is needed, but still to be sure configure ES
53
57
  return task.newListr([
54
- setupPersistedQuery(),
58
+ varnishConfigSetup(),
55
59
  configureElasticsearch()
56
60
  ], {
57
61
  concurrent: false,
58
62
  exitOnError: true,
59
- ctx
63
+ ctx,
64
+ rendererOptions: {
65
+ collapse: false
66
+ }
60
67
  });
61
68
  }
62
69
  case 1: {
63
70
  if (options.onlyInstallMagento) {
71
+ ctx.isSetupUpgradeNeeded = false;
64
72
  return task.newListr(
65
73
  installMagento()
66
74
  );
@@ -68,26 +76,31 @@ const migrateDatabase = (options = {}) => ({
68
76
 
69
77
  return task.newListr([
70
78
  installMagento(),
71
- setupPersistedQuery(),
72
79
  upgradeMagento(),
73
80
  magentoTask('cache:enable'),
81
+ varnishConfigSetup(),
74
82
  configureElasticsearch()
75
83
  ], {
76
84
  concurrent: false,
77
85
  exitOnError: true,
78
- ctx
86
+ ctx,
87
+ rendererOptions: {
88
+ collapse: false
89
+ }
79
90
  });
80
91
  }
81
92
  case 2: {
82
93
  return task.newListr([
83
- setupPersistedQuery(),
84
- adjustMagentoConfiguration(),
94
+ varnishConfigSetup(),
85
95
  configureElasticsearch(),
86
96
  upgradeMagento()
87
97
  ], {
88
98
  concurrent: false,
89
99
  exitOnError: true,
90
- ctx
100
+ ctx,
101
+ rendererOptions: {
102
+ collapse: false
103
+ }
91
104
  });
92
105
  }
93
106
  default: {
@@ -8,12 +8,17 @@ module.exports = () => ({
8
8
  task: async (ctx, task) => {
9
9
  const {
10
10
  ports,
11
- config: { overridenConfiguration: { host, ssl } },
11
+ config: {
12
+ overridenConfiguration: {
13
+ host,
14
+ ssl
15
+ }
16
+ },
12
17
  mysqlConnection
13
18
  } = ctx;
14
19
  const isNgrok = host.endsWith('ngrok.io');
15
20
  const enableSecureFrontend = ssl.enabled ? '1' : '0';
16
- const location = `${host}${ !isNgrok && ports.app !== 80 ? `:${ports.app}` : '' }/`;
21
+ const location = `${host}${ !isNgrok && ports.sslTerminator !== 80 ? `:${ports.sslTerminator }` : '' }/`;
17
22
  const secureLocation = `${host}/`; // SSL will work only on port 443, so you cannot run multiple projects with SSL at the same time.
18
23
  const httpUrl = `http://${location}`;
19
24
  const httpsUrl = `https://${secureLocation}`;
@@ -1,12 +1,36 @@
1
1
  const magentoTask = require('../../../util/magento-task');
2
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
+ const KnownError = require('../../../errors/known-error');
2
4
 
3
5
  /**
4
6
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
7
  */
6
8
  const upgradeMagento = () => ({
7
- task: (ctx, task) => task.newListr(
8
- magentoTask('setup:upgrade --no-interaction')
9
- )
9
+ skip: (ctx) => {
10
+ if ('isSetupUpgradeNeeded' in ctx) {
11
+ return !ctx.isSetupUpgradeNeeded;
12
+ }
13
+
14
+ return false;
15
+ },
16
+ task: (_ctx, task) => task.newListr([
17
+ magentoTask('setup:upgrade --no-interaction', {
18
+ onError: (e) => {
19
+ throw new KnownError(`Magento setup:upgrade command failed!
20
+ You can try disabling failed module and try again.
21
+ To disable module, open ${logger.style.misc('cli')} and type the following command: ${logger.style.command('m module:disable <module-name>')}
22
+
23
+ Error: ${e}`);
24
+ }
25
+ }),
26
+ {
27
+ task: (ctx) => {
28
+ ctx.isSetupUpgradeNeeded = false;
29
+ }
30
+ }
31
+ ], {
32
+ concurrent: false
33
+ })
10
34
  });
11
35
 
12
36
  module.exports = upgradeMagento;
@@ -0,0 +1,69 @@
1
+ const os = require('os');
2
+ const { updateTableValues } = require('../../../util/database');
3
+ const getIsWsl = require('../../../util/is-wsl');
4
+
5
+ /**
6
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
7
+ */
8
+ const varnishConfigSetup = () => ({
9
+ title: 'Varnish setup',
10
+ task: async (ctx, task) => {
11
+ const {
12
+ config: {
13
+ overridenConfiguration: {
14
+ configuration: {
15
+ varnish: {
16
+ enabled: varnishEnabled
17
+ }
18
+ }
19
+ }
20
+ },
21
+ mysqlConnection,
22
+ ports
23
+ } = ctx;
24
+
25
+ const isLinux = os.platform() === 'linux';
26
+ const isWsl = await getIsWsl();
27
+ // const host = (isLinux && !isWsl) ? 'localhost' : 'host.docker.internal';
28
+
29
+ if (varnishEnabled) {
30
+ await updateTableValues('core_config_data', [
31
+ {
32
+ path: 'system/full_page_cache/varnish/backend_host',
33
+ value: 'localhost'
34
+ },
35
+ {
36
+ path: 'system/full_page_cache/varnish/backend_port',
37
+ value: ports.varnish
38
+ },
39
+ {
40
+ path: 'system/full_page_cache/varnish/access_list',
41
+ value: (!isLinux || isWsl) ? 'host.docker.internal,localhost' : 'localhost'
42
+ },
43
+ {
44
+ path: 'system/full_page_cache/caching_application',
45
+ value: '2'
46
+ }
47
+ ], { mysqlConnection, task });
48
+ } else {
49
+ // delete varnish configuration if exists
50
+ await mysqlConnection.query(`
51
+ DELETE FROM core_config_data WHERE path LIKE '%varnish%';
52
+ `);
53
+
54
+ // update cache policy to not use varnish
55
+ // 0 - magento cache, 2 - varnish cache
56
+ await updateTableValues('core_config_data', [
57
+ {
58
+ path: 'system/full_page_cache/caching_application',
59
+ value: '0'
60
+ }
61
+ ], { mysqlConnection, task });
62
+ }
63
+ },
64
+ options: {
65
+ bottomBar: 10
66
+ }
67
+ });
68
+
69
+ module.exports = varnishConfigSetup;
@@ -0,0 +1,41 @@
1
+ const { request } = require('smol-request');
2
+ const KnownError = require('../../../errors/known-error');
3
+ const sleep = require('../../../util/sleep');
4
+
5
+ /**
6
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
7
+ */
8
+ const waitingForVarnish = () => ({
9
+ title: 'Waiting for Varnish to return code 200',
10
+ skip: (ctx) => !ctx.config.overridenConfiguration.configuration.varnish.enabled,
11
+ task: async (ctx) => {
12
+ let tries = 0;
13
+ while (tries < 10) {
14
+ try {
15
+ const response = await request(`http://localhost:${ctx.ports.sslTerminator}/`, {
16
+ responseType: 'headers'
17
+ });
18
+
19
+ if (response.status !== 200) {
20
+ tries++;
21
+ await sleep(2000);
22
+ } else {
23
+ break;
24
+ }
25
+ } catch (e) {
26
+ tries++;
27
+ await sleep(200);
28
+ }
29
+ }
30
+
31
+ if (tries === 10) {
32
+ throw new KnownError(`After 20 seconds website is still responding with non-200 code, which might indicate issue with setup.
33
+ Or Varnish is still loading...
34
+
35
+ Please check the logs!`);
36
+ }
37
+ },
38
+ exitOnError: false
39
+ });
40
+
41
+ module.exports = waitingForVarnish;
@@ -1,4 +1,5 @@
1
1
  const mysql = require('mysql2/promise');
2
+ const UnknownError = require('../../errors/unknown-error');
2
3
  const { execAsyncSpawn } = require('../../util/exec-async-command');
3
4
  const sleep = require('../../util/sleep');
4
5
 
@@ -44,7 +45,7 @@ Please wait, this will take some time and do not restart the MySQL container unt
44
45
  }
45
46
 
46
47
  if (tries === maxTries) {
47
- throw new Error(`Unable to connect to MySQL server. Check your server configuration!\n\n${ errors.join(' ') }`);
48
+ throw new UnknownError(`Unable to connect to MySQL server. Check your server configuration!\n\n${ errors.join(' ') }`);
48
49
  }
49
50
 
50
51
  task.title = 'MySQL server connected!';
@@ -1,8 +1,8 @@
1
- const adjustMagentoConfiguration = require('../magento/setup-magento/adjust-magento-configuration');
2
1
  const configureElasticsearch = require('../magento/setup-magento/configure-elasticsearch');
3
2
  const deleteAdminUsers = require('../magento/setup-magento/delete-admin-users');
4
3
  const deleteCustomers = require('../magento/setup-magento/delete-customers');
5
4
  const deleteOrders = require('../magento/setup-magento/delete-orders');
5
+ const varnishConfigSetup = require('../magento/setup-magento/varnish-config');
6
6
 
7
7
  /**
8
8
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -24,7 +24,7 @@ const disableForeignKeyCheck = () => ({
24
24
  const fixDB = () => ({
25
25
  title: 'Fixing database',
26
26
  task: async (ctx, task) => task.newListr([
27
- adjustMagentoConfiguration(),
27
+ varnishConfigSetup(),
28
28
  configureElasticsearch(),
29
29
  {
30
30
  title: 'Deleting customers data',
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable max-len */
2
+ const KnownError = require('../../errors/known-error');
3
+ const UnknownError = require('../../errors/unknown-error');
2
4
  const { execAsyncSpawn } = require('../../util/exec-async-command');
3
5
  const pathExists = require('../../util/path-exists');
4
6
 
@@ -9,7 +11,7 @@ const importDumpToMySQL = () => ({
9
11
  title: 'Importing Database Dump To MySQL',
10
12
  task: async (ctx, task) => {
11
13
  if (!await pathExists(ctx.importDb)) {
12
- throw new Error(`Dump file at ${ctx.importDb} does not exist. Please provide correct relative path to the file`);
14
+ throw new KnownError(`Dump file at ${ctx.importDb} does not exist. Please provide correct relative path to the file`);
13
15
  }
14
16
 
15
17
  const { config: { docker }, ports } = ctx;
@@ -42,7 +44,7 @@ const importDumpToMySQL = () => ({
42
44
  }
43
45
  );
44
46
  } catch (e) {
45
- throw new Error(`Unexpected error during dump import.\n\n${e}`);
47
+ throw new UnknownError(`Unexpected error during dump import.\n\n${e}`);
46
48
  }
47
49
 
48
50
  clearInterval(tickInterval);
@@ -1,3 +1,4 @@
1
+ const UnknownError = require('../../../errors/unknown-error');
1
2
  const sshDb = require('./ssh');
2
3
 
3
4
  /**
@@ -30,7 +31,7 @@ It can be a SSH (ssh://<url>) connection or mysql (mysql://<url>) connection.
30
31
  );
31
32
  }
32
33
  default: {
33
- throw new Error(`Unsupported protocol ${protocol}`);
34
+ throw new UnknownError(`Unsupported protocol ${protocol}`);
34
35
  }
35
36
  }
36
37
  }
@@ -3,6 +3,7 @@ const { NodeSSH } = require('node-ssh');
3
3
  const pathExists = require('../../../../util/path-exists');
4
4
  const regularSSHServer = require('./regular-server');
5
5
  const readymageSSH = require('./readymage');
6
+ const KnownError = require('../../../../errors/known-error');
6
7
 
7
8
  /**
8
9
  * @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext>}
@@ -25,7 +26,7 @@ const sshDb = () => ({
25
26
  });
26
27
 
27
28
  if (!(await pathExists(privateKey))) {
28
- throw new Error(`Private key not found: ${privateKey}`);
29
+ throw new KnownError(`Private key not found: ${privateKey}`);
29
30
  }
30
31
 
31
32
  ctx.privateKey = privateKey;
@@ -2,6 +2,7 @@ const mergeFiles = require('merge-files');
2
2
  const { orderTables, customerTables } = require('../../magento-tables');
3
3
  const { execAsyncSpawn } = require('../../../../util/exec-async-command');
4
4
  const mysqlDumpCommandWithOptions = require('./mysqldump-command');
5
+ const KnownError = require('../../../../errors/known-error');
5
6
  /**
6
7
  * @type {() => import('listr2').ListrTask<import('../../../../../typings/context').ListrContext & { ssh: import('node-ssh').NodeSSH }>}
7
8
  */
@@ -30,7 +31,7 @@ Do not enter "--result-file" option, we need to control that part.
30
31
  });
31
32
 
32
33
  if (dumpCommand.includes('--result-file')) {
33
- throw new Error('--result-file option is not allowed in user input command');
34
+ throw new KnownError('--result-file option is not allowed in user input command');
34
35
  }
35
36
 
36
37
  if (!withCustomersData) {
@@ -0,0 +1,28 @@
1
+ const bundledExtensions = [
2
+ 'bz2',
3
+ 'bcmath',
4
+ 'ctype',
5
+ 'curl',
6
+ 'intl',
7
+ 'dom',
8
+ 'filter',
9
+ 'hash',
10
+ 'sockets',
11
+ 'iconv',
12
+ 'json',
13
+ 'mbstring',
14
+ 'openssl',
15
+ 'xml',
16
+ 'mysql',
17
+ 'pdo',
18
+ 'soap',
19
+ 'xmlrpc',
20
+ 'xml',
21
+ 'zip',
22
+ 'fpm',
23
+ 'gd'
24
+ ];
25
+
26
+ module.exports = {
27
+ bundledExtensions
28
+ };
@@ -1,30 +1,16 @@
1
+ const { bundledExtensions } = require('./bundled-extensions');
2
+
3
+ const darwinVariants = [
4
+ 'openssl=$(brew --prefix openssl@1.1)', // ="$(brew --prefix openssl@1.1)"
5
+ 'curl=$(brew --prefix curl)',
6
+ 'intl=$(brew --prefix icu4c)',
7
+ 'bz2="$(brew --prefix bzip2)"'
8
+ ];
9
+
1
10
  const compileOptions = {
2
11
  linux: {
3
12
  cpuCount: '$(nproc)',
4
- variants: [
5
- '+bz2',
6
- '+bcmath',
7
- '+ctype',
8
- '+curl',
9
- '+intl',
10
- '+dom',
11
- '+filter',
12
- '+hash',
13
- '+sockets',
14
- '+iconv',
15
- '+json',
16
- '+mbstring',
17
- '+openssl',
18
- '+xml',
19
- '+mysql',
20
- '+pdo',
21
- '+soap',
22
- '+xmlrpc',
23
- '+xml',
24
- '+zip',
25
- '+fpm',
26
- '+gd'
27
- ],
13
+ variants: bundledExtensions.map((ext) => `+${ext}`),
28
14
  extraOptions: [
29
15
  '--with-freetype-dir=/usr/include/freetype2',
30
16
  '--with-openssl=/usr/',
@@ -39,30 +25,14 @@ const compileOptions = {
39
25
  },
40
26
  darwin: {
41
27
  cpuCount: '$(sysctl -n hw.ncpu)',
42
- variants: [
43
- '+neutral',
44
- '+bz2="$(brew --prefix bzip2)"',
45
- '+bcmath',
46
- '+ctype',
47
- '+curl=$(brew --prefix curl)',
48
- '+intl=$(brew --prefix icu4c)',
49
- '+dom',
50
- '+filter',
51
- '+hash',
52
- '+iconv',
53
- '+json',
54
- '+mbstring',
55
- '+openssl=$(brew --prefix openssl@1.1)', // ="$(brew --prefix openssl@1.1)"
56
- '+xml',
57
- '+mysql',
58
- '+pdo',
59
- '+soap',
60
- '+xmlrpc',
61
- '+xml',
62
- '+zip',
63
- '+fpm',
64
- '+gd'
65
- ],
28
+ variants: bundledExtensions.map((ext) => {
29
+ const darwinVariant = darwinVariants.find((dv) => dv.startsWith(ext));
30
+ if (darwinVariant) {
31
+ return `+${darwinVariant}`;
32
+ }
33
+
34
+ return `+${ext}`;
35
+ }),
66
36
  extraOptions: [
67
37
  '--with-zlib-dir=$(brew --prefix zlib)',
68
38
  '--with-iconv=$(brew --prefix libiconv)',
@@ -2,11 +2,12 @@ const systeminformation = require('systeminformation');
2
2
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
3
  const { execAsyncSpawn } = require('../../util/exec-async-command');
4
4
  const compileOptions = require('./compile-options');
5
+ const UnknownError = require('../../errors/unknown-error');
5
6
 
6
7
  /**
7
8
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
8
9
  */
9
- const compile = () => ({
10
+ const compilePHP = () => ({
10
11
  title: 'Compiling PHP',
11
12
  task: async ({ config: { php } }, task) => {
12
13
  const platformCompileOptions = compileOptions[process.platform];
@@ -31,7 +32,7 @@ const compile = () => ({
31
32
  }
32
33
  );
33
34
  } catch (e) {
34
- throw new Error(
35
+ throw new UnknownError(
35
36
  `Failed to compile the required PHP version.
36
37
  Tried compiling the PHP version ${ logger.style.misc(php.version) }.
37
38
  Use your favorite search engine to resolve the issue.
@@ -44,4 +45,4 @@ const compile = () => ({
44
45
  }
45
46
  });
46
47
 
47
- module.exports = compile;
48
+ module.exports = compilePHP;
@@ -1,76 +1,17 @@
1
1
  /* eslint-disable max-len */
2
- const path = require('path');
3
- const fs = require('fs');
4
- const { execAsyncSpawn } = require('../../util/exec-async-command');
5
- const pathExists = require('../../util/path-exists');
6
2
  const enableExtension = require('./extensions/enable');
7
3
  const installExtension = require('./extensions/install');
8
4
  const disableExtension = require('./extensions/disable');
9
- const phpbrewConfig = require('../../config/phpbrew');
10
-
11
- /**
12
- * Get enabled extensions list with versions
13
- * @param {import('../../../typings/context').ListrContext['config']} param0
14
- * @returns {Promise<{[key: string]: string}}>}
15
- */
16
- const getEnabledExtensions = async ({ php }) => {
17
- const output = await execAsyncSpawn(
18
- `${ php.binPath } -c ${php.iniPath} -r 'foreach (get_loaded_extensions() as $extension) echo "$extension:" . phpversion($extension) . "\n";'`
19
- );
20
-
21
- return output
22
- .split('\n')
23
- .map((m) => {
24
- // eslint-disable-next-line no-unused-vars
25
- const [_, moduleName, moduleVersion] = m.match(/(.+):(.+)/i);
26
-
27
- return [moduleName, moduleVersion];
28
- })
29
- .reduce((acc, [name, version]) => ({ ...acc, [name]: version }), {});
30
- };
31
-
32
- /**
33
- * Get disabled extensions list
34
- * @param {import('../../../typings/context').ListrContext['config']} param0
35
- * @returns {Promise<string[]>}
36
- */
37
- const getDisabledExtensions = async ({ php }) => {
38
- const extensionsIniDirectory = path.join(phpbrewConfig.phpPath, `php-${php.version}`, 'var', 'db');
39
-
40
- if (!await pathExists(extensionsIniDirectory)) {
41
- return [];
42
- }
43
-
44
- const extensionIniList = await fs.promises.readdir(
45
- extensionsIniDirectory,
46
- {
47
- encoding: 'utf-8',
48
- withFileTypes: true
49
- }
50
- );
51
-
52
- return extensionIniList.filter((f) => f.isFile() && f.name.endsWith('.disabled')).map((f) => f.name.replace('.disabled', ''));
53
- };
54
-
55
- /**
56
- * Get installed extensions
57
- * @param {import('../../../typings/context').ListrContext['config']} param0
58
- * @returns {Promise<string[]>}
59
- */
60
- const getInstalledExtensions = async ({ php }) => {
61
- const extensionDirectory = path.join(phpbrewConfig.buildPath, `php-${php.version}`, 'ext');
62
-
63
- const availableExtensions = await fs.promises.readdir(extensionDirectory, {
64
- encoding: 'utf-8'
65
- });
66
-
67
- return availableExtensions;
68
- };
5
+ const {
6
+ getEnabledExtensions,
7
+ getInstalledExtensions,
8
+ getDisabledExtensions
9
+ } = require('./extensions');
69
10
 
70
11
  /**
71
12
  * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
72
13
  */
73
- const configure = () => ({
14
+ const configurePHP = () => ({
74
15
  title: 'Configuring PHP extensions',
75
16
  task: async ({ config, debug }, task) => {
76
17
  const { php, php: { disabledExtensions = [] } } = config;
@@ -145,4 +86,4 @@ const configure = () => ({
145
86
  }
146
87
  });
147
88
 
148
- module.exports = configure;
89
+ module.exports = configurePHP;