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

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 (79) hide show
  1. package/lib/config/cma-config.js +16 -0
  2. package/lib/config/dependencies-for-platforms.js +3 -1
  3. package/lib/config/templates/varnish.template.vcl +9 -4
  4. package/lib/config/xml-parser.js +63 -0
  5. package/lib/tasks/file-system/create-phpstorm-config/database-config.js +249 -0
  6. package/lib/tasks/file-system/create-phpstorm-config/eslint-config.js +85 -0
  7. package/lib/tasks/file-system/create-phpstorm-config/exclude-folder-config.js +154 -0
  8. package/lib/tasks/file-system/create-phpstorm-config/index.js +27 -0
  9. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/coding-standard-config.js +26 -0
  10. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/config.js +54 -0
  11. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/custom-ruleset-path-config.js +28 -0
  12. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/default-properties-config.js +42 -0
  13. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/eslint-inspection-config.js +37 -0
  14. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/index.js +80 -0
  15. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/magento-coding-standard-config.js +26 -0
  16. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/mess-detector-validation-inspection-config.js +142 -0
  17. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/paths.js +20 -0
  18. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-fixer-validation-inspection-config.js +60 -0
  19. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/php-cs-validation-inspection-config.js +116 -0
  20. package/lib/tasks/file-system/create-phpstorm-config/inspection-tools-config/stylelint-inspection-config.js +37 -0
  21. package/lib/tasks/file-system/create-phpstorm-config/keys.js +14 -0
  22. package/lib/tasks/file-system/create-phpstorm-config/php-config/index.js +67 -0
  23. package/lib/tasks/file-system/create-phpstorm-config/php-config/mess-detector-config.js +54 -0
  24. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-code-sniffer-config.js +66 -0
  25. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-cs-fixer-config.js +58 -0
  26. package/lib/tasks/file-system/create-phpstorm-config/php-config/php-project-shared-configuration-config.js +59 -0
  27. package/lib/tasks/file-system/create-phpstorm-config/stylelint-config.js +77 -0
  28. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/composer-settings-config.js +97 -0
  29. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/format-setting-config.js +57 -0
  30. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/index.js +66 -0
  31. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-debug-general-config.js +64 -0
  32. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/php-server-config.js +57 -0
  33. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/properties-component-config.js +49 -0
  34. package/lib/tasks/file-system/create-phpstorm-config/workspace-config/run-manager-config.js +64 -0
  35. package/lib/tasks/file-system/create-phpstorm-config/xml-utils.js +5 -0
  36. package/lib/tasks/file-system/index.js +1 -1
  37. package/lib/tasks/magento/setup-magento/adjust-full-page-cache.js +26 -0
  38. package/lib/tasks/magento/setup-magento/delete-admin-users.js +1 -1
  39. package/lib/tasks/magento/setup-magento/delete-customers.js +7 -4
  40. package/lib/tasks/magento/setup-magento/delete-orders.js +6 -4
  41. package/lib/tasks/mysql/import-dump-to-mysql.js +9 -0
  42. package/lib/tasks/php/compile-options.js +13 -10
  43. package/lib/tasks/php/compile.js +2 -1
  44. package/lib/tasks/php/extensions/disable.js +2 -1
  45. package/lib/tasks/php/extensions/enable.js +2 -1
  46. package/lib/tasks/php/extensions/index.js +4 -1
  47. package/lib/tasks/php/extensions/install.js +3 -3
  48. package/lib/tasks/php/install-sodium.js +93 -0
  49. package/lib/tasks/php/update-phpbrew.js +5 -2
  50. package/lib/tasks/php-fpm/start-php-fpm.js +2 -1
  51. package/lib/tasks/requirements/composer.js +2 -2
  52. package/lib/tasks/requirements/dependency/mac.js +18 -3
  53. package/lib/tasks/requirements/docker/index.js +93 -40
  54. package/lib/tasks/requirements/docker/install-on-mac.js +29 -0
  55. package/lib/tasks/requirements/docker/running-status.js +30 -30
  56. package/lib/tasks/requirements/index.js +3 -0
  57. package/lib/tasks/requirements/php-version.js +21 -21
  58. package/lib/tasks/requirements/phpbrew/install.js +12 -1
  59. package/lib/tasks/requirements/platform.js +2 -1
  60. package/lib/tasks/requirements/rosetta.js +32 -0
  61. package/lib/tasks/start.js +2 -0
  62. package/lib/tasks/theme/link-theme.js +2 -2
  63. package/lib/tasks/theme/setup-themes.js +8 -2
  64. package/lib/tasks/theme/symlink-theme.js +6 -0
  65. package/lib/util/CSA-theme.js +4 -0
  66. package/lib/util/arch.js +1 -1
  67. package/lib/util/exec-async-command.d.ts +2 -0
  68. package/lib/util/exec-async-command.js +31 -15
  69. package/lib/util/exec-async.js +9 -0
  70. package/lib/util/get-brew-bin-path.js +64 -0
  71. package/lib/util/install-dependencies-task.js +11 -1
  72. package/lib/util/php-task.js +7 -7
  73. package/lib/util/run-composer.js +2 -1
  74. package/lib/util/run-php.js +4 -0
  75. package/package.json +3 -2
  76. package/typings/context.d.ts +3 -0
  77. package/typings/phpstorm.d.ts +33 -0
  78. package/lib/tasks/file-system/create-php-storm-config.js +0 -83
  79. package/lib/tasks/magento/setup-magento/disable-full-page-cache.js +0 -20
