@solid-stack/builder 2.0.0 → 2.0.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 (34) hide show
  1. package/README.md +10 -0
  2. package/dist/bin.js +202 -119
  3. package/dist/bin.js.map +1 -1
  4. package/dist/commands/mesh/commands/down/handler.d.ts.map +1 -1
  5. package/dist/commands/mesh/commands/up/handler.d.ts.map +1 -1
  6. package/dist/commands/service/commands/down/handler.d.ts.map +1 -1
  7. package/dist/core/checkers/checkDockerfile.d.ts.map +1 -1
  8. package/dist/core/checkers/checkDockerfileContract.d.ts.map +1 -1
  9. package/dist/core/composition/compileServiceComposition.d.ts.map +1 -1
  10. package/dist/core/composition/composeNetworks.d.ts +2 -0
  11. package/dist/core/composition/composeNetworks.d.ts.map +1 -0
  12. package/dist/core/composition/composePaths.d.ts.map +1 -1
  13. package/dist/core/composition/composeVolumes.d.ts +15 -0
  14. package/dist/core/composition/composeVolumes.d.ts.map +1 -0
  15. package/dist/core/composition/namespaceDependencyCompose.d.ts.map +1 -1
  16. package/dist/core/composition/validateDependencyCompose.d.ts.map +1 -1
  17. package/dist/core/composition/validateOverrideCompose.d.ts.map +1 -1
  18. package/dist/core/config/pathSafety.d.ts +1 -0
  19. package/dist/core/config/pathSafety.d.ts.map +1 -1
  20. package/dist/core/mesh/runners/runMeshDev.d.ts.map +1 -1
  21. package/dist/core/mesh/runners/runMeshProd.d.ts.map +1 -1
  22. package/dist/core/mesh/runners/runMeshTestE2e.d.ts.map +1 -1
  23. package/dist/core/mesh/v2/compileMeshComposition.d.ts.map +1 -1
  24. package/dist/core/runners/runDev.d.ts.map +1 -1
  25. package/dist/core/runners/runProd.d.ts.map +1 -1
  26. package/dist/core/teardownCompose.d.ts +1 -0
  27. package/dist/core/teardownCompose.d.ts.map +1 -1
  28. package/dist/index.js +202 -119
  29. package/dist/index.js.map +1 -1
  30. package/dist/utils/paths.d.ts +2 -0
  31. package/dist/utils/paths.d.ts.map +1 -1
  32. package/dist/utils/runState.d.ts +1 -0
  33. package/dist/utils/runState.d.ts.map +1 -1
  34. package/package.json +6 -3
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Command, Argument } from 'commander';
2
2
  import pc22 from 'picocolors';
3
- import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, renameSync, statSync, unlinkSync } from 'fs';
4
- import path4 from 'path';
3
+ import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, renameSync, statSync, realpathSync, lstatSync, readlinkSync, unlinkSync } from 'fs';
4
+ import path from 'path';
5
5
  import { z } from 'zod';
6
6
  import { spawnSync, spawn } from 'child_process';
7
7
  import { fileURLToPath } from 'url';
@@ -81,18 +81,44 @@ function errorMessage(err) {
81
81
  return String(err);
82
82
  }
83
83
  function resolveProjectDir(projectDir) {
84
- return path4.resolve(projectDir ?? process.cwd());
84
+ return path.resolve(projectDir ?? process.cwd());
85
+ }
86
+ function isBindMount(source) {
87
+ if (!source) return false;
88
+ if (source.startsWith(".") || source.startsWith("/") || source.startsWith("~") || source.startsWith("\\")) {
89
+ return true;
90
+ }
91
+ if (/^[a-zA-Z]:[\\/]/.test(source)) {
92
+ return true;
93
+ }
94
+ return false;
85
95
  }
86
96
  function isPathInside(parentDir, childPath) {
87
- const absParent = path4.resolve(parentDir);
88
- const absChild = path4.resolve(absParent, childPath);
89
- const rel = path4.relative(absParent, absChild);
90
- return rel !== ".." && !rel.startsWith(".." + path4.sep) && !rel.startsWith("../") && !path4.isAbsolute(rel);
97
+ const absParent = canonicalPath(parentDir);
98
+ const absChild = canonicalPath(path.resolve(parentDir, childPath));
99
+ const rel = path.relative(absParent, absChild);
100
+ return rel !== ".." && !rel.startsWith(".." + path.sep) && !rel.startsWith("../") && !path.isAbsolute(rel);
101
+ }
102
+ function canonicalPath(value) {
103
+ const absolute = path.resolve(value);
104
+ try {
105
+ return realpathSync(absolute);
106
+ } catch (error) {
107
+ if (error.code !== "ENOENT") throw error;
108
+ try {
109
+ if (lstatSync(absolute).isSymbolicLink()) return canonicalPath(path.resolve(path.dirname(absolute), readlinkSync(absolute)));
110
+ } catch (linkError) {
111
+ if (linkError.code !== "ENOENT") throw linkError;
112
+ }
113
+ const parent = path.dirname(absolute);
114
+ if (parent === absolute) throw error;
115
+ return path.join(canonicalPath(parent), path.basename(absolute));
116
+ }
91
117
  }
92
118
 
93
119
  // src/utils/getBuildJson.ts
