@pnpm/yaml.document-sync 1000.0.0-0 → 1000.0.0
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/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/patchDocument.js +18 -12
- package/lib/patchDocument.js.map +1 -1
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patchDocument = void 0;
|
|
4
|
+
var patchDocument_js_1 = require("./patchDocument.js");
|
|
5
|
+
Object.defineProperty(exports, "patchDocument", { enumerable: true, get: function () { return patchDocument_js_1.patchDocument; } });
|
|
2
6
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAkD;AAAzC,iHAAA,aAAa,OAAA"}
|
package/lib/patchDocument.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.patchDocument = patchDocument;
|
|
7
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
2
8
|
/**
|
|
3
9
|
* Recursively update a YAML document (in-place) to match the contents of a
|
|
4
10
|
* target value.
|
|
@@ -6,7 +12,7 @@ import yaml from 'yaml';
|
|
|
6
12
|
* Comments are preserved on a best-effort basis. There are several cases where
|
|
7
13
|
* ambiguity arises. See this package's README.md for details.
|
|
8
14
|
*/
|
|
9
|
-
|
|
15
|
+
function patchDocument(document, target, options) {
|
|
10
16
|
// Documents with errors can't be stringified and have unpredictable ASTs.
|
|
11
17
|
if (document.errors.length > 0) {
|
|
12
18
|
throw new Error('Document with errors cannot be patched');
|
|
@@ -23,16 +29,16 @@ function patchNode(node, target, ctx) {
|
|
|
23
29
|
if (target == null) {
|
|
24
30
|
return null;
|
|
25
31
|
}
|
|
26
|
-
if (
|
|
32
|
+
if (yaml_1.default.isAlias(node)) {
|
|
27
33
|
return patchAlias(node, target, ctx);
|
|
28
34
|
}
|
|
29
|
-
if (
|
|
35
|
+
if (yaml_1.default.isScalar(node)) {
|
|
30
36
|
return patchScalar(node, target, ctx);
|
|
31
37
|
}
|
|
32
|
-
if (
|
|
38
|
+
if (yaml_1.default.isMap(node)) {
|
|
33
39
|
return patchMap(node, target, ctx);
|
|
34
40
|
}
|
|
35
|
-
if (
|
|
41
|
+
if (yaml_1.default.isSeq(node)) {
|
|
36
42
|
return patchSeq(node, target, ctx);
|
|
37
43
|
}
|
|
38
44
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -85,7 +91,7 @@ function patchMap(map, target, ctx) {
|
|
|
85
91
|
for (const pair of map.items) {
|
|
86
92
|
// We can't update non-node types. Pairs should only contain values that are
|
|
87
93
|
// non-nodes if the yaml document was modified manually after parsing.
|
|
88
|
-
if (!
|
|
94
|
+
if (!yaml_1.default.isScalar(pair.key) || typeof pair.key.value !== 'string') {
|
|
89
95
|
throw new Error('Encountered unexpected non-node value: ' + String(pair.key));
|
|
90
96
|
}
|
|
91
97
|
mapKeyToExistingPair.set(pair.key.value, pair);
|
|
@@ -96,7 +102,7 @@ function patchMap(map, target, ctx) {
|
|
|
96
102
|
if (existingPair == null) {
|
|
97
103
|
return ctx.document.createPair(key, value);
|
|
98
104
|
}
|
|
99
|
-
if (!
|
|
105
|
+
if (!yaml_1.default.isNode(existingPair.value)) {
|
|
100
106
|
throw new Error('Encountered unexpected non-node value: ' + String(existingPair.value));
|
|
101
107
|
}
|
|
102
108
|
existingPair.value = patchNode(existingPair.value, value, ctx);
|
|
@@ -128,13 +134,13 @@ function patchSeqPrimitive(seq, target) {
|
|
|
128
134
|
// important to reuse them when possible.
|
|
129
135
|
const valueToNodesMap = new Map();
|
|
130
136
|
for (const item of seq.items) {
|
|
131
|
-
if (item != null && !
|
|
137
|
+
if (item != null && !yaml_1.default.isNode(item)) {
|
|
132
138
|
throw new Error('Encountered unexpected non-node value: ' + String(item));
|
|
133
139
|
}
|
|
134
140
|
// We know all items in the target list are scalars. If there's a non-scalar
|
|
135
141
|
// in the source list, it needs to be removed. Skip over this item so it's
|
|
136
142
|
// not added to the final list.
|
|
137
|
-
if (!
|
|
143
|
+
if (!yaml_1.default.isScalar(item) || !isPrimitive(item.value) || item.value == null) {
|
|
138
144
|
continue;
|
|
139
145
|
}
|
|
140
146
|
const nodeList = valueToNodesMap.get(item.value) ?? [];
|
|
@@ -149,7 +155,7 @@ function patchSeqPrimitive(seq, target) {
|
|
|
149
155
|
if (existingNodesList?.length === 0) {
|
|
150
156
|
valueToNodesMap.delete(item);
|
|
151
157
|
}
|
|
152
|
-
return firstExistingItem ?? new
|
|
158
|
+
return firstExistingItem ?? new yaml_1.default.Scalar(item);
|
|
153
159
|
});
|
|
154
160
|
return seq;
|
|
155
161
|
}
|
|
@@ -158,7 +164,7 @@ function patchSeqComplex(seq, target, ctx) {
|
|
|
158
164
|
for (let i = 0; i < Math.max(seq.items.length, target.length); i++) {
|
|
159
165
|
const existingItem = seq.items[i];
|
|
160
166
|
const targetItem = target[i];
|
|
161
|
-
if (existingItem != null && !
|
|
167
|
+
if (existingItem != null && !yaml_1.default.isNode(existingItem)) {
|
|
162
168
|
throw new Error('Encountered unexpected non-node value: ' + String(existingItem));
|
|
163
169
|
}
|
|
164
170
|
const nextItem = patchNode(existingItem, targetItem, ctx);
|
package/lib/patchDocument.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patchDocument.js","sourceRoot":"","sources":["../src/patchDocument.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"patchDocument.js","sourceRoot":"","sources":["../src/patchDocument.ts"],"names":[],"mappings":";;;;;AA6BA,sCAUC;AAvCD,gDAAuB;AAsBvB;;;;;;GAMG;AACH,SAAgB,aAAa,CAAE,QAAuB,EAAE,MAAe,EAAE,OAA8B;IACrG,0EAA0E;IAC1E,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;IAED,QAAQ,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE;QACvD,QAAQ;QACR,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,QAAQ;KACtC,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,SAAS,CAAE,IAAkC,EAAE,MAAe,EAAE,GAAiB;IACxF,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACjB,OAAO,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;IACxC,CAAC;IAED,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;IACtC,CAAC;IAED,IAAI,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;IACvC,CAAC;IAED,IAAI,cAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACrB,OAAO,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;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IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAA;AAC9G,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/yaml.document-sync",
|
|
3
|
-
"version": "1000.0.0
|
|
3
|
+
"version": "1000.0.0",
|
|
4
4
|
"description": "Update a YAML document to match the contents of an in-memory object.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
7
|
-
"
|
|
7
|
+
"pnpm10",
|
|
8
8
|
"patch",
|
|
9
9
|
"yaml"
|
|
10
10
|
],
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/pnpm/pnpm/issues"
|
|
17
17
|
},
|
|
18
|
-
"type": "
|
|
18
|
+
"type": "commonjs",
|
|
19
19
|
"main": "lib/index.js",
|
|
20
20
|
"types": "lib/index.d.ts",
|
|
21
21
|
"exports": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"yaml": "^2.8.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@pnpm/yaml.document-sync": "1000.0.0
|
|
32
|
+
"@pnpm/yaml.document-sync": "1000.0.0"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">=18.12"
|
|
36
36
|
},
|
|
37
37
|
"jest": {
|
|
38
38
|
"preset": "@pnpm/jest-config"
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"test": "pnpm run compile && pnpm run _test",
|
|
42
42
|
"compile": "tsc --build && pnpm run lint --fix",
|
|
43
43
|
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
44
|
-
"_test": "
|
|
44
|
+
"_test": "jest"
|
|
45
45
|
}
|
|
46
46
|
}
|