Build plugins

This commit is contained in:
Gregory Schier
2025-03-08 08:06:18 -08:00
parent cdce2ac53a
commit 12233cb6f6
7 changed files with 550 additions and 154 deletions

View File

@@ -1304,21 +1304,29 @@ ${indent}`) + "'";
start = start.replace(/\n+/g, `$&${indent}`);
}
const indentSize = indent ? "2" : "1";
let header = (literal ? "|" : ">") + (startWithSpace ? indentSize : "") + chomp;
let header = (startWithSpace ? indentSize : "") + chomp;
if (comment) {
header += " " + commentString(comment.replace(/ ?[\r\n]+/g, " "));
if (onComment)
onComment();
}
if (literal) {
value = value.replace(/\n+/g, `$&${indent}`);
return `${header}
${indent}${start}${value}${end}`;
}
value = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx, true));
return `${header}
if (!literal) {
const foldedValue = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
let literalFallback = false;
const foldOptions = getFoldOptions(ctx, true);
if (blockQuote !== "folded" && type !== Scalar.Scalar.BLOCK_FOLDED) {
foldOptions.onOverflow = () => {
literalFallback = true;
};
}
const body = foldFlowLines.foldFlowLines(`${start}${foldedValue}${end}`, indent, foldFlowLines.FOLD_BLOCK, foldOptions);
if (!literalFallback)
return `>${header}
${indent}${body}`;
}
value = value.replace(/\n+/g, `$&${indent}`);
return `|${header}
${indent}${start}${value}${end}`;
}
function plainString(item, ctx, onComment, onChompKeep) {
const { type, value } = item;
@@ -1446,7 +1454,12 @@ var require_stringify = __commonJS({
let obj;
if (identity.isScalar(item)) {
obj = item.value;
const match = tags.filter((t) => t.identify?.(obj));
let match = tags.filter((t) => t.identify?.(obj));
if (match.length > 1) {
const testMatch = match.filter((t) => t.test);
if (testMatch.length > 0)
match = testMatch;
}
tagObj = match.find((t) => t.format === item.format) ?? match.find((t) => !t.format);
} else {
obj = item;
@@ -1643,14 +1656,15 @@ ${ctx.indent}`;
var require_log = __commonJS({
"../../node_modules/yaml/dist/log.js"(exports2) {
"use strict";
var node_process = require("node:process");
function debug(logLevel, ...messages) {
if (logLevel === "debug")
console.log(...messages);
}
function warn(logLevel, warning) {
if (logLevel === "debug" || logLevel === "warn") {
if (typeof process !== "undefined" && process.emitWarning)
process.emitWarning(warning);
if (typeof node_process.emitWarning === "function")
node_process.emitWarning(warning);
else
console.warn(warning);
}
@@ -1660,51 +1674,36 @@ var require_log = __commonJS({
}
});
// ../../node_modules/yaml/dist/nodes/addPairToJSMap.js
var require_addPairToJSMap = __commonJS({
"../../node_modules/yaml/dist/nodes/addPairToJSMap.js"(exports2) {
// ../../node_modules/yaml/dist/schema/yaml-1.1/merge.js
var require_merge = __commonJS({
"../../node_modules/yaml/dist/schema/yaml-1.1/merge.js"(exports2) {
"use strict";
var log = require_log();
var stringify = require_stringify();
var identity = require_identity();
var Scalar = require_Scalar();
var toJS = require_toJS();
var MERGE_KEY = "<<";
function addPairToJSMap(ctx, map, { key, value }) {
if (ctx?.doc.schema.merge && isMergeKey(key)) {
value = identity.isAlias(value) ? value.resolve(ctx.doc) : value;
if (identity.isSeq(value))
for (const it of value.items)
mergeToJSMap(ctx, map, it);
else if (Array.isArray(value))
for (const it of value)
mergeToJSMap(ctx, map, it);
else
mergeToJSMap(ctx, map, value);
} else {
const jsKey = toJS.toJS(key, "", ctx);
if (map instanceof Map) {
map.set(jsKey, toJS.toJS(value, jsKey, ctx));
} else if (map instanceof Set) {
map.add(jsKey);
} else {
const stringKey = stringifyKey(key, jsKey, ctx);
const jsValue = toJS.toJS(value, stringKey, ctx);
if (stringKey in map)
Object.defineProperty(map, stringKey, {
value: jsValue,
writable: true,
enumerable: true,
configurable: true
});
else
map[stringKey] = jsValue;
}
}
return map;
var merge = {
identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
default: "key",
tag: "tag:yaml.org,2002:merge",
test: /^<<$/,
resolve: () => Object.assign(new Scalar.Scalar(Symbol(MERGE_KEY)), {
addToJSMap: addMergeToJSMap
}),
stringify: () => MERGE_KEY
};
var isMergeKey = (ctx, key) => (merge.identify(key) || identity.isScalar(key) && (!key.type || key.type === Scalar.Scalar.PLAIN) && merge.identify(key.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
function addMergeToJSMap(ctx, map, value) {
value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
if (identity.isSeq(value))
for (const it of value.items)
mergeValue(ctx, map, it);
else if (Array.isArray(value))
for (const it of value)
mergeValue(ctx, map, it);
else
mergeValue(ctx, map, value);
}
var isMergeKey = (key) => key === MERGE_KEY || identity.isScalar(key) && key.value === MERGE_KEY && (!key.type || key.type === Scalar.Scalar.PLAIN);
function mergeToJSMap(ctx, map, value) {
function mergeValue(ctx, map, value) {
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
if (!identity.isMap(source))
throw new Error("Merge sources must be maps or map aliases");
@@ -1726,6 +1725,48 @@ var require_addPairToJSMap = __commonJS({
}
return map;
}
exports2.addMergeToJSMap = addMergeToJSMap;
exports2.isMergeKey = isMergeKey;
exports2.merge = merge;
}
});
// ../../node_modules/yaml/dist/nodes/addPairToJSMap.js
var require_addPairToJSMap = __commonJS({
"../../node_modules/yaml/dist/nodes/addPairToJSMap.js"(exports2) {
"use strict";
var log = require_log();
var merge = require_merge();
var stringify = require_stringify();
var identity = require_identity();
var toJS = require_toJS();
function addPairToJSMap(ctx, map, { key, value }) {
if (identity.isNode(key) && key.addToJSMap)
key.addToJSMap(ctx, map, value);
else if (merge.isMergeKey(ctx, key))
merge.addMergeToJSMap(ctx, map, value);
else {
const jsKey = toJS.toJS(key, "", ctx);
if (map instanceof Map) {
map.set(jsKey, toJS.toJS(value, jsKey, ctx));
} else if (map instanceof Set) {
map.add(jsKey);
} else {
const stringKey = stringifyKey(key, jsKey, ctx);
const jsValue = toJS.toJS(value, stringKey, ctx);
if (stringKey in map)
Object.defineProperty(map, stringKey, {
value: jsValue,
writable: true,
enumerable: true,
configurable: true
});
else
map[stringKey] = jsValue;
}
}
return map;
}
function stringifyKey(key, jsKey, ctx) {
if (jsKey === null)
return "";
@@ -2481,7 +2522,7 @@ var require_schema2 = __commonJS({
identify: (value) => typeof value === "boolean",
default: true,
tag: "tag:yaml.org,2002:bool",
test: /^true|false$/,
test: /^true$|^false$/,
resolve: (str) => str === "true",
stringify: stringifyJSON
},
@@ -2520,6 +2561,7 @@ var require_schema2 = __commonJS({
var require_binary = __commonJS({
"../../node_modules/yaml/dist/schema/yaml-1.1/binary.js"(exports2) {
"use strict";
var node_buffer = require("node:buffer");
var Scalar = require_Scalar();
var stringifyString = require_stringifyString();
var binary = {
@@ -2536,8 +2578,8 @@ var require_binary = __commonJS({
* document.querySelector('#photo').src = URL.createObjectURL(blob)
*/
resolve(src, onError) {
if (typeof Buffer === "function") {
return Buffer.from(src, "base64");
if (typeof node_buffer.Buffer === "function") {
return node_buffer.Buffer.from(src, "base64");
} else if (typeof atob === "function") {
const str = atob(src.replace(/[\n\r]/g, ""));
const buffer = new Uint8Array(str.length);
@@ -2552,8 +2594,8 @@ var require_binary = __commonJS({
stringify({ comment, type, value }, ctx, onComment, onChompKeep) {
const buf = value;
let str;
if (typeof Buffer === "function") {
str = buf instanceof Buffer ? buf.toString("base64") : Buffer.from(buf.buffer).toString("base64");
if (typeof node_buffer.Buffer === "function") {
str = buf instanceof node_buffer.Buffer ? buf.toString("base64") : node_buffer.Buffer.from(buf.buffer).toString("base64");
} else if (typeof btoa === "function") {
let s = "";
for (let i = 0; i < buf.length; ++i)
@@ -3065,7 +3107,7 @@ var require_timestamp = __commonJS({
}
return new Date(date);
},
stringify: ({ value }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, "")
stringify: ({ value }) => value.toISOString().replace(/(T00:00:00)?\.000Z$/, "")
};
exports2.floatTime = floatTime;
exports2.intTime = intTime;
@@ -3085,6 +3127,7 @@ var require_schema3 = __commonJS({
var bool = require_bool2();
var float = require_float2();
var int = require_int2();
var merge = require_merge();
var omap = require_omap();
var pairs = require_pairs();
var set = require_set();
@@ -3104,6 +3147,7 @@ var require_schema3 = __commonJS({
float.floatExp,
float.float,
binary.binary,
merge.merge,
omap.omap,
pairs.pairs,
set.set,
@@ -3129,6 +3173,7 @@ var require_tags = __commonJS({
var schema = require_schema();
var schema$1 = require_schema2();
var binary = require_binary();
var merge = require_merge();
var omap = require_omap();
var pairs = require_pairs();
var schema$2 = require_schema3();
@@ -3153,6 +3198,7 @@ var require_tags = __commonJS({
intOct: int.intOct,
intTime: timestamp.intTime,
map: map.map,
merge: merge.merge,
null: _null.nullTag,
omap: omap.omap,
pairs: pairs.pairs,
@@ -3162,13 +3208,18 @@ var require_tags = __commonJS({
};
var coreKnownTags = {
"tag:yaml.org,2002:binary": binary.binary,
"tag:yaml.org,2002:merge": merge.merge,
"tag:yaml.org,2002:omap": omap.omap,
"tag:yaml.org,2002:pairs": pairs.pairs,
"tag:yaml.org,2002:set": set.set,
"tag:yaml.org,2002:timestamp": timestamp.timestamp
};
function getTags(customTags, schemaName) {
let tags = schemas.get(schemaName);
function getTags(customTags, schemaName, addMergeTag) {
const schemaTags = schemas.get(schemaName);
if (schemaTags && !customTags) {
return addMergeTag && !schemaTags.includes(merge.merge) ? schemaTags.concat(merge.merge) : schemaTags.slice();
}
let tags = schemaTags;
if (!tags) {
if (Array.isArray(customTags))
tags = [];
@@ -3183,15 +3234,19 @@ var require_tags = __commonJS({
} else if (typeof customTags === "function") {
tags = customTags(tags.slice());
}
return tags.map((tag) => {
if (typeof tag !== "string")
return tag;
const tagObj = tagsByName[tag];
if (tagObj)
return tagObj;
const keys = Object.keys(tagsByName).map((key) => JSON.stringify(key)).join(", ");
throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
});
if (addMergeTag)
tags = tags.concat(merge.merge);
return tags.reduce((tags2, tag) => {
const tagObj = typeof tag === "string" ? tagsByName[tag] : tag;
if (!tagObj) {
const tagName = JSON.stringify(tag);
const keys = Object.keys(tagsByName).map((key) => JSON.stringify(key)).join(", ");
throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
}
if (!tags2.includes(tagObj))
tags2.push(tagObj);
return tags2;
}, []);
}
exports2.coreKnownTags = coreKnownTags;
exports2.getTags = getTags;
@@ -3211,10 +3266,9 @@ var require_Schema = __commonJS({
var Schema = class _Schema {
constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
this.compat = Array.isArray(compat) ? tags.getTags(compat, "compat") : compat ? tags.getTags(null, compat) : null;
this.merge = !!merge;
this.name = typeof schema === "string" && schema || "core";
this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
this.tags = tags.getTags(customTags, this.name);
this.tags = tags.getTags(customTags, this.name, merge);
this.toStringOptions = toStringDefaults ?? null;
Object.defineProperty(this, identity.MAP, { value: map.map });
Object.defineProperty(this, identity.SCALAR, { value: string.string });
@@ -3346,6 +3400,7 @@ var require_Document = __commonJS({
logLevel: "warn",
prettyErrors: true,
strict: true,
stringKeys: false,
uniqueKeys: true,
version: "1.2"
}, options);
@@ -3547,7 +3602,7 @@ var require_Document = __commonJS({
this.directives.yaml.version = "1.1";
else
this.directives = new directives.Directives({ version: "1.1" });
opt = { merge: true, resolveKnownTags: false, schema: "yaml-1.1" };
opt = { resolveKnownTags: false, schema: "yaml-1.1" };
break;
case "1.2":
case "next":
@@ -3555,7 +3610,7 @@ var require_Document = __commonJS({
this.directives.yaml.version = version;
else
this.directives = new directives.Directives({ version });
opt = { merge: false, resolveKnownTags: true, schema: "core" };
opt = { resolveKnownTags: true, schema: "core" };
break;
case null:
if (this.directives)
@@ -3738,7 +3793,7 @@ var require_resolve_props = __commonJS({
if (atNewline) {
if (comment)
comment += token.source;
else
else if (!found || indicator !== "seq-item-ind")
spaceBefore = true;
} else
commentSep += token.source;
@@ -3888,7 +3943,7 @@ var require_util_map_includes = __commonJS({
const { uniqueKeys } = ctx.options;
if (uniqueKeys === false)
return false;
const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value && !(a.value === "<<" && ctx.schema.merge);
const isEqual = typeof uniqueKeys === "function" ? uniqueKeys : (a, b) => a === b || identity.isScalar(a) && identity.isScalar(b) && a.value === b.value;
return items.some((pair) => isEqual(pair.key, search));
}
exports2.mapIncludes = mapIncludes;
@@ -3947,10 +4002,12 @@ var require_resolve_block_map = __commonJS({
} else if (keyProps.found?.indent !== bm.indent) {
onError(offset, "BAD_INDENT", startColMsg);
}
ctx.atKey = true;
const keyStart = keyProps.end;
const keyNode = key ? composeNode(ctx, key, keyProps, onError) : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
if (ctx.schema.compat)
utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
ctx.atKey = false;
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
const valueProps = resolveProps.resolveProps(sep ?? [], {
@@ -4013,6 +4070,8 @@ var require_resolve_block_seq = __commonJS({
const seq = new NodeClass(ctx.schema);
if (ctx.atRoot)
ctx.atRoot = false;
if (ctx.atKey)
ctx.atKey = false;
let offset = bs.offset;
let commentEnd = null;
for (const { start, value } of bs.items) {
@@ -4116,6 +4175,8 @@ var require_resolve_flow_collection = __commonJS({
const atRoot = ctx.atRoot;
if (atRoot)
ctx.atRoot = false;
if (ctx.atKey)
ctx.atKey = false;
let offset = fc.offset + fc.start.source.length;
for (let i = 0; i < fc.items.length; ++i) {
const collItem = fc.items[i];
@@ -4191,10 +4252,12 @@ var require_resolve_flow_collection = __commonJS({
if (isBlock(value))
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
} else {
ctx.atKey = true;
const keyStart = props.end;
const keyNode = key ? composeNode(ctx, key, props, onError) : composeEmptyNode(ctx, keyStart, start, null, props, onError);
if (isBlock(key))
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
ctx.atKey = false;
const valueProps = resolveProps.resolveProps(sep ?? [], {
flow: fcName,
indicator: "map-value-ind",
@@ -4757,7 +4820,15 @@ var require_compose_scalar = __commonJS({
function composeScalar(ctx, token, tagToken, onError) {
const { value, type, comment, range } = token.type === "block-scalar" ? resolveBlockScalar.resolveBlockScalar(ctx, token, onError) : resolveFlowScalar.resolveFlowScalar(token, ctx.options.strict, onError);
const tagName = tagToken ? ctx.directives.tagName(tagToken.source, (msg) => onError(tagToken, "TAG_RESOLVE_FAILED", msg)) : null;
const tag = tagToken && tagName ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError) : token.type === "scalar" ? findScalarTagByTest(ctx, value, token, onError) : ctx.schema[identity.SCALAR];
let tag;
if (ctx.options.stringKeys && ctx.atKey) {
tag = ctx.schema[identity.SCALAR];
} else if (tagName)
tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
else if (token.type === "scalar")
tag = findScalarTagByTest(ctx, value, token, onError);
else
tag = ctx.schema[identity.SCALAR];
let scalar;
try {
const res = tag.resolve(value, (msg) => onError(tagToken ?? token, "TAG_RESOLVE_FAILED", msg), ctx.options);
@@ -4802,8 +4873,8 @@ var require_compose_scalar = __commonJS({
onError(tagToken, "TAG_RESOLVE_FAILED", `Unresolved tag: ${tagName}`, tagName !== "tag:yaml.org,2002:str");
return schema[identity.SCALAR];
}
function findScalarTagByTest({ directives, schema }, value, token, onError) {
const tag = schema.tags.find((tag2) => tag2.default && tag2.test?.test(value)) || schema[identity.SCALAR];
function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
const tag = schema.tags.find((tag2) => (tag2.default === true || atKey && tag2.default === "key") && tag2.test?.test(value)) || schema[identity.SCALAR];
if (schema.compat) {
const compat = schema.compat.find((tag2) => tag2.default && tag2.test?.test(value)) ?? schema[identity.SCALAR];
if (tag.tag !== compat.tag) {
@@ -4855,12 +4926,14 @@ var require_compose_node = __commonJS({
"../../node_modules/yaml/dist/compose/compose-node.js"(exports2) {
"use strict";
var Alias = require_Alias();
var identity = require_identity();
var composeCollection = require_compose_collection();
var composeScalar = require_compose_scalar();
var resolveEnd = require_resolve_end();
var utilEmptyScalarPosition = require_util_empty_scalar_position();
var CN = { composeNode, composeEmptyNode };
function composeNode(ctx, token, props, onError) {
const atKey = ctx.atKey;
const { spaceBefore, comment, anchor, tag } = props;
let node;
let isSrcToken = true;
@@ -4894,6 +4967,10 @@ var require_compose_node = __commonJS({
}
if (anchor && node.anchor === "")
onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
if (atKey && ctx.options.stringKeys && (!identity.isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
const msg = "With stringKeys, all keys must be strings";
onError(tag ?? token, "NON_STRING_KEY", msg);
}
if (spaceBefore)
node.spaceBefore = true;
if (comment) {
@@ -4957,6 +5034,7 @@ var require_compose_doc = __commonJS({
const opts = Object.assign({ _directives: directives }, options);
const doc = new Document.Document(void 0, opts);
const ctx = {
atKey: false,
atRoot: true,
directives: doc.directives,
options: doc.options,
@@ -4991,6 +5069,7 @@ var require_compose_doc = __commonJS({
var require_composer = __commonJS({
"../../node_modules/yaml/dist/compose/composer.js"(exports2) {
"use strict";
var node_process = require("node:process");
var directives = require_directives();
var Document = require_Document();
var errors = require_errors();
@@ -5106,7 +5185,7 @@ ${cb}` : comment;
}
/** Advance the composer by one CST token. */
*next(token) {
if (process.env.LOG_STREAM)
if (node_process.env.LOG_STREAM)
console.dir(token, { depth: null });
switch (token.type) {
case "directive":
@@ -6211,6 +6290,7 @@ var require_line_counter = __commonJS({
var require_parser = __commonJS({
"../../node_modules/yaml/dist/parse/parser.js"(exports2) {
"use strict";
var node_process = require("node:process");
var cst = require_cst();
var lexer = require_lexer();
function includesToken(list, type) {
@@ -6333,7 +6413,7 @@ var require_parser = __commonJS({
*/
*next(source) {
this.source = source;
if (process.env.LOG_TOKENS)
if (node_process.env.LOG_TOKENS)
console.log("|", cst.prettyToken(source));
if (this.atScalar) {
this.atScalar = false;
@@ -7067,6 +7147,7 @@ var require_public_api = __commonJS({
var Document = require_Document();
var errors = require_errors();
var log = require_log();
var identity = require_identity();
var lineCounter = require_line_counter();
var parser = require_parser();
function parseOptions(options) {
@@ -7144,6 +7225,8 @@ var require_public_api = __commonJS({
if (!keepUndefined)
return void 0;
}
if (identity.isDocument(value) && !_replacer)
return value.toString(options);
return new Document.Document(value, _replacer, options).toString(options);
}
exports2.parse = parse;