@scandipwa/magento-scripts 2.4.0 → 2.4.2-alpha.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.
@@ -115,7 +115,7 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
115
115
  : {}
116
116
 
117
117
  /**
118
- * @type {Record<string, import('../tasks/docker/containers/container-api').ContainerRunOptions & { _?: string, forwardedPorts?: string[], remoteImages?: string[], connectCommand?: string[], description?: string, pullImage?: boolean, dependsOn?: string[] }>}
118
+ * @type {Record<string, import('../tasks/docker/containers/container-api').ContainerRunOptions & { _?: string, forwardedPorts?: string[], remoteImages?: string[], connectCommand?: string[], description?: string, pullImage?: boolean, dependsOn?: string[], serviceReadyLog?: string }>}
119
119
  */
120
120
  const dockerConfig = {
121
121
  php: {
@@ -169,7 +169,8 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
169
169
  (ctx.platform === 'linux' && isDockerDesktop) ||
170
170
  !isDockerDesktop
171
171
  ? `${os.userInfo().uid}:${os.userInfo().gid}`
172
- : ''
172
+ : '',
173
+ serviceReadyLog: 'ready to handle connections'
173
174
  },
174
175
  phpWithXdebug: {
175
176
  _: 'PHP with Xdebug',
@@ -228,7 +229,8 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
228
229
  (ctx.platform === 'linux' && isDockerDesktop) ||
229
230
  !isDockerDesktop
230
231
  ? `${os.userInfo().uid}:${os.userInfo().gid}`
231
- : ''
232
+ : '',
233
+ serviceReadyLog: 'ready to handle connections'
232
234
  },
233
235
  sslTerminator: {
234
236
  _: 'SSL Terminator (Nginx)',
@@ -337,7 +339,8 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
337
339
  redis.version ? `redis:${redis.version}` : redis.image
338
340
  }`,
339
341
  name: `${prefix}_redis`,
340
- connectCommand: ['redis-cli']
342
+ connectCommand: ['redis-cli'],
343
+ serviceReadyLog: 'Ready to accept connections'
341
344
  },
342
345
  mariadb: {
343
346
  _: 'MariaDB',
@@ -423,7 +426,9 @@ module.exports = async (ctx, overridenConfiguration, baseConfig) => {
423
426
  : elasticsearch.image
424
427
  : opensearch.image
425
428
  }`,
426
- name: `${prefix}_${searchengine}`
429
+ name: `${prefix}_${searchengine}`,
430
+ serviceReadyLog:
431
+ searchengine === 'elasticsearch' ? '"started"' : '] started'
427
432
  },
