@snyk/fix 1.714.0 → 1.718.0
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/dist/plugins/python/handlers/fail-if-no-updates-applied.d.ts +2 -0
- package/dist/plugins/python/handlers/{ensure-has-updates.js → fail-if-no-updates-applied.js} +4 -4
- package/dist/plugins/python/handlers/fail-if-no-updates-applied.js.map +1 -0
- package/dist/plugins/python/handlers/pipenv-pipfile/update-dependencies/generate-upgrades.d.ts +4 -0
- package/dist/plugins/python/handlers/pipenv-pipfile/update-dependencies/generate-upgrades.js +19 -0
- package/dist/plugins/python/handlers/pipenv-pipfile/update-dependencies/generate-upgrades.js.map +1 -0
- package/dist/plugins/python/handlers/pipenv-pipfile/update-dependencies/index.d.ts +0 -3
- package/dist/plugins/python/handlers/pipenv-pipfile/update-dependencies/index.js +52 -23
- package/dist/plugins/python/handlers/pipenv-pipfile/update-dependencies/index.js.map +1 -1
- package/dist/plugins/python/handlers/poetry/update-dependencies/generate-upgrades.d.ts +5 -0
- package/dist/plugins/python/handlers/poetry/update-dependencies/generate-upgrades.js +45 -0
- package/dist/plugins/python/handlers/poetry/update-dependencies/generate-upgrades.js.map +1 -0
- package/dist/plugins/python/handlers/poetry/update-dependencies/index.d.ts +0 -4
- package/dist/plugins/python/handlers/poetry/update-dependencies/index.js +52 -86
- package/dist/plugins/python/handlers/poetry/update-dependencies/index.js.map +1 -1
- package/dist/plugins/python/handlers/poetry/update-dependencies/poetry-add.d.ts +2 -0
- package/dist/plugins/python/handlers/poetry/update-dependencies/poetry-add.js +53 -0
- package/dist/plugins/python/handlers/poetry/update-dependencies/poetry-add.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/dist/plugins/python/handlers/ensure-has-updates.d.ts +0 -2
- package/dist/plugins/python/handlers/ensure-has-updates.js.map +0 -1
package/dist/plugins/python/handlers/{ensure-has-updates.js → fail-if-no-updates-applied.js}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.failIfNoUpdatesApplied = void 0;
|
|
4
4
|
const debugLib = require("debug");
|
|
5
5
|
const no_fixes_applied_1 = require("../../../lib/errors/no-fixes-applied");
|
|
6
6
|
const attempted_changes_summary_1 = require("./attempted-changes-summary");
|
|
7
7
|
const debug = debugLib('snyk-fix:python:ensure-changes-applied');
|
|
8
|
-
function
|
|
8
|
+
function failIfNoUpdatesApplied(changes) {
|
|
9
9
|
if (!changes.length) {
|
|
10
10
|
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError();
|
|
11
11
|
}
|
|
@@ -17,5 +17,5 @@ function ensureHasUpdates(changes) {
|
|
|
17
17
|
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError(reason, tip);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
exports.
|
|
21
|
-
//# sourceMappingURL=
|
|
20
|
+
exports.failIfNoUpdatesApplied = failIfNoUpdatesApplied;
|
|
21
|
+
//# sourceMappingURL=fail-if-no-updates-applied.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fail-if-no-updates-applied.js","sourceRoot":"","sources":["../../../../src/plugins/python/handlers/fail-if-no-updates-applied.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAElC,2EAAkF;AAElF,2EAAiE;AAEjE,MAAM,KAAK,GAAG,QAAQ,CAAC,wCAAwC,CAAC,CAAC;AAEjE,SAAgB,sBAAsB,CAAC,OAA4B;IACjE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,MAAM,IAAI,6CAA0B,EAAE,CAAC;KACxC;IACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,8CAAkB,CAAC,CAAC,CAAC,CAAC,EAAE;QAC/C,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC7D,6EAA6E;QAC7E,QAAQ;QACR,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAoB,CAAC;QACtD,MAAM,IAAI,6CAA0B,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACnD;AACH,CAAC;AAXD,wDAWC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUpgrades = void 0;
|
|
4
|
+
const standardize_package_name_1 = require("../../../standardize-package-name");
|
|
5
|
+
const validate_required_data_1 = require("../../validate-required-data");
|
|
6
|
+
function generateUpgrades(entity) {
|
|
7
|
+
const { remediation } = validate_required_data_1.validateRequiredData(entity);
|
|
8
|
+
const { pin: pins } = remediation;
|
|
9
|
+
const upgrades = [];
|
|
10
|
+
for (const pkgAtVersion of Object.keys(pins)) {
|
|
11
|
+
const pin = pins[pkgAtVersion];
|
|
12
|
+
const newVersion = pin.upgradeTo.split('@')[1];
|
|
13
|
+
const [pkgName] = pkgAtVersion.split('@');
|
|
14
|
+
upgrades.push(`${standardize_package_name_1.standardizePackageName(pkgName)}==${newVersion}`);
|
|
15
|
+
}
|
|
16
|
+
return { upgrades };
|
|
17
|
+
}
|
|
18
|
+
exports.generateUpgrades = generateUpgrades;
|
|
19
|
+
//# sourceMappingURL=generate-upgrades.js.map
|
package/dist/plugins/python/handlers/pipenv-pipfile/update-dependencies/generate-upgrades.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-upgrades.js","sourceRoot":"","sources":["../../../../../../src/plugins/python/handlers/pipenv-pipfile/update-dependencies/generate-upgrades.ts"],"names":[],"mappings":";;;AACA,gFAA2E;AAC3E,yEAAoE;AAEpE,SAAgB,gBAAgB,CAAC,MAAmB;IAClD,MAAM,EAAE,WAAW,EAAE,GAAG,6CAAoB,CAAC,MAAM,CAAC,CAAC;IACrD,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,WAAW,CAAC;IAElC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/B,MAAM,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1C,QAAQ,CAAC,IAAI,CAAC,GAAG,iDAAsB,CAAC,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC,CAAC;KACpE;IACD,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC;AAZD,4CAYC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { PluginFixResponse } from '../../../../types';
|
|
2
2
|
import { EntityToFix, FixOptions } from '../../../../../types';
|
|
3
3
|
export declare function updateDependencies(entity: EntityToFix, options: FixOptions): Promise<PluginFixResponse>;
|
|
4
|
-
export declare function generateUpgrades(entity: EntityToFix): {
|
|
5
|
-
upgrades: string[];
|
|
6
|
-
};
|
|
@@ -1,43 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.updateDependencies = void 0;
|
|
4
4
|
const debugLib = require("debug");
|
|
5
|
+
const fail_if_no_updates_applied_1 = require("../../fail-if-no-updates-applied");
|
|
5
6
|
const no_fixes_applied_1 = require("../../../../../lib/errors/no-fixes-applied");
|
|
6
|
-
const
|
|
7
|
-
const validate_required_data_1 = require("../../validate-required-data");
|
|
8
|
-
const ensure_has_updates_1 = require("../../ensure-has-updates");
|
|
7
|
+
const generate_upgrades_1 = require("./generate-upgrades");
|
|
9
8
|
const pipenv_add_1 = require("./pipenv-add");
|
|
10
9
|
const debug = debugLib('snyk-fix:python:Pipfile');
|
|
10
|
+
function chooseFixStrategy(options) {
|
|
11
|
+
return options.sequentialFix ? fixSequentially : fixAll;
|
|
12
|
+
}
|
|
11
13
|
async function updateDependencies(entity, options) {
|
|
12
|
-
const handlerResult = await
|
|
14
|
+
const handlerResult = await chooseFixStrategy(options)(entity, options);
|
|
13
15
|
return handlerResult;
|
|
14
16
|
}
|
|
15
17
|
exports.updateDependencies = updateDependencies;
|
|
16
|
-
function generateUpgrades(entity) {
|
|
17
|
-
const { remediation } = validate_required_data_1.validateRequiredData(entity);
|
|
18
|
-
const { pin: pins } = remediation;
|
|
19
|
-
const upgrades = [];
|
|
20
|
-
for (const pkgAtVersion of Object.keys(pins)) {
|
|
21
|
-
const pin = pins[pkgAtVersion];
|
|
22
|
-
const newVersion = pin.upgradeTo.split('@')[1];
|
|
23
|
-
const [pkgName] = pkgAtVersion.split('@');
|
|
24
|
-
upgrades.push(`${standardize_package_name_1.standardizePackageName(pkgName)}==${newVersion}`);
|
|
25
|
-
}
|
|
26
|
-
return { upgrades };
|
|
27
|
-
}
|
|
28
|
-
exports.generateUpgrades = generateUpgrades;
|
|
29
18
|
async function fixAll(entity, options) {
|
|
30
19
|
const handlerResult = {
|
|
31
20
|
succeeded: [],
|
|
32
21
|
failed: [],
|
|
33
22
|
skipped: [],
|
|
34
23
|
};
|
|
35
|
-
const { upgrades } = await generateUpgrades(entity);
|
|
36
|
-
if (!upgrades.length) {
|
|
37
|
-
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError('Failed to calculate package updates to apply');
|
|
38
|
-
}
|
|
39
24
|
const changes = [];
|
|
40
25
|
try {
|
|
26
|
+
const { upgrades } = await generate_upgrades_1.generateUpgrades(entity);
|
|
27
|
+
if (!upgrades.length) {
|
|
28
|
+
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError('Failed to calculate package updates to apply');
|
|
29
|
+
}
|
|
41
30
|
// TODO: for better support we need to:
|
|
42
31
|
// 1. parse the manifest and extract original requirements, version spec etc
|
|
43
32
|
// 2. swap out only the version and retain original spec
|
|
@@ -47,7 +36,7 @@ async function fixAll(entity, options) {
|
|
|
47
36
|
if (upgrades.length) {
|
|
48
37
|
changes.push(...(await pipenv_add_1.pipenvAdd(entity, options, upgrades)));
|
|
49
38
|
}
|
|
50
|
-
|
|
39
|
+
fail_if_no_updates_applied_1.failIfNoUpdatesApplied(changes);
|
|
51
40
|
handlerResult.succeeded.push({
|
|
52
41
|
original: entity,
|
|
53
42
|
changes,
|
|
@@ -63,4 +52,44 @@ async function fixAll(entity, options) {
|
|
|
63
52
|
}
|
|
64
53
|
return handlerResult;
|
|
65
54
|
}
|
|
55
|
+
async function fixSequentially(entity, options) {
|
|
56
|
+
const handlerResult = {
|
|
57
|
+
succeeded: [],
|
|
58
|
+
failed: [],
|
|
59
|
+
skipped: [],
|
|
60
|
+
};
|
|
61
|
+
const { upgrades } = await generate_upgrades_1.generateUpgrades(entity);
|
|
62
|
+
// TODO: for better support we need to:
|
|
63
|
+
// 1. parse the manifest and extract original requirements, version spec etc
|
|
64
|
+
// 2. swap out only the version and retain original spec
|
|
65
|
+
// 3. re-lock the lockfile
|
|
66
|
+
// at the moment we do not parse Pipfile and therefore can't tell the difference
|
|
67
|
+
// between prod & dev updates
|
|
68
|
+
const changes = [];
|
|
69
|
+
try {
|
|
70
|
+
if (!upgrades.length) {
|
|
71
|
+
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError('Failed to calculate package updates to apply');
|
|
72
|
+
}
|
|
73
|
+
// update prod dependencies first
|
|
74
|
+
if (upgrades.length) {
|
|
75
|
+
for (const upgrade of upgrades) {
|
|
76
|
+
changes.push(...(await pipenv_add_1.pipenvAdd(entity, options, [upgrade])));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
fail_if_no_updates_applied_1.failIfNoUpdatesApplied(changes);
|
|
80
|
+
handlerResult.succeeded.push({
|
|
81
|
+
original: entity,
|
|
82
|
+
changes,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
debug(`Failed to fix ${entity.scanResult.identity.targetFile}.\nERROR: ${error}`);
|
|
87
|
+
handlerResult.failed.push({
|
|
88
|
+
original: entity,
|
|
89
|
+
tip: error.tip,
|
|
90
|
+
error,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return handlerResult;
|
|
94
|
+
}
|
|
66
95
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/plugins/python/handlers/pipenv-pipfile/update-dependencies/index.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/plugins/python/handlers/pipenv-pipfile/update-dependencies/index.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AASlC,iFAA0E;AAC1E,iFAAwF;AACxF,2DAAuD;AACvD,6CAAyC;AAEzC,MAAM,KAAK,GAAG,QAAQ,CAAC,yBAAyB,CAAC,CAAC;AAElD,SAAS,iBAAiB,CAAC,OAAmB;IAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1D,CAAC;AAEM,KAAK,UAAU,kBAAkB,CACtC,MAAmB,EACnB,OAAmB;IAEnB,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxE,OAAO,aAAa,CAAC;AACvB,CAAC;AAND,gDAMC;AAED,KAAK,UAAU,MAAM,CACnB,MAAmB,EACnB,OAAmB;IAEnB,MAAM,aAAa,GAAsB;QACvC,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;KACZ,CAAC;IACF,MAAM,OAAO,GAAwB,EAAE,CAAC;IACxC,IAAI;QACF,MAAM,EAAE,QAAQ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,CAAC,MAAM,EAAE;YACpB,MAAM,IAAI,6CAA0B,CAClC,8CAA8C,CAC/C,CAAC;SACH;QACD,iCAAiC;QACjC,IAAI,QAAQ,CAAC,MAAM,EAAE;YACnB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;gBAC9B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,sBAAS,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;aAChE;SACF;QAED,mDAAsB,CAAC,OAAO,CAAC,CAAC;QAEhC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC;YAC3B,QAAQ,EAAE,MAAM;YAChB,OAAO;SACR,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,KAAK,CACH,iBAAiB,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,aAAa,KAAK,EAAE,CAC3E,CAAC;QACF,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;YACxB,QAAQ,EAAE,MAAM;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,KAAK;SACN,CAAC,CAAC;KACJ;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUpgrades = void 0;
|
|
4
|
+
const pathLib = require("path");
|
|
5
|
+
const toml = require("toml");
|
|
6
|
+
const debugLib = require("debug");
|
|
7
|
+
const validate_required_data_1 = require("../../validate-required-data");
|
|
8
|
+
const standardize_package_name_1 = require("../../../standardize-package-name");
|
|
9
|
+
const debug = debugLib('snyk-fix:python:Poetry');
|
|
10
|
+
async function generateUpgrades(entity) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
const { remediation, targetFile } = validate_required_data_1.validateRequiredData(entity);
|
|
13
|
+
const pins = remediation.pin;
|
|
14
|
+
const targetFilePath = pathLib.resolve(entity.workspace.path, targetFile);
|
|
15
|
+
const { dir } = pathLib.parse(targetFilePath);
|
|
16
|
+
const pyProjectTomlRaw = await entity.workspace.readFile(pathLib.resolve(dir, 'pyproject.toml'));
|
|
17
|
+
const pyProjectToml = toml.parse(pyProjectTomlRaw);
|
|
18
|
+
const prodTopLevelDeps = Object.keys((_a = pyProjectToml.tool.poetry.dependencies) !== null && _a !== void 0 ? _a : {}).map((dep) => standardize_package_name_1.standardizePackageName(dep));
|
|
19
|
+
const devTopLevelDeps = Object.keys((_b = pyProjectToml.tool.poetry['dev-dependencies']) !== null && _b !== void 0 ? _b : {}).map((dep) => standardize_package_name_1.standardizePackageName(dep));
|
|
20
|
+
const upgrades = [];
|
|
21
|
+
const devUpgrades = [];
|
|
22
|
+
for (const pkgAtVersion of Object.keys(pins)) {
|
|
23
|
+
const pin = pins[pkgAtVersion];
|
|
24
|
+
const newVersion = pin.upgradeTo.split('@')[1];
|
|
25
|
+
const [pkgName] = pkgAtVersion.split('@');
|
|
26
|
+
const upgrade = `${standardize_package_name_1.standardizePackageName(pkgName)}==${newVersion}`;
|
|
27
|
+
if (pin.isTransitive || prodTopLevelDeps.includes(pkgName)) {
|
|
28
|
+
// transitive and it could have come from a dev or prod dep
|
|
29
|
+
// since we can't tell right now let be pinned into production deps
|
|
30
|
+
upgrades.push(upgrade);
|
|
31
|
+
}
|
|
32
|
+
else if (prodTopLevelDeps.includes(pkgName)) {
|
|
33
|
+
upgrades.push(upgrade);
|
|
34
|
+
}
|
|
35
|
+
else if (entity.options.dev && devTopLevelDeps.includes(pkgName)) {
|
|
36
|
+
devUpgrades.push(upgrade);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
debug(`Could not determine what type of upgrade ${upgrade} is. When choosing between: transitive upgrade, production or dev direct upgrade. `);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { upgrades, devUpgrades };
|
|
43
|
+
}
|
|
44
|
+
exports.generateUpgrades = generateUpgrades;
|
|
45
|
+
//# sourceMappingURL=generate-upgrades.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-upgrades.js","sourceRoot":"","sources":["../../../../../../src/plugins/python/handlers/poetry/update-dependencies/generate-upgrades.ts"],"names":[],"mappings":";;;AAAA,gCAAgC;AAChC,6BAA6B;AAE7B,kCAAkC;AAIlC,yEAAoE;AACpE,gFAA2E;AAE3E,MAAM,KAAK,GAAG,QAAQ,CAAC,wBAAwB,CAAC,CAAC;AAe1C,KAAK,UAAU,gBAAgB,CACpC,MAAmB;;IAEnB,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,6CAAoB,CAAC,MAAM,CAAC,CAAC;IACjE,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC;IAE7B,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC1E,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC9C,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,QAAQ,CACtD,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,gBAAgB,CAAC,CACvC,CAAC;IACF,MAAM,aAAa,GAAkB,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAElE,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,OAClC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,mCAAI,EAAE,CAC7C,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,iDAAsB,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,OACjC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,mCAAI,EAAE,CACpD,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,iDAAsB,CAAC,GAAG,CAAC,CAAC,CAAC;IAE5C,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/B,MAAM,UAAU,GAAG,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,MAAM,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE1C,MAAM,OAAO,GAAG,GAAG,iDAAsB,CAAC,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC;QAEpE,IAAI,GAAG,CAAC,YAAY,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC1D,2DAA2D;YAC3D,mEAAmE;YACnE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;aAAM,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAC7C,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;aAAM,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;YAClE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC3B;aAAM;YACL,KAAK,CACH,4CAA4C,OAAO,oFAAoF,CACxI,CAAC;SACH;KACF;IACD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC;AA5CD,4CA4CC"}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import { PluginFixResponse } from '../../../../types';
|
|
2
2
|
import { EntityToFix, FixOptions } from '../../../../../types';
|
|
3
3
|
export declare function updateDependencies(entity: EntityToFix, options: FixOptions): Promise<PluginFixResponse>;
|
|
4
|
-
export declare function generateUpgrades(entity: EntityToFix): Promise<{
|
|
5
|
-
upgrades: string[];
|
|
6
|
-
devUpgrades: string[];
|
|
7
|
-
}>;
|
|
@@ -1,100 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const pathLib = require("path");
|
|
5
|
-
const toml = require("toml");
|
|
3
|
+
exports.updateDependencies = void 0;
|
|
6
4
|
const debugLib = require("debug");
|
|
7
|
-
const
|
|
5
|
+
const generate_upgrades_1 = require("./generate-upgrades");
|
|
6
|
+
const poetry_add_1 = require("./poetry-add");
|
|
8
7
|
const no_fixes_applied_1 = require("../../../../../lib/errors/no-fixes-applied");
|
|
9
|
-
const
|
|
10
|
-
const validate_required_data_1 = require("../../validate-required-data");
|
|
11
|
-
const standardize_package_name_1 = require("../../../standardize-package-name");
|
|
12
|
-
const attempted_changes_summary_1 = require("../../attempted-changes-summary");
|
|
13
|
-
const ensure_has_updates_1 = require("../../ensure-has-updates");
|
|
8
|
+
const fail_if_no_updates_applied_1 = require("../../fail-if-no-updates-applied");
|
|
14
9
|
const debug = debugLib('snyk-fix:python:Poetry');
|
|
10
|
+
function chooseFixStrategy(options) {
|
|
11
|
+
return options.sequentialFix ? fixSequentially : fixAll;
|
|
12
|
+
}
|
|
15
13
|
async function updateDependencies(entity, options) {
|
|
16
|
-
const handlerResult = await
|
|
14
|
+
const handlerResult = await chooseFixStrategy(options)(entity, options);
|
|
17
15
|
return handlerResult;
|
|
18
16
|
}
|
|
19
17
|
exports.updateDependencies = updateDependencies;
|
|
20
|
-
async function generateUpgrades(entity) {
|
|
21
|
-
var _a, _b;
|
|
22
|
-
const { remediation, targetFile } = validate_required_data_1.validateRequiredData(entity);
|
|
23
|
-
const pins = remediation.pin;
|
|
24
|
-
const targetFilePath = pathLib.resolve(entity.workspace.path, targetFile);
|
|
25
|
-
const { dir } = pathLib.parse(targetFilePath);
|
|
26
|
-
const pyProjectTomlRaw = await entity.workspace.readFile(pathLib.resolve(dir, 'pyproject.toml'));
|
|
27
|
-
const pyProjectToml = toml.parse(pyProjectTomlRaw);
|
|
28
|
-
const prodTopLevelDeps = Object.keys((_a = pyProjectToml.tool.poetry.dependencies) !== null && _a !== void 0 ? _a : {}).map((dep) => standardize_package_name_1.standardizePackageName(dep));
|
|
29
|
-
const devTopLevelDeps = Object.keys((_b = pyProjectToml.tool.poetry['dev-dependencies']) !== null && _b !== void 0 ? _b : {}).map((dep) => standardize_package_name_1.standardizePackageName(dep));
|
|
30
|
-
const upgrades = [];
|
|
31
|
-
const devUpgrades = [];
|
|
32
|
-
for (const pkgAtVersion of Object.keys(pins)) {
|
|
33
|
-
const pin = pins[pkgAtVersion];
|
|
34
|
-
const newVersion = pin.upgradeTo.split('@')[1];
|
|
35
|
-
const [pkgName] = pkgAtVersion.split('@');
|
|
36
|
-
const upgrade = `${standardize_package_name_1.standardizePackageName(pkgName)}==${newVersion}`;
|
|
37
|
-
if (pin.isTransitive || prodTopLevelDeps.includes(pkgName)) {
|
|
38
|
-
// transitive and it could have come from a dev or prod dep
|
|
39
|
-
// since we can't tell right now let be pinned into production deps
|
|
40
|
-
upgrades.push(upgrade);
|
|
41
|
-
}
|
|
42
|
-
else if (prodTopLevelDeps.includes(pkgName)) {
|
|
43
|
-
upgrades.push(upgrade);
|
|
44
|
-
}
|
|
45
|
-
else if (entity.options.dev && devTopLevelDeps.includes(pkgName)) {
|
|
46
|
-
devUpgrades.push(upgrade);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
debug(`Could not determine what type of upgrade ${upgrade} is. When choosing between: transitive upgrade, production or dev direct upgrade. `);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return { upgrades, devUpgrades };
|
|
53
|
-
}
|
|
54
|
-
exports.generateUpgrades = generateUpgrades;
|
|
55
|
-
function throwPoetryError(stderr, command) {
|
|
56
|
-
const ALREADY_UP_TO_DATE = 'No dependencies to install or update';
|
|
57
|
-
const INCOMPATIBLE_PYTHON = new RegExp(/Python requirement (.*) is not compatible/g, 'gm');
|
|
58
|
-
const SOLVER_PROBLEM = /SolverProblemError(.* version solving failed)/gms;
|
|
59
|
-
const incompatiblePythonError = INCOMPATIBLE_PYTHON.exec(stderr);
|
|
60
|
-
if (incompatiblePythonError) {
|
|
61
|
-
throw new command_failed_to_run_error_1.CommandFailedError(`The current project's Python requirement ${incompatiblePythonError[1]} is not compatible with some of the required packages`, command);
|
|
62
|
-
}
|
|
63
|
-
const solverProblemError = SOLVER_PROBLEM.exec(stderr);
|
|
64
|
-
if (solverProblemError) {
|
|
65
|
-
throw new command_failed_to_run_error_1.CommandFailedError(solverProblemError[0].trim(), command);
|
|
66
|
-
}
|
|
67
|
-
if (stderr.includes(ALREADY_UP_TO_DATE)) {
|
|
68
|
-
throw new command_failed_to_run_error_1.CommandFailedError('No dependencies could be updated as they seem to be at the correct versions. Make sure installed dependencies in the environment match those in the lockfile by running `poetry update`', command);
|
|
69
|
-
}
|
|
70
|
-
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError();
|
|
71
|
-
}
|
|
72
18
|
async function fixAll(entity, options) {
|
|
73
19
|
const handlerResult = {
|
|
74
20
|
succeeded: [],
|
|
75
21
|
failed: [],
|
|
76
22
|
skipped: [],
|
|
77
23
|
};
|
|
78
|
-
const { upgrades, devUpgrades } = await generateUpgrades(entity);
|
|
79
|
-
if (![...upgrades, ...devUpgrades].length) {
|
|
80
|
-
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError('Failed to calculate package updates to apply');
|
|
81
|
-
}
|
|
24
|
+
const { upgrades, devUpgrades } = await generate_upgrades_1.generateUpgrades(entity);
|
|
82
25
|
// TODO: for better support we need to:
|
|
83
26
|
// 1. parse the manifest and extract original requirements, version spec etc
|
|
84
27
|
// 2. swap out only the version and retain original spec
|
|
85
28
|
// 3. re-lock the lockfile
|
|
86
29
|
const changes = [];
|
|
87
30
|
try {
|
|
31
|
+
if (![...upgrades, ...devUpgrades].length) {
|
|
32
|
+
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError('Failed to calculate package updates to apply');
|
|
33
|
+
}
|
|
88
34
|
// update prod dependencies first
|
|
89
35
|
if (upgrades.length) {
|
|
90
|
-
changes.push(...(await poetryAdd(entity, options, upgrades)));
|
|
36
|
+
changes.push(...(await poetry_add_1.poetryAdd(entity, options, upgrades)));
|
|
91
37
|
}
|
|
92
38
|
// update dev dependencies second
|
|
93
39
|
if (devUpgrades.length) {
|
|
94
40
|
const installDev = true;
|
|
95
|
-
changes.push(...(await poetryAdd(entity, options, devUpgrades, installDev)));
|
|
41
|
+
changes.push(...(await poetry_add_1.poetryAdd(entity, options, devUpgrades, installDev)));
|
|
96
42
|
}
|
|
97
|
-
|
|
43
|
+
fail_if_no_updates_applied_1.failIfNoUpdatesApplied(changes);
|
|
98
44
|
handlerResult.succeeded.push({
|
|
99
45
|
original: entity,
|
|
100
46
|
changes,
|
|
@@ -110,29 +56,49 @@ async function fixAll(entity, options) {
|
|
|
110
56
|
}
|
|
111
57
|
return handlerResult;
|
|
112
58
|
}
|
|
113
|
-
async function
|
|
114
|
-
|
|
59
|
+
async function fixSequentially(entity, options) {
|
|
60
|
+
const handlerResult = {
|
|
61
|
+
succeeded: [],
|
|
62
|
+
failed: [],
|
|
63
|
+
skipped: [],
|
|
64
|
+
};
|
|
65
|
+
const { upgrades, devUpgrades } = await generate_upgrades_1.generateUpgrades(entity);
|
|
66
|
+
// TODO: for better support we need to:
|
|
67
|
+
// 1. parse the manifest and extract original requirements, version spec etc
|
|
68
|
+
// 2. swap out only the version and retain original spec
|
|
69
|
+
// 3. re-lock the lockfile
|
|
115
70
|
const changes = [];
|
|
116
|
-
let poetryCommand;
|
|
117
|
-
const { remediation, targetFile } = validate_required_data_1.validateRequiredData(entity);
|
|
118
71
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (res.exitCode !== 0) {
|
|
127
|
-
poetryCommand = res.command;
|
|
128
|
-
throwPoetryError(res.stderr ? res.stderr : res.stdout, res.command);
|
|
72
|
+
if (![...upgrades, ...devUpgrades].length) {
|
|
73
|
+
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError('Failed to calculate package updates to apply');
|
|
74
|
+
}
|
|
75
|
+
// update prod dependencies first
|
|
76
|
+
if (upgrades.length) {
|
|
77
|
+
for (const upgrade of upgrades) {
|
|
78
|
+
changes.push(...(await poetry_add_1.poetryAdd(entity, options, [upgrade])));
|
|
129
79
|
}
|
|
130
80
|
}
|
|
131
|
-
|
|
81
|
+
// update dev dependencies second
|
|
82
|
+
if (devUpgrades.length) {
|
|
83
|
+
for (const upgrade of devUpgrades) {
|
|
84
|
+
const installDev = true;
|
|
85
|
+
changes.push(...(await poetry_add_1.poetryAdd(entity, options, [upgrade], installDev)));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
fail_if_no_updates_applied_1.failIfNoUpdatesApplied(changes);
|
|
89
|
+
handlerResult.succeeded.push({
|
|
90
|
+
original: entity,
|
|
91
|
+
changes,
|
|
92
|
+
});
|
|
132
93
|
}
|
|
133
94
|
catch (error) {
|
|
134
|
-
|
|
95
|
+
debug(`Failed to fix ${entity.scanResult.identity.targetFile}.\nERROR: ${error}`);
|
|
96
|
+
handlerResult.failed.push({
|
|
97
|
+
original: entity,
|
|
98
|
+
tip: error.tip,
|
|
99
|
+
error,
|
|
100
|
+
});
|
|
135
101
|
}
|
|
136
|
-
return
|
|
102
|
+
return handlerResult;
|
|
137
103
|
}
|
|
138
104
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/plugins/python/handlers/poetry/update-dependencies/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/plugins/python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,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;aAChE;SACF;QAED,iCAAiC;QACjC,IAAI,WAAW,CAAC,MAAM,EAAE;YACtB,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE;gBACjC,MAAM,UAAU,GAAG,IAAI,CAAC;gBACxB,OAAO,CAAC,IAAI,CACV,GAAG,CAAC,MAAM,sBAAS,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,CAC7D,CAAC;aACH;SACF;QACD,mDAAsB,CAAC,OAAO,CAAC,CAAC;QAChC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC;YAC3B,QAAQ,EAAE,MAAM;YAChB,OAAO;SACR,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,KAAK,CACH,iBAAiB,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,aAAa,KAAK,EAAE,CAC3E,CAAC;QACF,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC;YACxB,QAAQ,EAAE,MAAM;YAChB,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,KAAK;SACN,CAAC,CAAC;KACJ;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.poetryAdd = void 0;
|
|
4
|
+
const pathLib = require("path");
|
|
5
|
+
const poetryFix = require("@snyk/fix-poetry");
|
|
6
|
+
const validate_required_data_1 = require("../../validate-required-data");
|
|
7
|
+
const attempted_changes_summary_1 = require("../../attempted-changes-summary");
|
|
8
|
+
const command_failed_to_run_error_1 = require("../../../../../lib/errors/command-failed-to-run-error");
|
|
9
|
+
const no_fixes_applied_1 = require("../../../../../lib/errors/no-fixes-applied");
|
|
10
|
+
async function poetryAdd(entity, options, upgrades, dev) {
|
|
11
|
+
var _a;
|
|
12
|
+
const changes = [];
|
|
13
|
+
let poetryCommand;
|
|
14
|
+
const { remediation, targetFile } = validate_required_data_1.validateRequiredData(entity);
|
|
15
|
+
try {
|
|
16
|
+
const targetFilePath = pathLib.resolve(entity.workspace.path, targetFile);
|
|
17
|
+
const { dir } = pathLib.parse(targetFilePath);
|
|
18
|
+
if (!options.dryRun && upgrades.length) {
|
|
19
|
+
const res = await poetryFix.poetryAdd(dir, upgrades, {
|
|
20
|
+
dev,
|
|
21
|
+
python: (_a = entity.options.command) !== null && _a !== void 0 ? _a : undefined,
|
|
22
|
+
});
|
|
23
|
+
if (res.exitCode !== 0) {
|
|
24
|
+
poetryCommand = res.command;
|
|
25
|
+
throwPoetryError(res.stderr ? res.stderr : res.stdout, res.command);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
changes.push(...attempted_changes_summary_1.generateSuccessfulChanges(upgrades, remediation.pin));
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
changes.push(...attempted_changes_summary_1.generateFailedChanges(upgrades, remediation.pin, error, poetryCommand));
|
|
32
|
+
}
|
|
33
|
+
return changes;
|
|
34
|
+
}
|
|
35
|
+
exports.poetryAdd = poetryAdd;
|
|
36
|
+
function throwPoetryError(stderr, command) {
|
|
37
|
+
const ALREADY_UP_TO_DATE = 'No dependencies to install or update';
|
|
38
|
+
const INCOMPATIBLE_PYTHON = new RegExp(/Python requirement (.*) is not compatible/g, 'gm');
|
|
39
|
+
const SOLVER_PROBLEM = /SolverProblemError(.* version solving failed)/gms;
|
|
40
|
+
const incompatiblePythonError = INCOMPATIBLE_PYTHON.exec(stderr);
|
|
41
|
+
if (incompatiblePythonError) {
|
|
42
|
+
throw new command_failed_to_run_error_1.CommandFailedError(`The current project's Python requirement ${incompatiblePythonError[1]} is not compatible with some of the required packages`, command);
|
|
43
|
+
}
|
|
44
|
+
const solverProblemError = SOLVER_PROBLEM.exec(stderr);
|
|
45
|
+
if (solverProblemError) {
|
|
46
|
+
throw new command_failed_to_run_error_1.CommandFailedError(solverProblemError[0].trim(), command);
|
|
47
|
+
}
|
|
48
|
+
if (stderr.includes(ALREADY_UP_TO_DATE)) {
|
|
49
|
+
throw new command_failed_to_run_error_1.CommandFailedError('No dependencies could be updated as they seem to be at the correct versions. Make sure installed dependencies in the environment match those in the lockfile by running `poetry update`', command);
|
|
50
|
+
}
|
|
51
|
+
throw new no_fixes_applied_1.NoFixesCouldBeAppliedError();
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=poetry-add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poetry-add.js","sourceRoot":"","sources":["../../../../../../src/plugins/python/handlers/poetry/update-dependencies/poetry-add.ts"],"names":[],"mappings":";;;AAAA,gCAAgC;AAEhC,8CAA8C;AAO9C,yEAAoE;AACpE,+EAGyC;AACzC,uGAA2F;AAC3F,iFAAwF;AAEjF,KAAK,UAAU,SAAS,CAC7B,MAAmB,EACnB,OAAmB,EACnB,QAAkB,EAClB,GAAa;;IAEb,MAAM,OAAO,GAAwB,EAAE,CAAC;IACxC,IAAI,aAAa,CAAC;IAClB,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,6CAAoB,CAAC,MAAM,CAAC,CAAC;IACjE,IAAI;QACF,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QAC1E,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAC9C,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,EAAE;YACtC,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,QAAQ,EAAE;gBACnD,GAAG;gBACH,MAAM,QAAE,MAAM,CAAC,OAAO,CAAC,OAAO,mCAAI,SAAS;aAC5C,CAAC,CAAC;YACH,IAAI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AAkB,CAC1B,yLAAyL,EACzL,OAAO,CACR,CAAC;KACH;IACD,MAAM,IAAI,6CAA0B,EAAE,CAAC;AACzC,CAAC"}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@snyk/fix",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.718.0",
|
|
4
4
|
"description": "Snyk fix library and utility",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"registry": "https://registry.npmjs.org/",
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "a7838dae9aa9474464b4e0d8cd2c0e88d65391f5"
|
|
60
60
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ensure-has-updates.js","sourceRoot":"","sources":["../../../../src/plugins/python/handlers/ensure-has-updates.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAElC,2EAAkF;AAElF,2EAAiE;AAEjE,MAAM,KAAK,GAAG,QAAQ,CAAC,wCAAwC,CAAC,CAAC;AAEjE,SAAgB,gBAAgB,CAAC,OAA4B;IAC3D,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,MAAM,IAAI,6CAA0B,EAAE,CAAC;KACxC;IACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,8CAAkB,CAAC,CAAC,CAAC,CAAC,EAAE;QAC/C,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC7D,6EAA6E;QAC7E,QAAQ;QACR,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAoB,CAAC;QACtD,MAAM,IAAI,6CAA0B,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KACnD;AACH,CAAC;AAXD,4CAWC"}
|