projen 0.88.2 → 0.88.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 (176) hide show
  1. package/.jsii +2 -2
  2. package/lib/awscdk/auto-discover.js +5 -5
  3. package/lib/awscdk/awscdk-app-java.js +1 -1
  4. package/lib/awscdk/awscdk-app-py.js +1 -1
  5. package/lib/awscdk/awscdk-app-ts.js +1 -1
  6. package/lib/awscdk/awscdk-construct.js +2 -2
  7. package/lib/awscdk/awscdk-deps-java.js +1 -1
  8. package/lib/awscdk/awscdk-deps-js.js +1 -1
  9. package/lib/awscdk/awscdk-deps-py.js +1 -1
  10. package/lib/awscdk/awscdk-deps.js +1 -1
  11. package/lib/awscdk/cdk-config.js +1 -1
  12. package/lib/awscdk/cdk-tasks.js +1 -1
  13. package/lib/awscdk/integration-test.js +1 -1
  14. package/lib/awscdk/lambda-extension.js +1 -1
  15. package/lib/awscdk/lambda-function.js +2 -2
  16. package/lib/build/build-workflow.js +1 -1
  17. package/lib/cdk/auto-discover-base.js +2 -2
  18. package/lib/cdk/construct-lib.js +1 -1
  19. package/lib/cdk/integration-test-base.js +1 -1
  20. package/lib/cdk/jsii-docgen.js +1 -1
  21. package/lib/cdk/jsii-project.js +1 -1
  22. package/lib/cdk8s/auto-discover.js +2 -2
  23. package/lib/cdk8s/cdk8s-app-py.js +1 -1
  24. package/lib/cdk8s/cdk8s-app-ts.js +1 -1
  25. package/lib/cdk8s/cdk8s-construct.js +1 -1
  26. package/lib/cdk8s/cdk8s-deps-py.js +1 -1
  27. package/lib/cdk8s/cdk8s-deps.js +1 -1
  28. package/lib/cdk8s/integration-test.js +1 -1
  29. package/lib/cdktf/cdktf-construct.js +1 -1
  30. package/lib/circleci/circleci.js +1 -1
  31. package/lib/component.js +1 -1
  32. package/lib/dependencies.js +1 -1
  33. package/lib/dev-env.js +1 -1
  34. package/lib/docker-compose/docker-compose-service.js +1 -1
  35. package/lib/docker-compose/docker-compose.js +1 -1
  36. package/lib/file.js +1 -1
  37. package/lib/gitattributes.js +1 -1
  38. package/lib/github/actions-provider.js +1 -1
  39. package/lib/github/auto-approve.js +1 -1
  40. package/lib/github/auto-merge.js +1 -1
  41. package/lib/github/dependabot.js +1 -1
  42. package/lib/github/github-credentials.js +1 -1
  43. package/lib/github/github-project.js +1 -1
  44. package/lib/github/github.js +1 -1
  45. package/lib/github/mergify.js +1 -1
  46. package/lib/github/pr-template.js +1 -1
  47. package/lib/github/pull-request-backport.js +1 -1
  48. package/lib/github/pull-request-lint.js +1 -1
  49. package/lib/github/stale.js +1 -1
  50. package/lib/github/task-workflow-job.js +1 -1
  51. package/lib/github/task-workflow.js +1 -1
  52. package/lib/github/workflow-actions.js +1 -1
  53. package/lib/github/workflow-jobs.js +1 -1
  54. package/lib/github/workflow-steps.js +1 -1
  55. package/lib/github/workflows.js +1 -1
  56. package/lib/gitlab/configuration.js +1 -1
  57. package/lib/gitlab/gitlab-configuration.js +1 -1
  58. package/lib/gitlab/nested-configuration.js +1 -1
  59. package/lib/gitpod.js +1 -1
  60. package/lib/ignore-file.js +1 -1
  61. package/lib/ini.js +1 -1
  62. package/lib/java/java-project.js +1 -1
  63. package/lib/java/junit.js +1 -1
  64. package/lib/java/maven-compile.js +1 -1
  65. package/lib/java/maven-packaging.js +1 -1
  66. package/lib/java/maven-sample.js +1 -1
  67. package/lib/java/pom.js +2 -2
  68. package/lib/java/projenrc.js +1 -1
  69. package/lib/javascript/bundler.js +1 -1
  70. package/lib/javascript/eslint.js +1 -1
  71. package/lib/javascript/jest.js +4 -4
  72. package/lib/javascript/license-checker.js +1 -1
  73. package/lib/javascript/node-package.js +1 -1
  74. package/lib/javascript/node-project.js +1 -1
  75. package/lib/javascript/npm-config.js +1 -1
  76. package/lib/javascript/prettier.js +1 -1
  77. package/lib/javascript/projenrc.js +1 -1
  78. package/lib/javascript/typescript-config.js +2 -2
  79. package/lib/javascript/upgrade-dependencies.js +2 -2
  80. package/lib/javascript/yarnrc.js +1 -1
  81. package/lib/json-patch.js +1 -1
  82. package/lib/json.js +1 -1
  83. package/lib/license.js +1 -1
  84. package/lib/logger.js +1 -1
  85. package/lib/makefile.js +1 -1
  86. package/lib/object-file.js +1 -1
  87. package/lib/project-build.js +1 -1
  88. package/lib/project-tree.js +1 -1
  89. package/lib/project.js +1 -1
  90. package/lib/projects.js +1 -1
  91. package/lib/projenrc-json.js +2 -2
  92. package/lib/projenrc.js +1 -1
  93. package/lib/python/pip.js +1 -1
  94. package/lib/python/poetry.js +2 -2
  95. package/lib/python/projenrc.js +1 -1
  96. package/lib/python/pytest-sample.js +1 -1
  97. package/lib/python/pytest.js +1 -1
  98. package/lib/python/python-project.js +1 -1
  99. package/lib/python/python-sample.js +1 -1
  100. package/lib/python/requirements-file.js +1 -1
  101. package/lib/python/setuppy.js +1 -1
  102. package/lib/python/setuptools.js +1 -1
  103. package/lib/python/venv.js +1 -1
  104. package/lib/readme.js +1 -1
  105. package/lib/release/publisher.js +1 -1
  106. package/lib/release/release-trigger.js +1 -1
  107. package/lib/release/release.js +1 -1
  108. package/lib/renovatebot.js +1 -1
  109. package/lib/sample-file.js +2 -2
  110. package/lib/semver.js +1 -1
  111. package/lib/source-code.js +1 -1
  112. package/lib/task-runtime.js +1 -1
  113. package/lib/task.js +1 -1
  114. package/lib/tasks.js +1 -1
  115. package/lib/testing.js +1 -1
  116. package/lib/textfile.js +1 -1
  117. package/lib/toml.js +1 -1
  118. package/lib/typescript/projenrc-ts.js +1 -1
  119. package/lib/typescript/projenrc.js +1 -1
  120. package/lib/typescript/typescript-typedoc.js +1 -1
  121. package/lib/typescript/typescript.js +6 -6
  122. package/lib/version.js +2 -2
  123. package/lib/vscode/devcontainer.js +1 -1
  124. package/lib/vscode/extensions.js +1 -1
  125. package/lib/vscode/launch-config.js +1 -1
  126. package/lib/vscode/settings.js +1 -1
  127. package/lib/vscode/vscode.js +1 -1
  128. package/lib/web/next.js +3 -3
  129. package/lib/web/postcss.js +1 -1
  130. package/lib/web/react.js +4 -4
  131. package/lib/web/tailwind.js +1 -1
  132. package/lib/xmlfile.js +1 -1
  133. package/lib/yaml.js +1 -1
  134. package/node_modules/yaml/README.md +17 -3
  135. package/node_modules/yaml/browser/dist/compose/compose-doc.js +1 -0
  136. package/node_modules/yaml/browser/dist/compose/compose-node.js +10 -0
  137. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +14 -8
  138. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +2 -0
  139. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +2 -0
  140. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +4 -0
  141. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +1 -5
  142. package/node_modules/yaml/browser/dist/doc/Document.js +3 -2
  143. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +7 -49
  144. package/node_modules/yaml/browser/dist/public-api.js +3 -0
  145. package/node_modules/yaml/browser/dist/schema/Schema.js +1 -2
  146. package/node_modules/yaml/browser/dist/schema/tags.js +26 -13
  147. package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +64 -0
  148. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +2 -0
  149. package/node_modules/yaml/browser/dist/stringify/stringify.js +6 -1
  150. package/node_modules/yaml/dist/compose/compose-doc.js +1 -0
  151. package/node_modules/yaml/dist/compose/compose-node.d.ts +1 -0
  152. package/node_modules/yaml/dist/compose/compose-node.js +10 -0
  153. package/node_modules/yaml/dist/compose/compose-scalar.js +13 -7
  154. package/node_modules/yaml/dist/compose/resolve-block-map.js +2 -0
  155. package/node_modules/yaml/dist/compose/resolve-block-seq.js +2 -0
  156. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +4 -0
  157. package/node_modules/yaml/dist/compose/util-map-includes.js +1 -5
  158. package/node_modules/yaml/dist/doc/Document.js +3 -2
  159. package/node_modules/yaml/dist/errors.d.ts +1 -1
  160. package/node_modules/yaml/dist/nodes/Node.d.ts +7 -1
  161. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +6 -48
  162. package/node_modules/yaml/dist/options.d.ts +6 -0
  163. package/node_modules/yaml/dist/parse/lexer.d.ts +1 -1
  164. package/node_modules/yaml/dist/parse/parser.d.ts +3 -3
  165. package/node_modules/yaml/dist/public-api.js +3 -0
  166. package/node_modules/yaml/dist/schema/Schema.d.ts +0 -1
  167. package/node_modules/yaml/dist/schema/Schema.js +1 -2
  168. package/node_modules/yaml/dist/schema/tags.d.ts +9 -1
  169. package/node_modules/yaml/dist/schema/tags.js +26 -13
  170. package/node_modules/yaml/dist/schema/types.d.ts +6 -4
  171. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  172. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +68 -0
  173. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +2 -0
  174. package/node_modules/yaml/dist/stringify/stringify.js +6 -1
  175. package/node_modules/yaml/package.json +1 -1
  176. package/package.json +3 -3
