projen 0.88.2 → 0.88.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +29 -13
- package/lib/awscdk/auto-discover.js +5 -5
- package/lib/awscdk/awscdk-app-java.js +1 -1
- package/lib/awscdk/awscdk-app-py.js +1 -1
- package/lib/awscdk/awscdk-app-ts.js +1 -1
- package/lib/awscdk/awscdk-construct.js +2 -2
- package/lib/awscdk/awscdk-deps-java.js +1 -1
- package/lib/awscdk/awscdk-deps-js.js +1 -1
- package/lib/awscdk/awscdk-deps-py.js +1 -1
- package/lib/awscdk/awscdk-deps.js +1 -1
- package/lib/awscdk/cdk-config.js +1 -1
- package/lib/awscdk/cdk-tasks.js +1 -1
- package/lib/awscdk/integration-test.js +1 -1
- package/lib/awscdk/lambda-extension.js +1 -1
- package/lib/awscdk/lambda-function.js +2 -2
- package/lib/build/build-workflow.js +1 -1
- package/lib/cdk/auto-discover-base.js +2 -2
- package/lib/cdk/construct-lib.js +1 -1
- package/lib/cdk/integration-test-base.js +1 -1
- package/lib/cdk/jsii-docgen.js +1 -1
- package/lib/cdk/jsii-project.js +1 -1
- package/lib/cdk8s/auto-discover.js +2 -2
- package/lib/cdk8s/cdk8s-app-py.js +1 -1
- package/lib/cdk8s/cdk8s-app-ts.js +1 -1
- package/lib/cdk8s/cdk8s-construct.js +1 -1
- package/lib/cdk8s/cdk8s-deps-py.js +1 -1
- package/lib/cdk8s/cdk8s-deps.js +1 -1
- package/lib/cdk8s/integration-test.js +1 -1
- package/lib/cdktf/cdktf-construct.js +1 -1
- package/lib/circleci/circleci.js +1 -1
- package/lib/component.js +1 -1
- package/lib/dependencies.js +1 -1
- package/lib/dev-env.js +1 -1
- package/lib/docker-compose/docker-compose-service.js +1 -1
- package/lib/docker-compose/docker-compose.js +1 -1
- package/lib/file.js +1 -1
- package/lib/gitattributes.js +1 -1
- package/lib/github/actions-provider.js +1 -1
- package/lib/github/auto-approve.js +1 -1
- package/lib/github/auto-merge.js +10 -11
- package/lib/github/dependabot.js +1 -1
- package/lib/github/github-credentials.js +1 -1
- package/lib/github/github-project.js +1 -1
- package/lib/github/github.js +1 -1
- package/lib/github/mergify.d.ts +4 -0
- package/lib/github/mergify.js +2 -2
- package/lib/github/pr-template.js +1 -1
- package/lib/github/pull-request-backport.js +1 -1
- package/lib/github/pull-request-lint.js +1 -1
- package/lib/github/stale.js +1 -1
- package/lib/github/task-workflow-job.js +1 -1
- package/lib/github/task-workflow.js +1 -1
- package/lib/github/workflow-actions.js +1 -1
- package/lib/github/workflow-jobs.js +1 -1
- package/lib/github/workflow-steps.js +1 -1
- package/lib/github/workflows.js +1 -1
- package/lib/gitlab/configuration.js +1 -1
- package/lib/gitlab/gitlab-configuration.js +1 -1
- package/lib/gitlab/nested-configuration.js +1 -1
- package/lib/gitpod.js +1 -1
- package/lib/ignore-file.js +1 -1
- package/lib/ini.js +1 -1
- package/lib/java/java-project.js +1 -1
- package/lib/java/junit.js +1 -1
- package/lib/java/maven-compile.js +1 -1
- package/lib/java/maven-packaging.js +1 -1
- package/lib/java/maven-sample.js +1 -1
- package/lib/java/pom.js +2 -2
- package/lib/java/projenrc.js +1 -1
- package/lib/javascript/bundler.js +1 -1
- package/lib/javascript/eslint.js +1 -1
- package/lib/javascript/jest.js +4 -4
- package/lib/javascript/license-checker.js +1 -1
- package/lib/javascript/node-package.js +1 -1
- package/lib/javascript/node-project.js +1 -1
- package/lib/javascript/npm-config.js +1 -1
- package/lib/javascript/prettier.js +1 -1
- package/lib/javascript/projenrc.js +1 -1
- package/lib/javascript/typescript-config.js +2 -2
- package/lib/javascript/upgrade-dependencies.js +2 -2
- package/lib/javascript/yarnrc.js +1 -1
- package/lib/json-patch.js +1 -1
- package/lib/json.js +1 -1
- package/lib/license.js +1 -1
- package/lib/logger.js +1 -1
- package/lib/makefile.js +1 -1
- package/lib/object-file.js +1 -1
- package/lib/project-build.js +1 -1
- package/lib/project-tree.js +1 -1
- package/lib/project.js +1 -1
- package/lib/projects.js +1 -1
- package/lib/projenrc-json.js +2 -2
- package/lib/projenrc.js +1 -1
- package/lib/python/pip.js +1 -1
- package/lib/python/poetry.js +2 -2
- package/lib/python/projenrc.js +1 -1
- package/lib/python/pytest-sample.js +1 -1
- package/lib/python/pytest.js +1 -1
- package/lib/python/python-project.js +1 -1
- package/lib/python/python-sample.js +1 -1
- package/lib/python/requirements-file.js +1 -1
- package/lib/python/setuppy.js +1 -1
- package/lib/python/setuptools.js +1 -1
- package/lib/python/venv.js +1 -1
- package/lib/readme.js +1 -1
- package/lib/release/publisher.js +1 -1
- package/lib/release/release-trigger.js +1 -1
- package/lib/release/release.js +1 -1
- package/lib/renovatebot.js +1 -1
- package/lib/sample-file.js +2 -2
- package/lib/semver.js +1 -1
- package/lib/source-code.js +1 -1
- package/lib/task-runtime.js +1 -1
- package/lib/task.js +1 -1
- package/lib/tasks.js +1 -1
- package/lib/testing.js +1 -1
- package/lib/textfile.js +1 -1
- package/lib/toml.js +1 -1
- package/lib/typescript/projenrc-ts.js +1 -1
- package/lib/typescript/projenrc.js +1 -1
- package/lib/typescript/typescript-typedoc.js +1 -1
- package/lib/typescript/typescript.js +6 -6
- package/lib/version.js +2 -2
- package/lib/vscode/devcontainer.js +1 -1
- package/lib/vscode/extensions.js +1 -1
- package/lib/vscode/launch-config.js +1 -1
- package/lib/vscode/settings.js +1 -1
- package/lib/vscode/vscode.js +1 -1
- package/lib/web/next.js +3 -3
- package/lib/web/postcss.js +1 -1
- package/lib/web/react.js +4 -4
- package/lib/web/tailwind.js +1 -1
- package/lib/xmlfile.js +1 -1
- package/lib/yaml.js +1 -1
- package/node_modules/yaml/README.md +17 -3
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +1 -0
- package/node_modules/yaml/browser/dist/compose/compose-node.js +10 -0
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +14 -8
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +2 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +2 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +4 -0
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +1 -5
- package/node_modules/yaml/browser/dist/doc/Document.js +3 -2
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +7 -49
- package/node_modules/yaml/browser/dist/public-api.js +3 -0
- package/node_modules/yaml/browser/dist/schema/Schema.js +1 -2
- package/node_modules/yaml/browser/dist/schema/tags.js +26 -13
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +64 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +2 -0
- package/node_modules/yaml/browser/dist/stringify/stringify.js +6 -1
- package/node_modules/yaml/dist/compose/compose-doc.js +1 -0
- package/node_modules/yaml/dist/compose/compose-node.d.ts +1 -0
- package/node_modules/yaml/dist/compose/compose-node.js +10 -0
- package/node_modules/yaml/dist/compose/compose-scalar.js +13 -7
- package/node_modules/yaml/dist/compose/resolve-block-map.js +2 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +2 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +4 -0
- package/node_modules/yaml/dist/compose/util-map-includes.js +1 -5
- package/node_modules/yaml/dist/doc/Document.js +3 -2
- package/node_modules/yaml/dist/errors.d.ts +1 -1
- package/node_modules/yaml/dist/nodes/Node.d.ts +7 -1
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +6 -48
- package/node_modules/yaml/dist/options.d.ts +6 -0
- package/node_modules/yaml/dist/parse/lexer.d.ts +1 -1
- package/node_modules/yaml/dist/parse/parser.d.ts +3 -3
- package/node_modules/yaml/dist/public-api.js +3 -0
- package/node_modules/yaml/dist/schema/Schema.d.ts +0 -1
- package/node_modules/yaml/dist/schema/Schema.js +1 -2
- package/node_modules/yaml/dist/schema/tags.d.ts +9 -1
- package/node_modules/yaml/dist/schema/tags.js +26 -13
- package/node_modules/yaml/dist/schema/types.d.ts +6 -4
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +68 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +2 -0
- package/node_modules/yaml/dist/stringify/stringify.js +6 -1
- package/node_modules/yaml/package.json +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { isScalar, isAlias, isSeq, isMap } from '../../nodes/identity.js';
|
|
2
|
+
import { Scalar } from '../../nodes/Scalar.js';
|
|
3
|
+
|
|
4
|
+
// If the value associated with a merge key is a single mapping node, each of
|
|
5
|
+
// its key/value pairs is inserted into the current mapping, unless the key
|
|
6
|
+
// already exists in it. If the value associated with the merge key is a
|
|
7
|
+
// sequence, then this sequence is expected to contain mapping nodes and each
|
|
8
|
+
// of these nodes is merged in turn according to its order in the sequence.
|
|
9
|
+
// Keys in mapping nodes earlier in the sequence override keys specified in
|
|
10
|
+
// later mapping nodes. -- http://yaml.org/type/merge.html
|
|
11
|
+
const MERGE_KEY = '<<';
|
|
12
|
+
const merge = {
|
|
13
|
+
identify: value => value === MERGE_KEY ||
|
|
14
|
+
(typeof value === 'symbol' && value.description === MERGE_KEY),
|
|
15
|
+
default: 'key',
|
|
16
|
+
tag: 'tag:yaml.org,2002:merge',
|
|
17
|
+
test: /^<<$/,
|
|
18
|
+
resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), {
|
|
19
|
+
addToJSMap: addMergeToJSMap
|
|
20
|
+
}),
|
|
21
|
+
stringify: () => MERGE_KEY
|
|
22
|
+
};
|
|
23
|
+
const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
24
|
+
(isScalar(key) &&
|
|
25
|
+
(!key.type || key.type === Scalar.PLAIN) &&
|
|
26
|
+
merge.identify(key.value))) &&
|
|
27
|
+
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
|
|
28
|
+
function addMergeToJSMap(ctx, map, value) {
|
|
29
|
+
value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
30
|
+
if (isSeq(value))
|
|
31
|
+
for (const it of value.items)
|
|
32
|
+
mergeValue(ctx, map, it);
|
|
33
|
+
else if (Array.isArray(value))
|
|
34
|
+
for (const it of value)
|
|
35
|
+
mergeValue(ctx, map, it);
|
|
36
|
+
else
|
|
37
|
+
mergeValue(ctx, map, value);
|
|
38
|
+
}
|
|
39
|
+
function mergeValue(ctx, map, value) {
|
|
40
|
+
const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
41
|
+
if (!isMap(source))
|
|
42
|
+
throw new Error('Merge sources must be maps or map aliases');
|
|
43
|
+
const srcMap = source.toJSON(null, ctx, Map);
|
|
44
|
+
for (const [key, value] of srcMap) {
|
|
45
|
+
if (map instanceof Map) {
|
|
46
|
+
if (!map.has(key))
|
|
47
|
+
map.set(key, value);
|
|
48
|
+
}
|
|
49
|
+
else if (map instanceof Set) {
|
|
50
|
+
map.add(key);
|
|
51
|
+
}
|
|
52
|
+
else if (!Object.prototype.hasOwnProperty.call(map, key)) {
|
|
53
|
+
Object.defineProperty(map, key, {
|
|
54
|
+
value,
|
|
55
|
+
writable: true,
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return map;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export { addMergeToJSMap, isMergeKey, merge };
|
|
@@ -6,6 +6,7 @@ import { binary } from './binary.js';
|
|
|
6
6
|
import { trueTag, falseTag } from './bool.js';
|
|
7
7
|
import { floatNaN, floatExp, float } from './float.js';
|
|
8
8
|
import { intBin, intOct, int, intHex } from './int.js';
|
|
9
|
+
import { merge } from './merge.js';
|
|
9
10
|
import { omap } from './omap.js';
|
|
10
11
|
import { pairs } from './pairs.js';
|
|
11
12
|
import { set } from './set.js';
|
|
@@ -26,6 +27,7 @@ const schema = [
|
|
|
26
27
|
floatExp,
|
|
27
28
|
float,
|
|
28
29
|
binary,
|
|
30
|
+
merge,
|
|
29
31
|
omap,
|
|
30
32
|
pairs,
|
|
31
33
|
set,
|
|
@@ -54,7 +54,12 @@ function getTagObject(tags, item) {
|
|
|
54
54
|
let obj;
|
|
55
55
|
if (isScalar(item)) {
|
|
56
56
|
obj = item.value;
|
|
57
|
-
|
|
57
|
+
let match = tags.filter(t => t.identify?.(obj));
|
|
58
|
+
if (match.length > 1) {
|
|
59
|
+
const testMatch = match.filter(t => t.test);
|
|
60
|
+
if (testMatch.length > 0)
|
|
61
|
+
match = testMatch;
|
|
62
|
+
}
|
|
58
63
|
tagObj =
|
|
59
64
|
match.find(t => t.format === item.format) ?? match.find(t => !t.format);
|
|
60
65
|
}
|
|
@@ -9,6 +9,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
|
|
|
9
9
|
const opts = Object.assign({ _directives: directives }, options);
|
|
10
10
|
const doc = new Document.Document(undefined, opts);
|
|
11
11
|
const ctx = {
|
|
12
|
+
atKey: false,
|
|
12
13
|
atRoot: true,
|
|
13
14
|
directives: doc.directives,
|
|
14
15
|
options: doc.options,
|
|
@@ -5,6 +5,7 @@ import type { SourceToken, Token } from '../parse/cst.js';
|
|
|
5
5
|
import type { Schema } from '../schema/Schema.js';
|
|
6
6
|
import type { ComposeErrorHandler } from './composer.js';
|
|
7
7
|
export interface ComposeContext {
|
|
8
|
+
atKey: boolean;
|
|
8
9
|
atRoot: boolean;
|
|
9
10
|
directives: Directives;
|
|
10
11
|
options: Readonly<Required<Omit<ParseOptions, 'lineCounter'>>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Alias = require('../nodes/Alias.js');
|
|
4
|
+
var identity = require('../nodes/identity.js');
|
|
4
5
|
var composeCollection = require('./compose-collection.js');
|
|
5
6
|
var composeScalar = require('./compose-scalar.js');
|
|
6
7
|
var resolveEnd = require('./resolve-end.js');
|
|
@@ -8,6 +9,7 @@ var utilEmptyScalarPosition = require('./util-empty-scalar-position.js');
|
|
|
8
9
|
|
|
9
10
|
const CN = { composeNode, composeEmptyNode };
|
|
10
11
|
function composeNode(ctx, token, props, onError) {
|
|
12
|
+
const atKey = ctx.atKey;
|
|
11
13
|
const { spaceBefore, comment, anchor, tag } = props;
|
|
12
14
|
let node;
|
|
13
15
|
let isSrcToken = true;
|
|
@@ -43,6 +45,14 @@ function composeNode(ctx, token, props, onError) {
|
|
|
43
45
|
}
|
|
44
46
|
if (anchor && node.anchor === '')
|
|
45
47
|
onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
|
|
48
|
+
if (atKey &&
|
|
49
|
+
ctx.options.stringKeys &&
|
|
50
|
+
(!identity.isScalar(node) ||
|
|
51
|
+
typeof node.value !== 'string' ||
|
|
52
|
+
(node.tag && node.tag !== 'tag:yaml.org,2002:str'))) {
|
|
53
|
+
const msg = 'With stringKeys, all keys must be strings';
|
|
54
|
+
onError(tag ?? token, 'NON_STRING_KEY', msg);
|
|
55
|
+
}
|
|
46
56
|
if (spaceBefore)
|
|
47
57
|
node.spaceBefore = true;
|
|
48
58
|
if (comment) {
|
|
@@ -12,11 +12,16 @@ function composeScalar(ctx, token, tagToken, onError) {
|
|
|
12
12
|
const tagName = tagToken
|
|
13
13
|
? ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg))
|
|
14
14
|
: null;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
let tag;
|
|
16
|
+
if (ctx.options.stringKeys && ctx.atKey) {
|
|
17
|
+
tag = ctx.schema[identity.SCALAR];
|
|
18
|
+
}
|
|
19
|
+
else if (tagName)
|
|
20
|
+
tag = findScalarTagByName(ctx.schema, value, tagName, tagToken, onError);
|
|
21
|
+
else if (token.type === 'scalar')
|
|
22
|
+
tag = findScalarTagByTest(ctx, value, token, onError);
|
|
23
|
+
else
|
|
24
|
+
tag = ctx.schema[identity.SCALAR];
|
|
20
25
|
let scalar;
|
|
21
26
|
try {
|
|
22
27
|
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
|
|
@@ -64,8 +69,9 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
|
|
|
64
69
|
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
|
|
65
70
|
return schema[identity.SCALAR];
|
|
66
71
|
}
|
|
67
|
-
function findScalarTagByTest({ directives, schema }, value, token, onError) {
|
|
68
|
-
const tag = schema.tags.find(tag => tag.default && tag.
|
|
72
|
+
function findScalarTagByTest({ atKey, directives, schema }, value, token, onError) {
|
|
73
|
+
const tag = schema.tags.find(tag => (tag.default === true || (atKey && tag.default === 'key')) &&
|
|
74
|
+
tag.test?.test(value)) || schema[identity.SCALAR];
|
|
69
75
|
if (schema.compat) {
|
|
70
76
|
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
|
|
71
77
|
schema[identity.SCALAR];
|
|
@@ -52,12 +52,14 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
|
|
|
52
52
|
onError(offset, 'BAD_INDENT', startColMsg);
|
|
53
53
|
}
|
|
54
54
|
// key value
|
|
55
|
+
ctx.atKey = true;
|
|
55
56
|
const keyStart = keyProps.end;
|
|
56
57
|
const keyNode = key
|
|
57
58
|
? composeNode(ctx, key, keyProps, onError)
|
|
58
59
|
: composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
|
|
59
60
|
if (ctx.schema.compat)
|
|
60
61
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
|
|
62
|
+
ctx.atKey = false;
|
|
61
63
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
62
64
|
onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
|
|
63
65
|
// value properties
|
|
@@ -9,6 +9,8 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta
|
|
|
9
9
|
const seq = new NodeClass(ctx.schema);
|
|
10
10
|
if (ctx.atRoot)
|
|
11
11
|
ctx.atRoot = false;
|
|
12
|
+
if (ctx.atKey)
|
|
13
|
+
ctx.atKey = false;
|
|
12
14
|
let offset = bs.offset;
|
|
13
15
|
let commentEnd = null;
|
|
14
16
|
for (const { start, value } of bs.items) {
|
|
@@ -20,6 +20,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
20
20
|
const atRoot = ctx.atRoot;
|
|
21
21
|
if (atRoot)
|
|
22
22
|
ctx.atRoot = false;
|
|
23
|
+
if (ctx.atKey)
|
|
24
|
+
ctx.atKey = false;
|
|
23
25
|
let offset = fc.offset + fc.start.source.length;
|
|
24
26
|
for (let i = 0; i < fc.items.length; ++i) {
|
|
25
27
|
const collItem = fc.items[i];
|
|
@@ -99,12 +101,14 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
|
|
|
99
101
|
else {
|
|
100
102
|
// item is a key+value pair
|
|
101
103
|
// key value
|
|
104
|
+
ctx.atKey = true;
|
|
102
105
|
const keyStart = props.end;
|
|
103
106
|
const keyNode = key
|
|
104
107
|
? composeNode(ctx, key, props, onError)
|
|
105
108
|
: composeEmptyNode(ctx, keyStart, start, null, props, onError);
|
|
106
109
|
if (isBlock(key))
|
|
107
110
|
onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
|
|
111
|
+
ctx.atKey = false;
|
|
108
112
|
// value properties
|
|
109
113
|
const valueProps = resolveProps.resolveProps(sep ?? [], {
|
|
110
114
|
flow: fcName,
|
|
@@ -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 = {
|
|
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 = {
|
|
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
|
|
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 (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const tagObj = tagsByName[tag];
|
|
76
|
-
if (tagObj)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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`,
|
|
16
|
-
* an explicit tag
|
|
17
|
-
*
|
|
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;
|