@oxog/dockcraft 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.3.2] - 2026-12-03
11
+
12
+ ### Fixed
13
+
14
+ - **`port: 'auto'` and `port: { start, end }` could pick a host port the same configuration
15
+ already publishes.** Only the host was probed, and the app (or an earlier service) is not
16
+ running yet, so e.g. a plugin service with default port 3000 and `port: 'auto'` next to the
17
+ app on 3000 got 3000 and generation failed with "already published by 'app'". Automatic
18
+ ports now skip the app port and the ports of earlier services.
19
+
10
20
  ## [1.3.1] - 2026-12-02
11
21
 
12
22
  ### Documentation
@@ -268,6 +278,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
268
278
 
269
279
  ---
270
280
 
281
+ [1.3.2]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.2
271
282
  [1.3.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.1
272
283
  [1.3.0]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.3.0
273
284
  [1.2.1]: https://github.com/ersinkoc/DockCraft/releases/tag/v1.2.1
package/dist/cli/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  // src/version.ts
9
- var VERSION = "1.3.1";
9
+ var VERSION = "1.3.2";
10
10
 
11
11
  // src/cli/parser.ts
12
12
  function parseArgs(args) {
@@ -1107,12 +1107,13 @@ function mergePreset(config, presetName) {
1107
1107
  );
1108
1108
  return merged;
1109
1109
  }
1110
- async function resolveServicePorts(portConfig, containerPort) {
1110
+ async function resolveServicePorts(portConfig, containerPort, claimed = /* @__PURE__ */ new Set()) {
1111
1111
  if (portConfig === "auto") {
1112
- return {
1113
- port: containerPort,
1114
- hostPort: await resolvePort({ preferred: containerPort, strategy: "auto" })
1115
- };
1112
+ let hostPort = await resolvePort({ preferred: containerPort, strategy: "auto" });
1113
+ while (claimed.has(hostPort)) {
1114
+ hostPort = await resolvePort({ preferred: hostPort + 1, strategy: "auto" });
1115
+ }
1116
+ return { port: containerPort, hostPort };
1116
1117
  }
1117
1118
  if (typeof portConfig === "number") {
1118
1119
  return { port: containerPort, hostPort: portConfig };
@@ -1120,26 +1121,36 @@ async function resolveServicePorts(portConfig, containerPort) {
1120
1121
  if (portConfig && typeof portConfig === "object") {
1121
1122
  const startPort = portConfig.start ?? containerPort;
1122
1123
  const endPort = portConfig.end ?? startPort + 100;
1123
- return {
1124
- port: containerPort,
1125
- hostPort: await resolvePort({
1126
- preferred: startPort,
1127
- strategy: "range",
1128
- range: [startPort, endPort]
1129
- })
1130
- };
1124
+ let hostPort = await resolvePort({
1125
+ preferred: startPort,
1126
+ strategy: "range",
1127
+ range: [startPort, endPort]
1128
+ });
1129
+ while (hostPort !== void 0 && claimed.has(hostPort)) {
1130
+ hostPort = hostPort < endPort ? await findAvailablePortInRange(hostPort + 1, endPort) : void 0;
1131
+ }
1132
+ if (hostPort === void 0) throw new NoPortAvailableError([startPort, endPort]);
1133
+ return { port: containerPort, hostPort };
1131
1134
  }
1132
1135
  return { port: containerPort };
1133
1136
  }
1134
- async function resolveServiceConfig(name, config, projectName, definitions) {
1137
+ async function resolveServiceConfig(name, config, projectName, definitions, claimedPorts) {
1135
1138
  if ("image" in config && config.image) {
1136
- return resolveCustomService(name, config);
1139
+ return resolveCustomService(
1140
+ name,
1141
+ config,
1142
+ claimedPorts
1143
+ );
1137
1144
  }
1138
1145
  const definition = definitions?.get(name) ?? getService(name);
1139
1146
  if (!definition) {
1140
1147
  throw new ServiceNotFoundError(name);
1141
1148
  }
1142
- const { port, hostPort } = await resolveServicePorts(config.port, definition.defaultPort);
1149
+ const { port, hostPort } = await resolveServicePorts(
1150
+ config.port,
1151
+ definition.defaultPort,
1152
+ claimedPorts
1153
+ );
1143
1154
  const version = config.version ?? definition.defaultVersion;
1144
1155
  const image = typeof definition.image === "function" ? definition.image(version) : definition.image;
1145
1156
  const env = { ...definition.env, ...config.env };
@@ -1189,14 +1200,14 @@ async function resolveServiceConfig(name, config, projectName, definitions) {
1189
1200
  }
1190
1201
  return resolvedConfig;
1191
1202
  }
1192
- async function resolveCustomService(name, config) {
1203
+ async function resolveCustomService(name, config, claimedPorts) {
1193
1204
  let containerPort = 80;
1194
1205
  if (typeof config.port === "number") {
1195
1206
  containerPort = config.port;
1196
1207
  } else if (config.port && typeof config.port === "object" && config.port.start) {
1197
1208
  containerPort = config.port.start;
1198
1209
  }
1199
- const { port, hostPort } = await resolveServicePorts(config.port, containerPort);
1210
+ const { port, hostPort } = await resolveServicePorts(config.port, containerPort, claimedPorts);
1200
1211
  return {
1201
1212
  name,
1202
1213
  image: config.image,
@@ -1229,14 +1240,20 @@ async function resolveConfig(config) {
1229
1240
  const app = normalizeAppConfig({ ...appConfig, port: appPort });
1230
1241
  const definitions = pluginServiceDefinitions(finalConfig.plugins);
1231
1242
  const services2 = {};
1243
+ const claimedPorts = /* @__PURE__ */ new Set([app.port]);
1232
1244
  for (const [name, serviceConfig] of Object.entries(finalConfig.services ?? {})) {
1233
1245
  if (serviceConfig) {
1234
- services2[name] = await resolveServiceConfig(
1246
+ const service = await resolveServiceConfig(
1235
1247
  name,
1236
1248
  serviceConfig,
1237
1249
  finalConfig.name,
1238
- definitions
1250
+ definitions,
1251
+ claimedPorts
1239
1252
  );
1253
+ services2[name] = service;
1254
+ for (const port of [service.hostPort ?? service.port, ...service.ports ?? []]) {
1255
+ claimedPorts.add(port);
1256
+ }
1240
1257
  }
1241
1258
  }
1242
1259
  return {