lingo.dev 0.117.2 → 0.117.4
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/build/cli.cjs +175 -151
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +43 -19
- package/build/cli.mjs.map +1 -1
- package/package.json +2 -2
package/build/cli.mjs
CHANGED
|
@@ -2093,14 +2093,15 @@ function createYamlLoader() {
|
|
|
2093
2093
|
}
|
|
2094
2094
|
try {
|
|
2095
2095
|
const sourceDoc = YAML.parseDocument(originalInput);
|
|
2096
|
-
const metadata = extractQuotingMetadata(sourceDoc);
|
|
2097
2096
|
const outputDoc = YAML.parseDocument(
|
|
2098
2097
|
YAML.stringify(payload, {
|
|
2099
2098
|
lineWidth: -1,
|
|
2100
2099
|
defaultKeyType: "PLAIN"
|
|
2101
2100
|
})
|
|
2102
2101
|
);
|
|
2103
|
-
|
|
2102
|
+
const isRootKeyFormat = detectRootKeyFormat(sourceDoc, outputDoc);
|
|
2103
|
+
const metadata = extractQuotingMetadata(sourceDoc, isRootKeyFormat);
|
|
2104
|
+
applyQuotingMetadata(outputDoc, metadata, isRootKeyFormat);
|
|
2104
2105
|
return outputDoc.toString({ lineWidth: -1 });
|
|
2105
2106
|
} catch (error) {
|
|
2106
2107
|
console.warn("Failed to preserve YAML formatting:", error);
|
|
@@ -2113,14 +2114,39 @@ function createYamlLoader() {
|
|
|
2113
2114
|
}
|
|
2114
2115
|
});
|
|
2115
2116
|
}
|
|
2116
|
-
function
|
|
2117
|
+
function detectRootKeyFormat(sourceDoc, outputDoc) {
|
|
2118
|
+
const sourceRoot = sourceDoc.contents;
|
|
2119
|
+
const outputRoot = outputDoc.contents;
|
|
2120
|
+
if (!isYAMLMap(sourceRoot) || !isYAMLMap(outputRoot)) {
|
|
2121
|
+
return false;
|
|
2122
|
+
}
|
|
2123
|
+
const sourceMap = sourceRoot;
|
|
2124
|
+
const outputMap = outputRoot;
|
|
2125
|
+
if (!sourceMap.items || sourceMap.items.length !== 1 || !outputMap.items || outputMap.items.length !== 1) {
|
|
2126
|
+
return false;
|
|
2127
|
+
}
|
|
2128
|
+
const sourceRootKey = getKeyValue(sourceMap.items[0].key);
|
|
2129
|
+
const outputRootKey = getKeyValue(outputMap.items[0].key);
|
|
2130
|
+
if (sourceRootKey !== outputRootKey && typeof sourceRootKey === "string" && typeof outputRootKey === "string") {
|
|
2131
|
+
return true;
|
|
2132
|
+
}
|
|
2133
|
+
return false;
|
|
2134
|
+
}
|
|
2135
|
+
function extractQuotingMetadata(doc, skipRootKey) {
|
|
2117
2136
|
const metadata = {
|
|
2118
2137
|
keys: /* @__PURE__ */ new Map(),
|
|
2119
2138
|
values: /* @__PURE__ */ new Map()
|
|
2120
2139
|
};
|
|
2121
2140
|
const root = doc.contents;
|
|
2122
2141
|
if (!root) return metadata;
|
|
2123
|
-
|
|
2142
|
+
let startNode = root;
|
|
2143
|
+
if (skipRootKey && isYAMLMap(root)) {
|
|
2144
|
+
const rootMap = root;
|
|
2145
|
+
if (rootMap.items && rootMap.items.length === 1) {
|
|
2146
|
+
startNode = rootMap.items[0].value;
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
walkAndExtract(startNode, [], metadata);
|
|
2124
2150
|
return metadata;
|
|
2125
2151
|
}
|
|
2126
2152
|
function walkAndExtract(node, path19, metadata) {
|
|
@@ -2155,10 +2181,17 @@ function walkAndExtract(node, path19, metadata) {
|
|
|
2155
2181
|
}
|
|
2156
2182
|
}
|
|
2157
2183
|
}
|
|
2158
|
-
function applyQuotingMetadata(doc, metadata) {
|
|
2184
|
+
function applyQuotingMetadata(doc, metadata, skipRootKey) {
|
|
2159
2185
|
const root = doc.contents;
|
|
2160
2186
|
if (!root) return;
|
|
2161
|
-
|
|
2187
|
+
let startNode = root;
|
|
2188
|
+
if (skipRootKey && isYAMLMap(root)) {
|
|
2189
|
+
const rootMap = root;
|
|
2190
|
+
if (rootMap.items && rootMap.items.length === 1) {
|
|
2191
|
+
startNode = rootMap.items[0].value;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
walkAndApply(startNode, [], metadata);
|
|
2162
2195
|
}
|
|
2163
2196
|
function walkAndApply(node, path19, metadata) {
|
|
2164
2197
|
if (isScalar(node)) {
|
|
@@ -2196,22 +2229,13 @@ function walkAndApply(node, path19, metadata) {
|
|
|
2196
2229
|
}
|
|
2197
2230
|
}
|
|
2198
2231
|
function isScalar(node) {
|
|
2199
|
-
|
|
2200
|
-
return true;
|
|
2201
|
-
}
|
|
2202
|
-
return node && typeof node === "object" && "value" in node && ("type" in node || "format" in node);
|
|
2232
|
+
return YAML.isScalar(node);
|
|
2203
2233
|
}
|
|
2204
2234
|
function isYAMLMap(node) {
|
|
2205
|
-
|
|
2206
|
-
return true;
|
|
2207
|
-
}
|
|
2208
|
-
return node && typeof node === "object" && "items" in node && Array.isArray(node.items) && !("value" in node);
|
|
2235
|
+
return YAML.isMap(node);
|
|
2209
2236
|
}
|
|
2210
2237
|
function isYAMLSeq(node) {
|
|
2211
|
-
|
|
2212
|
-
return true;
|
|
2213
|
-
}
|
|
2214
|
-
return node && typeof node === "object" && "items" in node && Array.isArray(node.items) && !("type" in node) && !("value" in node);
|
|
2238
|
+
return YAML.isSeq(node);
|
|
2215
2239
|
}
|
|
2216
2240
|
function getKeyValue(key) {
|
|
2217
2241
|
if (key === null || key === void 0) {
|
|
@@ -13615,7 +13639,7 @@ async function renderHero2() {
|
|
|
13615
13639
|
// package.json
|
|
13616
13640
|
var package_default = {
|
|
13617
13641
|
name: "lingo.dev",
|
|
13618
|
-
version: "0.117.
|
|
13642
|
+
version: "0.117.4",
|
|
13619
13643
|
description: "Lingo.dev CLI",
|
|
13620
13644
|
private: false,
|
|
13621
13645
|
publishConfig: {
|