@catladder/cli 0.0.0-next-3401f823 → 0.0.0-next-32b3a548

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 (78) hide show
  1. package/dist/bundles/catenv/index.js +401 -145
  2. package/dist/bundles/cli/index.js +414 -151
  3. package/dist/cli/src/apps/catenv/printVariables.js.map +1 -1
  4. package/dist/cli/src/apps/catenv/types.d.ts +0 -1
  5. package/dist/cli/src/apps/catenv/utils.d.ts +2 -5
  6. package/dist/cli/src/apps/catenv/utils.js +4 -9
  7. package/dist/cli/src/apps/catenv/utils.js.map +1 -1
  8. package/dist/cli/src/apps/catenv/writeDotEnvFiles.js +1 -3
  9. package/dist/cli/src/apps/catenv/writeDotEnvFiles.js.map +1 -1
  10. package/dist/cli/src/apps/cli/commands/project/cloudSql/commandProjectRestoreDb.js +12 -12
  11. package/dist/cli/src/apps/cli/commands/project/cloudSql/commandProjectRestoreDb.js.map +1 -1
  12. package/dist/cli/src/apps/cli/commands/project/commandCloudSqlProxy.js +6 -6
  13. package/dist/cli/src/apps/cli/commands/project/commandCloudSqlProxy.js.map +1 -1
  14. package/dist/cli/src/config/getProjectConfig.js.map +1 -1
  15. package/dist/pipeline/src/bash/BashExpression.d.ts +0 -5
  16. package/dist/pipeline/src/bash/BashExpression.js +1 -15
  17. package/dist/pipeline/src/bash/BashExpression.js.map +1 -1
  18. package/dist/pipeline/src/bash/bashEscape.d.ts +30 -0
  19. package/dist/pipeline/src/bash/bashEscape.js +129 -0
  20. package/dist/pipeline/src/bash/bashEscape.js.map +1 -0
  21. package/dist/pipeline/src/bash/bashYaml.js +26 -2
  22. package/dist/pipeline/src/bash/bashYaml.js.map +1 -1
  23. package/dist/pipeline/src/bash/getInjectVarsScript.js +6 -2
  24. package/dist/pipeline/src/bash/getInjectVarsScript.js.map +1 -1
  25. package/dist/pipeline/src/bash/index.d.ts +2 -0
  26. package/dist/pipeline/src/bash/index.js +19 -0
  27. package/dist/pipeline/src/bash/index.js.map +1 -0
  28. package/dist/pipeline/src/build/base/writeDotEnv.js +4 -3
  29. package/dist/pipeline/src/build/base/writeDotEnv.js.map +1 -1
  30. package/dist/pipeline/src/build/docker.d.ts +3 -3
  31. package/dist/pipeline/src/context/getEnvironmentVariables.d.ts +3 -1
  32. package/dist/pipeline/src/context/getEnvironmentVariables.js +23 -12
  33. package/dist/pipeline/src/context/getEnvironmentVariables.js.map +1 -1
  34. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js +2 -2
  35. package/dist/pipeline/src/deploy/cloudRun/createJobs/getCloudRunDeployScripts.js.map +1 -1
  36. package/dist/pipeline/src/deploy/cloudRun/utils/getServiceName.d.ts +1 -1
  37. package/dist/pipeline/src/deploy/kubernetes/cloudSql/index.d.ts +2 -2
  38. package/dist/pipeline/src/deploy/kubernetes/cloudSql/index.js.map +1 -1
  39. package/dist/pipeline/src/deploy/kubernetes/kubeEnv.d.ts +3 -3
  40. package/dist/pipeline/src/deploy/kubernetes/kubeValues.d.ts +2 -2
  41. package/dist/pipeline/src/globalScriptFunctions/index.d.ts +4 -0
  42. package/dist/pipeline/src/globalScriptFunctions/index.js +6 -2
  43. package/dist/pipeline/src/globalScriptFunctions/index.js.map +1 -1
  44. package/dist/pipeline/src/index.d.ts +2 -0
  45. package/dist/pipeline/src/index.js +2 -0
  46. package/dist/pipeline/src/index.js.map +1 -1
  47. package/dist/pipeline/src/types/context.d.ts +2 -1
  48. package/dist/pipeline/src/types/context.js.map +1 -1
  49. package/dist/pipeline/src/variables/VariableValue.d.ts +3 -0
  50. package/dist/pipeline/src/variables/VariableValue.js +3 -0
  51. package/dist/pipeline/src/variables/VariableValue.js.map +1 -0
  52. package/dist/pipeline/src/variables/VariableValueContainingReferences.d.ts +24 -0
  53. package/dist/pipeline/src/variables/VariableValueContainingReferences.js +69 -0
  54. package/dist/pipeline/src/variables/VariableValueContainingReferences.js.map +1 -0
  55. package/dist/pipeline/src/variables/resolveAllReferences.d.ts +3 -0
  56. package/dist/pipeline/src/variables/resolveAllReferences.js +25 -0
  57. package/dist/pipeline/src/variables/resolveAllReferences.js.map +1 -0
  58. package/dist/pipeline/src/variables/resolveAllReferencesOnce.d.ts +5 -0
  59. package/dist/pipeline/src/variables/resolveAllReferencesOnce.js +23 -0
  60. package/dist/pipeline/src/variables/resolveAllReferencesOnce.js.map +1 -0
  61. package/dist/pipeline/src/variables/resolveReferencesOnce.d.ts +8 -0
  62. package/dist/pipeline/src/variables/resolveReferencesOnce.js +21 -0
  63. package/dist/pipeline/src/variables/resolveReferencesOnce.js.map +1 -0
  64. package/dist/tsconfig.tsbuildinfo +1 -1
  65. package/package.json +1 -1
  66. package/src/apps/catenv/printVariables.ts +2 -2
  67. package/src/apps/catenv/types.ts +2 -2
  68. package/src/apps/catenv/utils.ts +8 -12
  69. package/src/apps/catenv/writeDotEnvFiles.ts +2 -5
  70. package/src/apps/cli/commands/project/cloudSql/commandProjectRestoreDb.ts +16 -10
  71. package/src/apps/cli/commands/project/commandCloudSqlProxy.ts +5 -3
  72. package/src/config/getProjectConfig.ts +5 -1
  73. package/dist/pipeline/src/bash/replaceAsync.d.ts +0 -2
  74. package/dist/pipeline/src/bash/replaceAsync.js +0 -37
  75. package/dist/pipeline/src/bash/replaceAsync.js.map +0 -1
  76. package/dist/pipeline/src/context/resolveReferences.d.ts +0 -3
  77. package/dist/pipeline/src/context/resolveReferences.js +0 -56
  78. package/dist/pipeline/src/context/resolveReferences.js.map +0 -1
