Skip to content

Commit

Permalink
feat(unstable): tar up directory with deno.json (#21228)
Browse files Browse the repository at this point in the history
Co-authored-by: David Sherret <[email protected]>
Co-authored-by: Luca Casonato <[email protected]>
Co-authored-by: Luca Casonato <[email protected]>
  • Loading branch information
4 people committed Nov 23, 2023
1 parent 778e4c9 commit 585cf2d
Show file tree
Hide file tree
Showing 11 changed files with 844 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 117,7 @@ rustyline = { version = "=10.0.0", default-features = false, features = ["custom
rustyline-derive = "=0.7.0"
serde.workspace = true
serde_repr.workspace = true
sha2.workspace = true
shell-escape = "=0.1.5"
tar.workspace = true
tempfile.workspace = true
Expand Down
41 changes: 40 additions & 1 deletion cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 279,12 @@ pub struct VendorFlags {
pub force: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PublishFlags {
pub directory: String,
pub token: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq)]
pub enum DenoSubcommand {
Bench(BenchFlags),
Expand All @@ -305,6 311,8 @@ pub enum DenoSubcommand {
Types,
Upgrade(UpgradeFlags),
Vendor(VendorFlags),
// TODO:
Publish(PublishFlags),
}

impl DenoSubcommand {
Expand Down Expand Up @@ -715,7 723,7 @@ impl Flags {
}
Bundle(_) | Completions(_) | Doc(_) | Fmt(_) | Init(_) | Install(_)
| Uninstall(_) | Jupyter(_) | Lsp | Lint(_) | Types | Upgrade(_)
| Vendor(_) => None,
| Vendor(_) | Publish(_) => None,
}
}

Expand Down Expand Up @@ -911,6 919,8 @@ pub fn flags_from_vec(args: Vec<String>) -> 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),
// TODO:
"do-not-use-publish" => publish_parse(&mut flags, &mut m),
_ => unreachable!(),
}
} else {
Expand Down Expand Up @@ -1045,6 1055,7 @@ fn clap_root() -> Command {
.subcommand(uninstall_subcommand())
.subcommand(lsp_subcommand())
.subcommand(lint_subcommand())
.subcommand(publish_subcommand())
.subcommand(repl_subcommand())
.subcommand(task_subcommand())
.subcommand(test_subcommand())
Expand Down Expand Up @@ -2302,6 2313,27 @@ Remote modules and multiple modules may also be specified:
.arg(ca_file_arg()))
}

fn publish_subcommand() -> Command {
Command::new("do-not-use-publish")
.hide(true)
.about("Publish a package to the Deno registry")
// TODO: .long_about()
.defer(|cmd| {
cmd.arg(
Arg::new("directory")
.help(
"The directory to the package, or workspace of packages to publish",
)
.value_hint(ValueHint::DirPath)
.required(true),
)
.arg(
Arg::new("token")
.help("The API token to use when publishing. If unset, interactive authentication will be used.")
)
})
}

fn compile_args(app: Command) -> Command {
compile_args_without_check_args(app.arg(no_check_arg()))
}
Expand Down Expand Up @@ -3722,6 3754,13 @@ fn vendor_parse(flags: &mut Flags, matches: &mut ArgMatches) {
});
}

fn publish_parse(flags: &mut Flags, matches: &mut ArgMatches) {
flags.subcommand = DenoSubcommand::Publish(PublishFlags {
directory: matches.remove_one::<String>("directory").unwrap(),
token: matches.remove_one("token"),
});
}

fn compile_args_parse(flags: &mut Flags, matches: &mut ArgMatches) {
compile_args_without_check_parse(flags, matches);
no_check_arg_parse(flags, matches);
Expand Down
2 changes: 1 addition & 1 deletion cli/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 165,7 @@ impl FetchCacher {
}
}

static DENO_REGISTRY_URL: Lazy<Url> = Lazy::new(|| {
pub(crate) static DENO_REGISTRY_URL: Lazy<Url> = Lazy::new(|| {
let env_var_name = "DENO_REGISTRY_URL";
if let Ok(registry_url) = std::env::var(env_var_name) {
// ensure there is a trailing slash for the directory
Expand Down
2 changes: 1 addition & 1 deletion cli/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 259,7 @@ impl HttpClient {
result
}

fn client(&self) -> Result<&reqwest::Client, AnyError> {
pub(crate) fn client(&self) -> Result<&reqwest::Client, AnyError> {
self.cell.get_or_try_init(|| {
create_http_client(
get_user_agent(),
Expand Down
4 changes: 4 additions & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 204,10 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
DenoSubcommand::Vendor(vendor_flags) => spawn_subcommand(async {
tools::vendor::vendor(flags, vendor_flags).await
}),
// TODO:
DenoSubcommand::Publish(publish_flags) => spawn_subcommand(async {
tools::registry::publish(flags, publish_flags).await
}),
};

handle.await?
Expand Down
1 change: 1 addition & 0 deletions cli/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 12,7 @@ pub mod init;
pub mod installer;
pub mod jupyter;
pub mod lint;
pub mod registry;
pub mod repl;
pub mod run;
pub mod task;
Expand Down
Loading

0 comments on commit 585cf2d

Please sign in to comment.