@@ -0,0 +1,57 @@
1
+ const { nameKey } = require('../keys');
2
+
3
+ const PHP_SERVERS_COMPONENT_NAME = 'PhpServers';
4
+
5
+ const hostKey = '@_host';
6
+
7
+ /**
8
+ * @param {Array} workspaceConfigs
9
+ * @param {import('../../../../../typings/phpstorm').PHPStormConfig} phpStormConfiguration
10
+ * @returns {Promise<Boolean>}
11
+ */
12
+ const setupPHPServers = async (workspaceConfigs, phpStormConfiguration) => {
13
+ const { xdebug } = phpStormConfiguration;
14
+ let hasChanges = false;
15
+ const phpServersComponent = workspaceConfigs.find(
16
+ (workspaceConfig) => workspaceConfig[nameKey] === PHP_SERVERS_COMPONENT_NAME
17
+ );
18
+
19
+ const defaultServerConfig = {
20
+ [hostKey]: xdebug.debugServerAddress,
21
+ id: '7e16e907-9ce3-4559-9d26-a30a5650d11f',
22
+ [nameKey]: xdebug.serverName
23
+ };
24
+
25
+ if (phpServersComponent) {
26
+ if (phpServersComponent.servers && !Array.isArray(phpServersComponent.servers)) {
27
+ hasChanges = true;
28
+ phpServersComponent.servers = [phpServersComponent.servers];
29
+ } else if (!phpServersComponent.servers) {
30
+ hasChanges = true;
31
+ phpServersComponent.servers = [];
32
+ }
33
+
34
+ const serverConfiguration = phpServersComponent.servers.find((server) => server.server[nameKey] === xdebug.serverName);
35
+
36
+ if (!serverConfiguration) {
37
+ hasChanges = true;
38
+ phpServersComponent.servers.push({
39
+ server: defaultServerConfig
40
+ });
41
+ }
42
+ } else {
43
+ hasChanges = true;
44
+ workspaceConfigs.push({
45
+ [nameKey]: PHP_SERVERS_COMPONENT_NAME,
46
+ servers: [
47
+ {
48
+ server: defaultServerConfig
49
+ }
50
+ ]
51
+ });
52
+ }
53
+
54
+ return hasChanges;
55
+ };
56
+
57
+ module.exports = setupPHPServers;
@@ -0,0 +1,49 @@
1
+ const path = require('path');
2
+ // const { baseConfig } = require('../../../../config');
3
+ const { getCSAThemes } = require('../../../../util/CSA-theme');
4
+ const pathExists = require('../../../../util/path-exists');
5
+ const { nameKey } = require('../keys');
6
+ // const { formatPathForPHPStormConfig } = require('../xml-utils');
7
+
8
+ const PROPERTIES_COMPONENT_NAME = 'PropertiesComponent';
9
+
10
+ const defaultProperties = {
11
+ keyToString: {
12
+ 'RunOnceActivity.OpenProjectViewOnStart': 'true',
13
+ 'RunOnceActivity.ShowReadmeOnStart': 'true'
14
+ }
15
+ };
16
+
17
+ /**
18
+ * @param {Array} workspaceConfigs
19
+ * @returns {Promise<Boolean>}
20
+ */
21
+ const setupPropertiesComponent = async (workspaceConfigs) => {
22
+ let hasChanges = false;
23
+ const propertiesComponent = workspaceConfigs.find(
24
+ (workspaceConfig) => workspaceConfig[nameKey] === PROPERTIES_COMPONENT_NAME
25
+ );
26
+
27
+ if (!propertiesComponent) {
28
+ hasChanges = true;
29
+ const themes = await getCSAThemes();
30
+ if (themes.length > 0) {
31
+ const theme = themes[0];
32
+ const themeESLintPath = path.join(process.cwd(), theme.themePath, 'node_modules', 'eslint');
33
+ if (await pathExists(themeESLintPath)) {
34
+ defaultProperties.keyToString['node.js.selected.package.eslint'] = themeESLintPath;
35
+ defaultProperties.keyToString['js.linters.configure.manually.selectedeslint'] = 'true';
36
+ defaultProperties.keyToString['node.js.detected.package.eslint'] = 'true';
37
+ defaultProperties.keyToString['settings.editor.selected.configurable'] = 'settings.javascript.linters.eslint';
38
+ }
39
+ }
40
+ workspaceConfigs.push({
41
+ [nameKey]: PROPERTIES_COMPONENT_NAME,
42
+ _cdata: JSON.stringify(defaultProperties)
43
+ });
44
+ }
45
+
46
+ return hasChanges;
47
+ };
48
+
49
+ module.exports = setupPropertiesComponent;
@@ -0,0 +1,64 @@
1
+ const { nameKey } = require('../keys');
2
+
3
+ const RUN_MANAGER_COMPONENT_NAME = 'RunManager';
4
+
5
+ const PHP_REMOTE_DEBUG_RUN_CONFIGURATION_TYPE = 'PhpRemoteDebugRunConfigurationType';
6
+
7
+ const serverNameKey = '@_server_name';
8
+ const sessionIdKey = '@_session_id';
9
+
10
+ /**
11
+ * @param {Array} workspaceConfigs
12
+ * @param {import('../../../../../typings/phpstorm').PHPStormConfig} phpStormConfiguration
13
+ * @returns {Promise<Boolean>}
14
+ */
15
+ const setupRunManager = async (workspaceConfigs, phpStormConfiguration) => {
16
+ const { xdebug } = phpStormConfiguration;
17
+ let hasChanges = false;
18
+ const runManagerComponent = workspaceConfigs.find(
19
+ (workspaceConfig) => workspaceConfig[nameKey] === RUN_MANAGER_COMPONENT_NAME
20
+ );
21
+
22
+ const defaultRunManagerConfiguration = {
23
+ [nameKey]: xdebug.runManagerName,
24
+ '@_type': PHP_REMOTE_DEBUG_RUN_CONFIGURATION_TYPE,
25
+ '@_factoryName': 'PHP Remote Debug',
26
+ '@_filter_connections': 'FILTER',
27
+ [serverNameKey]: xdebug.serverName,
28
+ [sessionIdKey]: xdebug.sessionId,
29
+ method: {
30
+ '@_v': '2'
31
+ }
32
+ };
33
+
34
+ if (runManagerComponent) {
35
+ if (runManagerComponent.configuration && !Array.isArray(runManagerComponent.configuration)) {
36
+ hasChanges = true;
37
+ runManagerComponent.configuration = [runManagerComponent.configuration];
38
+ } else if (!runManagerComponent.configuration) {
39
+ hasChanges = true;
40
+ runManagerComponent.configuration = [];
41
+ }
42
+
43
+ const phpRemoteDebugRunConfiguration = runManagerComponent.configuration.find(
44
+ (configuration) => configuration['@_type'] === PHP_REMOTE_DEBUG_RUN_CONFIGURATION_TYPE && configuration[nameKey] === xdebug.runManagerName
45
+ );
46
+
47
+ if (!phpRemoteDebugRunConfiguration) {
48
+ hasChanges = true;
49
+ runManagerComponent.configuration.push(defaultRunManagerConfiguration);
50
+ }
51
+ } else {
52
+ hasChanges = true;
53
+ workspaceConfigs.push({
54
+ [nameKey]: RUN_MANAGER_COMPONENT_NAME,
55
+ configuration: [
56
+ defaultRunManagerConfiguration
57
+ ]
58
+ });
59
+ }
60
+
61
+ return hasChanges;
62
+ };
63
+
64
+ module.exports = setupRunManager;
@@ -0,0 +1,5 @@
1
+ const formatPathForPHPStormConfig = (p) => p.replace(process.cwd(), '$PROJECT_DIR$');
2
+
3
+ module.exports = {
4
+ formatPathForPHPStormConfig
5
+ };
@@ -1,7 +1,7 @@
1
1
  const createNginxConfig = require('./create-nginx-config');
