这是indexloc提供的服务,不要输入任何密码
Skip to content

fix(mfe): build internal package if present in graph #9383

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

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/turborepo-lib/src/turbo_json/loader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::collections::HashMap;

use itertools::Itertools;
use tracing::debug;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf};
use turborepo_errors::Spanned;
use turborepo_micro_frontend::MICRO_FRONTENDS_PACKAGE_INTERNAL;
use turborepo_repository::{
package_graph::{PackageInfo, PackageName},
package_json::PackageJson,
Expand Down Expand Up @@ -184,7 +186,10 @@ impl TurboJsonLoader {
Error::NoTurboJSON => Ok(TurboJson::default()),
err => Err(err),
})?;
turbo_json.with_proxy();
let needs_proxy_build = packages
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only want to add this if the internal package is in the graph meaning there's a valid build task

.keys()
.contains(&PackageName::from(MICRO_FRONTENDS_PACKAGE_INTERNAL));
turbo_json.with_proxy(needs_proxy_build);
Ok(turbo_json)
} else {
turbo_json
Expand Down
8 changes: 7 additions & 1 deletion crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
use struct_iterable::Iterable;
use turbopath::AbsoluteSystemPath;
use turborepo_errors::Spanned;
use turborepo_micro_frontend::MICRO_FRONTENDS_PACKAGE_INTERNAL;
use turborepo_repository::package_graph::ROOT_PKG_NAME;
use turborepo_unescape::UnescapedString;

Expand Down Expand Up @@ -610,7 +611,7 @@ impl TurboJson {
}

/// Adds a local proxy task to a workspace TurboJson
pub fn with_proxy(&mut self) {
pub fn with_proxy(&mut self, needs_proxy_build: bool) {
if self.extends.is_empty() {
self.extends = Spanned::new(vec!["//".into()]);
}
Expand All @@ -619,6 +620,11 @@ impl TurboJson {
TaskName::from("proxy"),
Spanned::new(RawTaskDefinition {
cache: Some(Spanned::new(false)),
depends_on: needs_proxy_build.then(|| {
Spanned::new(vec![Spanned::new(UnescapedString::from(format!(
"{MICRO_FRONTENDS_PACKAGE_INTERNAL}#build"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't love that we have to hardcode this task, but we can iterate on it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't love this, but for all other uses of the MFE package that don't have it as a workspace package this will be unnecessary.

)))])
}),
..Default::default()
}),
);
Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-micro-frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use turbopath::AbsoluteSystemPath;
///
/// This is subject to change at any time.
pub const DEFAULT_MICRO_FRONTENDS_CONFIG: &str = "micro-frontends.jsonc";
pub const MICRO_FRONTENDS_PACKAGES: &[&str] = ["@vercel/micro-frontends-internal"].as_slice();
pub const MICRO_FRONTENDS_PACKAGES: &[&str] = [MICRO_FRONTENDS_PACKAGE_INTERNAL].as_slice();
pub const MICRO_FRONTENDS_PACKAGE_INTERNAL: &str = "@vercel/micro-frontends-internal";

/// The minimal amount of information Turborepo needs to correctly start a local
/// proxy server for microfrontends
Expand Down
5 changes: 5 additions & 0 deletions crates/turborepo-unescape/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ impl From<UnescapedString> for String {
}
}

impl From<String> for UnescapedString {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required since there isn't any other way to construct an UnescapedString

fn from(value: String) -> Self {
Self(value)
}
}
// For testing purposes
impl From<&'static str> for UnescapedString {
fn from(value: &'static str) -> Self {
Expand Down
Loading