1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

feat(publish): add --set-version <version> flag (#26141)

This commit is contained in:
Cornelius Krassow 2024-11-20 01:00:47 +01:00 committed by GitHub
parent 8be2bbf074
commit 9956731ddb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 127 additions and 27 deletions

View file

@ -428,6 +428,7 @@ pub struct PublishFlags {
pub allow_slow_types: bool, pub allow_slow_types: bool,
pub allow_dirty: bool, pub allow_dirty: bool,
pub no_provenance: bool, pub no_provenance: bool,
pub set_version: Option<String>,
} }
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
@ -1391,7 +1392,7 @@ pub fn flags_from_vec(args: Vec<OsString>) -> clap::error::Result<Flags> {
"uninstall" => uninstall_parse(&mut flags, &mut m), "uninstall" => uninstall_parse(&mut flags, &mut m),
"upgrade" => upgrade_parse(&mut flags, &mut m), "upgrade" => upgrade_parse(&mut flags, &mut m),
"vendor" => vendor_parse(&mut flags, &mut m), "vendor" => vendor_parse(&mut flags, &mut m),
"publish" => publish_parse(&mut flags, &mut m), "publish" => publish_parse(&mut flags, &mut m)?,
_ => unreachable!(), _ => unreachable!(),
} }
} else { } else {
@ -3253,7 +3254,8 @@ fn publish_subcommand() -> Command {
.help("Allow publishing if the repository has uncommitted changed") .help("Allow publishing if the repository has uncommitted changed")
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.help_heading(PUBLISH_HEADING), .help_heading(PUBLISH_HEADING),
).arg( )
.arg(
Arg::new("no-provenance") Arg::new("no-provenance")
.long("no-provenance") .long("no-provenance")
.help(cstr!("Disable provenance attestation. .help(cstr!("Disable provenance attestation.
@ -3261,6 +3263,14 @@ fn publish_subcommand() -> Command {
.action(ArgAction::SetTrue) .action(ArgAction::SetTrue)
.help_heading(PUBLISH_HEADING) .help_heading(PUBLISH_HEADING)
) )
.arg(
Arg::new("set-version")
.long("set-version")
.help("Set version for a package to be published.
<p(245)>This flag can be used while publishing individual packages and cannot be used in a workspace.</>")
.value_name("VERSION")
.help_heading(PUBLISH_HEADING)
)
.arg(check_arg(/* type checks by default */ true)) .arg(check_arg(/* type checks by default */ true))
.arg(no_check_arg()) .arg(no_check_arg())
}) })
@ -5229,7 +5239,10 @@ fn vendor_parse(flags: &mut Flags, _matches: &mut ArgMatches) {
flags.subcommand = DenoSubcommand::Vendor flags.subcommand = DenoSubcommand::Vendor
} }
fn publish_parse(flags: &mut Flags, matches: &mut ArgMatches) { fn publish_parse(
flags: &mut Flags,
matches: &mut ArgMatches,
) -> clap::error::Result<()> {
flags.type_check_mode = TypeCheckMode::Local; // local by default flags.type_check_mode = TypeCheckMode::Local; // local by default
unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionOnly); unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionOnly);
no_check_arg_parse(flags, matches); no_check_arg_parse(flags, matches);
@ -5242,7 +5255,10 @@ fn publish_parse(flags: &mut Flags, matches: &mut ArgMatches) {
allow_slow_types: matches.get_flag("allow-slow-types"), allow_slow_types: matches.get_flag("allow-slow-types"),
allow_dirty: matches.get_flag("allow-dirty"), allow_dirty: matches.get_flag("allow-dirty"),
no_provenance: matches.get_flag("no-provenance"), no_provenance: matches.get_flag("no-provenance"),
set_version: matches.remove_one::<String>("set-version"),
}); });
Ok(())
} }
fn compile_args_parse( fn compile_args_parse(
@ -10769,6 +10785,7 @@ mod tests {
"--allow-slow-types", "--allow-slow-types",
"--allow-dirty", "--allow-dirty",
"--token=asdf", "--token=asdf",
"--set-version=1.0.1",
]); ]);
assert_eq!( assert_eq!(
r.unwrap(), r.unwrap(),
@ -10779,6 +10796,7 @@ mod tests {
allow_slow_types: true, allow_slow_types: true,
allow_dirty: true, allow_dirty: true,
no_provenance: true, no_provenance: true,
set_version: Some("1.0.1".to_string()),
}), }),
type_check_mode: TypeCheckMode::Local, type_check_mode: TypeCheckMode::Local,
..Flags::default() ..Flags::default()

