@oxog/dockcraft 1.1.1 → 1.2.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.js CHANGED
@@ -503,6 +503,7 @@ async function resolvePort(options = {}) {
503
503
  return preferred;
504
504
  }
505
505
  throw new PortConflictError(preferred);
506
+ // @ts-expect-error -- TS7029: the fall-through to 'auto' (no range given) is intended
506
507
  case "range":
507
508
  if (range) {
508
509
  const [start, end = start + 100] = range;
@@ -887,8 +888,8 @@ function validateServiceConfig(name, config) {
887
888
  if (!isComposeServiceName(name)) {
888
889
  errors.push({
889
890
  code: "INVALID_SERVICE_NAME",
890
- message: `Invalid service name '${name}'. Must start with a letter or digit and contain only letters, digits, '.', '_' and '-'.`,
891
- path: `services.${name}`,
891
+ message: `Invalid service name '${String(name)}'. Must start with a letter or digit and contain only letters, digits, '.', '_' and '-'.`,
892
+ path: `services.${String(name)}`,
892
893
  value: name
893
894
  });
894
895
  }
@@ -905,6 +906,7 @@ function validateServiceConfig(name, config) {
905
906
  if (svc.version !== void 0 && !isVersion(svc.version)) {
906
907
  errors.push({
907
908
  code: "INVALID_VERSION",
909
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string -- echoes whatever invalid value was given
908
910
  message: `Invalid version '${String(svc.version)}' for service '${name}'. Must be a valid Docker image tag.`,
909
911
  path: `services.${name}.version`,
910
912
  value: svc.version
@@ -913,6 +915,7 @@ function validateServiceConfig(name, config) {
913
915
  if (svc.image !== void 0 && !isDockerImage(svc.image)) {
914
916
  errors.push({
915
917
  code: "INVALID_IMAGE",
918
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string -- echoes whatever invalid value was given
916
919
  message: `Invalid image '${String(svc.image)}' for service '${name}'. Must be a Docker image reference such as 'elasticsearch:8.11.0'.`,
917
920
  path: `services.${name}.image`,
918
921
  value: svc.image
@@ -1032,9 +1035,47 @@ function nodeHealthcheckScript(port, path) {
1032
1035
  }
1033
1036
 
1034
1037
  // src/generators/dockerfile.ts
1038
+ var SHELL_BUILTINS = /* @__PURE__ */ new Set([
1039
+ ".",
1040
+ ":",
1041
+ "!",
1042
+ "alias",
1043
+ "bg",
1044
+ "break",
1045
+ "case",
1046
+ "cd",
1047
+ "command",
1048
+ "continue",
1049
+ "eval",
1050
+ "exec",
1051
+ "exit",
1052
+ "export",
1053
+ "fg",
1054
+ "for",
1055
+ "if",
1056
+ "jobs",
1057
+ "read",
1058
+ "readonly",
1059
+ "return",
1060
+ "set",
1061
+ "shift",
1062
+ "source",
1063
+ "time",
1064
+ "times",
1065
+ "trap",
1066
+ "ulimit",
1067
+ "umask",
1068
+ "unalias",
1069
+ "unset",
1070
+ "until",
1071
+ "wait",
1072
+ "while"
1073
+ ]);
1035
1074
  function dockerCmd(command) {
1036
1075
  const words = command.trim().split(/\s+/);
1037
- if (words.every((word) => /^[\w@%+=:,./-]+$/.test(word))) {
1076
+ const first = words[0] ?? "";
1077
+ const needsShell = SHELL_BUILTINS.has(first) || /^[A-Za-z_]\w*=/.test(first);
1078
+ if (!needsShell && words.every((word) => /^[\w@%+=:,./-]+$/.test(word))) {
1038
1079
  return `CMD ${JSON.stringify(words).replace(/","/g, '", "')}`;
1039
1080
  }
1040
1081
  return `CMD ${command.trim()}`;
@@ -1481,7 +1522,7 @@ function envValue(value) {
1481
1522
  if (!/['\r\n]/.test(value)) {
1482
1523
  return `'${value}'`;
1483
1524
  }
1484
- const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r");
1525
+ const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\$/g, "\\$").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
1485
1526
  return `"${escaped}"`;
1486
1527
  }
1487
1528
  function generateEnvExample(config) {