Skip to content

Commit 02e0620

Browse files
committed
move out workspace resolution from arg parsing
1 parent 4042363 commit 02e0620

File tree

17 files changed

+14
-36
lines changed

17 files changed

+14
-36
lines changed

cli/args/flags.rs

+3-24
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ use color_print::cstr;
2626
use deno_config::deno_json::NodeModulesDirMode;
2727
use deno_config::glob::FilePatterns;
2828
use deno_config::glob::PathOrPatternSet;
29-
use deno_config::workspace::WorkspaceDirectory;
30-
use deno_config::workspace::WorkspaceDiscoverOptions;
31-
use deno_config::workspace::WorkspaceDiscoverStart;
3229
use deno_core::anyhow::bail;
3330
use deno_core::anyhow::Context;
3431
use deno_core::error::AnyError;
@@ -3269,7 +3266,8 @@ fn publish_subcommand() -> Command {
32693266
.arg(
32703267
Arg::new("set-version")
32713268
.long("set-version")
3272-
.help("Set the version specified in the configuration file")
3269+
.help("Set version for a package to be published.
3270+
<p(245)>This flag can be used while publishing individual packages and cannot be used in a workspace.</>")
32733271
.value_name("VERSION")
32743272
.help_heading(PUBLISH_HEADING)
32753273
)
@@ -5251,32 +5249,13 @@ fn publish_parse(
52515249
check_arg_parse(flags, matches);
52525250
config_args_parse(flags, matches);
52535251

5254-
let set_version = matches.remove_one::<String>("set-version");
5255-
5256-
if set_version.is_some() {
5257-
if let Ok(workspace_dir) = WorkspaceDirectory::discover(
5258-
WorkspaceDiscoverStart::Paths(&[
5259-
std::env::current_dir().unwrap_or_default()
5260-
]),
5261-
&WorkspaceDiscoverOptions::default(),
5262-
) {
5263-
let jsr_packages = workspace_dir.jsr_packages_for_publish();
5264-
if jsr_packages.len() > 1 {
5265-
return Err(clap::Error::raw(
5266-
clap::error::ErrorKind::ArgumentConflict,
5267-
"The --set-version flag cannot be used in a workspace. It is only allowed for individual packages.",
5268-
));
5269-
}
5270-
}
5271-
}
5272-
52735252
flags.subcommand = DenoSubcommand::Publish(PublishFlags {
52745253
token: matches.remove_one("token"),
52755254
dry_run: matches.get_flag("dry-run"),
52765255
allow_slow_types: matches.get_flag("allow-slow-types"),
52775256
allow_dirty: matches.get_flag("allow-dirty"),
52785257
no_provenance: matches.get_flag("no-provenance"),
5279-
set_version,
5258+
set_version: matches.remove_one::<String>("set-version"),
52805259
});
52815260

52825261
Ok(())

cli/tools/registry/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,14 @@ pub async fn publish(
111111
}
112112

113113
if let Some(version) = &publish_flags.set_version {
114-
publish_configs = publish_configs
115-
.into_iter()
116-
.map(|mut config| {
117-
let mut config_file = config.config_file.as_ref().clone();
118-
config_file.json.version = Some(version.clone());
119-
config.config_file = Arc::new(config_file);
120-
config
121-
})
122-
.collect();
114+
if publish_configs.len() > 1 {
115+
bail!("Cannot use --set-version when publishing a workspace. Change your cwd to an individual package instead.");
116+
}
117+
if let Some(publish_config) = publish_configs.get_mut(0) {
118+
let mut config_file = publish_config.config_file.as_ref().clone();
119+
config_file.json.version = Some(version.clone());
120+
publish_config.config_file = Arc::new(config_file);
121+
}
123122
}
124123

125124
let specifier_unfurler = Arc::new(SpecifierUnfurler::new(

tests/specs/publish/error_set_version/error_set_version.out

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
error: Cannot use --set-version when publishing a workspace. Change your cwd to an individual package instead.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Check file:///[WILDCARD]/publish/successful_set_version/mod.ts
1+
Check file:///[WILDCARD]/success/mod.ts
22
Checking for slow types in the public API...
3-
Check file:///[WILDCARD]/publish/successful_set_version/mod.ts
3+
Check file:///[WILDCARD]/success/mod.ts
44
Publishing @foo/[email protected] ...
55
Successfully published @foo/[email protected]
66
Visit http://127.0.0.1:4250/@foo/[email protected] for details

0 commit comments

Comments
 (0)