Skip to content

Commit

Permalink
fix(mfe): build internal package if present in graph
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-olszewski committed Nov 5, 2024
1 parent 21863ad commit 8d63aa5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
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
.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"
)))])
}),
..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 {
fn from(value: String) -> Self {
Self(value)
}
}
// For testing purposes
impl From<&'static str> for UnescapedString {
fn from(value: &'static str) -> Self {
Expand Down

0 comments on commit 8d63aa5

Please sign in to comment.