Skip to content

Commit

Permalink
fix: circular configs options data
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 committed Nov 29, 2024
1 parent 16902b0 commit 0edd5a3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"cors": "2.8.5",
"dayjs": "1.11.13",
"fs-extra": "^11.1.1",
"json-cycle": "^1.5.0",
"lodash": "^4.17.21",
"open": "^8.4.2",
"serve-static": "1.16.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/sdk/sdk/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import { createHash } from 'crypto';
import process from 'process';
import { AsyncSeriesHook } from 'tapable';
const jc = require('json-cycle');
import { debug } from '@rsdoctor/utils/logger';
import { transformDataUrls } from '../utils';
import { RsdoctorSDKOptions, DataWithUrl } from './types';
Expand Down Expand Up @@ -142,6 +143,9 @@ export abstract class SDKCore<T extends RsdoctorSDKOptions>
}
const jsonStr: string | string[] = await (async () => {
try {
if (key === 'configs') {
return JSON.stringify(jc.decycle(data));
}
return JSON.stringify(data);
} catch (error) {
// use the stream json stringify when call JSON.stringify failed due to the json is too large.
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/sdk/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RsdoctorWebpackSDKOptions } from './types';
import { SDKCore } from './core';
import { Algorithm } from '@rsdoctor/utils/common';
import { isNumber } from 'lodash';
const jc = require('json-cycle');

export * from '../utils/openBrowser';

Expand Down Expand Up @@ -504,6 +505,9 @@ export class RsdoctorSDK<

const jsonStrFn = () => {
try {
if (key === 'configs') {
return JSON.stringify(jc.decycle(data));
}
return JSON.stringify(data);
} catch (error) {
console.error(error);
Expand Down
9 changes: 7 additions & 2 deletions packages/utils/src/common/algorithm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { deflateSync, inflateSync } from 'zlib';
import { Buffer } from 'buffer';
import { debug } from '../logger';

export function mergeIntervals(intervals: [number, number][]) {
// Sort from small to large
Expand All @@ -25,9 +26,13 @@ export function mergeIntervals(intervals: [number, number][]) {
}

export function compressText(input: string): string {
return deflateSync(input).toString('base64');
try {
return deflateSync(input).toString('base64');
} catch (e) {
debug(() => `compressText error: ${e}`);
return '';
}
}

export function decompressText(input: string): string {
return inflateSync(Buffer.from(input, 'base64')).toString();
}
Expand Down
12 changes: 10 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0edd5a3

Please sign in to comment.