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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDocument,
|
|
1
|
+
import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/Node.js';
|
|
2
2
|
|
|
3
3
|
const BREAK = Symbol('break visit');
|
|
4
4
|
const SKIP = Symbol('skip children');
|
|
@@ -34,29 +34,14 @@ const REMOVE = Symbol('remove node');
|
|
|
34
34
|
* specific defined one will be used for each node.
|
|
35
35
|
*/
|
|
36
36
|
function visit(node, visitor) {
|
|
37
|
-
|
|
38
|
-
(visitor.Collection || visitor.Node || visitor.Value)) {
|
|
39
|
-
visitor = Object.assign({
|
|
40
|
-
Alias: visitor.Node,
|
|
41
|
-
Map: visitor.Node,
|
|
42
|
-
Scalar: visitor.Node,
|
|
43
|
-
Seq: visitor.Node
|
|
44
|
-
}, visitor.Value && {
|
|
45
|
-
Map: visitor.Value,
|
|
46
|
-
Scalar: visitor.Value,
|
|
47
|
-
Seq: visitor.Value
|
|
48
|
-
}, visitor.Collection && {
|
|
49
|
-
Map: visitor.Collection,
|
|
50
|
-
Seq: visitor.Collection
|
|
51
|
-
}, visitor);
|
|
52
|
-
}
|
|
37
|
+
const visitor_ = initVisitor(visitor);
|
|
53
38
|
if (isDocument(node)) {
|
|
54
|
-
const cd =
|
|
39
|
+
const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
|
|
55
40
|
if (cd === REMOVE)
|
|
56
41
|
node.contents = null;
|
|
57
42
|
}
|
|
58
43
|
else
|
|
59
|
-
|
|
44
|
+
visit_(null, node, visitor_, Object.freeze([]));
|
|
60
45
|
}
|
|
61
46
|
// Without the `as symbol` casts, TS declares these in the `visit`
|
|
62
47
|
// namespace using `var`, but then complains about that because
|
|
@@ -67,55 +52,104 @@ visit.BREAK = BREAK;
|
|
|
67
52
|
visit.SKIP = SKIP;
|
|
68
53
|
/** Remove the current node */
|
|
69
54
|
visit.REMOVE = REMOVE;
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (visitor.Map)
|
|
76
|
-
ctrl = visitor.Map(key, node, path);
|
|
77
|
-
}
|
|
78
|
-
else if (isSeq(node)) {
|
|
79
|
-
if (visitor.Seq)
|
|
80
|
-
ctrl = visitor.Seq(key, node, path);
|
|
81
|
-
}
|
|
82
|
-
else if (isPair(node)) {
|
|
83
|
-
if (visitor.Pair)
|
|
84
|
-
ctrl = visitor.Pair(key, node, path);
|
|
55
|
+
function visit_(key, node, visitor, path) {
|
|
56
|
+
const ctrl = callVisitor(key, node, visitor, path);
|
|
57
|
+
if (isNode(ctrl) || isPair(ctrl)) {
|
|
58
|
+
replaceNode(key, path, ctrl);
|
|
59
|
+
return visit_(key, ctrl, visitor, path);
|
|
85
60
|
}
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
61
|
+
if (typeof ctrl !== 'symbol') {
|
|
62
|
+
if (isCollection(node)) {
|
|
63
|
+
path = Object.freeze(path.concat(node));
|
|
64
|
+
for (let i = 0; i < node.items.length; ++i) {
|
|
65
|
+
const ci = visit_(i, node.items[i], visitor, path);
|
|
66
|
+
if (typeof ci === 'number')
|
|
67
|
+
i = ci - 1;
|
|
68
|
+
else if (ci === BREAK)
|
|
69
|
+
return BREAK;
|
|
70
|
+
else if (ci === REMOVE) {
|
|
71
|
+
node.items.splice(i, 1);
|
|
72
|
+
i -= 1;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (isPair(node)) {
|
|
77
|
+
path = Object.freeze(path.concat(node));
|
|
78
|
+
const ck = visit_('key', node.key, visitor, path);
|
|
79
|
+
if (ck === BREAK)
|
|
80
|
+
return BREAK;
|
|
81
|
+
else if (ck === REMOVE)
|
|
82
|
+
node.key = null;
|
|
83
|
+
const cv = visit_('value', node.value, visitor, path);
|
|
84
|
+
if (cv === BREAK)
|
|
85
|
+
return BREAK;
|
|
86
|
+
else if (cv === REMOVE)
|
|
87
|
+
node.value = null;
|
|
88
|
+
}
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
return ctrl;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Apply an async visitor to an AST node or document.
|
|
94
|
+
*
|
|
95
|
+
* Walks through the tree (depth-first) starting from `node`, calling a
|
|
96
|
+
* `visitor` function with three arguments:
|
|
97
|
+
* - `key`: For sequence values and map `Pair`, the node's index in the
|
|
98
|
+
* collection. Within a `Pair`, `'key'` or `'value'`, correspondingly.
|
|
99
|
+
* `null` for the root node.
|
|
100
|
+
* - `node`: The current node.
|
|
101
|
+
* - `path`: The ancestry of the current node.
|
|
102
|
+
*
|
|
103
|
+
* The return value of the visitor may be used to control the traversal:
|
|
104
|
+
* - `Promise`: Must resolve to one of the following values
|
|
105
|
+
* - `undefined` (default): Do nothing and continue
|
|
106
|
+
* - `visit.SKIP`: Do not visit the children of this node, continue with next
|
|
107
|
+
* sibling
|
|
108
|
+
* - `visit.BREAK`: Terminate traversal completely
|
|
109
|
+
* - `visit.REMOVE`: Remove the current node, then continue with the next one
|
|
110
|
+
* - `Node`: Replace the current node, then continue by visiting it
|
|
111
|
+
* - `number`: While iterating the items of a sequence or map, set the index
|
|
112
|
+
* of the next step. This is useful especially if the index of the current
|
|
113
|
+
* node has changed.
|
|
114
|
+
*
|
|
115
|
+
* If `visitor` is a single function, it will be called with all values
|
|
116
|
+
* encountered in the tree, including e.g. `null` values. Alternatively,
|
|
117
|
+
* separate visitor functions may be defined for each `Map`, `Pair`, `Seq`,
|
|
118
|
+
* `Alias` and `Scalar` node. To define the same visitor function for more than
|
|
119
|
+
* one node type, use the `Collection` (map and seq), `Value` (map, seq & scalar)
|
|
120
|
+
* and `Node` (alias, map, seq & scalar) targets. Of all these, only the most
|
|
121
|
+
* specific defined one will be used for each node.
|
|
122
|
+
*/
|
|
123
|
+
async function visitAsync(node, visitor) {
|
|
124
|
+
const visitor_ = initVisitor(visitor);
|
|
125
|
+
if (isDocument(node)) {
|
|
126
|
+
const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
|
|
127
|
+
if (cd === REMOVE)
|
|
128
|
+
node.contents = null;
|
|
93
129
|
}
|
|
130
|
+
else
|
|
131
|
+
await visitAsync_(null, node, visitor_, Object.freeze([]));
|
|
132
|
+
}
|
|
133
|
+
// Without the `as symbol` casts, TS declares these in the `visit`
|
|
134
|
+
// namespace using `var`, but then complains about that because
|
|
135
|
+
// `unique symbol` must be `const`.
|
|
136
|
+
/** Terminate visit traversal completely */
|
|
137
|
+
visitAsync.BREAK = BREAK;
|
|
138
|
+
/** Do not visit the children of the current node */
|
|
139
|
+
visitAsync.SKIP = SKIP;
|
|
140
|
+
/** Remove the current node */
|
|
141
|
+
visitAsync.REMOVE = REMOVE;
|
|
142
|
+
async function visitAsync_(key, node, visitor, path) {
|
|
143
|
+
const ctrl = await callVisitor(key, node, visitor, path);
|
|
94
144
|
if (isNode(ctrl) || isPair(ctrl)) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
parent.items[key] = ctrl;
|
|
98
|
-
}
|
|
99
|
-
else if (isPair(parent)) {
|
|
100
|
-
if (key === 'key')
|
|
101
|
-
parent.key = ctrl;
|
|
102
|
-
else
|
|
103
|
-
parent.value = ctrl;
|
|
104
|
-
}
|
|
105
|
-
else if (isDocument(parent)) {
|
|
106
|
-
parent.contents = ctrl;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const pt = isAlias(parent) ? 'alias' : 'scalar';
|
|
110
|
-
throw new Error(`Cannot replace node with ${pt} parent`);
|
|
111
|
-
}
|
|
112
|
-
return _visit(key, ctrl, visitor, path);
|
|
145
|
+
replaceNode(key, path, ctrl);
|
|
146
|
+
return visitAsync_(key, ctrl, visitor, path);
|
|
113
147
|
}
|
|
114
148
|
if (typeof ctrl !== 'symbol') {
|
|
115
149
|
if (isCollection(node)) {
|
|
116
150
|
path = Object.freeze(path.concat(node));
|
|
117
151
|
for (let i = 0; i < node.items.length; ++i) {
|
|
118
|
-
const ci =
|
|
152
|
+
const ci = await visitAsync_(i, node.items[i], visitor, path);
|
|
119
153
|
if (typeof ci === 'number')
|
|
120
154
|
i = ci - 1;
|
|
121
155
|
else if (ci === BREAK)
|
|
@@ -128,12 +162,12 @@ function _visit(key, node, visitor, path) {
|
|
|
128
162
|
}
|
|
129
163
|
else if (isPair(node)) {
|
|
130
164
|
path = Object.freeze(path.concat(node));
|
|
131
|
-
const ck =
|
|
165
|
+
const ck = await visitAsync_('key', node.key, visitor, path);
|
|
132
166
|
if (ck === BREAK)
|
|
133
167
|
return BREAK;
|
|
134
168
|
else if (ck === REMOVE)
|
|
135
169
|
node.key = null;
|
|
136
|
-
const cv =
|
|
170
|
+
const cv = await visitAsync_('value', node.value, visitor, path);
|
|
137
171
|
if (cv === BREAK)
|
|
138
172
|
return BREAK;
|
|
139
173
|
else if (cv === REMOVE)
|
|
@@ -142,5 +176,59 @@ function _visit(key, node, visitor, path) {
|
|
|
142
176
|
}
|
|
143
177
|
return ctrl;
|
|
144
178
|
}
|
|
179
|
+
function initVisitor(visitor) {
|
|
180
|
+
if (typeof visitor === 'object' &&
|
|
181
|
+
(visitor.Collection || visitor.Node || visitor.Value)) {
|
|
182
|
+
return Object.assign({
|
|
183
|
+
Alias: visitor.Node,
|
|
184
|
+
Map: visitor.Node,
|
|
185
|
+
Scalar: visitor.Node,
|
|
186
|
+
Seq: visitor.Node
|
|
187
|
+
}, visitor.Value && {
|
|
188
|
+
Map: visitor.Value,
|
|
189
|
+
Scalar: visitor.Value,
|
|
190
|
+
Seq: visitor.Value
|
|
191
|
+
}, visitor.Collection && {
|
|
192
|
+
Map: visitor.Collection,
|
|
193
|
+
Seq: visitor.Collection
|
|
194
|
+
}, visitor);
|
|
195
|
+
}
|
|
196
|
+
return visitor;
|
|
197
|
+
}
|
|
198
|
+
function callVisitor(key, node, visitor, path) {
|
|
199
|
+
var _a, _b, _c, _d, _e;
|
|
200
|
+
if (typeof visitor === 'function')
|
|
201
|
+
return visitor(key, node, path);
|
|
202
|
+
if (isMap(node))
|
|
203
|
+
return (_a = visitor.Map) === null || _a === void 0 ? void 0 : _a.call(visitor, key, node, path);
|
|
204
|
+
if (isSeq(node))
|
|
205
|
+
return (_b = visitor.Seq) === null || _b === void 0 ? void 0 : _b.call(visitor, key, node, path);
|
|
206
|
+
if (isPair(node))
|
|
207
|
+
return (_c = visitor.Pair) === null || _c === void 0 ? void 0 : _c.call(visitor, key, node, path);
|
|
208
|
+
if (isScalar(node))
|
|
209
|
+
return (_d = visitor.Scalar) === null || _d === void 0 ? void 0 : _d.call(visitor, key, node, path);
|
|
210
|
+
if (isAlias(node))
|
|
211
|
+
return (_e = visitor.Alias) === null || _e === void 0 ? void 0 : _e.call(visitor, key, node, path);
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
function replaceNode(key, path, node) {
|
|
215
|
+
const parent = path[path.length - 1];
|
|
216
|
+
if (isCollection(parent)) {
|
|
217
|
+
parent.items[key] = node;
|
|
218
|
+
}
|
|
219
|
+
else if (isPair(parent)) {
|
|
220
|
+
if (key === 'key')
|
|
221
|
+
parent.key = node;
|
|
222
|
+
else
|
|
223
|
+
parent.value = node;
|
|
224
|
+
}
|
|
225
|
+
else if (isDocument(parent)) {
|
|
226
|
+
parent.contents = node;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const pt = isAlias(parent) ? 'alias' : 'scalar';
|
|
230
|
+
throw new Error(`Cannot replace node with ${pt} parent`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
145
233
|
|
|
146
|
-
export { visit };
|
|
234
|
+
export { visit, visitAsync };
|
|
@@ -22,7 +22,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
|
|
|
22
22
|
startOnNewline: true
|
|
23
23
|
});
|
|
24
24
|
if (props.found) {
|
|
25
|
-
doc.directives.
|
|
25
|
+
doc.directives.docStart = true;
|
|
26
26
|
if (value &&
|
|
27
27
|
(value.type === 'block-map' || value.type === 'block-seq') &&
|
|
28
28
|
!props.hasNewline)
|
|
@@ -10,6 +10,7 @@ const CN = { composeNode, composeEmptyNode };
|
|
|
10
10
|
function composeNode(ctx, token, props, onError) {
|
|
11
11
|
const { spaceBefore, comment, anchor, tag } = props;
|
|
12
12
|
let node;
|
|
13
|
+
let isSrcToken = true;
|
|
13
14
|
switch (token.type) {
|
|
14
15
|
case 'alias':
|
|
15
16
|
node = composeAlias(ctx, token, onError);
|
|
@@ -31,9 +32,14 @@ function composeNode(ctx, token, props, onError) {
|
|
|
31
32
|
if (anchor)
|
|
32
33
|
node.anchor = anchor.source.substring(1);
|
|
33
34
|
break;
|
|
34
|
-
default:
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
default: {
|
|
36
|
+
const message = token.type === 'error'
|
|
37
|
+
? token.message
|
|
38
|
+
: `Unsupported token (type: ${token.type})`;
|
|
39
|
+
onError(token, 'UNEXPECTED_TOKEN', message);
|
|
40
|
+
node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
|
|
41
|
+
isSrcToken = false;
|
|
42
|
+
}
|
|
37
43
|
}
|
|
38
44
|
if (anchor && node.anchor === '')
|
|
39
45
|
onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
|
|
@@ -45,7 +51,8 @@ function composeNode(ctx, token, props, onError) {
|
|
|
45
51
|
else
|
|
46
52
|
node.commentBefore = comment;
|
|
47
53
|
}
|
|
48
|
-
|
|
54
|
+
// @ts-expect-error Type checking misses meaning of isSrcToken
|
|
55
|
+
if (ctx.options.keepSourceTokens && isSrcToken)
|
|
49
56
|
node.srcToken = token;
|
|
50
57
|
return node;
|
|
51
58
|
}
|
|
@@ -72,6 +79,8 @@ function composeAlias({ options }, { offset, source, end }, onError) {
|
|
|
72
79
|
const alias = new Alias.Alias(source.substring(1));
|
|
73
80
|
if (alias.source === '')
|
|
74
81
|
onError(offset, 'BAD_ALIAS', 'Alias cannot be an empty string');
|
|
82
|
+
if (alias.source.endsWith(':'))
|
|
83
|
+
onError(offset + source.length - 1, 'BAD_ALIAS', 'Alias ending in : is ambiguous', true);
|
|
75
84
|
const valueEnd = offset + source.length;
|
|
76
85
|
const re = resolveEnd.resolveEnd(end, valueEnd, options.strict, onError);
|
|
77
86
|
alias.range = [offset, valueEnd, re.offset];
|
|
@@ -2,7 +2,7 @@ import { Directives } from '../doc/directives.js';
|
|
|
2
2
|
import { Document } from '../doc/Document.js';
|
|
3
3
|
import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
|
|
4
4
|
import { Range } from '../nodes/Node.js';
|
|
5
|
-
import { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
|
|
5
|
+
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
|
|
6
6
|
import type { Token } from '../parse/cst.js';
|
|
7
7
|
declare type ErrorSource = number | [number, number] | Range | {
|
|
8
8
|
offset: number;
|
|
@@ -4,7 +4,6 @@ var directives = require('../doc/directives.js');
|
|
|
4
4
|
var Document = require('../doc/Document.js');
|
|
5
5
|
var errors = require('../errors.js');
|
|
6
6
|
var Node = require('../nodes/Node.js');
|
|
7
|
-
var options = require('../options.js');
|
|
8
7
|
var composeDoc = require('./compose-doc.js');
|
|
9
8
|
var resolveEnd = require('./resolve-end.js');
|
|
10
9
|
|
|
@@ -57,7 +56,7 @@ function parsePrelude(prelude) {
|
|
|
57
56
|
* ```
|
|
58
57
|
*/
|
|
59
58
|
class Composer {
|
|
60
|
-
constructor(options
|
|
59
|
+
constructor(options = {}) {
|
|
61
60
|
this.doc = null;
|
|
62
61
|
this.atDirectives = false;
|
|
63
62
|
this.prelude = [];
|
|
@@ -70,10 +69,8 @@ class Composer {
|
|
|
70
69
|
else
|
|
71
70
|
this.errors.push(new errors.YAMLParseError(pos, code, message));
|
|
72
71
|
};
|
|
73
|
-
this.directives = new directives.Directives({
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
this.options = options$1;
|
|
72
|
+
this.directives = new directives.Directives({ version: options.version || '1.2' });
|
|
73
|
+
this.options = options;
|
|
77
74
|
}
|
|
78
75
|
decorate(doc, afterDoc) {
|
|
79
76
|
const { comment, afterEmptyLine } = parsePrelude(this.prelude);
|
|
@@ -83,7 +80,7 @@ class Composer {
|
|
|
83
80
|
if (afterDoc) {
|
|
84
81
|
doc.comment = doc.comment ? `${doc.comment}\n${comment}` : comment;
|
|
85
82
|
}
|
|
86
|
-
else if (afterEmptyLine || doc.directives.
|
|
83
|
+
else if (afterEmptyLine || doc.directives.docStart || !dc) {
|
|
87
84
|
doc.commentBefore = comment;
|
|
88
85
|
}
|
|
89
86
|
else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) {
|
|
@@ -150,8 +147,8 @@ class Composer {
|
|
|
150
147
|
break;
|
|
151
148
|
case 'document': {
|
|
152
149
|
const doc = composeDoc.composeDoc(this.options, this.directives, token, this.onError);
|
|
153
|
-
if (this.atDirectives && !doc.directives.
|
|
154
|
-
this.onError(token, 'MISSING_CHAR', 'Missing directives-end indicator line');
|
|
150
|
+
if (this.atDirectives && !doc.directives.docStart)
|
|
151
|
+
this.onError(token, 'MISSING_CHAR', 'Missing directives-end/doc-start indicator line');
|
|
155
152
|
this.decorate(doc, false);
|
|
156
153
|
if (this.doc)
|
|
157
154
|
yield this.doc;
|
|
@@ -183,6 +180,7 @@ class Composer {
|
|
|
183
180
|
this.errors.push(new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', msg));
|
|
184
181
|
break;
|
|
185
182
|
}
|
|
183
|
+
this.doc.directives.docEnd = true;
|
|
186
184
|
const end = resolveEnd.resolveEnd(token.end, token.offset + token.source.length, this.doc.options.strict, this.onError);
|
|
187
185
|
this.decorate(this.doc, true);
|
|
188
186
|
if (end.comment) {
|
|
@@ -19,8 +19,10 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
19
19
|
break;
|
|
20
20
|
}
|
|
21
21
|
// shortcut for empty contents
|
|
22
|
-
if (
|
|
23
|
-
const value = header.chomp === '+'
|
|
22
|
+
if (chompStart === 0) {
|
|
23
|
+
const value = header.chomp === '+' && lines.length > 0
|
|
24
|
+
? '\n'.repeat(Math.max(1, lines.length - 1))
|
|
25
|
+
: '';
|
|
24
26
|
let end = start + header.length;
|
|
25
27
|
if (scalar.source)
|
|
26
28
|
end += scalar.source.length;
|
|
@@ -48,6 +50,11 @@ function resolveBlockScalar(scalar, strict, onError) {
|
|
|
48
50
|
}
|
|
49
51
|
offset += indent.length + content.length + 1;
|
|
50
52
|
}
|
|
53
|
+
// include trailing more-indented empty lines in content
|
|
54
|
+
for (let i = lines.length - 1; i >= chompStart; --i) {
|
|
55
|
+
if (lines[i][0].length > trimIndent)
|
|
56
|
+
chompStart = i + 1;
|
|
57
|
+
}
|
|
51
58
|
let value = '';
|
|
52
59
|
let sep = '';
|
|
53
60
|
let prevMoreIndented = false;
|
|
@@ -61,6 +61,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
61
61
|
case 'anchor':
|
|
62
62
|
if (anchor)
|
|
63
63
|
onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
|
|
64
|
+
if (token.source.endsWith(':'))
|
|
65
|
+
onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
|
|
64
66
|
anchor = token;
|
|
65
67
|
if (start === null)
|
|
66
68
|
start = token.offset;
|
|
@@ -5,7 +5,7 @@ import { Pair } from '../nodes/Pair.js';
|
|
|
5
5
|
import type { Scalar } from '../nodes/Scalar.js';
|
|
6
6
|
import type { YAMLMap } from '../nodes/YAMLMap.js';
|
|
7
7
|
import type { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
8
|
-
import { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
|
|
8
|
+
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
|
|
9
9
|
import { Schema } from '../schema/Schema.js';
|
|
10
10
|
import { Directives } from './directives.js';
|
|
11
11
|
export declare type Replacer = any[] | ((key: any, value: any) => unknown);
|
|
@@ -5,7 +5,6 @@ var Collection = require('../nodes/Collection.js');
|
|
|
5
5
|
var Node = require('../nodes/Node.js');
|
|
6
6
|
var Pair = require('../nodes/Pair.js');
|
|
7
7
|
var toJS = require('../nodes/toJS.js');
|
|
8
|
-
var options = require('../options.js');
|
|
9
8
|
var Schema = require('../schema/Schema.js');
|
|
10
9
|
var stringify = require('../stringify/stringify.js');
|
|
11
10
|
var stringifyDocument = require('../stringify/stringifyDocument.js');
|
|
@@ -15,7 +14,7 @@ var createNode = require('./createNode.js');
|
|
|
15
14
|
var directives = require('./directives.js');
|
|
16
15
|
|
|
17
16
|
class Document {
|
|
18
|
-
constructor(value, replacer, options
|
|
17
|
+
constructor(value, replacer, options) {
|
|
19
18
|
/** A comment before this Document */
|
|
20
19
|
this.commentBefore = null;
|
|
21
20
|
/** A comment immediately after this Document */
|
|
@@ -29,25 +28,33 @@ class Document {
|
|
|
29
28
|
if (typeof replacer === 'function' || Array.isArray(replacer)) {
|
|
30
29
|
_replacer = replacer;
|
|
31
30
|
}
|
|
32
|
-
else if (options
|
|
33
|
-
options
|
|
31
|
+
else if (options === undefined && replacer) {
|
|
32
|
+
options = replacer;
|
|
34
33
|
replacer = undefined;
|
|
35
34
|
}
|
|
36
|
-
const opt = Object.assign({
|
|
35
|
+
const opt = Object.assign({
|
|
36
|
+
intAsBigInt: false,
|
|
37
|
+
keepSourceTokens: false,
|
|
38
|
+
logLevel: 'warn',
|
|
39
|
+
prettyErrors: true,
|
|
40
|
+
strict: true,
|
|
41
|
+
uniqueKeys: true,
|
|
42
|
+
version: '1.2'
|
|
43
|
+
}, options);
|
|
37
44
|
this.options = opt;
|
|
38
45
|
let { version } = opt;
|
|
39
|
-
if (options
|
|
40
|
-
this.directives = options
|
|
46
|
+
if (options === null || options === void 0 ? void 0 : options.directives) {
|
|
47
|
+
this.directives = options.directives.atDocument();
|
|
41
48
|
if (this.directives.yaml.explicit)
|
|
42
49
|
version = this.directives.yaml.version;
|
|
43
50
|
}
|
|
44
51
|
else
|
|
45
52
|
this.directives = new directives.Directives({ version });
|
|
46
|
-
this.setSchema(version, options
|
|
53
|
+
this.setSchema(version, options);
|
|
47
54
|
if (value === undefined)
|
|
48
55
|
this.contents = null;
|
|
49
56
|
else {
|
|
50
|
-
this.contents = this.createNode(value, _replacer, options
|
|
57
|
+
this.contents = this.createNode(value, _replacer, options);
|
|
51
58
|
}
|
|
52
59
|
}
|
|
53
60
|
/**
|
|
@@ -11,7 +11,9 @@ export declare class Directives {
|
|
|
11
11
|
* The directives-end/doc-start marker `---`. If `null`, a marker may still be
|
|
12
12
|
* included in the document's stringified representation.
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
docStart: true | null;
|
|
15
|
+
/** The doc-end marker `...`. */
|
|
16
|
+
docEnd: boolean;
|
|
15
17
|
/**
|
|
16
18
|
* Used when parsing YAML 1.1, where:
|
|
17
19
|
* > If the document specifies no directives, it is parsed using the same
|
|
@@ -18,13 +18,15 @@ class Directives {
|
|
|
18
18
|
* The directives-end/doc-start marker `---`. If `null`, a marker may still be
|
|
19
19
|
* included in the document's stringified representation.
|
|
20
20
|
*/
|
|
21
|
-
this.
|
|
21
|
+
this.docStart = null;
|
|
22
|
+
/** The doc-end marker `...`. */
|
|
23
|
+
this.docEnd = false;
|
|
22
24
|
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
23
25
|
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
24
26
|
}
|
|
25
27
|
clone() {
|
|
26
28
|
const copy = new Directives(this.yaml, this.tags);
|
|
27
|
-
copy.
|
|
29
|
+
copy.docStart = this.docStart;
|
|
28
30
|
return copy;
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
@@ -73,7 +75,7 @@ class Directives {
|
|
|
73
75
|
}
|
|
74
76
|
case '%YAML': {
|
|
75
77
|
this.yaml.explicit = true;
|
|
76
|
-
if (parts.length
|
|
78
|
+
if (parts.length !== 1) {
|
|
77
79
|
onError(0, '%YAML directive should contain exactly one part');
|
|
78
80
|
return false;
|
|
79
81
|
}
|
|
@@ -83,7 +85,8 @@ class Directives {
|
|
|
83
85
|
return true;
|
|
84
86
|
}
|
|
85
87
|
else {
|
|
86
|
-
|
|
88
|
+
const isValid = /^\d+\.\d+$/.test(version);
|
|
89
|
+
onError(6, `Unsupported YAML version ${version}`, isValid);
|
|
87
90
|
return false;
|
|
88
91
|
}
|
|
89
92
|
}
|
|
@@ -8,7 +8,7 @@ export { Pair } from './nodes/Pair.js';
|
|
|
8
8
|
export { Scalar } from './nodes/Scalar.js';
|
|
9
9
|
export { YAMLMap } from './nodes/YAMLMap.js';
|
|
10
10
|
export { YAMLSeq } from './nodes/YAMLSeq.js';
|
|
11
|
-
export { CreateNodeOptions,
|
|
11
|
+
export type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
|
|
12
12
|
export * as CST from './parse/cst.js';
|
|
13
13
|
export { Lexer } from './parse/lexer.js';
|
|
14
14
|
export { LineCounter } from './parse/line-counter.js';
|
|
@@ -16,4 +16,4 @@ export { Parser } from './parse/parser.js';
|
|
|
16
16
|
export { EmptyStream, parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
|
|
17
17
|
export type { TagId, Tags } from './schema/tags';
|
|
18
18
|
export type { CollectionTag, ScalarTag } from './schema/types';
|
|
19
|
-
export { visit, visitor, visitorFn } from './visit.js';
|
|
19
|
+
export { asyncVisitor, asyncVisitorFn, visit, visitAsync, visitor, visitorFn } from './visit.js';
|
|
@@ -10,7 +10,6 @@ var Pair = require('./nodes/Pair.js');
|
|
|
10
10
|
var Scalar = require('./nodes/Scalar.js');
|
|
11
11
|
var YAMLMap = require('./nodes/YAMLMap.js');
|
|
12
12
|
var YAMLSeq = require('./nodes/YAMLSeq.js');
|
|
13
|
-
var options = require('./options.js');
|
|
14
13
|
var cst = require('./parse/cst.js');
|
|
15
14
|
var lexer = require('./parse/lexer.js');
|
|
16
15
|
var lineCounter = require('./parse/line-counter.js');
|
|
@@ -39,7 +38,6 @@ exports.Pair = Pair.Pair;
|
|
|
39
38
|
exports.Scalar = Scalar.Scalar;
|
|
40
39
|
exports.YAMLMap = YAMLMap.YAMLMap;
|
|
41
40
|
exports.YAMLSeq = YAMLSeq.YAMLSeq;
|
|
42
|
-
exports.defaultOptions = options.defaultOptions;
|
|
43
41
|
exports.CST = cst;
|
|
44
42
|
exports.Lexer = lexer.Lexer;
|
|
45
43
|
exports.LineCounter = lineCounter.LineCounter;
|
|
@@ -49,3 +47,4 @@ exports.parseAllDocuments = publicApi.parseAllDocuments;
|
|
|
49
47
|
exports.parseDocument = publicApi.parseDocument;
|
|
50
48
|
exports.stringify = publicApi.stringify;
|
|
51
49
|
exports.visit = visit.visit;
|
|
50
|
+
exports.visitAsync = visit.visitAsync;
|
|
@@ -328,11 +328,3 @@ export declare type ToStringOptions = {
|
|
|
328
328
|
*/
|
|
329
329
|
verifyAliasOrder?: boolean;
|
|
330
330
|
};
|
|
331
|
-
/**
|
|
332
|
-
* `yaml` defines document-specific options in three places: as an argument of
|
|
333
|
-
* parse, create and stringify calls, in the values of `YAML.defaultOptions`,
|
|
334
|
-
* and in the version-dependent `YAML.Document.defaults` object. Values set in
|
|
335
|
-
* `YAML.defaultOptions` override version-dependent defaults, and argument
|
|
336
|
-
* options override both.
|
|
337
|
-
*/
|
|
338
|
-
export declare const defaultOptions: Required<Omit<ParseOptions, 'lineCounter'> & Omit<DocumentOptions, 'directives'>>;
|
|
@@ -359,9 +359,14 @@ class Lexer {
|
|
|
359
359
|
let indent = -1;
|
|
360
360
|
do {
|
|
361
361
|
nl = yield* this.pushNewline();
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
if (nl > 0) {
|
|
363
|
+
sp = yield* this.pushSpaces(false);
|
|
364
364
|
this.indentValue = indent = sp;
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
sp = 0;
|
|
368
|
+
}
|
|
369
|
+
sp += yield* this.pushSpaces(true);
|
|
365
370
|
} while (nl + sp > 0);
|
|
366
371
|
const line = this.getLine();
|
|
367
372
|
if (line === null)
|
|
@@ -535,9 +540,10 @@ class Lexer {
|
|
|
535
540
|
let ch = this.buffer[i];
|
|
536
541
|
if (ch === '\r')
|
|
537
542
|
ch = this.buffer[--i];
|
|
543
|
+
const lastChar = i; // Drop the line if last char not more indented
|
|
538
544
|
while (ch === ' ' || ch === '\t')
|
|
539
545
|
ch = this.buffer[--i];
|
|
540
|
-
if (ch === '\n' && i >= this.pos)
|
|
546
|
+
if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
|
|
541
547
|
nl = i;
|
|
542
548
|
else
|
|
543
549
|
break;
|
|
@@ -620,11 +626,13 @@ class Lexer {
|
|
|
620
626
|
return ((yield* this.pushUntil(isNotAnchorChar)) +
|
|
621
627
|
(yield* this.pushSpaces(true)) +
|
|
622
628
|
(yield* this.pushIndicators()));
|
|
623
|
-
case ':':
|
|
624
|
-
case '?': // this is an error outside flow collections
|
|
625
629
|
case '-': // this is an error
|
|
626
|
-
|
|
627
|
-
|
|
630
|
+
case '?': // this is an error outside flow collections
|
|
631
|
+
case ':': {
|
|
632
|
+
const inFlow = this.flowLevel > 0;
|
|
633
|
+
const ch1 = this.charAt(1);
|
|
634
|
+
if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
|
|
635
|
+
if (!inFlow)
|
|
628
636
|
this.indentNext = this.indentValue + 1;
|
|
629
637
|
else if (this.flowKey)
|
|
630
638
|
this.flowKey = false;
|
|
@@ -632,6 +640,7 @@ class Lexer {
|
|
|
632
640
|
(yield* this.pushSpaces(true)) +
|
|
633
641
|
(yield* this.pushIndicators()));
|
|
634
642
|
}
|
|
643
|
+
}
|
|
635
644
|
}
|
|
636
645
|
return 0;
|
|
637
646
|
}
|