Skip to content

Commit

Permalink
feat!: streamline extension standalone testing
Browse files Browse the repository at this point in the history
  • Loading branch information
halajohn committed Jan 11, 2025
1 parent d210337 commit 3d0ee55
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
58 changes: 34 additions & 24 deletions core/src/ten_manager/src/cmd/cmd_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn create_sub_cmd(args_cfg: &crate::cmd_line::ArgsCfg) -> Command {
.arg(
Arg::new("STANDALONE")
.long("standalone")
.help("Install in standalone mode, only for extension package.")
.help("Install in standalone mode, only for extension package")
.action(clap::ArgAction::SetTrue)
.required(false),
)
Expand Down Expand Up @@ -195,7 +195,8 @@ fn prepare_standalone_app_dir(extension_dir: &Path) -> Result<PathBuf> {

let manifest_json = dot_ten_app_dir.join(MANIFEST_JSON_FILENAME);
if !manifest_json.exists() {
// Create a basic `manifest.json`.
// Create a basic `manifest.json`, and in that manifest.json, there will
// be a local dependency pointing to the current extension folder.
let content = r#"{
"type": "app",
"name": "app_for_standalone",
Expand All @@ -213,39 +214,49 @@ fn prepare_standalone_app_dir(extension_dir: &Path) -> Result<PathBuf> {
Ok(dot_ten_app_dir)
}

pub async fn execute_cmd(
tman_config: &TmanConfig,
command_data: InstallCommand,
) -> Result<()> {
tman_verbose_println!(tman_config, "Executing install command");
tman_verbose_println!(tman_config, "{:?}", command_data);
tman_verbose_println!(tman_config, "{:?}", tman_config);

let started = Instant::now();

let original_cwd = crate::fs::get_cwd()?;

// Path logic for standalone mode and non-standalone mode.
let app_dir_to_work_with = if command_data.standalone {
/// Path logic for standalone mode and non-standalone mode.
fn determine_app_dir_to_work_with(
standalone: bool,
original_cwd: &Path,
) -> Result<PathBuf> {
if standalone {
// If it is standalone mode, it can only be executed in the extension
// directory.
check_is_extension_folder(&original_cwd)?;
check_is_extension_folder(original_cwd)?;

let dot_ten_app_dir_path = prepare_standalone_app_dir(&original_cwd)?;
let dot_ten_app_dir_path = prepare_standalone_app_dir(original_cwd)?;

env::set_current_dir(&dot_ten_app_dir_path)?;

dot_ten_app_dir_path.clone()
Ok(dot_ten_app_dir_path)
} else {
// Non-standalone mode can only be executed in the extension directory.
// If it is an extension, it should search upwards for the nearest app;
// if it is an app, it can be used directly.
let app_dir = find_nearest_app_dir(original_cwd.clone())?;
let app_dir = find_nearest_app_dir(original_cwd.to_path_buf())?;

env::set_current_dir(&app_dir)?;

app_dir
};
Ok(app_dir)
}
}

pub async fn execute_cmd(
tman_config: &TmanConfig,
command_data: InstallCommand,
) -> Result<()> {
tman_verbose_println!(tman_config, "Executing install command");
tman_verbose_println!(tman_config, "{:?}", command_data);
tman_verbose_println!(tman_config, "{:?}", tman_config);

let started = Instant::now();

let original_cwd = crate::fs::get_cwd()?;

let app_dir_to_work_with = determine_app_dir_to_work_with(
command_data.standalone,
&original_cwd.clone(),
)?;

// If `tman install` is run within the scope of an app, then the app and
// those addons (extensions, ...) installed in the app directory are all
Expand Down Expand Up @@ -368,8 +379,7 @@ pub async fn execute_cmd(
}

PkgType::Extension => {
// Install all dependencies of the extension package, but a APP
// folder (i.e., `.ten/app`) should be created first.
// Install all dependencies of the extension package.
filter_compatible_pkgs_to_candidates(
tman_config,
&initial_pkgs_to_find_candidates,
Expand Down
1 change: 1 addition & 0 deletions core/src/ten_manager/src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ fn install_local_dependency_pkg_info(
dest_dir_path
);
} else {
// Create all parent folders for `dest_dir`.
let dest_path = Path::new(dest_dir_path);
if let Some(parent) = dest_path.parent() {
fs::create_dir_all(parent).with_context(|| {
Expand Down

0 comments on commit 3d0ee55

Please sign in to comment.