From 9fe12b4eb9c6fd8634ed32936f36aac3aa298a23 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 2 Dec 2024 05:04:33 +0000 Subject: [PATCH] build(release): compile new build 2.6.5 [skip ci] --- dist/index.js | 255 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 166 insertions(+), 89 deletions(-) diff --git a/dist/index.js b/dist/index.js index daef615..2e94854 100644 --- a/dist/index.js +++ b/dist/index.js @@ -26626,7 +26626,7 @@ function removeUndefinedProperties(obj) { return obj; } -function merge(defaults, route, options) { +function merge$1(defaults, route, options) { if (typeof route === "string") { let [method, url] = route.split(" "); options = Object.assign(url ? { method, url } : { url: method }, options); @@ -26880,16 +26880,16 @@ function parse$4(options) { } function endpointWithDefaults(defaults, route, options) { - return parse$4(merge(defaults, route, options)); + return parse$4(merge$1(defaults, route, options)); } function withDefaults$2(oldDefaults, newDefaults) { - const DEFAULTS = merge(oldDefaults, newDefaults); + const DEFAULTS = merge$1(oldDefaults, newDefaults); const endpoint = endpointWithDefaults.bind(null, DEFAULTS); return Object.assign(endpoint, { DEFAULTS, defaults: withDefaults$2.bind(null, DEFAULTS), - merge: merge.bind(null, DEFAULTS), + merge: merge$1.bind(null, DEFAULTS), parse: parse$4 }); } @@ -31612,23 +31612,32 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) { start = start.replace(/\n+/g, `$&${indent}`); } const indentSize = indent ? '2' : '1'; // root is at -1 - let header = (literal ? '|' : '>') + (startWithSpace ? indentSize : '') + chomp; + // Leading | or > is added later + 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}\n${indent}${start}${value}${end}`; + if (!literal) { + const foldedValue = value + .replace(/\n+/g, '\n$&') + .replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded + // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent + .replace(/\n+/g, `$&${indent}`); + let literalFallback = false; + const foldOptions = getFoldOptions(ctx, true); + if (blockQuote !== 'folded' && type !== Scalar_1$1.Scalar.BLOCK_FOLDED) { + foldOptions.onOverflow = () => { + literalFallback = true; + }; + } + const body = foldFlowLines_1.foldFlowLines(`${start}${foldedValue}${end}`, indent, foldFlowLines_1.FOLD_BLOCK, foldOptions); + if (!literalFallback) + return `>${header}\n${indent}${body}`; } - value = value - .replace(/\n+/g, '\n$&') - .replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded - // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent - .replace(/\n+/g, `$&${indent}`); - const body = foldFlowLines_1.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines_1.FOLD_BLOCK, getFoldOptions(ctx, true)); - return `${header}\n${indent}${body}`; + value = value.replace(/\n+/g, `$&${indent}`); + return `|${header}\n${indent}${start}${value}${end}`; } function plainString(item, ctx, onComment, onChompKeep) { const { type, value } = item; @@ -31775,7 +31784,12 @@ function getTagObject(tags, item) { 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); } @@ -32021,47 +32035,6 @@ var log = { warn: warn_1 }; -const 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_1.toJS(key, '', ctx); - if (map instanceof Map) { - map.set(jsKey, toJS_1.toJS(value, jsKey, ctx)); - } - else if (map instanceof Set) { - map.add(jsKey); - } - else { - const stringKey = stringifyKey(key, jsKey, ctx); - const jsValue = toJS_1.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; -} -const isMergeKey = (key) => key === MERGE_KEY || - (identity.isScalar(key) && - key.value === MERGE_KEY && - (!key.type || key.type === Scalar_1$1.Scalar.PLAIN)); // If the value associated with a merge key is a single mapping node, each of // its key/value pairs is inserted into the current mapping, unless the key // already exists in it. If the value associated with the merge key is a @@ -32069,7 +32042,35 @@ const isMergeKey = (key) => key === MERGE_KEY || // of these nodes is merged in turn according to its order in the sequence. // Keys in mapping nodes earlier in the sequence override keys specified in // later mapping nodes. -- http://yaml.org/type/merge.html -function mergeToJSMap(ctx, map, value) { +const MERGE_KEY = '<<'; +const 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_1$1.Scalar(Symbol(MERGE_KEY)), { + addToJSMap: addMergeToJSMap + }), + stringify: () => MERGE_KEY +}; +const isMergeKey = (ctx, key) => (merge.identify(key) || + (identity.isScalar(key) && + (!key.type || key.type === Scalar_1$1.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); +} +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'); @@ -32093,6 +32094,47 @@ function mergeToJSMap(ctx, map, value) { } return map; } + +var addMergeToJSMap_1 = addMergeToJSMap; +var isMergeKey_1 = isMergeKey; +var merge_2 = merge; + +var merge_1 = { + addMergeToJSMap: addMergeToJSMap_1, + isMergeKey: isMergeKey_1, + merge: merge_2 +}; + +function addPairToJSMap(ctx, map, { key, value }) { + if (identity.isNode(key) && key.addToJSMap) + key.addToJSMap(ctx, map, value); + // TODO: Should drop this special case for bare << handling + else if (merge_1.isMergeKey(ctx, key)) + merge_1.addMergeToJSMap(ctx, map, value); + else { + const jsKey = toJS_1.toJS(key, '', ctx); + if (map instanceof Map) { + map.set(jsKey, toJS_1.toJS(value, jsKey, ctx)); + } + else if (map instanceof Set) { + map.add(jsKey); + } + else { + const stringKey = stringifyKey(key, jsKey, ctx); + const jsValue = toJS_1.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 ''; @@ -32824,7 +32866,7 @@ const jsonScalars = [ 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 }, @@ -33441,7 +33483,7 @@ const timestamp = { } return new Date(date); }, - stringify: ({ value }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '') + stringify: ({ value }) => value.toISOString().replace(/(T00:00:00)?\.000Z$/, '') }; var floatTime_1 = floatTime; @@ -33469,6 +33511,7 @@ const schema = [ float_1.floatExp, float_1.float, binary_1.binary, + merge_1.merge, omap_1.omap, pairs_1.pairs, set_1.set, @@ -33502,6 +33545,7 @@ const tagsByName = { intOct: int_1$1.intOct, intTime: timestamp_1.intTime, map: map_1.map, + merge: merge_1.merge, null: _null.nullTag, omap: omap_1.omap, pairs: pairs_1.pairs, @@ -33511,13 +33555,20 @@ const tagsByName = { }; const coreKnownTags = { 'tag:yaml.org,2002:binary': binary_1.binary, + 'tag:yaml.org,2002:merge': merge_1.merge, 'tag:yaml.org,2002:omap': omap_1.omap, 'tag:yaml.org,2002:pairs': pairs_1.pairs, 'tag:yaml.org,2002:set': set_1.set, 'tag:yaml.org,2002:timestamp': timestamp_1.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_1.merge) + ? schemaTags.concat(merge_1.merge) + : schemaTags.slice(); + } + let tags = schemaTags; if (!tags) { if (Array.isArray(customTags)) tags = []; @@ -33536,17 +33587,21 @@ function getTags(customTags, schemaName) { 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_1.merge); + return tags.reduce((tags, 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 (!tags.includes(tagObj)) + tags.push(tagObj); + return tags; + }, []); } var coreKnownTags_1 = coreKnownTags; @@ -33565,10 +33620,9 @@ class Schema { : 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_1.map }); Object.defineProperty(this, identity.SCALAR, { value: string_1.string }); @@ -33705,6 +33759,7 @@ class Document { logLevel: 'warn', prettyErrors: true, strict: true, + stringKeys: false, uniqueKeys: true, version: '1.2' }, options); @@ -33928,7 +33983,7 @@ class Document { 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': @@ -33936,7 +33991,7 @@ class Document { 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) @@ -34291,11 +34346,7 @@ function mapIncludes(ctx, items, search) { 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)); + : (a, b) => a === b || (identity.isScalar(a) && identity.isScalar(b) && a.value === b.value); return items.some(pair => isEqual(pair.key, search)); } @@ -34350,12 +34401,14 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta onError(offset, 'BAD_INDENT', startColMsg); } // key value + 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'); // value properties @@ -34421,6 +34474,8 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta 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) { @@ -34517,6 +34572,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr 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]; @@ -34596,12 +34653,14 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr else { // item is a key+value pair // key value + 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; // value properties const valueProps = resolveProps_1.resolveProps(sep ?? [], { flow: fcName, @@ -35223,11 +35282,16 @@ function composeScalar(ctx, token, tagToken, 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); @@ -35275,8 +35339,9 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) { 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(tag => tag.default && tag.test?.test(value)) || schema[identity.SCALAR]; +function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) { + const tag = schema.tags.find(tag => (tag.default === true || (atKey && tag.default === 'key')) && + tag.test?.test(value)) || schema[identity.SCALAR]; if (schema.compat) { const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ?? schema[identity.SCALAR]; @@ -35330,6 +35395,7 @@ var utilEmptyScalarPosition = { const CN = { composeNode, composeEmptyNode }; function composeNode(ctx, token, props, onError) { + const atKey = ctx.atKey; const { spaceBefore, comment, anchor, tag } = props; let node; let isSrcToken = true; @@ -35365,6 +35431,14 @@ function composeNode(ctx, token, props, onError) { } 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) { @@ -35425,6 +35499,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError) const opts = Object.assign({ _directives: directives }, options); const doc = new Document_1$1.Document(undefined, opts); const ctx = { + atKey: false, atRoot: true, directives: doc.directives, options: doc.options, @@ -37999,6 +38074,8 @@ function stringify$3(value, replacer, options) { if (!keepUndefined) return undefined; } + if (identity.isDocument(value) && !_replacer) + return value.toString(options); return new Document_1$1.Document(value, _replacer, options).toString(options); }