Skip to content

Commit

Permalink
refactor(cli): disable api-all on templates (#5538)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Nov 3, 2022
1 parent dc9269b commit 582c25a
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .changes/templates-allowlist-false.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Changed the project template to not enable all APIs by default.
3 changes: 1 addition & 2 deletions tooling/cli/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ pub fn command(mut options: Options) -> Result<()> {
} else {
(
Some(
std::fs::read_to_string(&config)
.with_context(|| "failed to read custom configuration")?,
std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?,
),
Some(config.clone()),
)
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn command_internal(mut options: Options) -> Result<()> {
Some(if config.starts_with('{') {
config.to_string()
} else {
std::fs::read_to_string(&config).with_context(|| "failed to read custom configuration")?
std::fs::read_to_string(config).with_context(|| "failed to read custom configuration")?
})
} else {
None
Expand Down
8 changes: 4 additions & 4 deletions tooling/cli/src/helpers/updater_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct KeyPair {

fn create_file(path: &Path) -> crate::Result<BufWriter<File>> {
if let Some(parent) = path.parent() {
fs::create_dir_all(&parent)?;
fs::create_dir_all(parent)?;
}
let file = File::create(path)?;
Ok(BufWriter::new(file))
Expand Down Expand Up @@ -72,12 +72,12 @@ where
sk_path.display()
));
} else {
std::fs::remove_file(&sk_path)?;
std::fs::remove_file(sk_path)?;
}
}

if pk_path.exists() {
std::fs::remove_file(&pk_path)?;
std::fs::remove_file(pk_path)?;
}

let mut sk_writer = create_file(sk_path)?;
Expand All @@ -88,7 +88,7 @@ where
write!(pk_writer, "{:}", pubkey)?;
pk_writer.flush()?;

Ok((fs::canonicalize(&sk_path)?, fs::canonicalize(&pk_path)?))
Ok((fs::canonicalize(sk_path)?, fs::canonicalize(pk_path)?))
}

/// Read key from file
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/src/helpers/web_dev_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async fn handler<T>(req: Request<T>, state: Arc<State>) -> impl IntoResponse {
uri.strip_prefix('/').unwrap_or(&uri)
};

