lingo.dev 0.117.2 → 0.117.3
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 +40 -7
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +40 -7
- package/build/cli.mjs.map +1 -1
- package/package.json +1 -1
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)) {
|
|
@@ -13615,7 +13648,7 @@ async function renderHero2() {
|
|
|
13615
13648
|
// package.json
|
|
13616
13649
|
var package_default = {
|
|
13617
13650
|
name: "lingo.dev",
|
|
13618
|
-
version: "0.117.
|
|
13651
|
+
version: "0.117.3",
|
|
13619
13652
|
description: "Lingo.dev CLI",
|
|
13620
13653
|
private: false,
|
|
13621
13654
|
publishConfig: {
|