@cdklabs/cdk-cicd-wrapper 0.3.1 → 0.3.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.
Files changed (94) hide show
  1. package/.jsii +5 -5
  2. package/lib/code-pipeline/AppStage.js +1 -1
  3. package/lib/code-pipeline/CDKPipeline.js +1 -1
  4. package/lib/code-pipeline/PostDeployBuildStep.js +1 -1
  5. package/lib/code-pipeline/PreDeployBuildStep.js +1 -1
  6. package/lib/common/spi/ResourceContext.js +1 -1
  7. package/lib/common/types/BaseStackProvider.js +1 -1
  8. package/lib/common/types/DefaultStackProvider.js +1 -1
  9. package/lib/common/types/Types.js +2 -2
  10. package/lib/constructs/CodeCommitRepositoryConstruct.js +1 -1
  11. package/lib/constructs/CodeStarConnectionConstruct.js +1 -1
  12. package/lib/plugins/index.js +1 -1
  13. package/lib/plugins/optimization/DestroyEncryptionKeysOnDeletePlugin.js +1 -1
  14. package/lib/plugins/pipeline/GitHubPipelinePlugin.js +1 -1
  15. package/lib/plugins/security/AccessLogsForBucketPlugin.js +1 -1
  16. package/lib/plugins/security/DisablePublicIPAssignmentForEC2Plugin.js +1 -1
  17. package/lib/plugins/security/EncryptBucketOnTransitPlugin.js +1 -1
  18. package/lib/plugins/security/EncryptCloudWatchLogGroupsPlugin.js +1 -1
  19. package/lib/plugins/security/EncryptSNSTopicOnTransitPlugin.js +1 -1
  20. package/lib/plugins/security/LambdaDLQPlugin.js +1 -1
  21. package/lib/plugins/security/RotateEncryptionKeysPlugin.js +1 -1
  22. package/lib/plugins/utils/CodeArtifactPlugin.js +1 -1
  23. package/lib/resource-providers/CIDefinitionProvider.js +2 -2
  24. package/lib/resource-providers/CodeBuildFactoryProvider.js +5 -5
  25. package/lib/resource-providers/ComplianceBucketProvider.js +1 -1
  26. package/lib/resource-providers/EncryptionProvider.js +1 -1
  27. package/lib/resource-providers/HooksProvider.js +2 -2
  28. package/lib/resource-providers/LoggingProvider.js +1 -1
  29. package/lib/resource-providers/ParameterProvider.js +1 -1
  30. package/lib/resource-providers/PhaseCommandProvider.js +6 -6
  31. package/lib/resource-providers/ProxyProvider.js +1 -1
  32. package/lib/resource-providers/RepositoryProvider.js +5 -5
  33. package/lib/resource-providers/StageProvider.js +1 -1
  34. package/lib/resource-providers/VPCProvider.js +1 -1
  35. package/lib/stacks/CodeStarConnectRepositoryStack.js +1 -1
  36. package/lib/stacks/EncryptionStack.js +1 -1
  37. package/lib/stacks/PipelineBlueprint.js +2 -2
  38. package/lib/stacks/PostDeployExecutorStack.js +1 -1
  39. package/lib/stacks/SSMParameterStack.js +1 -1
  40. package/lib/stacks/compliance-bucket/ComplianceBucketStack.js +1 -1
  41. package/lib/stacks/vpc/ManagedVPCStack.js +1 -1
  42. package/lib/stacks/vpc/NoVPCStack.js +1 -1
  43. package/lib/stacks/vpc/VPCFromLookUpStack.js +1 -1
  44. package/lib/utils/ParameterResolver.js +1 -1
  45. package/node_modules/yaml/README.md +2 -20
  46. package/node_modules/yaml/browser/dist/compose/compose-collection.js +1 -1
  47. package/node_modules/yaml/browser/dist/compose/compose-node.js +11 -4
  48. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +1 -1
  49. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +2 -2
  50. package/node_modules/yaml/browser/dist/compose/resolve-props.js +2 -4
  51. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +1 -2
  52. package/node_modules/yaml/browser/dist/doc/anchors.js +1 -2
  53. package/node_modules/yaml/browser/dist/doc/createNode.js +1 -2
  54. package/node_modules/yaml/browser/dist/errors.js +1 -1
  55. package/node_modules/yaml/browser/dist/nodes/Alias.js +25 -12
  56. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +1 -1
  57. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +1 -0
  58. package/node_modules/yaml/browser/dist/parse/parser.js +2 -2
  59. package/node_modules/yaml/browser/dist/schema/tags.js +3 -3
  60. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +1 -2
  61. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +1 -1
  62. package/node_modules/yaml/browser/dist/stringify/stringify.js +4 -4
  63. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +13 -3
  64. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +1 -1
  65. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +1 -1
  66. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +4 -5
  67. package/node_modules/yaml/dist/cli.d.ts +1 -1
  68. package/node_modules/yaml/dist/cli.mjs +5 -3
  69. package/node_modules/yaml/dist/compose/compose-collection.js +1 -1
  70. package/node_modules/yaml/dist/compose/compose-node.js +11 -4
  71. package/node_modules/yaml/dist/compose/composer.js +1 -1
  72. package/node_modules/yaml/dist/compose/resolve-block-seq.js +1 -1
  73. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +2 -2
  74. package/node_modules/yaml/dist/compose/resolve-props.js +2 -4
  75. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +1 -2
  76. package/node_modules/yaml/dist/doc/anchors.js +1 -2
  77. package/node_modules/yaml/dist/doc/createNode.js +1 -2
  78. package/node_modules/yaml/dist/errors.d.ts +1 -1
  79. package/node_modules/yaml/dist/errors.js +1 -1
  80. package/node_modules/yaml/dist/log.js +1 -1
  81. package/node_modules/yaml/dist/nodes/Alias.d.ts +1 -1
  82. package/node_modules/yaml/dist/nodes/Alias.js +24 -11
  83. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +1 -0
  84. package/node_modules/yaml/dist/nodes/toJS.d.ts +2 -0
  85. package/node_modules/yaml/dist/options.d.ts +6 -0
  86. package/node_modules/yaml/dist/parse/parser.js +3 -3
  87. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +2 -3
  88. package/node_modules/yaml/dist/stringify/stringify.js +4 -4
  89. package/node_modules/yaml/dist/stringify/stringifyCollection.js +13 -3
  90. package/node_modules/yaml/dist/stringify/stringifyNumber.js +1 -1
  91. package/node_modules/yaml/dist/stringify/stringifyPair.js +1 -1
  92. package/node_modules/yaml/dist/stringify/stringifyString.js +3 -4
  93. package/node_modules/yaml/package.json +6 -5
  94. package/package.json +16 -16