2
2
  const createPhpConfig = require('./create-php-config');
3
3
  const createPhpFpmConfig = require('./create-php-fpm-config');
4
- const createPhpStormConfig = require('./create-php-storm-config');
4
+ const createPhpStormConfig = require('./create-phpstorm-config');
5
5
  const createSSLTerminatorConfig = require('./create-ssl-terminator-config');
6
6
  const createVarnishConfig = require('./create-varnish-config');
7
7
  const createVSCodeConfig = require('./create-vscode-config');
@@ -0,0 +1,26 @@
1
+ const envPhpToJson = require('../../../util/env-php-json');
2
+ const magentoTask = require('../../../util/magento-task');
3
+
4
+ /**
5
+ * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
6
+ */
7
+ const disableFullPageCache = () => ({
8
+ title: 'Adjusting full_page cache setting',
9
+ task: async ({ magentoVersion, config }, task) => {
10
+ const { cache_types } = await envPhpToJson(process.cwd(), { magentoVersion });
11
+
12
+ if (cache_types.full_page !== 0 && !config.overridenConfiguration.configuration.varnish.enabled) {
13
+ task.title = 'Disabling full_page cache in Magento';
14
+ return task.newListr(magentoTask('cache:disable full_page'));
15
+ }
16
+
17
+ if (config.overridenConfiguration.configuration.varnish.enabled && cache_types.full_page !== 1) {
18
+ task.title = 'Enabling full_page cache in Magento (Varnish is enabled)';
19
+ return task.newListr(magentoTask('cache:enable full_page'));
20
+ }
21
+
22
+ task.skip();
23
+ }
24
+ });
25
+
26
+ module.exports = disableFullPageCache;
@@ -1,7 +1,7 @@
1
1
  const { isTableExists } = require('../../../util/database');
