edge-functions 6.1.0 → 6.1.1-stage.2
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.
|
@@ -2090,14 +2090,66 @@ async function writeUserConfig(config) {
|
|
|
2090
2090
|
*/
|
|
2091
2091
|
|
|
2092
2092
|
`;
|
|
2093
|
-
|
|
2094
|
-
if (
|
|
2095
|
-
return
|
|
2093
|
+
function cleanUndefinedValues(obj) {
|
|
2094
|
+
if (obj === null || obj === void 0) {
|
|
2095
|
+
return obj;
|
|
2096
2096
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2097
|
+
if (Array.isArray(obj)) {
|
|
2098
|
+
return obj.map(cleanUndefinedValues).filter((item) => item !== void 0);
|
|
2099
|
+
}
|
|
2100
|
+
if (typeof obj === "object") {
|
|
2101
|
+
const cleaned = {};
|
|
2102
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
2103
|
+
if (value !== void 0) {
|
|
2104
|
+
const cleanedValue = cleanUndefinedValues(value);
|
|
2105
|
+
if (cleanedValue !== void 0) {
|
|
2106
|
+
cleaned[key] = cleanedValue;
|
|
2107
|
+
}
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
return cleaned;
|
|
2111
|
+
}
|
|
2112
|
+
return obj;
|
|
2113
|
+
}
|
|
2114
|
+
function configToJavaScript(obj, indent = 0) {
|
|
2115
|
+
const spaces = " ".repeat(indent);
|
|
2116
|
+
if (typeof obj === "function") {
|
|
2117
|
+
return obj.toString();
|
|
2118
|
+
}
|
|
2119
|
+
if (typeof obj === "string") {
|
|
2120
|
+
return `'${obj.replace(/'/g, "\\'")}'`;
|
|
2121
|
+
}
|
|
2122
|
+
if (typeof obj === "number" || typeof obj === "boolean") {
|
|
2123
|
+
return String(obj);
|
|
2124
|
+
}
|
|
2125
|
+
if (obj === null || obj === void 0) {
|
|
2126
|
+
return String(obj);
|
|
2127
|
+
}
|
|
2128
|
+
if (Array.isArray(obj)) {
|
|
2129
|
+
if (obj.length === 0) return "[]";
|
|
2130
|
+
const items = obj.map((item) => configToJavaScript(item, indent + 1));
|
|
2131
|
+
return `[
|
|
2132
|
+
${spaces} ${items.join(`,
|
|
2133
|
+
${spaces} `)}
|
|
2134
|
+
${spaces}]`;
|
|
2135
|
+
}
|
|
2136
|
+
if (typeof obj === "object") {
|
|
2137
|
+
const entries = Object.entries(obj).filter(([, value]) => value !== void 0);
|
|
2138
|
+
if (entries.length === 0) return "{}";
|
|
2139
|
+
const props = entries.map(([key, value]) => {
|
|
2140
|
+
const keyStr = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : `'${key}'`;
|
|
2141
|
+
return `${spaces} ${keyStr}: ${configToJavaScript(value, indent + 1)}`;
|
|
2142
|
+
});
|
|
2143
|
+
return `{
|
|
2144
|
+
${props.join(",\n")}
|
|
2145
|
+
${spaces}}`;
|
|
2146
|
+
}
|
|
2147
|
+
return String(obj);
|
|
2148
|
+
}
|
|
2149
|
+
const cleanedConfig = cleanUndefinedValues(config);
|
|
2150
|
+
const configString = configToJavaScript(cleanedConfig);
|
|
2099
2151
|
const formattedContent = await prettier.format(
|
|
2100
|
-
configComment + `${moduleExportStyle} ${
|
|
2152
|
+
configComment + `${moduleExportStyle} ${configString};`,
|
|
2101
2153
|
{
|
|
2102
2154
|
parser: "babel",
|
|
2103
2155
|
semi: false,
|