@scandipwa/magento-scripts 1.14.1-alpha.8 → 1.15.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.
Files changed (178) hide show
  1. package/lib/commands/cli.js +9 -4
  2. package/lib/commands/logs.js +1 -0
  3. package/lib/commands/start.js +18 -5
  4. package/lib/config/check-configuration-file.js +16 -1
  5. package/lib/config/cma-config.js +16 -0
  6. package/lib/config/dependencies-for-platforms.js +15 -3
  7. package/lib/config/docker.js +45 -12
  8. package/lib/config/get-port-config.js +7 -2
  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 +2 -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 +2 -0
  16. package/lib/config/templates/nginx.template.conf +0 -31
  17. package/lib/config/templates/ssl-terminator.template.conf +27 -0
  18. package/lib/config/templates/varnish.template.vcl +9 -4
  19. package/lib/config/versions/magento-2.3.0.js +3 -1
  20. package/lib/config/versions/magento-2.3.1.js +3 -1
  21. package/lib/config/versions/magento-2.3.2-p2.js +3 -1
  22. package/lib/config/versions/magento-2.3.2.js +3 -1
  23. package/lib/config/versions/magento-2.3.3-p1.js +3 -1
  24. package/lib/config/versions/magento-2.3.3.js +3 -1
  25. package/lib/config/versions/magento-2.3.4-p2.js +3 -1
  26. package/lib/config/versions/magento-2.3.4.js +3 -1
  27. package/lib/config/versions/magento-2.3.5-p1.js +3 -1
  28. package/lib/config/versions/magento-2.3.5-p2.js +3 -1
  29. package/lib/config/versions/magento-2.3.5.js +3 -1
  30. package/lib/config/versions/magento-2.3.6-p1.js +3 -1
  31. package/lib/config/versions/magento-2.3.6.js +3 -1
  32. package/lib/config/versions/magento-2.3.7-p1.js +3 -1
  33. package/lib/config/versions/magento-2.3.7-p2.js +3 -1
  34. package/lib/config/versions/magento-2.3.7-p3.js +3 -1
  35. package/lib/config/versions/magento-2.3.7.js +3 -1
  36. package/lib/config/versions/magento-2.4.0-p1.js +3 -1
  37. package/lib/config/versions/magento-2.4.0.js +3 -1
  38. package/lib/config/versions/magento-2.4.1-p1.js +3 -1
  39. package/lib/config/versions/magento-2.4.1.js +3 -1
  40. package/lib/config/versions/magento-2.4.2-p1.js +3 -1
  41. package/lib/config/versions/magento-2.4.2-p2.js +3 -1
  42. package/lib/config/versions/magento-2.4.2.js +3 -1
  43. package/lib/config/versions/magento-2.4.3-p1.js +3 -1
  44. package/lib/config/versions/magento-2.4.3-p2.js +3 -1
  45. package/lib/config/versions/magento-2.4.3.js +3 -1
  46. package/lib/config/versions/magento-2.4.4.js +3 -1
  47. package/lib/config/xml-parser.js +63 -0
  48. package/lib/errors/known-error.js +15 -0
  49. package/lib/errors/unknown-error.js +15 -0
  50. package/lib/tasks/cli/create-bashrc-config.js +2 -1
  51. package/lib/tasks/composer/index.js +5 -3
  52. package/lib/tasks/composer/local-auth-json.js +8 -4
  53. package/lib/tasks/docker/network.js +2 -1
  54. package/lib/tasks/execute/index.js +2 -3
  55. package/lib/tasks/file-system/create-nginx-config.js +4 -43
  56. package/lib/tasks/file-system/create-php-config.js +2 -1
  57. package/lib/tasks/file-system/create-php-fpm-config.js +2 -1
  58. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +249 -0
  59. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +85 -0
  60. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +154 -0
  61. package/lib/tasks/file-system/create-phpstorm-config/index.js +27 -0
  62. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +26 -0
  63. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +54 -0
  64. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +28 -0
  65. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +42 -0
  66. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +37 -0
  67. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +80 -0
  68. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +26 -0
  69. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +142 -0
  70. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +20 -0
  71. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +60 -0
  72. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +116 -0
  73. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +37 -0
  74. package/lib/tasks/file-system/create-phpstorm-config/keys.js +14 -0
  75. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +67 -0
  76. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +54 -0
  77. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +66 -0
  78. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +58 -0
  79. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +59 -0
  80. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +77 -0
  81. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +97 -0
  82. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +57 -0
  83. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +66 -0
  84. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +64 -0
  85. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +57 -0
  86. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +49 -0
  87. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +64 -0
  88. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +5 -0
  89. package/lib/tasks/file-system/create-ssl-terminator-config.js +96 -0
  90. package/lib/tasks/file-system/create-varnish-config.js +2 -1
  91. package/lib/tasks/file-system/create-vscode-config.js +3 -2
  92. package/lib/tasks/file-system/index.js +3 -1
  93. package/lib/tasks/magento/enable-magento-composer-plugins.js +3 -2
  94. package/lib/tasks/magento/install-magento.js +7 -5
  95. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +26 -0
  96. package/lib/tasks/magento/setup-magento/delete-admin-users.js +1 -1
  97. package/lib/tasks/magento/setup-magento/delete-customers.js +7 -4
  98. package/lib/tasks/magento/setup-magento/delete-orders.js +6 -4
  99. package/lib/tasks/magento/setup-magento/flush-redis-config.js +2 -1
  100. package/lib/tasks/magento/setup-magento/index.js +3 -1
  101. package/lib/tasks/magento/setup-magento/install-magento.js +2 -1
  102. package/lib/tasks/magento/setup-magento/set-base-url.js +7 -2
  103. package/lib/tasks/magento/setup-magento/upgrade-magento.js +11 -1
  104. package/lib/tasks/magento/setup-magento/waiting-for-varnish.js +41 -0
  105. package/lib/tasks/mysql/connect-to-mysql.js +2 -1
  106. package/lib/tasks/mysql/import-dump-to-mysql.js +13 -2
  107. package/lib/tasks/mysql/import-remote-db/index.js +2 -1
  108. package/lib/tasks/mysql/import-remote-db/ssh/index.js +2 -1
  109. package/lib/tasks/mysql/import-remote-db/ssh/regular-server.js +2 -1
  110. package/lib/tasks/php/bundled-extensions.js +28 -0
  111. package/lib/tasks/php/compile-options.js +27 -54
  112. package/lib/tasks/php/compile.js +6 -4
  113. package/lib/tasks/php/configure.js +7 -66
  114. package/lib/tasks/php/extensions/disable.js +2 -1
  115. package/lib/tasks/php/extensions/enable.js +2 -1
  116. package/lib/tasks/php/extensions/index.js +74 -0
  117. package/lib/tasks/php/extensions/install.js +3 -3
  118. package/lib/tasks/php/index.js +7 -6
  119. package/lib/tasks/php/install-sodium.js +93 -0
  120. package/lib/tasks/php/update-phpbrew.js +7 -3
  121. package/lib/tasks/php/validate-php.js +67 -0
  122. package/lib/tasks/php-fpm/start-php-fpm.js +4 -2
  123. package/lib/tasks/requirements/composer.js +59 -5
  124. package/lib/tasks/requirements/dependency/arch.js +2 -1
  125. package/lib/tasks/requirements/dependency/centos.js +2 -1
  126. package/lib/tasks/requirements/dependency/fedora.js +2 -1
  127. package/lib/tasks/requirements/dependency/mac.js +18 -3
  128. package/lib/tasks/requirements/docker/index.js +94 -40
  129. package/lib/tasks/requirements/docker/install-on-mac.js +29 -0
  130. package/lib/tasks/requirements/docker/install.js +2 -1
  131. package/lib/tasks/requirements/docker/running-status.js +32 -31
  132. package/lib/tasks/requirements/docker/version.js +2 -1
  133. package/lib/tasks/requirements/index.js +3 -0
  134. package/lib/tasks/requirements/node-version.js +2 -1
  135. package/lib/tasks/requirements/php-version.js +26 -24
  136. package/lib/tasks/requirements/phpbrew/index.js +2 -1
  137. package/lib/tasks/requirements/phpbrew/install.js +14 -2
  138. package/lib/tasks/requirements/phpbrew/version.js +2 -1
  139. package/lib/tasks/requirements/platform.js +5 -3
  140. package/lib/tasks/requirements/rosetta.js +32 -0
  141. package/lib/tasks/start.js +10 -2
  142. package/lib/tasks/status/index.js +24 -8
  143. package/lib/tasks/theme/build-theme.js +2 -1
  144. package/lib/tasks/theme/install-theme.js +2 -1
  145. package/lib/tasks/theme/link-theme.js +2 -2
  146. package/lib/tasks/theme/retrieve-theme-data.js +2 -1
  147. package/lib/tasks/theme/setup-persisted-query.js +2 -1
  148. package/lib/tasks/theme/setup-themes.js +10 -3
  149. package/lib/tasks/theme/symlink-theme.js +8 -1
  150. package/lib/util/CSA-theme.js +4 -0
  151. package/lib/util/analytics.js +320 -0
  152. package/lib/util/arch.js +1 -1
  153. package/lib/util/config-file-validator.js +4 -2
  154. package/lib/util/config-php-json.js +3 -2
  155. package/lib/util/env-php-json.js +3 -2
  156. package/lib/util/exec-async-command.d.ts +2 -0
  157. package/lib/util/exec-async-command.js +31 -15
  158. package/lib/util/exec-async.js +9 -0
  159. package/lib/util/get-brew-bin-path.js +64 -0
  160. package/lib/util/get-installed-magento-version.js +3 -2
  161. package/lib/util/get-jsonfile-data.js +2 -1
  162. package/lib/util/install-dependencies-task.js +15 -5
  163. package/lib/util/instance-metadata.js +11 -4
  164. package/lib/util/ip.js +47 -1
  165. package/lib/util/magento-task.js +20 -9
  166. package/lib/util/php-task.js +7 -7
  167. package/lib/util/request.js +0 -0
  168. package/lib/util/resolve-configuration-with-overrides.js +2 -1
  169. package/lib/util/run-composer.js +5 -3
  170. package/lib/util/run-magento.js +3 -2
  171. package/lib/util/run-php.js +7 -2
  172. package/lib/util/wait-for-it.js +3 -2
  173. package/package.json +5 -3
  174. package/typings/context.d.ts +4 -0
  175. package/typings/index.d.ts +13 -1
  176. package/typings/phpstorm.d.ts +33 -0
  177. package/lib/tasks/file-system/create-php-storm-config.js +0 -82
  178. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +0 -20