2
2
 
3
3
  /**
4
- * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
4
+ * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
5
  */
6
6
  const deleteAdminUsers = () => ({
7
7
  title: 'Deleting old admin users',
@@ -1,7 +1,7 @@
1
1
  const { customerTables } = require('../../mysql/magento-tables');
2
2
 
3
3
  /**
4
- * @type {() => import(listr2).ListrTask<import(../../../../typings/context).ListrContext>}
4
+ * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
5
  */
6
6
  const deleteCustomers = () => ({
7
7
  title: 'Deleting customers',
@@ -12,10 +12,13 @@ const deleteCustomers = () => ({
12
12
  task.skip();
13
13
  return;
14
14
  }
15
+
16
+ const [rows] = await mysqlConnection.query('select TABLE_NAME from information_schema.TABLES;');
17
+
15
18
  await Promise.all(
16
- customerTables.map(
17
- (tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`)
18
- )
19
+ customerTables
20
+ .filter((tableName) => rows.some((row) => row.TABLE_NAME === tableName))
21
+ .map((tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
19
22
  );
20
23
  }
21
24
  });
@@ -1,7 +1,7 @@
1
1
  const { orderTables } = require('../../mysql/magento-tables');
2
2
 
3
3
  /**
4
- * @type {import(listr2).ListrTask<import(../../../../typings/context).ListrContext>}
4
+ * @returns {import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
5
5
  */
6
6
  const deleteOrders = () => ({
7
7
  title: 'Deleting orders',
@@ -13,10 +13,12 @@ const deleteOrders = () => ({
13
13
  return;
14
14
  }
15
15
 
16
+ const [rows] = await mysqlConnection.query('select TABLE_NAME from information_schema.TABLES;');
17
+
16
18
  await Promise.all(
17
- orderTables.map(
18
- (tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`)
19
- )
19
+ orderTables
20
+ .filter((tableName) => rows.some((row) => row.TABLE_NAME === tableName))
21
+ .map((tableName) => mysqlConnection.query(`TRUNCATE TABLE \`${ tableName }\`;`))
20
22
  );
21
23
  }
22
24
  });
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable max-len */
2
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
2
3
  const KnownError = require('../../errors/known-error');
3
4
  const UnknownError = require('../../errors/unknown-error');
4
5
  const { execAsyncSpawn } = require('../../util/exec-async-command');
@@ -44,6 +45,14 @@ const importDumpToMySQL = () => ({
44
45
  }
45
46
  );
46
47
  } catch (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
+
47
56
  throw new UnknownError(`Unexpected error during dump import.\n\n${e}`);
48
57
  }
49
58
 
@@ -1,10 +1,12 @@
1
+ /* eslint-disable max-len */
2
+ const { getBrewCommandSync, getBrewBinPathSync } = require('../../util/get-brew-bin-path');
1
3
  const { bundledExtensions } = require('./bundled-extensions');
2
4
 
3
5
  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)"'
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)"`
8
10
  ];
