@fynpo/base 1.1.10 → 1.1.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/dist/caching.d.ts +25 -8
- package/dist/caching.js +45 -27
- package/dist/caching.js.map +1 -1
- package/dist/minimatch-group.d.ts +26 -0
- package/dist/minimatch-group.js +73 -1
- package/dist/minimatch-group.js.map +1 -1
- package/package.json +1 -1
package/dist/caching.d.ts
CHANGED
|
@@ -16,7 +16,17 @@ declare type FilesFilterPatterns = {
|
|
|
16
16
|
/**
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
-
declare type
|
|
19
|
+
declare type CacheBaseRule = {
|
|
20
|
+
/**
|
|
21
|
+
* minimatch options to be passed directly to minimatch
|
|
22
|
+
* Default: `{ dot: true }`
|
|
23
|
+
*/
|
|
24
|
+
minimatchOptions?: any;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
declare type CacheInputRule = FilesFilterPatterns & CacheBaseRule & {
|
|
20
30
|
/** npm scripts to include as the input */
|
|
21
31
|
npmScripts?: string | string[];
|
|
22
32
|
/** env variables to include as the input */
|
|
@@ -27,18 +37,24 @@ declare type CacheInput = FilesFilterPatterns & {
|
|
|
27
37
|
/**
|
|
28
38
|
*
|
|
29
39
|
*/
|
|
30
|
-
declare type
|
|
40
|
+
declare type CacheOutputRule = FilesFilterPatterns & CacheBaseRule & {
|
|
31
41
|
/**
|
|
32
42
|
* use npm pack to create a list of files to include.
|
|
33
43
|
* will check them against the exclude patterns and ignore any that match
|
|
34
44
|
*/
|
|
35
45
|
filesFromNpmPack?: boolean;
|
|
36
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* process caching input rules and return result from it
|
|
49
|
+
*
|
|
50
|
+
* @param param0
|
|
51
|
+
* @returns result from processing input rules
|
|
52
|
+
*/
|
|
37
53
|
export declare function processInput({ cwd, input, packageJson, extra, }?: {
|
|
38
54
|
cwd?: string;
|
|
39
|
-
input:
|
|
55
|
+
input: CacheInputRule;
|
|
40
56
|
packageJson?: Record<string, string | unknown>;
|
|
41
|
-
extra?:
|
|
57
|
+
extra?: any;
|
|
42
58
|
}): Promise<{
|
|
43
59
|
files: string[];
|
|
44
60
|
data: {
|
|
@@ -46,22 +62,23 @@ export declare function processInput({ cwd, input, packageJson, extra, }?: {
|
|
|
46
62
|
versions: any;
|
|
47
63
|
npmScripts: any;
|
|
48
64
|
fileHashes: Record<string, string>;
|
|
49
|
-
extra:
|
|
65
|
+
extra: any;
|
|
50
66
|
};
|
|
51
67
|
hash: string;
|
|
52
68
|
}>;
|
|
53
69
|
/**
|
|
70
|
+
* process lifecycle caching input rules
|
|
54
71
|
*
|
|
55
72
|
* @param param0
|
|
56
73
|
* @returns
|
|
57
74
|
*/
|
|
58
75
|
export declare function processLifecycleInput({ cwd, input, packageJson, }?: {
|
|
59
76
|
cwd?: string;
|
|
60
|
-
input:
|
|
77
|
+
input: CacheInputRule;
|
|
61
78
|
packageJson?: Record<string, string | unknown>;
|
|
62
79
|
}): Promise<{}>;
|
|
63
80
|
/**
|
|
64
|
-
* Process build cache output
|
|
81
|
+
* Process build cache output rules.
|
|
65
82
|
*
|
|
66
83
|
* @param param0
|
|
67
84
|
* @returns
|
|
@@ -74,7 +91,7 @@ export declare function processOutput({ cwd, inputHash, calcHash, output, preFil
|
|
|
74
91
|
/** Should we calculate hash for the output files? */
|
|
75
92
|
calcHash?: boolean;
|
|
76
93
|
/** output config */
|
|
77
|
-
output:
|
|
94
|
+
output: CacheOutputRule;
|
|
78
95
|
/** list of pre-determined files, will be filtered with output.exclude */
|
|
79
96
|
preFiles?: string[];
|
|
80
97
|
}): Promise<{
|
package/dist/caching.js
CHANGED
|
@@ -8,25 +8,33 @@ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
|
8
8
|
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
9
9
|
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
10
10
|
const crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
|
|
11
|
+
const minimatch_group_1 = require("./minimatch-group");
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
+
* create a sha256 hash for some data
|
|
13
14
|
*
|
|
14
|
-
* @param
|
|
15
|
+
* @param data
|
|
15
16
|
* @returns
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const hash = crypto_1.default.createHash("sha256").update(data).digest(encoding);
|
|
20
|
-
return hash;
|
|
18
|
+
function hashData1(data, encoding = "base64url") {
|
|
19
|
+
return crypto_1.default.createHash("sha256").update(data).digest(encoding);
|
|
21
20
|
}
|
|
21
|
+
function hashData2(data, encoding = "base64url") {
|
|
22
|
+
if (encoding === "base64url") {
|
|
23
|
+
return hashData1(data, "base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
24
|
+
}
|
|
25
|
+
return hashData1(data, encoding);
|
|
26
|
+
}
|
|
27
|
+
const hashData = typeof crypto_1.default.createHash("sha256").digest("base64url") === "string" ? hashData1 : hashData2;
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
29
|
+
* generate sha256 has of a file
|
|
24
30
|
*
|
|
25
|
-
* @param
|
|
31
|
+
* @param filename
|
|
26
32
|
* @returns
|
|
27
33
|
*/
|
|
28
|
-
function
|
|
29
|
-
|
|
34
|
+
async function hashFile(filename, encoding = "base64url") {
|
|
35
|
+
const data = await fs_1.default.promises.readFile(filename);
|
|
36
|
+
const hash = hashData(data, encoding);
|
|
37
|
+
return hash;
|
|
30
38
|
}
|
|
31
39
|
/**
|
|
32
40
|
* generate hash for an array of files
|
|
@@ -67,15 +75,6 @@ function makeMmPatterns(patterns, options = { dot: true }) {
|
|
|
67
75
|
.map((x) => x && new minimatch_1.default.Minimatch(x, options))
|
|
68
76
|
.filter((x) => x);
|
|
69
77
|
}
|
|
70
|
-
/**
|
|
71
|
-
*
|
|
72
|
-
* @param fullPath
|
|
73
|
-
* @param patterns
|
|
74
|
-
* @returns
|
|
75
|
-
*/
|
|
76
|
-
function checkMmMatch(fullPath, patterns) {
|
|
77
|
-
return !lodash_1.default.isEmpty(patterns) && patterns.find((patternMm) => patternMm.match(fullPath));
|
|
78
|
-
}
|
|
79
78
|
/**
|
|
80
79
|
* Scan for files using include and exclude patterns
|
|
81
80
|
*
|
|
@@ -85,34 +84,53 @@ function checkMmMatch(fullPath, patterns) {
|
|
|
85
84
|
*/
|
|
86
85
|
async function scanFiles(cwd, includes, excludes) {
|
|
87
86
|
const filter = (_file, _path, extras) => {
|
|
88
|
-
if (!checkMmMatch(extras.dirFile, includes) || checkMmMatch(extras.dirFile, excludes)) {
|
|
87
|
+
if (!(0, minimatch_group_1.checkMmMatch)(extras.dirFile, includes) || (0, minimatch_group_1.checkMmMatch)(extras.dirFile, excludes)) {
|
|
89
88
|
return false;
|
|
90
89
|
}
|
|
91
90
|
return true;
|
|
92
91
|
};
|
|
92
|
+
const dirIncludes = includes.map((mx) => (0, minimatch_group_1.deconstructMM)(mx));
|
|
93
|
+
const filterDir = (_file, _path, extras) => {
|
|
94
|
+
const dir = `${extras.dirFile}/`; // add extra / to force matching directory
|
|
95
|
+
const inc = dirIncludes.find((di) => (0, minimatch_group_1.checkMmMatch)(dir, di.mms));
|
|
96
|
+
if (inc) {
|
|
97
|
+
const exc = (0, minimatch_group_1.checkMmMatch)(dir, excludes);
|
|
98
|
+
if (!exc) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
};
|
|
93
104
|
return (await (0, filter_scan_dir_1.filterScanDir)({
|
|
94
105
|
cwd,
|
|
95
106
|
filter,
|
|
96
|
-
filterDir
|
|
107
|
+
filterDir,
|
|
97
108
|
fullStat: false,
|
|
98
109
|
concurrency: 500,
|
|
99
110
|
})).sort();
|
|
100
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* process caching input rules and return result from it
|
|
114
|
+
*
|
|
115
|
+
* @param param0
|
|
116
|
+
* @returns result from processing input rules
|
|
117
|
+
*/
|
|
101
118
|
async function processInput({ cwd, input, packageJson, extra, } = { input: {} }) {
|
|
102
|
-
const files = await scanFiles(cwd, makeMmPatterns(input.include), makeMmPatterns(input.exclude));
|
|
119
|
+
const files = await scanFiles(cwd, makeMmPatterns(input.include, input.minimatchOptions), makeMmPatterns(input.exclude, input.minimatchOptions));
|
|
103
120
|
const fileHashes = await hashFiles(cwd, files);
|
|
104
121
|
const data = {
|
|
105
122
|
env: lodash_1.default.pick(process.env, input.includeEnv),
|
|
106
123
|
versions: lodash_1.default.pick(process.versions, input.includeVersions),
|
|
107
124
|
npmScripts: lodash_1.default.pick(lodash_1.default.get(packageJson || (await readPackageJson(cwd)), "scripts"), input.npmScripts),
|
|
108
125
|
fileHashes,
|
|
109
|
-
extra: extra ||
|
|
126
|
+
extra: extra || {}, // additional data
|
|
110
127
|
};
|
|
111
128
|
const hash = hashData(JSON.stringify(data));
|
|
112
129
|
return { files, data, hash };
|
|
113
130
|
}
|
|
114
131
|
exports.processInput = processInput;
|
|
115
132
|
/**
|
|
133
|
+
* process lifecycle caching input rules
|
|
116
134
|
*
|
|
117
135
|
* @param param0
|
|
118
136
|
* @returns
|
|
@@ -127,19 +145,19 @@ async function processLifecycleInput({ cwd, input, packageJson, } = { input: {}
|
|
|
127
145
|
}
|
|
128
146
|
exports.processLifecycleInput = processLifecycleInput;
|
|
129
147
|
/**
|
|
130
|
-
* Process build cache output
|
|
148
|
+
* Process build cache output rules.
|
|
131
149
|
*
|
|
132
150
|
* @param param0
|
|
133
151
|
* @returns
|
|
134
152
|
*/
|
|
135
153
|
async function processOutput({ cwd, inputHash, calcHash, output, preFiles, } = { output: {} }) {
|
|
136
|
-
const mmIncludes = makeMmPatterns(output.include);
|
|
137
|
-
const mmExcludes = makeMmPatterns(output.exclude);
|
|
154
|
+
const mmIncludes = makeMmPatterns(output.include, output.minimatchOptions);
|
|
155
|
+
const mmExcludes = makeMmPatterns(output.exclude, output.minimatchOptions);
|
|
138
156
|
const files = await scanFiles(cwd, mmIncludes, mmExcludes);
|
|
139
157
|
preFiles = []
|
|
140
158
|
.concat(preFiles)
|
|
141
159
|
.filter((x) => {
|
|
142
|
-
if (!x ||
|
|
160
|
+
if (!x || (0, minimatch_group_1.unrollMmMatch)(x, mmExcludes)) {
|
|
143
161
|
return false;
|
|
144
162
|
}
|
|
145
163
|
return true;
|
package/dist/caching.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caching.js","sourceRoot":"","sources":["../src/caching.ts"],"names":[],"mappings":";;;;AAAA,qDAA4D;AAC5D,uEAA2B;AAC3B,iEAAuB;AACvB,yDAAoB;AACpB,6DAAwB;AACxB,iEAA4B;
|
|
1
|
+
{"version":3,"file":"caching.js","sourceRoot":"","sources":["../src/caching.ts"],"names":[],"mappings":";;;;AAAA,qDAA4D;AAC5D,uEAA2B;AAC3B,iEAAuB;AACvB,yDAAoB;AACpB,6DAAwB;AACxB,iEAA4B;AAC5B,uDAA+E;AAsD/E;;;;;GAKG;AACH,SAAS,SAAS,CAAC,IAAS,EAAE,WAAwC,WAAW;IAC/E,OAAO,gBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,SAAS,CAAC,IAAS,EAAE,WAAwC,WAAW;IAC/E,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,OAAO,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;KAC5F;IACD,OAAO,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,QAAQ,GACZ,OAAO,gBAAM,CA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OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,cAAI,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAElD,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,MAAM,QAAQ,GAAG,gBAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,IAAI,IAAI,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;IAErC,EAAE;IAEF,IAAI,QAAQ,EAAE;QACZ,UAAU,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC5C,IAAI,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;QACjC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;KACvC;IAED,EAAE;IACF,OAAO;QACL,KAAK,EAAE,QAAQ;QACf,IAAI;QACJ,IAAI;QACJ,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE;QAClB,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE;KACnB,CAAC;AACJ,CAAC;AAxDD,sCAwDC"}
|
|
@@ -23,4 +23,30 @@ export declare type MMGroups = Record<string, MMGroup[]>;
|
|
|
23
23
|
* @returns object of grouped minimatch objects
|
|
24
24
|
*/
|
|
25
25
|
export declare function groupMM(mms: mm.IMinimatch[], groups: MMGroups): MMGroups;
|
|
26
|
+
/**
|
|
27
|
+
* process a minimatch pattern to group them for matching directories
|
|
28
|
+
*
|
|
29
|
+
* - needs to create a new pattern at every non-string part
|
|
30
|
+
* @param pattern
|
|
31
|
+
*/
|
|
32
|
+
export declare function deconstructMM(m0: mm.IMinimatch): {
|
|
33
|
+
m0: mm.IMinimatch;
|
|
34
|
+
mms: mm.IMinimatch[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* check that a path matches against a list of minimatch patterns
|
|
38
|
+
*
|
|
39
|
+
* @param fullPath
|
|
40
|
+
* @param patterns
|
|
41
|
+
* @returns the first pattern that match or false
|
|
42
|
+
*/
|
|
43
|
+
export declare function checkMmMatch(fullPath: string, patterns: mm.IMinimatch[]): mm.IMinimatch;
|
|
44
|
+
/**
|
|
45
|
+
* Take a full path and match each level of it to a list of minimatch patterns
|
|
46
|
+
*
|
|
47
|
+
* @param path
|
|
48
|
+
* @param mms
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
export declare function unrollMmMatch(path: string, mms: mm.IMinimatch[]): boolean;
|
|
26
52
|
export {};
|
package/dist/minimatch-group.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.groupMM = void 0;
|
|
3
|
+
exports.unrollMmMatch = exports.checkMmMatch = exports.deconstructMM = exports.groupMM = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const minimatch_1 = (0, tslib_1.__importDefault)(require("minimatch"));
|
|
6
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
4
7
|
/**
|
|
5
8
|
* process a list of minimatch objects and group them by the string prefix of their patterns
|
|
6
9
|
*
|
|
@@ -32,4 +35,73 @@ function groupMM(mms, groups) {
|
|
|
32
35
|
return groups;
|
|
33
36
|
}
|
|
34
37
|
exports.groupMM = groupMM;
|
|
38
|
+
/**
|
|
39
|
+
* process a minimatch pattern to group them for matching directories
|
|
40
|
+
*
|
|
41
|
+
* - needs to create a new pattern at every non-string part
|
|
42
|
+
* @param pattern
|
|
43
|
+
*/
|
|
44
|
+
function deconstructMM(m0) {
|
|
45
|
+
const mms = [];
|
|
46
|
+
const patterns = { m0, mms };
|
|
47
|
+
const set = m0.set[0];
|
|
48
|
+
const globParts = m0.globParts[0];
|
|
49
|
+
const iParts = [];
|
|
50
|
+
const { GLOBSTAR } = minimatch_1.default;
|
|
51
|
+
for (let ix = 0; ix < set.length; ix++) {
|
|
52
|
+
const s = set[ix];
|
|
53
|
+
const g = globParts[ix];
|
|
54
|
+
// if we hit something that's not string, then we need a mm with just the strings
|
|
55
|
+
// because a dir like "src" will not match "src/*"
|
|
56
|
+
if (typeof s !== "string" && iParts.length > 0) {
|
|
57
|
+
mms.push(new minimatch_1.default.Minimatch(iParts.join("/"), m0.options));
|
|
58
|
+
}
|
|
59
|
+
if (ix === set.length - 1) {
|
|
60
|
+
mms.push(m0);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
iParts.push(g);
|
|
65
|
+
if (typeof s !== "string") {
|
|
66
|
+
mms.push(new minimatch_1.default.Minimatch(iParts.join("/"), m0.options));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (s === GLOBSTAR) {
|
|
70
|
+
// a pattern ending in GLOBSTAR will match anything
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return patterns;
|
|
75
|
+
}
|
|
76
|
+
exports.deconstructMM = deconstructMM;
|
|
77
|
+
/**
|
|
78
|
+
* check that a path matches against a list of minimatch patterns
|
|
79
|
+
*
|
|
80
|
+
* @param fullPath
|
|
81
|
+
* @param patterns
|
|
82
|
+
* @returns the first pattern that match or false
|
|
83
|
+
*/
|
|
84
|
+
function checkMmMatch(fullPath, patterns) {
|
|
85
|
+
return !lodash_1.default.isEmpty(patterns) && patterns.find((patternMm) => patternMm.match(fullPath));
|
|
86
|
+
}
|
|
87
|
+
exports.checkMmMatch = checkMmMatch;
|
|
88
|
+
/**
|
|
89
|
+
* Take a full path and match each level of it to a list of minimatch patterns
|
|
90
|
+
*
|
|
91
|
+
* @param path
|
|
92
|
+
* @param mms
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
function unrollMmMatch(path, mms) {
|
|
96
|
+
const parts = path.split("/");
|
|
97
|
+
let rp;
|
|
98
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
99
|
+
rp = rp !== undefined ? rp + "/" + parts[i] : parts[i];
|
|
100
|
+
if (checkMmMatch(`${rp}/`, mms)) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return !!checkMmMatch(path, mms);
|
|
105
|
+
}
|
|
106
|
+
exports.unrollMmMatch = unrollMmMatch;
|
|
35
107
|
//# sourceMappingURL=minimatch-group.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minimatch-group.js","sourceRoot":"","sources":["../src/minimatch-group.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"minimatch-group.js","sourceRoot":"","sources":["../src/minimatch-group.ts"],"names":[],"mappings":";;;;AAAA,uEAA2B;AAC3B,iEAAuB;AAoBvB;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,GAAoB,EAAE,MAAgB;IAC5D,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;QACjB,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YAC5B,MAAM,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;YACvD,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1C,MAAM,IAAI,GAAG;gBACX,EAAE;gBACF,GAAG;gBACH,KAAK;gBACL,EAAE;gBACF,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,EAAE;aACxB,CAAC;YAEF,wBAAwB;YACxB,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE;gBAClB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