@oxog/dockcraft 1.3.0 → 1.3.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.
package/dist/index.cjs CHANGED
@@ -85,7 +85,10 @@ var NoPortAvailableError = class extends DockcraftError {
85
85
  };
86
86
  var FileWriteError = class extends DockcraftError {
87
87
  constructor(path, code = "FILE_WRITE_ERROR", cause) {
88
- super(`Failed to write file: ${path}${cause instanceof Error ? ` (${cause.message})` : ""}`, code);
88
+ super(
89
+ `Failed to write file: ${path}${cause instanceof Error ? ` (${cause.message})` : ""}`,
90
+ code
91
+ );
89
92
  this.name = "FileWriteError";
90
93
  if (cause !== void 0) {
91
94
  this.cause = cause;
@@ -538,11 +541,7 @@ async function findAvailablePortInRange(start, end) {
538
541
  return void 0;
539
542
  }
540
543
  async function resolvePort(options = {}) {
541
- const {
542
- preferred = 3e3,
543
- strategy = "auto",
544
- range
545
- } = options;
544
+ const { preferred = 3e3, strategy = "auto", range } = options;
546
545
  switch (strategy) {
547
546
  case "fixed":
548
547
  if (await isPortAvailable(preferred)) {
@@ -646,7 +645,11 @@ async function resolveServicePorts(portConfig, containerPort) {
646
645
  const endPort = portConfig.end ?? startPort + 100;
647
646
  return {
648
647
  port: containerPort,
649
- hostPort: await resolvePort({ preferred: startPort, strategy: "range", range: [startPort, endPort] })
648
+ hostPort: await resolvePort({
649
+ preferred: startPort,
650
+ strategy: "range",
651
+ range: [startPort, endPort]
652
+ })
650
653
  };
651
654
  }
652
655
  return { port: containerPort };
@@ -682,7 +685,8 @@ async function resolveServiceConfig(name, config, projectName, definitions) {
682
685
  if (mongoConfig.database) env.MONGO_INITDB_DATABASE = mongoConfig.database;
683
686
  if (mongoConfig.user) env.MONGO_INITDB_ROOT_USERNAME = mongoConfig.user;
684
687
  if (mongoConfig.password) env.MONGO_INITDB_ROOT_PASSWORD = mongoConfig.password;
685
- if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE) env.MONGO_INITDB_DATABASE = projectName;
688
+ if (!mongoConfig.database && !config.env?.MONGO_INITDB_DATABASE)
689
+ env.MONGO_INITDB_DATABASE = projectName;
686
690
  } else if (name === "redis") {
687
691
  const redisConfig = config;
688
692
  if (redisConfig.password) env.REDIS_PASSWORD = redisConfig.password;
@@ -823,17 +827,21 @@ function namedVolume(spec) {
823
827
  var VALID_OUTPUT_FILES = ["dockerfile", "compose", "dockerignore", "env", "scripts", "makefile"];
824
828
  function validateProjectName(name) {
825
829
  if (isProjectName(name)) return [];
826
- return [{
827
- code: "INVALID_NAME",
828
- message: `Invalid project name '${String(name)}'. Must start with a letter and contain only letters, numbers, hyphens, and underscores.`,
829
- path: "name",
830
- value: name
831
- }];
830
+ return [
831
+ {
832
+ code: "INVALID_NAME",
833
+ message: `Invalid project name '${String(name)}'. Must start with a letter and contain only letters, numbers, hyphens, and underscores.`,
834
+ path: "name",
835
+ value: name
836
+ }
837
+ ];
832
838
  }
833
839
  function validateStringList(value, path) {
834
840
  if (value === void 0) return [];
835
841
  if (!Array.isArray(value)) {
836
- return [{ code: "INVALID_TYPE", message: `'${path}' must be an array of strings.`, path, value }];
842
+ return [
843
+ { code: "INVALID_TYPE", message: `'${path}' must be an array of strings.`, path, value }
844
+ ];
837
845
  }
838
846
  return value.filter((item) => !isSingleLine(item) || item === "").map((item) => ({
839
847
  code: "INVALID_VALUE",
@@ -897,7 +905,12 @@ function validateAppConfig(config) {
897
905
  }
898
906
  if (config.env !== void 0) {
899
907
  if (!Array.isArray(config.env)) {
900
- errors.push({ code: "INVALID_TYPE", message: `'app.env' must be an array of variable names.`, path: "app.env", value: config.env });
908
+ errors.push({
909
+ code: "INVALID_TYPE",
910
+ message: `'app.env' must be an array of variable names.`,
911
+ path: "app.env",
912
+ value: config.env
913
+ });
901
914
  } else {
902
915
  for (const envVar of config.env) {
903
916
  if (!isEnvVarName(envVar)) {
@@ -922,12 +935,14 @@ function validateServicePort(name, port) {
922
935
  return [];
923
936
  }
924
937
  }
925
- return [{
926
- code: "INVALID_PORT",
927
- message: `Invalid port configuration for service '${name}'. Must be a port number (1-65535), 'auto', or a range { start, end } with start <= end.`,
928
- path: `services.${name}.port`,
929
- value: port
930
- }];
938
+ return [
939
+ {
940
+ code: "INVALID_PORT",
941
+ message: `Invalid port configuration for service '${name}'. Must be a port number (1-65535), 'auto', or a range { start, end } with start <= end.`,
942
+ path: `services.${name}.port`,
943
+ value: port
944
+ }
945
+ ];
931
946
  }
932
947
  function validateServiceConfig(name, config) {
933
948
  const errors = [];
@@ -970,7 +985,12 @@ function validateServiceConfig(name, config) {
970
985
  errors.push(...validateServicePort(name, svc.port));
971
986
  if (svc.env !== void 0) {
972
987
  if (typeof svc.env !== "object" || svc.env === null || Array.isArray(svc.env)) {
973
- errors.push({ code: "INVALID_TYPE", message: `'services.${name}.env' must be an object of strings.`, path: `services.${name}.env`, value: svc.env });
988
+ errors.push({
989
+ code: "INVALID_TYPE",
990
+ message: `'services.${name}.env' must be an object of strings.`,
991
+ path: `services.${name}.env`,
992
+ value: svc.env
993
+ });
974
994
  } else {
975
995
  for (const [key, value] of Object.entries(svc.env)) {
976
996
  if (key === "" || /[=\s]/.test(key) || typeof value !== "string") {
@@ -984,7 +1004,14 @@ function validateServiceConfig(name, config) {
984
1004
  }
985
1005
  }
986
1006
  }
987
- for (const key of ["user", "password", "database", "rootPassword", "command", "healthcheck"]) {
1007
+ for (const key of [
1008
+ "user",
1009
+ "password",
1010
+ "database",
1011
+ "rootPassword",
1012
+ "command",
1013
+ "healthcheck"
1014
+ ]) {
988
1015
  const value = svc[key];
989
1016
  if (value !== void 0 && typeof value !== "string") {
990
1017
  errors.push({
@@ -1027,7 +1054,9 @@ function validateConfig(config) {
1027
1054
  if (typeof config !== "object" || config === null) {
1028
1055
  return {
1029
1056
  valid: false,
1030
- errors: [{ code: "INVALID_CONFIG", message: "Configuration must be an object.", value: config }]
1057
+ errors: [
1058
+ { code: "INVALID_CONFIG", message: "Configuration must be an object.", value: config }
1059
+ ]
1031
1060
  };
1032
1061
  }
1033
1062
  errors.push(...validateProjectName(config.name));
@@ -1054,7 +1083,10 @@ function validateResolvedConfig(config) {
1054
1083
  const usedPorts = /* @__PURE__ */ new Map();
1055
1084
  usedPorts.set(config.app.port, "app");
1056
1085
  for (const [serviceName, serviceConfig] of Object.entries(config.services)) {
1057
- const published = [serviceConfig.hostPort ?? serviceConfig.port, ...serviceConfig.ports ?? []];
1086
+ const published = [
1087
+ serviceConfig.hostPort ?? serviceConfig.port,
1088
+ ...serviceConfig.ports ?? []
1089
+ ];
1058
1090
  for (const port of published) {
1059
1091
  const owner = usedPorts.get(port);
1060
1092
  if (owner !== void 0) {
@@ -1881,7 +1913,8 @@ ${errorMessages}`, errors);
1881
1913
  }
1882
1914
  function isSafeOutputPath(fileName) {
1883
1915
  if (typeof fileName !== "string" || fileName === "" || fileName.includes("\0")) return false;
1884
- if ((0, import_path3.isAbsolute)(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\")) return false;
1916
+ if ((0, import_path3.isAbsolute)(fileName) || /^[a-zA-Z]:/.test(fileName) || fileName.startsWith("\\"))
1917
+ return false;
1885
1918
  const normalized = (0, import_path3.normalize)(fileName.replace(/\\/g, "/"));
1886
1919
  return !normalized.split(/[\\/]/).includes("..") && normalized !== ".";
1887
1920
  }
@@ -1897,11 +1930,11 @@ async function dockcraft(config, options = {}) {
1897
1930
  }
1898
1931
  const context = {
1899
1932
  config: resolved,
1900
- ports: new Map(
1901
- Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])
1902
- ),
1933
+ ports: new Map(Object.entries(resolved.services).map(([name, svc]) => [name, svc.port])),
1903
1934
  strings: new Map(
1904
- Object.entries(resolved.services).filter((entry) => Boolean(entry[1].connectionString)).map(([name, svc]) => [name, svc.connectionString])
1935
+ Object.entries(resolved.services).filter(
1936
+ (entry) => Boolean(entry[1].connectionString)
1937
+ ).map(([name, svc]) => [name, svc.connectionString])
1905
1938
  )
1906
1939
  };
1907
1940
  context.ports.set("app", resolved.app.port);