fn link_children_packages(opts: &opts::Link, lerna_manifest: &MonorepoManifest) -> Result<bool> {
    let mut is_exit_success = true;

    lerna_manifest
        .internal_package_manifests
        .iter()
        .fold(HashMap::new(), key_children_by_parent)
        .iter()
        .try_for_each(|(directory, children)| -> Result<()> {
            let desired_project_references = create_project_references(children);
            let tsconfig_filename = opts.root.join(directory).join("tsconfig.json");
            let tsconfig = TypescriptConfig::from_directory(&opts.root, directory)?;
            let current_project_references = tsconfig
                .contents
                .get("references")
                .map(|value| {
                    serde_json::from_value::<Vec<TypescriptProjectReference>>(value.clone())
                        .expect("Value starting as JSON should be serializable")
                })
                .unwrap_or_default();
            let needs_update = !vecs_match(
                &current_project_references,
                &desired_project_references.references,
            );
            if !needs_update {
                return Ok(());
            }
            if opts.check_only {
                is_exit_success = false;
                let serialized = serde_json::to_string_pretty(&desired_project_references)?;
                println!(
                    "File has out-of-date project references: {:?}, expecting:",
                    tsconfig_filename
                );
                println!("{}", serialized);
                Ok(())
            } else {
                write_project_references(tsconfig_filename, &desired_project_references)
            }
        })?;

    Ok(is_exit_success)
}
// Create a tsconfig.json file in each parent directory to an internal package.
// This permits us to build the monorepo from the top down.
Create a tsconfig.json file in each parent directory to an internal package.
This permits us to build the monorepo from the top down.
Create a tsconfig . json file in each parent directory to an internal package . This permits us to build the monorepo from the top down .
fn link_children_packages(opts: &opts::Link, lerna_manifest: &MonorepoManifest) -> Result<bool> {
    let mut is_exit_success = true;
    lerna_manifest
        .internal_package_manifests
        .iter()
        .fold(HashMap::new(), key_children_by_parent)
        .iter()
        .try_for_each(|(directory, children)| -> Result<()> {
            let desired_project_references = create_project_references(children);
            let tsconfig_filename = opts.root.join(directory).join("tsconfig.json");
            let tsconfig = TypescriptConfig::from_directory(&opts.root, directory)?;
            let current_project_references = tsconfig
                .contents
                .get("references")
                .map(|value| {
                    serde_json::from_value::<Vec<TypescriptProjectReference>>(value.clone())
                        .expect("Value starting as JSON should be serializable")
                })
                .unwrap_or_default();
            let needs_update = !vecs_match(
                &current_project_references,
                &desired_project_references.references,
            );
            if !needs_update {
                return Ok(());
            }
            if opts.check_only {
                is_exit_success = false;
                let serialized = serde_json::to_string_pretty(&desired_project_references)?;
                println!(
                    "File has out-of-date project references: {:?}, expecting:",
                    tsconfig_filename
                );
                println!("{}", serialized);
                Ok(())
            } else {
                write_project_references(tsconfig_filename, &desired_project_references)
            }
        })?;
    Ok(is_exit_success)
}
fn link_children_packages ( opts : & opts :: Link , lerna_manifest : & MonorepoManifest ) -> Result < bool > { let mut is_exit_success = true ; lerna_manifest . internal_package_manifests . iter ( ) . fold ( HashMap :: new ( ) , key_children_by_parent ) . iter ( ) . try_for_each ( | ( directory , children ) | -> Result < ( ) > { let desired_project_references = create_project_references ( children ) ; let tsconfig_filename = opts . root . join ( directory ) . join ( " " ) ; let tsconfig = TypescriptConfig :: from_directory ( & opts . root , directory ) ? ; let current_project_references = tsconfig . contents . get ( " " ) . map ( | value | { serde_json :: from_value :: < Vec < TypescriptProjectReference > > ( value . clone ( ) ) . expect ( " " ) } ) . unwrap_or_default ( ) ; let needs_update = ! vecs_match ( & current_project_references , & desired_project_references . references , ) ; if ! needs_update { return Ok ( ( ) ) ; } if opts . check_only { is_exit_success = false ; let serialized = serde_json :: to_string_pretty ( & desired_project_references ) ? ; println ! ( " " tsconfig_filename ) ; println ! ( " " serialized ) ; Ok ( ( ) ) } else { write_project_references ( tsconfig_filename , & desired_project_references ) } } ) ? ; Ok ( is_exit_success ) }
Create a tsconfig.json file in each parent directory to an internal package.
Create a tsconfig . json file in each parent directory to an internal package .
opts
&opts::Link
lerna_manifest
&MonorepoManifest