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:
parent
8be2bbf074
commit
9956731ddb
16 changed files with 127 additions and 27 deletions
|
@ -428,6 +428,7 @@ pub struct PublishFlags {
|
|||
pub allow_slow_types: bool,
|
||||
pub allow_dirty: bool,
|
||||
pub no_provenance: bool,
|
||||
pub set_version: Option<String>,
|
||||
}
|
||||
|
||||
#[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),
|
||||
"upgrade" => upgrade_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!(),
|
||||
}
|
||||
} else {
|
||||
|
@ -3253,7 +3254,8 @@ fn publish_subcommand() -> Command {
|
|||
.help("Allow publishing if the repository has uncommitted changed")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help_heading(PUBLISH_HEADING),
|
||||
).arg(
|
||||
)
|
||||
.arg(
|
||||
Arg::new("no-provenance")
|
||||
.long("no-provenance")
|
||||
.help(cstr!("Disable provenance attestation.
|
||||
|
@ -3261,6 +3263,14 @@ fn publish_subcommand() -> Command {
|
|||
.action(ArgAction::SetTrue)
|
||||
.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(no_check_arg())
|
||||
})
|
||||
|
@ -5229,7 +5239,10 @@ fn vendor_parse(flags: &mut Flags, _matches: &mut ArgMatches) {
|
|||
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
|
||||
unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionOnly);
|
||||
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_dirty: matches.get_flag("allow-dirty"),
|
||||
no_provenance: matches.get_flag("no-provenance"),
|
||||
set_version: matches.remove_one::<String>("set-version"),
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile_args_parse(
|
||||
|
@ -10769,6 +10785,7 @@ mod tests {
|
|||
"--allow-slow-types",
|
||||
"--allow-dirty",
|
||||
"--token=asdf",
|
||||
"--set-version=1.0.1",
|
||||
]);
|
||||
assert_eq!(
|
||||
r.unwrap(),
|
||||
|
@ -10779,6 +10796,7 @@ mod tests {
|
|||
allow_slow_types: true,
|
||||
allow_dirty: true,
|
||||
no_provenance: true,
|
||||
set_version: Some("1.0.1".to_string()),
|
||||
}),
|
||||
type_check_mode: TypeCheckMode::Local,
|
||||
..Flags::default()
|
||||
|
|
|
@ -90,7 +90,7 @@ pub async fn publish(
|
|||
|
||||
let cli_options = cli_factory.cli_options()?;
|
||||
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() {
|
||||
match cli_options.start_dir.maybe_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(
|
||||
if cli_options.unstable_sloppy_imports() {
|
||||
Some(CliSloppyImportsResolver::new(SloppyImportsCachedFs::new(
|
||||
|
@ -410,9 +422,12 @@ impl PublishPreparer {
|
|||
let deno_json = &package.config_file;
|
||||
let config_path = deno_json.specifier.to_file_path().unwrap();
|
||||
let root_dir = config_path.parent().unwrap().to_path_buf();
|
||||
let Some(version) = deno_json.json.version.clone() else {
|
||||
bail!("{} is missing 'version' field", deno_json.specifier);
|
||||
};
|
||||
let version = deno_json.json.version.clone().ok_or_else(|| {
|
||||
deno_core::anyhow::anyhow!(
|
||||
"{} is missing 'version' field",
|
||||
deno_json.specifier
|
||||
)
|
||||
})?;
|
||||
if deno_json.json.exports.is_none() {
|
||||
let mut suggested_entrypoint = None;
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"args": "publish --set-version 1.1.0 --token 'sadfasdf'",
|
||||
"output": "error_set_version.out",
|
||||
"exitCode": 1
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"workspace": {
|
||||
"members": [
|
||||
"packages/package1",
|
||||
"packages/package2"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
error: Cannot use --set-version when publishing a workspace. Change your cwd to an individual package instead.
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@foo/package1",
|
||||
"version": "1.0.0",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export function package1() {
|
||||
return "package1";
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@foo/package2",
|
||||
"version": "1.0.0",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
export function package2() {
|
||||
return "package2";
|
||||
}
|
0
tests/specs/publish/set_version/success/LICENSE
Normal file
0
tests/specs/publish/set_version/success/LICENSE
Normal file
4
tests/specs/publish/set_version/success/__test__.jsonc
Normal file
4
tests/specs/publish/set_version/success/__test__.jsonc
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"args": "publish --set-version 1.1.0 --token 'sadfasdf'",
|
||||
"output": "successful_set_version.out"
|
||||
}
|
10
tests/specs/publish/set_version/success/deno.json
Normal file
10
tests/specs/publish/set_version/success/deno.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "@foo/bar",
|
||||
"version": "1.0.0",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@std/http": "./std_http.ts"
|
||||
}
|
||||
}
|
7
tests/specs/publish/set_version/success/mod.ts
Normal file
7
tests/specs/publish/set_version/success/mod.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import http from "@std/http";
|
||||
|
||||
export function foobar(): { fileServer(): void } {
|
||||
return {
|
||||
fileServer: http.fileServer,
|
||||
};
|
||||
}
|
6
tests/specs/publish/set_version/success/std_http.ts
Normal file
6
tests/specs/publish/set_version/success/std_http.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
// temp until we get jsr:@std/http in the test server
|
||||
export default {
|
||||
fileServer() {
|
||||
console.log("Hi");
|
||||
},
|
||||
};
|
|
@ -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
|
Loading…
Reference in a new issue