9
11
 
10
12
  const compileOptions = {
@@ -34,18 +36,19 @@ const compileOptions = {
34
36
  return `+${ext}`;
35
37
  }),
36
38
  extraOptions: [
37
- '--with-zlib-dir=$(brew --prefix zlib)',
38
- '--with-iconv=$(brew --prefix libiconv)',
39
+ `--with-zlib-dir=$(${getBrewCommandSync()} --prefix zlib)`,
40
+ `--with-iconv=$(${getBrewCommandSync()} --prefix libiconv)`,
39
41
  '--with-gd=shared'
40
42
  ],
41
43
  env: {
42
44
  // eslint-disable-next-line max-len
43
- 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',
44
- 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`,
45
47
  CXX: 'g++ -DTRUE=1 -DFALSE=0',
46
48
  CC: 'gcc -DTRUE=1 -DFALSE=0',
47
- LDFLAGS: '$(brew --prefix openssl@1.1)/lib/libssl.dylib $(brew --prefix openssl@1.1)/lib/libcrypto.dylib',
48
- 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}`
49
52
  }
50
53
  }
51
54
  };
@@ -28,7 +28,8 @@ const compilePHP = () => ({
28
28
  {
29
29
  callback: (t) => {
30
30
  task.output = t;
31
- }
31
+ },
32
+ useRosetta2: true
32
33
  }
33
34
  );
