node-karin 1.15.3 → 1.15.5
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/CHANGELOG.md +14 -0
- package/dist/cli/index.cjs +1 -1
- package/dist/cli/index.mjs +78 -495
- package/dist/index.d.ts +25 -5
- package/dist/index.mjs +47 -30
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -271,9 +271,9 @@ const isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE]
|
|
|
271
271
|
const isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
|
|
272
272
|
const isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
|
|
273
273
|
const isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
|
|
274
|
-
const isScalar
|
|
274
|
+
const isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR$1;
|
|
275
275
|
const isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
|
|
276
|
-
function isCollection
|
|
276
|
+
function isCollection(node) {
|
|
277
277
|
if (node && typeof node === "object")
|
|
278
278
|
switch (node[NODE_TYPE]) {
|
|
279
279
|
case MAP:
|
|
@@ -293,22 +293,22 @@ function isNode(node) {
|
|
|
293
293
|
}
|
|
294
294
|
return false;
|
|
295
295
|
}
|
|
296
|
-
const hasAnchor = (node) => (isScalar
|
|
297
|
-
const BREAK
|
|
298
|
-
const SKIP
|
|
299
|
-
const REMOVE
|
|
300
|
-
function visit
|
|
296
|
+
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
297
|
+
const BREAK = Symbol("break visit");
|
|
298
|
+
const SKIP = Symbol("skip children");
|
|
299
|
+
const REMOVE = Symbol("remove node");
|
|
300
|
+
function visit(node, visitor) {
|
|
301
301
|
const visitor_ = initVisitor(visitor);
|
|
302
302
|
if (isDocument(node)) {
|
|
303
303
|
const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
|
|
304
|
-
if (cd === REMOVE
|
|
304
|
+
if (cd === REMOVE)
|
|
305
305
|
node.contents = null;
|
|
306
306
|
} else
|
|
307
307
|
visit_(null, node, visitor_, Object.freeze([]));
|
|
308
308
|
}
|
|
309
|
-
visit
|
|
310
|
-
visit
|
|
311
|
-
visit
|
|
309
|
+
visit.BREAK = BREAK;
|
|
310
|
+
visit.SKIP = SKIP;
|
|
311
|
+
visit.REMOVE = REMOVE;
|
|
312
312
|
function visit_(key, node, visitor, path2) {
|
|
313
313
|
const ctrl = callVisitor(key, node, visitor, path2);
|
|
314
314
|
if (isNode(ctrl) || isPair(ctrl)) {
|
|
@@ -316,15 +316,15 @@ function visit_(key, node, visitor, path2) {
|
|
|
316
316
|
return visit_(key, ctrl, visitor, path2);
|
|
317
317
|
}
|
|
318
318
|
if (typeof ctrl !== "symbol") {
|
|
319
|
-
if (isCollection
|
|
319
|
+
if (isCollection(node)) {
|
|
320
320
|
path2 = Object.freeze(path2.concat(node));
|
|
321
321
|
for (let i = 0; i < node.items.length; ++i) {
|
|
322
322
|
const ci = visit_(i, node.items[i], visitor, path2);
|
|
323
323
|
if (typeof ci === "number")
|
|
324
324
|
i = ci - 1;
|
|
325
|
-
else if (ci === BREAK
|
|
326
|
-
return BREAK
|
|
327
|
-
else if (ci === REMOVE
|
|
325
|
+
else if (ci === BREAK)
|
|
326
|
+
return BREAK;
|
|
327
|
+
else if (ci === REMOVE) {
|
|
328
328
|
node.items.splice(i, 1);
|
|
329
329
|
i -= 1;
|
|
330
330
|
}
|
|
@@ -332,62 +332,14 @@ function visit_(key, node, visitor, path2) {
|
|
|
332
332
|
} else if (isPair(node)) {
|
|
333
333
|
path2 = Object.freeze(path2.concat(node));
|
|
334
334
|
const ck = visit_("key", node.key, visitor, path2);
|
|
335
|
-
if (ck === BREAK
|
|
336
|
-
return BREAK
|
|
337
|
-
else if (ck === REMOVE
|
|
335
|
+
if (ck === BREAK)
|
|
336
|
+
return BREAK;
|
|
337
|
+
else if (ck === REMOVE)
|
|
338
338
|
node.key = null;
|
|
339
339
|
const cv = visit_("value", node.value, visitor, path2);
|
|
340
|
-
if (cv === BREAK
|
|
341
|
-
return BREAK
|
|
342
|
-
else if (cv === REMOVE
|
|
343
|
-
node.value = null;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return ctrl;
|
|
347
|
-
}
|
|
348
|
-
async function visitAsync(node, visitor) {
|
|
349
|
-
const visitor_ = initVisitor(visitor);
|
|
350
|
-
if (isDocument(node)) {
|
|
351
|
-
const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
|
|
352
|
-
if (cd === REMOVE$1)
|
|
353
|
-
node.contents = null;
|
|
354
|
-
} else
|
|
355
|
-
await visitAsync_(null, node, visitor_, Object.freeze([]));
|
|
356
|
-
}
|
|
357
|
-
visitAsync.BREAK = BREAK$1;
|
|
358
|
-
visitAsync.SKIP = SKIP$1;
|
|
359
|
-
visitAsync.REMOVE = REMOVE$1;
|
|
360
|
-
async function visitAsync_(key, node, visitor, path2) {
|
|
361
|
-
const ctrl = await callVisitor(key, node, visitor, path2);
|
|
362
|
-
if (isNode(ctrl) || isPair(ctrl)) {
|
|
363
|
-
replaceNode(key, path2, ctrl);
|
|
364
|
-
return visitAsync_(key, ctrl, visitor, path2);
|
|
365
|
-
}
|
|
366
|
-
if (typeof ctrl !== "symbol") {
|
|
367
|
-
if (isCollection$1(node)) {
|
|
368
|
-
path2 = Object.freeze(path2.concat(node));
|
|
369
|
-
for (let i = 0; i < node.items.length; ++i) {
|
|
370
|
-
const ci = await visitAsync_(i, node.items[i], visitor, path2);
|
|
371
|
-
if (typeof ci === "number")
|
|
372
|
-
i = ci - 1;
|
|
373
|
-
else if (ci === BREAK$1)
|
|
374
|
-
return BREAK$1;
|
|
375
|
-
else if (ci === REMOVE$1) {
|
|
376
|
-
node.items.splice(i, 1);
|
|
377
|
-
i -= 1;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
} else if (isPair(node)) {
|
|
381
|
-
path2 = Object.freeze(path2.concat(node));
|
|
382
|
-
const ck = await visitAsync_("key", node.key, visitor, path2);
|
|
383
|
-
if (ck === BREAK$1)
|
|
384
|
-
return BREAK$1;
|
|
385
|
-
else if (ck === REMOVE$1)
|
|
386
|
-
node.key = null;
|
|
387
|
-
const cv = await visitAsync_("value", node.value, visitor, path2);
|
|
388
|
-
if (cv === BREAK$1)
|
|
389
|
-
return BREAK$1;
|
|
390
|
-
else if (cv === REMOVE$1)
|
|
340
|
+
if (cv === BREAK)
|
|
341
|
+
return BREAK;
|
|
342
|
+
else if (cv === REMOVE)
|
|
391
343
|
node.value = null;
|
|
392
344
|
}
|
|
393
345
|
}
|
|
@@ -420,7 +372,7 @@ function callVisitor(key, node, visitor, path2) {
|
|
|
420
372
|
return visitor.Seq?.(key, node, path2);
|
|
421
373
|
if (isPair(node))
|
|
422
374
|
return visitor.Pair?.(key, node, path2);
|
|
423
|
-
if (isScalar
|
|
375
|
+
if (isScalar(node))
|
|
424
376
|
return visitor.Scalar?.(key, node, path2);
|
|
425
377
|
if (isAlias(node))
|
|
426
378
|
return visitor.Alias?.(key, node, path2);
|
|
@@ -428,7 +380,7 @@ function callVisitor(key, node, visitor, path2) {
|
|
|
428
380
|
}
|
|
429
381
|
function replaceNode(key, path2, node) {
|
|
430
382
|
const parent = path2[path2.length - 1];
|
|
431
|
-
if (isCollection
|
|
383
|
+
if (isCollection(parent)) {
|
|
432
384
|
parent.items[key] = node;
|
|
433
385
|
} else if (isPair(parent)) {
|
|
434
386
|
if (key === "key")
|
|
@@ -585,7 +537,7 @@ class Directives {
|
|
|
585
537
|
let tagNames;
|
|
586
538
|
if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
|
|
587
539
|
const tags = {};
|
|
588
|
-
visit
|
|
540
|
+
visit(doc.contents, (_key, node) => {
|
|
589
541
|
if (isNode(node) && node.tag)
|
|
590
542
|
tags[node.tag] = true;
|
|
591
543
|
});
|
|
@@ -613,7 +565,7 @@ function anchorIsValid(anchor) {
|
|
|
613
565
|
}
|
|
614
566
|
function anchorNames(root) {
|
|
615
567
|
const anchors = /* @__PURE__ */ new Set();
|
|
616
|
-
visit
|
|
568
|
+
visit(root, {
|
|
617
569
|
Value(_key, node) {
|
|
618
570
|
if (node.anchor)
|
|
619
571
|
anchors.add(node.anchor);
|
|
@@ -649,7 +601,7 @@ function createNodeAnchors(doc, prefix) {
|
|
|
649
601
|
setAnchors: () => {
|
|
650
602
|
for (const source of aliasObjects) {
|
|
651
603
|
const ref = sourceObjects.get(source);
|
|
652
|
-
if (typeof ref === "object" && ref.anchor && (isScalar
|
|
604
|
+
if (typeof ref === "object" && ref.anchor && (isScalar(ref.node) || isCollection(ref.node))) {
|
|
653
605
|
ref.node.anchor = ref.anchor;
|
|
654
606
|
} else {
|
|
655
607
|
const error2 = new Error("Failed to resolve repeated object (this should not happen)");
|
|
@@ -770,10 +722,10 @@ class Alias extends NodeBase {
|
|
|
770
722
|
*/
|
|
771
723
|
resolve(doc) {
|
|
772
724
|
let found = void 0;
|
|
773
|
-
visit
|
|
725
|
+
visit(doc, {
|
|
774
726
|
Node: (_key, node) => {
|
|
775
727
|
if (node === this)
|
|
776
|
-
return visit
|
|
728
|
+
return visit.BREAK;
|
|
777
729
|
if (node.anchor === this.source)
|
|
778
730
|
found = node;
|
|
779
731
|
}
|
|
@@ -828,7 +780,7 @@ function getAliasCount(doc, node, anchors) {
|
|
|
828
780
|
const source = node.resolve(doc);
|
|
829
781
|
const anchor = anchors && source && anchors.get(source);
|
|
830
782
|
return anchor ? anchor.count * anchor.aliasCount : 0;
|
|
831
|
-
} else if (isCollection
|
|
783
|
+
} else if (isCollection(node)) {
|
|
832
784
|
let count = 0;
|
|
833
785
|
for (const item of node.items) {
|
|
834
786
|
const c = getAliasCount(doc, item, anchors);
|
|
@@ -984,7 +936,7 @@ class Collection extends NodeBase {
|
|
|
984
936
|
else {
|
|
985
937
|
const [key, ...rest] = path2;
|
|
986
938
|
const node = this.get(key, true);
|
|
987
|
-
if (isCollection
|
|
939
|
+
if (isCollection(node))
|
|
988
940
|
node.addIn(rest, value);
|
|
989
941
|
else if (node === void 0 && this.schema)
|
|
990
942
|
this.set(key, collectionFromPath(this.schema, rest, value));
|
|
@@ -1001,7 +953,7 @@ class Collection extends NodeBase {
|
|
|
1001
953
|
if (rest.length === 0)
|
|
1002
954
|
return this.delete(key);
|
|
1003
955
|
const node = this.get(key, true);
|
|
1004
|
-
if (isCollection
|
|
956
|
+
if (isCollection(node))
|
|
1005
957
|
return node.deleteIn(rest);
|
|
1006
958
|
else
|
|
1007
959
|
throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
|
|
@@ -1015,16 +967,16 @@ class Collection extends NodeBase {
|
|
|
1015
967
|
const [key, ...rest] = path2;
|
|
1016
968
|
const node = this.get(key, true);
|
|
1017
969
|
if (rest.length === 0)
|
|
1018
|
-
return !keepScalar && isScalar
|
|
970
|
+
return !keepScalar && isScalar(node) ? node.value : node;
|
|
1019
971
|
else
|
|
1020
|
-
return isCollection
|
|
972
|
+
return isCollection(node) ? node.getIn(rest, keepScalar) : void 0;
|
|
1021
973
|
}
|
|
1022
974
|
hasAllNullValues(allowScalar) {
|
|
1023
975
|
return this.items.every((node) => {
|
|
1024
976
|
if (!isPair(node))
|
|
1025
977
|
return false;
|
|
1026
978
|
const n = node.value;
|
|
1027
|
-
return n == null || allowScalar && isScalar
|
|
979
|
+
return n == null || allowScalar && isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
|
|
1028
980
|
});
|
|
1029
981
|
}
|
|
1030
982
|
/**
|
|
@@ -1035,7 +987,7 @@ class Collection extends NodeBase {
|
|
|
1035
987
|
if (rest.length === 0)
|
|
1036
988
|
return this.has(key);
|
|
1037
989
|
const node = this.get(key, true);
|
|
1038
|
-
return isCollection
|
|
990
|
+
return isCollection(node) ? node.hasIn(rest) : false;
|
|
1039
991
|
}
|
|
1040
992
|
/**
|
|
1041
993
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
@@ -1047,7 +999,7 @@ class Collection extends NodeBase {
|
|
|
1047
999
|
this.set(key, value);
|
|
1048
1000
|
} else {
|
|
1049
1001
|
const node = this.get(key, true);
|
|
1050
|
-
if (isCollection
|
|
1002
|
+
if (isCollection(node))
|
|
1051
1003
|
node.setIn(rest, value);
|
|
1052
1004
|
else if (node === void 0 && this.schema)
|
|
1053
1005
|
this.set(key, collectionFromPath(this.schema, rest, value));
|
|
@@ -1510,7 +1462,7 @@ function getTagObject(tags, item) {
|
|
|
1510
1462
|
}
|
|
1511
1463
|
let tagObj = void 0;
|
|
1512
1464
|
let obj;
|
|
1513
|
-
if (isScalar
|
|
1465
|
+
if (isScalar(item)) {
|
|
1514
1466
|
obj = item.value;
|
|
1515
1467
|
let match = tags.filter((t) => t.identify?.(obj));
|
|
1516
1468
|
if (match.length > 1) {
|
|
@@ -1533,7 +1485,7 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
|
|
|
1533
1485
|
if (!doc.directives)
|
|
1534
1486
|
return "";
|
|
1535
1487
|
const props = [];
|
|
1536
|
-
const anchor = (isScalar
|
|
1488
|
+
const anchor = (isScalar(node) || isCollection(node)) && node.anchor;
|
|
1537
1489
|
if (anchor && anchorIsValid(anchor)) {
|
|
1538
1490
|
anchors.add(anchor);
|
|
1539
1491
|
props.push(`&${anchor}`);
|
|
@@ -1543,7 +1495,7 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
|
|
|
1543
1495
|
props.push(doc.directives.tagString(tag));
|
|
1544
1496
|
return props.join(" ");
|
|
1545
1497
|
}
|
|
1546
|
-
function stringify$
|
|
1498
|
+
function stringify$1(item, ctx, onComment, onChompKeep) {
|
|
1547
1499
|
if (isPair(item))
|
|
1548
1500
|
return item.toString(ctx, onComment, onChompKeep);
|
|
1549
1501
|
if (isAlias(item)) {
|
|
@@ -1566,10 +1518,10 @@ function stringify$2(item, ctx, onComment, onChompKeep) {
|
|
|
1566
1518
|
const props = stringifyProps(node, tagObj, ctx);
|
|
1567
1519
|
if (props.length > 0)
|
|
1568
1520
|
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
|
|
1569
|
-
const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : isScalar
|
|
1521
|
+
const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : isScalar(node) ? stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
|
|
1570
1522
|
if (!props)
|
|
1571
1523
|
return str;
|
|
1572
|
-
return isScalar
|
|
1524
|
+
return isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
|
|
1573
1525
|
${ctx.indent}${str}`;
|
|
1574
1526
|
}
|
|
1575
1527
|
function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
@@ -1579,12 +1531,12 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
|
1579
1531
|
if (keyComment) {
|
|
1580
1532
|
throw new Error("With simple keys, key nodes cannot have comments");
|
|
1581
1533
|
}
|
|
1582
|
-
if (isCollection
|
|
1534
|
+
if (isCollection(key) || !isNode(key) && typeof key === "object") {
|
|
1583
1535
|
const msg = "With simple keys, collection cannot be used as a key value";
|
|
1584
1536
|
throw new Error(msg);
|
|
1585
1537
|
}
|
|
1586
1538
|
}
|
|
1587
|
-
let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || isCollection
|
|
1539
|
+
let explicitKey = !simpleKeys && (!key || keyComment && value == null && !ctx.inFlow || isCollection(key) || (isScalar(key) ? key.type === Scalar.BLOCK_FOLDED || key.type === Scalar.BLOCK_LITERAL : typeof key === "object"));
|
|
1588
1540
|
ctx = Object.assign({}, ctx, {
|
|
1589
1541
|
allNullValues: false,
|
|
1590
1542
|
implicitKey: !explicitKey && (simpleKeys || !allNullValues),
|
|
@@ -1592,7 +1544,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
|
1592
1544
|
});
|
|
1593
1545
|
let keyCommentDone = false;
|
|
1594
1546
|
let chompKeep = false;
|
|
1595
|
-
let str = stringify$
|
|
1547
|
+
let str = stringify$1(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
|
|
1596
1548
|
if (!explicitKey && !ctx.inFlow && str.length > 1024) {
|
|
1597
1549
|
if (simpleKeys)
|
|
1598
1550
|
throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
|
|
@@ -1637,14 +1589,14 @@ ${indent}:`;
|
|
|
1637
1589
|
value = doc.createNode(value);
|
|
1638
1590
|
}
|
|
1639
1591
|
ctx.implicitKey = false;
|
|
1640
|
-
if (!explicitKey && !keyComment && isScalar
|
|
1592
|
+
if (!explicitKey && !keyComment && isScalar(value))
|
|
1641
1593
|
ctx.indentAtStart = str.length + 1;
|
|
1642
1594
|
chompKeep = false;
|
|
1643
1595
|
if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && isSeq(value) && !value.flow && !value.tag && !value.anchor) {
|
|
1644
1596
|
ctx.indent = ctx.indent.substring(2);
|
|
1645
1597
|
}
|
|
1646
1598
|
let valueCommentDone = false;
|
|
1647
|
-
const valueStr = stringify$
|
|
1599
|
+
const valueStr = stringify$1(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
|
|
1648
1600
|
let ws = " ";
|
|
1649
1601
|
if (keyComment || vsb || vcb) {
|
|
1650
1602
|
ws = vsb ? "\n" : "";
|
|
@@ -1660,7 +1612,7 @@ ${indentComment(cs, ctx.indent)}`;
|
|
|
1660
1612
|
ws += `
|
|
1661
1613
|
${ctx.indent}`;
|
|
1662
1614
|
}
|
|
1663
|
-
} else if (!explicitKey && isCollection
|
|
1615
|
+
} else if (!explicitKey && isCollection(value)) {
|
|
1664
1616
|
const vs0 = valueStr[0];
|
|
1665
1617
|
const nl0 = valueStr.indexOf("\n");
|
|
1666
1618
|
const hasNewline = nl0 !== -1;
|
|
@@ -1709,7 +1661,7 @@ const merge = {
|
|
|
1709
1661
|
}),
|
|
1710
1662
|
stringify: () => MERGE_KEY
|
|
1711
1663
|
};
|
|
1712
|
-
const isMergeKey = (ctx, key) => (merge.identify(key) || isScalar
|
|
1664
|
+
const isMergeKey = (ctx, key) => (merge.identify(key) || isScalar(key) && (!key.type || key.type === Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
|
|
1713
1665
|
function addMergeToJSMap(ctx, map2, value) {
|
|
1714
1666
|
value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
1715
1667
|
if (isSeq(value))
|
|
@@ -1849,7 +1801,7 @@ function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, fl
|
|
|
1849
1801
|
}
|
|
1850
1802
|
}
|
|
1851
1803
|
chompKeep = false;
|
|
1852
|
-
let str2 = stringify$
|
|
1804
|
+
let str2 = stringify$1(item, itemCtx, () => comment2 = null, () => chompKeep = true);
|
|
1853
1805
|
if (comment2)
|
|
1854
1806
|
str2 += lineComment(str2, itemIndent, commentString(comment2));
|
|
1855
1807
|
if (chompKeep && comment2)
|
|
@@ -1916,7 +1868,7 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
|
1916
1868
|
}
|
|
1917
1869
|
if (comment)
|
|
1918
1870
|
reqNewline = true;
|
|
1919
|
-
let str = stringify$
|
|
1871
|
+
let str = stringify$1(item, itemCtx, () => comment = null);
|
|
1920
1872
|
if (i < items.length - 1)
|
|
1921
1873
|
str += ",";
|
|
1922
1874
|
if (comment)
|
|
@@ -1955,12 +1907,12 @@ function addCommentBefore({ indent, options: { commentString } }, lines, comment
|
|
|
1955
1907
|
}
|
|
1956
1908
|
}
|
|
1957
1909
|
function findPair(items, key) {
|
|
1958
|
-
const k = isScalar
|
|
1910
|
+
const k = isScalar(key) ? key.value : key;
|
|
1959
1911
|
for (const it of items) {
|
|
1960
1912
|
if (isPair(it)) {
|
|
1961
1913
|
if (it.key === key || it.key === k)
|
|
1962
1914
|
return it;
|
|
1963
|
-
if (isScalar
|
|
1915
|
+
if (isScalar(it.key) && it.key.value === k)
|
|
1964
1916
|
return it;
|
|
1965
1917
|
}
|
|
1966
1918
|
}
|
|
@@ -2020,7 +1972,7 @@ class YAMLMap extends Collection {
|
|
|
2020
1972
|
if (prev) {
|
|
2021
1973
|
if (!overwrite)
|
|
2022
1974
|
throw new Error(`Key ${_pair.key} already set`);
|
|
2023
|
-
if (isScalar
|
|
1975
|
+
if (isScalar(prev.value) && isScalarValue(_pair.value))
|
|
2024
1976
|
prev.value.value = _pair.value;
|
|
2025
1977
|
else
|
|
2026
1978
|
prev.value = _pair.value;
|
|
@@ -2044,7 +1996,7 @@ class YAMLMap extends Collection {
|
|
|
2044
1996
|
get(key, keepScalar) {
|
|
2045
1997
|
const it = findPair(this.items, key);
|
|
2046
1998
|
const node = it?.value;
|
|
2047
|
-
return (!keepScalar && isScalar
|
|
1999
|
+
return (!keepScalar && isScalar(node) ? node.value : node) ?? void 0;
|
|
2048
2000
|
}
|
|
2049
2001
|
has(key) {
|
|
2050
2002
|
return !!findPair(this.items, key);
|
|
@@ -2126,7 +2078,7 @@ class YAMLSeq extends Collection {
|
|
|
2126
2078
|
if (typeof idx !== "number")
|
|
2127
2079
|
return void 0;
|
|
2128
2080
|
const it = this.items[idx];
|
|
2129
|
-
return !keepScalar && isScalar
|
|
2081
|
+
return !keepScalar && isScalar(it) ? it.value : it;
|
|
2130
2082
|
}
|
|
2131
2083
|
/**
|
|
2132
2084
|
* Checks if the collection includes a value with the key `key`.
|
|
@@ -2150,7 +2102,7 @@ class YAMLSeq extends Collection {
|
|
|
2150
2102
|
if (typeof idx !== "number")
|
|
2151
2103
|
throw new Error(`Expected a valid index, not ${key}.`);
|
|
2152
2104
|
const prev = this.items[idx];
|
|
2153
|
-
if (isScalar
|
|
2105
|
+
if (isScalar(prev) && isScalarValue(value))
|
|
2154
2106
|
prev.value = value;
|
|
2155
2107
|
else
|
|
2156
2108
|
this.items[idx] = value;
|
|
@@ -2192,7 +2144,7 @@ class YAMLSeq extends Collection {
|
|
|
2192
2144
|
}
|
|
2193
2145
|
}
|
|
2194
2146
|
function asItemIndex(key) {
|
|
2195
|
-
let idx = isScalar
|
|
2147
|
+
let idx = isScalar(key) ? key.value : key;
|
|
2196
2148
|
if (idx && typeof idx === "string")
|
|
2197
2149
|
idx = Number(idx);
|
|
2198
2150
|
return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
|
|
@@ -2565,7 +2517,7 @@ const omap = {
|
|
|
2565
2517
|
const pairs2 = resolvePairs(seq2, onError);
|
|
2566
2518
|
const seenKeys = [];
|
|
2567
2519
|
for (const { key } of pairs2.items) {
|
|
2568
|
-
if (isScalar
|
|
2520
|
+
if (isScalar(key)) {
|
|
2569
2521
|
if (seenKeys.includes(key.value)) {
|
|
2570
2522
|
onError(`Ordered maps must not include duplicate keys: ${key.value}`);
|
|
2571
2523
|
} else {
|
|
@@ -2726,7 +2678,7 @@ class YAMLSet extends YAMLMap {
|
|
|
2726
2678
|
*/
|
|
2727
2679
|
get(key, keepPair) {
|
|
2728
2680
|
const pair = findPair(this.items, key);
|
|
2729
|
-
return !keepPair && isPair(pair) ? isScalar
|
|
2681
|
+
return !keepPair && isPair(pair) ? isScalar(pair.key) ? pair.key.value : pair.key : pair;
|
|
2730
2682
|
}
|
|
2731
2683
|
set(key, value) {
|
|
2732
2684
|
if (typeof value !== "boolean")
|
|
@@ -3003,7 +2955,7 @@ function stringifyDocument(doc, options) {
|
|
|
3003
2955
|
contentComment = doc.contents.comment;
|
|
3004
2956
|
}
|
|
3005
2957
|
const onChompKeep = contentComment ? void 0 : () => chompKeep = true;
|
|
3006
|
-
let body = stringify$
|
|
2958
|
+
let body = stringify$1(doc.contents, ctx, () => contentComment = null, onChompKeep);
|
|
3007
2959
|
if (contentComment)
|
|
3008
2960
|
body += lineComment(body, "", commentString(contentComment));
|
|
3009
2961
|
if ((body[0] === "|" || body[0] === ">") && lines[lines.length - 1] === "---") {
|
|
@@ -3011,7 +2963,7 @@ function stringifyDocument(doc, options) {
|
|
|
3011
2963
|
} else
|
|
3012
2964
|
lines.push(body);
|
|
3013
2965
|
} else {
|
|
3014
|
-
lines.push(stringify$
|
|
2966
|
+
lines.push(stringify$1(doc.contents, ctx));
|
|
3015
2967
|
}
|
|
3016
2968
|
if (doc.directives?.docEnd) {
|
|
3017
2969
|
if (doc.comment) {
|
|
@@ -3152,7 +3104,7 @@ class Document {
|
|
|
3152
3104
|
sourceObjects
|
|
3153
3105
|
};
|
|
3154
3106
|
const node = createNode(value, tag, ctx);
|
|
3155
|
-
if (flow && isCollection
|
|
3107
|
+
if (flow && isCollection(node))
|
|
3156
3108
|
node.flow = true;
|
|
3157
3109
|
setAnchors();
|
|
3158
3110
|
return node;
|
|
@@ -3192,7 +3144,7 @@ class Document {
|
|
|
3192
3144
|
* `true` (collections are always returned intact).
|
|
3193
3145
|
*/
|
|
3194
3146
|
get(key, keepScalar) {
|
|
3195
|
-
return isCollection
|
|
3147
|
+
return isCollection(this.contents) ? this.contents.get(key, keepScalar) : void 0;
|
|
3196
3148
|
}
|
|
3197
3149
|
/**
|
|
3198
3150
|
* Returns item at `path`, or `undefined` if not found. By default unwraps
|
|
@@ -3201,14 +3153,14 @@ class Document {
|
|
|
3201
3153
|
*/
|
|
3202
3154
|
getIn(path2, keepScalar) {
|
|
3203
3155
|
if (isEmptyPath(path2))
|
|
3204
|
-
return !keepScalar && isScalar
|
|
3205
|
-
return isCollection
|
|
3156
|
+
return !keepScalar && isScalar(this.contents) ? this.contents.value : this.contents;
|
|
3157
|
+
return isCollection(this.contents) ? this.contents.getIn(path2, keepScalar) : void 0;
|
|
3206
3158
|
}
|
|
3207
3159
|
/**
|
|
3208
3160
|
* Checks if the document includes a value with the key `key`.
|
|
3209
3161
|
*/
|
|
3210
3162
|
has(key) {
|
|
3211
|
-
return isCollection
|
|
3163
|
+
return isCollection(this.contents) ? this.contents.has(key) : false;
|
|
3212
3164
|
}
|
|
3213
3165
|
/**
|
|
3214
3166
|
* Checks if the document includes a value at `path`.
|
|
@@ -3216,7 +3168,7 @@ class Document {
|
|
|
3216
3168
|
hasIn(path2) {
|
|
3217
3169
|
if (isEmptyPath(path2))
|
|
3218
3170
|
return this.contents !== void 0;
|
|
3219
|
-
return isCollection
|
|
3171
|
+
return isCollection(this.contents) ? this.contents.hasIn(path2) : false;
|
|
3220
3172
|
}
|
|
3221
3173
|
/**
|
|
3222
3174
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
@@ -3323,7 +3275,7 @@ class Document {
|
|
|
3323
3275
|
}
|
|
3324
3276
|
}
|
|
3325
3277
|
function assertCollection(contents) {
|
|
3326
|
-
if (isCollection
|
|
3278
|
+
if (isCollection(contents))
|
|
3327
3279
|
return true;
|
|
3328
3280
|
throw new Error("Expected a YAML collection as document contents");
|
|
3329
3281
|
}
|
|
@@ -3556,7 +3508,7 @@ function mapIncludes(ctx, items, search) {
|
|
|
3556
3508
|
const { uniqueKeys } = ctx.options;
|
|
3557
3509
|
if (uniqueKeys === false)
|
|
3558
3510
|
return false;
|
|
3559
|
-
const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || isScalar
|
|
3511
|
+
const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || isScalar(a) && isScalar(b) && a.value === b.value;
|
|
3560
3512
|
return items.some((pair) => isEqual(pair.key, search));
|
|
3561
3513
|
}
|
|
3562
3514
|
const startColMsg = "All mapping items must start at the same column";
|
|
@@ -4354,7 +4306,7 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
4354
4306
|
let scalar;
|
|
4355
4307
|
try {
|
|
4356
4308
|
const res = tag.resolve(value, (msg) => onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg), ctx.options);
|
|
4357
|
-
scalar = isScalar
|
|
4309
|
+
scalar = isScalar(res) ? res : new Scalar(res);
|
|
4358
4310
|
} catch (error2) {
|
|
4359
4311
|
const msg = error2 instanceof Error ? error2.message : String(error2);
|
|
4360
4312
|
onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg);
|
|
@@ -4467,7 +4419,7 @@ function composeNode(ctx, token, props, onError) {
|
|
|
4467
4419
|
}
|
|
4468
4420
|
if (anchor && node.anchor === "")
|
|
4469
4421
|
onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
|
|
4470
|
-
if (atKey && ctx.options.stringKeys && (!isScalar
|
|
4422
|
+
if (atKey && ctx.options.stringKeys && (!isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
|
|
4471
4423
|
const msg = "With stringKeys, all keys must be strings";
|
|
4472
4424
|
onError(tag ?? token, "NON_STRING_KEY", msg);
|
|
4473
4425
|
}
|
|
@@ -4607,7 +4559,7 @@ class Composer {
|
|
|
4607
4559
|
${comment}` : comment;
|
|
4608
4560
|
} else if (afterEmptyLine || doc.directives.docStart || !dc) {
|
|
4609
4561
|
doc.commentBefore = comment;
|
|
4610
|
-
} else if (isCollection
|
|
4562
|
+
} else if (isCollection(dc) && !dc.flow && dc.items.length > 0) {
|
|
4611
4563
|
let it = dc.items[0];
|
|
4612
4564
|
if (isPair(it))
|
|
4613
4565
|
it = it.key;
|
|
@@ -4737,304 +4689,10 @@ ${end.comment}` : end.comment;
|
|
|
4737
4689
|
}
|
|
4738
4690
|
}
|
|
4739
4691
|
}
|
|
4740
|
-
function resolveAsScalar(token, strict = true, onError) {
|
|
4741
|
-
if (token) {
|
|
4742
|
-
const _onError = (pos, code, message) => {
|
|
4743
|
-
const offset = typeof pos === "number" ? pos : Array.isArray(pos) ? pos[0] : pos.offset;
|
|
4744
|
-
if (onError)
|
|
4745
|
-
onError(offset, code, message);
|
|
4746
|
-
else
|
|
4747
|
-
throw new YAMLParseError([offset, offset + 1], code, message);
|
|
4748
|
-
};
|
|
4749
|
-
switch (token.type) {
|
|
4750
|
-
case "scalar":
|
|
4751
|
-
case "single-quoted-scalar":
|
|
4752
|
-
case "double-quoted-scalar":
|
|
4753
|
-
return resolveFlowScalar(token, strict, _onError);
|
|
4754
|
-
case "block-scalar":
|
|
4755
|
-
return resolveBlockScalar({ options: { strict } }, token, _onError);
|
|
4756
|
-
}
|
|
4757
|
-
}
|
|
4758
|
-
return null;
|
|
4759
|
-
}
|
|
4760
|
-
function createScalarToken(value, context) {
|
|
4761
|
-
const { implicitKey = false, indent, inFlow = false, offset = -1, type = "PLAIN" } = context;
|
|
4762
|
-
const source = stringifyString({ type, value }, {
|
|
4763
|
-
implicitKey,
|
|
4764
|
-
indent: indent > 0 ? " ".repeat(indent) : "",
|
|
4765
|
-
inFlow,
|
|
4766
|
-
options: { blockQuote: true, lineWidth: -1 }
|
|
4767
|
-
});
|
|
4768
|
-
const end = context.end ?? [
|
|
4769
|
-
{ type: "newline", offset: -1, indent, source: "\n" }
|
|
4770
|
-
];
|
|
4771
|
-
switch (source[0]) {
|
|
4772
|
-
case "|":
|
|
4773
|
-
case ">": {
|
|
4774
|
-
const he = source.indexOf("\n");
|
|
4775
|
-
const head = source.substring(0, he);
|
|
4776
|
-
const body = source.substring(he + 1) + "\n";
|
|
4777
|
-
const props = [
|
|
4778
|
-
{ type: "block-scalar-header", offset, indent, source: head }
|
|
4779
|
-
];
|
|
4780
|
-
if (!addEndtoBlockProps(props, end))
|
|
4781
|
-
props.push({ type: "newline", offset: -1, indent, source: "\n" });
|
|
4782
|
-
return { type: "block-scalar", offset, indent, props, source: body };
|
|
4783
|
-
}
|
|
4784
|
-
case '"':
|
|
4785
|
-
return { type: "double-quoted-scalar", offset, indent, source, end };
|
|
4786
|
-
case "'":
|
|
4787
|
-
return { type: "single-quoted-scalar", offset, indent, source, end };
|
|
4788
|
-
default:
|
|
4789
|
-
return { type: "scalar", offset, indent, source, end };
|
|
4790
|
-
}
|
|
4791
|
-
}
|
|
4792
|
-
function setScalarValue(token, value, context = {}) {
|
|
4793
|
-
let { afterKey = false, implicitKey = false, inFlow = false, type } = context;
|
|
4794
|
-
let indent = "indent" in token ? token.indent : null;
|
|
4795
|
-
if (afterKey && typeof indent === "number")
|
|
4796
|
-
indent += 2;
|
|
4797
|
-
if (!type)
|
|
4798
|
-
switch (token.type) {
|
|
4799
|
-
case "single-quoted-scalar":
|
|
4800
|
-
type = "QUOTE_SINGLE";
|
|
4801
|
-
break;
|
|
4802
|
-
case "double-quoted-scalar":
|
|
4803
|
-
type = "QUOTE_DOUBLE";
|
|
4804
|
-
break;
|
|
4805
|
-
case "block-scalar": {
|
|
4806
|
-
const header = token.props[0];
|
|
4807
|
-
if (header.type !== "block-scalar-header")
|
|
4808
|
-
throw new Error("Invalid block scalar header");
|
|
4809
|
-
type = header.source[0] === ">" ? "BLOCK_FOLDED" : "BLOCK_LITERAL";
|
|
4810
|
-
break;
|
|
4811
|
-
}
|
|
4812
|
-
default:
|
|
4813
|
-
type = "PLAIN";
|
|
4814
|
-
}
|
|
4815
|
-
const source = stringifyString({ type, value }, {
|
|
4816
|
-
implicitKey: implicitKey || indent === null,
|
|
4817
|
-
indent: indent !== null && indent > 0 ? " ".repeat(indent) : "",
|
|
4818
|
-
inFlow,
|
|
4819
|
-
options: { blockQuote: true, lineWidth: -1 }
|
|
4820
|
-
});
|
|
4821
|
-
switch (source[0]) {
|
|
4822
|
-
case "|":
|
|
4823
|
-
case ">":
|
|
4824
|
-
setBlockScalarValue(token, source);
|
|
4825
|
-
break;
|
|
4826
|
-
case '"':
|
|
4827
|
-
setFlowScalarValue(token, source, "double-quoted-scalar");
|
|
4828
|
-
break;
|
|
4829
|
-
case "'":
|
|
4830
|
-
setFlowScalarValue(token, source, "single-quoted-scalar");
|
|
4831
|
-
break;
|
|
4832
|
-
default:
|
|
4833
|
-
setFlowScalarValue(token, source, "scalar");
|
|
4834
|
-
}
|
|
4835
|
-
}
|
|
4836
|
-
function setBlockScalarValue(token, source) {
|
|
4837
|
-
const he = source.indexOf("\n");
|
|
4838
|
-
const head = source.substring(0, he);
|
|
4839
|
-
const body = source.substring(he + 1) + "\n";
|
|
4840
|
-
if (token.type === "block-scalar") {
|
|
4841
|
-
const header = token.props[0];
|
|
4842
|
-
if (header.type !== "block-scalar-header")
|
|
4843
|
-
throw new Error("Invalid block scalar header");
|
|
4844
|
-
header.source = head;
|
|
4845
|
-
token.source = body;
|
|
4846
|
-
} else {
|
|
4847
|
-
const { offset } = token;
|
|
4848
|
-
const indent = "indent" in token ? token.indent : -1;
|
|
4849
|
-
const props = [
|
|
4850
|
-
{ type: "block-scalar-header", offset, indent, source: head }
|
|
4851
|
-
];
|
|
4852
|
-
if (!addEndtoBlockProps(props, "end" in token ? token.end : void 0))
|
|
4853
|
-
props.push({ type: "newline", offset: -1, indent, source: "\n" });
|
|
4854
|
-
for (const key of Object.keys(token))
|
|
4855
|
-
if (key !== "type" && key !== "offset")
|
|
4856
|
-
delete token[key];
|
|
4857
|
-
Object.assign(token, { type: "block-scalar", indent, props, source: body });
|
|
4858
|
-
}
|
|
4859
|
-
}
|
|
4860
|
-
function addEndtoBlockProps(props, end) {
|
|
4861
|
-
if (end)
|
|
4862
|
-
for (const st of end)
|
|
4863
|
-
switch (st.type) {
|
|
4864
|
-
case "space":
|
|
4865
|
-
case "comment":
|
|
4866
|
-
props.push(st);
|
|
4867
|
-
break;
|
|
4868
|
-
case "newline":
|
|
4869
|
-
props.push(st);
|
|
4870
|
-
return true;
|
|
4871
|
-
}
|
|
4872
|
-
return false;
|
|
4873
|
-
}
|
|
4874
|
-
function setFlowScalarValue(token, source, type) {
|
|
4875
|
-
switch (token.type) {
|
|
4876
|
-
case "scalar":
|
|
4877
|
-
case "double-quoted-scalar":
|
|
4878
|
-
case "single-quoted-scalar":
|
|
4879
|
-
token.type = type;
|
|
4880
|
-
token.source = source;
|
|
4881
|
-
break;
|
|
4882
|
-
case "block-scalar": {
|
|
4883
|
-
const end = token.props.slice(1);
|
|
4884
|
-
let oa = source.length;
|
|
4885
|
-
if (token.props[0].type === "block-scalar-header")
|
|
4886
|
-
oa -= token.props[0].source.length;
|
|
4887
|
-
for (const tok of end)
|
|
4888
|
-
tok.offset += oa;
|
|
4889
|
-
delete token.props;
|
|
4890
|
-
Object.assign(token, { type, source, end });
|
|
4891
|
-
break;
|
|
4892
|
-
}
|
|
4893
|
-
case "block-map":
|
|
4894
|
-
case "block-seq": {
|
|
4895
|
-
const offset = token.offset + source.length;
|
|
4896
|
-
const nl = { type: "newline", offset, indent: token.indent, source: "\n" };
|
|
4897
|
-
delete token.items;
|
|
4898
|
-
Object.assign(token, { type, source, end: [nl] });
|
|
4899
|
-
break;
|
|
4900
|
-
}
|
|
4901
|
-
default: {
|
|
4902
|
-
const indent = "indent" in token ? token.indent : -1;
|
|
4903
|
-
const end = "end" in token && Array.isArray(token.end) ? token.end.filter((st) => st.type === "space" || st.type === "comment" || st.type === "newline") : [];
|
|
4904
|
-
for (const key of Object.keys(token))
|
|
4905
|
-
if (key !== "type" && key !== "offset")
|
|
4906
|
-
delete token[key];
|
|
4907
|
-
Object.assign(token, { type, indent, source, end });
|
|
4908
|
-
}
|
|
4909
|
-
}
|
|
4910
|
-
}
|
|
4911
|
-
const stringify$1 = (cst2) => "type" in cst2 ? stringifyToken(cst2) : stringifyItem(cst2);
|
|
4912
|
-
function stringifyToken(token) {
|
|
4913
|
-
switch (token.type) {
|
|
4914
|
-
case "block-scalar": {
|
|
4915
|
-
let res = "";
|
|
4916
|
-
for (const tok of token.props)
|
|
4917
|
-
res += stringifyToken(tok);
|
|
4918
|
-
return res + token.source;
|
|
4919
|
-
}
|
|
4920
|
-
case "block-map":
|
|
4921
|
-
case "block-seq": {
|
|
4922
|
-
let res = "";
|
|
4923
|
-
for (const item of token.items)
|
|
4924
|
-
res += stringifyItem(item);
|
|
4925
|
-
return res;
|
|
4926
|
-
}
|
|
4927
|
-
case "flow-collection": {
|
|
4928
|
-
let res = token.start.source;
|
|
4929
|
-
for (const item of token.items)
|
|
4930
|
-
res += stringifyItem(item);
|
|
4931
|
-
for (const st of token.end)
|
|
4932
|
-
res += st.source;
|
|
4933
|
-
return res;
|
|
4934
|
-
}
|
|
4935
|
-
case "document": {
|
|
4936
|
-
let res = stringifyItem(token);
|
|
4937
|
-
if (token.end)
|
|
4938
|
-
for (const st of token.end)
|
|
4939
|
-
res += st.source;
|
|
4940
|
-
return res;
|
|
4941
|
-
}
|
|
4942
|
-
default: {
|
|
4943
|
-
let res = token.source;
|
|
4944
|
-
if ("end" in token && token.end)
|
|
4945
|
-
for (const st of token.end)
|
|
4946
|
-
res += st.source;
|
|
4947
|
-
return res;
|
|
4948
|
-
}
|
|
4949
|
-
}
|
|
4950
|
-
}
|
|
4951
|
-
function stringifyItem({ start: start2, key, sep, value }) {
|
|
4952
|
-
let res = "";
|
|
4953
|
-
for (const st of start2)
|
|
4954
|
-
res += st.source;
|
|
4955
|
-
if (key)
|
|
4956
|
-
res += stringifyToken(key);
|
|
4957
|
-
if (sep)
|
|
4958
|
-
for (const st of sep)
|
|
4959
|
-
res += st.source;
|
|
4960
|
-
if (value)
|
|
4961
|
-
res += stringifyToken(value);
|
|
4962
|
-
return res;
|
|
4963
|
-
}
|
|
4964
|
-
const BREAK = Symbol("break visit");
|
|
4965
|
-
const SKIP = Symbol("skip children");
|
|
4966
|
-
const REMOVE = Symbol("remove item");
|
|
4967
|
-
function visit(cst2, visitor) {
|
|
4968
|
-
if ("type" in cst2 && cst2.type === "document")
|
|
4969
|
-
cst2 = { start: cst2.start, value: cst2.value };
|
|
4970
|
-
_visit(Object.freeze([]), cst2, visitor);
|
|
4971
|
-
}
|
|
4972
|
-
visit.BREAK = BREAK;
|
|
4973
|
-
visit.SKIP = SKIP;
|
|
4974
|
-
visit.REMOVE = REMOVE;
|
|
4975
|
-
visit.itemAtPath = (cst2, path2) => {
|
|
4976
|
-
let item = cst2;
|
|
4977
|
-
for (const [field, index] of path2) {
|
|
4978
|
-
const tok = item?.[field];
|
|
4979
|
-
if (tok && "items" in tok) {
|
|
4980
|
-
item = tok.items[index];
|
|
4981
|
-
} else
|
|
4982
|
-
return void 0;
|
|
4983
|
-
}
|
|
4984
|
-
return item;
|
|
4985
|
-
};
|
|
4986
|
-
visit.parentCollection = (cst2, path2) => {
|
|
4987
|
-
const parent = visit.itemAtPath(cst2, path2.slice(0, -1));
|
|
4988
|
-
const field = path2[path2.length - 1][0];
|
|
4989
|
-
const coll = parent?.[field];
|
|
4990
|
-
if (coll && "items" in coll)
|
|
4991
|
-
return coll;
|
|
4992
|
-
throw new Error("Parent collection not found");
|
|
4993
|
-
};
|
|
4994
|
-
function _visit(path2, item, visitor) {
|
|
4995
|
-
let ctrl = visitor(item, path2);
|
|
4996
|
-
if (typeof ctrl === "symbol")
|
|
4997
|
-
return ctrl;
|
|
4998
|
-
for (const field of ["key", "value"]) {
|
|
4999
|
-
const token = item[field];
|
|
5000
|
-
if (token && "items" in token) {
|
|
5001
|
-
for (let i = 0; i < token.items.length; ++i) {
|
|
5002
|
-
const ci = _visit(Object.freeze(path2.concat([[field, i]])), token.items[i], visitor);
|
|
5003
|
-
if (typeof ci === "number")
|
|
5004
|
-
i = ci - 1;
|
|
5005
|
-
else if (ci === BREAK)
|
|
5006
|
-
return BREAK;
|
|
5007
|
-
else if (ci === REMOVE) {
|
|
5008
|
-
token.items.splice(i, 1);
|
|
5009
|
-
i -= 1;
|
|
5010
|
-
}
|
|
5011
|
-
}
|
|
5012
|
-
if (typeof ctrl === "function" && field === "key")
|
|
5013
|
-
ctrl = ctrl(item, path2);
|
|
5014
|
-
}
|
|
5015
|
-
}
|
|
5016
|
-
return typeof ctrl === "function" ? ctrl(item, path2) : ctrl;
|
|
5017
|
-
}
|
|
5018
4692
|
const BOM = "\uFEFF";
|
|
5019
4693
|
const DOCUMENT = "";
|
|
5020
4694
|
const FLOW_END = "";
|
|
5021
4695
|
const SCALAR = "";
|
|
5022
|
-
const isCollection = (token) => !!token && "items" in token;
|
|
5023
|
-
const isScalar = (token) => !!token && (token.type === "scalar" || token.type === "single-quoted-scalar" || token.type === "double-quoted-scalar" || token.type === "block-scalar");
|
|
5024
|
-
function prettyToken(token) {
|
|
5025
|
-
switch (token) {
|
|
5026
|
-
case BOM:
|
|
5027
|
-
return "<BOM>";
|
|
5028
|
-
case DOCUMENT:
|
|
5029
|
-
return "<DOC>";
|
|
5030
|
-
case FLOW_END:
|
|
5031
|
-
return "<FLOW_END>";
|
|
5032
|
-
case SCALAR:
|
|
5033
|
-
return "<SCALAR>";
|
|
5034
|
-
default:
|
|
5035
|
-
return JSON.stringify(token);
|
|
5036
|
-
}
|
|
5037
|
-
}
|
|
5038
4696
|
function tokenType(source) {
|
|
5039
4697
|
switch (source) {
|
|
5040
4698
|
case BOM:
|
|
@@ -5094,22 +4752,6 @@ function tokenType(source) {
|
|
|
5094
4752
|
}
|
|
5095
4753
|
return null;
|
|
5096
4754
|
}
|
|
5097
|
-
const cst = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
5098
|
-
__proto__: null,
|
|
5099
|
-
BOM,
|
|
5100
|
-
DOCUMENT,
|
|
5101
|
-
FLOW_END,
|
|
5102
|
-
SCALAR,
|
|
5103
|
-
createScalarToken,
|
|
5104
|
-
isCollection,
|
|
5105
|
-
isScalar,
|
|
5106
|
-
prettyToken,
|
|
5107
|
-
resolveAsScalar,
|
|
5108
|
-
setScalarValue,
|
|
5109
|
-
stringify: stringify$1,
|
|
5110
|
-
tokenType,
|
|
5111
|
-
visit
|
|
5112
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
5113
4755
|
function isEmpty(ch) {
|
|
5114
4756
|
switch (ch) {
|
|
5115
4757
|
case void 0:
|
|
@@ -6552,20 +6194,6 @@ function parseOptions(options) {
|
|
|
6552
6194
|
const lineCounter = options.lineCounter || prettyErrors && new LineCounter() || null;
|
|
6553
6195
|
return { lineCounter, prettyErrors };
|
|
6554
6196
|
}
|
|
6555
|
-
function parseAllDocuments(source, options = {}) {
|
|
6556
|
-
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
6557
|
-
const parser = new Parser(lineCounter?.addNewLine);
|
|
6558
|
-
const composer = new Composer(options);
|
|
6559
|
-
const docs = Array.from(composer.compose(parser.parse(source)));
|
|
6560
|
-
if (prettyErrors && lineCounter)
|
|
6561
|
-
for (const doc of docs) {
|
|
6562
|
-
doc.errors.forEach(prettifyError(source, lineCounter));
|
|
6563
|
-
doc.warnings.forEach(prettifyError(source, lineCounter));
|
|
6564
|
-
}
|
|
6565
|
-
if (docs.length > 0)
|
|
6566
|
-
return docs;
|
|
6567
|
-
return Object.assign([], { empty: true }, composer.streamInfo());
|
|
6568
|
-
}
|
|
6569
6197
|
function parseDocument(source, options = {}) {
|
|
6570
6198
|
const { lineCounter, prettyErrors } = parseOptions(options);
|
|
6571
6199
|
const parser = new Parser(lineCounter?.addNewLine);
|
|
@@ -6587,11 +6215,6 @@ function parseDocument(source, options = {}) {
|
|
|
6587
6215
|
}
|
|
6588
6216
|
function parse(src, reviver, options) {
|
|
6589
6217
|
let _reviver = void 0;
|
|
6590
|
-
if (typeof reviver === "function") {
|
|
6591
|
-
_reviver = reviver;
|
|
6592
|
-
} else if (options === void 0 && reviver && typeof reviver === "object") {
|
|
6593
|
-
options = reviver;
|
|
6594
|
-
}
|
|
6595
6218
|
const doc = parseDocument(src, options);
|
|
6596
6219
|
if (!doc)
|
|
6597
6220
|
return null;
|
|
@@ -6606,19 +6229,11 @@ function parse(src, reviver, options) {
|
|
|
6606
6229
|
}
|
|
6607
6230
|
function stringify(value, replacer, options) {
|
|
6608
6231
|
let _replacer = null;
|
|
6609
|
-
if (
|
|
6232
|
+
if (Array.isArray(replacer)) {
|
|
6610
6233
|
_replacer = replacer;
|
|
6611
|
-
} else if (options === void 0 && replacer) {
|
|
6612
|
-
options = replacer;
|
|
6613
|
-
}
|
|
6614
|
-
if (typeof options === "string")
|
|
6615
|
-
options = options.length;
|
|
6616
|
-
if (typeof options === "number") {
|
|
6617
|
-
const indent = Math.round(options);
|
|
6618
|
-
options = indent < 1 ? void 0 : indent > 8 ? { indent: 8 } : { indent };
|
|
6619
6234
|
}
|
|
6620
6235
|
if (value === void 0) {
|
|
6621
|
-
const { keepUndefined } =
|
|
6236
|
+
const { keepUndefined } = {};
|
|
6622
6237
|
if (!keepUndefined)
|
|
6623
6238
|
return void 0;
|
|
6624
6239
|
}
|
|
@@ -6626,38 +6241,6 @@ function stringify(value, replacer, options) {
|
|
|
6626
6241
|
return value.toString(options);
|
|
6627
6242
|
return new Document(value, _replacer, options).toString(options);
|
|
6628
6243
|
}
|
|
6629
|
-
const YAML = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
6630
|
-
__proto__: null,
|
|
6631
|
-
Alias,
|
|
6632
|
-
CST: cst,
|
|
6633
|
-
Composer,
|
|
6634
|
-
Document,
|
|
6635
|
-
Lexer,
|
|
6636
|
-
LineCounter,
|
|
6637
|
-
Pair,
|
|
6638
|
-
Parser,
|
|
6639
|
-
Scalar,
|
|
6640
|
-
Schema,
|
|
6641
|
-
YAMLError,
|
|
6642
|
-
YAMLMap,
|
|
6643
|
-
YAMLParseError,
|
|
6644
|
-
YAMLSeq,
|
|
6645
|
-
YAMLWarning,
|
|
6646
|
-
isAlias,
|
|
6647
|
-
isCollection: isCollection$1,
|
|
6648
|
-
isDocument,
|
|
6649
|
-
isMap,
|
|
6650
|
-
isNode,
|
|
6651
|
-
isPair,
|
|
6652
|
-
isScalar: isScalar$1,
|
|
6653
|
-
isSeq,
|
|
6654
|
-
parse,
|
|
6655
|
-
parseAllDocuments,
|
|
6656
|
-
parseDocument,
|
|
6657
|
-
stringify,
|
|
6658
|
-
visit: visit$1,
|
|
6659
|
-
visitAsync
|
|
6660
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
6661
6244
|
const MAIN = "index.mjs";
|
|
6662
6245
|
const getIsDev = (dir) => {
|
|
6663
6246
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -6828,7 +6411,7 @@ const createWorkspace = (isDev, dir) => {
|
|
|
6828
6411
|
const workspace = path.join(dir, "pnpm-workspace.yaml");
|
|
6829
6412
|
let data = {};
|
|
6830
6413
|
try {
|
|
6831
|
-
data = fs.existsSync(workspace) ?
|
|
6414
|
+
data = fs.existsSync(workspace) ? parse(fs.readFileSync(workspace, "utf-8")) : {};
|
|
6832
6415
|
} catch {
|
|
6833
6416
|
data = {};
|
|
6834
6417
|
}
|
|
@@ -6872,7 +6455,7 @@ const createWorkspace = (isDev, dir) => {
|
|
|
6872
6455
|
...data.publicHoistPattern
|
|
6873
6456
|
];
|
|
6874
6457
|
data.publicHoistPattern = dedupe(publicHoistPattern);
|
|
6875
|
-
fs.writeFileSync(workspace,
|
|
6458
|
+
fs.writeFileSync(workspace, stringify(
|
|
6876
6459
|
Object.assign(
|
|
6877
6460
|
{
|
|
6878
6461
|
lockfile: false,
|
|
@@ -7320,11 +6903,11 @@ const readWorkspaceFile = () => {
|
|
|
7320
6903
|
throw new Error("pnpm-workspace.yaml 文件不存在");
|
|
7321
6904
|
}
|
|
7322
6905
|
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
7323
|
-
return
|
|
6906
|
+
return parse(fileContent);
|
|
7324
6907
|
};
|
|
7325
6908
|
const writeWorkspaceFile = (content) => {
|
|
7326
6909
|
const filePath = getWorkspaceFilePath();
|
|
7327
|
-
const yamlStr =
|
|
6910
|
+
const yamlStr = stringify(content);
|
|
7328
6911
|
fs.writeFileSync(filePath, yamlStr, "utf-8");
|
|
7329
6912
|
};
|
|
7330
6913
|
const addBuildDependency = (dependencies) => {
|