View file

@ -90,7 +90,7 @@ pub async fn publish(
let cli_options = cli_factory.cli_options()?; let cli_options = cli_factory.cli_options()?;
let directory_path = cli_options.initial_cwd(); let directory_path = cli_options.initial_cwd();
let publish_configs = cli_options.start_dir.jsr_packages_for_publish(); let mut publish_configs = cli_options.start_dir.jsr_packages_for_publish();
if publish_configs.is_empty() { if publish_configs.is_empty() {
match cli_options.start_dir.maybe_deno_json() { match cli_options.start_dir.maybe_deno_json() {
Some(deno_json) => { Some(deno_json) => {
@ -108,6 +108,18 @@ pub async fn publish(
} }
} }
} }
if let Some(version) = &publish_flags.set_version {
if publish_configs.len() > 1 {
bail!("Cannot use --set-version when publishing a workspace. Change your cwd to an individual package instead.");
}
if let Some(publish_config) = publish_configs.get_mut(0) {
let mut config_file = publish_config.config_file.as_ref().clone();
config_file.json.version = Some(version.clone());
publish_config.config_file = Arc::new(config_file);
}
}
let specifier_unfurler = Arc::new(SpecifierUnfurler::new( let specifier_unfurler = Arc::new(SpecifierUnfurler::new(
if cli_options.unstable_sloppy_imports() { if cli_options.unstable_sloppy_imports() {
Some(CliSloppyImportsResolver::new(SloppyImportsCachedFs::new( Some(CliSloppyImportsResolver::new(SloppyImportsCachedFs::new(
@ -410,9 +422,12 @@ impl PublishPreparer {
let deno_json = &package.config_file; let deno_json = &package.config_file;
let config_path = deno_json.specifier.to_file_path().unwrap(); let config_path = deno_json.specifier.to_file_path().unwrap();
let root_dir = config_path.parent().unwrap().to_path_buf(); let root_dir = config_path.parent().unwrap().to_path_buf();
let Some(version) = deno_json.json.version.clone() else { let version = deno_json.json.version.clone().ok_or_else(|| {
bail!("{} is missing 'version' field", deno_json.specifier); deno_core::anyhow::anyhow!(
}; "{} is missing 'version' field",
deno_json.specifier
)
})?;
if deno_json.json.exports.is_none() { if deno_json.json.exports.is_none() {
let mut suggested_entrypoint = None; let mut suggested_entrypoint = None;

View file

@ -0,0 +1,5 @@
{
"args": "publish --set-version 1.1.0 --token 'sadfasdf'",
"output": "error_set_version.out",
"exitCode": 1
}

View file

@ -0,0 +1,8 @@
{
"workspace": {
"members": [
"packages/package1",
"packages/package2"
]
}
}

View file

@ -0,0 +1 @@
error: Cannot use --set-version when publishing a workspace. Change your cwd to an individual package instead.

View file

@ -0,0 +1,7 @@
{
"name": "@foo/package1",
"version": "1.0.0",
"exports": {
".": "./mod.ts"
}
}

View file

@ -0,0 +1,3 @@
export function package1() {
return "package1";
}

View file

@ -0,0 +1,7 @@
{
"name": "@foo/package2",
"version": "1.0.0",
"exports": {
".": "./mod.ts"
}
}

View file

@ -0,0 +1,3 @@
export function package2() {
return "package2";
}

View file

@ -0,0 +1,4 @@
{
"args": "publish --set-version 1.1.0 --token 'sadfasdf'",
"output": "successful_set_version.out"
}

View file

@ -0,0 +1,10 @@
{
"name": "@foo/bar",
"version": "1.0.0",
"exports": {
".": "./mod.ts"
},
"imports": {
"@std/http": "./std_http.ts"
}
}

View file

@ -0,0 +1,7 @@
import http from "@std/http";
export function foobar(): { fileServer(): void } {
return {
fileServer: http.fileServer,
};
}

View file

@ -0,0 +1,6 @@
// temp until we get jsr:@std/http in the test server
export default {
fileServer() {
console.log("Hi");
},
};

View file

@ -0,0 +1,6 @@
Check file:///[WILDCARD]/success/mod.ts
Checking for slow types in the public API...
Check file:///[WILDCARD]/success/mod.ts
Publishing @foo/bar@1.1.0 ...
Successfully published @foo/bar@1.1.0
Visit http://127.0.0.1:4250/@foo/bar@1.1.0 for details