From 4706b7042b258f4abe53f4f37318f9faf6a0d8a3 Mon Sep 17 00:00:00 2001 From: Matthew McEachen Date: Fri, 15 Nov 2024 12:04:15 -0800 Subject: [PATCH] Fix windows build - Updated the clean script to include node-gyp clean. - Added platform-specific volume mount point retrieval for Windows and macOS. - Modified GetVolumeMetadata function to accept options and updated its declaration. - Extracted UUID from volume metadata in the _getVolumeMetadata function. --- package.json | 4 ++-- src/binding.cpp | 20 ++++++++++++++++++++ src/index.ts | 6 +++++- src/windows/fs_meta.cpp | 3 +-- src/windows/fs_meta.h | 2 +- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index b5f5f04..9265bb5 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "license": "MIT", "scripts": { "install": "npm run build:gyp", - "clean": "rm -rf dist build", + "clean": "rm -rf dist build && node-gyp clean", "prebuild": "npm run clean", "build": "run-p build:*", "prebuild:gyp": "node scripts/configure.js", @@ -48,7 +48,7 @@ "pretest": "tsc -p tsconfig.test.json", "test": "run-s test:*", "test:jest": "jest", - "test:memory": "cross-env TEST_MEMORY=1 node --expose-gc ./node_modules/.bin/jest src/__tests__/memory.test.ts", + "test:memory": "cross-env TEST_MEMORY=1 node --expose-gc node_modules/jest/bin/jest.js src/__tests__/memory.test.ts", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "fmt": "run-p fmt:*", diff --git a/src/binding.cpp b/src/binding.cpp index db68f3a..0a436d5 100644 --- a/src/binding.cpp +++ b/src/binding.cpp @@ -1,6 +1,12 @@ #include #include +#if defined(_WIN32) +#include "windows/fs_meta.h" +#elif defined(__APPLE__) +#include "darwin/fs_meta.h" +#elif defined(__linux__) #include "linux/fs_meta.h" +#endif namespace { @@ -40,7 +46,21 @@ Napi::Value GetGioMountPoints(const Napi::CallbackInfo& info) { } #endif + +#if defined(_WIN32) || defined(__APPLE__) +Napi::Value GetVolumeMountPoints(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + return FSMeta::GetVolumeMountPoints(env); +} +#endif + Napi::Object Init(Napi::Env env, Napi::Object exports) { + +#if defined(_WIN32) || defined(__APPLE__) + exports.Set("getVolumeMountPoints", + Napi::Function::New(env, GetVolumeMountPoints)); +#endif + exports.Set("getVolumeMetadata", Napi::Function::New(env, GetVolumeMetadata)); diff --git a/src/index.ts b/src/index.ts index 4fd7d43..4af3c91 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,7 @@ import { import { FsOptions, options, TimeoutMsDefault } from "./options.js"; import { isLinux, isWindows } from "./platform.js"; import { isBlank } from "./string.js"; +import { extractUUID } from "./uuid.js"; import { VolumeMetadata } from "./volume_metadata.js"; export { @@ -131,5 +132,8 @@ async function _getVolumeMetadata( o, )) as VolumeMetadata; - return { ...metadata, ...remoteInfo }; + const result = { ...metadata, ...remoteInfo }; + result.uuid = extractUUID(result.uuid) ?? result.uuid; + + return result; } diff --git a/src/windows/fs_meta.cpp b/src/windows/fs_meta.cpp index 5081c63..65950e8 100644 --- a/src/windows/fs_meta.cpp +++ b/src/windows/fs_meta.cpp @@ -140,11 +140,10 @@ Napi::Value GetVolumeMountPoints(Napi::Env env) { return deferred.Promise(); } -Napi::Value GetVolumeMetadata(Napi::Env env, const std::string &mountPoint) { +Napi::Value GetVolumeMetadata(const Napi::Env& env, const std::string& mountPoint, const Napi::Object& options) { auto deferred = Napi::Promise::Deferred::New(env); auto *worker = new GetVolumeMetadataWorker(mountPoint, deferred); worker->Queue(); return deferred.Promise(); } - } // namespace FSMeta \ No newline at end of file diff --git a/src/windows/fs_meta.h b/src/windows/fs_meta.h index 3968534..6a0cecb 100644 --- a/src/windows/fs_meta.h +++ b/src/windows/fs_meta.h @@ -6,5 +6,5 @@ namespace FSMeta { Napi::Value GetVolumeMountPoints(Napi::Env env); -Napi::Value GetVolumeMetadata(Napi::Env env, const std::string &mountPoint); +Napi::Value GetVolumeMetadata(const Napi::Env& env, const std::string& path, const Napi::Object& options); } // namespace FSMeta \ No newline at end of file