Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/cli",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/client",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"main": "dist/index.html",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/components",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"license": "MIT",
"types": "dist/index.d.ts",
"repository": {
Expand Down
11 changes: 5 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/core",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand All @@ -10,7 +10,8 @@
"main": "dist/index.cjs",
"types": "dist/index.d.ts",
"files": [
"dist"
"dist",
"compiled"
],
"type": "module",
"exports": {
Expand Down Expand Up @@ -61,7 +62,7 @@
},
"scripts": {
"dev": "npm run start",
"build": "rslib build",
"build": "npm run prebundle && rslib build",
"start": "rslib build -w",
"test": "rstest run",
"prebundle": "prebundle"
Expand All @@ -72,6 +73,7 @@
"@rsdoctor/types": "workspace:*",
"@rsdoctor/utils": "workspace:*",
"browserslist-load-config": "^1.0.1",
"filesize": "^10.1.6",
"fs-extra": "^11.1.1",
"lodash-es": "^4.17.21",
"semver": "^7.7.2",
Expand All @@ -80,16 +82,13 @@
"devDependencies": {
"@rsbuild/plugin-check-syntax": "1.4.0",
"axios": "^1.12.0",
"path-browserify": "1.0.1",
"enhanced-resolve": "5.12.0",
"filesize": "^10.1.6",
"@rspack/core": "1.5.2",
"@scripts/test-helper": "workspace:*",
"@types/fs-extra": "^11.0.4",
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.8.1",
"@types/node-fetch": "^2.6.12",
"@types/path-browserify": "1.0.3",
"@types/semver": "^7.7.0",
"@types/tapable": "2.2.7",
"babel-loader": "10.0.0",
Expand Down
36 changes: 36 additions & 0 deletions packages/core/prebundle.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @type {import('prebundle').Config} */
export default {
dependencies: ['axios', '@rsbuild/plugin-check-syntax'],
exclude: [
'@rsdoctor/client',
'@rsdoctor/graph',
'@rsdoctor/types',
'@rsdoctor/utils',
'safer-buffer',
],

build: {
platform: 'node',
target: 'node16',
format: 'cjs',
minify: false,
sourcemap: false,
metafile: false,
write: true,
output: {
chunkFormat: 'commonjs',
},
environment: {
node: true,
},
},

output: {
dir: './compiled',
filename: '[name].cjs',
},

resolve: {
extensions: ['.js', '.json', '.ts', '.tsx'],
},
};
38 changes: 38 additions & 0 deletions packages/core/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
import { defineConfig, rspack } from '@rslib/core';
import { dualPackageBundleless } from '../../scripts/rslib.base.config';
import prebundleConfig from './prebundle.config.mjs';

const regexpMap: Record<string, RegExp> = {};

for (const item of prebundleConfig.dependencies) {
const depName = typeof item === 'string' ? item : item.name;
if (typeof item !== 'string' && item.dtsOnly) {
continue;
}

regexpMap[depName] = new RegExp(`compiled[\\/]${depName}(?:[\\/]|$)`);
}

const externalsPrebundle = [
({ request }: { request?: string }, callback: any) => {
if (request) {
if (
prebundleConfig.dependencies.includes(request) &&
request !== '@rsbuild/plugin-check-syntax'
) {
return callback(undefined, `../../../compiled/${request}/index.js`);
} else if (request === '@rsbuild/plugin-check-syntax') {
return callback(undefined, `../../../../compiled/${request}/index.js`);
}
const entries = Object.entries(regexpMap);
for (const [name, test] of entries) {
if (test.test(request)) {
return callback(undefined, `../compiled/${name}/index.js`);
}
}
}
callback();
},
];

const externals = [
// Externalize workspace packages
'@rsdoctor/graph',
'@rsdoctor/sdk',
'@rsdoctor/types',
'@rsdoctor/utils',
'lodash-es',
'semver',
'source-map',
...externalsPrebundle,
];

export default defineConfig({
Expand Down
2 changes: 1 addition & 1 deletion packages/document/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/docs",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"scripts": {
"dev": "cross-env RSPRESS_PERSIST_CACHE=false rspress dev",
"build": "cross-env RSPRESS_PERSIST_CACHE=false rspress build && sh build.sh",
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/graph",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/rspack-plugin",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/sdk",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down Expand Up @@ -48,7 +48,6 @@
"cors": "2.8.5",
"dayjs": "1.11.18",
"fs-extra": "^11.1.1",
"json-cycle": "^1.5.0",
"open": "^10.2.0",
"sirv": "2.0.4",
"source-map": "^0.7.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/sdk/sdk/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';
import { createHash } from 'crypto';
import process from 'process';
import { AsyncSeriesHook } from 'tapable';
const jc = require('json-cycle');
import { decycle } from '@rsdoctor/utils/common';
import { logger } from '@rsdoctor/utils/logger';
import { transformDataUrls } from '../utils';
import { RsdoctorSDKOptions, DataWithUrl } from './types';
Expand Down Expand Up @@ -144,7 +144,7 @@ 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(decycle(data));
}
return JSON.stringify(data);
} catch (error) {
Expand Down
7 changes: 3 additions & 4 deletions packages/sdk/src/sdk/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ import { SDKCore } from './core';
import { Algorithm } from '@rsdoctor/utils/common';
import { Lodash } from '@rsdoctor/utils/common';
import { findRoot } from '../utils';

const require = createRequire(import.meta.url);
const jc = require('json-cycle');
import { decycle } from '@rsdoctor/utils/common';

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

const require = createRequire(import.meta.url);
export class RsdoctorSDK<
T extends RsdoctorWebpackSDKOptions = RsdoctorWebpackSDKOptions,
>
Expand Down Expand Up @@ -556,7 +555,7 @@ export class RsdoctorSDK<
const jsonStrFn = () => {
try {
if (key === 'configs') {
return JSON.stringify(jc.decycle(data));
return JSON.stringify(decycle(data));
}
return JSON.stringify(data);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/types",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/utils",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
59 changes: 59 additions & 0 deletions packages/utils/src/common/decycle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* The following code is based on
* https://github.com/valery-barysok/json-cycle/blob/master/cycle.js
*
*
* MIT Licensed
* Author juliyvchirkov
* https://github.com/valery-barysok/json-cycle?tab=MIT-1-ov-file
*/
export function decycle<T = any>(object: T): T {
const objects: any[] = [];
const paths: string[] = [];

function derez(value: any, path: string): any {
let _value = value;

try {
_value = value.toJSON();
} catch {
// Ignore toJSON errors
}

if (typeof _value === 'object' && _value) {
for (let i = 0; i < objects.length; i += 1) {
if (objects[i] === _value) {
return { $ref: paths[i] };
}
}

objects.push(_value);
paths.push(path);

let nu: any;

if (Object.prototype.toString.apply(_value) === '[object Array]') {
nu = [];
for (let i = 0; i < _value.length; i += 1) {
nu[i] = derez(_value[i], path + '[' + i + ']');
}
} else {
nu = {};
for (const name in _value) {
if (Object.hasOwn(_value, name)) {
nu[name] = derez(
_value[name],
path + '[' + JSON.stringify(name) + ']',
);
}
}
}

return nu;
}

return _value;
}

return derez(object, '$');
}
1 change: 1 addition & 0 deletions packages/utils/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * as Package from './package';
export * as Lodash from './lodash';
export * as GlobalConfig from './global-config';
export * as File from './file';
export * from './decycle';
2 changes: 1 addition & 1 deletion packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/webpack-plugin",
"version": "1.2.3",
"version": "1.2.4-beta.5",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
Loading
Loading