Skip to content

Commit

Permalink
Fix windows build
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
mceachen committed Nov 15, 2024
1 parent b8cb0ad commit 4706b70
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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:*",
Expand Down
20 changes: 20 additions & 0 deletions src/binding.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <napi.h>
#include <string>
#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 {

Expand Down Expand Up @@ -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));

Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
3 changes: 1 addition & 2 deletions src/windows/fs_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/windows/fs_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4706b70

Please sign in to comment.