let file = std::fs::read(state.serve_dir.join(&uri))
let file = std::fs::read(state.serve_dir.join(uri))
.or_else(|_| std::fs::read(state.serve_dir.join(format!("{}.html", &uri))))
.or_else(|_| std::fs::read(state.serve_dir.join(format!("{}/index.html", &uri))))
.or_else(|_| std::fs::read(state.serve_dir.join("index.html")));
Expand Down
19 changes: 7 additions & 12 deletions tooling/cli/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn npm_latest_version(pm: &PackageManager, name: &str) -> crate::Result<Option<S
let output = cmd
.arg("info")
.arg(name)
.args(&["version", "--json"])
.args(["version", "--json"])
.output()?;
if output.status.success() {
let stdout = String::from_utf8_lossy(&output.stdout);
Expand Down Expand Up @@ -219,9 +219,9 @@ fn npm_package_version<P: AsRef<Path>>(
let (output, regex) = match pm {
PackageManager::Yarn => (
cross_command("yarn")
.args(&["list", "--pattern"])
.args(["list", "--pattern"])
.arg(name)
.args(&["--depth", "0"])
.args(["--depth", "0"])
.current_dir(app_dir)
.output()?,
None,
Expand All @@ -238,7 +238,7 @@ fn npm_package_version<P: AsRef<Path>>(
cross_command("npm")
.arg("list")
.arg(name)
.args(&["version", "--depth", "0"])
.args(["version", "--depth", "0"])
.current_dir(app_dir)
.output()?,
None,
Expand All @@ -247,7 +247,7 @@ fn npm_package_version<P: AsRef<Path>>(
cross_command("pnpm")
.arg("list")
.arg(name)
.args(&["--parseable", "--depth", "0"])
.args(["--parseable", "--depth", "0"])
.current_dir(app_dir)
.output()?,
None,
Expand All @@ -273,11 +273,7 @@ fn get_version(command: &str, args: &[&str]) -> crate::Result<Option<String>> {
.arg("--version")
.output()?;
let version = if output.status.success() {
Some(
String::from_utf8_lossy(&output.stdout)
.replace('\n', "")
.replace('\r', ""),
)
Some(String::from_utf8_lossy(&output.stdout).replace(['\n', '\r'], ""))
} else {
None
};
Expand Down Expand Up @@ -380,8 +376,7 @@ fn active_rust_toolchain() -> crate::Result<Option<String>> {
let toolchain = if output.status.success() {
Some(
String::from_utf8_lossy(&output.stdout)
.replace('\n', "")
.replace('\r', "")
.replace(['\n', '\r'], "")
.split('(')
.collect::<Vec<&str>>()[0]
.into(),
Expand Down
7 changes: 2 additions & 5 deletions tooling/cli/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub fn command(mut options: Options) -> Result<()> {
let (tauri_dep, tauri_build_dep) = if let Some(tauri_path) = options.tauri_path {
(
format!(
r#"{{ path = {:?}, features = [ "api-all" ] }}"#,
r#"{{ path = {:?} }}"#,
resolve_tauri_path(&tauri_path, "core/tauri")
),
format!(
Expand All @@ -177,10 +177,7 @@ pub fn command(mut options: Options) -> Result<()> {
)
} else {
(
format!(
r#"{{ version = "{}", features = [ "api-all" ] }}"#,
metadata.tauri
),
format!(r#"{{ version = "{}" }}"#, metadata.tauri),
format!(r#"{{ version = "{}" }}"#, metadata.tauri_build),
)
};
Expand Down
6 changes: 3 additions & 3 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ impl Rust {
info!(
"File {} changed. Rebuilding application...",
event_path
.strip_prefix(&app_path)
.strip_prefix(app_path)
.unwrap_or(&event_path)
.display()
);
Expand Down Expand Up @@ -626,7 +626,7 @@ impl AppSettings for RustAppSettings {
.package_settings
.default_run
.clone()
.unwrap_or_else(|| "".to_string());
.unwrap_or_default();
for binary in bin {
binaries.push(
if Some(&binary.name) == self.cargo_package_settings.name.as_ref()
Expand Down Expand Up @@ -759,7 +759,7 @@ impl RustAppSettings {
.target()
.map(|t| t.to_string())
.unwrap_or_else(|| {
let output = Command::new("rustc").args(&["-vV"]).output().unwrap();
let output = Command::new("rustc").args(["-vV"]).output().unwrap();
let stdout = String::from_utf8_lossy(&output.stdout);
stdout
.split('\n')
Expand Down
8 changes: 4 additions & 4 deletions tooling/cli/src/interface/rust/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ pub fn build(
}

if options.target == Some("universal-apple-darwin".into()) {
std::fs::create_dir_all(&out_dir).with_context(|| "failed to create project out directory")?;
std::fs::create_dir_all(out_dir).with_context(|| "failed to create project out directory")?;

let mut lipo_cmd = Command::new("lipo");
lipo_cmd
.arg("-create")
.arg("-output")
.arg(out_dir.join(&bin_name));
.arg(out_dir.join(bin_name));
for triple in ["aarch64-apple-darwin", "x86_64-apple-darwin"] {
let mut options = options.clone();
options.target.replace(triple.into());
Expand All @@ -114,7 +114,7 @@ pub fn build(
build_production_app(options, available_targets, config_features.clone())
.with_context(|| format!("failed to build {} binary", triple))?;

lipo_cmd.arg(triple_out_dir.join(&bin_name));
lipo_cmd.arg(triple_out_dir.join(bin_name));
}

let lipo_status = lipo_cmd.output_ok()?.status;
Expand Down Expand Up @@ -344,7 +344,7 @@ fn rename_app(bin_path: &Path, product_name: Option<&str>) -> crate::Result<Path
.join(&product_name)
.with_extension(bin_path.extension().unwrap_or_default());

rename(&bin_path, &product_path).with_context(|| {
rename(bin_path, &product_path).with_context(|| {
format!(
"failed to rename `{}` to `{}`",
bin_path.display(),
Expand Down
5 changes: 1 addition & 4 deletions tooling/cli/src/interface/rust/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ fn write_features(
}
Value::String(version) => {
let mut def = InlineTable::default();
def.get_or_insert(
"version",
version.to_string().replace('\"', "").replace(' ', ""),
);
def.get_or_insert("version", version.to_string().replace(['\"', ' '], ""));
def.get_or_insert("features", Value::Array(toml_array(features)));
*dep = Value::InlineTable(def);
}
Expand Down
7 changes: 2 additions & 5 deletions tooling/cli/src/plugin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn command(mut options: Options) -> Result<()> {
resolve_tauri_path(&tauri_path, "core/tauri")
),
format!(
r#"{{ path = {:?}, features = [ "api-all" ] }}"#,
r#"{{ path = {:?} }}"#,
resolve_tauri_path(&tauri_path, "core/tauri")
),
format!(
Expand All @@ -83,10 +83,7 @@ pub fn command(mut options: Options) -> Result<()> {
} else {
(
format!(r#"{{ version = "{}" }}"#, metadata.tauri),
format!(
r#"{{ version = "{}", features = [ "api-all" ] }}"#,
metadata.tauri
),
format!(r#"{{ version = "{}" }}"#, metadata.tauri),
format!(r#"{{ version = "{}" }}"#, metadata.tauri_build),
)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"active": false
},
"allowlist": {
"all": true
"all": false
},
"windows": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
},
"allowlist": {
"all": true
"all": false
},
"windows": [
{
Expand Down
2 changes: 1 addition & 1 deletion tooling/cli/templates/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"active": false
},
"allowlist": {
"all": true
"all": false
},
"windows": [
{
Expand Down

0 comments on commit 582c25a

Please sign in to comment.