@solid-stack/builder 1.1.3 → 1.1.4

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/dist/bin.js CHANGED
@@ -527,20 +527,6 @@ function checkMeshJson(mesh) {
527
527
  }
528
528
  const services = result.data.services;
529
529
  const serviceKeys = new Set(Object.keys(services));
530
- const seenPorts = /* @__PURE__ */ new Map();
531
- for (const [serviceName, serviceConfig] of Object.entries(services)) {
532
- if (serviceConfig.port) {
533
- const portNum = Number(serviceConfig.port);
534
- if (!isNaN(portNum)) {
535
- if (seenPorts.has(portNum)) {
536
- throw new ScriptError(
537
- `Host port collision in mesh.json: Port ${portNum} is declared by both "${seenPorts.get(portNum)}" and "${serviceName}".`
538
- );
539
- }
540
- seenPorts.set(portNum, serviceName);
541
- }
542
- }
543
- }
544
530
  const graph = /* @__PURE__ */ new Map();
545
531
  for (const sName of serviceKeys) {
546
532
  graph.set(sName, /* @__PURE__ */ new Set());
@@ -854,7 +840,8 @@ var extractBuildDeps = (buildJson, projectDir = process.cwd()) => {
854
840
  z.string(),
855
841
  z.object({
856
842
  path: z.string(),
857
- service: z.string().optional()
843
+ service: z.string().optional(),
844
+ port: z.union([z.number(), z.string()]).optional()
858
845
  })
859
846
  )
860
847
  });
@@ -871,7 +858,8 @@ var extractBuildDeps = (buildJson, projectDir = process.cwd()) => {
871
858
  return {
872
859
  path: path13.resolve(projectDir, service.path),
873
860
  name,
874
- serviceName: service.service
861
+ serviceName: service.service,
862
+ port: service.port
875
863
  };
876
864
  }
877
865
  );
@@ -1144,24 +1132,44 @@ function compileMeshEnvironment(mode, rawMeshDir = process.cwd(), options = {})
1144
1132
  const globalDepAliasToProvider = /* @__PURE__ */ new Map();
1145
1133
  const INTERNAL_PORT = 3e3;
1146
1134
  const serviceUrls = /* @__PURE__ */ new Map();