@@ -102,12 +102,22 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
102
102
  if (comment)
103
103
  reqNewline = true;
104
104
  let str = stringify(item, itemCtx, () => (comment = null));
105
- if (i < items.length - 1)
105
+ reqNewline || (reqNewline = lines.length > linesAtValue || str.includes('\n'));
106
+ if (i < items.length - 1) {
106
107
  str += ',';
108
+ }
109
+ else if (ctx.options.trailingComma) {
110
+ if (ctx.options.lineWidth > 0) {
111
+ reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) +
112
+ (str.length + 2) >
113
+ ctx.options.lineWidth);
114
+ }
115
+ if (reqNewline) {
116
+ str += ',';
117
+ }
118
+ }
107
119
  if (comment)
108
120
  str += lineComment(str, itemIndent, commentString(comment));
109
- if (!reqNewline && (lines.length > linesAtValue || str.includes('\n')))
110
- reqNewline = true;
111
121
  lines.push(str);
112
122
  linesAtValue = lines.length;
113
123
  }
@@ -4,7 +4,7 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
4
4
  const num = typeof value === 'number' ? value : Number(value);
5
5
  if (!isFinite(num))
6
6
  return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';
7
- let n = JSON.stringify(value);
7
+ let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);
8
8
  if (!format &&
9
9
  minFractionDigits &&
10
10
  (!tag || tag === 'tag:yaml.org,2002:float') &&
@@ -101,7 +101,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
101
101
  ws += `\n${indentComment(cs, ctx.indent)}`;
102
102
  }
