chore: adjust prettier config, .gitignore and use taplo to format toml files (#1728)

* chore: adjust prettier config, .gitignore and use taplo to format toml files

This brings the plugins-workspace repository to the same code style of the main tauri repo

* format toml

* ignore examples gen dir

* add .vscode/extensions.json

* remove packageManager field

* fmt

* fix audit

* taplo ignore permissions autogenerated files

* remove create dummy dist

* fix prettier workflow

* install fmt in prettier workflow

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
Amr Bashir
2024-09-04 14:54:23 +03:00
committed by GitHub
parent 72c2ce82c1
commit cf4d7d4e6c
227 changed files with 2534 additions and 2505 deletions
-2
View File
@@ -1,2 +0,0 @@
node_modules
/.tauri
+3 -3
View File
@@ -10,11 +10,11 @@ repository = { workspace = true }
links = "tauri-plugin-log"
[package.metadata.docs.rs]
rustc-args = [ "--cfg", "docsrs" ]
rustdoc-args = [ "--cfg", "docsrs" ]
rustc-args = ["--cfg", "docsrs"]
rustdoc-args = ["--cfg", "docsrs"]
[build-dependencies]
tauri-plugin = { workspace = true, features = [ "build" ] }
tauri-plugin = { workspace = true, features = ["build"] }
[dependencies]
serde = { workspace = true }
+6 -6
View File
@@ -68,17 +68,17 @@ fn main() {
Afterwards all the plugin's APIs are available through the JavaScript guest bindings:
```javascript
import { trace, info, error, attachConsole } from "@tauri-apps/plugin-log";
import { trace, info, error, attachConsole } from '@tauri-apps/plugin-log'
// with TargetKind::Webview enabled this function will print logs to the browser console
const detach = await attachConsole();
const detach = await attachConsole()
trace("Trace");
info("Info");
error("Error");
trace('Trace')
info('Info')
error('Error')
// detach the browser console from the log stream
detach();
detach()
```
To log from rust code, add the log crate to your `Cargo.toml`:
+1
View File
@@ -39,6 +39,7 @@ One possible threat you need to consider when using this plugin is that secrets
in logs can theoretically be leaked when the application's frontend gets compromised.
For this threat to be possible all of the following requirements need to be fulfilled:
- `TargetKind::Webview` enabled OR secrets stem from frontend logs
- Frontend application is compromised via something like XSS (cross-site-scripting) OR logs are directly exposed
- Logs contain secrets or sensitive information
+49 -49
View File
@@ -2,13 +2,13 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/core";
import { listen, type UnlistenFn, type Event } from "@tauri-apps/api/event";
import { invoke } from '@tauri-apps/api/core'
import { listen, type UnlistenFn, type Event } from '@tauri-apps/api/event'
export interface LogOptions {
file?: string;
line?: number;
keyValues?: Record<string, string | undefined>;
file?: string
line?: number
keyValues?: Record<string, string | undefined>
}
enum LogLevel {
@@ -41,35 +41,35 @@ enum LogLevel {
*
* Designates very serious errors.
*/
Error,
Error
}
async function log(
level: LogLevel,
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
const traces = new Error().stack?.split("\n").map((line) => line.split("@"));
const traces = new Error().stack?.split('\n').map((line) => line.split('@'))
const filtered = traces?.filter(([name, location]) => {
return name.length > 0 && location !== "[native code]";
});
return name.length > 0 && location !== '[native code]'
})
const { file, line, keyValues } = options ?? {};
const { file, line, keyValues } = options ?? {}
let location = filtered?.[0]?.filter((v) => v.length > 0).join("@");
if (location === "Error") {
location = "webview::unknown";
let location = filtered?.[0]?.filter((v) => v.length > 0).join('@')
if (location === 'Error') {
location = 'webview::unknown'
}
await invoke("plugin:log|log", {
await invoke('plugin:log|log', {
level,
message,
location,
file,
line,
keyValues,
});
keyValues
})
}
/**
@@ -90,9 +90,9 @@ async function log(
*/
export async function error(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Error, message, options);
await log(LogLevel.Error, message, options)
}
/**
@@ -112,9 +112,9 @@ export async function error(
*/
export async function warn(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Warn, message, options);
await log(LogLevel.Warn, message, options)
}
/**
@@ -134,9 +134,9 @@ export async function warn(
*/
export async function info(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Info, message, options);
await log(LogLevel.Info, message, options)
}
/**
@@ -156,9 +156,9 @@ export async function info(
*/
export async function debug(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Debug, message, options);
await log(LogLevel.Debug, message, options)
}
/**
@@ -178,17 +178,17 @@ export async function debug(
*/
export async function trace(
message: string,
options?: LogOptions,
options?: LogOptions
): Promise<void> {
await log(LogLevel.Trace, message, options);
await log(LogLevel.Trace, message, options)
}
interface RecordPayload {
level: LogLevel;
message: string;
level: LogLevel
message: string
}
type LoggerFn = (fn: RecordPayload) => void;
type LoggerFn = (fn: RecordPayload) => void
/**
* Attaches a listener for the log, and calls the passed function for each log entry.
@@ -197,19 +197,19 @@ type LoggerFn = (fn: RecordPayload) => void;
* @returns a function to cancel the listener.
*/
export async function attachLogger(fn: LoggerFn): Promise<UnlistenFn> {
return await listen("log://log", (event: Event<RecordPayload>) => {
const { level } = event.payload;
let { message } = event.payload;
return await listen('log://log', (event: Event<RecordPayload>) => {
const { level } = event.payload
let { message } = event.payload
// Strip ANSI escape codes
message = message.replace(
// TODO: Investigate security/detect-unsafe-regex
// eslint-disable-next-line no-control-regex, security/detect-unsafe-regex
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
"",
);
fn({ message, level });
});
''
)
fn({ message, level })
})
}
/**
@@ -221,23 +221,23 @@ export async function attachConsole(): Promise<UnlistenFn> {
return await attachLogger(({ level, message }: RecordPayload) => {
switch (level) {
case LogLevel.Trace:
console.log(message);
break;
console.log(message)
break
case LogLevel.Debug:
console.debug(message);
break;
console.debug(message)
break
case LogLevel.Info:
console.info(message);
break;
console.info(message)
break
case LogLevel.Warn:
console.warn(message);
break;
console.warn(message)
break
case LogLevel.Error:
console.error(message);
break;
console.error(message)
break
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`unknown log level ${level}`);
throw new Error(`unknown log level ${level}`)
}
});
})
}
+2 -2
View File
@@ -2,6 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { createConfig } from "../../shared/rollup.config.js";
import { createConfig } from '../../shared/rollup.config.js'
export default createConfig();
export default createConfig()