@@ -89,9 +89,10 @@ const makeExportKeyValuestring = (variables) => (0, utils_1.makeKeyValueString)(
89
89
  "use strict";
90
90
 
91
91
  Object.defineProperty(exports, "__esModule", ({ value: true }));
92
- exports.sanitizeEnvVarName = exports.sanitizeMultiLine = exports.makeKeyValueString = exports.getCurrentComponentAndEnvFromChoice = exports.getComponentFullPath = void 0;
92
+ exports.sanitizeEnvVarName = exports.makeKeyValueString = exports.getCurrentComponentAndEnvFromChoice = exports.getComponentFullPath = void 0;
93
93
  const path_1 = __nccwpck_require__(1017);
94
94
  const projects_1 = __nccwpck_require__(9011);
95
+ const pipeline_1 = __nccwpck_require__(603);
95
96
  const getComponentFullPath = (gitRoot, config, componentName) => {
96
97
  return (0, path_1.join)(gitRoot, config.components[componentName].dir);
97
98
  };
@@ -112,16 +113,10 @@ const getCurrentComponentAndEnvFromChoice = async (config, choice) => {
112
113
  };
113
114
  exports.getCurrentComponentAndEnvFromChoice = getCurrentComponentAndEnvFromChoice;
114
115
  const makeKeyValueString = (variables, keyPrefix = "") => Object.entries(variables)
115
- .map(([key, value]) => `${keyPrefix}${key}='${value}'`)
116
+ // quotes are important, otherwise line breaks don't work properly
117
+ .map(([key, value]) => `${keyPrefix}${key}=${(0, pipeline_1.escapeForDotEnv)(value)}`)
116
118
  .join("\n");
117
119
  exports.makeKeyValueString = makeKeyValueString;
118
- const sanitizeMultiLine = (variables) => {
119
- return Object.fromEntries(Object.entries(variables).map(([key, value]) => [
120
- key,
121
- value.replaceAll("\n", "\\n"),
122
- ]));
123
- };
124
- exports.sanitizeMultiLine = sanitizeMultiLine;
125
120
  const sanitizeEnvVarName = (name) => name.replace(/[\s\-.]+/g, "_");
126
121
  exports.sanitizeEnvVarName = sanitizeEnvVarName;
127
122
  //# sourceMappingURL=utils.js.map
@@ -156,9 +151,7 @@ const writeDotEnvFiles = async (config, choice) => {
156
151
  delete variables["_ALL_ENV_VAR_KEYS"];
157
152
  const componentDir = (0, utils_1.getComponentFullPath)(gitRoot, config, componentName);
158
153
  const filePath = (0, path_1.join)(componentDir, ".env");
159
- // many .dotenv don't like multiline values, so we sanitize them here
160
- const variablesSanitized = (0, utils_1.sanitizeMultiLine)(variables);
161
- await (0, pipeline_1.writeGeneratedFile)(filePath, (0, utils_1.makeKeyValueString)(variablesSanitized), {
154
+ await (0, pipeline_1.writeGeneratedFile)(filePath, (0, utils_1.makeKeyValueString)(variables), {
162
155
  commentChar: "#",
163
156
  });
164
157
  }
@@ -758,7 +751,7 @@ exports.getProjectNamespace = getProjectNamespace;
758
751
  "use strict";
759
752
 
760
753
  Object.defineProperty(exports, "__esModule", ({ value: true }));
761
- exports.bashEscape = exports.joinBashExpressions = exports.getBashVariable = exports.BashExpression = void 0;
754
+ exports.joinBashExpressions = exports.getBashVariable = exports.BashExpression = void 0;
762
755
  /**
763
756
  * this class represents a string that can be evaluated in bash scripts.
764
757
  *
@@ -822,21 +815,143 @@ const joinBashExpressions = (parts, joiner = "") => {
822
815
  }
823
816
  };
824
817
  exports.joinBashExpressions = joinBashExpressions;
818
+ //# sourceMappingURL=BashExpression.js.map
819
+
820
+ /***/ }),
821
+
822
+ /***/ 2463:
823
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
824
+
825
+ "use strict";
826
+
827
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
828
+ exports.escapeForDotEnv = exports.escapeSingleQuotes = exports.escapeDoubleQuotes = exports.escapeBashExpression = exports.escapeString = exports.bashEscape = void 0;
829
+ const globalScriptFunctions_1 = __nccwpck_require__(2912);
830
+ const VariableValueContainingReferences_1 = __nccwpck_require__(1592);
831
+ const BashExpression_1 = __nccwpck_require__(2376);
825
832
  /**
826
833
  * escapes a string or bash expression for bash
827
- * it mainly escapes double quotes
834
+ * it either can escape single or double quotes (double is default)
828
835
  */
829
- const bashEscape = (value) => {
830
- if (value instanceof BashExpression) {
831
- return value.toString(); // no need to escape bash expressions, as we want them to evaluate
836
+ const bashEscape = (value, options = {
837
+ quotes: "double",
838
+ }) => {
839
+ if (value instanceof BashExpression_1.BashExpression) {
840
+ // no need to escape
841
+ return (0, exports.escapeBashExpression)(value, options);
832
842
  }
833
- // we wrap it in double quotes, so we need to escape them
834
- if (typeof value === "string")
835
- return value.replace(/"/g, '\\"');
836
- return value;
843
+ if (value instanceof VariableValueContainingReferences_1.VariableValueContainingReferences) {
844
+ return value.toString(options);
845
+ }
846
+ return (0, exports.escapeString)(value, options);
837
847
  };
838
848
  exports.bashEscape = bashEscape;
839
- //# sourceMappingURL=BashExpression.js.map
849
+ const escapeString = (value, { quotes } = {
850
+ quotes: "double",
851
+ }) => {
852
+ const quoteEscaped = quotes
853
+ ? quotes === "single"
854
+ ? (0, exports.escapeSingleQuotes)(value)
855
+ : (0, exports.escapeDoubleQuotes)(value)
856
+ : value;
857
+ return quoteEscaped;
858
+ };
859
+ exports.escapeString = escapeString;
860
+ const escapeBashExpression = (value, options) => {
861
+ // no need to escape, we just return the string
862
+ return value;
863
+ };
864
+ exports.escapeBashExpression = escapeBashExpression;
865
+ const escapeDoubleQuotes = (value) => value === null || value === void 0 ? void 0 : value.toString().replace(/"/g, '\\"');
866
+ exports.escapeDoubleQuotes = escapeDoubleQuotes;
867
+ const escapeSingleQuotes = (value) => value === null || value === void 0 ? void 0 : value.toString().replace(/'/g, "\\'");
868
+ exports.escapeSingleQuotes = escapeSingleQuotes;
869
+ /**
870
+ *
871
+ * what an absolute nightmare.
872
+ * unfortunatly, dotenv has many limitations. You can't escape quotes properly.
873
+ *
874
+ * In order to be very forgiving, we need to do some magic here:
875
+ *
876
+ * - when the value contains no newlines, we are fine
877
+ * - if the value contains newlines, we need to wrap it in quotes. And thats where the problem begins:
878
+ * - you can't escape quotes. this is a shitty limitation of dotenv and node
879
+ * - you can have inner quotes, but they break in node.js (not in dotenv though), see https://github.com/nodejs/node/issues/54134
880
+ * - so we need to quote cleverly
881
+ * - to make things worse, we need to check whether we have a simple stirng or a bash expression, that needs to be evalulated first...
882
+ */
883
+ const escapeForDotEnv = (value) => {
884
+ if (value === undefined || value === null) {
885
+ return "";
886
+ }
887
+ if (typeof value === "string") {
888
+ // if string contains newlines, we need to wrap it in quotes
889
+ // we additionaly escape newlines, that give best compatibility
890
+ if (value.includes("\n")) {
891
+ const newlinesReplaces = value.replace(/\n/g, "\\n");
892
+ // default to ", but if this is not possible, we try to use ' or `
893
+ const quote = value.includes(`"`)
894
+ ? value.includes(`'`)
895
+ ? value.includes("`")
896
+ ? // If all quote types are present, default to no
897
+ ""
898
+ : "`"
899
+ : "'"
900
+ : '"';
901
+ // if we found a quote, we can wrap the string in it
902
+ return `${quote}${newlinesReplaces}${quote}`;
903
+ }
904
+ else {
905
+ // otherwise we can return as is
906
+ return value;
907
+ }
908
+ }
909
+ else if (value instanceof BashExpression_1.BashExpression) {
910
+ return escapeBashExpressionForDotEnv(value);
911
+ }
912
+ else if (value instanceof VariableValueContainingReferences_1.VariableValueContainingReferences) {
913
+ // instead of doing it part-wise, we just do it all at once
914
+ const containsAnyBashExpression = value.parts.some((part) => part instanceof BashExpression_1.BashExpression);
915
+ if (!containsAnyBashExpression) {
916
+ return (0, exports.escapeForDotEnv)(value.toString({
917
+ quotes: "double",
918
+ }));
919
+ }
920
+ else {
921
+ const result = escapeBashExpressionForDotEnv(new BashExpression_1.BashExpression(value.toString({
922
+ quotes: "double",
923
+ })));
924
+ return result;
925
+ }
926
+ }
927
+ else {
928
+ return value;
929
+ }
930
+ };
931
+ exports.escapeForDotEnv = escapeForDotEnv;
932
+ // basically the same thing as above for bash
933
+ // thx chatgpt for this
934
+ const escapeForDotEnvScript = (0, globalScriptFunctions_1.registerGlobalScriptFunction)("escapeForDotEnv", `
935
+ input="\${1:-$(cat)}"
936
+ input="\${input//$'\\n'/\\\\n}"
937
+ if [[ "$input" == *\\\\n* ]]; then
938
+ if [[ "$input" == *\\"* && "$input" == *\\'* && "$input" == *\\\`* ]]; then
939
+ printf "%s\\n" "$input"
940
+ elif [[ "$input" == *\\"* && "$input" == *\\'* ]]; then
941
+ printf "\`%s\`\\n" "$input"
942
+ elif [[ "$input" == *\\"* ]]; then
943
+ printf "'%s'\\n" "$input"
944
+ else
945
+ printf "\\"%s\\"\\n" "$input"
946
+ fi
947
+ else
948
+ printf "%s\\n" "$input"
949
+ fi
950
+ `);
951
+ const escapeBashExpressionForDotEnv = (value) => {
952
+ return value.transformWithCommand(escapeForDotEnvScript.name).toString();
953
+ };
954
+ //# sourceMappingURL=bashEscape.js.map
840
955
 
841
956
  /***/ }),
842
957
 
@@ -866,6 +981,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
866
981
  exports.writeBashYamlToFileScript = exports.yamlBashString = void 0;
867
982
  const yaml_1 = __nccwpck_require__(8033);
868
983
  const BashExpression_1 = __nccwpck_require__(2376);
984
+ const VariableValueContainingReferences_1 = __nccwpck_require__(1592);
869
985
  const bashExpressionType = {
870
986
  tag: "",
871
987
  resolve: (str) => {
@@ -876,10 +992,33 @@ const bashExpressionType = {
876
992
  // we create a BLOCK_LITERAL
877
993
  // but because bash will interpret the value, it may resolve to a multiline string
878
994
  // so we need to indent every line using sed
879
- return "|-\n" + node.value.transformWithCommand(`sed 's/^/${ctx.indent}/'`);
995
+ return ("|-\n" +
996
+ ctx.indent +
997
+ indentNewlinesInBashExpression(node.value, ctx.indent));
880
998
  },
881
999
  identify: (v) => v instanceof BashExpression_1.BashExpression,
882
1000
  };
1001
+ const indentNewlinesInBashExpression = (expression, indent) => {
1002
+ return expression.transformWithCommand(`sed '1!s/^/${indent}/'`);
1003
+ };
1004
+ const variableContainingReferences = {
1005
+ tag: "",
1006
+ resolve: (str) => {
1007
+ // not really needed,but let's make typescript happy
1008
+ return new VariableValueContainingReferences_1.VariableValueContainingReferences(str);
1009
+ },
1010
+ stringify(node, ctx) {
1011
+ const value = node.value;
1012
+ const stringified = value.parts
1013
+ .map((part) => part instanceof BashExpression_1.BashExpression
1014
+ ? indentNewlinesInBashExpression(part, ctx.indent)
1015
+ : // indent every new line
1016
+ part.toString().replace(/\n/g, `\n${ctx.indent}`))
1017
+ .join("");
1018
+ return "|-\n" + ctx.indent + stringified;
1019
+ },
1020
+ identify: (v) => v instanceof VariableValueContainingReferences_1.VariableValueContainingReferences,
1021
+ };
883
1022
  /***
884
1023
  * creates a yaml string that can be used in bash scripts
885
1024
  * it handles BashExpressions correctly so that they can be evaluated in bash
@@ -888,7 +1027,7 @@ const yamlBashString = (value) => {
888
1027
  return (0, yaml_1.stringify)(value, {
889
1028
  defaultStringType: "BLOCK_LITERAL",
890
1029
  defaultKeyType: "PLAIN",
891
- customTags: [bashExpressionType],
1030
+ customTags: [bashExpressionType, variableContainingReferences],
892
1031
  aliasDuplicateObjects: false,
893
1032
  lineWidth: 0,
894
1033
  });
@@ -919,61 +1058,47 @@ exports.writeBashYamlToFileScript = writeBashYamlToFileScript;
919
1058
  Object.defineProperty(exports, "__esModule", ({ value: true }));
920
1059
  exports.getInjectVarsScript = void 0;
921
1060
  const lodash_1 = __nccwpck_require__(3255);
922
- const BashExpression_1 = __nccwpck_require__(2376);
1061
+ const bashEscape_1 = __nccwpck_require__(2463);
923
1062
  const getInjectVarsScript = (vars) => {
924
1063
  if (!vars)
925
1064
  return [];
926
1065
  // filter out null and undefined values
927
1066
  return Object.entries(vars)
928
1067
  .filter(([, value]) => !(0, lodash_1.isNil)(value))
929
- .map(([key, value]) => `export ${key}="${value ? (0, BashExpression_1.bashEscape)(value) : ""}"`);
1068
+ .map(([key, value]) => `export ${key}="${value
1069
+ ? (0, bashEscape_1.bashEscape)(value, {
1070
+ quotes: "double",
1071
+ })
1072
+ : ""}"`);
930
1073
  };
931
1074
  exports.getInjectVarsScript = getInjectVarsScript;
932
1075
  //# sourceMappingURL=getInjectVarsScript.js.map
933
1076
 
934
1077
  /***/ }),
935
1078
 
936
- /***/ 2233:
937
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
1079
+ /***/ 2990:
1080
+ /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
938
1081
 
939
1082
  "use strict";
940
1083
 
941
- Object.defineProperty(exports, "__esModule", ({ value: true }));
942
- const BashExpression_1 = __nccwpck_require__(2376);
943
- // from https://github.com/dsblv/string-replace-async/blob/main/index.js
944
- // and adjusted a bit
945
- async function replaceAsync(string, searchValue, replacer) {
946
- const wasBashExpression = string instanceof BashExpression_1.BashExpression;
947
- try {
948
- // 1. Run fake pass of `replace`, collect values from `replacer` calls
949
- // 2. Resolve them with `Promise.all`
950
- // 3. Run `replace` with resolved values
951
- const values = [];
952
- String.prototype.replace.call(string instanceof BashExpression_1.BashExpression ? string : (0, BashExpression_1.bashEscape)(string), searchValue, function (...args) {
953
- // eslint-disable-next-line prefer-spread
954
- const result = replacer.apply(undefined, args);
955
- values.push(result);
956
- return "";
957
- });
958
- const resolvedValues = await Promise.all(values);
959
- const containsBashExpression = resolvedValues.some((value) => value instanceof BashExpression_1.BashExpression);
960
- const result = (string instanceof BashExpression_1.BashExpression ? string : (0, BashExpression_1.bashEscape)(string)).replace(searchValue, function () {
961
- var _a, _b;
962
- return (_b = (_a = resolvedValues.shift()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "";
963
- });
964
- if (wasBashExpression || containsBashExpression) {
965
- return new BashExpression_1.BashExpression(result);
966
- }
967
- else {
968
- return result;
969
- }
970
- }
971
- catch (error) {
972
- return Promise.reject(error);
1084
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1085
+ if (k2 === undefined) k2 = k;
1086
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1087
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1088
+ desc = { enumerable: true, get: function() { return m[k]; } };
973
1089
  }
974
- }
975
- exports["default"] = replaceAsync;
976
- //# sourceMappingURL=replaceAsync.js.map
1090
+ Object.defineProperty(o, k2, desc);
1091
+ }) : (function(o, m, k, k2) {
1092
+ if (k2 === undefined) k2 = k;
1093
+ o[k2] = m[k];
1094
+ }));
1095
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
1096
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1097
+ };
1098
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
1099
+ __exportStar(__nccwpck_require__(2463), exports);
1100
+ __exportStar(__nccwpck_require__(2376), exports);
1101
+ //# sourceMappingURL=index.js.map
977
1102
 
978
1103
  /***/ }),
