Skip to content

Commit

Permalink
Merge branch 'main' into renovate/babel-monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 authored Nov 5, 2024
2 parents fe976c3 + c3a64ca commit 5b644ca
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 60 deletions.
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": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/client",
"version": "0.4.7",
"version": "0.4.8",
"main": "dist/index.html",
"repository": {
"type": "git",
Expand Down Expand Up @@ -43,7 +43,7 @@
"normalize.css": "8.0.1",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-error-boundary": "^4.0.13",
"react-error-boundary": "^4.1.2",
"react-router-dom": "6.4.3",
"serve-static": "1.16.2",
"typescript": "^5.2.2"
Expand Down
4 changes: 2 additions & 2 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/components",
"version": "0.4.7",
"version": "0.4.8",
"main": "./dist/index.js",
"license": "MIT",
"module": "dist/index.js",
Expand Down Expand Up @@ -81,7 +81,7 @@
"react-markdown": "^9.0.1",
"react-router-dom": "6.4.3",
"socket.io-client": "4.6.1",
"terser": "^5.34.1",
"terser": "^5.36.0",
"typescript": "^5.2.2",
"url-parse": "1.5.10"
},
Expand Down
27 changes: 23 additions & 4 deletions packages/components/src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { PropsWithChildren, useContext, useEffect } from 'react';
import { FloatButton, Layout as L } from 'antd';
import { MAIN_BG, Size } from '../../constants';
import { Language, MAIN_BG, Size } from '../../constants';
import { Header } from './header';
import { useLocale, useI18n } from '../../utils';
import {
useLocale,
useI18n,
getFirstVisitFromStorage,
setFirstVisitToStorage,
getLanguage,
} from '../../utils';
import { Progress } from './progress';
import { ConfigContext } from '../../config';

Expand All @@ -16,8 +22,21 @@ export const Layout = (props: PropsWithChildren<LayoutProps>): JSX.Element => {
const { children } = props;

useEffect(() => {
if (i18n.language !== locale) {
i18n.changeLanguage(locale);
let currentLocale = locale;
// Check if the user is visiting the site for the first time
const visited = getFirstVisitFromStorage();
if (!visited) {
setFirstVisitToStorage('1');
const targetLang = window.navigator.language.split('-')[0];
const userLang = getLanguage(targetLang);

if (Object.values(Language).includes(userLang)) {
currentLocale = userLang;
}
}

if (i18n.language !== currentLocale) {
i18n.changeLanguage(currentLocale);
}
}, [locale]);

Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/utils/locale.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import cn from 'antd/es/locale/zh_CN';
import en from 'antd/es/locale/en_GB';
import type { Locale } from 'antd/es/locale';
import { Language } from '../constants';

export function getLocale(locale: string): Locale {
const res = locale === 'cn' || locale === 'zh-CN' ? cn : en;
return res;
}

export function getLanguage(locale: string): Language {
const res = locale === 'cn' || locale === 'zh' ? Language.Cn : Language.En;
return res;
}
9 changes: 9 additions & 0 deletions packages/components/src/utils/storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum Keys {
Locale = 'LOCALE',
ViewMode = 'VIEWMODE',
APILoaderMode4Dev = 'APILOADERMODE_DEV',
FirstVisit = 'FIRST_VISIT'
}

export function getStorage(key: string): string | null {
Expand Down Expand Up @@ -67,3 +68,11 @@ export function setAPILoaderModeToStorage(mode: APILoaderMode4Dev) {
export function getAPILoaderModeFromStorage() {
return getStorage(Keys.APILoaderMode4Dev) || APILoaderMode4Dev.Default;
}

export function getFirstVisitFromStorage() {
return getStorage(Keys.FirstVisit);
}

export function setFirstVisitToStorage(value: '1') {
setStorage(Keys.FirstVisit, value);
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/core",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ features 属性是用于分析功能开关的,具体的功能项如下:
- **resolver**:resolver 分析,默认关闭。
- **lite**: **(废弃,参考:[mode.lite]())** lite 模式。lite 模式和普通模式的区别就是不再缓存源码信息,只缓存打包后的代码信息,这样分析页面上的代码也将是打包后的。默认普通模式。

所以,**默认配置是开启了 Bundle 分析能力、 Loader he Plugin 构建时分析**。没有开启 Resolver 分析能力, Rspack 暂不支持 Resolver 分析能力。
所以,**默认配置是开启了 Bundle 分析能力、 Loader Plugin 构建时分析**。没有开启 Resolver 分析能力, Rspack 暂不支持 Resolver 分析能力。

:::tip
**如果出现了 out of memory 的报错,可以尝试:**
Expand Down
2 changes: 1 addition & 1 deletion packages/document/docs/zh/config/options/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ features 属性是用于分析功能开关的,具体的功能项如下:
- **resolver**:resolver 分析,默认关闭。
- **lite**: **(废弃,使用 [mode.lite](#mode))** lite 模式。lite 模式和普通模式的区别就是不再展示源码信息,只展示打包后的代码信息,这样分析页面上的代码也将是打包后的。默认普通模式。

所以,**默认配置是开启了 Bundle 分析能力、 Loader he Plugin 构建时分析**。没有开启 Resolver 分析能力, Rspack 暂不支持 Resolver 分析能力。
所以,**默认配置是开启了 Bundle 分析能力、 Loader Plugin 构建时分析**。没有开启 Resolver 分析能力, Rspack 暂不支持 Resolver 分析能力。

:::tip
**如果出现了 out of memory 的报错,可以尝试:**
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": "0.4.7",
"version": "0.4.8",
"scripts": {
"dev": "rspress dev",
"build": "rspress build",
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": "0.4.7",
"version": "0.4.8",
"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": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/sdk",
"version": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
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": "0.4.7",
"version": "0.4.8",
"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": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
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": "0.4.7",
"version": "0.4.8",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
8 changes: 2 additions & 6 deletions packages/webpack-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export class RsdoctorWebpackPlugin<Rules extends Linter.ExtendRuleData[]>

public modulesGraph: ModuleGraph;

private outsideInstance = false;

public _bootstrapTask!: Promise<unknown>;

protected browserIsOpened = false;
Expand All @@ -69,7 +67,6 @@ export class RsdoctorWebpackPlugin<Rules extends Linter.ExtendRuleData[]>
brief: this.options.brief,
},
});
this.outsideInstance = Boolean(this.options.sdkInstance);
this.modulesGraph = new ModuleGraph();
this.chunkGraph = new ChunkGraph();
this.isRsdoctorPlugin = true;
Expand All @@ -86,9 +83,8 @@ export class RsdoctorWebpackPlugin<Rules extends Linter.ExtendRuleData[]>
}

// External instances do not need to be injected into the global.
if (!this.outsideInstance) {
setSDK(this.sdk);
}
setSDK(this.sdk);

// TODO: to fix the TypeError: Type instantiation is excessively deep and possibly infinite.
// @ts-ignore
new InternalSummaryPlugin<Compiler>(this).apply(compiler);
Expand Down
Loading

0 comments on commit 5b644ca

Please sign in to comment.