From 2be45d61019d5ce6e160d62d0a3fceffea3af56d Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 25 Sep 2024 09:25:51 -0700 Subject: [PATCH] Simpler Tauri resource paths (#112) --- plugin-runtime/package.json | 4 ++-- scripts/.gitignore | 1 + scripts/vendor-node.cjs | 7 ++++--- scripts/vendor-protoc.cjs | 4 ++-- src-tauri/tauri.conf.json | 12 ++++++------ src-tauri/yaak_grpc/src/proto.rs | 2 +- src-tauri/yaak_plugin_runtime/src/manager.rs | 2 +- src-tauri/yaak_plugin_runtime/src/nodejs.rs | 2 +- 8 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 scripts/.gitignore diff --git a/plugin-runtime/package.json b/plugin-runtime/package.json index 535344a0..82a88937 100644 --- a/plugin-runtime/package.json +++ b/plugin-runtime/package.json @@ -2,8 +2,8 @@ "name": "@yaakapp-internal/plugin-runtime", "scripts": { "build": "run-p build:*", - "build:main": "esbuild src/index.ts --bundle --platform=node --outfile=build/index.cjs", - "build:worker": "esbuild src/index.worker.ts --bundle --platform=node --outfile=build/index.worker.cjs", + "build:main": "esbuild src/index.ts --bundle --platform=node --outfile=../src-tauri/vendored/plugin-runtime/index.cjs", + "build:worker": "esbuild src/index.worker.ts --bundle --platform=node --outfile=../src-tauri/vendored/plugin-runtime/index.worker.cjs", "build:proto": "grpc_tools_node_protoc --ts_proto_out=src/gen --ts_proto_opt=outputServices=nice-grpc,outputServices=generic-definitions,useExactTypes=false --proto_path=../proto ../proto/plugins/*.proto" }, "dependencies": { diff --git a/scripts/.gitignore b/scripts/.gitignore new file mode 100644 index 00000000..94a37de3 --- /dev/null +++ b/scripts/.gitignore @@ -0,0 +1 @@ +tmp-* diff --git a/scripts/vendor-node.cjs b/scripts/vendor-node.cjs index ef751a49..34939501 100644 --- a/scripts/vendor-node.cjs +++ b/scripts/vendor-node.cjs @@ -47,10 +47,11 @@ if (existsSync(binDest) && tryExecSync(`${binDest} --version`).trim() === NODE_V rmSync(destDir, { recursive: true, force: true }); mkdirSync(destDir, { recursive: true }); -(async function () { - const url = URL_MAP[key]; - const tmpDir = path.join(__dirname, 'tmp', Date.now().toString()); +const url = URL_MAP[key]; +const tmpDir = path.join(__dirname, 'tmp-node'); +rmSync(tmpDir, { recursive: true, force: true }); +(async function () { // Download GitHub release artifact const { filePath } = await new Downloader({ url, directory: tmpDir }).download(); diff --git a/scripts/vendor-protoc.cjs b/scripts/vendor-protoc.cjs index df1ca89f..ef626b36 100644 --- a/scripts/vendor-protoc.cjs +++ b/scripts/vendor-protoc.cjs @@ -38,7 +38,7 @@ const key = `${process.platform}_${process.env.YAAK_TARGET_ARCH ?? process.arch} console.log(`Vendoring protoc ${VERSION} for ${key}`); const url = URL_MAP[key]; -const tmpDir = path.join(__dirname, 'tmp', Date.now().toString()); +const tmpDir = path.join(__dirname, 'tmp-protoc'); const binSrc = path.join(tmpDir, SRC_BIN_MAP[key]); const binDst = path.join(dstDir, DST_BIN_MAP[key]); @@ -47,6 +47,7 @@ if (existsSync(binDst) && tryExecSync(`${binDst} --version`).trim().includes(VER return; } +rmSync(tmpDir, { recursive: true, force: true }); rmSync(dstDir, { recursive: true, force: true }); mkdirSync(dstDir, { recursive: true }); @@ -64,7 +65,6 @@ mkdirSync(dstDir, { recursive: true }); const includeSrc = path.join(tmpDir, 'include'); const includeDst = path.join(dstDir, 'include'); cpSync(includeSrc, includeDst, { recursive: true }); - rmSync(tmpDir, { recursive: true, force: true }); console.log('Downloaded protoc to', binDst); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 1c5cfc94..b24a79e5 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -56,12 +56,12 @@ "icons/release/icon.ico" ], "longDescription": "A cross-platform desktop app for interacting with REST, GraphQL, and gRPC", - "resources": { - "migrations": "migrations", - "vendored/protoc/include": "protoc-include", - "vendored/plugins": "plugins", - "../plugin-runtime/build": "plugin-runtime" - }, + "resources": [ + "migrations", + "vendored/protoc/include", + "vendored/plugins", + "vendored/plugin-runtime" + ], "shortDescription": "Play with APIs, intuitively", "targets": [ "app", diff --git a/src-tauri/yaak_grpc/src/proto.rs b/src-tauri/yaak_grpc/src/proto.rs index 3842f22f..b5dc9552 100644 --- a/src-tauri/yaak_grpc/src/proto.rs +++ b/src-tauri/yaak_grpc/src/proto.rs @@ -34,7 +34,7 @@ pub async fn fill_pool_from_files( let desc_path = temp_dir().join(random_file_name); let global_import_dir = app_handle .path() - .resolve("protoc-include", BaseDirectory::Resource) + .resolve("vendored/protoc/protoc-include", BaseDirectory::Resource) .expect("failed to resolve protoc include directory"); // HACK: Remove UNC prefix for Windows paths diff --git a/src-tauri/yaak_plugin_runtime/src/manager.rs b/src-tauri/yaak_plugin_runtime/src/manager.rs index 9559f7af..3b084e03 100644 --- a/src-tauri/yaak_plugin_runtime/src/manager.rs +++ b/src-tauri/yaak_plugin_runtime/src/manager.rs @@ -126,7 +126,7 @@ impl PluginManager { pub async fn list_plugin_dirs(&self, app_handle: &AppHandle) -> Vec { let plugins_dir = app_handle .path() - .resolve("plugins", BaseDirectory::Resource) + .resolve("vendored/plugins", BaseDirectory::Resource) .expect("failed to resolve plugin directory resource"); let bundled_plugin_dirs = read_plugins_dir(&plugins_dir) diff --git a/src-tauri/yaak_plugin_runtime/src/nodejs.rs b/src-tauri/yaak_plugin_runtime/src/nodejs.rs index 4c9a3488..8d8a9cc2 100644 --- a/src-tauri/yaak_plugin_runtime/src/nodejs.rs +++ b/src-tauri/yaak_plugin_runtime/src/nodejs.rs @@ -22,7 +22,7 @@ pub async fn start_nodejs_plugin_runtime( ) -> Result<()> { let plugin_runtime_main = app .path() - .resolve("plugin-runtime", BaseDirectory::Resource)? + .resolve("vendored/plugin-runtime", BaseDirectory::Resource)? .join("index.cjs"); // HACK: Remove UNC prefix for Windows paths to pass to sidecar