Skip to content

Commit

Permalink
fix: change ip to resolve the ip's SSRF risk (#436)
Browse files Browse the repository at this point in the history
fix(client): module code show error (#441)

chore(deps): update all patch dependencies (#379)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

chore: support rspack 1.x

chore: support rspack 1.x
  • Loading branch information
easy1090 committed Jul 24, 2024
1 parent f69181c commit 1059ddd
Show file tree
Hide file tree
Showing 22 changed files with 808 additions and 1,563 deletions.
6 changes: 6 additions & 0 deletions .changeset/giant-months-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rsdoctor/rspack-plugin': patch
'@rsdoctor/types': patch
---

chore: support rspack 1.x
6 changes: 3 additions & 3 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"@rsdoctor/utils": "workspace:*",
"@rsdoctor/webpack-plugin": "workspace:*",
"@rspack/core": "0.7.5",
"@types/lodash": "^4.17.0",
"@types/lodash": "^4.17.7",
"@types/node": "^16",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/webpack": "5.28.0",
"fast-glob": "^3.3.1",
"@types/webpack": "5.28.5",
"fast-glob": "^3.3.2",
"loader-utils": "^2.0.4",
"playwright": "1.33.0",
"typescript": "^5.2.2"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.5.1",
"@changesets/cli": "^2.27.1",
"@changesets/cli": "^2.27.7",
"@modern-js/module-tools": "^2.54.5",
"@rsdoctor/tsconfig": "workspace:*",
"@scripts/test-helper": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"test": "vitest run"
},
"devDependencies": {
"@types/yargs": "17.0.13",
"@types/yargs": "17.0.32",
"typescript": "^5.2.2"
},
"dependencies": {
Expand All @@ -34,7 +34,7 @@
"@rsdoctor/utils": "workspace:*",
"axios": "^1.7.2",
"chalk": "^4.1.2",
"ora": "^5.0.1",
"ora": "^5.4.1",
"tslib": "2.4.1",
"yargs": "17.6.2"
},
Expand Down
16 changes: 8 additions & 8 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@
"dist/"
],
"devDependencies": {
"@rsbuild/core": "0.7.5",
"@rsbuild/plugin-sass": "0.7.5",
"@rsbuild/plugin-node-polyfill": "0.7.5",
"@rsbuild/plugin-react": "0.7.5",
"@rsbuild/plugin-type-check": "0.7.5",
"@rsbuild/core": "0.7.10",
"@rsbuild/plugin-sass": "0.7.10",
"@rsbuild/plugin-node-polyfill": "0.7.10",
"@rsbuild/plugin-react": "0.7.10",
"@rsbuild/plugin-type-check": "0.7.10",
"@rsdoctor/components": "workspace:*",
"@rsdoctor/types": "workspace:*",
"@types/node": "^16",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/serve-static": "1.15.0",
"@types/webpack": "5.28.0",
"@types/serve-static": "1.15.7",
"@types/webpack": "5.28.5",
"antd": "5.15.3",
"normalize.css": "8.0.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-error-boundary": "^4.0.11",
"react-error-boundary": "^4.0.13",
"react-router-dom": "6.4.3",
"serve-static": "1.15.0",
"typescript": "^5.2.2"
Expand Down
12 changes: 6 additions & 6 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@
"dist/"
],
"devDependencies": {
"@ant-design/icons": "4.8.0",
"@ant-design/icons": "4.8.3",
"@monaco-editor/react": "4.6.0",
"@rsdoctor/graph": "workspace:*",
"@rsdoctor/types": "workspace:*",
"@rsdoctor/utils": "workspace:*",
"@types/lodash-es": "4.17.6",
"@types/lodash-es": "4.17.12",
"@types/node": "^16",
"@types/path-browserify": "1.0.1",
"@types/path-browserify": "1.0.2",
"@types/react": "^18",
"@types/react-highlight-words": "^0.16.7",
"@types/url-parse": "1.4.8",
"@types/url-parse": "1.4.11",
"ansi-to-react": "6.1.6",
"antd": "5.15.3",
"axios": "^1.7.2",
"dayjs": "1.11.6",
"echarts": "^5.5.0",
"dayjs": "1.11.12",
"echarts": "^5.5.1",
"echarts-for-react": "^3.0.2",
"i18next": "22.0.4",
"lodash-es": "4.17.21",
Expand Down
13 changes: 11 additions & 2 deletions packages/components/src/pages/BundleSize/components/asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const tagStyle = {
export const ModuleCodeViewer: React.FC<{ data: SDK.ModuleData }> = ({
data,
}) => {
const [tab, setTab] = useState('parsedSource');
const [tab, setTab] = useState('');
const { t } = useI18n();

const TAB_LAB_MAP: Record<string, string> = {
Expand Down Expand Up @@ -105,6 +105,9 @@ export const ModuleCodeViewer: React.FC<{ data: SDK.ModuleData }> = ({
tab: TAB_LAB_MAP[e.tab],
key: e.tab,
}))}
defaultActiveTabKey={
source['parsedSource'] ? 'parsedSource' : 'source'
}
onTabChange={(v) => setTab(v)}
tabBarExtraContent={
<Popover
Expand Down Expand Up @@ -162,7 +165,13 @@ export const ModuleCodeViewer: React.FC<{ data: SDK.ModuleData }> = ({
language={getOriginalLanguage(path)}
// eslint-disable-next-line financial/no-float-calculation
height={window.innerHeight / 1.5}
value={source[tab]}
value={
tab
? source[tab]
: source['parsedSource']
? source['parsedSource']
: source['source']
}
options={{
readOnly: true,
domReadOnly: true,
Expand Down
20 changes: 10 additions & 10 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@
"@rsdoctor/utils": "workspace:*",
"axios": "^1.7.2",
"enhanced-resolve": "5.12.0",
"filesize": "^10.1.2",
"filesize": "^10.1.4",
"fs-extra": "^11.1.1",
"loader-utils": "^2.0.4",
"lodash": "^4.17.21",
"path-browserify": "1.0.1",
"semver": "^7.6.3",
"source-map": "^0.7.4",
"webpack-bundle-analyzer": "^4.9.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-sources": "^3.2.3"
},
"devDependencies": {
"@rspack/core": "0.7.5",
"@scripts/test-helper": "workspace:*",
"@types/fs-extra": "^11.0.2",
"@types/loader-utils": "^2.0.5",
"@types/lodash": "^4.17.0",
"@types/fs-extra": "^11.0.4",
"@types/loader-utils": "^2.0.6",
"@types/lodash": "^4.17.7",
"@types/node": "^16",
"@types/node-fetch": "^2.6.9",
"@types/path-browserify": "1.0.1",
"@types/semver": "^7.5.4",
"@types/tapable": "2.2.2",
"@types/webpack": "5.28.0",
"@types/node-fetch": "^2.6.11",
"@types/path-browserify": "1.0.2",
"@types/semver": "^7.5.8",
"@types/tapable": "2.2.7",
"@types/webpack": "5.28.5",
"@types/webpack-sources": "^3.2.3",
"babel-loader": "9.1.3",
"string-loader": "0.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/document/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"react-markdown": "^9.0.1",
"rsfamily-doc-ui": "^1.0.3",
"rspress": "^1.26.1"
"rsfamily-doc-ui": "^1.1.2",
"rspress": "^1.26.2"
}
}
6 changes: 3 additions & 3 deletions packages/graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
"source-map": "^0.7.4"
},
"devDependencies": {
"@types/body-parser": "1.19.2",
"@types/estree": "1.0.0",
"@types/lodash": "^4.17.0",
"@types/body-parser": "1.19.5",
"@types/estree": "1.0.5",
"@types/lodash": "^4.17.7",
"@types/node": "^16",
"fs-extra": "^11.1.1",
"tslib": "2.4.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/rspack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
},
"devDependencies": {
"@rspack/core": "0.7.5",
"@types/loader-utils": "^2.0.5",
"@types/lodash": "^4.17.0",
"@types/loader-utils": "^2.0.6",
"@types/lodash": "^4.17.7",
"@types/node": "^16",
"@types/tapable": "2.2.2",
"@types/tapable": "2.2.7",
"tslib": "2.4.1",
"typescript": "^5.2.2"
},
"peerDependencies": {
"@rspack/core": "0.x"
"@rspack/core": "0.x || 1.x"
},
"publishConfig": {
"access": "public",
Expand Down
16 changes: 7 additions & 9 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,22 @@
"@rsdoctor/graph": "workspace:*",
"@rsdoctor/types": "workspace:*",
"@rsdoctor/utils": "workspace:*",
"body-parser": "1.20.1",
"body-parser": "1.20.2",
"cors": "2.8.5",
"dayjs": "1.11.6",
"ip": "1.1.9",
"dayjs": "1.11.12",
"lodash": "^4.17.21",
"open": "^8.4.0",
"open": "^8.4.2",
"serve-static": "1.15.0",
"socket.io": "4.7.2",
"source-map": "^0.7.4",
"tapable": "2.2.1"
},
"devDependencies": {
"@types/body-parser": "1.19.2",
"@types/cors": "2.8.13",
"@types/ip": "1.1.0",
"@types/lodash": "^4.17.0",
"@types/body-parser": "1.19.5",
"@types/cors": "2.8.17",
"@types/lodash": "^4.17.7",
"@types/node": "^16",
"@types/serve-static": "1.15.0",
"@types/serve-static": "1.15.7",
"tslib": "2.4.1",
"typescript": "^5.2.2"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/sdk/server/apis/project.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SDK } from '@rsdoctor/types';
import ip from 'ip';
import { BaseAPI } from './base';
import { Router } from '../router';
import { getLocalIpAddress } from '../utils';

export class ProjectAPI extends BaseAPI {
@Router.get(SDK.ServerAPI.API.Env)
Expand All @@ -11,7 +11,7 @@ export class ProjectAPI extends BaseAPI {
const { server } = this.ctx;

return {
ip: ip.address(),
ip: getLocalIpAddress(),
port: server.port,
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/sdk/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import serve from 'serve-static';
import { Bundle } from '@rsdoctor/utils/common';
import assert from 'assert';
import bodyParser from 'body-parser';
import ip from 'ip';
import cors from 'cors';
import { PassThrough } from 'stream';
import { Socket } from './socket';
Expand All @@ -13,6 +12,7 @@ import * as APIs from './apis';
import { chalk, logger } from '@rsdoctor/utils/logger';
import { openBrowser } from '@/sdk/utils/openBrowser';
import path from 'path';
import { getLocalIpAddress } from './utils';
export * from './utils';

export class RsdoctorServer implements SDK.RsdoctorServerInstance {
Expand Down Expand Up @@ -45,7 +45,7 @@ export class RsdoctorServer implements SDK.RsdoctorServerInstance {
}

public get host(): string {
const host = ip.address();
const host = getLocalIpAddress();
return host;
}

Expand Down
13 changes: 13 additions & 0 deletions packages/sdk/src/sdk/server/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SDK } from '@rsdoctor/types';
import os from 'os';

export function getDataByPagination<T>(
data: T[],
Expand All @@ -18,3 +19,15 @@ export function getDataByPagination<T>(
},
};
}

export function getLocalIpAddress() {
const interfaces = os.networkInterfaces();
for (const iface of Object.values(interfaces)) {
for (const alias of iface as os.NetworkInterfaceInfo[]) {
if (alias.family === 'IPv4' && !alias.internal) {
return alias.address;
}
}
}
return '127.0.0.1'; // fallback to localhost if no external IP found
}
4 changes: 2 additions & 2 deletions packages/sdk/tests/server/apis/project.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, it, expect, vi } from 'vitest';
import ip from 'ip';
import { Manifest, SDK } from '@rsdoctor/types';
import { Manifest as ManifestShared } from '@rsdoctor/utils/common';

import { cwd, setupSDK } from '../../utils';
import { getLocalIpAddress } from '@/sdk/server/utils';

vi.setConfig({ testTimeout: 50000 });

Expand All @@ -13,7 +13,7 @@ describe('test server/apis/project.ts', () => {
it(`test api: ${SDK.ServerAPI.API.Env}`, async () => {
const env = (await target.get(SDK.ServerAPI.API.Env)).toJSON();

expect(env.ip).toEqual(ip.address());
expect(env.ip).toEqual(getLocalIpAddress());
expect(env.port).toEqual(target.server.port);
});

Expand Down
10 changes: 5 additions & 5 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"start": "npm run build -- -w"
},
"dependencies": {
"@types/connect": "3.4.35",
"@types/estree": "1.0.0",
"@types/tapable": "2.2.2",
"@types/webpack": "5.28.0",
"@types/connect": "3.4.38",
"@types/estree": "1.0.5",
"@types/tapable": "2.2.7",
"@types/webpack": "5.28.5",
"source-map": "^0.7.4"
},
"devDependencies": {
Expand All @@ -32,7 +32,7 @@
"@rspack/core": "0.7.5"
},
"peerDependencies": {
"@rspack/core": "0.x"
"@rspack/core": "0.x || 1.x"
},
"peerDependenciesMeta": {
"@rspack/core": {
Expand Down
Loading

0 comments on commit 1059ddd

Please sign in to comment.