-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(prepare): esbuild should respect tsconfig.json #12439
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Walkthrough此更改引入了装饰器功能,添加了新的JavaScript和TypeScript文件来定义和使用装饰器。同时,更新了构建测试文件以验证装饰器功能,并在构建过程中检查 Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Size Change: +55 B (0%) Total Size: 9.9 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Outside diff range and nitpick comments (1)
packages/preset-umi/src/features/prepare/build.ts (1)
45-45
: 在构建选项中有一个关于incremental
选项的注释。如果这个选项不再相关,请考虑清理或删除这个注释。
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- packages/preset-umi/fixtures/prepare-build/normal/index.ts (1 hunks)
- packages/preset-umi/fixtures/prepare-build/normal/paramDecorator/jsDecorator.js (1 hunks)
- packages/preset-umi/fixtures/prepare-build/normal/paramDecorator/tsDecorator.ts (1 hunks)
- packages/preset-umi/fixtures/prepare-build/normal/tsconfig.json (1 hunks)
- packages/preset-umi/src/features/prepare/build.test.ts (1 hunks)
- packages/preset-umi/src/features/prepare/build.ts (3 hunks)
Files skipped from review due to trivial changes (2)
- packages/preset-umi/fixtures/prepare-build/normal/tsconfig.json
- packages/preset-umi/src/features/prepare/build.test.ts
Additional context used
Biome
packages/preset-umi/fixtures/prepare-build/normal/paramDecorator/jsDecorator.js
[error] 8-8: Decorators are not valid here. (parse)
Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting theunsafeParameterDecoratorsEnabled
option totrue
in your configuration file.packages/preset-umi/fixtures/prepare-build/normal/paramDecorator/tsDecorator.ts
[error] 10-10: Decorators are not valid here. (parse)
Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting theunsafeParameterDecoratorsEnabled
option totrue
in your configuration file.
[error] 1-1: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)
any disables many type checking rules. Its use should be avoided.
packages/preset-umi/src/features/prepare/build.ts
[error] 20-20: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)
any disables many type checking rules. Its use should be avoided.
Additional comments not posted (4)
packages/preset-umi/fixtures/prepare-build/normal/paramDecorator/jsDecorator.js (1)
1-1
: 函数prop
看起来是一个装饰器的占位符,没有问题。packages/preset-umi/fixtures/prepare-build/normal/paramDecorator/tsDecorator.ts (1)
13-13
: 方法test
中使用console.log(param);
正确引用了方法参数,没有问题。packages/preset-umi/fixtures/prepare-build/normal/index.ts (1)
11-19
: 新导入的load
,UseDecorator
, 和TsUseDecorator
在文件中被正确使用,没有问题。packages/preset-umi/src/features/prepare/build.ts (1)
26-28
: 检查tsconfig.json
文件的存在并相应地设置tsconfig
的逻辑正确实现,没有问题。
export class UseDecorator { | ||
@prop() | ||
a = 1; | ||
|
||
fn( | ||
@prop() | ||
jsParam, | ||
) { | ||
console.log(a); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据静态分析工具的提示,参数装饰器在没有特定配置的情况下在 JavaScript 中不是有效的。您可以通过在配置文件中设置 unsafeParameterDecoratorsEnabled
选项为 true
来启用参数装饰器,或者考虑重构代码。
Tools
Biome
[error] 8-8: Decorators are not valid here. (parse)
Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting theunsafeParameterDecoratorsEnabled
option totrue
in your configuration file.
@prop() | ||
jsParam, | ||
) { | ||
console.log(a); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在方法 fn
中使用 console.log(a);
时,变量 a
没有在方法作用域中定义。您应该使用 this.a
来引用类属性。
- console.log(a);
+ console.log(this.a);
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
console.log(a); | |
console.log(this.a); |
@tsProp() | ||
export class TsUseDecorator { | ||
@tsProp() | ||
a = 1; | ||
|
||
@tsProp() | ||
test( | ||
@tsProp() | ||
param: string, | ||
) { | ||
console.log(param); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
根据静态分析工具的提示,参数装饰器在没有特定配置的情况下在 TypeScript 中不是有效的。您可以通过在配置文件中设置 unsafeParameterDecoratorsEnabled
选项为 true
来启用参数装饰器,或者考虑重构代码。
Tools
Biome
[error] 10-10: Decorators are not valid here. (parse)
Decorators are only valid on class declarations, class expressions, and class methods.
You can enable parameter decorators by setting theunsafeParameterDecoratorsEnabled
option totrue
in your configuration file.
@@ -0,0 +1,15 @@ | |||
function tsProp(): any {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数 tsProp
返回类型为 any
,这通常不是一个好的做法,因为它会禁用许多类型检查规则。建议指定一个更明确的类型。
- function tsProp(): any {}
+ function tsProp(): unknown {}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
function tsProp(): any {} | |
function tsProp(): unknown {} |
Tools
Biome
[error] 1-1: Unexpected any. Specify a different type. (lint/suspicious/noExplicitAny)
any disables many type checking rules. Its use should be avoided.
@@ -22,6 +23,10 @@ export async function build(opts: { | |||
}): Promise<[BuildResult, BuildContext | undefined]> { | |||
const outdir = path.join(path.dirname(opts.entryPoints[0]), 'out'); | |||
const alias = opts.config?.alias || {}; | |||
const tsconfig = existsSync(path.join(opts.config.cwd, 'tsconfig.json')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们是不是最好在 api.appData
或者 api.paths
上把 tsconfig 路径和内容事先读出来比较好,这样谁都可以用。
实际 prepare 被有传 tsconfig 给 esbuild,用户根据提示改也不生效。
Summary by CodeRabbit
新功能
UseDecorator
和TsUseDecorator
类,允许在属性和方法参数上使用装饰器。tsconfig.json
文件,启用了experimentalDecorators
设置以支持实验性的装饰器功能。测试