@rsdoctor/utils 1.6.4 → 1.6.5
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/build/json.d.cts +1 -1
- package/dist/build/json.d.ts +1 -1
- package/dist/build.cjs +26 -12
- package/dist/build.js +12 -6
- package/dist/common.cjs +57 -17
- package/dist/common.js +56 -26
- package/package.json +2 -2
package/dist/build/json.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { SDK } from '@rsdoctor/types';
|
|
2
|
-
export declare function stringify<T, P = T extends undefined ? undefined : string>(json: T, replacer?: (this: any, key: string, value: any) => any, space?: string | number, cycle?: boolean): Promise<P>;
|
|
2
|
+
export declare function stringify<T, P = T extends undefined ? undefined : string>(json: T, replacer?: (this: any, key: string, value: any) => any, space?: string | number, cycle?: boolean, chunkSize?: number): Promise<P>;
|
|
3
3
|
export declare const readPackageJson: (file: string, readFile?: SDK.GetPackageFile) => SDK.PackageBasicData | undefined;
|
package/dist/build/json.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { SDK } from '@rsdoctor/types';
|
|
2
|
-
export declare function stringify<T, P = T extends undefined ? undefined : string>(json: T, replacer?: (this: any, key: string, value: any) => any, space?: string | number, cycle?: boolean): Promise<P>;
|
|
2
|
+
export declare function stringify<T, P = T extends undefined ? undefined : string>(json: T, replacer?: (this: any, key: string, value: any) => any, space?: string | number, cycle?: boolean, chunkSize?: number): Promise<P>;
|
|
3
3
|
export declare const readPackageJson: (file: string, readFile?: SDK.GetPackageFile) => SDK.PackageBasicData | undefined;
|
package/dist/build.cjs
CHANGED
|
@@ -5,9 +5,9 @@ var __webpack_modules__ = {
|
|
|
5
5
|
function random(min, max) {
|
|
6
6
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
7
7
|
}
|
|
8
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
8
|
+
__webpack_require__("zlib"), __webpack_require__("buffer"), __webpack_require__("./src/logger.ts"), __webpack_require__.d(__webpack_exports__, {
|
|
9
9
|
random: ()=>random
|
|
10
|
-
})
|
|
10
|
+
});
|
|
11
11
|
},
|
|
12
12
|
"./src/common/index.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
13
13
|
__webpack_require__.d(__webpack_exports__, {
|
|
@@ -16,7 +16,7 @@ var __webpack_modules__ = {
|
|
|
16
16
|
var package_namespaceObject = {};
|
|
17
17
|
__webpack_require__.r(package_namespaceObject), __webpack_require__.d(package_namespaceObject, {
|
|
18
18
|
getPackageMetaFromModulePath: ()=>getPackageMetaFromModulePath
|
|
19
|
-
}), __webpack_require__("./src/common/algorithm.ts"), __webpack_require__("
|
|
19
|
+
}), __webpack_require__("buffer"), __webpack_require__("stream"), require("string_decoder"), __webpack_require__("zlib"), __webpack_require__("path"), __webpack_require__("./src/common/algorithm.ts"), __webpack_require__("process"), __webpack_require__("@rsdoctor/types"), __webpack_require__("./src/logger.ts"), RegExp(`(.*)${/[-|.]/.source}(${/(?:[a-f0-9]{4,32}|[a-zA-Z]{3,}[0-9]|[a-zA-Z]*[0-9][a-zA-Z]{2,}|[a-zA-Z]*[0-9][a-zA-Z0-9]{3,31})/.source})(${/(?:\.[a-z|A-Z|0-9]{2,}){1,}/.source})$`);
|
|
20
20
|
var lodash = __webpack_require__("./src/common/lodash.ts");
|
|
21
21
|
let PACKAGE_SLUG = /[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*/, MODULE_PATH_PACKAGES = RegExp(`(?:${/(?:node_modules|~)(?:\/\.pnpm)?/.source}/)(?:(?:@${PACKAGE_SLUG.source}[/|+])?(?:${PACKAGE_SLUG.source}\\+)*(?:${PACKAGE_SLUG.source})(?:${/@[\w|\-|_|.]+/.source})?)(?:_(?:@${PACKAGE_SLUG.source}[/|+])?(?:${PACKAGE_SLUG.source})(?:@${PACKAGE_SLUG.source})?)*/`, 'g'), PACKAGE_PATH_NAME = /(?:(?:node_modules|~)(?:\/\.pnpm)?\/)(?:((?:@[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*[/|+])?(?:(?:[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*\+)*)(?:[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*))(?:@[\w|\-|_|.]+)?)(?:_((?:@[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*[/|+])?(?:[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*))(?:@[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*))*\//gm, getPackageMetaFromModulePath = (modulePath)=>{
|
|
22
22
|
var data;
|
|
@@ -95,6 +95,9 @@ var __webpack_modules__ = {
|
|
|
95
95
|
"@rsdoctor/types" (module) {
|
|
96
96
|
module.exports = require("@rsdoctor/types");
|
|
97
97
|
},
|
|
98
|
+
buffer (module) {
|
|
99
|
+
module.exports = require("buffer");
|
|
100
|
+
},
|
|
98
101
|
fs (module) {
|
|
99
102
|
module.exports = require("fs");
|
|
100
103
|
},
|
|
@@ -106,6 +109,12 @@ var __webpack_modules__ = {
|
|
|
106
109
|
},
|
|
107
110
|
process (module) {
|
|
108
111
|
module.exports = require("process");
|
|
112
|
+
},
|
|
113
|
+
stream (module) {
|
|
114
|
+
module.exports = require("stream");
|
|
115
|
+
},
|
|
116
|
+
zlib (module) {
|
|
117
|
+
module.exports = require("zlib");
|
|
109
118
|
}
|
|
110
119
|
}, __webpack_module_cache__ = {};
|
|
111
120
|
function __webpack_require__(moduleId) {
|
|
@@ -239,23 +248,22 @@ for(var __rspack_i in (()=>{
|
|
|
239
248
|
return JSON.parse(readFileSync(path));
|
|
240
249
|
}
|
|
241
250
|
let external_json_stream_stringify_namespaceObject = require("json-stream-stringify");
|
|
242
|
-
var common = __webpack_require__("./src/common/index.ts");
|
|
243
|
-
|
|
244
|
-
function stringify(json, replacer, space, cycle) {
|
|
251
|
+
var common = __webpack_require__("./src/common/index.ts"), external_stream_ = __webpack_require__("stream");
|
|
252
|
+
function stringify(json, replacer, space, cycle, chunkSize = 419430400) {
|
|
245
253
|
let jsonList = [];
|
|
246
254
|
return json && 'object' == typeof json ? new Promise((resolve, reject)=>{
|
|
247
|
-
let stream = new external_json_stream_stringify_namespaceObject.JsonStreamStringify(json, replacer, space, cycle), currentLength = 0, currentContent = '', batchProcessor = new
|
|
255
|
+
let stream = new external_json_stream_stringify_namespaceObject.JsonStreamStringify(json, replacer, space, cycle), currentLength = 0, currentContent = '', batchProcessor = new external_stream_.Transform({
|
|
248
256
|
readableObjectMode: !0,
|
|
249
257
|
transform (chunk, _encoding, callback) {
|
|
250
258
|
chunk.toString().split('\\n').forEach((line)=>{
|
|
251
|
-
currentLength + line.length >
|
|
259
|
+
currentLength + line.length > chunkSize && (jsonList.push(currentContent), currentContent = '', currentLength = 0), line.length && (currentContent += line, currentLength += line.length);
|
|
252
260
|
}), callback();
|
|
253
261
|
}
|
|
254
262
|
});
|
|
255
263
|
stream.pipe(batchProcessor).on('data', (line)=>{
|
|
256
|
-
currentLength + line.length >
|
|
264
|
+
currentLength + line.length > chunkSize && (jsonList.push(currentContent), currentContent = '', currentLength = 0), line.length && (currentContent += line, currentLength += line.length);
|
|
257
265
|
}).on('end', ()=>{
|
|
258
|
-
|
|
266
|
+
currentContent.length > 0 && jsonList.push(currentContent), resolve(jsonList);
|
|
259
267
|
}).on('error', (err)=>reject(err));
|
|
260
268
|
}) : Promise.resolve(JSON.stringify(json, replacer, space));
|
|
261
269
|
}
|
|
@@ -299,7 +307,12 @@ for(var __rspack_i in (()=>{
|
|
|
299
307
|
host
|
|
300
308
|
});
|
|
301
309
|
}
|
|
302
|
-
let createGetPortSyncFunctionString = (expectPort, host = defaultHost)
|
|
310
|
+
let createGetPortSyncFunctionString = (expectPort, host = defaultHost)=>{
|
|
311
|
+
let port = function(port) {
|
|
312
|
+
if ('number' != typeof port || !Number.isInteger(port) || port < 0 || port > 65535) throw RangeError(`Invalid port: ${String(port)}`);
|
|
313
|
+
return port;
|
|
314
|
+
}(expectPort);
|
|
315
|
+
return `
|
|
303
316
|
(() => {
|
|
304
317
|
const net = require('net');
|
|
305
318
|
|
|
@@ -329,9 +342,10 @@ async function getAvailablePort(expectPort) {
|
|
|
329
342
|
}
|
|
330
343
|
}
|
|
331
344
|
|
|
332
|
-
getAvailablePort(${
|
|
345
|
+
getAvailablePort(${port}).then(port => process.stdout.write(port.toString()));
|
|
333
346
|
})();
|
|
334
347
|
`.trim();
|
|
348
|
+
};
|
|
335
349
|
function getPortSync(expectPort, host = defaultHost) {
|
|
336
350
|
let statement = '\n' === external_os_default().EOL ? createGetPortSyncFunctionString(expectPort, host) : createGetPortSyncFunctionString(expectPort, host).replace(/\n/g, '');
|
|
337
351
|
return Number((0, external_child_process_namespaceObject.execFileSync)(process.execPath, [
|
package/dist/build.js
CHANGED
|
@@ -103,21 +103,21 @@ async function readJSON(path) {
|
|
|
103
103
|
function readJSONSync(path) {
|
|
104
104
|
return JSON.parse(readFileSync(path));
|
|
105
105
|
}
|
|
106
|
-
function stringify(json, replacer, space, cycle) {
|
|
106
|
+
function stringify(json, replacer, space, cycle, chunkSize = 419430400) {
|
|
107
107
|
let jsonList = [];
|
|
108
108
|
return json && 'object' == typeof json ? new Promise((resolve, reject)=>{
|
|
109
109
|
let stream = new JsonStreamStringify(json, replacer, space, cycle), currentLength = 0, currentContent = '', batchProcessor = new Transform({
|
|
110
110
|
readableObjectMode: !0,
|
|
111
111
|
transform (chunk, _encoding, callback) {
|
|
112
112
|
chunk.toString().split('\\n').forEach((line)=>{
|
|
113
|
-
currentLength + line.length >
|
|
113
|
+
currentLength + line.length > chunkSize && (jsonList.push(currentContent), currentContent = '', currentLength = 0), line.length && (currentContent += line, currentLength += line.length);
|
|
114
114
|
}), callback();
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
117
|
stream.pipe(batchProcessor).on('data', (line)=>{
|
|
118
|
-
currentLength + line.length >
|
|
118
|
+
currentLength + line.length > chunkSize && (jsonList.push(currentContent), currentContent = '', currentLength = 0), line.length && (currentContent += line, currentLength += line.length);
|
|
119
119
|
}).on('end', ()=>{
|
|
120
|
-
|
|
120
|
+
currentContent.length > 0 && jsonList.push(currentContent), resolve(jsonList);
|
|
121
121
|
}).on('error', (err)=>reject(err));
|
|
122
122
|
}) : Promise.resolve(JSON.stringify(json, replacer, space));
|
|
123
123
|
}
|
|
@@ -153,7 +153,12 @@ async function getPort(expectPort, host = defaultHost) {
|
|
|
153
153
|
host
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
|
-
let createGetPortSyncFunctionString = (expectPort, host = defaultHost)
|
|
156
|
+
let createGetPortSyncFunctionString = (expectPort, host = defaultHost)=>{
|
|
157
|
+
let port = function(port) {
|
|
158
|
+
if ('number' != typeof port || !Number.isInteger(port) || port < 0 || port > 65535) throw RangeError(`Invalid port: ${String(port)}`);
|
|
159
|
+
return port;
|
|
160
|
+
}(expectPort);
|
|
161
|
+
return `
|
|
157
162
|
(() => {
|
|
158
163
|
const net = require('net');
|
|
159
164
|
|
|
@@ -183,9 +188,10 @@ async function getAvailablePort(expectPort) {
|
|
|
183
188
|
}
|
|
184
189
|
}
|
|
185
190
|
|
|
186
|
-
getAvailablePort(${
|
|
191
|
+
getAvailablePort(${port}).then(port => process.stdout.write(port.toString()));
|
|
187
192
|
})();
|
|
188
193
|
`.trim();
|
|
194
|
+
};
|
|
189
195
|
function getPortSync(expectPort, host = defaultHost) {
|
|
190
196
|
let statement = '\n' === os.EOL ? createGetPortSyncFunctionString(expectPort, host) : createGetPortSyncFunctionString(expectPort, host).replace(/\n/g, '');
|
|
191
197
|
return Number(execFileSync(process.execPath, [
|
package/dist/common.cjs
CHANGED
|
@@ -2,14 +2,8 @@
|
|
|
2
2
|
const __rslib_import_meta_url__ = "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
3
|
var __webpack_modules__ = {
|
|
4
4
|
"./src/common/algorithm.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
5
|
-
__webpack_require__.r(__webpack_exports__)
|
|
6
|
-
|
|
7
|
-
decompressText: ()=>decompressText,
|
|
8
|
-
mergeIntervals: ()=>mergeIntervals,
|
|
9
|
-
random: ()=>random
|
|
10
|
-
});
|
|
11
|
-
let external_zlib_namespaceObject = require("zlib"), external_buffer_namespaceObject = require("buffer");
|
|
12
|
-
var logger = __webpack_require__("./src/logger.ts");
|
|
5
|
+
__webpack_require__.r(__webpack_exports__);
|
|
6
|
+
var zlib__rspack_import_0 = __webpack_require__("zlib"), buffer__rspack_import_1 = __webpack_require__("buffer"), _logger__rspack_import_2 = __webpack_require__("./src/logger.ts");
|
|
13
7
|
function mergeIntervals(intervals) {
|
|
14
8
|
let previous, current;
|
|
15
9
|
intervals.sort((a, b)=>a[0] - b[0]);
|
|
@@ -19,17 +13,23 @@ var __webpack_modules__ = {
|
|
|
19
13
|
}
|
|
20
14
|
function compressText(input) {
|
|
21
15
|
try {
|
|
22
|
-
return (0,
|
|
16
|
+
return (0, zlib__rspack_import_0.deflateSync)(input).toString('base64');
|
|
23
17
|
} catch (e) {
|
|
24
|
-
return
|
|
18
|
+
return _logger__rspack_import_2.logger.debug(`compressText error: ${e}`), '';
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
21
|
function decompressText(input) {
|
|
28
|
-
return (0,
|
|
22
|
+
return (0, zlib__rspack_import_0.inflateSync)(buffer__rspack_import_1.Buffer.from(input, 'base64')).toString();
|
|
29
23
|
}
|
|
30
24
|
function random(min, max) {
|
|
31
25
|
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
32
26
|
}
|
|
27
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
28
|
+
compressText: ()=>compressText,
|
|
29
|
+
decompressText: ()=>decompressText,
|
|
30
|
+
mergeIntervals: ()=>mergeIntervals,
|
|
31
|
+
random: ()=>random
|
|
32
|
+
});
|
|
33
33
|
},
|
|
34
34
|
"./src/common/crypto.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
35
35
|
function encode(str) {
|
|
@@ -338,6 +338,9 @@ var __webpack_modules__ = {
|
|
|
338
338
|
"@rsdoctor/types" (module) {
|
|
339
339
|
module.exports = require("@rsdoctor/types");
|
|
340
340
|
},
|
|
341
|
+
buffer (module) {
|
|
342
|
+
module.exports = require("buffer");
|
|
343
|
+
},
|
|
341
344
|
fs (module) {
|
|
342
345
|
module.exports = require("fs");
|
|
343
346
|
},
|
|
@@ -349,6 +352,12 @@ var __webpack_modules__ = {
|
|
|
349
352
|
},
|
|
350
353
|
process (module) {
|
|
351
354
|
module.exports = require("process");
|
|
355
|
+
},
|
|
356
|
+
stream (module) {
|
|
357
|
+
module.exports = require("stream");
|
|
358
|
+
},
|
|
359
|
+
zlib (module) {
|
|
360
|
+
module.exports = require("zlib");
|
|
352
361
|
}
|
|
353
362
|
}, __webpack_module_cache__ = {};
|
|
354
363
|
function __webpack_require__(moduleId) {
|
|
@@ -514,7 +523,9 @@ for(var __rspack_i in (()=>{
|
|
|
514
523
|
readMcpConfig: ()=>readMcpConfig,
|
|
515
524
|
writeMcpPort: ()=>writeMcpPort
|
|
516
525
|
});
|
|
517
|
-
var common_summary = __webpack_require__("./src/common/summary.ts"), common_crypto = __webpack_require__("./src/common/crypto.ts"),
|
|
526
|
+
var common_summary = __webpack_require__("./src/common/summary.ts"), common_crypto = __webpack_require__("./src/common/crypto.ts"), external_buffer_ = __webpack_require__("buffer"), external_stream_ = __webpack_require__("stream");
|
|
527
|
+
let external_string_decoder_namespaceObject = require("string_decoder");
|
|
528
|
+
var external_zlib_ = __webpack_require__("zlib"), external_path_ = __webpack_require__("path"), external_path_default = __webpack_require__.n(external_path_);
|
|
518
529
|
function isUrl(uri) {
|
|
519
530
|
return /^https?:\/\//.test(uri);
|
|
520
531
|
}
|
|
@@ -524,12 +535,40 @@ for(var __rspack_i in (()=>{
|
|
|
524
535
|
function isRemoteUrl(uri) {
|
|
525
536
|
return !!('string' == typeof uri && (isUrl(uri) || isFilePath(uri)));
|
|
526
537
|
}
|
|
538
|
+
async function* decodeBase64Shards(shardingFiles, fetchImplement) {
|
|
539
|
+
let remainder = '';
|
|
540
|
+
for (let url of shardingFiles){
|
|
541
|
+
let encodedText = remainder + await fetchImplement(url), decodableLength = encodedText.length - encodedText.length % 4;
|
|
542
|
+
decodableLength > 0 && (yield external_buffer_.Buffer.from(encodedText.slice(0, decodableLength), 'base64')), remainder = encodedText.slice(decodableLength);
|
|
543
|
+
}
|
|
544
|
+
remainder.length > 0 && (yield external_buffer_.Buffer.from(remainder, 'base64'));
|
|
545
|
+
}
|
|
527
546
|
function isShardingData(data) {
|
|
528
547
|
return !!(Array.isArray(data) && data.length > 0 && data.every((e)=>isRemoteUrl(e)));
|
|
529
548
|
}
|
|
530
549
|
async function fetchShardingData(shardingFiles, fetchImplement) {
|
|
531
|
-
|
|
532
|
-
|
|
550
|
+
if (0 === shardingFiles.length) return [];
|
|
551
|
+
let decoder = new external_string_decoder_namespaceObject.StringDecoder('utf8'), jsonParts = [];
|
|
552
|
+
await new Promise((resolve, reject)=>{
|
|
553
|
+
let iterator, reading;
|
|
554
|
+
(0, external_stream_.pipeline)((iterator = decodeBase64Shards(shardingFiles, fetchImplement)[Symbol.asyncIterator](), reading = !1, new external_stream_.Readable({
|
|
555
|
+
read () {
|
|
556
|
+
reading || (reading = !0, iterator.next().then(({ value, done })=>{
|
|
557
|
+
reading = !1, this.push(done ? null : value);
|
|
558
|
+
}, (error)=>{
|
|
559
|
+
reading = !1, this.destroy(error);
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
})), (0, external_zlib_.createInflate)(), new external_stream_.Writable({
|
|
563
|
+
write (chunk, _encoding, callback) {
|
|
564
|
+
jsonParts.push(decoder.write(external_buffer_.Buffer.from(chunk))), callback();
|
|
565
|
+
}
|
|
566
|
+
}), (error)=>{
|
|
567
|
+
error ? reject(error) : resolve();
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
let finalPart = decoder.end();
|
|
571
|
+
return finalPart && jsonParts.push(finalPart), JSON.parse(jsonParts.join(''));
|
|
533
572
|
}
|
|
534
573
|
async function fetchShardingFiles(data, fetchImplement, filterKeys) {
|
|
535
574
|
return (await Promise.all(Object.keys(data).map(async (_key)=>{
|
|
@@ -543,6 +582,7 @@ for(var __rspack_i in (()=>{
|
|
|
543
582
|
};
|
|
544
583
|
}))).reduce((t, c)=>Object.assign(t, c));
|
|
545
584
|
}
|
|
585
|
+
var algorithm = __webpack_require__("./src/common/algorithm.ts");
|
|
546
586
|
function findLoaderTotalTiming(loaders) {
|
|
547
587
|
let start = 1 / 0, end = -1 / 0;
|
|
548
588
|
for(let i = 0; i < loaders.length; i++){
|
|
@@ -690,10 +730,10 @@ for(var __rspack_i in (()=>{
|
|
|
690
730
|
let directories, rootPath = root || process.cwd();
|
|
691
731
|
return (loaders1 = loaders, root1 = rootPath, directories = new Set(), loaders1.forEach((item)=>{
|
|
692
732
|
if (item.resource.path.startsWith(root1)) {
|
|
693
|
-
let pathParts = item.resource.path.
|
|
733
|
+
let pathParts = item.resource.path.slice(root1.length).replace(/^\/+/, '').split('/');
|
|
694
734
|
if (pathParts.length >= 2) {
|
|
695
|
-
let
|
|
696
|
-
directories.add(`${
|
|
735
|
+
let normalizedRoot = root1.replace(/\/+$/, '');
|
|
736
|
+
directories.add(`${normalizedRoot}/${pathParts[0]}`);
|
|
697
737
|
}
|
|
698
738
|
} else {
|
|
699
739
|
let pathParts = item.resource.path.split('/'), twoLevelDir = pathParts.slice(0, pathParts.length - 1).join('/');
|
package/dist/common.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { __webpack_require__ } from "./0~rslib-runtime.js";
|
|
2
|
-
import { deflateSync, inflateSync } from "zlib";
|
|
3
2
|
import { Buffer } from "buffer";
|
|
3
|
+
import { Readable, Writable, pipeline } from "stream";
|
|
4
|
+
import { StringDecoder } from "string_decoder";
|
|
5
|
+
import { createInflate, deflateSync, inflateSync } from "zlib";
|
|
4
6
|
import path_0, { isAbsolute, relative } from "path";
|
|
5
7
|
import { hrtime } from "process";
|
|
6
8
|
import { Client, Constants, Rule, SDK } from "@rsdoctor/types";
|
|
@@ -170,26 +172,6 @@ function decode(str) {
|
|
|
170
172
|
for(let i = 0; i < str.length; i++)'!' === str[i] ? (res += String.fromCharCode(+tmp), tmp = '') : tmp += str[i];
|
|
171
173
|
return tmp && (res += String.fromCharCode(+tmp)), res;
|
|
172
174
|
}
|
|
173
|
-
function mergeIntervals(intervals) {
|
|
174
|
-
let previous, current;
|
|
175
|
-
intervals.sort((a, b)=>a[0] - b[0]);
|
|
176
|
-
let result = [];
|
|
177
|
-
for(let i = 0; i < intervals.length; i++)current = intervals[i], !previous || current[0] > previous[1] ? (previous = current, result.push(current)) : previous[1] = Math.max(previous[1], current[1]);
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
function compressText(input) {
|
|
181
|
-
try {
|
|
182
|
-
return deflateSync(input).toString('base64');
|
|
183
|
-
} catch (e) {
|
|
184
|
-
return rsdoctorLogger.debug(`compressText error: ${e}`), '';
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function decompressText(input) {
|
|
188
|
-
return inflateSync(Buffer.from(input, 'base64')).toString();
|
|
189
|
-
}
|
|
190
|
-
function random(min, max) {
|
|
191
|
-
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
192
|
-
}
|
|
193
175
|
function isUrl(uri) {
|
|
194
176
|
return /^https?:\/\//.test(uri);
|
|
195
177
|
}
|
|
@@ -199,12 +181,40 @@ function isFilePath(uri) {
|
|
|
199
181
|
function isRemoteUrl(uri) {
|
|
200
182
|
return !!('string' == typeof uri && (isUrl(uri) || isAbsolute(uri)));
|
|
201
183
|
}
|
|
184
|
+
async function* decodeBase64Shards(shardingFiles, fetchImplement) {
|
|
185
|
+
let remainder = '';
|
|
186
|
+
for (let url of shardingFiles){
|
|
187
|
+
let encodedText = remainder + await fetchImplement(url), decodableLength = encodedText.length - encodedText.length % 4;
|
|
188
|
+
decodableLength > 0 && (yield Buffer.from(encodedText.slice(0, decodableLength), 'base64')), remainder = encodedText.slice(decodableLength);
|
|
189
|
+
}
|
|
190
|
+
remainder.length > 0 && (yield Buffer.from(remainder, 'base64'));
|
|
191
|
+
}
|
|
202
192
|
function isShardingData(data) {
|
|
203
193
|
return !!(Array.isArray(data) && data.length > 0 && data.every((e)=>isRemoteUrl(e)));
|
|
204
194
|
}
|
|
205
195
|
async function fetchShardingData(shardingFiles, fetchImplement) {
|
|
206
|
-
|
|
207
|
-
|
|
196
|
+
if (0 === shardingFiles.length) return [];
|
|
197
|
+
let decoder = new StringDecoder('utf8'), jsonParts = [];
|
|
198
|
+
await new Promise((resolve, reject)=>{
|
|
199
|
+
let iterator, reading;
|
|
200
|
+
pipeline((iterator = decodeBase64Shards(shardingFiles, fetchImplement)[Symbol.asyncIterator](), reading = !1, new Readable({
|
|
201
|
+
read () {
|
|
202
|
+
reading || (reading = !0, iterator.next().then(({ value, done })=>{
|
|
203
|
+
reading = !1, this.push(done ? null : value);
|
|
204
|
+
}, (error)=>{
|
|
205
|
+
reading = !1, this.destroy(error);
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
})), createInflate(), new Writable({
|
|
209
|
+
write (chunk, _encoding, callback) {
|
|
210
|
+
jsonParts.push(decoder.write(Buffer.from(chunk))), callback();
|
|
211
|
+
}
|
|
212
|
+
}), (error)=>{
|
|
213
|
+
error ? reject(error) : resolve();
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
let finalPart = decoder.end();
|
|
217
|
+
return finalPart && jsonParts.push(finalPart), JSON.parse(jsonParts.join(''));
|
|
208
218
|
}
|
|
209
219
|
async function fetchShardingFiles(data, fetchImplement, filterKeys) {
|
|
210
220
|
return (await Promise.all(Object.keys(data).map(async (_key)=>{
|
|
@@ -218,6 +228,26 @@ async function fetchShardingFiles(data, fetchImplement, filterKeys) {
|
|
|
218
228
|
};
|
|
219
229
|
}))).reduce((t, c)=>Object.assign(t, c));
|
|
220
230
|
}
|
|
231
|
+
function mergeIntervals(intervals) {
|
|
232
|
+
let previous, current;
|
|
233
|
+
intervals.sort((a, b)=>a[0] - b[0]);
|
|
234
|
+
let result = [];
|
|
235
|
+
for(let i = 0; i < intervals.length; i++)current = intervals[i], !previous || current[0] > previous[1] ? (previous = current, result.push(current)) : previous[1] = Math.max(previous[1], current[1]);
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
function compressText(input) {
|
|
239
|
+
try {
|
|
240
|
+
return deflateSync(input).toString('base64');
|
|
241
|
+
} catch (e) {
|
|
242
|
+
return rsdoctorLogger.debug(`compressText error: ${e}`), '';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function decompressText(input) {
|
|
246
|
+
return inflateSync(Buffer.from(input, 'base64')).toString();
|
|
247
|
+
}
|
|
248
|
+
function random(min, max) {
|
|
249
|
+
return Math.floor(Math.random() * (max - min + 1) + min);
|
|
250
|
+
}
|
|
221
251
|
function findLoaderTotalTiming(loaders) {
|
|
222
252
|
let start = 1 / 0, end = -1 / 0;
|
|
223
253
|
for(let i = 0; i < loaders.length; i++){
|
|
@@ -360,10 +390,10 @@ function getDirectoriesLoaders(loaders, root) {
|
|
|
360
390
|
let directories, rootPath = root || process.cwd();
|
|
361
391
|
return (directories = new Set(), loaders.forEach((item)=>{
|
|
362
392
|
if (item.resource.path.startsWith(rootPath)) {
|
|
363
|
-
let pathParts = item.resource.path.
|
|
393
|
+
let pathParts = item.resource.path.slice(rootPath.length).replace(/^\/+/, '').split('/');
|
|
364
394
|
if (pathParts.length >= 2) {
|
|
365
|
-
let
|
|
366
|
-
directories.add(`${
|
|
395
|
+
let normalizedRoot = rootPath.replace(/\/+$/, '');
|
|
396
|
+
directories.add(`${normalizedRoot}/${pathParts[0]}`);
|
|
367
397
|
}
|
|
368
398
|
} else {
|
|
369
399
|
let pathParts = item.resource.path.split('/'), twoLevelDir = pathParts.slice(0, pathParts.length - 1).join('/');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/utils",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"picocolors": "^1.1.1",
|
|
102
102
|
"rslog": "^2.1.2",
|
|
103
103
|
"strip-ansi": "^7.2.0",
|
|
104
|
-
"@rsdoctor/types": "1.6.
|
|
104
|
+
"@rsdoctor/types": "1.6.5"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
107
|
"@types/babel__code-frame": "7.27.0",
|