projen 0.53.10 → 0.53.13
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 +155 -104
- package/changelog.md +1 -6
- package/docs/api/API.md +18 -12
- package/lib/awscdk/auto-discover.js +4 -4
- 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.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-ts.js +1 -1
- package/lib/cdk8s/cdk8s-construct.js +1 -1
- package/lib/cdk8s/integration-test.js +1 -1
- package/lib/cdktf/cdktf-construct.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.js +2 -2
- package/lib/file.js +1 -1
- package/lib/gitattributes.js +1 -1
- package/lib/github/auto-approve.js +1 -1
- package/lib/github/auto-merge.js +1 -1
- package/lib/github/dependabot.js +1 -1
- package/lib/github/github-project.js +1 -1
- package/lib/github/github.js +1 -1
- package/lib/github/mergify.js +1 -1
- package/lib/github/pr-template.js +1 -1
- package/lib/github/pull-request-lint.js +1 -1
- package/lib/github/stale.js +1 -1
- package/lib/github/task-workflow.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 +1 -1
- 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 +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 +1 -1
- package/lib/javascript/upgrade-dependencies.d.ts +5 -2
- package/lib/javascript/upgrade-dependencies.js +51 -41
- 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.js +1 -1
- package/lib/projects.js +1 -1
- package/lib/projenrc-json.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.d.ts +14 -0
- package/lib/release/release.js +26 -2
- package/lib/run-task.js +0 -1813
- 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.d.ts +4 -0
- package/lib/task.js +12 -4
- 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.js +1 -1
- package/lib/typescript/typescript-typedoc.js +1 -1
- package/lib/typescript/typescript.js +3 -3
- package/lib/version.js +1 -1
- package/lib/vscode/devcontainer.js +1 -1
- package/lib/vscode/launch-config.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/browser/dist/compose/compose-doc.js +1 -1
- package/node_modules/yaml/browser/dist/compose/compose-node.js +13 -4
- package/node_modules/yaml/browser/dist/compose/composer.js +5 -7
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +9 -2
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +2 -0
- package/node_modules/yaml/browser/dist/doc/Document.js +9 -2
- package/node_modules/yaml/browser/dist/doc/directives.js +7 -4
- package/node_modules/yaml/browser/dist/index.js +1 -2
- package/node_modules/yaml/browser/dist/parse/lexer.js +16 -7
- package/node_modules/yaml/browser/dist/parse/parser.js +64 -30
- package/node_modules/yaml/browser/dist/schema/common/null.js +3 -1
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +26 -8
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +1 -1
- package/node_modules/yaml/browser/dist/visit.js +150 -62
- package/node_modules/yaml/dist/compose/compose-doc.js +1 -1
- package/node_modules/yaml/dist/compose/compose-node.js +13 -4
- package/node_modules/yaml/dist/compose/composer.d.ts +1 -1
- package/node_modules/yaml/dist/compose/composer.js +7 -9
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +9 -2
- package/node_modules/yaml/dist/compose/resolve-props.js +2 -0
- package/node_modules/yaml/dist/doc/Document.d.ts +1 -1
- package/node_modules/yaml/dist/doc/Document.js +16 -9
- package/node_modules/yaml/dist/doc/directives.d.ts +3 -1
- package/node_modules/yaml/dist/doc/directives.js +7 -4
- package/node_modules/yaml/dist/index.d.ts +2 -2
- package/node_modules/yaml/dist/index.js +1 -2
- package/node_modules/yaml/dist/options.d.ts +0 -8
- package/node_modules/yaml/dist/parse/lexer.js +16 -7
- package/node_modules/yaml/dist/parse/parser.js +64 -30
- package/node_modules/yaml/dist/schema/common/null.js +3 -1
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +26 -8
- package/node_modules/yaml/dist/stringify/stringifyPair.js +1 -1
- package/node_modules/yaml/dist/test-events.js +8 -9
- package/node_modules/yaml/dist/visit.d.ts +49 -10
- package/node_modules/yaml/dist/visit.js +149 -60
- package/node_modules/yaml/package.json +3 -3
- package/package.json +3 -3
- package/releasetag.txt +1 -1
- package/version.txt +1 -1
- package/node_modules/yaml/browser/dist/options.js +0 -18
- package/node_modules/yaml/dist/options.js +0 -20
|
@@ -545,36 +545,70 @@ class Parser {
|
|
|
545
545
|
this.onKeyLine = true;
|
|
546
546
|
return;
|
|
547
547
|
case 'map-value-ind':
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
548
|
+
if (includesToken(it.start, 'explicit-key-ind')) {
|
|
549
|
+
if (!it.sep) {
|
|
550
|
+
if (includesToken(it.start, 'newline')) {
|
|
551
|
+
Object.assign(it, { key: null, sep: [this.sourceToken] });
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
const start = getFirstKeyStartProps(it.start);
|
|
555
|
+
this.stack.push({
|
|
556
|
+
type: 'block-map',
|
|
557
|
+
offset: this.offset,
|
|
558
|
+
indent: this.indent,
|
|
559
|
+
items: [{ start, key: null, sep: [this.sourceToken] }]
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else if (it.value) {
|
|
564
|
+
map.items.push({ start: [], key: null, sep: [this.sourceToken] });
|
|
565
|
+
}
|
|
566
|
+
else if (includesToken(it.sep, 'map-value-ind')) {
|
|
567
|
+
this.stack.push({
|
|
568
|
+
type: 'block-map',
|
|
569
|
+
offset: this.offset,
|
|
570
|
+
indent: this.indent,
|
|
571
|
+
items: [{ start: [], key: null, sep: [this.sourceToken] }]
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
else if (isFlowToken(it.key) &&
|
|
575
|
+
!includesToken(it.sep, 'newline')) {
|
|
576
|
+
const start = getFirstKeyStartProps(it.start);
|
|
577
|
+
const key = it.key;
|
|
578
|
+
const sep = it.sep;
|
|
579
|
+
sep.push(this.sourceToken);
|
|
580
|
+
// @ts-expect-error type guard is wrong here
|
|
581
|
+
delete it.key, delete it.sep;
|
|
582
|
+
this.stack.push({
|
|
583
|
+
type: 'block-map',
|
|
584
|
+
offset: this.offset,
|
|
585
|
+
indent: this.indent,
|
|
586
|
+
items: [{ start, key, sep }]
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
it.sep.push(this.sourceToken);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
if (!it.sep) {
|
|
595
|
+
Object.assign(it, { key: null, sep: [this.sourceToken] });
|
|
596
|
+
}
|
|
597
|
+
else if (it.value || atNextItem) {
|
|
598
|
+
map.items.push({ start: [], key: null, sep: [this.sourceToken] });
|
|
599
|
+
}
|
|
600
|
+
else if (includesToken(it.sep, 'map-value-ind')) {
|
|
601
|
+
this.stack.push({
|
|
602
|
+
type: 'block-map',
|
|
603
|
+
offset: this.offset,
|
|
604
|
+
indent: this.indent,
|
|
605
|
+
items: [{ start: [], key: null, sep: [this.sourceToken] }]
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
it.sep.push(this.sourceToken);
|
|
610
|
+
}
|
|
575
611
|
}
|
|
576
|
-
else
|
|
577
|
-
it.sep.push(this.sourceToken);
|
|
578
612
|
this.onKeyLine = true;
|
|
579
613
|
return;
|
|
580
614
|
case 'alias':
|
|
@@ -738,7 +772,7 @@ class Parser {
|
|
|
738
772
|
else {
|
|
739
773
|
const parent = this.peek(2);
|
|
740
774
|
if (parent.type === 'block-map' &&
|
|
741
|
-
(this.type === 'map-value-ind' ||
|
|
775
|
+
((this.type === 'map-value-ind' && parent.indent === fc.indent) ||
|
|
742
776
|
(this.type === 'newline' &&
|
|
743
777
|
!parent.items[parent.items.length - 1].sep))) {
|
|
744
778
|
yield* this.pop();
|
|
@@ -9,7 +9,9 @@ const nullTag = {
|
|
|
9
9
|
tag: 'tag:yaml.org,2002:null',
|
|
10
10
|
test: /^(?:~|[Nn]ull|NULL)?$/,
|
|
11
11
|
resolve: () => new Scalar.Scalar(null),
|
|
12
|
-
stringify: ({ source }, ctx) => source && nullTag.test.test(source)
|
|
12
|
+
stringify: ({ source }, ctx) => typeof source === 'string' && nullTag.test.test(source)
|
|
13
|
+
? source
|
|
14
|
+
: ctx.options.nullStr
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
exports.nullTag = nullTag;
|
|
@@ -5,6 +5,7 @@ var stringify = require('./stringify.js');
|
|
|
5
5
|
var stringifyComment = require('./stringifyComment.js');
|
|
6
6
|
|
|
7
7
|
function stringifyDocument(doc, options) {
|
|
8
|
+
var _a;
|
|
8
9
|
const lines = [];
|
|
9
10
|
let hasDirectives = options.directives === true;
|
|
10
11
|
if (options.directives !== false && doc.directives) {
|
|
@@ -13,7 +14,7 @@ function stringifyDocument(doc, options) {
|
|
|
13
14
|
lines.push(dir);
|
|
14
15
|
hasDirectives = true;
|
|
15
16
|
}
|
|
16
|
-
else if (doc.directives.
|
|
17
|
+
else if (doc.directives.docStart)
|
|
17
18
|
hasDirectives = true;
|
|
18
19
|
}
|
|
19
20
|
if (hasDirectives)
|
|
@@ -56,13 +57,30 @@ function stringifyDocument(doc, options) {
|
|
|
56
57
|
else {
|
|
57
58
|
lines.push(stringify.stringify(doc.contents, ctx));
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
if ((_a = doc.directives) === null || _a === void 0 ? void 0 : _a.docEnd) {
|
|
61
|
+
if (doc.comment) {
|
|
62
|
+
const cs = commentString(doc.comment);
|
|
63
|
+
if (cs.includes('\n')) {
|
|
64
|
+
lines.push('...');
|
|
65
|
+
lines.push(stringifyComment.indentComment(cs, ''));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
lines.push(`... ${cs}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
lines.push('...');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
let dc = doc.comment;
|
|
77
|
+
if (dc && chompKeep)
|
|
78
|
+
dc = dc.replace(/^\n+/, '');
|
|
79
|
+
if (dc) {
|
|
80
|
+
if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '')
|
|
81
|
+
lines.push('');
|
|
82
|
+
lines.push(stringifyComment.indentComment(commentString(dc), ''));
|
|
83
|
+
}
|
|
66
84
|
}
|
|
67
85
|
return lines.join('\n') + '\n';
|
|
68
86
|
}
|
|
@@ -41,7 +41,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
|
41
41
|
if (allNullValues || value == null) {
|
|
42
42
|
if (keyCommentDone && onComment)
|
|
43
43
|
onComment();
|
|
44
|
-
return explicitKey ? `? ${str}` : str;
|
|
44
|
+
return str === '' ? '?' : explicitKey ? `? ${str}` : str;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
else if ((allNullValues && !simpleKeys) || (value == null && explicitKey)) {
|
|
@@ -36,24 +36,23 @@ function testEvents(src) {
|
|
|
36
36
|
let root = doc.contents;
|
|
37
37
|
if (Array.isArray(root))
|
|
38
38
|
root = root[0];
|
|
39
|
-
|
|
40
|
-
const [rootStart, , rootEnd] = doc.range || [0, , 0];
|
|
39
|
+
const [rootStart] = doc.range || [0];
|
|
41
40
|
const error = doc.errors[0];
|
|
42
41
|
if (error && (!error.pos || error.pos[0] < rootStart))
|
|
43
42
|
throw new Error();
|
|
44
43
|
let docStart = '+DOC';
|
|
45
|
-
if (doc.directives.
|
|
44
|
+
if (doc.directives.docStart)
|
|
46
45
|
docStart += ' ---';
|
|
47
|
-
else if (doc.contents &&
|
|
46
|
+
else if (doc.contents &&
|
|
47
|
+
doc.contents.range[2] === doc.contents.range[0] &&
|
|
48
|
+
!doc.contents.anchor &&
|
|
49
|
+
!doc.contents.tag)
|
|
48
50
|
continue;
|
|
49
51
|
events.push(docStart);
|
|
50
52
|
addEvents(events, doc, (_a = error === null || error === void 0 ? void 0 : error.pos[0]) !== null && _a !== void 0 ? _a : -1, root);
|
|
51
53
|
let docEnd = '-DOC';
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
if (/^\.\.\.($|\s)/m.test(post))
|
|
55
|
-
docEnd += ' ...';
|
|
56
|
-
}
|
|
54
|
+
if (doc.directives.docEnd)
|
|
55
|
+
docEnd += ' ...';
|
|
57
56
|
events.push(docEnd);
|
|
58
57
|
}
|
|
59
58
|
}
|
|
@@ -16,6 +16,17 @@ export declare type visitor = visitorFn<unknown> | {
|
|
|
16
16
|
Seq?: visitorFn<YAMLSeq>;
|
|
17
17
|
Value?: visitorFn<Scalar | YAMLMap | YAMLSeq>;
|
|
18
18
|
};
|
|
19
|
+
export declare type asyncVisitorFn<T> = (key: number | 'key' | 'value' | null, node: T, path: readonly (Document | Node | Pair)[]) => void | symbol | number | Node | Pair | Promise<void | symbol | number | Node | Pair>;
|
|
20
|
+
export declare type asyncVisitor = asyncVisitorFn<unknown> | {
|
|
21
|
+
Alias?: asyncVisitorFn<Alias>;
|
|
22
|
+
Collection?: asyncVisitorFn<YAMLMap | YAMLSeq>;
|
|
23
|
+
Map?: asyncVisitorFn<YAMLMap>;
|
|
24
|
+
Node?: asyncVisitorFn<Alias | Scalar | YAMLMap | YAMLSeq>;
|
|
25
|
+
Pair?: asyncVisitorFn<Pair>;
|
|
26
|
+
Scalar?: asyncVisitorFn<Scalar>;
|
|
27
|
+
Seq?: asyncVisitorFn<YAMLSeq>;
|
|
28
|
+
Value?: asyncVisitorFn<Scalar | YAMLMap | YAMLSeq>;
|
|
29
|
+
};
|
|
19
30
|
/**
|
|
20
31
|
* Apply a visitor to an AST node or document.
|
|
21
32
|
*
|
|
@@ -46,18 +57,46 @@ export declare type visitor = visitorFn<unknown> | {
|
|
|
46
57
|
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
47
58
|
* specific defined one will be used for each node.
|
|
48
59
|
*/
|
|
49
|
-
export declare function visit(node: Node | Document | null, visitor:
|
|
50
|
-
Alias?: visitorFn<Alias>;
|
|
51
|
-
Collection?: visitorFn<YAMLMap | YAMLSeq>;
|
|
52
|
-
Map?: visitorFn<YAMLMap>;
|
|
53
|
-
Node?: visitorFn<Alias | Scalar | YAMLMap | YAMLSeq>;
|
|
54
|
-
Pair?: visitorFn<Pair>;
|
|
55
|
-
Scalar?: visitorFn<Scalar>;
|
|
56
|
-
Seq?: visitorFn<YAMLSeq>;
|
|
57
|
-
Value?: visitorFn<Scalar | YAMLMap | YAMLSeq>;
|
|
58
|
-
}): void;
|
|
60
|
+
export declare function visit(node: Node | Document | null, visitor: visitor): void;
|
|
59
61
|
export declare namespace visit {
|
|
60
62
|
var BREAK: symbol;
|
|
61
63
|
var SKIP: symbol;
|
|
62
64
|
var REMOVE: symbol;
|
|
63
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Apply an async visitor to an AST node or document.
|
|
68
|
+
*
|
|
69
|
+
* Walks through the tree (depth-first) starting from `node`, calling a
|
|
70
|
+
* `visitor` function with three arguments:
|
|
71
|
+
* - `key`: For sequence values and map `Pair`, the node's index in the
|
|
72
|
+
* collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
|
|
73
|
+
* `null` for the root node.
|
|
74
|
+
* - `node`: The current node.
|
|
75
|
+
* - `path`: The ancestry of the current node.
|
|
76
|
+
*
|
|
77
|
+
* The return value of the visitor may be used to control the traversal:
|
|
78
|
+
* - `Promise`: Must resolve to one of the following values
|
|
79
|
+
* - `undefined` (default): Do nothing and continue
|
|
80
|
+
* - `visit.SKIP`: Do not visit the children of this node, continue with next
|
|
81
|
+
* sibling
|
|
82
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
83
|
+
* - `visit.REMOVE`: Remove the current node, then continue with the next one
|
|
84
|
+
* - `Node`: Replace the current node, then continue by visiting it
|
|
85
|
+
* - `number`: While iterating the items of a sequence or map, set the index
|
|
86
|
+
* of the next step. This is useful especially if the index of the current
|
|
87
|
+
* node has changed.
|
|
88
|
+
*
|
|
89
|
+
* If `visitor` is a single function, it will be called with all values
|
|
90
|
+
* encountered in the tree, including e.g. `null` values. Alternatively,
|
|
91
|
+
* separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
|
|
92
|
+
* `Alias` and `Scalar` node. To define the same visitor function for more than
|
|
93
|
+
* one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
|
|
94
|
+
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
95
|
+
* specific defined one will be used for each node.
|
|
96
|
+
*/
|
|
97
|
+
export declare function visitAsync(node: Node | Document | null, visitor: asyncVisitor): Promise<void>;
|
|
98
|
+
export declare namespace visitAsync {
|
|
99
|
+
var BREAK: symbol;
|
|
100
|
+
var SKIP: symbol;
|
|
101
|
+
var REMOVE: symbol;
|
|
102
|
+
}
|
|
@@ -36,29 +36,14 @@ const REMOVE = Symbol('remove node');
|
|
|
36
36
|
* specific defined one will be used for each node.
|
|
37
37
|
*/
|
|
38
38
|
function visit(node, visitor) {
|
|
39
|
-
|
|
40
|
-
(visitor.Collection || visitor.Node || visitor.Value)) {
|
|
41
|
-
visitor = Object.assign({
|
|
42
|
-
Alias: visitor.Node,
|
|
43
|
-
Map: visitor.Node,
|
|
44
|
-
Scalar: visitor.Node,
|
|
45
|
-
Seq: visitor.Node
|
|
46
|
-
}, visitor.Value && {
|
|
47
|
-
Map: visitor.Value,
|
|
48
|
-
Scalar: visitor.Value,
|
|
49
|
-
Seq: visitor.Value
|
|
50
|
-
}, visitor.Collection && {
|
|
51
|
-
Map: visitor.Collection,
|
|
52
|
-
Seq: visitor.Collection
|
|
53
|
-
}, visitor);
|
|
54
|
-
}
|
|
39
|
+
const visitor_ = initVisitor(visitor);
|
|
55
40
|
if (Node.isDocument(node)) {
|
|
56
|
-
const cd =
|
|
41
|
+
const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
|
|
57
42
|
if (cd === REMOVE)
|
|
58
43
|
node.contents = null;
|
|
59
44
|
}
|
|
60
45
|
else
|
|
61
|
-
|
|
46
|
+
visit_(null, node, visitor_, Object.freeze([]));
|
|
62
47
|
}
|
|
63
48
|
// Without the `as symbol` casts, TS declares these in the `visit`
|
|
64
49
|
// namespace using `var`, but then complains about that because
|
|
@@ -69,55 +54,104 @@ visit.BREAK = BREAK;
|
|
|
69
54
|
visit.SKIP = SKIP;
|
|
70
55
|
/** Remove the current node */
|
|
71
56
|
visit.REMOVE = REMOVE;
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (visitor.Map)
|
|
78
|
-
ctrl = visitor.Map(key, node, path);
|
|
79
|
-
}
|
|
80
|
-
else if (Node.isSeq(node)) {
|
|
81
|
-
if (visitor.Seq)
|
|
82
|
-
ctrl = visitor.Seq(key, node, path);
|
|
83
|
-
}
|
|
84
|
-
else if (Node.isPair(node)) {
|
|
85
|
-
if (visitor.Pair)
|
|
86
|
-
ctrl = visitor.Pair(key, node, path);
|
|
57
|
+
function visit_(key, node, visitor, path) {
|
|
58
|
+
const ctrl = callVisitor(key, node, visitor, path);
|
|
59
|
+
if (Node.isNode(ctrl) || Node.isPair(ctrl)) {
|
|
60
|
+
replaceNode(key, path, ctrl);
|
|
61
|
+
return visit_(key, ctrl, visitor, path);
|
|
87
62
|
}
|
|
88
|
-
|
|
89
|
-
if (
|
|
90
|
-
|
|
63
|
+
if (typeof ctrl !== 'symbol') {
|
|
64
|
+
if (Node.isCollection(node)) {
|
|
65
|
+
path = Object.freeze(path.concat(node));
|
|
66
|
+
for (let i = 0; i < node.items.length; ++i) {
|
|
67
|
+
const ci = visit_(i, node.items[i], visitor, path);
|
|
68
|
+
if (typeof ci === 'number')
|
|
69
|
+
i = ci - 1;
|
|
70
|
+
else if (ci === BREAK)
|
|
71
|
+
return BREAK;
|
|
72
|
+
else if (ci === REMOVE) {
|
|
73
|
+
node.items.splice(i, 1);
|
|
74
|
+
i -= 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (Node.isPair(node)) {
|
|
79
|
+
path = Object.freeze(path.concat(node));
|
|
80
|
+
const ck = visit_('key', node.key, visitor, path);
|
|
81
|
+
if (ck === BREAK)
|
|
82
|
+
return BREAK;
|
|
83
|
+
else if (ck === REMOVE)
|
|
84
|
+
node.key = null;
|
|
85
|
+
const cv = visit_('value', node.value, visitor, path);
|
|
86
|
+
if (cv === BREAK)
|
|
87
|
+
return BREAK;
|
|
88
|
+
else if (cv === REMOVE)
|
|
89
|
+
node.value = null;
|
|
90
|
+
}
|
|
91
91
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
return ctrl;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Apply an async visitor to an AST node or document.
|
|
96
|
+
*
|
|
97
|
+
* Walks through the tree (depth-first) starting from `node`, calling a
|
|
98
|
+
* `visitor` function with three arguments:
|
|
99
|
+
* - `key`: For sequence values and map `Pair`, the node's index in the
|
|
100
|
+
* collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
|
|
101
|
+
* `null` for the root node.
|
|
102
|
+
* - `node`: The current node.
|
|
103
|
+
* - `path`: The ancestry of the current node.
|
|
104
|
+
*
|
|
105
|
+
* The return value of the visitor may be used to control the traversal:
|
|
106
|
+
* - `Promise`: Must resolve to one of the following values
|
|
107
|
+
* - `undefined` (default): Do nothing and continue
|
|
108
|
+
* - `visit.SKIP`: Do not visit the children of this node, continue with next
|
|
109
|
+
* sibling
|
|
110
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
111
|
+
* - `visit.REMOVE`: Remove the current node, then continue with the next one
|
|
112
|
+
* - `Node`: Replace the current node, then continue by visiting it
|
|
113
|
+
* - `number`: While iterating the items of a sequence or map, set the index
|
|
114
|
+
* of the next step. This is useful especially if the index of the current
|
|
115
|
+
* node has changed.
|
|
116
|
+
*
|
|
117
|
+
* If `visitor` is a single function, it will be called with all values
|
|
118
|
+
* encountered in the tree, including e.g. `null` values. Alternatively,
|
|
119
|
+
* separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
|
|
120
|
+
* `Alias` and `Scalar` node. To define the same visitor function for more than
|
|
121
|
+
* one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
|
|
122
|
+
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
123
|
+
* specific defined one will be used for each node.
|
|
124
|
+
*/
|
|
125
|
+
async function visitAsync(node, visitor) {
|
|
126
|
+
const visitor_ = initVisitor(visitor);
|
|
127
|
+
if (Node.isDocument(node)) {
|
|
128
|
+
const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
|
|
129
|
+
if (cd === REMOVE)
|
|
130
|
+
node.contents = null;
|
|
95
131
|
}
|
|
132
|
+
else
|
|
133
|
+
await visitAsync_(null, node, visitor_, Object.freeze([]));
|
|
134
|
+
}
|
|
135
|
+
// Without the `as symbol` casts, TS declares these in the `visit`
|
|
136
|
+
// namespace using `var`, but then complains about that because
|
|
137
|
+
// `unique symbol` must be `const`.
|
|
138
|
+
/** Terminate visit traversal completely */
|
|
139
|
+
visitAsync.BREAK = BREAK;
|
|
140
|
+
/** Do not visit the children of the current node */
|
|
141
|
+
visitAsync.SKIP = SKIP;
|
|
142
|
+
/** Remove the current node */
|
|
143
|
+
visitAsync.REMOVE = REMOVE;
|
|
144
|
+
async function visitAsync_(key, node, visitor, path) {
|
|
145
|
+
const ctrl = await callVisitor(key, node, visitor, path);
|
|
96
146
|
if (Node.isNode(ctrl) || Node.isPair(ctrl)) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
parent.items[key] = ctrl;
|
|
100
|
-
}
|
|
101
|
-
else if (Node.isPair(parent)) {
|
|
102
|
-
if (key === 'key')
|
|
103
|
-
parent.key = ctrl;
|
|
104
|
-
else
|
|
105
|
-
parent.value = ctrl;
|
|
106
|
-
}
|
|
107
|
-
else if (Node.isDocument(parent)) {
|
|
108
|
-
parent.contents = ctrl;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const pt = Node.isAlias(parent) ? 'alias' : 'scalar';
|
|
112
|
-
throw new Error(`Cannot replace node with ${pt} parent`);
|
|
113
|
-
}
|
|
114
|
-
return _visit(key, ctrl, visitor, path);
|
|
147
|
+
replaceNode(key, path, ctrl);
|
|
148
|
+
return visitAsync_(key, ctrl, visitor, path);
|
|
115
149
|
}
|
|
116
150
|
if (typeof ctrl !== 'symbol') {
|
|
117
151
|
if (Node.isCollection(node)) {
|
|
118
152
|
path = Object.freeze(path.concat(node));
|
|
119
153
|
for (let i = 0; i < node.items.length; ++i) {
|
|
120
|
-
const ci =
|
|
154
|
+
const ci = await visitAsync_(i, node.items[i], visitor, path);
|
|
121
155
|
if (typeof ci === 'number')
|
|
122
156
|
i = ci - 1;
|
|
123
157
|
else if (ci === BREAK)
|
|
@@ -130,12 +164,12 @@ function _visit(key, node, visitor, path) {
|
|
|
130
164
|
}
|
|
131
165
|
else if (Node.isPair(node)) {
|
|
132
166
|
path = Object.freeze(path.concat(node));
|
|
133
|
-
const ck =
|
|
167
|
+
const ck = await visitAsync_('key', node.key, visitor, path);
|
|
134
168
|
if (ck === BREAK)
|
|
135
169
|
return BREAK;
|
|
136
170
|
else if (ck === REMOVE)
|
|
137
171
|
node.key = null;
|
|
138
|
-
const cv =
|
|
172
|
+
const cv = await visitAsync_('value', node.value, visitor, path);
|
|
139
173
|
if (cv === BREAK)
|
|
140
174
|
return BREAK;
|
|
141
175
|
else if (cv === REMOVE)
|
|
@@ -144,5 +178,60 @@ function _visit(key, node, visitor, path) {
|
|
|
144
178
|
}
|
|
145
179
|
return ctrl;
|
|
146
180
|
}
|
|
181
|
+
function initVisitor(visitor) {
|
|
182
|
+
if (typeof visitor === 'object' &&
|
|
183
|
+
(visitor.Collection || visitor.Node || visitor.Value)) {
|
|
184
|
+
return Object.assign({
|
|
185
|
+
Alias: visitor.Node,
|
|
186
|
+
Map: visitor.Node,
|
|
187
|
+
Scalar: visitor.Node,
|
|
188
|
+
Seq: visitor.Node
|
|
189
|
+
}, visitor.Value && {
|
|
190
|
+
Map: visitor.Value,
|
|
191
|
+
Scalar: visitor.Value,
|
|
192
|
+
Seq: visitor.Value
|
|
193
|
+
}, visitor.Collection && {
|
|
194
|
+
Map: visitor.Collection,
|
|
195
|
+
Seq: visitor.Collection
|
|
196
|
+
}, visitor);
|
|
197
|
+
}
|
|
198
|
+
return visitor;
|
|
199
|
+
}
|
|
200
|
+
function callVisitor(key, node, visitor, path) {
|
|
201
|
+
var _a, _b, _c, _d, _e;
|
|
202
|
+
if (typeof visitor === 'function')
|
|
203
|
+
return visitor(key, node, path);
|
|
204
|
+
if (Node.isMap(node))
|
|
205
|
+
return (_a = visitor.Map) === null || _a === void 0 ? void 0 : _a.call(visitor, key, node, path);
|
|
206
|
+
if (Node.isSeq(node))
|
|
207
|
+
return (_b = visitor.Seq) === null || _b === void 0 ? void 0 : _b.call(visitor, key, node, path);
|
|
208
|
+
if (Node.isPair(node))
|
|
209
|
+
return (_c = visitor.Pair) === null || _c === void 0 ? void 0 : _c.call(visitor, key, node, path);
|
|
210
|
+
if (Node.isScalar(node))
|
|
211
|
+
return (_d = visitor.Scalar) === null || _d === void 0 ? void 0 : _d.call(visitor, key, node, path);
|
|
212
|
+
if (Node.isAlias(node))
|
|
213
|
+
return (_e = visitor.Alias) === null || _e === void 0 ? void 0 : _e.call(visitor, key, node, path);
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
function replaceNode(key, path, node) {
|
|
217
|
+
const parent = path[path.length - 1];
|
|
218
|
+
if (Node.isCollection(parent)) {
|
|
219
|
+
parent.items[key] = node;
|
|
220
|
+
}
|
|
221
|
+
else if (Node.isPair(parent)) {
|
|
222
|
+
if (key === 'key')
|
|
223
|
+
parent.key = node;
|
|
224
|
+
else
|
|
225
|
+
parent.value = node;
|
|
226
|
+
}
|
|
227
|
+
else if (Node.isDocument(parent)) {
|
|
228
|
+
parent.contents = node;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const pt = Node.isAlias(parent) ? 'alias' : 'scalar';
|
|
232
|
+
throw new Error(`Cannot replace node with ${pt} parent`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
147
235
|
|
|
148
236
|
exports.visit = visit;
|
|
237
|
+
exports.visitAsync = visitAsync;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yaml",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-11",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"author": "Eemeli Aro <eemeli@gmail.com>",
|
|
6
6
|
"repository": "github:eemeli/yaml",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"@babel/plugin-transform-typescript": "^7.12.17",
|
|
71
71
|
"@babel/preset-env": "^7.12.11",
|
|
72
72
|
"@rollup/plugin-babel": "^5.2.3",
|
|
73
|
-
"@rollup/plugin-replace": "^
|
|
73
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
74
74
|
"@rollup/plugin-typescript": "^8.1.1",
|
|
75
75
|
"@types/jest": "^27.0.1",
|
|
76
|
-
"@types/node": "^
|
|
76
|
+
"@types/node": "^12.20.47",
|
|
77
77
|
"@typescript-eslint/eslint-plugin": "^5.3.1",
|
|
78
78
|
"@typescript-eslint/parser": "^5.3.1",
|
|
79
79
|
"babel-jest": "^27.0.1",
|
package/package.json
CHANGED
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
"json-schema": "^0.4.0",
|
|
76
76
|
"markmac": "^0.1.146",
|
|
77
77
|
"npm-check-updates": "^12",
|
|
78
|
-
"prettier": "^2.6.
|
|
78
|
+
"prettier": "^2.6.1",
|
|
79
79
|
"standard-version": "^9",
|
|
80
|
-
"ts-jest": "^27.1.
|
|
80
|
+
"ts-jest": "^27.1.4",
|
|
81
81
|
"typescript": "^3.9.10"
|
|
82
82
|
},
|
|
83
83
|
"dependencies": {
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
},
|
|
122
122
|
"main": "lib/index.js",
|
|
123
123
|
"license": "Apache-2.0",
|
|
124
|
-
"version": "0.53.
|
|
124
|
+
"version": "0.53.13",
|
|
125
125
|
"jest": {
|
|
126
126
|
"testMatch": [
|
|
127
127
|
"<rootDir>/src/**/__tests__/**/*.ts?(x)",
|
package/releasetag.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
v0.53.
|
|
1
|
+
v0.53.13
|
package/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.53.
|
|
1
|
+
0.53.13
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `yaml` defines document-specific options in three places: as an argument of
|
|
3
|
-
* parse, create and stringify calls, in the values of `YAML.defaultOptions`,
|
|
4
|
-
* and in the version-dependent `YAML.Document.defaults` object. Values set in
|
|
5
|
-
* `YAML.defaultOptions` override version-dependent defaults, and argument
|
|
6
|
-
* options override both.
|
|
7
|
-
*/
|
|
8
|
-
const defaultOptions = {
|
|
9
|
-
intAsBigInt: false,
|
|
10
|
-
keepSourceTokens: false,
|
|
11
|
-
logLevel: 'warn',
|
|
12
|
-
prettyErrors: true,
|
|
13
|
-
strict: true,
|
|
14
|
-
uniqueKeys: true,
|
|
15
|
-
version: '1.2'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { defaultOptions };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* `yaml` defines document-specific options in three places: as an argument of
|
|
5
|
-
* parse, create and stringify calls, in the values of `YAML.defaultOptions`,
|
|
6
|
-
* and in the version-dependent `YAML.Document.defaults` object. Values set in
|
|
7
|
-
* `YAML.defaultOptions` override version-dependent defaults, and argument
|
|
8
|
-
* options override both.
|
|
9
|
-
*/
|
|
10
|
-
const defaultOptions = {
|
|
11
|
-
intAsBigInt: false,
|
|
12
|
-
keepSourceTokens: false,
|
|
13
|
-
logLevel: 'warn',
|
|
14
|
-
prettyErrors: true,
|
|
15
|
-
strict: true,
|
|
16
|
-
uniqueKeys: true,
|
|
17
|
-
version: '1.2'
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
exports.defaultOptions = defaultOptions;
|