Skip to content

Commit 6d3f313

Browse files
fix(core/path): change sep and delimiter to functions (#7160)
* fix(core/path): change `sep` and `delimiter` to functions * fix impl * semicolons * return types * generated * fix init js --------- Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent bfaf624 commit 6d3f313

File tree

8 files changed

+220
-294
lines changed

8 files changed

+220
-294
lines changed

Diff for: .changes/path-sep-delimter.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tauri-apps/api': 'minor:enhance'
3+
---
4+
5+
Changed `sep` and `delimiter` from `path` module into functions to fix import in frameworks like `next.js`

Diff for: core/tauri/scripts/bundle.global.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: core/tauri/src/path/init.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
if (!('path' in window.__TAURI__)) {
6+
window.__TAURI__.path = {}
7+
}
8+
9+
window.__TAURI__.path.__sep = __TEMPLATE_sep__
10+
window.__TAURI__.path.__delimiter = __TEMPLATE_delimiter__

Diff for: core/tauri/src/path/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::{
1111

1212
use serde::{de::Error as DeError, Deserialize, Deserializer};
1313
use serde_repr::{Deserialize_repr, Serialize_repr};
14+
use serialize_to_javascript::{default_template, DefaultTemplate, Template};
1415

1516
#[cfg(any(path_all, test))]
1617
mod commands;
@@ -331,6 +332,13 @@ fn resolve_path<R: Runtime>(
331332
Ok(base_dir_path)
332333
}
333334

335+
#[derive(Template)]
336+
#[default_template("./init.js")]
337+
struct InitJavascript {
338+
sep: &'static str,
339+
delimiter: &'static str,
340+
}
341+
334342
/// Initializes the plugin.
335343
pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {
336344
#[allow(unused_mut)]
@@ -350,7 +358,18 @@ pub(crate) fn init<R: Runtime>() -> TauriPlugin<R> {
350358
]);
351359
}
352360

361+
#[cfg(windows)]
362+
let (sep, delimiter) = ("\\", ";");
363+
#[cfg(not(windows))]
364+
let (sep, delimiter) = ("/", ":");
365+
366+
let init_js = InitJavascript { sep, delimiter }
367+
.render_default(&Default::default())
368+
// this will never fail with the above sep and delimiter values
369+
.unwrap();
370+
353371
builder
372+
.js_init_script(init_js.to_string())
354373
.setup(|app, _api| {
355374
#[cfg(target_os = "android")]
356375
{

0 commit comments

Comments
 (0)