@fynpo/base 1.1.11 → 1.1.14
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 +28 -8
- package/dist/caching.js +53 -27
- package/dist/caching.js.map +1 -1
- package/dist/minimatch-group.d.ts +26 -0
- package/dist/minimatch-group.js +74 -1
- package/dist/minimatch-group.js.map +1 -1
- package/package.json +1 -1
package/dist/caching.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Crypto from "crypto";
|
|
1
3
|
/**
|
|
2
4
|
*
|
|
3
5
|
*/
|
|
@@ -16,7 +18,17 @@ declare type FilesFilterPatterns = {
|
|
|
16
18
|
/**
|
|
17
19
|
*
|
|
18
20
|
*/
|
|
19
|
-
declare type
|
|
21
|
+
declare type CacheBaseRule = {
|
|
22
|
+
/**
|
|
23
|
+
* minimatch options to be passed directly to minimatch
|
|
24
|
+
* Default: `{ dot: true }`
|
|
25
|
+
*/
|
|
26
|
+
minimatchOptions?: any;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
declare type CacheInputRule = FilesFilterPatterns & CacheBaseRule & {
|
|
20
32
|
/** npm scripts to include as the input */
|
|
21
33
|
npmScripts?: string | string[];
|
|
22
34
|
/** env variables to include as the input */
|
|
@@ -27,18 +39,25 @@ declare type CacheInput = FilesFilterPatterns & {
|
|
|
27
39
|
/**
|
|
28
40
|
*
|
|
29
41
|
*/
|
|
30
|
-
declare type
|
|
42
|
+
declare type CacheOutputRule = FilesFilterPatterns & CacheBaseRule & {
|
|
31
43
|
/**
|
|
32
44
|
* use npm pack to create a list of files to include.
|
|
33
45
|
* will check them against the exclude patterns and ignore any that match
|
|
34
46
|
*/
|
|
35
47
|
filesFromNpmPack?: boolean;
|
|
36
48
|
};
|
|
49
|
+
export declare const readHashDigest: (hash: Crypto.Hash, encoding?: BufferEncoding) => any;
|
|
50
|
+
/**
|
|
51
|
+
* process caching input rules and return result from it
|
|
52
|
+
*
|
|
53
|
+
* @param param0
|
|
54
|
+
* @returns result from processing input rules
|
|
55
|
+
*/
|
|
37
56
|
export declare function processInput({ cwd, input, packageJson, extra, }?: {
|
|
38
57
|
cwd?: string;
|
|
39
|
-
input:
|
|
58
|
+
input: CacheInputRule;
|
|
40
59
|
packageJson?: Record<string, string | unknown>;
|
|
41
|
-
extra?:
|
|
60
|
+
extra?: any;
|
|
42
61
|
}): Promise<{
|
|
43
62
|
files: string[];
|
|
44
63
|
data: {
|
|
@@ -46,22 +65,23 @@ export declare function processInput({ cwd, input, packageJson, extra, }?: {
|
|
|
46
65
|
versions: any;
|
|
47
66
|
npmScripts: any;
|
|
48
67
|
fileHashes: Record<string, string>;
|
|
49
|
-
extra:
|
|
68
|
+
extra: any;
|
|
50
69
|
};
|
|
51
70
|
hash: string;
|
|
52
71
|
}>;
|
|
53
72
|
/**
|
|
73
|
+
* process lifecycle caching input rules
|
|
54
74
|
*
|
|
55
75
|
* @param param0
|
|
56
76
|
* @returns
|
|
57
77
|
*/
|
|
58
78
|
export declare function processLifecycleInput({ cwd, input, packageJson, }?: {
|
|
59
79
|
cwd?: string;
|
|
60
|
-
input:
|
|
80
|
+
input: CacheInputRule;
|
|
61
81
|
packageJson?: Record<string, string | unknown>;
|
|
62
82
|
}): Promise<{}>;
|
|
63
83
|
/**
|
|
64
|
-
* Process build cache output
|
|
84
|
+
* Process build cache output rules.
|
|
65
85
|
*
|
|
66
86
|
* @param param0
|
|
67
87
|
* @returns
|
|
@@ -74,7 +94,7 @@ export declare function processOutput({ cwd, inputHash, calcHash, output, preFil
|
|
|
74
94
|
/** Should we calculate hash for the output files? */
|
|
75
95
|
calcHash?: boolean;
|
|
76
96
|
/** output config */
|
|
77
|
-
output:
|
|
97
|
+
output: CacheOutputRule;
|
|
78
98
|
/** list of pre-determined files, will be filtered with output.exclude */
|
|
79
99
|
preFiles?: string[];
|
|
80
100
|
}): Promise<{
|
package/dist/caching.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.processOutput = exports.processLifecycleInput = exports.processInput = void 0;
|
|
3
|
+
exports.processOutput = exports.processLifecycleInput = exports.processInput = exports.readHashDigest = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const filter_scan_dir_1 = require("filter-scan-dir");
|
|
6
6
|
const minimatch_1 = (0, tslib_1.__importDefault)(require("minimatch"));
|
|
@@ -8,6 +8,7 @@ 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
|
*
|
|
@@ -17,13 +18,33 @@ const crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
|
|
|
17
18
|
function hashData1(data, encoding = "base64url") {
|
|
18
19
|
return crypto_1.default.createHash("sha256").update(data).digest(encoding);
|
|
19
20
|
}
|
|
21
|
+
function makeBase64Url(hash) {
|
|
22
|
+
return hash.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
23
|
+
}
|
|
20
24
|
function hashData2(data, encoding = "base64url") {
|
|
21
25
|
if (encoding === "base64url") {
|
|
22
|
-
return hashData1(data, "base64")
|
|
26
|
+
return makeBase64Url(hashData1(data, "base64"));
|
|
23
27
|
}
|
|
24
28
|
return hashData1(data, encoding);
|
|
25
29
|
}
|
|
26
|
-
const
|
|
30
|
+
const hasBase64Url = typeof crypto_1.default.createHash("sha256").digest("base64url") === "string";
|
|
31
|
+
const hashData = hasBase64Url ? hashData1 : hashData2;
|
|
32
|
+
exports.readHashDigest = hasBase64Url
|
|
33
|
+
? (hash, encoding = "base64url") => {
|
|
34
|
+
hash.setEncoding(encoding);
|
|
35
|
+
hash.end();
|
|
36
|
+
return hash.read();
|
|
37
|
+
}
|
|
38
|
+
: (hash, encoding = "base64url") => {
|
|
39
|
+
if (encoding === "base64url") {
|
|
40
|
+
hash.setEncoding("base64");
|
|
41
|
+
hash.end();
|
|
42
|
+
return makeBase64Url(hash.read());
|
|
43
|
+
}
|
|
44
|
+
hash.setEncoding(encoding);
|
|
45
|
+
hash.end();
|
|
46
|
+
return hash.read();
|
|
47
|
+
};
|
|
27
48
|
/**
|
|
28
49
|
* generate sha256 has of a file
|
|
29
50
|
*
|
|
@@ -74,15 +95,6 @@ function makeMmPatterns(patterns, options = { dot: true }) {
|
|
|
74
95
|
.map((x) => x && new minimatch_1.default.Minimatch(x, options))
|
|
75
96
|
.filter((x) => x);
|
|
76
97
|
}
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @param fullPath
|
|
80
|
-
* @param patterns
|
|
81
|
-
* @returns
|
|
82
|
-
*/
|
|
83
|
-
function checkMmMatch(fullPath, patterns) {
|
|
84
|
-
return !lodash_1.default.isEmpty(patterns) && patterns.find((patternMm) => patternMm.match(fullPath));
|
|
85
|
-
}
|
|
86
98
|
/**
|
|
87
99
|
* Scan for files using include and exclude patterns
|
|
88
100
|
*
|
|
@@ -92,34 +104,53 @@ function checkMmMatch(fullPath, patterns) {
|
|
|
92
104
|
*/
|
|
93
105
|
async function scanFiles(cwd, includes, excludes) {
|
|
94
106
|
const filter = (_file, _path, extras) => {
|
|
95
|
-
if (!checkMmMatch(extras.dirFile, includes) || checkMmMatch(extras.dirFile, excludes)) {
|
|
107
|
+
if (!(0, minimatch_group_1.checkMmMatch)(extras.dirFile, includes) || (0, minimatch_group_1.checkMmMatch)(extras.dirFile, excludes)) {
|
|
96
108
|
return false;
|
|
97
109
|
}
|
|
98
110
|
return true;
|
|
99
111
|
};
|
|
112
|
+
const dirIncludes = includes.map((mx) => (0, minimatch_group_1.deconstructMM)(mx));
|
|
113
|
+
const filterDir = (_file, _path, extras) => {
|
|
114
|
+
const dir = `${extras.dirFile}/`; // add extra / to force matching directory
|
|
115
|
+
const inc = dirIncludes.find((di) => (0, minimatch_group_1.checkMmMatch)(dir, di.mms));
|
|
116
|
+
if (inc) {
|
|
117
|
+
const exc = (0, minimatch_group_1.checkMmMatch)(dir, excludes);
|
|
118
|
+
if (!exc) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
};
|
|
100
124
|
return (await (0, filter_scan_dir_1.filterScanDir)({
|
|
101
125
|
cwd,
|
|
102
126
|
filter,
|
|
103
|
-
filterDir
|
|
127
|
+
filterDir,
|
|
104
128
|
fullStat: false,
|
|
105
129
|
concurrency: 500,
|
|
106
130
|
})).sort();
|
|
107
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* process caching input rules and return result from it
|
|
134
|
+
*
|
|
135
|
+
* @param param0
|
|
136
|
+
* @returns result from processing input rules
|
|
137
|
+
*/
|
|
108
138
|
async function processInput({ cwd, input, packageJson, extra, } = { input: {} }) {
|
|
109
|
-
const files = await scanFiles(cwd, makeMmPatterns(input.include), makeMmPatterns(input.exclude));
|
|
139
|
+
const files = await scanFiles(cwd, makeMmPatterns(input.include, input.minimatchOptions), makeMmPatterns(input.exclude, input.minimatchOptions));
|
|
110
140
|
const fileHashes = await hashFiles(cwd, files);
|
|
111
141
|
const data = {
|
|
112
142
|
env: lodash_1.default.pick(process.env, input.includeEnv),
|
|
113
143
|
versions: lodash_1.default.pick(process.versions, input.includeVersions),
|
|
114
144
|
npmScripts: lodash_1.default.pick(lodash_1.default.get(packageJson || (await readPackageJson(cwd)), "scripts"), input.npmScripts),
|
|
115
145
|
fileHashes,
|
|
116
|
-
extra: extra ||
|
|
146
|
+
extra: extra || {}, // additional data
|
|
117
147
|
};
|
|
118
148
|
const hash = hashData(JSON.stringify(data));
|
|
119
149
|
return { files, data, hash };
|
|
120
150
|
}
|
|
121
151
|
exports.processInput = processInput;
|
|
122
152
|
/**
|
|
153
|
+
* process lifecycle caching input rules
|
|
123
154
|
*
|
|
124
155
|
* @param param0
|
|
125
156
|
* @returns
|
|
@@ -134,19 +165,19 @@ async function processLifecycleInput({ cwd, input, packageJson, } = { input: {}
|
|
|
134
165
|
}
|
|
135
166
|
exports.processLifecycleInput = processLifecycleInput;
|
|
136
167
|
/**
|
|
137
|
-
* Process build cache output
|
|
168
|
+
* Process build cache output rules.
|
|
138
169
|
*
|
|
139
170
|
* @param param0
|
|
140
171
|
* @returns
|
|
141
172
|
*/
|
|
142
173
|
async function processOutput({ cwd, inputHash, calcHash, output, preFiles, } = { output: {} }) {
|
|
143
|
-
const mmIncludes = makeMmPatterns(output.include);
|
|
144
|
-
const mmExcludes = makeMmPatterns(output.exclude);
|
|
174
|
+
const mmIncludes = makeMmPatterns(output.include, output.minimatchOptions);
|
|
175
|
+
const mmExcludes = makeMmPatterns(output.exclude, output.minimatchOptions);
|
|
145
176
|
const files = await scanFiles(cwd, mmIncludes, mmExcludes);
|
|
146
177
|
preFiles = []
|
|
147
178
|
.concat(preFiles)
|
|
148
179
|
.filter((x) => {
|
|
149
|
-
if (!x ||
|
|
180
|
+
if (!x || (0, minimatch_group_1.unrollMmMatch)(x, mmExcludes)) {
|
|
150
181
|
return false;
|
|
151
182
|
}
|
|
152
183
|
return true;
|
|
@@ -163,13 +194,8 @@ async function processOutput({ cwd, inputHash, calcHash, output, preFiles, } = {
|
|
|
163
194
|
hash = hashData(JSON.stringify(data));
|
|
164
195
|
}
|
|
165
196
|
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
data,
|
|
169
|
-
hash,
|
|
170
|
-
access: Date.now(),
|
|
171
|
-
create: Date.now(),
|
|
172
|
-
};
|
|
197
|
+
const now = Date.now();
|
|
198
|
+
return { files: allFiles, data, hash, access: now, create: now };
|
|
173
199
|
}
|
|
174
200
|
exports.processOutput = processOutput;
|
|
175
201
|
//# sourceMappingURL=caching.js.map
|
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,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,SAAS,CAAC,IAAS,EAAE,WAAwC,WAAW;IAC/E,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,OAAO,aAAa,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;KACjD;IACD,OAAO,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,gBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,QAAQ,CAAC;AAEzF,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAA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AAC;KACvC;IAED,EAAE;IACF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACnE,CAAC;AAnDD,sCAmDC"}
|
|
@@ -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 m0 minimatch 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[]): false | 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[]): false | mm.IMinimatch;
|
|
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,74 @@ 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 m0 minimatch 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
|
+
const m1 = checkMmMatch(`${rp}/`, mms);
|
|
101
|
+
if (m1) {
|
|
102
|
+
return m1;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return checkMmMatch(path, mms);
|
|
106
|
+
}
|
|
107
|
+
exports.unrollMmMatch = unrollMmMatch;
|
|
35
108
|
//# 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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