@@ -1,4 +1,7 @@
1
1
  /* eslint-disable max-len */
2
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
3
+ const KnownError = require('../../errors/known-error');
4
+ const UnknownError = require('../../errors/unknown-error');
2
5
  const { execAsyncSpawn } = require('../../util/exec-async-command');
3
6
  const pathExists = require('../../util/path-exists');
4
7
 
@@ -9,7 +12,7 @@ const importDumpToMySQL = () => ({
9
12
  title: 'Importing Database Dump To MySQL',
10
13
  task: async (ctx, task) => {
11
14
  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`);
15
+ throw new KnownError(`Dump file at ${ctx.importDb} does not exist. Please provide correct relative path to the file`);
13
16
  }
14
17
 
15
18
  const { config: { docker }, ports } = ctx;
@@ -42,7 +45,15 @@ const importDumpToMySQL = () => ({
42
45
  }
43
46
  );
44
47
  } catch (e) {
45
- throw new Error(`Unexpected error during dump import.\n\n${e}`);
48
+ if (e.includes('Unknown collation: \'utf8mb4_0900_ai_ci\'')) {
49
+ throw new KnownError(`Error happened during database dump import!
50
+
51
+ ${e}
52
+
53
+ You can try replacing all occurrences of ${logger.style.misc('utf8mb4_0900_ai_ci')} with ${logger.style.misc('utf8mb4_general_ci')} in your ${logger.style.file(ctx.importDb)} file!`);
54
+ }
55
+
56
+ throw new UnknownError(`Unexpected error during dump import.\n\n${e}`);
46
57
  }
47
58
 
48
59
  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,18 @@
1
+ /* eslint-disable max-len */
2
+ const { getBrewCommandSync, getBrewBinPathSync } = require('../../util/get-brew-bin-path');
3
+ const { bundledExtensions } = require('./bundled-extensions');
4
+
5
+ const darwinVariants = [
6
+ `openssl=$(${getBrewCommandSync()} --prefix openssl@1.1)`, // ="$(brew --prefix openssl@1.1)"
7
+ `curl=$(${getBrewCommandSync()} --prefix curl)`,
8
+ `intl=$(${getBrewCommandSync()} --prefix icu4c)`,
9
+ `bz2="$(${getBrewCommandSync()} --prefix bzip2)"`
10
+ ];
11
+
1
12
  const compileOptions = {
2
13
  linux: {
3
14
  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
- ],
15
+ variants: bundledExtensions.map((ext) => `+${ext}`),
28
16
  extraOptions: [
29
17
  '--with-freetype-dir=/usr/include/freetype2',
30
18
  '--with-openssl=/usr/',
@@ -39,43 +27,28 @@ const compileOptions = {
39
27
  },
40
28
  darwin: {
41
29
  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
- ],
30
+ variants: bundledExtensions.map((ext) => {
31
+ const darwinVariant = darwinVariants.find((dv) => dv.startsWith(ext));
32
+ if (darwinVariant) {
33
+ return `+${darwinVariant}`;
34
+ }
35
+
36
+ return `+${ext}`;
37
+ }),
66
38
  extraOptions: [
67
- '--with-zlib-dir=$(brew --prefix zlib)',
68
- '--with-iconv=$(brew --prefix libiconv)',
39
+ `--with-zlib-dir=$(${getBrewCommandSync()} --prefix zlib)`,
40
+ `--with-iconv=$(${getBrewCommandSync()} --prefix libiconv)`,
69
41
  '--with-gd=shared'
70
42
  ],
71
43
  env: {
72
44
  // eslint-disable-next-line max-len
73
- PKG_CONFIG_PATH: '$PKG_CONFIG_PATH:$(brew --prefix libxml2)/lib/pkgconfig:$(brew --prefix icu4c)/lib/pkgconfig:$(brew --prefix openssl@1.1)/lib/pkgconfig:$(brew --prefix curl)/lib/pkgconfig:$(brew --prefix zlib)/lib/pkgconfig',
74
- CPATH: '$CPATH:$(brew --prefix openssl@1.1)/include',
45
+ PKG_CONFIG_PATH: `$PKG_CONFIG_PATH:$(${getBrewCommandSync()} --prefix libxml2)/lib/pkgconfig:$(${getBrewCommandSync()} --prefix icu4c)/lib/pkgconfig:$(${getBrewCommandSync()} --prefix openssl@1.1)/lib/pkgconfig:$(${getBrewCommandSync()} --prefix curl)/lib/pkgconfig:$(${getBrewCommandSync()} --prefix zlib)/lib/pkgconfig`,
46
+ CPATH: `$CPATH:$(${getBrewCommandSync()} --prefix openssl@1.1)/include`,
75
47
  CXX: 'g++ -DTRUE=1 -DFALSE=0',
76
48
  CC: 'gcc -DTRUE=1 -DFALSE=0',
77
- LDFLAGS: '$(brew --prefix openssl@1.1)/lib/libssl.dylib $(brew --prefix openssl@1.1)/lib/libcrypto.dylib',
78
- CFLAGS: '-Wno-implicit-function-declaration' // https://github.com/phpbrew/phpbrew/issues/1222
49
+ LDFLAGS: `$(${getBrewCommandSync()} --prefix openssl@1.1)/lib/libssl.dylib $(${getBrewCommandSync()} --prefix openssl@1.1)/lib/libcrypto.dylib`,
50
+ CFLAGS: '-Wno-implicit-function-declaration', // https://github.com/phpbrew/phpbrew/issues/1222
51
+ PATH: `${getBrewBinPathSync().replace('/brew', '')}:${process.env.PATH}`
79
52
  }
80
53
  }
81
54
  };
@@ -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];
@@ -27,11 +28,12 @@ const compile = () => ({
27
28
  {
28
29
  callback: (t) => {
29
30
  task.output = t;
30
- }
31
+ },
32
+ useRosetta2: true
31
33
  }
32
34
  );
33
35
  } catch (e) {
34
- throw new Error(
36
+ throw new UnknownError(
35
37
  `Failed to compile the required PHP version.
36
38
  Tried compiling the PHP version ${ logger.style.misc(php.version) }.
37
39
  Use your favorite search engine to resolve the issue.
@@ -44,4 +46,4 @@ const compile = () => ({
44
46
  }
45
47
  });
46
48
 
47
- module.exports = compile;
49
+ 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;
@@ -27,7 +27,8 @@ const disableExtension = (extensionName) => ({
27
27
  {
28
28
  callback: (t) => {
29
29
  task.output = t;
30
- }
30
+ },
31
+ useRosetta2: true
31
32
  });
32
33
  if (hooks && hooks.postDisable) {
33
34
  await Promise.resolve(hooks.postDisable(config));
@@ -29,7 +29,8 @@ const enableExtension = (extensionName, extensionOptions) => ({
29
29
  {
30
30
  callback: (t) => {
31
31
  task.output = t;
32
- }
32
+ },
33
+ useRosetta2: true
33
34
  });
34
35
 
35
36
  if (hooks && hooks.postEnable) {
@@ -0,0 +1,74 @@
1
+ /* eslint-disable max-len */
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const { execAsyncSpawn } = require('../../../util/exec-async-command');
6
+ const pathExists = require('../../../util/path-exists');
7
+ const phpbrewConfig = require('../../../config/phpbrew');
8
+ const { getArch } = require('../../../util/arch');
9
+
10
+ /**
11
+ * Get enabled extensions list with versions
12
+ * @param {import('../../../../typings/context').ListrContext['config']} param0
13
+ * @returns {Promise<{[key: string]: string}}>}
14
+ */
15
+ const getEnabledExtensions = async ({ php }) => {
16
+ const isArmMac = await getArch() === 'arm64' && os.platform() === 'darwin';
17
+ const output = await execAsyncSpawn(
18
+ `${isArmMac ? 'arch -x86_64 ' : ''}${ 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
+ };
69
+
70
+ module.exports = {
71
+ getEnabledExtensions,
72
+ getDisabledExtensions,
73
+ getInstalledExtensions
74
+ };
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable max-len */
2
- const macosVersion = require('macos-version');
3
2
  const phpbrewConfig = require('../../../config/phpbrew');
4
3
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
5
4
 
@@ -20,7 +19,7 @@ const installExtension = (extensionName, extensionOptions) => ({
20
19
  if (extensionOptions.install) {
21
20
  await Promise.resolve(extensionOptions.install(ctx, task));
22
21
  } else {
23
- const options = macosVersion.isMacOS ? extensionOptions.macosOptions : extensionOptions.linuxOptions;
22
+ const options = ctx.platform === 'darwin' ? extensionOptions.macosOptions : extensionOptions.linuxOptions;
24
23
 
25
24
  if (hooks && hooks.preInstall) {
26
25
  await Promise.resolve(hooks.preInstall(config));
@@ -32,7 +31,8 @@ const installExtension = (extensionName, extensionOptions) => ({
32
31
  {
33
32
  callback: (t) => {
34
33
  task.output = t;
35
- }
34
+ },
35
+ useRosetta2: true
36
36
  });
37
37
 
38
38
  if (hooks && hooks.postInstall) {
@@ -2,10 +2,11 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const logger = require('@scandipwa/scandipwa-dev-utils/logger');
4
4
  const pathExists = require('../../util/path-exists');
5
- const compile = require('./compile');
6
- const configure = require('./configure');
5
+ const compilePhp = require('./compile');
6
+ const configurePhp = require('./configure');
7
7
  const updatePhpBrew = require('./update-phpbrew');
8
8
  const phpbrewConfig = require('../../config/phpbrew');
9
+ const UnknownError = require('../../errors/unknown-error');
9
10
 
10
11
  /**
11
12
  * @type {() => import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
@@ -52,7 +53,7 @@ const installPhp = () => ({
52
53
  return;
53
54
  }
54
55
  } catch (e) {
55
- throw new Error(
56
+ throw new UnknownError(
56
57
  `Failed to extract the list of installed PHP versions.
57
58
  Possibly, you forgot to setup PHPBrew?
58
59
  Follow these instruction: ${ logger.style.link('https://phpbrew.github.io/phpbrew/#setting-up') }
@@ -63,7 +64,7 @@ const installPhp = () => ({
63
64
  // eslint-disable-next-line consistent-return
64
65
  return task.newListr([
65
66
  updatePhpBrew(),
66
- compile()
67
+ compilePhp()
67
68
  ], {
68
69
  concurrent: false,
69
70
  exitOnError: true
@@ -73,6 +74,6 @@ const installPhp = () => ({
73
74
 
74
75
  module.exports = {
75
76
  installPhp,
76
- compilePhp: compile,
77
- configurePhp: configure
77
+ compilePhp,
78
+ configurePhp
78
79
  };
@@ -0,0 +1,93 @@
1
+ const path = require('path');
2
+ const os = require('os');
3
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
4
+ const { cmaGlobalConfig } = require('../../config/cma-config');
5
+ const downloadFile = require('../../util/download-file');
6
+ const { execCommandTask } = require('../../util/exec-async-command');
7
+ const { getEnabledExtensions } = require('./extensions');
8
+
9
+ const libsodiumArchiveUrl = 'https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz';
10
+
11
+ const HAS_LIBSODIUM_BEEN_INSTALLED = 'hasLibsodiumBeenInstalled';
12
+
13
+ /**
14
+ * @returns {import('listr2').ListrTask<import('../../../typings/context').ListrContext>}
15
+ */
16
+ const installSodiumExtension = () => ({
17
+ skip: async (ctx) => {
18
+ if (ctx.isArmMac) {
19
+ if (cmaGlobalConfig.has(HAS_LIBSODIUM_BEEN_INSTALLED)) {
20
+ const hasLibsodiumBeenInstalled = cmaGlobalConfig.get(HAS_LIBSODIUM_BEEN_INSTALLED);
21
+ return hasLibsodiumBeenInstalled;
22
+ }
23
+
24
+ return false;
25
+ }
26
+
27
+ return true;
28
+ },
29
+ task: async (ctx, task) => {
30
+ task.title = 'Preparing libsodium to installation';
31
+ const tempDir = os.tmpdir();
32
+ const destination = path.join(tempDir, path.parse(libsodiumArchiveUrl).base);
33
+ const extractedArchivePath = path.join(tempDir, 'libsodium-stable');
34
+ const enabledExtensions = await getEnabledExtensions(ctx.config);
35
+
36
+ if ('sodium' in enabledExtensions) {
37
+ cmaGlobalConfig.set(HAS_LIBSODIUM_BEEN_INSTALLED, true);
38
+ task.skip();
39
+ return;
40
+ }
41
+
42
+ return task.newListr([
43
+ {
44
+ title: 'Downloading archive',
45
+ task: async () => {
46
+ await downloadFile(libsodiumArchiveUrl, { destination });
47
+ }
48
+ },
49
+ {
50
+ ...execCommandTask(`tar -zxf ${destination}`, {
51
+ cwd: tempDir
52
+ }),
53
+ title: 'Extracting archive'
54
+ },
55
+ execCommandTask('./configure', {
56
+ cwd: extractedArchivePath
57
+ }),
58
+ execCommandTask('make && make check', {
59
+ cwd: extractedArchivePath
60
+ }),
61
+ {
62
+ title: 'Installing...',
63
+ task: async (ctx, task) => {
64
+ task.output = 'Enter your sudo password!';
65
+ task.output = logger.style.command(`>[sudo] password for ${ os.userInfo().username }:`);
66
+
67
+ return task.newListr(
68
+ execCommandTask('sudo make install', {
69
+ callback: (t) => {
70
+ task.output = t;
71
+ },
72
+ pipeInput: true,
73
+ cwd: extractedArchivePath
74
+ })
75
+ );
76
+ },
77
+ options: {
78
+ bottomBar: 10
79
+ }
80
+ },
81
+ {
82
+ task: () => {
83
+ cmaGlobalConfig.set(HAS_LIBSODIUM_BEEN_INSTALLED, true);
84
+ }
85
+ }
86
+ ]);
87
+ },
88
+ options: {
89
+ bottomBar: 10
90
+ }
91
+ });
92
+
93
+ module.exports = installSodiumExtension;
@@ -1,3 +1,4 @@
1
+ const UnknownError = require('../../errors/unknown-error');
1
2
  const { execAsyncSpawn } = require('../../util/exec-async-command');
2
3
 
3
4
  /**
@@ -7,7 +8,9 @@ const updatePhpBrew = () => ({
7
8
  title: 'Updating PHPBrew PHP versions',
8
9
  task: async ({ config: { php } }, task) => {
9
10
  try {
10
- const knownPhpVersions = await execAsyncSpawn('phpbrew known');
11
+ const knownPhpVersions = await execAsyncSpawn('phpbrew known', {
12
+ useRosetta2: true
13
+ });
11
14
 
12
15
  if (knownPhpVersions.includes(`${php.version}`)) {
13
16
  task.skip();
@@ -17,10 +20,11 @@ const updatePhpBrew = () => ({
17
20
  await execAsyncSpawn('phpbrew known --update', {
18
21
  callback: (t) => {
19
22
  task.output = t;
20
- }
23
+ },
24
+ useRosetta2: true
21
25
  });
22
26
  } catch (e) {
23
- throw new Error(`Unexpected error while updating phpbrew known php versions\n\n${e}`);
27
+ throw new UnknownError(`Unexpected error while updating phpbrew known php versions\n\n${e}`);
24
28
  }
25
29
  },
26
30
  options: {