Skip to content

Commit

Permalink
Merge branch 'main' into fix-router-v5-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrieLii authored Jan 17, 2024
2 parents 47d579d + 4e115f5 commit d93d064
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 15 deletions.
6 changes: 6 additions & 0 deletions .changeset/odd-dryers-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/module-tools': patch
---

perf(module-tools): log error detail which may throw by own plugin and complete error stack
perf(module-tools): 补齐错误栈并且打印错误细节,因为这错误可能并不是 esbuild 抛出的,而是我们自己的插件抛出的
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useLang } from 'rspress/runtime';

export function Announcement() {
const lang = useLang();

return (
<div
style={{
height: '2rem',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgb(88 209 126 / 0.5)',
}}
>
<a
href="https://rsbuild.dev/"
target="_blank"
rel="noopener noreferrer "
style={{
textDecorationLine: 'underline',
fontWeight: 700,
color: 'rgb(55 65 81)',
}}
>
{lang === 'zh'
? 'Modern.js Builder 已升级为 Rsbuild, 欢迎使用 Rsbuild 👏🏻'
: 'Modern.js Builder has been upgraded to Rsbuild, welcome to use Rsbuild 👏🏻'}
</a>
</div>
);
}
21 changes: 21 additions & 0 deletions packages/document/builder-doc/theme/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Theme from 'rspress/theme';
import { NoSSR } from 'rspress/runtime';
import { Announcement } from './components/Announcement';

const Layout = () => (
<Theme.Layout
beforeNav={
<NoSSR>
<Announcement />
</NoSSR>
}
/>
);

// eslint-disable-next-line import/export
export * from 'rspress/theme';

export default {
...Theme,
Layout,
};
2 changes: 1 addition & 1 deletion packages/document/builder-doc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"compilerOptions": {
"jsx": "preserve"
},
"include": ["docs", "rspress.config.ts", "src"]
"include": ["docs", "rspress.config.ts", "src", "theme"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,13 @@ type ParseToolOptions = {

In case of `web`, the component will be rendered directly in the page, otherwise it will be loaded through an iframe.

### desperated: languages
### deprecated: languages

:::warning
Starting from version MAJOR_VERSION.44.0, please refer to the [Internationalization](https://rspress.dev/guide/default-theme/i18n.html) section to implement multiple languages.
:::

### desperated: useModuleSidebar
### deprecated: useModuleSidebar

:::warning
Starting from version MAJOR_VERSION.44.0, a sniffing mechanism has been implemented internally, so please directly use [\_meta.json](https://rspress.dev/guide/basic/auto-nav-sidebar.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,13 @@ type ParseToolOptions = {

`web`时,代码块内容将会直接渲染在页面中,反之将会通过 iframe 加载。

### desperated: languages
### deprecated: languages

:::warning
从 MAJOR_VERSION.44.0 版本开始,请参考 [国际化](https://rspress.dev/zh/guide/default-theme/i18n.html) 章节来实现多语言。
:::

### desperated: useModuleSidebar
### deprecated: useModuleSidebar

:::warning
从 MAJOR_VERSION.44.0 版本开始,内部实现了嗅探机制,请直接使用 [_meta.json](https://rspress.dev/zh/guide/basic/auto-nav-sidebar.html)
Expand Down
9 changes: 9 additions & 0 deletions packages/solutions/module-tools/src/builder/esbuild/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ImportKind,
formatMessages,
Format,
BuildFailure,
} from 'esbuild';
import * as tapable from 'tapable';
import { FSWatcher, chalk, logger, fs, lodash } from '@modern-js/utils';
Expand Down Expand Up @@ -292,6 +293,14 @@ export class EsbuildCompiler implements ICompiler {
});
}
} catch (error: any) {
if ('errors' in error) {
// log error detail which may throw by own plugins
(error as BuildFailure)?.errors?.forEach(err => {
if (err?.detail) {
logger.error(err.detail.toString());
}
});
}
if (watch) {
this.instance?.cancel();
logger.error(error);
Expand Down
14 changes: 4 additions & 10 deletions packages/solutions/module-tools/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export class InternalBuildError extends Error {

public format: Format;

private e: Error;

constructor(
e: Error,
opts: {
Expand All @@ -49,11 +47,10 @@ export class InternalBuildError extends Error {
target: Target;
},
) {
super(e.message);
super(e.stack);

Error.captureStackTrace(this, this.constructor);

this.e = e;
this.buildType = opts.buildType;
this.target = opts.target;
this.format = opts.format;
Expand All @@ -65,7 +62,7 @@ export class InternalBuildError extends Error {

formatError() {
const msgs: string[] = [];
const { e, buildType, target, format } = this;
const { buildType, target, format } = this;
const textL = 25;
const title = `│ ${padSpaceWith(`${buildType} failed:`, textL - 2, {
style: chalk.red.underline,
Expand All @@ -92,11 +89,8 @@ export class InternalBuildError extends Error {
chalk.blue.bold.underline(`\nDetailed Information: `),
);

if (e.stack) {
msgs.push(e.stack);
} else {
msgs.push(e.message);
}
// remove 'Error: '
msgs.push(this.stack?.substring(7) || this.message);

return msgs;
}
Expand Down

0 comments on commit d93d064

Please sign in to comment.