34
35
  } catch (e) {
@@ -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) {
@@ -1,9 +1,11 @@
1
1
  /* eslint-disable max-len */
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
+ const os = require('os');
4
5
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
5
6
  const pathExists = require('../../../util/path-exists');
6
7
  const phpbrewConfig = require('../../../config/phpbrew');
8
+ const { getArch } = require('../../../util/arch');
7
9
 
8
10
  /**
9
11
  * Get enabled extensions list with versions
@@ -11,8 +13,9 @@ const phpbrewConfig = require('../../../config/phpbrew');
11
13
  * @returns {Promise<{[key: string]: string}}>}
12
14
  */
13
15
  const getEnabledExtensions = async ({ php }) => {
16
+ const isArmMac = await getArch() === 'arm64' && os.platform() === 'darwin';
14
17
  const output = await execAsyncSpawn(
15
- `${ php.binPath } -c ${php.iniPath} -r 'foreach (get_loaded_extensions() as $extension) echo "$extension:" . phpversion($extension) . "\n";'`
18
+ `${isArmMac ? 'arch -x86_64 ' : ''}${ php.binPath } -c ${php.iniPath} -r 'foreach (get_loaded_extensions() as $extension) echo "$extension:" . phpversion($extension) . "\n";'`
16
19
  );
17
20
 
18
21
  return output
@@ -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) {
@@ -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;
@@ -8,7 +8,9 @@ const updatePhpBrew = () => ({
8
8
  title: 'Updating PHPBrew PHP versions',
9
9
  task: async ({ config: { php } }, task) => {
10
10
  try {
11
- const knownPhpVersions = await execAsyncSpawn('phpbrew known');
11
+ const knownPhpVersions = await execAsyncSpawn('phpbrew known', {
12
+ useRosetta2: true
13
+ });
12
14
 
13
15
  if (knownPhpVersions.includes(`${php.version}`)) {
14
16
  task.skip();
@@ -18,7 +20,8 @@ const updatePhpBrew = () => ({
18
20
  await execAsyncSpawn('phpbrew known --update', {
19
21
  callback: (t) => {
20
22
  task.output = t;
21
- }
23
+ },
24
+ useRosetta2: true
22
25
  });
23
26
  } catch (e) {
24
27
  throw new UnknownError(`Unexpected error while updating phpbrew known php versions\n\n${e}`);
@@ -32,7 +32,8 @@ const startPhpFpm = () => ({
32
32
  {
33
33
  callback: (t) => {
34
34
  task.output = t;
35
- }
35
+ },
36
+ useRosetta2: true
36
37
  }
37
38
  );
38
39
  } catch (e) {
@@ -88,8 +88,8 @@ ${ logger.style.misc('Password') } (${ logger.style.misc('Private key') }):`,
88
88
  const authContent = {
89
89
  'http-basic': {
90
90
  'repo.magento.com': {
91
- username: usernameCredentials,
92
- password: passwordCredentials
91
+ username: usernameCredentials.trim(),
92
+ password: passwordCredentials.trim()
93
93
  }
94
94
  }
95
95
  };
@@ -1,14 +1,28 @@
1
+ const logger = require('@scandipwa/scandipwa-dev-utils/logger');
1
2
  const dependenciesForPlatforms = require('../../../config/dependencies-for-platforms');
3
+ const KnownError = require('../../../errors/known-error');
2
4
  const { execAsyncSpawn } = require('../../../util/exec-async-command');
5
+ const {
6
+ BREW_BIN_PATH_ARM_NATIVE,
7
+ BREW_BIN_PATH_ARM_ROSETTA,
8
+ getBrewCommand
9
+ } = require('../../../util/get-brew-bin-path');
3
10
  const installDependenciesTask = require('../../../util/install-dependencies-task');
4
-
11
+ const pathExists = require('../../../util/path-exists');
5
12
  /**
6
13
  * @type {() => import('listr2').ListrTask<import('../../../../typings/context').ListrContext>}
7
14
  */
8
15
  const macDependenciesCheck = () => ({
9
16
  title: 'Checking MacOS dependencies',
10
17
  task: async (ctx, task) => {
11
- const installedDependencies = (await execAsyncSpawn('brew list')).split('\n');
18
+ if (ctx.arch === 'arm64') {
19
+ if (!await pathExists(BREW_BIN_PATH_ARM_ROSETTA) && await pathExists(BREW_BIN_PATH_ARM_NATIVE)) {
20
+ throw new KnownError(`Missing rosetta brew!
21
+ Please make sure that you have installed brew in rosetta2 terminal!
22
+ Follow the instructions: ${logger.style.link('https://docs.create-magento-app.com/getting-started/prerequisites/installation-on-macos/installation-on-macos-apple-silicon')}`);
23
+ }
24
+ }
25
+ const installedDependencies = (await execAsyncSpawn(`${await getBrewCommand()} list`)).split('\n');
12
26
 
13
27
  const dependenciesToInstall = dependenciesForPlatforms
14
28
  .darwin
@@ -19,7 +33,8 @@ const macDependenciesCheck = () => ({
19
33
  return task.newListr(
20
34
  installDependenciesTask({
21
35
  platform: 'darwin',
22
- dependenciesToInstall
36
+ dependenciesToInstall,
37
+ useMacNativeEnvironment: false
23
38
  })
24
39
  );
25
40
  }