103
103
  if (valueStr === '' && !ctx.inFlow) {
104
- if (ws === '\n')
104
+ if (ws === '\n' && valueComment)
105
105
  ws = '\n\n';
106
106
  }
107
107
  else {
@@ -1,5 +1,5 @@
1
1
  import { Scalar } from '../nodes/Scalar.js';
2
- import { foldFlowLines, FOLD_QUOTED, FOLD_FLOW, FOLD_BLOCK } from './foldFlowLines.js';
2
+ import { foldFlowLines, FOLD_FLOW, FOLD_QUOTED, FOLD_BLOCK } from './foldFlowLines.js';
3
3
 
4
4
  const getFoldOptions = (ctx, isBlock) => ({
5
5
  indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
@@ -159,7 +159,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
159
159
  const { blockQuote, commentString, lineWidth } = ctx.options;
160
160
  // 1. Block can't end in whitespace unless the last line is non-empty.
161
161
  // 2. Strings consisting of only whitespace are best rendered explicitly.
162
- if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
162
+ if (!blockQuote || /\n[\t ]+$/.test(value)) {
163
163
  return quotedString(value, ctx);
164
164
  }
165
165
  const indent = ctx.indent ||
@@ -253,10 +253,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
253
253
  (inFlow && /[[\]{},]/.test(value))) {
254
254
  return quotedString(value, ctx);
255
255
  }
256
- if (!value ||
257
- /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
256
+ if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
258
257
  // not allowed:
259
- // - empty string, '-' or '?'
258
+ // - '-' or '?'
260
259
  // - start with an indicator character (except [?:-]) or /[?-] /
261
260
  // - '\n ', ': ' or ' \n' anywhere
262
261
  // - '#' not preceded by a non-space char
@@ -1,4 +1,4 @@
1
- export declare const help = "yaml: A command-line YAML processor and inspector\n\nReads stdin and writes output to stdout and errors & warnings to stderr.\n\nUsage:\n yaml Process a YAML stream, outputting it as YAML\n yaml cst Parse the CST of a YAML stream\n yaml lex Parse the lexical tokens of a YAML stream\n yaml valid Validate a YAML stream, returning 0 on success\n\nOptions:\n --help, -h Show this message.\n --json, -j Output JSON.\n --indent 2 Output pretty-printed data, indented by the given number of spaces.\n\nAdditional options for bare \"yaml\" command:\n --doc, -d Output pretty-printed JS Document objects.\n --single, -1 Require the input to consist of a single YAML document.\n --strict, -s Stop on errors.\n --visit, -v Apply a visitor to each document (requires a path to import)\n --yaml 1.1 Set the YAML version. (default: 1.2)";
1
+ export declare const help = "yaml: A command-line YAML processor and inspector\n\nReads stdin and writes output to stdout and errors & warnings to stderr.\n\nUsage:\n yaml Process a YAML stream, outputting it as YAML\n yaml cst Parse the CST of a YAML stream\n yaml lex Parse the lexical tokens of a YAML stream\n yaml valid Validate a YAML stream, returning 0 on success\n\nOptions:\n --help, -h Show this message.\n --json, -j Output JSON.\n --indent 2 Output pretty-printed data, indented by the given number of spaces.\n --merge, -m Enable support for \"<<\" merge keys.\n\nAdditional options for bare \"yaml\" command:\n --doc, -d Output pretty-printed JS Document objects.\n --single, -1 Require the input to consist of a single YAML document.\n --strict, -s Stop on errors.\n --visit, -v Apply a visitor to each document (requires a path to import)\n --yaml 1.1 Set the YAML version. (default: 1.2)";
2
2
  export declare class UserError extends Error {
3
3
  static ARGS: number;
4
4
  static SINGLE: number;
@@ -1,5 +1,5 @@
1
- import { resolve } from 'node:path';
2
- import { parseArgs } from 'node:util';
1
+ import { resolve } from 'path';
2
+ import { parseArgs } from 'util';
3
3
  import { prettyToken } from './parse/cst.js';
4
4
  import { Lexer } from './parse/lexer.js';
5
5
  import { Parser } from './parse/parser.js';
@@ -23,6 +23,7 @@ Options:
23
23
  --help, -h Show this message.
24
24
  --json, -j Output JSON.
25
25
  --indent 2 Output pretty-printed data, indented by the given number of spaces.
26
+ --merge, -m Enable support for "<<" merge keys.
26
27
 
27
28
  Additional options for bare "yaml" command:
28
29
  --doc, -d Output pretty-printed JS Document objects.
@@ -48,6 +49,7 @@ async function cli(stdin, done, argv) {
48
49
  doc: { type: 'boolean', short: 'd' },
49
50
  help: { type: 'boolean', short: 'h' },
50
51
  indent: { type: 'string', short: 'i' },
52
+ merge: { type: 'boolean', short: 'm' },
51
53
  json: { type: 'boolean', short: 'j' },
52
54
  single: { type: 'boolean', short: '1' },
53
55
  strict: { type: 'boolean', short: 's' },
@@ -117,7 +119,7 @@ async function cli(stdin, done, argv) {
117
119
  const lineCounter = new LineCounter();
118
120
  const parser = new Parser(lineCounter.addNewLine);
119
121
  // @ts-expect-error Version is validated at runtime
120
- const composer = new Composer({ version: opt.yaml });
122
+ const composer = new Composer({ version: opt.yaml, merge: opt.merge });
121
123
  const visitor = opt.visit
122
124
  ? (await import(resolve(opt.visit))).default
123
125
  : null;
@@ -61,7 +61,7 @@ function composeCollection(CN, ctx, token, props, onError) {
61
61
  let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
62
62
  if (!tag) {
63
63
  const kt = ctx.schema.knownTags[tagName];
64
- if (kt && kt.collection === expType) {
64
+ if (kt?.collection === expType) {
65
65
  ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
66
66
  tag = kt;
67
67
  }
@@ -30,19 +30,26 @@ function composeNode(ctx, token, props, onError) {
30
30
  case 'block-map':
31
31
  case 'block-seq':
32
32
  case 'flow-collection':
33
- node = composeCollection.composeCollection(CN, ctx, token, props, onError);
34
- if (anchor)
35
- node.anchor = anchor.source.substring(1);
33
+ try {
34
+ node = composeCollection.composeCollection(CN, ctx, token, props, onError);
35
+ if (anchor)
36
+ node.anchor = anchor.source.substring(1);
37
+ }
38
+ catch (error) {
39
+ // Almost certainly here due to a stack overflow
40
+ const message = error instanceof Error ? error.message : String(error);
41
+ onError(token, 'RESOURCE_EXHAUSTION', message);
42
+ }
36
43
  break;
37
44
  default: {
38
45
  const message = token.type === 'error'
39
46
  ? token.message
40
47
  : `Unsupported token (type: ${token.type})`;
41
48
  onError(token, 'UNEXPECTED_TOKEN', message);
42
- node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
43
49
  isSrcToken = false;
44
50
  }
45
51
  }
52
+ node ?? (node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError));
46
53
  if (anchor && node.anchor === '')
47
54
  onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
48
55
  if (atKey &&
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var node_process = require('node:process');
3
+ var node_process = require('process');
4
4
  var directives = require('../doc/directives.js');
5
5
  var Document = require('../doc/Document.js');
6
6
  var errors = require('../errors.js');
@@ -24,7 +24,7 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta
24
24
  });
25
25
  if (!props.found) {
26
26
  if (props.anchor || props.tag || value) {
27
- if (value && value.type === 'block-seq')
27
+ if (value?.type === 'block-seq')
28
28
  onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
29
29
  else
30
30
  onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
@@ -135,7 +135,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
135
135
  }
136
136
  }
137
137
  else if (value) {
138
- if ('source' in value && value.source && value.source[0] === ':')
138
+ if ('source' in value && value.source?.[0] === ':')
139
139
  onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
140
140
  else
141
141
  onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
@@ -179,7 +179,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
179
179
  const expectedEnd = isMap ? '}' : ']';
180
180
  const [ce, ...ee] = fc.end;
181
181
  let cePos = offset;
182
- if (ce && ce.source === expectedEnd)
182
+ if (ce?.source === expectedEnd)
183
183
  cePos = ce.offset + ce.source.length;
184
184
  else {
185
185
  const name = fcName[0].toUpperCase() + fcName.substring(1);
@@ -74,8 +74,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
74
74
  if (token.source.endsWith(':'))
75
75
  onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
76
76
  anchor = token;
77
- if (start === null)
78
- start = token.offset;
77
+ start ?? (start = token.offset);
79
78
  atNewline = false;
80
79
  hasSpace = false;
81
80
  reqSpace = true;
@@ -84,8 +83,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
84
83
  if (tag)
85
84
  onError(token, 'MULTIPLE_TAGS', 'A node can have at most one tag');
86
85
  tag = token;
87
- if (start === null)
88
- start = token.offset;
86
+ start ?? (start = token.offset);
89
87
  atNewline = false;
90
88
  hasSpace = false;
91
89
  reqSpace = true;
@@ -2,8 +2,7 @@
2
2
 
3
3
  function emptyScalarPosition(offset, before, pos) {
4
4
  if (before) {
5
- if (pos === null)
6
- pos = before.length;
5
+ pos ?? (pos = before.length);
7
6
  for (let i = pos - 1; i >= 0; --i) {
8
7
  let st = before[i];
9
8
  switch (st.type) {
@@ -41,8 +41,7 @@ function createNodeAnchors(doc, prefix) {
41
41
  return {
42
42
  onAnchor: (source) => {
43
43
  aliasObjects.push(source);
44
- if (!prevAnchors)
45
- prevAnchors = anchorNames(doc);
44
+ prevAnchors ?? (prevAnchors = anchorNames(doc));
46
45
  const anchor = findNewAnchor(prefix, prevAnchors);
47
46
  prevAnchors.add(anchor);
48
47
  return anchor;
@@ -40,8 +40,7 @@ function createNode(value, tagName, ctx) {
40
40
  if (aliasDuplicateObjects && value && typeof value === 'object') {
41
41
  ref = sourceObjects.get(value);
42
42
  if (ref) {
43
- if (!ref.anchor)
44
- ref.anchor = onAnchor(value);
43
+ ref.anchor ?? (ref.anchor = onAnchor(value));
45
44
  return new Alias.Alias(ref.anchor);
46
45
  }
47
46
  else {
@@ -1,5 +1,5 @@
1
1
  import type { LineCounter } from './parse/line-counter';
2
- export type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'NON_STRING_KEY' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
2
+ export type ErrorCode = 'ALIAS_PROPS' | 'BAD_ALIAS' | 'BAD_DIRECTIVE' | 'BAD_DQ_ESCAPE' | 'BAD_INDENT' | 'BAD_PROP_ORDER' | 'BAD_SCALAR_START' | 'BLOCK_AS_IMPLICIT_KEY' | 'BLOCK_IN_FLOW' | 'DUPLICATE_KEY' | 'IMPOSSIBLE' | 'KEY_OVER_1024_CHARS' | 'MISSING_CHAR' | 'MULTILINE_IMPLICIT_KEY' | 'MULTIPLE_ANCHORS' | 'MULTIPLE_DOCS' | 'MULTIPLE_TAGS' | 'NON_STRING_KEY' | 'RESOURCE_EXHAUSTION' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
3
3
  export type LinePos = {
4
4
  line: number;
5
5
  col: number;
@@ -48,7 +48,7 @@ const prettifyError = (src, lc) => (error) => {
48
48
  if (/[^ ]/.test(lineStr)) {
49
49
  let count = 1;
50
50
  const end = error.linePos[1];
51
- if (end && end.line === line && end.col > col) {
51
+ if (end?.line === line && end.col > col) {
52
52
  count = Math.max(1, Math.min(end.col - col, 80 - ci));
53
53
  }
54
54
  const pointer = ' '.repeat(ci) + '^'.repeat(count);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var node_process = require('node:process');
3
+ var node_process = require('process');
4
4
 
5
5
  function debug(logLevel, ...messages) {
6
6
  if (logLevel === 'debug')
@@ -23,7 +23,7 @@ export declare class Alias extends NodeBase {
23
23
  * Resolve the value of this alias within `doc`, finding the last
24
24
  * instance of the `source` anchor before this node.
25
25
  */
26
- resolve(doc: Document): Scalar | YAMLMap | YAMLSeq | undefined;
26
+ resolve(doc: Document, ctx?: ToJSContext): Scalar | YAMLMap | YAMLSeq | undefined;
27
27
  toJSON(_arg?: unknown, ctx?: ToJSContext): unknown;
28
28
  toString(ctx?: StringifyContext, _onComment?: () => void, _onChompKeep?: () => void): string;
29
29
  }
@@ -20,23 +20,36 @@ class Alias extends Node.NodeBase {
20
20
  * Resolve the value of this alias within `doc`, finding the last
21
21
  * instance of the `source` anchor before this node.
22
22
  */
23
- resolve(doc) {
23
+ resolve(doc, ctx) {
24
+ let nodes;
25
+ if (ctx?.aliasResolveCache) {
26
+ nodes = ctx.aliasResolveCache;
27
+ }
28
+ else {
29
+ nodes = [];
30
+ visit.visit(doc, {
31
+ Node: (_key, node) => {
32
+ if (identity.isAlias(node) || identity.hasAnchor(node))
33
+ nodes.push(node);
34
+ }
35
+ });
36
+ if (ctx)
37
+ ctx.aliasResolveCache = nodes;
38
+ }
24
39
  let found = undefined;
25
- visit.visit(doc, {
26
- Node: (_key, node) => {
27
- if (node === this)
28
- return visit.visit.BREAK;
29
- if (node.anchor === this.source)
30
- found = node;
31
- }
32
- });
40
+ for (const node of nodes) {
41
+ if (node === this)
42
+ break;
43
+ if (node.anchor === this.source)
44
+ found = node;
45
+ }
33
46
  return found;
34
47
  }
35
48
  toJSON(_arg, ctx) {
36
49
  if (!ctx)
37
50
  return { source: this.source };
38
51
  const { anchors, doc, maxAliasCount } = ctx;
39
- const source = this.resolve(doc);
52
+ const source = this.resolve(doc, ctx);
40
53
  if (!source) {
41
54
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
42
55
  throw new ReferenceError(msg);
@@ -48,7 +61,7 @@ class Alias extends Node.NodeBase {
48
61
  data = anchors.get(source);
49
62
  }
50
63
  /* istanbul ignore if */
51
- if (!data || data.res === undefined) {
64
+ if (data?.res === undefined) {
52
65
  const msg = 'This should not happen: Alias anchor was not resolved?';
53
66
  throw new ReferenceError(msg);
54
67
  }
@@ -39,6 +39,7 @@ function addPairToJSMap(ctx, map, { key, value }) {
39
39
  function stringifyKey(key, jsKey, ctx) {
40
40
  if (jsKey === null)
41
41
  return '';
42
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
42
43
  if (typeof jsKey !== 'object')
43
44
  return String(jsKey);
44
45
  if (identity.isNode(key) && ctx?.doc) {
@@ -7,6 +7,8 @@ export interface AnchorData {
7
7
  }
8
8
  export interface ToJSContext {
9
9
  anchors: Map<Node, AnchorData>;
10
+ /** Cached anchor and alias nodes in the order they occur in the document */
11
+ aliasResolveCache?: Node[];
10
12
  doc: Document<Node, boolean>;
11
13
  keep: boolean;
12
14
  mapAsMap: boolean;
@@ -326,6 +326,12 @@ export type ToStringOptions = {
326
326
  * Default: `null`
327
327
  */
328
328
  singleQuote?: boolean | null;
329
+ /**
330
+ * Add a trailing comma after the last entry in a flow map or flow sequence that's split across multiple lines.
331
+ *
332
+ * Default: `'false'`
333
+ */
334
+ trailingComma?: boolean;
329
335
  /**
330
336
  * String representation for `true`.
331
337
  * With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var node_process = require('node:process');
3
+ var node_process = require('process');
4
4
  var cst = require('./cst.js');
5
5
  var lexer = require('./lexer.js');
6
6
 
@@ -231,7 +231,7 @@ class Parser {
231
231
  }
232
232
  *step() {
233
233
  const top = this.peek(1);
234
- if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) {
234
+ if (this.type === 'doc-end' && top?.type !== 'doc-end') {
235
235
  while (this.stack.length > 0)
236
236
  yield* this.pop();
237
237
  this.stack.push({
@@ -763,7 +763,7 @@ class Parser {
763
763
  do {
764
764
  yield* this.pop();
765
765
  top = this.peek(1);
766
- } while (top && top.type === 'flow-collection');
766
+ } while (top?.type === 'flow-collection');
767
767
  }
768
768
  else if (fc.end.length === 0) {
769
769
  switch (this.type) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var node_buffer = require('node:buffer');
3
+ var node_buffer = require('buffer');
4
4
  var Scalar = require('../../nodes/Scalar.js');
5
5
  var stringifyString = require('../../stringify/stringifyString.js');
6
6
 
@@ -53,8 +53,7 @@ const binary = {
53
53
  else {
54
54
  throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
55
55
  }
56
- if (!type)
57
- type = Scalar.Scalar.BLOCK_LITERAL;
56
+ type ?? (type = Scalar.Scalar.BLOCK_LITERAL);
58
57
  if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
59
58
  const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
60
59
  const n = Math.ceil(str.length / lineWidth);
@@ -22,6 +22,7 @@ function createStringifyContext(doc, options) {
22
22
  nullStr: 'null',
23
23
  simpleKeys: false,
24
24
  singleQuote: null,
25
+ trailingComma: false,
25
26
  trueStr: 'true',
26
27
  verifyAliasOrder: true
27
28
  }, doc.schema.toStringOptions, options);
@@ -70,7 +71,7 @@ function getTagObject(tags, item) {
70
71
  tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
71
72
  }
72
73
  if (!tagObj) {
73
- const name = obj?.constructor?.name ?? typeof obj;
74
+ const name = obj?.constructor?.name ?? (obj === null ? 'null' : typeof obj);
74
75
  throw new Error(`Tag not resolved for ${name} value`);
75
76
  }
76
77
  return tagObj;
@@ -85,7 +86,7 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) {
85
86
  anchors$1.add(anchor);
86
87
  props.push(`&${anchor}`);
87
88
  }
88
- const tag = node.tag ? node.tag : tagObj.default ? null : tagObj.tag;
89
+ const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
89
90
  if (tag)
90
91
  props.push(doc.directives.tagString(tag));
91
92
  return props.join(' ');
@@ -111,8 +112,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
111
112
  const node = identity.isNode(item)
112
113
  ? item
113
114
  : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });
114
- if (!tagObj)
115
- tagObj = getTagObject(ctx.doc.schema.tags, node);
115
+ tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
116
116
  const props = stringifyProps(node, tagObj, ctx);
117
117
  if (props.length > 0)
118
118
  ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
@@ -104,12 +104,22 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
104
104
  if (comment)
105
105
  reqNewline = true;
106
106
  let str = stringify.stringify(item, itemCtx, () => (comment = null));
107
- if (i < items.length - 1)
107
+ reqNewline || (reqNewline = lines.length > linesAtValue || str.includes('\n'));
108
+ if (i < items.length - 1) {
108
109
  str += ',';
110
+ }
111
+ else if (ctx.options.trailingComma) {
112
+ if (ctx.options.lineWidth > 0) {
113
+ reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) +
114
+ (str.length + 2) >
115
+ ctx.options.lineWidth);
116
+ }
117
+ if (reqNewline) {
118
+ str += ',';
119
+ }
120
+ }
109
121
  if (comment)
110
122
  str += stringifyComment.lineComment(str, itemIndent, commentString(comment));
111
- if (!reqNewline && (lines.length > linesAtValue || str.includes('\n')))
112
- reqNewline = true;
113
123
  lines.push(str);
114
124
  linesAtValue = lines.length;
115
125
  }
@@ -6,7 +6,7 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
6
6
  const num = typeof value === 'number' ? value : Number(value);
7
7
  if (!isFinite(num))
8
8
  return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';
9
- let n = JSON.stringify(value);
9
+ let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);
10
10
  if (!format &&
11
11
  minFractionDigits &&
12
12
  (!tag || tag === 'tag:yaml.org,2002:float') &&
@@ -103,7 +103,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
103
103
  ws += `\n${stringifyComment.indentComment(cs, ctx.indent)}`;
104
104
  }
105
105
  if (valueStr === '' && !ctx.inFlow) {
106
- if (ws === '\n')
106
+ if (ws === '\n' && valueComment)
107
107
  ws = '\n\n';
108
108
  }
109
109
  else {
@@ -161,7 +161,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
161
161
  const { blockQuote, commentString, lineWidth } = ctx.options;
162
162
  // 1. Block can't end in whitespace unless the last line is non-empty.
163
163
  // 2. Strings consisting of only whitespace are best rendered explicitly.
164
- if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
164
+ if (!blockQuote || /\n[\t ]+$/.test(value)) {
165
165
  return quotedString(value, ctx);
166
166
  }
167
167
  const indent = ctx.indent ||
@@ -255,10 +255,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
255
255
  (inFlow && /[[\]{},]/.test(value))) {
256
256
  return quotedString(value, ctx);
257
257
  }
258
- if (!value ||
259
- /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
258
+ if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
260
259
  // not allowed:
261
- // - empty string, '-' or '?'
260
+ // - '-' or '?'
262
261
  // - start with an indicator character (except [?:-]) or /[?-] /
263
262
  // - '\n ', ': ' or ' \n' anywhere
264
263
  // - '#' not preceded by a non-space char
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.7.1",
3
+ "version": "2.8.3",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
+ "funding": "https://github.com/sponsors/eemeli",
6
7
  "repository": "github:eemeli/yaml",
7
8
  "description": "JavaScript parser and stringifier for YAML",
8
9
  "keywords": [
@@ -73,16 +74,16 @@
73
74
  "@babel/preset-env": "^7.12.11",
74
75
  "@eslint/js": "^9.9.1",
75
76
  "@rollup/plugin-babel": "^6.0.3",
76
- "@rollup/plugin-replace": "^5.0.2",
77
+ "@rollup/plugin-replace": "^6.0.3",
77
78
  "@rollup/plugin-typescript": "^12.1.1",
78
79
  "@types/jest": "^29.2.4",
79
80
  "@types/node": "^20.11.20",
80
81
  "babel-jest": "^29.0.1",
81
- "cross-env": "^7.0.3",
82
82
  "eslint": "^9.9.1",
83
- "eslint-config-prettier": "^9.0.0",
83
+ "eslint-config-prettier": "^10.1.8",
84
84
  "fast-check": "^2.12.0",
85
85
  "jest": "^29.0.1",
86
+ "jest-resolve": "^29.7.0",
86
87
  "jest-ts-webcompat-resolver": "^1.0.0",
87
88
  "prettier": "^3.0.2",
88
89
  "rollup": "^4.12.0",
@@ -91,6 +92,6 @@
91
92
  "typescript-eslint": "^8.4.0"
92
93
  },
93
94
  "engines": {
94
- "node": ">= 14"
95
+ "node": ">= 14.6"
95
96
  }
96
97
  }