projen 0.91.28 → 0.91.30
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 +42 -17
- 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 +1 -1
- package/lib/github/auto-queue.js +1 -1
- 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/merge-queue.js +1 -1
- package/lib/github/mergify.js +1 -1
- package/lib/github/pr-template.js +1 -1
- package/lib/github/pull-request-backport.js +1 -1
- package/lib/github/pull-request-lint.d.ts +7 -0
- package/lib/github/pull-request-lint.js +3 -2
- 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/run-task.cjs +451 -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 +4 -3
- 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/just-diff/CHANGELOG.md +49 -0
- package/node_modules/just-diff/LICENSE +21 -0
- package/node_modules/just-diff/README.md +86 -0
- package/node_modules/just-diff/index.cjs +230 -0
- package/node_modules/just-diff/index.d.ts +20 -0
- package/node_modules/just-diff/index.mjs +227 -0
- package/node_modules/just-diff/index.tests.ts +65 -0
- package/node_modules/just-diff/package.json +33 -0
- package/node_modules/just-diff/rollup.config.js +3 -0
- package/node_modules/just-diff-apply/CHANGELOG.md +43 -0
- package/node_modules/just-diff-apply/LICENSE +21 -0
- package/node_modules/just-diff-apply/README.md +69 -0
- package/node_modules/just-diff-apply/index.cjs +161 -0
- package/node_modules/just-diff-apply/index.d.ts +17 -0
- package/node_modules/just-diff-apply/index.mjs +158 -0
- package/node_modules/just-diff-apply/index.tests.ts +108 -0
- package/node_modules/just-diff-apply/package.json +34 -0
- package/node_modules/just-diff-apply/rollup.config.js +3 -0
- package/node_modules/parse-conflict-json/LICENSE.md +20 -0
- package/node_modules/parse-conflict-json/README.md +42 -0
- package/node_modules/parse-conflict-json/lib/index.js +104 -0
- package/node_modules/parse-conflict-json/node_modules/json-parse-even-better-errors/LICENSE.md +25 -0
- package/node_modules/parse-conflict-json/node_modules/json-parse-even-better-errors/README.md +96 -0
- package/node_modules/parse-conflict-json/node_modules/json-parse-even-better-errors/lib/index.js +137 -0
- package/node_modules/parse-conflict-json/node_modules/json-parse-even-better-errors/package.json +50 -0
- package/node_modules/parse-conflict-json/package.json +51 -0
- package/package.json +4 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/*
|
|
2
|
+
const obj1 = {a: 3, b: 5};
|
|
3
|
+
diffApply(obj1,
|
|
4
|
+
[
|
|
5
|
+
{ "op": "remove", "path": ['b'] },
|
|
6
|
+
{ "op": "replace", "path": ['a'], "value": 4 },
|
|
7
|
+
{ "op": "add", "path": ['c'], "value": 5 }
|
|
8
|
+
]
|
|
9
|
+
);
|
|
10
|
+
obj1; // {a: 4, c: 5}
|
|
11
|
+
|
|
12
|
+
// using converter to apply jsPatch standard paths
|
|
13
|
+
// see http://jsonpatch.com
|
|
14
|
+
import {diff, jsonPatchPathConverter} from 'just-diff'
|
|
15
|
+
const obj2 = {a: 3, b: 5};
|
|
16
|
+
diffApply(obj2, [
|
|
17
|
+
{ "op": "remove", "path": '/b' },
|
|
18
|
+
{ "op": "replace", "path": '/a', "value": 4 }
|
|
19
|
+
{ "op": "add", "path": '/c', "value": 5 }
|
|
20
|
+
], jsonPatchPathConverter);
|
|
21
|
+
obj2; // {a: 4, c: 5}
|
|
22
|
+
|
|
23
|
+
// arrays
|
|
24
|
+
const obj3 = {a: 4, b: [1, 2, 3]};
|
|
25
|
+
diffApply(obj3, [
|
|
26
|
+
{ "op": "replace", "path": ['a'], "value": 3 }
|
|
27
|
+
{ "op": "replace", "path": ['b', 2], "value": 4 }
|
|
28
|
+
{ "op": "add", "path": ['b', 3], "value": 9 }
|
|
29
|
+
]);
|
|
30
|
+
obj3; // {a: 3, b: [1, 2, 4, 9]}
|
|
31
|
+
|
|
32
|
+
// nested paths
|
|
33
|
+
const obj4 = {a: 4, b: {c: 3}};
|
|
34
|
+
diffApply(obj4, [
|
|
35
|
+
{ "op": "replace", "path": ['a'], "value": 5 }
|
|
36
|
+
{ "op": "remove", "path": ['b', 'c']}
|
|
37
|
+
{ "op": "add", "path": ['b', 'd'], "value": 4 }
|
|
38
|
+
]);
|
|
39
|
+
obj4; // {a: 5, b: {d: 4}}
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
var REMOVE = 'remove';
|
|
43
|
+
var REPLACE = 'replace';
|
|
44
|
+
var ADD = 'add';
|
|
45
|
+
var MOVE = 'move';
|
|
46
|
+
|
|
47
|
+
function diffApply(obj, diff, pathConverter) {
|
|
48
|
+
if (!obj || typeof obj != 'object') {
|
|
49
|
+
throw new Error('base object must be an object or an array');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!Array.isArray(diff)) {
|
|
53
|
+
throw new Error('diff must be an array');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var diffLength = diff.length;
|
|
57
|
+
for (var i = 0; i < diffLength; i++) {
|
|
58
|
+
var thisDiff = diff[i];
|
|
59
|
+
var subObject = obj;
|
|
60
|
+
var thisOp = thisDiff.op;
|
|
61
|
+
|
|
62
|
+
var thisPath = transformPath(pathConverter, thisDiff.path);
|
|
63
|
+
var thisFromPath = thisDiff.from && transformPath(pathConverter, thisDiff.from);
|
|
64
|
+
var toPath, toPathCopy, lastToProp, subToObject, valueToMove;
|
|
65
|
+
|
|
66
|
+
if (thisFromPath) {
|
|
67
|
+
// MOVE only, "fromPath" is effectively path and "path" is toPath
|
|
68
|
+
toPath = thisPath;
|
|
69
|
+
thisPath = thisFromPath;
|
|
70
|
+
|
|
71
|
+
toPathCopy = toPath.slice();
|
|
72
|
+
lastToProp = toPathCopy.pop();
|
|
73
|
+
prototypeCheck(lastToProp);
|
|
74
|
+
if (lastToProp == null) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var thisToProp;
|
|
79
|
+
while (((thisToProp = toPathCopy.shift())) != null) {
|
|
80
|
+
prototypeCheck(thisToProp);
|
|
81
|
+
if (!(thisToProp in subToObject)) {
|
|
82
|
+
subToObject[thisToProp] = {};
|
|
83
|
+
}
|
|
84
|
+
subToObject = subToObject[thisToProp];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var pathCopy = thisPath.slice();
|
|
89
|
+
var lastProp = pathCopy.pop();
|
|
90
|
+
prototypeCheck(lastProp);
|
|
91
|
+
if (lastProp == null) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var thisProp;
|
|
96
|
+
while (((thisProp = pathCopy.shift())) != null) {
|
|
97
|
+
prototypeCheck(thisProp);
|
|
98
|
+
if (!(thisProp in subObject)) {
|
|
99
|
+
subObject[thisProp] = {};
|
|
100
|
+
}
|
|
101
|
+
subObject = subObject[thisProp];
|
|
102
|
+
}
|
|
103
|
+
if (thisOp === REMOVE || thisOp === REPLACE || thisOp === MOVE) {
|
|
104
|
+
var path = thisOp === MOVE ? thisDiff.from : thisDiff.path;
|
|
105
|
+
if (!subObject.hasOwnProperty(lastProp)) {
|
|
106
|
+
throw new Error(['expected to find property', path, 'in object', obj].join(' '));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (thisOp === REMOVE || thisOp === MOVE) {
|
|
110
|
+
if (thisOp === MOVE) {
|
|
111
|
+
valueToMove = subObject[lastProp];
|
|
112
|
+
}
|
|
113
|
+
Array.isArray(subObject) ? subObject.splice(lastProp, 1) : delete subObject[lastProp];
|
|
114
|
+
}
|
|
115
|
+
if (thisOp === REPLACE || thisOp === ADD) {
|
|
116
|
+
subObject[lastProp] = thisDiff.value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (thisOp === MOVE) {
|
|
120
|
+
subObject[lastToProp] = valueToMove;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return subObject;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function transformPath(pathConverter, thisPath) {
|
|
127
|
+
if(pathConverter) {
|
|
128
|
+
thisPath = pathConverter(thisPath);
|
|
129
|
+
if(!Array.isArray(thisPath)) {
|
|
130
|
+
throw new Error([
|
|
131
|
+
'pathConverter must return an array, returned:',
|
|
132
|
+
thisPath,
|
|
133
|
+
].join(' '));
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
if(!Array.isArray(thisPath)) {
|
|
137
|
+
throw new Error([
|
|
138
|
+
'diff path',
|
|
139
|
+
thisPath,
|
|
140
|
+
'must be an array, consider supplying a path converter']
|
|
141
|
+
.join(' '));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return thisPath;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function jsonPatchPathConverter(stringPath) {
|
|
148
|
+
return stringPath.split('/').slice(1);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function prototypeCheck(prop) {
|
|
152
|
+
// coercion is intentional to catch prop values like `['__proto__']`
|
|
153
|
+
if (prop == '__proto__' || prop == 'constructor' || prop == 'prototype') {
|
|
154
|
+
throw new Error('setting of prototype values not supported');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export {diffApply, jsonPatchPathConverter};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import * as diffObj from "./index";
|
|
2
|
+
|
|
3
|
+
const { diffApply, jsonPatchPathConverter } = diffObj;
|
|
4
|
+
const obj1 = {
|
|
5
|
+
a: 2,
|
|
6
|
+
b: 3,
|
|
7
|
+
c: {
|
|
8
|
+
d: 5
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
const arr1 = [1, "bee"];
|
|
12
|
+
|
|
13
|
+
const objOps: diffObj.DiffOps = [
|
|
14
|
+
{
|
|
15
|
+
op: "replace",
|
|
16
|
+
path: ["a"],
|
|
17
|
+
value: 10
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
op: "remove",
|
|
21
|
+
path: ["b"]
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
op: "add",
|
|
25
|
+
path: ["e"],
|
|
26
|
+
value: 15
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
op: "remove",
|
|
30
|
+
path: ["c", "d"]
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const arrOps: diffObj.DiffOps = [
|
|
35
|
+
{
|
|
36
|
+
op: "replace",
|
|
37
|
+
path: [1],
|
|
38
|
+
value: 10
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
op: "remove",
|
|
42
|
+
path: [2]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
op: "add",
|
|
46
|
+
path: [7],
|
|
47
|
+
value: 15
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
//OK
|
|
52
|
+
diffApply(obj1, objOps);
|
|
53
|
+
diffApply(obj1, []);
|
|
54
|
+
diffApply(arr1, arrOps);
|
|
55
|
+
diffApply(arr1, []);
|
|
56
|
+
diffApply(obj1, objOps, jsonPatchPathConverter);
|
|
57
|
+
diffApply(arr1, arrOps, jsonPatchPathConverter);
|
|
58
|
+
|
|
59
|
+
// not OK
|
|
60
|
+
// @ts-expect-error
|
|
61
|
+
diffApply(obj1);
|
|
62
|
+
// @ts-expect-error
|
|
63
|
+
diffApply(arr2);
|
|
64
|
+
// @ts-expect-error
|
|
65
|
+
diffApply("a");
|
|
66
|
+
// @ts-expect-error
|
|
67
|
+
diffApply(true);
|
|
68
|
+
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
diffApply(obj1, 1);
|
|
71
|
+
// @ts-expect-error
|
|
72
|
+
diffApply(3, arr2);
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
diffApply(obj1, "a");
|
|
75
|
+
// @ts-expect-error
|
|
76
|
+
diffApply("b", arr2);
|
|
77
|
+
|
|
78
|
+
// @ts-expect-error
|
|
79
|
+
diffApply(obj1, [{ op: "delete", path: ["a"] }]);
|
|
80
|
+
// @ts-expect-error
|
|
81
|
+
diffApply(obj1, [{ op: "delete", path: ["a"] }], jsonPatchPathConverter);
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
diffApply(obj1, "a", jsonPatchPathConverter);
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
diffApply(obj1, ["a", "b", "c"], jsonPatchPathConverter);
|
|
86
|
+
|
|
87
|
+
// @ts-expect-error
|
|
88
|
+
diff("a", jsonPatchPathConverter);
|
|
89
|
+
// @ts-expect-error
|
|
90
|
+
diff(true, jsonPatchPathConverter);
|
|
91
|
+
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
diff(obj1, 1, jsonPatchPathConverter);
|
|
94
|
+
// @ts-expect-error
|
|
95
|
+
diff(3, arr2, jsonPatchPathConverter);
|
|
96
|
+
// @ts-expect-error
|
|
97
|
+
diff(obj1, "a", jsonPatchPathConverter);
|
|
98
|
+
// @ts-expect-error
|
|
99
|
+
diff("b", arr2, jsonPatchPathConverter);
|
|
100
|
+
|
|
101
|
+
// @ts-expect-error
|
|
102
|
+
diff(obj1, obj2, "a");
|
|
103
|
+
// @ts-expect-error
|
|
104
|
+
diff(arr1, arr2, 1);
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
diff(obj1, arr1, "bee");
|
|
107
|
+
// @ts-expect-error
|
|
108
|
+
diff(obj2, arr2, "nope");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "just-diff-apply",
|
|
3
|
+
"version": "5.5.0",
|
|
4
|
+
"description": "Apply a diff to an object. Optionally supports jsonPatch protocol",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"require": "./index.cjs",
|
|
10
|
+
"import": "./index.mjs"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"main": "index.cjs",
|
|
15
|
+
"types": "index.d.ts",
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
18
|
+
"build": "rollup -c"
|
|
19
|
+
},
|
|
20
|
+
"repository": "https://github.com/angus-c/just",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"object",
|
|
23
|
+
"diff",
|
|
24
|
+
"apply",
|
|
25
|
+
"jsonPatch",
|
|
26
|
+
"no-dependencies",
|
|
27
|
+
"just"
|
|
28
|
+
],
|
|
29
|
+
"author": "Angus Croll",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/angus-c/just/issues"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
|
|
2
|
+
|
|
3
|
+
ISC License
|
|
4
|
+
|
|
5
|
+
Copyright npm, Inc.
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this
|
|
8
|
+
software for any purpose with or without fee is hereby
|
|
9
|
+
granted, provided that the above copyright notice and this
|
|
10
|
+
permission notice appear in all copies.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
|
13
|
+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
|
15
|
+
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
17
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
18
|
+
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
19
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# parse-conflict-json
|
|
2
|
+
|
|
3
|
+
Parse a JSON string that has git merge conflicts, resolving if possible.
|
|
4
|
+
|
|
5
|
+
If the JSON is valid, it just does `JSON.parse` as normal.
|
|
6
|
+
|
|
7
|
+
If either side of the conflict is invalid JSON, then an error is thrown for
|
|
8
|
+
that.
|
|
9
|
+
|
|
10
|
+
## USAGE
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
// after a git merge that left some conflicts there
|
|
14
|
+
const data = fs.readFileSync('package-lock.json', 'utf8')
|
|
15
|
+
|
|
16
|
+
// reviverFunction is passed to JSON.parse as the reviver function
|
|
17
|
+
// preference defaults to 'ours', set to 'theirs' to prefer the other
|
|
18
|
+
// side's changes.
|
|
19
|
+
const parsed = parseConflictJson(data, reviverFunction, preference)
|
|
20
|
+
|
|
21
|
+
// returns true if the data looks like a conflicted diff file
|
|
22
|
+
parsed.isDiff(data)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Algorithm
|
|
26
|
+
|
|
27
|
+
If `prefer` is set to `theirs`, then the vaules of `theirs` and `ours` are
|
|
28
|
+
switched in the resolver function. (Ie, we'll apply their changes on top
|
|
29
|
+
of our object, rather than the other way around.)
|
|
30
|
+
|
|
31
|
+
- Parse the conflicted file into 3 pieces: `ours`, `theirs`, and `parent`
|
|
32
|
+
|
|
33
|
+
- Get the [diff](https://github.com/angus-c/just#just-diff) from `parent`
|
|
34
|
+
to `ours`.
|
|
35
|
+
|
|
36
|
+
- [Apply](https://github.com/angus-c/just#just-diff-apply) each change of
|
|
37
|
+
that diff to `theirs`.
|
|
38
|
+
|
|
39
|
+
If any change in the diff set cannot be applied (ie, because they
|
|
40
|
+
changed an object into a non-object and we changed a field on that
|
|
41
|
+
object), then replace the object at the specified path with the object
|
|
42
|
+
at the path in `ours`.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const parseJSON = require('json-parse-even-better-errors')
|
|
2
|
+
const { diff } = require('just-diff')
|
|
3
|
+
const { diffApply } = require('just-diff-apply')
|
|
4
|
+
|
|
5
|
+
const globalObjectProperties = Object.getOwnPropertyNames(Object.prototype)
|
|
6
|
+
|
|
7
|
+
const stripBOM = content => {
|
|
8
|
+
content = content.toString()
|
|
9
|
+
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
10
|
+
// because the buffer-to-string conversion in `fs.readFileSync()`
|
|
11
|
+
// translates it to FEFF, the UTF-16 BOM.
|
|
12
|
+
if (content.charCodeAt(0) === 0xFEFF) {
|
|
13
|
+
content = content.slice(1)
|
|
14
|
+
}
|
|
15
|
+
return content
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const PARENT_RE = /\|{7,}/g
|
|
19
|
+
const OURS_RE = /<{7,}/g
|
|
20
|
+
const THEIRS_RE = /={7,}/g
|
|
21
|
+
const END_RE = />{7,}/g
|
|
22
|
+
|
|
23
|
+
const isDiff = str =>
|
|
24
|
+
str.match(OURS_RE) && str.match(THEIRS_RE) && str.match(END_RE)
|
|
25
|
+
|
|
26
|
+
const parseConflictJSON = (str, reviver, prefer) => {
|
|
27
|
+
prefer = prefer || 'ours'
|
|
28
|
+
if (prefer !== 'theirs' && prefer !== 'ours') {
|
|
29
|
+
throw new TypeError('prefer param must be "ours" or "theirs" if set')
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
str = stripBOM(str)
|
|
33
|
+
|
|
34
|
+
if (!isDiff(str)) {
|
|
35
|
+
return parseJSON(str)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const pieces = str.split(/[\n\r]+/g).reduce((acc, line) => {
|
|
39
|
+
if (line.match(PARENT_RE)) {
|
|
40
|
+
acc.state = 'parent'
|
|
41
|
+
} else if (line.match(OURS_RE)) {
|
|
42
|
+
acc.state = 'ours'
|
|
43
|
+
} else if (line.match(THEIRS_RE)) {
|
|
44
|
+
acc.state = 'theirs'
|
|
45
|
+
} else if (line.match(END_RE)) {
|
|
46
|
+
acc.state = 'top'
|
|
47
|
+
} else {
|
|
48
|
+
if (acc.state === 'top' || acc.state === 'ours') {
|
|
49
|
+
acc.ours += line
|
|
50
|
+
}
|
|
51
|
+
if (acc.state === 'top' || acc.state === 'theirs') {
|
|
52
|
+
acc.theirs += line
|
|
53
|
+
}
|
|
54
|
+
if (acc.state === 'top' || acc.state === 'parent') {
|
|
55
|
+
acc.parent += line
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return acc
|
|
59
|
+
}, {
|
|
60
|
+
state: 'top',
|
|
61
|
+
ours: '',
|
|
62
|
+
theirs: '',
|
|
63
|
+
parent: '',
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
// this will throw if either piece is not valid JSON, that's intended
|
|
67
|
+
const parent = parseJSON(pieces.parent, reviver)
|
|
68
|
+
const ours = parseJSON(pieces.ours, reviver)
|
|
69
|
+
const theirs = parseJSON(pieces.theirs, reviver)
|
|
70
|
+
|
|
71
|
+
return prefer === 'ours'
|
|
72
|
+
? resolve(parent, ours, theirs)
|
|
73
|
+
: resolve(parent, theirs, ours)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const isObj = obj => obj && typeof obj === 'object'
|
|
77
|
+
|
|
78
|
+
const copyPath = (to, from, path, i) => {
|
|
79
|
+
const p = path[i]
|
|
80
|
+
if (isObj(to[p]) && isObj(from[p]) &&
|
|
81
|
+
Array.isArray(to[p]) === Array.isArray(from[p])) {
|
|
82
|
+
return copyPath(to[p], from[p], path, i + 1)
|
|
83
|
+
}
|
|
84
|
+
to[p] = from[p]
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// get the diff from parent->ours and applying our changes on top of theirs.
|
|
88
|
+
// If they turned an object into a non-object, then put it back.
|
|
89
|
+
const resolve = (parent, ours, theirs) => {
|
|
90
|
+
const dours = diff(parent, ours)
|
|
91
|
+
for (let i = 0; i < dours.length; i++) {
|
|
92
|
+
if (globalObjectProperties.find(prop => dours[i].path.includes(prop))) {
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
diffApply(theirs, [dours[i]])
|
|
97
|
+
} catch (e) {
|
|
98
|
+
copyPath(theirs, ours, dours[i].path, 0)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return theirs
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = Object.assign(parseConflictJSON, { isDiff })
|
package/node_modules/parse-conflict-json/node_modules/json-parse-even-better-errors/LICENSE.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright 2017 Kat Marchán
|
|
2
|
+
Copyright npm, Inc.
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
5
|
+
copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
to deal in the Software without restriction, including without limitation
|
|
7
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
This library is a fork of 'better-json-errors' by Kat Marchán, extended and
|
|
25
|
+
distributed under the terms of the MIT license above.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# json-parse-even-better-errors
|
|
2
|
+
|
|
3
|
+
[`json-parse-even-better-errors`](https://github.com/npm/json-parse-even-better-errors)
|
|
4
|
+
is a Node.js library for getting nicer errors out of `JSON.parse()`,
|
|
5
|
+
including context and position of the parse errors.
|
|
6
|
+
|
|
7
|
+
It also preserves the newline and indentation styles of the JSON data, by
|
|
8
|
+
putting them in the object or array in the `Symbol.for('indent')` and
|
|
9
|
+
`Symbol.for('newline')` properties.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
`$ npm install --save json-parse-even-better-errors`
|
|
14
|
+
|
|
15
|
+
## Table of Contents
|
|
16
|
+
|
|
17
|
+
* [Example](#example)
|
|
18
|
+
* [Features](#features)
|
|
19
|
+
* [Contributing](#contributing)
|
|
20
|
+
* [API](#api)
|
|
21
|
+
* [`parse`](#parse)
|
|
22
|
+
|
|
23
|
+
### Example
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
const parseJson = require('json-parse-even-better-errors')
|
|
27
|
+
|
|
28
|
+
parseJson('"foo"') // returns the string 'foo'
|
|
29
|
+
parseJson('garbage') // more useful error message
|
|
30
|
+
parseJson.noExceptions('garbage') // returns undefined
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* Like JSON.parse, but the errors are better.
|
|
36
|
+
* Strips a leading byte-order-mark that you sometimes get reading files.
|
|
37
|
+
* Has a `noExceptions` method that returns undefined rather than throwing.
|
|
38
|
+
* Attaches the newline character(s) used to the `Symbol.for('newline')`
|
|
39
|
+
property on objects and arrays.
|
|
40
|
+
* Attaches the indentation character(s) used to the `Symbol.for('indent')`
|
|
41
|
+
property on objects and arrays.
|
|
42
|
+
|
|
43
|
+
## Indentation
|
|
44
|
+
|
|
45
|
+
To preserve indentation when the file is saved back to disk, use
|
|
46
|
+
`data[Symbol.for('indent')]` as the third argument to `JSON.stringify`, and
|
|
47
|
+
if you want to preserve windows `\r\n` newlines, replace the `\n` chars in
|
|
48
|
+
the string with `data[Symbol.for('newline')]`.
|
|
49
|
+
|
|
50
|
+
For example:
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
const txt = await readFile('./package.json', 'utf8')
|
|
54
|
+
const data = parseJsonEvenBetterErrors(txt)
|
|
55
|
+
const indent = Symbol.for('indent')
|
|
56
|
+
const newline = Symbol.for('newline')
|
|
57
|
+
// .. do some stuff to the data ..
|
|
58
|
+
const string = JSON.stringify(data, null, data[indent]) + '\n'
|
|
59
|
+
const eolFixed = data[newline] === '\n' ? string
|
|
60
|
+
: string.replace(/\n/g, data[newline])
|
|
61
|
+
await writeFile('./package.json', eolFixed)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Indentation is determined by looking at the whitespace between the initial
|
|
65
|
+
`{` and `[` and the character that follows it. If you have lots of weird
|
|
66
|
+
inconsistent indentation, then it won't track that or give you any way to
|
|
67
|
+
preserve it. Whether this is a bug or a feature is debatable ;)
|
|
68
|
+
|
|
69
|
+
### API
|
|
70
|
+
|
|
71
|
+
#### <a name="parse"></a> `parse(txt, reviver = null, context = 20)`
|
|
72
|
+
|
|
73
|
+
Works just like `JSON.parse`, but will include a bit more information when
|
|
74
|
+
an error happens, and attaches a `Symbol.for('indent')` and
|
|
75
|
+
`Symbol.for('newline')` on objects and arrays. This throws a
|
|
76
|
+
`JSONParseError`.
|
|
77
|
+
|
|
78
|
+
#### <a name="parse"></a> `parse.noExceptions(txt, reviver = null)`
|
|
79
|
+
|
|
80
|
+
Works just like `JSON.parse`, but will return `undefined` rather than
|
|
81
|
+
throwing an error.
|
|
82
|
+
|
|
83
|
+
#### <a name="jsonparseerror"></a> `class JSONParseError(er, text, context = 20, caller = null)`
|
|
84
|
+
|
|
85
|
+
Extends the JavaScript `SyntaxError` class to parse the message and provide
|
|
86
|
+
better metadata.
|
|
87
|
+
|
|
88
|
+
Pass in the error thrown by the built-in `JSON.parse`, and the text being
|
|
89
|
+
parsed, and it'll parse out the bits needed to be helpful.
|
|
90
|
+
|
|
91
|
+
`context` defaults to 20.
|
|
92
|
+
|
|
93
|
+
Set a `caller` function to trim internal implementation details out of the
|
|
94
|
+
stack trace. When calling `parseJson`, this is set to the `parseJson`
|
|
95
|
+
function. If not set, then the constructor defaults to itself, so the
|
|
96
|
+
stack trace will point to the spot where you call `new JSONParseError`.
|