979
1104
 
@@ -1267,8 +1392,9 @@ exports.writeBuildInfo = writeBuildInfo;
1267
1392
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1268
1393
  exports.componentContextNeedsBuildTimeDotEnv = exports.writeDotEnv = void 0;
1269
1394
  const lodash_1 = __nccwpck_require__(3255);
1270
- const gitlab_1 = __nccwpck_require__(8490);
1395
+ const bashEscape_1 = __nccwpck_require__(2463);
1271
1396
  const getBuildInfoVariables_1 = __nccwpck_require__(7827);
1397
+ const gitlab_1 = __nccwpck_require__(8490);
1272
1398
  /**
1273
1399
  * writes a .env file in the components folder
1274
1400
  * @param context
@@ -1283,9 +1409,9 @@ const writeDotEnv = (context) => {
1283
1409
  // filter out build variables, since they may interfer with caching like turbo
1284
1410
  // build variables are rarely used anyway and we may treat them differently in the future
1285
1411
  .filter(([key]) => !getBuildInfoVariables_1.ALL_BUILD_VARIABLES.includes(key))
1286
- .map(([key, value]) => `${key}=${value === null || value === void 0 ? void 0 : value.toString().replaceAll("\n", "\\n")}`)
1412
+ .map(([key, value]) => `${key}=${(0, bashEscape_1.escapeForDotEnv)(value)}`)
1287
1413
  .join("\n");
1288
- return (0, gitlab_1.collapseableSection)("write-dotenv-" + context.name, "write dot env")([
1414
+ return (0, gitlab_1.collapseableSection)("write-dotenv-" + context.name, "write dot env for " + context.name)([
1289
1415
  `cat <<EOF > ${context.build.dir}/.env
1290
1416
  ${keyValueString}
1291
1417
  EOF`,
@@ -2912,9 +3038,10 @@ exports.getSecretVarNameForContext = exports.getSecretVarName = exports.getEnvir
2912
3038
  const deploy_1 = __nccwpck_require__(8483);
2913
3039
  const BashExpression_1 = __nccwpck_require__(2376);
2914
3040
  const types_1 = __nccwpck_require__(4466);
3041
+ const VariableValueContainingReferences_1 = __nccwpck_require__(1592);
3042
+ const resolveAllReferences_1 = __nccwpck_require__(6305);
2915
3043
  const getBuildInfoVariables_1 = __nccwpck_require__(7827);
2916
3044
  const getEnvironmentContext_1 = __nccwpck_require__(3663);
2917
- const resolveReferences_1 = __nccwpck_require__(3115);
2918
3045
  const transformJobOnlyVars_1 = __nccwpck_require__(1552);
2919
3046
  const envVars_1 = __nccwpck_require__(6296);
2920
3047
  const getBasePredefinedVariables = (ctx) => {
@@ -2925,8 +3052,8 @@ const getBasePredefinedVariables = (ctx) => {
2925
3052
  ...(ctx.envType !== "local" ? (0, getBuildInfoVariables_1.getBuildInfoVariables)(ctx) : {}),
2926
3053
  };
2927
3054
  };
2928
- const getEnvironmentVariables = async (ctx, alreadyVisited = {}) => {
2929
- var _a, _b, _c, _d, _e, _f, _g;
3055
+ const getEnvironmentVariables = async (ctx, options = {}) => {
3056
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2930
3057
  const environmentContext = (0, getEnvironmentContext_1.getEnvironmentContext)(ctx);
2931
3058
  const { config, env, componentName } = ctx;
2932
3059
  const { envConfigRaw, deployConfigRaw, buildConfigRaw, envType } = environmentContext;
@@ -2979,18 +3106,28 @@ const getEnvironmentVariables = async (ctx, alreadyVisited = {}) => {
2979
3106
  ];
2980
3107
  const secretEnvVars = (0, envVars_1.makeSecretEnvVarMapping)(env, componentName, secretEnvVarKeys);
2981
3108
  const publicEnvVarsRawSanitized = (0, envVars_1.stringifyValues)(publicEnvVarsRaw);
2982
- const envVarsRaw = addIndexVar({
3109
+ const publicEnvVarsUnresolved = Object.fromEntries(Object.entries(publicEnvVarsRawSanitized).map(([key, value]) => [
3110
+ key,
3111
+ (0, VariableValueContainingReferences_1.createVariableValueContainingReferencesFromString)(value, {
3112
+ componentName: ctx.componentName,
3113
+ }),
3114
+ ]));
3115
+ const publicEnvVars = ((_h = options.shouldResolveReferences) !== null && _h !== void 0 ? _h : true)
3116
+ ? await (0, resolveAllReferences_1.resolveAllReferences)(publicEnvVarsUnresolved, async (otherComponentName) => {
3117
+ const { envVars: otherEnvVars } = await (0, exports.getEnvironmentVariables)({
3118
+ ...ctx,
3119
+ componentName: otherComponentName,
3120
+ }, {
3121
+ shouldResolveReferences: false, // we already do this here with replaceAllReferences recursivly until re replaced all
3122
+ });
3123
+ return otherEnvVars;
3124
+ })
3125
+ : publicEnvVarsUnresolved;
3126
+ const envVars = addIndexVar({
2983
3127
  ...predefinedVariables,
2984
3128
  ...secretEnvVars,
2985
- ...publicEnvVarsRawSanitized,
3129
+ ...publicEnvVars,
2986
3130
  });
2987
- const envVars = (await (0, resolveReferences_1.resolveReferences)(envVarsRaw, async (otherComponentName, alreadyVisited) => {
2988
- const { envVars: otherEnvVars } = await (0, exports.getEnvironmentVariables)({
2989
- ...ctx,
2990
- componentName: otherComponentName,
2991
- }, alreadyVisited);
2992
- return otherEnvVars;
2993
- }, alreadyVisited));
2994
3131
  return {
2995
3132
  envVars,
2996
3133
  secretEnvVarKeys,
@@ -3108,69 +3245,6 @@ __exportStar(__nccwpck_require__(5133), exports);
3108
3245
 
3109
3246
  /***/ }),