1135
+ const allocatedPorts = /* @__PURE__ */ new Map();
1136
+ function claimPort(portVal, ownerDesc) {
1137
+ if (!portVal) return;
1138
+ const portStr = String(portVal);
1139
+ const hostPort = portStr.includes(":") ? portStr.split(":")[0] : portStr;
1140
+ if (!hostPort) return;
1141
+ if (allocatedPorts.has(hostPort)) {
1142
+ throw new ScriptError(
1143
+ `\u274C Port Collision Detected: Host port ${hostPort} is requested by both [${allocatedPorts.get(hostPort)}] and [${ownerDesc}].`
1144
+ );
1145
+ }
1146
+ allocatedPorts.set(hostPort, ownerDesc);
1147
+ }
1147
1148
  for (const [serviceName, serviceConfig] of Object.entries(mesh.services)) {
1148
1149
  const serviceDir = path13.resolve(meshDir, serviceConfig.path);
1149
1150
  const serviceBuildJson = getBuildJson(serviceDir);
1151
+ const serviceDeps = extractBuildDeps(serviceBuildJson, serviceDir);
1150
1152
  let publicPort = null;
1151
1153
  if (serviceConfig.port !== void 0 && serviceConfig.port !== null && serviceConfig.port !== "") {
1152
- const p = Number(serviceConfig.port);
1153
- if (!isNaN(p) && p > 0) {
1154
- publicPort = p;
1155
- }
1154
+ publicPort = serviceConfig.port;
1155
+ claimPort(publicPort, `mesh service "${serviceName}"`);
1156
1156
  } else if (serviceConfig.preservePort && serviceBuildJson.port) {
1157
- const p = Number(serviceBuildJson.port);
1158
- if (!isNaN(p) && p > 0) {
1159
- publicPort = p;
1157
+ publicPort = serviceBuildJson.port;
1158
+ claimPort(publicPort, `mesh service "${serviceName}" (via preservePort)`);
1159
+ }
1160
+ const provideMap = {
1161
+ ...serviceConfig.replaceMocks || {},
1162
+ ...serviceConfig.provideDependency || {}
1163
+ };
1164
+ for (const dep of serviceDeps) {
1165
+ if (!provideMap[dep.name] && !(mesh.dependencies && mesh.dependencies[dep.name]) && dep.port) {
1166
+ claimPort(dep.port, `local dependency "${dep.name}" of service "${serviceName}"`);
1160
1167
  }
1161
1168
  }
1169
+ const hostPort = publicPort ? String(publicPort).includes(":") ? String(publicPort).split(":")[0] : String(publicPort) : null;
1162
1170
  serviceUrls.set(serviceName, {
1163
1171
  networkUrl: `http://${serviceName}:${INTERNAL_PORT}`,
1164
- publicUrl: publicPort ? `http://localhost:${publicPort}` : null
1172
+ publicUrl: hostPort ? `http://localhost:${hostPort}` : null
1165
1173
  });
1166
1174
  }
1167
1175
  function escapeRegExp(string) {
@@ -1445,6 +1453,10 @@ function compileMeshEnvironment(mode, rawMeshDir = process.cwd(), options = {})
1445
1453
  delete resolvedMock.container_name;
1446
1454
  normalizeDependsOn(resolvedMock);
1447
1455
  applyInternalMockDependsOnMapping(resolvedMock, sidecarMapping);
1456
+ if (dep.port) {
1457
+ const portMapping = String(dep.port).includes(":") ? String(dep.port) : `${dep.port}:3000`;
1458
+ resolvedMock.ports = [...resolvedMock.ports || [], portMapping];
1459
+ }
1448
1460
  resolvedMock.networks = {
1449
1461
  [`${serviceName}_net`]: {
1450
1462
  aliases: [depKey, namespacedDepKey]
@@ -2710,9 +2722,11 @@ ${explanation}`);
2710
2722
  urlRegistry.set(buildJson.name, urlRegistry.get("app"));
2711
2723
  }
2712
2724
  for (const dep of dependencies) {
2725
+ const depPortStr = dep.port ? String(dep.port) : null;
2726
+ const depHostPort = depPortStr ? depPortStr.includes(":") ? depPortStr.split(":")[0] : depPortStr : null;
2713
2727
  urlRegistry.set(dep.name, {
2714
2728
  networkUrl: `http://${dep.name}:${INTERNAL_PORT}`,
2715
- publicUrl: null
2729
+ publicUrl: depHostPort ? `http://localhost:${depHostPort}` : null
2716
2730
  });
2717
2731
  }
2718
2732
  const interpolateEnv = (val, context) => {
@@ -2786,6 +2800,20 @@ ${explanation}`);
2786
2800
  yml.services.tester.environment[k] = interpolateEnv(v, "Tester EnvOverrides");
2787
2801
  }
2788
2802
  }
2803
+ if (yml.services) {
2804
+ for (const dep of dependencies) {
2805
+ if (dep.port) {
2806
+ let targetSvc = dep.serviceName && yml.services[dep.serviceName] ? dep.serviceName : dep.name;
2807
+ if (!yml.services[targetSvc]) {
2808
+ targetSvc = Object.keys(yml.services).find((k) => k !== "app" && k !== "tester") || targetSvc;
2809
+ }
2810
+ if (yml.services[targetSvc]) {
2811
+ const portMapping = String(dep.port).includes(":") ? String(dep.port) : `${dep.port}:3000`;
2812
+ yml.services[targetSvc].ports = [...yml.services[targetSvc].ports || [], portMapping];
2813
+ }
2814
+ }
2815
+ }
2816
+ }
2789
2817
  attachName(yml, projectName);
2790
2818
  const finalYamlConfig = stringify(yml);
2791
2819
  return finalYamlConfig;