94
120
  var getBuildJson = (projectDir = process.cwd()) => {
95
- const absProjectDir = resolveProjectDir(projectDir), buildJsonPath = path4.join(absProjectDir, "build.json");
121
+ const absProjectDir = resolveProjectDir(projectDir), buildJsonPath = path.join(absProjectDir, "build.json");
96
122
  if (!existsSync(buildJsonPath)) throw new NotFoundError(`Build JSON file not found at ${buildJsonPath}. Please make sure build.json exists in the project root.`);
97
123
  let rawData;
98
124
  try {
@@ -113,6 +139,18 @@ var getBuildJson = (projectDir = process.cwd()) => {
113
139
  }
114
140
  return result.data;
115
141
  };
142
+ function resolveInsideProject(projectDir, relativePath, context) {
143
+ if (!relativePath.trim()) throw new ConfigError({ ...context, value: relativePath, reason: "Path must not be empty" });
144
+ const resolved = path.resolve(projectDir, relativePath);
145
+ if (!isPathInside(projectDir, relativePath)) throw new ConfigError({ ...context, value: relativePath, reason: "Path escapes the project directory" });
146
+ return resolved;
147
+ }
148
+ function resolveApplicationDockerfile(projectDir, relativePath = "Dockerfile", stage) {
149
+ const context = { sourceFile: path.join(projectDir, "build.json"), configPath: "dockerfile", ...stage ? { stage } : {} };
150
+ const resolved = resolveInsideProject(projectDir, relativePath, context);
151
+ if (!existsSync(resolved) || !statSync(resolved).isFile()) throw new ConfigError({ ...context, value: relativePath, reason: `Application Dockerfile not found or not a regular file: ${resolved}` });
152
+ return resolved;
153
+ }
116
154
 
117
155
  // src/core/checkers/constants.ts
118
156
  var HADOLINT_IMAGE = process.env.HADOLINT_IMAGE || "hadolint/hadolint:v2.12.0";
@@ -157,15 +195,7 @@ ${ctx.detail}`);
157
195
  // src/core/checkers/checkDockerfile.ts
158
196
  function checkDockerfile(buildJson, projectDir) {
159
197
  const dockerfileRel = buildJson.dockerfile || "Dockerfile";
160
- const dockerfilePath = path4.resolve(projectDir, dockerfileRel);
161
- if (!isPathInside(projectDir, dockerfilePath)) {
162
- throw new ScriptError(
163
- `Security error: Dockerfile path "${dockerfileRel}" escapes the project directory.`
164
- );
165
- }
166
- if (!existsSync(dockerfilePath)) {
167
- throw new ConfigError({ sourceFile: path4.join(projectDir, "build.json"), configPath: "dockerfile", value: dockerfileRel, composition: "service", reason: `Application Dockerfile not found at ${dockerfilePath}` });
168
- }
198
+ const dockerfilePath = resolveApplicationDockerfile(projectDir, dockerfileRel);
169
199
  const content = readFileSync(dockerfilePath, "utf-8");
170
200
  console.log(pc22.cyan(`
171
201
  \u{1F50D} Linting Dockerfile (${dockerfileRel})...`));
@@ -185,8 +215,8 @@ function getTemplatesDir() {
185
215
  lastEnvTemplatesDir = envVal;
186
216
  }
187
217
  if (envVal) {
188
- const envDir = path4.resolve(envVal);
189
- if (!fs.existsSync(envDir) || !fs.existsSync(path4.join(envDir, "docker"))) {
218
+ const envDir = path.resolve(envVal);
219
+ if (!fs.existsSync(envDir) || !fs.existsSync(path.join(envDir, "docker"))) {
190
220
  throw new ScriptError(
191
221
  `BUILDER_TEMPLATES_DIR is set to "${envVal}" but directory does not exist or lacks a "docker/" subdirectory (resolved: "${envDir}").`
192
222
  );
@@ -196,18 +226,18 @@ function getTemplatesDir() {
196
226
  if (cachedTemplatesDir && fs.existsSync(cachedTemplatesDir)) {
197
227
  return cachedTemplatesDir;
198
228
  }
199
- const currentDir = typeof __dirname !== "undefined" ? __dirname : path4.dirname(fileURLToPath(import.meta.url));
229
+ const currentDir = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
200
230
  const candidates = [
201
231
  // When executing compiled output in dist/ (e.g. dist/templates)
202
- path4.resolve(currentDir, "templates"),
203
- path4.resolve(currentDir, "../templates"),
232
+ path.resolve(currentDir, "templates"),
233
+ path.resolve(currentDir, "../templates"),
204
234
  // When executing from src/ (e.g. src/core/templates.ts -> ../../templates)
205
- path4.resolve(currentDir, "../../templates"),
235
+ path.resolve(currentDir, "../../templates"),
206
236
  // Fallback relative to cwd
207
- path4.resolve(process.cwd(), "templates")
237
+ path.resolve(process.cwd(), "templates")
208
238
  ];
209
239
  for (const cand of candidates) {
210
- if (fs.existsSync(cand) && fs.existsSync(path4.join(cand, "docker"))) {
240
+ if (fs.existsSync(cand) && fs.existsSync(path.join(cand, "docker"))) {
211
241
  cachedTemplatesDir = cand;
212
242
  return cand;
213
243
  }
@@ -219,15 +249,15 @@ ${candidates.join("\n")}`
219
249
  }
220
250
  function getDockerComposeTemplate(filename) {
221
251
  const templatesDir = getTemplatesDir();
222
- const filePath = path4.join(templatesDir, "docker", filename);
252
+ const filePath = path.join(templatesDir, "docker", filename);
223
253
  if (!fs.existsSync(filePath)) {
224
254
  throw new ScriptError(`Docker compose template not found: ${filePath}`);
225
255
  }
226
256
  return filePath;
227
257
  }
228
258
  function getDockerfilePolicyDir() {
229
- const policyDir = path4.join(getTemplatesDir(), "policy", "dockerfile");
230
- if (!fs.existsSync(path4.join(policyDir, "dockerfile.rego"))) throw new ScriptError(`Builder Dockerfile policy not found: ${policyDir}`);
259
+ const policyDir = path.join(getTemplatesDir(), "policy", "dockerfile");
260
+ if (!fs.existsSync(path.join(policyDir, "dockerfile.rego"))) throw new ScriptError(`Builder Dockerfile policy not found: ${policyDir}`);
231
261
  return policyDir;
232
262
  }
233
263
 