3110
3247
 
3111
- /***/ 3115:
3112
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
3113
-
3114
- "use strict";
3115
-
3116
- var __importDefault = (this && this.__importDefault) || function (mod) {
3117
- return (mod && mod.__esModule) ? mod : { "default": mod };
3118
- };
3119
- Object.defineProperty(exports, "__esModule", ({ value: true }));
3120
- exports.resolveReferences = void 0;
3121
- const lodash_1 = __nccwpck_require__(3255);
3122
- const replaceAsync_1 = __importDefault(__nccwpck_require__(2233));
3123
- // regex to resolve references in catladder variables
3124
- // those expressions have the pattern ${componentName:variableName}
3125
- const REGEX = /\$\{(([^:}]+):)?([^}]+)}/gm;
3126
- const resolveReferences = async (vars, getOtherVariables, alreadyVisitedBase = {}) => {
3127
- /**
3128
- *
3129
- * replace referenced variables with their values in a value string
3130
- */
3131
- const replaceSingleValue = async (value, alreadyVisited = alreadyVisitedBase) => {
3132
- if (REGEX.test(value.toString())) {
3133
- // we consider variables that got references in it BashExpressions, because the replacement may be one
3134
- return await (0, replaceAsync_1.default)(value, REGEX, async (match, _, componentName, variableName) => {
3135
- var _a, _b;
3136
- if ((_a = alreadyVisited[componentName]) === null || _a === void 0 ? void 0 : _a[variableName]) {
3137
- return match; // prevent endless loop
3138
- }
3139
- const newAlreadyVisited = (0, lodash_1.merge)({}, alreadyVisited, {
3140
- [componentName]: {
3141
- [variableName]: true,
3142
- },
3143
- });
3144
- const result = componentName
3145
- ? (_b = (await (getOtherVariables === null || getOtherVariables === void 0 ? void 0 : getOtherVariables(componentName, newAlreadyVisited).then((r) => r === null || r === void 0 ? void 0 : r[variableName])))) !== null && _b !== void 0 ? _b : null
3146
- : vars[variableName]; // is self reference
3147
- const replaced = result !== null && result !== undefined
3148
- ? await replaceSingleValue(result, newAlreadyVisited)
3149
- : match;
3150
- return replaced;
3151
- });
3152
- }
3153
- else {
3154
- return value;
3155
- }
3156
- };
3157
- return Object.fromEntries(await Promise.all(Object.entries(vars).map(async ([key, value]) => {
3158
- if (value === null || value === undefined) {
3159
- return [key, null];
3160
- }
3161
- return [
3162
- key,
3163
- value !== null && value !== undefined
3164
- ? await replaceSingleValue(value)
3165
- : null,
3166
- ];
3167
- })));
3168
- };
3169
- exports.resolveReferences = resolveReferences;
3170
- //# sourceMappingURL=resolveReferences.js.map
3171
-
3172
- /***/ }),
3173
-
3174
3248
  /***/ 1552:
3175
3249
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
3176
3250
 
@@ -4007,15 +4081,15 @@ exports.getCloudRunDeployScripts = void 0;
4007
4081
  const lodash_1 = __nccwpck_require__(3255);
4008
4082
  const gitlab_1 = __nccwpck_require__(8490);
4009
4083
  const sbom_1 = __nccwpck_require__(4986);
4084
+ const __1 = __nccwpck_require__(2674);
4085
+ const bashYaml_1 = __nccwpck_require__(4660);
4010
4086
  const cleanup_1 = __nccwpck_require__(7888);
4011
4087
  const database_1 = __nccwpck_require__(8206);
4012
4088
  const gcloudServiceAccountLoginCommands_1 = __nccwpck_require__(6320);
4013
4089
  const cloudRunJobs_1 = __nccwpck_require__(1224);
4014
4090
  const cloudRunServices_1 = __nccwpck_require__(7334);
4015
4091
  const common_1 = __nccwpck_require__(3325);
4016
- const __1 = __nccwpck_require__(2674);
4017
4092
  const constants_1 = __nccwpck_require__(8865);
4018
- const bashYaml_1 = __nccwpck_require__(4660);
4019
4093
  function getCloudRunDeployScripts(context) {
4020
4094
  var _a;
4021
4095
  const deployConfig = (0, common_1.getCloudRunDeployConfig)(context);
@@ -5233,14 +5307,18 @@ class GlobalScriptFunction {
5233
5307
  }
5234
5308
  toBashFunction() {
5235
5309
  return `function ${this.name} () {
5236
- ${this.script}
5237
- }`;
5310
+ ${this.script.trim()}
5311
+ }`.trim();
5238
5312
  }
5239
5313
  invoke(...args) {
5240
5314
  return `${this.name} ${args.join(" ")}`;
5241
5315
  }
5242
5316
  }
5243
5317
  exports.globalScriptFunctions = new Map();
5318
+ /**
5319
+ * registers a global script function
5320
+ * only use that in top-level scopes as it will attach the function to the global scope
5321
+ */
5244
5322
  const registerGlobalScriptFunction = (name, script) => {
5245
5323
  if (exports.globalScriptFunctions.has(name)) {
5246
5324
  throw new Error(`Global script function ${name} already exists`);
@@ -5283,6 +5361,8 @@ __exportStar(__nccwpck_require__(5875), exports);
5283
5361
  __exportStar(__nccwpck_require__(7862), exports);
5284
5362
  __exportStar(__nccwpck_require__(8483), exports);
5285
5363
  __exportStar(__nccwpck_require__(2228), exports);
5364
+ __exportStar(__nccwpck_require__(1619), exports);
5365
+ __exportStar(__nccwpck_require__(2990), exports);
5286
5366
  //# sourceMappingURL=index.js.map
5287
5367
 
5288
5368
  /***/ }),
@@ -6579,6 +6659,182 @@ exports.writeYamlfile = writeYamlfile;
6579
6659
 
6580
6660
  /***/ }),
6581
6661
 
6662
+ /***/ 1619:
6663
+ /***/ ((__unused_webpack_module, exports) => {
6664
+
6665
+ "use strict";
6666
+
6667
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6668
+ //# sourceMappingURL=VariableValue.js.map
6669
+
6670
+ /***/ }),
6671
+
6672
+ /***/ 1592:
6673
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6674
+
6675
+ "use strict";
6676
+
6677
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6678
+ exports.createVariableValueContainingReferencesFromString = exports.VariableValueContainingReferences = exports.VariableReference = exports.UnresolvableReference = void 0;
6679
+ const BashExpression_1 = __nccwpck_require__(2376);
6680
+ const bashEscape_1 = __nccwpck_require__(2463);
6681
+ class UnresolvableReference {
6682
+ constructor(reference) {
6683
+ this.reference = reference;
6684
+ }
6685
+ toString() {
6686
+ return `Unresolvable reference: ${this.reference.toString()}`;
6687
+ }
6688
+ }
6689
+ exports.UnresolvableReference = UnresolvableReference;
6690
+ class VariableReference {
6691
+ constructor(componentName, variableName) {
6692
+ this.componentName = componentName;
6693
+ this.variableName = variableName;
6694
+ }
6695
+ toString() {
6696
+ return `\${${this.componentName}:${this.variableName}}`;
6697
+ }
6698
+ }
6699
+ exports.VariableReference = VariableReference;
6700
+ class VariableValueContainingReferences {
6701
+ constructor(parts) {
6702
+ this.parts = (Array.isArray(parts) ? parts : [parts]).flatMap((part) => part instanceof VariableValueContainingReferences
6703
+ ? part.parts
6704
+ : part === ""
6705
+ ? []
6706
+ : [part]);
6707
+ }
6708
+ toString(options = {
6709
+ quotes: false,
6710
+ }) {
6711
+ return this.parts
6712
+ .map((part) => {
6713
+ if (typeof part === "string") {
6714
+ return (0, bashEscape_1.escapeString)(part, options);
6715
+ }
6716
+ else if (part instanceof BashExpression_1.BashExpression) {
6717
+ return (0, bashEscape_1.escapeBashExpression)(part, options);
6718
+ }
6719
+ else {
6720
+ return part.toString();
6721
+ }
6722
+ })
6723
+ .join("");
6724
+ }
6725
+ }
6726
+ exports.VariableValueContainingReferences = VariableValueContainingReferences;
6727
+ // regex to resolve references in catladder variables
6728
+ // those expressions have the pattern ${componentName:variableName}
6729
+ const REGEX = /\$\{(([^:}]+):)?([^}]+)}/gm;
6730
+ const createVariableValueContainingReferencesFromString = (value, options) => {
6731
+ const parts = [];
6732
+ let match;
6733
+ let lastIndex = 0;
6734
+ while ((match = REGEX.exec(value)) !== null) {
6735
+ const [fullMatch, _, otherComponentName, variableName] = match;
6736
+ parts.push(value.slice(lastIndex, match.index));
6737
+ parts.push(new VariableReference(otherComponentName || options.componentName, variableName));
6738
+ lastIndex = REGEX.lastIndex;
6739
+ }
6740
+ parts.push(value.slice(lastIndex));
6741
+ return new VariableValueContainingReferences(parts);
6742
+ };
6743
+ exports.createVariableValueContainingReferencesFromString = createVariableValueContainingReferencesFromString;
6744
+ //# sourceMappingURL=VariableValueContainingReferences.js.map
6745
+
6746
+ /***/ }),
6747
+
6748
+ /***/ 6305:
6749
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6750
+
6751
+ "use strict";
6752
+
6753
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6754
+ exports.resolveAllReferences = void 0;
6755
+ const VariableValueContainingReferences_1 = __nccwpck_require__(1592);
6756
+ const resolveAllReferencesOnce_1 = __nccwpck_require__(9554);
6757
+ const resolveAllReferences = async (values, getEnvVars) => {
6758
+ // replace until there aren't any references left
6759
+ let result = values;
6760
+ let i = 0;
6761
+ while (Object.values(result).some((value) => value.parts.some((part) => part instanceof VariableValueContainingReferences_1.VariableReference))) {
6762
+ const replaced = await (0, resolveAllReferencesOnce_1.resolveAllReferencesOnce)(result, getEnvVars);
6763
+ result = replaced;
6764
+ i++;
6765
+ if (i > 1000) {
6766
+ const unresolved = Object.entries(result).filter(([key, value]) => value.parts.some((part) => part instanceof VariableValueContainingReferences_1.VariableReference));
6767
+ throw new Error("Infinite loop detected in these variables: " +
6768
+ unresolved
6769
+ .map(([key, value]) => `${key} (last reference: ${value.parts.find((part) => part instanceof VariableValueContainingReferences_1.VariableReference)})`)
6770
+ .join(", "));
6771
+ }
6772
+ }
6773
+ return result;
6774
+ };
6775
+ exports.resolveAllReferences = resolveAllReferences;
6776
+ //# sourceMappingURL=resolveAllReferences.js.map
6777
+
6778
+ /***/ }),
6779
+
6780
+ /***/ 9554:
6781
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6782
+
6783
+ "use strict";
6784
+
6785
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6786
+ exports.resolveAllReferencesOnce = void 0;
6787
+ const VariableValueContainingReferences_1 = __nccwpck_require__(1592);
6788
+ const resolveReferencesOnce_1 = __nccwpck_require__(8749);
6789
+ const resolveAllReferencesOnce = async (values, getEnvVars) => {
6790
+ const allReferences = Object.values(values).flatMap((value) => value === null || value === void 0 ? void 0 : value.parts.filter((part) => part instanceof VariableValueContainingReferences_1.VariableReference));
6791
+ const allComponentsUnique = Array.from(new Set(allReferences.map((reference) => reference.componentName)));
6792
+ const allEnvVarsInComponents = Object.fromEntries(await Promise.all(allComponentsUnique.map(async (componentName) => [
6793
+ componentName,
6794
+ await getEnvVars(componentName),
6795
+ ])));
6796
+ return Object.fromEntries(Object.entries(values).map(([key, value]) => [
6797
+ key,
6798
+ value !== null && value !== undefined
6799
+ ? (0, resolveReferencesOnce_1.resolveReferencesOnce)(value, ({ componentName, variableName }) => {
6800
+ return allEnvVarsInComponents[componentName][variableName];
6801
+ })
6802
+ : value,
6803
+ ]));
6804
+ };
6805
+ exports.resolveAllReferencesOnce = resolveAllReferencesOnce;
6806
+ //# sourceMappingURL=resolveAllReferencesOnce.js.map
6807
+
6808
+ /***/ }),
6809
+
6810
+ /***/ 8749:
6811
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6812
+
6813
+ "use strict";
6814
+
6815
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
6816
+ exports.resolveReferencesOnce = void 0;
6817
+ const VariableValueContainingReferences_1 = __nccwpck_require__(1592);
6818
+ const resolveReferencesOnce = (value, resolver) => {
6819
+ const replacedParts = value.parts.map((part) => {
6820
+ if (part instanceof VariableValueContainingReferences_1.VariableReference) {
6821
+ const result = resolver({
6822
+ componentName: part.componentName,
6823
+ variableName: part.variableName,
6824
+ });
6825
+ return result !== null && result !== void 0 ? result : new VariableValueContainingReferences_1.UnresolvableReference(part);
6826
+ }
6827
+ else {
6828
+ return part;
6829
+ }
6830
+ });
6831
+ return new VariableValueContainingReferences_1.VariableValueContainingReferences(replacedParts);
6832
+ };
6833
+ exports.resolveReferencesOnce = resolveReferencesOnce;
6834
+ //# sourceMappingURL=resolveReferencesOnce.js.map
6835
+
6836
+ /***/ }),
6837
+
6582
6838
  /***/ 5763:
6583
6839
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
6584
6840