428
433
  maildev: {
429
434
  _: 'MailDev',
@@ -73,6 +73,8 @@ const defaultPorts = {
73
73
  sslTerminator: 80,
74
74
  fpm: 9000,
75
75
  fpmXdebug: 9001,
76
+ // for xdebug server running in the editor
77
+ xdebug: 9003,
76
78
  mariadb: 3306,
77
79
  redis: 6379,
78
80
  elasticsearch: 9200,
@@ -99,10 +101,12 @@ const getPortsConfig = async (ports, options = {}) => {
99
101
  p = p.concat(await getUsedByOtherCMAProjectsPorts())
100
102
  }
101
103
 
104
+ const { xdebug: _, ...portsWithoutXDebug } = mergedPorts
105
+
102
106
  /**
103
107
  * @type {Record<string, string>}
104
108
  */
105
- const portsToCheck = Object.entries(mergedPorts).reduce(
109
+ const portsToCheck = Object.entries(portsWithoutXDebug).reduce(
106
110
  (acc, [name, port]) => {
107
111
  if (acc[port]) {
108
112
  let i = 0
@@ -146,6 +150,21 @@ const getPortsConfig = async (ports, options = {}) => {
146
150
  }
147
151
  }
148
152
 
153
+ // XDebug port will be occupied by the editor
154
+ // so we can expect default port to be free
155
+ // if setup ran more than once
156
+ // first time: default port (9003) is free
157
+ // second time: default port (9003) is occupied by the editor, we choose 9004
158
+ // third time: default port (9004) is occupied by the editor, we choose 9003
159
+ // that way port number will not grow indefinitely
160
+ const xdebugPort = await getPort(defaultPorts.xdebug, {
161
+ portIgnoreList: Object.keys(availablePorts).map((item) =>
162
+ Number.parseInt(item)
163
+ )
164
+ })
165
+
166
+ availablePorts.xdebug = xdebugPort
167
+
149
168
  return availablePorts
150
169
  }
151
170
 
@@ -9,7 +9,7 @@ xdebug.remote_enable=1
9
9
 
10
10
  xdebug.remote_host=<%~ it.hostMachine %>
11
11
 
12
- xdebug.remote_port=9003
12
+ xdebug.remote_port=<%~ it.xdebugPort %>
13
13
 
14
14
  xdebug.remote_log=<%~ it.mageRoot %>/var/log/xdebug.log
15
15
 
@@ -18,7 +18,7 @@ xdebug.remote_log=<%~ it.mageRoot %>/var/log/xdebug.log
18
18
  xdebug.mode=debug
19
19
  xdebug.client_host=<%~ it.hostMachine %>
20
20
 
21
- xdebug.client_port=9003
21
+ xdebug.client_port=<%~ it.xdebugPort %>
22
22
 
23
23
  ; THIS THING WILL BREAK PHP
24
24
  ; xdebug.start_with_request=yes
@@ -5,6 +5,7 @@ const KnownError = require('../../../errors/known-error')
5
5
  const containerApi = require('./container-api')
6
6
  const { imageApi } = require('../image')
7
7
  const { execAsyncSpawn } = require('../../../util/exec-async-command')
8
+ const waitForLogs = require('../../../util/wait-for-logs')
8
9
 
9
10
  /**
10
11
  * @param {string[]} containers
@@ -154,7 +155,9 @@ const startContainers = () => ({
154
155
  all: true
155
156
  })
156
157
 
157
- const missingContainers = Object.entries(docker.getContainers(ports))
158
+ const containers = docker.getContainers(ports)
159
+
160
+ const missingContainers = Object.entries(containers)
158
161
  .filter(
159
162
  ([nameWithoutPrefix, { name }]) =>
160
163
  !containerList.some((c) => c.Names === name)
@@ -189,7 +192,9 @@ const startContainers = () => ({
189
192
  const startedContainers = []
190
193
  subTask.title = `Container ${
191
194
  container._
192
- } is waiting for ${dependsOn.join(', ')} to start...`
195
+ } is waiting for ${dependsOn
196
+ .map((a) => containers[a]._)
197
+ .join(', ')} to start...`
193
198
  await Promise.all(
194
199
  dependsOn.map(
195
200
  async (name) =>
@@ -217,6 +222,7 @@ const startContainers = () => ({
217
222
  d
218
223
  )
219
224
  )
225
+ .map((d) => containers[d]._)
220
226
  .join(', ')} to start...`
221
227
  clearTimeout(timeout)
222
228
  resolve()
@@ -231,6 +237,13 @@ const startContainers = () => ({
231
237
 
232
238
  await containerApi.run(container)
233
239
 
240
+ if (container.serviceReadyLog) {
241
+ await waitForLogs({
242
+ containerName: container.name,
243
+ matchText: container.serviceReadyLog
244
+ })
245
+ }
246
+
234
247
  containerStatuses[
235
248
  container.nameWithoutPrefix
236
249
  ].started = true
@@ -240,7 +253,7 @@ const startContainers = () => ({
240
253
  cb()
241
254
  })
242
255
 
243
- subTask.output = `${container._} container started`
256
+ subTask.title = `${container._} container started`
244
257
  }
245
258
  })),
246
259
  {
@@ -34,7 +34,7 @@ const createNginxConfig = () => ({
34
34
  networkSettings.phpWithXdebugNetwork = containers.phpWithXdebug.name
35
35
 
36
36
  networkSettings.fpmPort = 9000
37
- networkSettings.fpmXdebugPort = 9001
37
+ networkSettings.fpmXdebugPort = 9000
38
38
 
39
39
  networkSettings.hostPort = 80
40
40
  }
@@ -26,6 +26,8 @@ const createPhpDebugConfig = () => ({
26
26
  ? '127.0.0.1'
27
27
  : 'host.docker.internal'
28
28
 
29
+ const { xdebug: xdebugPort } = ctx.ports
30
+
29
31
  try {
30
32
  await setConfigFile({
31
33
  configPathname: php.debugIniPath,
@@ -35,7 +37,8 @@ const createPhpDebugConfig = () => ({
35
37
  debug,
36
38
  mageRoot: baseConfig.containerMagentoDir,
37
39
  isXDebug2,
38
- hostMachine
40
+ hostMachine,
41
+ xdebugPort
39
42
  }
40
43
  })
41
44
  } catch (e) {
@@ -36,7 +36,7 @@ const setupWorkspaceConfig = () => ({
36
36
  setupPHPStanProjectConfiguration(workspaceConfigs),
37
37
  setupPSalmProjectConfiguration(workspaceConfigs),
38
38
  setupPHPWorkspaceProjectConfiguration(workspaceConfigs, ctx),
39
- setupPHPDebugGeneral(workspaceConfigs),
39
+ setupPHPDebugGeneral(workspaceConfigs, ctx),
40
40
  setupPHPServers(workspaceConfigs, workspaceConfig, ctx),
41
41
  setupComposerSettings(workspaceConfigs, ctx),
42
42
  setupRunManager(workspaceConfigs, workspaceConfig),
@@ -61,7 +61,7 @@ const setupWorkspaceConfig = () => ({
61
61
  setupPHPCodeSnifferProjectConfiguration(workspaceConfigs),
62
62
  setupPHPStanProjectConfiguration(workspaceConfigs),
63
63
  setupPSalmProjectConfiguration(workspaceConfigs),
64
- setupPHPDebugGeneral(workspaceConfigs),
64
+ setupPHPDebugGeneral(workspaceConfigs, ctx),
65
65
  setupPHPServers(workspaceConfigs, workspaceConfig, ctx),
66
66
  setupPHPWorkspaceProjectConfiguration(workspaceConfigs, ctx),
67
67
  setupRunManager(workspaceConfigs, workspaceConfig),
@@ -7,13 +7,16 @@ const xdebugDebugPortKey = '@_xdebug_debug_port'
7
7
  const ignoreConnectionsThroughUnregisteredServersKey =
8
8
  '@_ignore_connections_through_unregistered_servers'
9
9
 
10
- const xdebugPort = '9003'
11
-
12
10
  /**
13
11
  * @param {Array} workspaceConfigs
12
+ * @param {import('../../../../../typings/context').ListrContext} ctx
14
13
  * @returns {Promise<Boolean>}
15
14
  */
16
- const setupPHPDebugGeneral = async (workspaceConfigs) => {
15
+ const setupPHPDebugGeneral = async (workspaceConfigs, ctx) => {
16
+ const { ports } = ctx
17
+
18
+ const xdebugPort = `${ports.xdebug}`
19
+
17
20
  let hasChanges = false
18
21
  const phpDebugGeneralComponent = workspaceConfigs.find(
19
22
  (workspaceConfig) =>
@@ -7,8 +7,6 @@ const UnknownError = require('../../errors/unknown-error')
7
7
 
8
8
  const listenForXDebugConfigName = 'Listen for XDebug'
9
9
 
10
- const xdebugPort = 9003
11
-
12
10
  const vscodeLaunchConfigPath = path.join(
13
11
  process.cwd(),
14
12
  '.vscode',
@@ -19,6 +17,7 @@ const vscodeLaunchConfigPath = path.join(
19
17
  * @param {import('../../../typings/context').ListrContext} ctx
20
18
  */
21
19
  const addPHPDebugConfig = (vscodeLaunchConfig, ctx) => {
20
+ const { ports } = ctx
22
21
  const phpXDebugConfig = vscodeLaunchConfig.configurations.find(
23
22
  ({ name }) => name === listenForXDebugConfigName
24
23
  )
@@ -29,7 +28,8 @@ const addPHPDebugConfig = (vscodeLaunchConfig, ctx) => {
29
28
  name: listenForXDebugConfigName,
30
29
  type: 'php',
31
30
  request: 'launch',
32
- port: xdebugPort,
31
+ // port: xdebugPort,
32
+ port: ports.xdebug,
33
33
  pathMappings: {
34
34
  // eslint-disable-next-line no-template-curly-in-string
35
35
  [ctx.config.baseConfig.containerMagentoDir]: '${workspaceFolder}'
@@ -52,8 +52,8 @@ const addPHPDebugConfig = (vscodeLaunchConfig, ctx) => {
52
52
  return true
53
53
  }
54
54
 
55
- if (!phpXDebugConfig.port || phpXDebugConfig.port !== xdebugPort) {
56
- phpXDebugConfig.port = xdebugPort
55
+ if (!phpXDebugConfig.port || phpXDebugConfig.port !== ports.xdebug) {
56
+ phpXDebugConfig.port = ports.xdebug
57
57
 
58
58
  hasChanges = true
59
59
  }
@@ -129,7 +129,7 @@ const createVSCodeConfig = () => ({
129
129
  template: vscodeLaunchConfigTemplatePath,
130
130
  configPathname: vscodeLaunchConfigPath,
131
131
  templateArgs: {
132
- XDebugPort: xdebugPort,
132
+ XDebugPort: ctx.ports.xdebug,
133
133
  baseConfig: ctx.config.baseConfig
134
134
  }
135
135
  })
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Scripts and configuration used by CMA.",
4
4
  "homepage": "https://docs.create-magento-app.com/",
5
5
  "repository": "github:scandipwa/create-magento-app",
6
- "version": "2.4.0",
6
+ "version": "2.4.2-alpha.0",
7
7
  "main": "./index.js",
8
8
  "types": "./typings/index.d.ts",
9
9
  "license": "OSL-3.0",
@@ -59,5 +59,5 @@
59
59
  "@types/node": "^20.14.11",
60
60
  "@types/yargs": "^17.0.32"
61
61
  },
62
- "gitHead": "2260d8d8945d830bb552aa910af847ce7fe8ab6b"
62
+ "gitHead": "77f33d97f83963ba52d9cf493a9a6cb86029a76e"
63
63
  }
@@ -118,6 +118,7 @@ export interface ListrContext {
118
118
  command: string
119
119
  connectCommand: string[]
120
120
  dependsOn?: string[]
121
+ serviceReadyLog?: string
121
122
  }
122
123
  >
123
124
  }
@@ -154,4 +155,5 @@ export interface ListrContext {
154
155
  dockerServerData?: DockerVersionResult['Server']
155
156
  dockerClientData?: DockerVersionResult['Client']
156
157
  dockerVersion?: DockerVersionResult['Server']['Version']
158
+ dockerMemoryLimit: number
157
159
  }