-
Notifications
You must be signed in to change notification settings - Fork 108
feat(pack): support runtime entry bootstrap #2449
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,21 @@ pub enum ProviderConfigValue { | |
| #[turbo_tasks::value(transparent)] | ||
| pub struct ProviderConfig(FxIndexMap<RcStr, ProviderConfigValue>); | ||
|
|
||
| /// Runtime bootstrap configuration - can be either inline code or a file path | ||
| #[derive( | ||
| Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, NonLocalValue, OperationValue, | ||
| )] | ||
| #[serde(untagged)] | ||
| pub enum RuntimeBootstrapConfig { | ||
| /// Inline JavaScript code | ||
| Code(RcStr), | ||
| /// Path to a JavaScript/TypeScript file | ||
| Path(RcStr), | ||
| } | ||
|
Comment on lines
+124
to
+133
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
pub enum RuntimeBootstrapConfig {
/// Path to a JavaScript/TypeScript file, as an object: `{ "path": "./bootstrap.js" }`
Path { path: RcStr },
/// Inline JavaScript code, as a string
Code(RcStr),
} |
||
|
|
||
| #[turbo_tasks::value(transparent)] | ||
| pub struct OptionRuntimeBootstrapConfig(Option<RuntimeBootstrapConfig>); | ||
|
|
||
| #[turbo_tasks::value(serialization = "custom", eq = "manual")] | ||
| #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize, OperationValue)] | ||
| #[serde(rename_all = "camelCase")] | ||
|
|
@@ -142,6 +157,7 @@ pub struct Config { | |
| cache_handler: Option<RcStr>, | ||
| node_polyfill: Option<bool>, | ||
| dev_server: Option<DevServer>, | ||
| runtime_bootstrap: Option<RuntimeBootstrapConfig>, | ||
| #[serde(default)] | ||
| experimental: ExperimentalConfig, | ||
| #[cfg(feature = "test")] | ||
|
|
@@ -1191,6 +1207,11 @@ impl Config { | |
| Vc::cell(self.node_polyfill.unwrap_or(false)) | ||
| } | ||
|
|
||
| #[turbo_tasks::function] | ||
| pub fn runtime_bootstrap(&self) -> Vc<OptionRuntimeBootstrapConfig> { | ||
| OptionRuntimeBootstrapConfig(self.runtime_bootstrap.clone()).cell() | ||
| } | ||
|
|
||
| #[turbo_tasks::function] | ||
| pub async fn import_externals(&self) -> Result<Vc<bool>> { | ||
| Ok(Vc::cell(match self.experimental.esm_externals { | ||
|
|
||
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.
match表达式的Code和Path分支中存在代码重复。创建bootstrap_source后的逻辑(即runtime_entries.push(...))是完全相同的。建议将这部分通用逻辑提取到match表达式之外,以减少重复并提高代码的可读性和可维护性。