@@ -235,19 +265,12 @@ function getDockerfilePolicyDir() {
235
265
  function checkDockerfileContract(build, projectDir) {
236
266
  const root = resolveProjectDir(projectDir);
237
267
  const relative = build.dockerfile ?? "Dockerfile";
238
- const dockerfile = path4.resolve(root, relative);
239
- if (!isPathInside(root, dockerfile) || !existsSync(dockerfile)) throw new ConfigError({ sourceFile: path4.join(root, "build.json"), configPath: "dockerfile", value: relative, composition: "service", reason: "Application Dockerfile missing or outside project" });
268
+ resolveApplicationDockerfile(root, relative);
240
269
  const policyDir = getDockerfilePolicyDir();
241
270
  console.log(pc22.cyan(`
242
271
  \u{1F50D} Validating Builder Dockerfile contract (${relative})...`));
243
272
  runStep("docker", ["run", "--rm", "--network", "none", "--mount", `type=bind,src=${root},dst=/project,readonly`, "--mount", `type=bind,src=${policyDir},dst=/builder-policy,readonly`, "-w", "/project", CONFTEST_IMAGE, "test", relative, "-p", "/builder-policy"], root, { stepName: "Dockerfile Contract", targetFile: relative });
244
273
  }
245
- function resolveInsideProject(projectDir, relativePath, context) {
246
- if (!relativePath.trim()) throw new ConfigError({ ...context, value: relativePath, reason: "Path must not be empty" });
247
- const resolved = path4.resolve(projectDir, relativePath);
248
- if (!isPathInside(projectDir, relativePath)) throw new ConfigError({ ...context, value: relativePath, reason: "Path escapes the project directory" });
249
- return resolved;
250
- }
251
274
  function loadComposeDocument(absolutePath, context) {
252
275
  const fail = (reason, value) => {
253
276
  throw new ConfigError({ ...context, sourceFile: absolutePath, ...{} , reason });
@@ -281,7 +304,7 @@ function getDeclaredYamlFiles(build, projectDir) {
281
304
  const files = [];
282
305
  const seen = /* @__PURE__ */ new Set();
283
306
  const add = (relativePath, source, kind, stage) => {
284
- const absolutePath = path4.resolve(projectDir, relativePath);
307
+ const absolutePath = path.resolve(projectDir, relativePath);
285
308
  if (seen.has(absolutePath)) return;
286
309
  seen.add(absolutePath);
287
310
  files.push({ relativePath, absolutePath, source, kind, ...stage ? { stage } : {} });
@@ -307,6 +330,12 @@ function checkYamlFiles(build, projectDir) {
307
330
  }
308
331
  }
309
332
 
333
+ // src/core/composition/composeNetworks.ts
334
+ function normalizeNetworks(value) {
335
+ if (Array.isArray(value)) return Object.fromEntries(value.filter((name) => typeof name === "string").map((name) => [name, null]));
336
+ return value && typeof value === "object" ? { ...value } : {};
337
+ }
338
+
310
339
  // src/core/config/endpointProperties.ts
311
340
  function resolveEndpointProperty(endpoint, property, context) {
312
341
  const published = () => {
@@ -489,7 +518,7 @@ function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, valid
489
518
  }
490
519
  return allocated;
491
520
  }
492
- const cachePath = path4.join(projectDir, AUTO_PORT_CACHE_RELATIVE_PATH);
521
+ const cachePath = path.join(projectDir, AUTO_PORT_CACHE_RELATIVE_PATH);
493
522
  let cached = {};
494
523
  try {
495
524
  if (existsSync(cachePath)) {
@@ -513,7 +542,7 @@ function allocateHostPorts(projectDir, stage, intentsInDeterministicOrder, valid
513
542
  nextCache[intent.logicalPath] = selected;
514
543
  }
515
544
  if (intentsInDeterministicOrder.some((i) => i.requested === "AUTO")) {
516
- mkdirSync(path4.dirname(cachePath), { recursive: true });
545
+ mkdirSync(path.dirname(cachePath), { recursive: true });
517
546
  const temp = `${cachePath}.${process.pid}.tmp`;
518
547
  writeFileSync(temp, JSON.stringify({ version: AUTO_PORT_CACHE_VERSION, allocations: nextCache }, null, 2));
519
548
  renameSync(temp, cachePath);
@@ -524,7 +553,7 @@ function normalizeProjectName(name, projectDir) {
524
553
  let normalized = name.toLowerCase().replace(/[^a-z0-9_-]/g, "-").replace(/^[-_]+/, "").replace(/[-_]+$/, "");
525
554
  if (!normalized || !/^[a-z0-9]/.test(normalized)) {
526
555
  if (projectDir) {
527
- const hash = crypto.createHash("sha1").update(path4.resolve(projectDir)).digest("hex").slice(0, 7);
556
+ const hash = crypto.createHash("sha1").update(path.resolve(projectDir)).digest("hex").slice(0, 7);
528
557
  return `project-${hash}`;
529
558
  }
530
559
  return "project";
@@ -534,7 +563,7 @@ function normalizeProjectName(name, projectDir) {
534
563
  function deriveProjectName(name, stage, projectDir, options = {}) {
535
564
  let base = normalizeProjectName(name, projectDir);
536
565
  if (options.hash && projectDir) {
537
- const hash = crypto.createHash("sha1").update(path4.resolve(projectDir)).digest("hex").slice(0, 7);
566
+ const hash = crypto.createHash("sha1").update(path.resolve(projectDir)).digest("hex").slice(0, 7);
538
567
  base = `${base}-${hash}`;
539
568
  }
540
569
  if (!stage) {
@@ -555,24 +584,66 @@ function deriveProjectName(name, stage, projectDir, options = {}) {
555
584
  }
556
585
  return `${base}-${s}`;
557
586
  }
587
+ function parseVolume(mount) {
588
+ if (typeof mount === "string") {
589
+ const separators = [];
590
+ let start = 0;
591
+ for (let i = 0; i < mount.length; i++) {
592
+ if (mount[i] !== ":") continue;
593
+ if (i === start + 1 && /[a-z]/i.test(mount[start]) && /[\\/]/.test(mount[i + 1] ?? "")) continue;
594
+ separators.push(i);
595
+ start = i + 1;
596
+ }
597
+ const first = separators[0];
598
+ if (first === void 0) return { type: "volume", target: mount, suffix: "" };
599
+ const source = mount.slice(0, first), end = separators[1];
600
+ return { type: isBindMount(source) ? "bind" : "volume", source, target: mount.slice(first + 1, end), suffix: mount.slice(first) };
601
+ }
602
+ if (mount && typeof mount === "object") {
603
+ const value = mount;
604
+ return { type: String(value.type ?? "volume"), ...typeof value.source === "string" ? { source: value.source } : {}, target: String(value.target ?? ""), suffix: "" };
605
+ }
606
+ return void 0;
607
+ }
608
+ function rewriteVolumeSource(mount, source) {
609
+ const parsed = parseVolume(mount);
610
+ return typeof mount === "string" ? `${source}${parsed.suffix}` : { ...mount, source };
611
+ }
612
+ function namespaceVolume(mount, names) {
613
+ const parsed = parseVolume(mount);
614
+ const source = parsed?.type === "volume" && parsed.source ? names.get(parsed.source) : void 0;
615
+ return source ? rewriteVolumeSource(mount, source) : mount;
616
+ }
617
+ function isAnonymousVolume(mount) {
618
+ const parsed = parseVolume(mount);
619
+ return parsed?.type === "volume" && !parsed.source;
620
+ }
621
+ function isHostFilesystemRoot(source) {
622
+ const normalized = source.replaceAll("\\", "/");
623
+ if (/^[a-z]:\//i.test(normalized) || normalized.startsWith("//")) {
624
+ const windows = path.win32.normalize(source);
625
+ return windows === path.win32.parse(windows).root;
626
+ }
627
+ return path.posix.normalize(normalized) === "/";
628
+ }
629
+ function anonymousVolumeServices(services) {
630
+ return Object.entries(services).filter(([, service]) => Array.isArray(service.volumes) && service.volumes.some(isAnonymousVolume)).map(([name]) => name);
631
+ }
558
632
  var posix = (p) => p.replace(/\\/g, "/");
559
633
  function rebase(p, base, out) {
560
- if (path4.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p)) return posix(path4.normalize(p));
561
- const abs = path4.resolve(base, p);
562
- const rel = path4.relative(out, abs);
634
+ if (path.isAbsolute(p) || /^[A-Za-z]:[\\/]/.test(p)) return posix(path.normalize(p));
635
+ const abs = path.resolve(base, p);
636
+ const rel = path.relative(out, abs);
563
637
  const result = posix(isPathInside(out, rel) ? rel || "." : abs);
564
- return result !== "." && !result.startsWith(".") && !path4.isAbsolute(result) ? `./${result}` : result;
638
+ return result !== "." && !result.startsWith(".") && !path.isAbsolute(result) ? `./${result}` : result;
565
639
  }
566
640
  function volumeShort(v, base, out) {
567
- const parts = v.split(":");
568
- if (parts.length < 2) return v;
569
- const source = parts[0];
570
- if (source === "" || source.startsWith("/") || source.startsWith("~") || /^[A-Za-z]:[\\/]/.test(source)) return v;
571
- if (source.startsWith(".") || source.includes("/") || source.includes("\\")) parts[0] = rebase(source, base, out);
572
- return parts.join(":");
641
+ const mount = parseVolume(v);
642
+ if (mount?.type !== "bind" || !mount.source || /^(?:[\\/]|~|[a-z]:)/i.test(mount.source)) return v;
643
+ return rewriteVolumeSource(v, rebase(mount.source, base, out));
573
644
  }
574
645
  function rebaseComposePaths(document, composeFilePath, outputProjectDir) {
575
- const doc = structuredClone(document), base = path4.dirname(composeFilePath), out = path4.resolve(outputProjectDir);
646
+ const doc = structuredClone(document), base = path.dirname(composeFilePath), out = path.resolve(outputProjectDir);
576
647
  for (const svc of Object.values(doc.services ?? {})) {
577
648
  if (typeof svc.build === "string") svc.build = rebase(svc.build, base, out);
578
649
  else if (svc.build && typeof svc.build === "object") {
@@ -639,13 +710,13 @@ function namespaceDependencyCompose(options) {
639
710
  svc.network_mode = `service:${serviceNameMap.get(key) ?? key}`;
640
711
  }
641
712
  if (Array.isArray(svc.volumes_from)) svc.volumes_from = svc.volumes_from.map((v) => typeof v === "string" ? v.replace(/^([^:]+)(.*)$/, (all, n, rest) => `${serviceNameMap.get(n) ?? n}${rest}`) : v);
642
- if (Array.isArray(svc.volumes)) svc.volumes = svc.volumes.map((v) => {
643
- if (typeof v !== "string") return v;
644
- const [src, ...rest] = v.split(":");
645
- const mapped = volumeNameMap.get(src);
646
- return mapped ? [mapped, ...rest].join(":") : v;
647
- });
648
- if (svc.volumes && Array.isArray(svc.volumes)) svc.volumes = svc.volumes.map((v) => v && typeof v === "object" && v.type === "volume" ? { ...v, source: volumeNameMap.get(v.source) ?? v.source } : v);
713
+ if (Array.isArray(svc.volumes)) svc.volumes = svc.volumes.map((v) => namespaceVolume(v, volumeNameMap));
714
+ if (svc.networks === void 0 && svc.network_mode === void 0 && svc.extends === void 0 && networkNameMap.has("default")) svc.networks = { default: null };
715
+ for (const key of ["ipc", "pid"]) if (typeof svc[key] === "string" && svc[key].startsWith("service:")) svc[key] = `service:${serviceNameMap.get(svc[key].slice(8)) ?? svc[key].slice(8)}`;
716
+ if (svc.extends && typeof svc.extends === "object" && !svc.extends.file) {
717
+ const ref = svc.extends;
718
+ if (typeof ref.service === "string") ref.service = serviceNameMap.get(ref.service) ?? ref.service;
719
+ }
649
720
  if (Array.isArray(svc.networks)) svc.networks = svc.networks.map((v) => typeof v === "string" ? networkNameMap.get(v) ?? v : v);
650
721
  else if (svc.networks && typeof svc.networks === "object") svc.networks = rewriteKeys(svc.networks, networkNameMap);
651
722
  for (const key of ["configs", "secrets"]) if (Array.isArray(svc[key])) svc[key] = svc[key].map((v) => typeof v === "string" ? (key === "configs" ? configNameMap : secretNameMap).get(v) ?? v : v && typeof v === "object" ? { ...v, source: (key === "configs" ? configNameMap : secretNameMap).get(v.source) ?? v.source } : v);
@@ -672,8 +743,8 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
672
743
  if (svc.privileged === true) fail(`services.${name}.privileged`, `privileged services are forbidden`);
673
744
  if (svc.container_name !== void 0) fail(`services.${name}.container_name`, `fixed container_name is forbidden`);
674
745
  for (const v of Array.isArray(svc.volumes) ? svc.volumes : []) {
675
- const source = typeof v === "string" ? v.split(":")[0] : v && typeof v === "object" ? v.source : void 0;
676
- if (typeof source === "string" && source.replaceAll("\\", "/") === "/") fail(`services.${name}.volumes`, `host root bind mounts are forbidden`, v);
746
+ const mount = parseVolume(v);
747
+ if (mount?.type === "bind" && mount.source && isHostFilesystemRoot(mount.source)) fail(`services.${name}.volumes`, "host root bind mounts are forbidden", v);
677
748
  }
678
749
  const internalRefs = [];
679
750
  if (Array.isArray(svc.depends_on)) {
@@ -688,6 +759,12 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
688
759
  if (Array.isArray(svc.volumes_from)) {
689
760
  for (const ref of svc.volumes_from) if (typeof ref === "string") internalRefs.push(["volumes_from", ref.split(":")[0]]);
690
761
  }
762
+ for (const key of ["ipc", "pid"]) if (typeof svc[key] === "string" && svc[key].startsWith("service:")) internalRefs.push([key, svc[key].slice(8)]);
763
+ if (svc.extends && typeof svc.extends === "object") {
764
+ const ref = svc.extends;
765
+ if (ref.file !== void 0) fail(`services.${name}.extends.file`, "external extends is unsupported for atomic dependency implementations");
766
+ if (typeof ref.service === "string") internalRefs.push(["extends.service", ref.service]);
767
+ }
691
768
  for (const [property, target] of internalRefs) if (!services[target]) fail(`services.${name}.${property}`, `internal service reference "${target}" does not exist in this dependency Compose bundle`, target);
692
769
  }
693
770
  if (!Object.keys(dependency.endpoints).length) return;
@@ -707,8 +784,8 @@ function validateDependencyCompose(dependencyKey, dependency, document, context)
707
784
 
708
785
  // src/core/composition/validateOverrideCompose.ts
709
786
  function validateAndPrepareAppOverride(document, context) {
710
- const fail = (path20, reason, value) => {
711
- throw new ConfigError({ sourceFile: context.file, configPath: path20, stage: context.stage, composition: "service", ...{} , reason });
787
+ const fail = (path19, reason, value) => {
788
+ throw new ConfigError({ sourceFile: context.file, configPath: path19, stage: context.stage, composition: "service", ...{} , reason });
712
789
  };
713
790
  const keys = Object.keys(document.services ?? {});
714
791
  if (keys.length !== 1 || keys[0] !== "app") fail("services", "override must define exactly one service named app");
@@ -729,27 +806,25 @@ function validateAndPrepareAppOverride(document, context) {
729
806
  const resourceKeys = ["volumes", "networks", "configs", "secrets"];
730
807
  const resources = {};
731
808
  for (const kind of resourceKeys) {
732
- const defs = document[kind] ?? {};
733
- const refs2 = /* @__PURE__ */ new Set();
734
- const refsVal = app[kind];
735
- if (Array.isArray(refsVal)) for (const v of refsVal) {
736
- if (typeof v === "string") refs2.add(v);
737
- else if (v && typeof v === "object" && typeof v.source === "string") refs2.add(v.source);
738
- }
739
- else if (refsVal && typeof refsVal === "object") for (const [k, v] of Object.entries(refsVal)) {
740
- refs2.add(k);
741
- if (v && typeof v === "object" && typeof v.source === "string") refs2.add(v.source);
742
- }
743
- const mapped = {};
744
- for (const [name, def] of Object.entries(defs)) {
809
+ const defs = document[kind] ?? {}, refs2 = /* @__PURE__ */ new Set(), value = app[kind];
810
+ if (Array.isArray(value)) for (const ref of value) {
811
+ if (kind === "volumes") {
812
+ const volume = parseVolume(ref);
813
+ if (volume?.type === "volume" && volume.source) refs2.add(volume.source);
814
+ } else if (typeof ref === "string") refs2.add(ref);
815
+ else if (ref && typeof ref === "object" && typeof ref.source === "string") refs2.add(ref.source);
816
+ }
817
+ else if (value && typeof value === "object") for (const name of Object.keys(value)) refs2.add(name);
818
+ const names = /* @__PURE__ */ new Map(), mapped = {};
819
+ for (const [name, definition] of Object.entries(defs)) {
745
820
  if (!refs2.has(name)) fail(`${kind}.${name}`, "override resource must be consumed by app");
746
821
  const target = `app-override--${context.stage}--${kind.slice(0, -1)}--${name}`;
747
- mapped[target] = def;
748
- for (const ref of refs2) if (ref === name) ;
822
+ names.set(name, target);
823
+ mapped[target] = definition;
749
824
  }
750
- if (Object.keys(mapped).length) resources[kind] = mapped;
751
- if (app[kind] && typeof app[kind] === "object" && !Array.isArray(app[kind])) app[kind] = Object.fromEntries(Object.entries(app[kind]).map(([k, v]) => [`app-override--${context.stage}--${kind.slice(0, -1)}--${k}`, v]));
752
- else if (Array.isArray(app[kind])) app[kind] = app[kind].map((v) => typeof v === "string" ? `app-override--${context.stage}--${kind.slice(0, -1)}--${v}` : v && typeof v === "object" ? { ...v, source: `app-override--${context.stage}--${kind.slice(0, -1)}--${v.source}` } : v);
825
+ if (names.size) resources[kind] = mapped;
826
+ if (Array.isArray(value)) app[kind] = value.map((ref) => kind === "volumes" ? namespaceVolume(ref, names) : typeof ref === "string" ? names.get(ref) ?? ref : ref && typeof ref === "object" && typeof ref.source === "string" ? { ...ref, source: names.get(ref.source) ?? ref.source } : ref);
827
+ else if (value && typeof value === "object") app[kind] = Object.fromEntries(Object.entries(value).map(([name, definition]) => [names.get(name) ?? name, definition]));
753
828
  }
754
829
  return { app, resources };
755
830
  }
@@ -860,10 +935,10 @@ function addPorts(service, endpointPairs) {
860
935
  }
861
936
  }
862
937
  function compileServiceComposition(stage, projectDir, options = {}) {
863
- const root = resolveProjectDir(projectDir), buildPath = path4.join(root, "build.json"), raw = getBuildJson(root), effective = resolveBuildStage(raw, stage, buildPath), profile = getExecutionProfile(stage, Boolean(options.full));
864
- resolveInsideProject(root, raw.dockerfile ?? "Dockerfile", { sourceFile: buildPath, configPath: "dockerfile", stage });
938
+ const root = resolveProjectDir(projectDir), buildPath = path.join(root, "build.json"), raw = getBuildJson(root), effective = resolveBuildStage(raw, stage, buildPath), profile = getExecutionProfile(stage, Boolean(options.full));
939
+ resolveApplicationDockerfile(root, raw.dockerfile ?? "Dockerfile", stage);
865
940
  const seed = getTemplateSeed(stage, Boolean(options.meshMode));
866
- const rawName = options.projectNameOverride ?? raw.name ?? path4.basename(root);
941
+ const rawName = options.projectNameOverride ?? raw.name ?? path.basename(root);
867
942
  const projectName = deriveProjectName(rawName, stage);
868
943
  const namespaced = {};
869
944
  for (const [key, dep] of Object.entries(effective.dependencies).sort(([a], [b]) => a.localeCompare(b))) {
@@ -937,7 +1012,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
937
1012
  }
938
1013
  const appEnv = options.deferReferenceResolution ? ownEnv(effective, stage) : resolveEnv(ownEnv(effective, stage), registry, "app.env");
939
1014
  let buildAppEnvironment = { ...appEnv };
940
- const runtimeDotenv = path4.join(root, `.env.${profile.runtimeStage}`);
1015
+ const runtimeDotenv = path.join(root, `.env.${profile.runtimeStage}`);
941
1016
  if (fs.existsSync(runtimeDotenv)) {
942
1017
  const text = fs.readFileSync(runtimeDotenv, "utf8");
943
1018
  for (const line of text.split(/\r?\n/)) {
@@ -947,14 +1022,14 @@ function compileServiceComposition(stage, projectDir, options = {}) {
947
1022
  }
948
1023
  const internal = { EXEC_MODE: profile.runtimeStage, INFRA_MODE: profile.integrated ? "integrated" : "isolated", ...getPrimaryEndpoint(effective.app.endpoints) ? { PORT: String(getPrimaryEndpoint(effective.app.endpoints)[1].port) } : {} };
949
1024
  const appBuild = app.build && typeof app.build === "object" ? app.build : { context: "." };
950
- const outputDir = options.composeOutputDir ? path4.resolve(options.composeOutputDir) : root;
951
- const serviceContext = path4.relative(outputDir, root).replace(/\\/g, "/") || ".";
1025
+ const outputDir = options.composeOutputDir ? path.resolve(options.composeOutputDir) : root;
1026
+ const serviceContext = path.relative(outputDir, root).replace(/\\/g, "/") || ".";
952
1027
  appBuild.context = options.meshMode ? serviceContext : ".";
953
1028
  if (raw.dockerfile) appBuild.dockerfile = raw.dockerfile;
954
1029
  else delete appBuild.dockerfile;
955
1030
  appBuild.target = profile.appTarget;
956
1031
  app.build = appBuild;
957
- app.env_file = [{ path: options.meshMode ? path4.posix.join(serviceContext, `.env.${profile.runtimeStage}`) : `.env.${profile.runtimeStage}`, required: false }];
1032
+ app.env_file = [{ path: options.meshMode ? path.posix.join(serviceContext, `.env.${profile.runtimeStage}`) : `.env.${profile.runtimeStage}`, required: false }];
958
1033
  app.environment = { ...appEnv, ...options.externalAppEnv ? Object.fromEntries(Object.entries(options.externalAppEnv).map(([k, v]) => [k, v.replace(/\$/g, "$$$$")])) : {}, ...internal };
959
1034
  if (stage === "dev") app.volumes = [`${options.meshMode && serviceContext !== "." ? `./${serviceContext}` : "."}:/app`, "/app/node_modules"];
960
1035
  for (const [name, ep] of Object.entries(appEndpoints)) if (!options.meshMode && ep.effectivelyPublished) addPorts(app, [[ep, ep.publicPort]]);
@@ -977,7 +1052,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
977
1052
  if (effective.overrideCompose) {
978
1053
  const overridePath = resolveInsideProject(root, effective.overrideCompose, { sourceFile: buildPath, configPath: "override-compose", stage });
979
1054
  const odoc = rebaseComposePaths(loadComposeDocument(overridePath, { sourceFile: buildPath, configPath: "override-compose", stage, composition: "service" }), overridePath, options.composeOutputDir ?? root);
980
- const prepared = validateAndPrepareAppOverride(odoc, { file: overridePath, stage, expectedBuildContext: options.meshMode ? path4.relative(options.composeOutputDir ?? root, root).replace(/\\/g, "/") || "." : "." });
1055
+ const prepared = validateAndPrepareAppOverride(odoc, { file: overridePath, stage, expectedBuildContext: options.meshMode ? path.relative(options.composeOutputDir ?? root, root).replace(/\\/g, "/") || "." : "." });
981
1056
  for (const section of ["volumes", "networks", "configs", "secrets"]) if (prepared.resources[section]) mergeDocument(compose, { services: {}, [section]: prepared.resources[section] }, "app override");
982
1057
  const rawOverrideEnv = normalizeComposeEnvironment(prepared.app.environment, "override-compose.services.app.environment");
983
1058
  const overrideEnv = options.deferReferenceResolution ? rawOverrideEnv : resolveEnv(rawOverrideEnv, registry, "override-compose.services.app.environment");
@@ -990,7 +1065,7 @@ function compileServiceComposition(stage, projectDir, options = {}) {
990
1065
  merged.build = appBuild;
991
1066
  merged.env_file = app.env_file;
992
1067
  merged.depends_on = app.depends_on;
993
- merged.networks = { default: null, ...app.networks ?? {}, ...prepared.app.networks ?? {} };
1068
+ merged.networks = { ...!options.meshMode ? { default: null } : {}, ...normalizeNetworks(app.networks), ...normalizeNetworks(prepared.app.networks) };
994
1069
  compose.services.app = merged;
995
1070
  app = merged;
996
1071
  }
@@ -1120,7 +1195,7 @@ var meshSchema = z.object({ $schema: z.string().optional(), name: z.string().opt
1120
1195
 
1121
1196
  // src/core/mesh/getMeshJson.ts
1122
1197
  function getMeshJson(projectDir = process.cwd()) {
1123
- const absDir = resolveProjectDir(projectDir), meshPath = path4.resolve(absDir, "mesh.json");
1198
+ const absDir = resolveProjectDir(projectDir), meshPath = path.resolve(absDir, "mesh.json");
1124
1199
  if (!existsSync(meshPath)) throw new NotFoundError(`mesh.json not found in directory: ${absDir}`);
1125
1200
  let content;
1126
1201
  try {
@@ -1173,9 +1248,9 @@ function resolveMeshStage(mesh, stage, sourceFile) {
1173
1248
  function loadEffectiveMeshServices(meshDir, effectiveMesh, stage) {
1174
1249
  const out = {};
1175
1250
  for (const [name, svc] of Object.entries(effectiveMesh.services).sort(([a], [b]) => a.localeCompare(b))) {
1176
- const abs = resolveInsideProject(meshDir, svc.path, { sourceFile: path4.join(meshDir, "mesh.json"), configPath: `services.${name}.path`, stage });
1177
- if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) throw new ConfigError({ sourceFile: path4.join(meshDir, "mesh.json"), configPath: `services.${name}.path`, stage, composition: "mesh", value: svc.path, reason: "Mesh service directory does not exist" });
1178
- const buildJsonPath = path4.join(abs, "build.json"), build = getBuildJson(abs), effectiveBuild = resolveBuildStage(build, stage, buildJsonPath);
1251
+ const abs = resolveInsideProject(meshDir, svc.path, { sourceFile: path.join(meshDir, "mesh.json"), configPath: `services.${name}.path`, stage });
1252
+ if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) throw new ConfigError({ sourceFile: path.join(meshDir, "mesh.json"), configPath: `services.${name}.path`, stage, composition: "mesh", value: svc.path, reason: "Mesh service directory does not exist" });
1253
+ const buildJsonPath = path.join(abs, "build.json"), build = getBuildJson(abs), effectiveBuild = resolveBuildStage(build, stage, buildJsonPath);
1179
1254
  out[name] = { name, path: svc.path, absolutePath: abs, buildJsonPath, effectiveBuild, meshEnv: { ...svc.env ?? {} }, dependencyBindings: { ...svc.dependencies ?? {} }, dependsOn: [...svc.dependsOn ?? []], publish: [...svc.publish ?? []] };
1180
1255
  }
1181
1256
  return out;
@@ -1417,8 +1492,8 @@ function setEnv(service, env) {
1417
1492
  service.environment = { ...current, ...env };
1418
1493
  }
1419
1494
  function compileMeshComposition(stage, meshDir, options = {}) {
1420
- const meshPath = path4.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, stage, meshPath), services = loadEffectiveMeshServices(meshDir, effective, stage), bindings = buildDependencyBindings(services, stage, meshPath), bindingMap = bindingsMap(bindings);
1421
- const rawName = raw.name ?? path4.basename(meshDir), projectName = deriveProjectName(rawName, stage, meshDir);
1495
+ const meshPath = path.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, stage, meshPath), services = loadEffectiveMeshServices(meshDir, effective, stage), bindings = buildDependencyBindings(services, stage, meshPath), bindingMap = bindingsMap(bindings);
1496
+ const rawName = raw.name ?? path.basename(meshDir), projectName = deriveProjectName(rawName, stage, meshDir);
1422
1497
  const fragments = {};
1423
1498
  const compose = { name: projectName, services: {}, networks: { mesh: { driver: "bridge" } } };
1424
1499
  for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
@@ -1439,20 +1514,20 @@ function compileMeshComposition(stage, meshDir, options = {}) {
1439
1514
  const owner = ep.networkHost;
1440
1515
  const ownerService = compose.services[owner];
1441
1516
  if (ownerService) {
1442
- const old = ownerService.networks && typeof ownerService.networks === "object" && !Array.isArray(ownerService.networks) ? ownerService.networks : {};
1517
+ const old = normalizeNetworks(ownerService.networks);
1443
1518
  old[privateName] = null;
1444
1519
  ownerService.networks = old;
1445
1520
  }
1446
1521
  }
1447
1522
  for (const generated of Object.keys(fragment.compose.services).filter((k) => k.startsWith(`svc--${name}--dep--${dep}--`))) {
1448
1523
  const ownerService = compose.services[generated];
1449
- const old = ownerService.networks && typeof ownerService.networks === "object" && !Array.isArray(ownerService.networks) ? ownerService.networks : {};
1524
+ const old = normalizeNetworks(ownerService.networks);
1450
1525
  old[privateName] = null;
1451
1526
  ownerService.networks = old;
1452
1527
  }
1453
1528
  }
1454
1529
  }
1455
- app.networks = networks;
1530
+ app.networks = { ...normalizeNetworks(app.networks), ...networks };
1456
1531
  }
1457
1532
  const publication = resolveMeshPublication(services, bindingMap, stage, meshPath), intents = [];
1458
1533
  for (const name of Object.keys(services).sort()) for (const pub of publication.filter((p) => p.ownerMeshService === name && p.target === "app").sort((a, b) => a.endpoint.localeCompare(b.endpoint))) {
@@ -1557,7 +1632,7 @@ function compileMeshComposition(stage, meshDir, options = {}) {
1557
1632
 
1558
1633
  // src/core/mesh/checkers/checkMeshServices.ts
1559
1634
  function checkMeshServices(mesh, meshDir) {
1560
- const root = resolveProjectDir(meshDir), meshPath = path4.join(root, "mesh.json");
1635
+ const root = resolveProjectDir(meshDir), meshPath = path.join(root, "mesh.json");
1561
1636
  const checked = /* @__PURE__ */ new Set();
1562
1637
  for (const stage of ["dev", "prod", "test", "e2e"]) {
1563
1638
  const effective = resolveMeshStage(mesh, stage, meshPath);
@@ -1587,11 +1662,11 @@ function checkMeshServices(mesh, meshDir) {
1587
1662
  function checkMeshTester(mesh, meshDir, options = {}) {
1588
1663
  const root = resolveProjectDir(meshDir);
1589
1664
  if (!mesh.tester) {
1590
- if (options.required) throw new ConfigError({ sourceFile: path4.join(root, "mesh.json"), configPath: "tester", stage: "e2e", composition: "mesh", reason: "Global mesh E2E requires root tester" });
1665
+ if (options.required) throw new ConfigError({ sourceFile: path.join(root, "mesh.json"), configPath: "tester", stage: "e2e", composition: "mesh", reason: "Global mesh E2E requires root tester" });
1591
1666
  return;
1592
1667
  }
1593
- const file = resolveInsideProject(root, mesh.tester.compose, { sourceFile: path4.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e" });
1594
- loadComposeDocument(file, { sourceFile: path4.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e", composition: "mesh" });
1668
+ const file = resolveInsideProject(root, mesh.tester.compose, { sourceFile: path.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e" });
1669
+ loadComposeDocument(file, { sourceFile: path.join(root, "mesh.json"), configPath: "tester.compose", stage: "e2e", composition: "mesh" });
1595
1670
  compileMeshComposition("e2e", root, { validationMode: true });
1596
1671
  }
1597
1672
 
@@ -1803,8 +1878,8 @@ async function teardownCompose(yamlConfig, projectDir, options = {}) {
1803
1878
  }
1804
1879
  const inputData = options.projectName ? void 0 : yamlConfig;
1805
1880
  if (!removeVolumes) {
1806
- const rmArgs = [...baseArgs, "rm", "-f", "-v", "app"];
1807
- await runSpawn("docker", rmArgs, absProjectDir, inputData, true, 15e3);
1881
+ const services = yamlConfig.trim() ? anonymousVolumeServices(parse(yamlConfig)?.services ?? {}) : options.anonymousVolumeServices ?? [];
1882
+ if (services.length) await runSpawn("docker", [...baseArgs, "rm", "-s", "-f", "-v", ...services], absProjectDir, inputData, true, 15e3);
1808
1883
  }
1809
1884
  const downArgs = [...baseArgs, "down"];
1810
1885
  if (removeVolumes) {
@@ -1861,12 +1936,12 @@ function redactYamlSecrets(yamlContent) {
1861
1936
  return redacted;
1862
1937
  }
1863
1938
  function getRunStatePath(projectDir) {
1864
- return path4.resolve(resolveProjectDir(projectDir), ".builder", "run.state");
1939
+ return path.resolve(resolveProjectDir(projectDir), ".builder", "run.state");
1865
1940
  }
1866
1941
  function writeRunState(projectDir, state) {
1867
1942
  try {
1868
1943
  const absDir = resolveProjectDir(projectDir);
1869
- const builderDir = path4.resolve(absDir, ".builder");
1944
+ const builderDir = path.resolve(absDir, ".builder");
1870
1945
  if (!existsSync(builderDir)) {
1871
1946
  mkdirSync(builderDir, { recursive: true });
1872
1947
  }
@@ -1875,7 +1950,7 @@ function writeRunState(projectDir, state) {
1875
1950
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
1876
1951
  };
1877
1952
  writeFileSync(
1878
- path4.resolve(builderDir, "run.state"),
1953
+ path.resolve(builderDir, "run.state"),
1879
1954
  JSON.stringify(fullState, null, 2),
1880
1955
  "utf-8"
1881
1956
  );
@@ -1906,9 +1981,9 @@ function projectNamesForServiceStage(projectDir, stage) {
1906
1981
  let rawName;
1907
1982
  try {
1908
1983
  const buildJson = getBuildJson(absDir);
1909
- rawName = buildJson.name || path4.basename(absDir);
1984
+ rawName = buildJson.name || path.basename(absDir);
1910
1985
  } catch {
1911
- rawName = path4.basename(absDir);
1986
+ rawName = path.basename(absDir);
1912
1987
  }
1913
1988
  const s = stage.toLowerCase();
1914
1989
  if (s === "dev") {
@@ -1937,10 +2012,10 @@ function projectNamesForMeshStage(meshDir, stage) {
1937
2012
  let serviceNames = [];
1938
2013
  try {
1939
2014
  const mesh = getMeshJson(absDir);
1940
- rawMeshName = mesh.name || path4.basename(absDir);
1941
- serviceNames = Object.keys(resolveMeshStage(mesh, "test", path4.join(absDir, "mesh.json")).services);
2015
+ rawMeshName = mesh.name || path.basename(absDir);
2016
+ serviceNames = Object.keys(resolveMeshStage(mesh, "test", path.join(absDir, "mesh.json")).services);
1942
2017
  } catch {
1943
- rawMeshName = path4.basename(absDir);
2018
+ rawMeshName = path.basename(absDir);
1944
2019
  }
1945
2020
  const s = stage.toLowerCase();
1946
2021
  if (s === "dev") {
@@ -1995,6 +2070,7 @@ async function handleMeshDown(rawStage = "dev", options = {}) {
1995
2070
  for (const proj of uniqueProjects) {
1996
2071
  await teardownCompose("", meshDir, {
1997
2072
  projectName: proj,
2073
+ ...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
1998
2074
  removeVolumes: Boolean(options.volumes)
1999
2075
  });
2000
2076
  }
@@ -2162,6 +2238,7 @@ async function runMeshDev(options = {}) {
2162
2238
  await checkHostPortCollisions(hostPorts);
2163
2239
  writeRunState(meshDir, {
2164
2240
  projectName,
2241
+ anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
2165
2242
  stage: "dev",
2166
2243
  projectDir: meshDir
2167
2244
  });
@@ -2203,6 +2280,7 @@ async function runMeshProd(options = {}) {
2203
2280
  await checkHostPortCollisions(hostPorts);
2204
2281
  writeRunState(meshDir, {
2205
2282
  projectName,
2283
+ anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
2206
2284
  stage: "prod",
2207
2285
  projectDir: meshDir
2208
2286
  });
@@ -2224,7 +2302,7 @@ async function runMeshProd(options = {}) {
2224
2302
  return status;
2225
2303
  }
2226
2304
  async function runMeshTestUnit(options = {}) {
2227
- const meshDir = resolveProjectDir(options.projectDir), meshPath = path4.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, "test", meshPath), services = loadEffectiveMeshServices(meshDir, effective, "test");
2305
+ const meshDir = resolveProjectDir(options.projectDir), meshPath = path.join(meshDir, "mesh.json"), raw = getMeshJson(meshDir), effective = resolveMeshStage(raw, "test", meshPath), services = loadEffectiveMeshServices(meshDir, effective, "test");
2228
2306
  console.log(pc22.bold(pc22.blue("\n[1/2] MESH SERVICE UNIT/ISOLATED TESTS\n")));
2229
2307
  for (const [name, svc] of Object.entries(services).sort(([a], [b]) => a.localeCompare(b))) {
2230
2308
  console.log(pc22.cyan(`-> Running isolated unit tests for [${name}]`));
@@ -2238,7 +2316,7 @@ async function runMeshTestUnit(options = {}) {
2238
2316
  const resolved = resolveMeshEnvMap(env, refCtx, `services.${name}.env`);
2239
2317
  const app = compiled.compose.services.app;
2240
2318
  app.environment = { ...app.environment, ...resolvedBuild, ...resolved };
2241
- const projectName = `${deriveProjectName(raw.name ?? path4.basename(meshDir), "dev")}-${name}-test`;
2319
+ const projectName = `${deriveProjectName(raw.name ?? path.basename(meshDir), "dev")}-${name}-test`;
2242
2320
  compiled.compose.name = projectName;
2243
2321
  const yaml = stringify(compiled.compose);
2244
2322
  if (options.debug) console.log(yaml);
@@ -2261,7 +2339,6 @@ async function runMeshTestUnit(options = {}) {
2261
2339
  }
2262
2340
  async function runMeshTestE2e(options = {}) {
2263
2341
  const meshDir = resolveProjectDir(options.projectDir), mesh = getMeshJson(meshDir);
2264
- if (!options.skipChecks) checkMesh(meshDir, { requireTester: true });
2265
2342
  if (!mesh.tester) throw new ScriptError("Global mesh E2E requires root mesh.json.tester { compose, service, env? }");
2266
2343
  const { yaml, testerServiceName } = compileMeshEnvironment("e2e", meshDir);
2267
2344
  if (!testerServiceName) throw new ScriptError("Global mesh E2E tester runner could not be compiled.");
@@ -2302,6 +2379,9 @@ async function handleMeshUp(rawStage = "dev", options = {}) {
2302
2379
  ...options,
2303
2380
  projectDir
2304
2381
  };
2382
+ if (["dev", "prod", "test-unit", "test-e2e", "test"].includes(stage) && !options.skipChecks) {
2383
+ checkMesh(projectDir, { requireTester: stage === "test-e2e" || stage === "test" });
2384
+ }
2305
2385
  switch (stage) {
2306
2386
  case "dev":
2307
2387
  return await runMeshDev(runOptions);
@@ -2455,6 +2535,7 @@ async function handleServiceDown(rawStage = "dev", options = {}) {
2455
2535
  for (const proj of uniqueProjects) {
2456
2536
  await teardownCompose("", projectDir, {
2457
2537
  projectName: proj,
2538
+ ...runState?.projectName === proj && runState.anonymousVolumeServices ? { anonymousVolumeServices: runState.anonymousVolumeServices } : {},
2458
2539
  removeVolumes: Boolean(options.volumes)
2459
2540
  });
2460
2541
  }
@@ -2523,6 +2604,7 @@ var runDev = async (options) => {
2523
2604
  await checkHostPortCollisions(hostPorts);
2524
2605
  writeRunState(options.projectDir, {
2525
2606
  projectName,
2607
+ anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
2526
2608
  stage: "dev",
2527
2609
  projectDir: options.projectDir
2528
2610
  });
@@ -2566,6 +2648,7 @@ var runProd = async (options) => {
2566
2648
  await checkHostPortCollisions(hostPorts);
2567
2649
  writeRunState(options.projectDir, {
2568
2650
  projectName,
2651
+ anonymousVolumeServices: anonymousVolumeServices(parsed?.services ?? {}),
2569
2652
  stage: "prod",
2570
2653
  projectDir: options.projectDir
2571
2654
  });
@@ -2902,7 +2985,7 @@ async function handleExportEnv(rawStage, options = {}) {
2902
2985
  const files = [];
2903
2986
  try {
2904
2987
  for (const snapshot of snapshots) {
2905
- let filename = path4.join(projectDir, `.env.${snapshot.stage}`);
2988
+ let filename = path.join(projectDir, `.env.${snapshot.stage}`);
2906
2989
  while (true) {
2907
2990
  let overwrite = false;
2908
2991
  if (existsSync(filename)) {
@@ -2911,11 +2994,11 @@ async function handleExportEnv(rawStage, options = {}) {
2911
2994
  if (!overwrite) {
2912
2995
  const name = (await ask(`New filename for ${snapshot.stage} (relative to the service directory): `)).trim();
2913
2996
  if (!name) continue;
2914
- filename = path4.resolve(projectDir, name);
2997
+ filename = path.resolve(projectDir, name);
2915
2998
  continue;
2916
2999
  }
2917
3000
  }
2918
- mkdirSync(path4.dirname(filename), { recursive: true });
3001
+ mkdirSync(path.dirname(filename), { recursive: true });
2919
3002
  try {
2920
3003
  writeFileSync(filename, snapshot.content, { encoding: "utf-8", flag: overwrite ? "w" : "wx", mode: 384 });
2921
3004
  } catch (error) {