@@ -8,11 +8,7 @@ function mapIncludes(ctx, items, search) {
8
8
  return false;
9
9
  const isEqual = typeof uniqueKeys === 'function'
10
10
  ? uniqueKeys
11
- : (a, b) => a === b ||
12
- (identity.isScalar(a) &&
13
- identity.isScalar(b) &&
14
- a.value === b.value &&
15
- !(a.value === '<<' && ctx.schema.merge));
11
+ : (a, b) => a === b || (identity.isScalar(a) && identity.isScalar(b) && a.value === b.value);
16
12
  return items.some(pair => isEqual(pair.key, search));
17
13
  }
18
14
 
@@ -37,6 +37,7 @@ class Document {
37
37
  logLevel: 'warn',
38
38
  prettyErrors: true,
39
39
  strict: true,
40
+ stringKeys: false,
40
41
  uniqueKeys: true,
41
42
  version: '1.2'
42
43
  }, options);
@@ -260,7 +261,7 @@ class Document {
260
261
  this.directives.yaml.version = '1.1';
261
262
  else
262
263
  this.directives = new directives.Directives({ version: '1.1' });
263
- opt = { merge: true, resolveKnownTags: false, schema: 'yaml-1.1' };
264
+ opt = { resolveKnownTags: false, schema: 'yaml-1.1' };
264
265
  break;
265
266
  case '1.2':
266
267
  case 'next':
@@ -268,7 +269,7 @@ class Document {
268
269
  this.directives.yaml.version = version;
269
270
  else
270
271
  this.directives = new directives.Directives({ version });
271
- opt = { merge: false, resolveKnownTags: true, schema: 'core' };
272
+ opt = { resolveKnownTags: true, schema: 'core' };
272
273
  break;
273
274
  case null:
274
275
  if (this.directives)
@@ -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' | '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' | 'TAB_AS_INDENT' | 'TAG_RESOLVE_FAILED' | 'UNEXPECTED_TOKEN' | 'BAD_COLLECTION_TYPE';
3
3
  export type LinePos = {
4
4
  line: number;
5
5
  col: number;
@@ -5,7 +5,8 @@ import type { StringifyContext } from '../stringify/stringify.js';
5
5
  import type { Alias } from './Alias.js';
6
6
  import { NODE_TYPE } from './identity.js';
7
7
  import type { Scalar } from './Scalar.js';
8
- import type { YAMLMap } from './YAMLMap.js';
8
+ import { ToJSContext } from './toJS.js';
9
+ import type { MapLike, YAMLMap } from './YAMLMap.js';
9
10
  import type { YAMLSeq } from './YAMLSeq.js';
10
11
  export type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
11
12
  /** Utility type mapper */
@@ -36,6 +37,11 @@ export declare abstract class NodeBase {
36
37
  srcToken?: Token;
37
38
  /** A fully qualified tag, if required */
38
39
  tag?: string;
40
+ /**
41
+ * Customize the way that a key-value pair is resolved.
42
+ * Used for YAML 1.1 !!merge << handling.
43
+ */
44
+ addToJSMap?: (ctx: ToJSContext | undefined, map: MapLike, value: unknown) => void;
39
45
  /** A plain JS representation of this node */
40
46
  abstract toJSON(): any;
41
47
  abstract toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
@@ -1,24 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var log = require('../log.js');
4
+ var merge = require('../schema/yaml-1.1/merge.js');
4
5
  var stringify = require('../stringify/stringify.js');
5
6
  var identity = require('./identity.js');
6
- var Scalar = require('./Scalar.js');
7
7
  var toJS = require('./toJS.js');
8
8
 
9
- const MERGE_KEY = '<<';
10
9
  function addPairToJSMap(ctx, map, { key, value }) {
11
- if (ctx?.doc.schema.merge && isMergeKey(key)) {
12
- value = identity.isAlias(value) ? value.resolve(ctx.doc) : value;
13
- if (identity.isSeq(value))
14
- for (const it of value.items)
15
- mergeToJSMap(ctx, map, it);
16
- else if (Array.isArray(value))
17
- for (const it of value)
18
- mergeToJSMap(ctx, map, it);
19
- else
20
- mergeToJSMap(ctx, map, value);
21
- }
10
+ if (identity.isNode(key) && key.addToJSMap)
11
+ key.addToJSMap(ctx, map, value);
12
+ // TODO: Should drop this special case for bare << handling
13
+ else if (merge.isMergeKey(ctx, key))
14
+ merge.addMergeToJSMap(ctx, map, value);
22
15
  else {
23
16
  const jsKey = toJS.toJS(key, '', ctx);
24
17
  if (map instanceof Map) {
@@ -43,41 +36,6 @@ function addPairToJSMap(ctx, map, { key, value }) {
43
36
  }
44
37
  return map;
45
38
  }
46
- const isMergeKey = (key) => key === MERGE_KEY ||
47
- (identity.isScalar(key) &&
48
- key.value === MERGE_KEY &&
49
- (!key.type || key.type === Scalar.Scalar.PLAIN));
50
- // If the value associated with a merge key is a single mapping node, each of
51
- // its key/value pairs is inserted into the current mapping, unless the key
52
- // already exists in it. If the value associated with the merge key is a
53
- // sequence, then this sequence is expected to contain mapping nodes and each
54
- // of these nodes is merged in turn according to its order in the sequence.
55
- // Keys in mapping nodes earlier in the sequence override keys specified in
56
- // later mapping nodes. -- http://yaml.org/type/merge.html
57
- function mergeToJSMap(ctx, map, value) {
58
- const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
59
- if (!identity.isMap(source))
60
- throw new Error('Merge sources must be maps or map aliases');
61
- const srcMap = source.toJSON(null, ctx, Map);
62
- for (const [key, value] of srcMap) {
63
- if (map instanceof Map) {
64
- if (!map.has(key))
65
- map.set(key, value);
66
- }
67
- else if (map instanceof Set) {
68
- map.add(key);
69
- }
70
- else if (!Object.prototype.hasOwnProperty.call(map, key)) {
71
- Object.defineProperty(map, key, {
72
- value,
73
- writable: true,
74
- enumerable: true,
75
- configurable: true
76
- });
77
- }
78
- }
79
- return map;
80
- }
81
39
  function stringifyKey(key, jsKey, ctx) {
82
40
  if (jsKey === null)
83
41
  return '';
@@ -42,6 +42,12 @@ export type ParseOptions = {
42
42
  * Default: `true`
43
43
  */
44
44
  strict?: boolean;
45
+ /**
46
+ * Parse all mapping keys as strings. Treat all non-scalar keys as errors.
47
+ *
48
+ * Default: `false`
49
+ */
50
+ stringKeys?: boolean;
45
51
  /**
46
52
  * YAML requires map keys to be unique. By default, this is checked by
47
53
  * comparing scalar values with `===`; deep equality is not checked for
@@ -59,7 +59,7 @@ export declare class Lexer {
59
59
  *
60
60
  * @returns A generator of lexical tokens
61
61
  */
62
- lex(source: string, incomplete?: boolean): Generator<string, void, unknown>;
62
+ lex(source: string, incomplete?: boolean): Generator<string, void, any>;
63
63
  private atLineEnd;
64
64
  private charAt;
65
65
  private continueScalar;
@@ -57,14 +57,14 @@ export declare class Parser {
57
57
  *
58
58
  * @returns A generator of tokens representing each directive, document, and other structure.
59
59
  */
60
- parse(source: string, incomplete?: boolean): Generator<Token, void, unknown>;
60
+ parse(source: string, incomplete?: boolean): Generator<Token, void, any>;
61
61
  /**
62
62
  * Advance the parser by the `source` of one lexical token.
63
63
  */
64
- next(source: string): Generator<Token, void, unknown>;
64
+ next(source: string): Generator<Token, void, any>;
65
65
  private lexer;
66
66
  /** Call at end of input to push out any remaining constructions */
67
- end(): Generator<Token, void, unknown>;
67
+ end(): Generator<Token, void, any>;
68
68
  private get sourceToken();
69
69
  private step;
70
70
  private peek;
@@ -4,6 +4,7 @@ var composer = require('./compose/composer.js');
4
4
  var Document = require('./doc/Document.js');
5
5
  var errors = require('./errors.js');
6
6
  var log = require('./log.js');
7
+ var identity = require('./nodes/identity.js');
7
8
  var lineCounter = require('./parse/line-counter.js');
8
9
  var parser = require('./parse/parser.js');
9
10
 
@@ -95,6 +96,8 @@ function stringify(value, replacer, options) {
95
96
  if (!keepUndefined)
96
97
  return undefined;
97
98
  }
99
+ if (identity.isDocument(value) && !_replacer)
100
+ return value.toString(options);
98
101
  return new Document.Document(value, _replacer, options).toString(options);
99
102
  }
100
103
 
@@ -5,7 +5,6 @@ import type { CollectionTag, ScalarTag } from './types.js';
5
5
  export declare class Schema {
6
6
  compat: Array<CollectionTag | ScalarTag> | null;
7
7
  knownTags: Record<string, CollectionTag | ScalarTag>;
8
- merge: boolean;
9
8
  name: string;
10
9
  sortMapEntries: ((a: Pair, b: Pair) => number) | null;
11
10
  tags: Array<CollectionTag | ScalarTag>;
@@ -14,10 +14,9 @@ class Schema {
14
14
  : compat
15
15
  ? tags.getTags(null, compat)
16
16
  : null;
17
- this.merge = !!merge;
18
17
  this.name = (typeof schema === 'string' && schema) || 'core';
19
18
  this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
20
- this.tags = tags.getTags(customTags, this.name);
19
+ this.tags = tags.getTags(customTags, this.name, merge);
21
20
  this.toStringOptions = toStringDefaults ?? null;
22
21
  Object.defineProperty(this, identity.MAP, { value: map.map });
23
22
  Object.defineProperty(this, identity.SCALAR, { value: string.string });
@@ -14,6 +14,10 @@ declare const tagsByName: {
14
14
  intOct: ScalarTag;
15
15
  intTime: ScalarTag;
16
16
  map: CollectionTag;
17
+ merge: ScalarTag & {
18
+ identify(value: unknown): boolean;
19
+ test: RegExp;
20
+ };
17
21
  null: ScalarTag & {
18
22
  test: RegExp;
19
23
  };
@@ -29,6 +33,10 @@ export type TagId = keyof typeof tagsByName;
29
33
  export type Tags = Array<ScalarTag | CollectionTag | TagId>;
30
34
  export declare const coreKnownTags: {
31
35
  'tag:yaml.org,2002:binary': ScalarTag;
36
+ 'tag:yaml.org,2002:merge': ScalarTag & {
37
+ identify(value: unknown): boolean;
38
+ test: RegExp;
39
+ };
32
40
  'tag:yaml.org,2002:omap': CollectionTag;
33
41
  'tag:yaml.org,2002:pairs': CollectionTag;
34
42
  'tag:yaml.org,2002:set': CollectionTag;
@@ -36,5 +44,5 @@ export declare const coreKnownTags: {
36
44
  test: RegExp;
37
45
  };
38
46
  };
39
- export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (CollectionTag | ScalarTag)[];
47
+ export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string, addMergeTag?: boolean): (CollectionTag | ScalarTag)[];
40
48
  export {};
@@ -10,6 +10,7 @@ var int = require('./core/int.js');
10
10
  var schema = require('./core/schema.js');
11
11
  var schema$1 = require('./json/schema.js');
12
12
  var binary = require('./yaml-1.1/binary.js');
13
+ var merge = require('./yaml-1.1/merge.js');
13
14
  var omap = require('./yaml-1.1/omap.js');
14
15
  var pairs = require('./yaml-1.1/pairs.js');
15
16
  var schema$2 = require('./yaml-1.1/schema.js');
@@ -35,6 +36,7 @@ const tagsByName = {
35
36
  intOct: int.intOct,
36
37
  intTime: timestamp.intTime,
37
38
  map: map.map,
39
+ merge: merge.merge,
38
40
  null: _null.nullTag,
39
41
  omap: omap.omap,
40
42
  pairs: pairs.pairs,
@@ -44,13 +46,20 @@ const tagsByName = {
44
46
  };
45
47
  const coreKnownTags = {
46
48
  'tag:yaml.org,2002:binary': binary.binary,
49
+ 'tag:yaml.org,2002:merge': merge.merge,
47
50
  'tag:yaml.org,2002:omap': omap.omap,
48
51
  'tag:yaml.org,2002:pairs': pairs.pairs,
49
52
  'tag:yaml.org,2002:set': set.set,
50
53
  'tag:yaml.org,2002:timestamp': timestamp.timestamp
51
54
  };
52
- function getTags(customTags, schemaName) {
53
- let tags = schemas.get(schemaName);
55
+ function getTags(customTags, schemaName, addMergeTag) {
56
+ const schemaTags = schemas.get(schemaName);
57
+ if (schemaTags && !customTags) {
58
+ return addMergeTag && !schemaTags.includes(merge.merge)
59
+ ? schemaTags.concat(merge.merge)
60
+ : schemaTags.slice();
61
+ }
62
+ let tags = schemaTags;
54
63
  if (!tags) {
55
64
  if (Array.isArray(customTags))
56
65
  tags = [];
@@ -69,17 +78,21 @@ function getTags(customTags, schemaName) {
69
78
  else if (typeof customTags === 'function') {
70
79
  tags = customTags(tags.slice());
71
80
  }
72
- return tags.map(tag => {
73
- if (typeof tag !== 'string')
74
- return tag;
75
- const tagObj = tagsByName[tag];
76
- if (tagObj)
77
- return tagObj;
78
- const keys = Object.keys(tagsByName)
79
- .map(key => JSON.stringify(key))
80
- .join(', ');
81
- throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
82
- });
81
+ if (addMergeTag)
82
+ tags = tags.concat(merge.merge);
83
+ return tags.reduce((tags, tag) => {
84
+ const tagObj = typeof tag === 'string' ? tagsByName[tag] : tag;
85
+ if (!tagObj) {
86
+ const tagName = JSON.stringify(tag);
87
+ const keys = Object.keys(tagsByName)
88
+ .map(key => JSON.stringify(key))
89
+ .join(', ');
90
+ throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
91
+ }
92
+ if (!tags.includes(tagObj))
93
+ tags.push(tagObj);
94
+ return tags;
95
+ }, []);
83
96
  }
84
97
 
85
98
  exports.coreKnownTags = coreKnownTags;
@@ -12,11 +12,13 @@ interface TagBase {
12
12
  */
13
13
  createNode?: (schema: Schema, value: unknown, ctx: CreateNodeContext) => Node;
14
14
  /**
15
- * If `true`, together with `test` allows for values to be stringified without
16
- * an explicit tag. For most cases, it's unlikely that you'll actually want to
17
- * use this, even if you first think you do.
15
+ * If `true`, allows for values to be stringified without
16
+ * an explicit tag together with `test`.
17
+ * If `'key'`, this only applies if the value is used as a mapping key.
18
+ * For most cases, it's unlikely that you'll actually want to use this,
19
+ * even if you first think you do.
18
20
  */
19
- default?: boolean;
21
+ default?: boolean | 'key';
20
22
  /**
21
23
  * If a tag has multiple forms that should be parsed and/or stringified
22
24
  * differently, use `format` to identify them.
@@ -0,0 +1,9 @@
1
+ import type { ToJSContext } from '../../nodes/toJS.js';
2
+ import type { MapLike } from '../../nodes/YAMLMap.js';
3
+ import type { ScalarTag } from '../types.js';
4
+ export declare const merge: ScalarTag & {
5
+ identify(value: unknown): boolean;
6
+ test: RegExp;
7
+ };
8
+ export declare const isMergeKey: (ctx: ToJSContext | undefined, key: unknown) => boolean | undefined;
9
+ export declare function addMergeToJSMap(ctx: ToJSContext | undefined, map: MapLike, value: unknown): void;
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ var identity = require('../../nodes/identity.js');
4
+ var Scalar = require('../../nodes/Scalar.js');
5
+
6
+ // If the value associated with a merge key is a single mapping node, each of
7
+ // its key/value pairs is inserted into the current mapping, unless the key
8
+ // already exists in it. If the value associated with the merge key is a
9
+ // sequence, then this sequence is expected to contain mapping nodes and each
10
+ // of these nodes is merged in turn according to its order in the sequence.
11
+ // Keys in mapping nodes earlier in the sequence override keys specified in
12
+ // later mapping nodes. -- http://yaml.org/type/merge.html
13
+ const MERGE_KEY = '<<';
14
+ const merge = {
15
+ identify: value => value === MERGE_KEY ||
16
+ (typeof value === 'symbol' && value.description === MERGE_KEY),
17
+ default: 'key',
18
+ tag: 'tag:yaml.org,2002:merge',
19
+ test: /^<<$/,
20
+ resolve: () => Object.assign(new Scalar.Scalar(Symbol(MERGE_KEY)), {
21
+ addToJSMap: addMergeToJSMap
22
+ }),
23
+ stringify: () => MERGE_KEY
24
+ };
25
+ const isMergeKey = (ctx, key) => (merge.identify(key) ||
26
+ (identity.isScalar(key) &&
27
+ (!key.type || key.type === Scalar.Scalar.PLAIN) &&
28
+ merge.identify(key.value))) &&
29
+ ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
30
+ function addMergeToJSMap(ctx, map, value) {
31
+ value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
32
+ if (identity.isSeq(value))
33
+ for (const it of value.items)
34
+ mergeValue(ctx, map, it);
35
+ else if (Array.isArray(value))
36
+ for (const it of value)
37
+ mergeValue(ctx, map, it);
38
+ else
39
+ mergeValue(ctx, map, value);
40
+ }
41
+ function mergeValue(ctx, map, value) {
42
+ const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value;
43
+ if (!identity.isMap(source))
44
+ throw new Error('Merge sources must be maps or map aliases');
45
+ const srcMap = source.toJSON(null, ctx, Map);
46
+ for (const [key, value] of srcMap) {
47
+ if (map instanceof Map) {
48
+ if (!map.has(key))
49
+ map.set(key, value);
50
+ }
51
+ else if (map instanceof Set) {
52
+ map.add(key);
53
+ }
54
+ else if (!Object.prototype.hasOwnProperty.call(map, key)) {
55
+ Object.defineProperty(map, key, {
56
+ value,
57
+ writable: true,
58
+ enumerable: true,
59
+ configurable: true
60
+ });
61
+ }
62
+ }
63
+ return map;
64
+ }
65
+
66
+ exports.addMergeToJSMap = addMergeToJSMap;
67
+ exports.isMergeKey = isMergeKey;
68
+ exports.merge = merge;
@@ -8,6 +8,7 @@ var binary = require('./binary.js');
8
8
  var bool = require('./bool.js');
9
9
  var float = require('./float.js');
10
10
  var int = require('./int.js');
11
+ var merge = require('./merge.js');
11
12
  var omap = require('./omap.js');
12
13
  var pairs = require('./pairs.js');
13
14
  var set = require('./set.js');
@@ -28,6 +29,7 @@ const schema = [
28
29
  float.floatExp,
29
30
  float.float,
30
31
  binary.binary,
32
+ merge.merge,
31
33
  omap.omap,
32
34
  pairs.pairs,
33
35
  set.set,
@@ -56,7 +56,12 @@ function getTagObject(tags, item) {
56
56
  let obj;
57
57
  if (identity.isScalar(item)) {
58
58
  obj = item.value;
59
- const match = tags.filter(t => t.identify?.(obj));
59
+ let match = tags.filter(t => t.identify?.(obj));
60
+ if (match.length > 1) {
61
+ const testMatch = match.filter(t => t.test);
62
+ if (testMatch.length > 0)
63
+ match = testMatch;
64
+ }
60
65
  tagObj =
61
66
  match.find(t => t.format === item.format) ?? match.find(t => !t.format);
62
67
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "repository": "github:eemeli/yaml",
package/package.json CHANGED
@@ -69,9 +69,9 @@
69
69
  "jest": "^29",
70
70
  "jest-junit": "^15",
71
71
  "jsii": "5.5.x",
72
- "jsii-diff": "^1.103.1",
72
+ "jsii-diff": "^1.104.0",
73
73
  "jsii-docgen": "^10.5.0",
74
- "jsii-pacmak": "^1.103.1",
74
+ "jsii-pacmak": "^1.104.0",
75
75
  "jsii-rosetta": "5.5.x",
76
76
  "license-checker": "^25.0.1",
77
77
  "markmac": "^0.1.146",
@@ -130,7 +130,7 @@
130
130
  "publishConfig": {
131
131
  "access": "public"
132
132
  },
133
- "version": "0.88.2",
133
+ "version": "0.88.3",
134
134
  "jest": {
135
135
  "coverageProvider": "v8",
136
136
  "coverageReporters": [