@photostructure/fs-metadata 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/C++_REVIEW_TODO.md +1 -1
  2. package/CHANGELOG.md +11 -1
  3. package/CLAUDE.md +30 -23
  4. package/CONTRIBUTING.md +41 -0
  5. package/binding.gyp +2 -1
  6. package/dist/index.cjs +1439 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +360 -0
  9. package/dist/index.d.mts +360 -0
  10. package/dist/index.d.ts +360 -0
  11. package/dist/index.mjs +1397 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/package.json +19 -22
  14. package/prebuilds/darwin-arm64/@photostructure+fs-metadata.glibc.node +0 -0
  15. package/prebuilds/linux-arm64/@photostructure+fs-metadata.musl.node +0 -0
  16. package/prebuilds/linux-x64/@photostructure+fs-metadata.glibc.node +0 -0
  17. package/prebuilds/linux-x64/@photostructure+fs-metadata.musl.node +0 -0
  18. package/prebuilds/win32-x64/@photostructure+fs-metadata.glibc.node +0 -0
  19. package/scripts/check-memory.mjs +53 -173
  20. package/scripts/clang-tidy.mjs +1 -1
  21. package/scripts/sanitizers-test.sh +151 -0
  22. package/scripts/valgrind-test.mjs +1 -1
  23. package/scripts/{valgrind.sh → valgrind-test.sh} +15 -0
  24. package/src/common/error_utils.h +23 -0
  25. package/src/common/metadata_worker.h +4 -1
  26. package/src/darwin/hidden.cpp +13 -6
  27. package/src/darwin/volume_metadata.cpp +2 -2
  28. package/src/darwin/volume_mount_points.cpp +8 -1
  29. package/src/linux/blkid_cache.cpp +8 -2
  30. package/src/linux/volume_metadata.cpp +1 -1
  31. package/src/test-utils/worker-thread-helper.cjs +88 -0
  32. package/src/windows/hidden.cpp +20 -11
  33. package/coverage/base.css +0 -224
  34. package/coverage/block-navigation.js +0 -87
  35. package/coverage/favicon.png +0 -0
  36. package/coverage/index.html +0 -131
  37. package/coverage/lcov-report/base.css +0 -224
  38. package/coverage/lcov-report/block-navigation.js +0 -87
  39. package/coverage/lcov-report/favicon.png +0 -0
  40. package/coverage/lcov-report/index.html +0 -131
  41. package/coverage/lcov-report/prettify.css +0 -1
  42. package/coverage/lcov-report/prettify.js +0 -2
  43. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  44. package/coverage/lcov-report/sorter.js +0 -196
  45. package/coverage/lcov-report/src/array.ts.html +0 -217
  46. package/coverage/lcov-report/src/async.ts.html +0 -547
  47. package/coverage/lcov-report/src/debuglog.ts.html +0 -187
  48. package/coverage/lcov-report/src/defer.ts.html +0 -175
  49. package/coverage/lcov-report/src/dirname.ts.html +0 -124
  50. package/coverage/lcov-report/src/error.ts.html +0 -322
  51. package/coverage/lcov-report/src/fs.ts.html +0 -316
  52. package/coverage/lcov-report/src/glob.ts.html +0 -472
  53. package/coverage/lcov-report/src/hidden.ts.html +0 -724
  54. package/coverage/lcov-report/src/index.html +0 -521
  55. package/coverage/lcov-report/src/index.ts.html +0 -676
  56. package/coverage/lcov-report/src/linux/dev_disk.ts.html +0 -316
  57. package/coverage/lcov-report/src/linux/index.html +0 -146
  58. package/coverage/lcov-report/src/linux/mount_points.ts.html +0 -364
  59. package/coverage/lcov-report/src/linux/mtab.ts.html +0 -493
  60. package/coverage/lcov-report/src/mount_point.ts.html +0 -106
  61. package/coverage/lcov-report/src/number.ts.html +0 -148
  62. package/coverage/lcov-report/src/object.ts.html +0 -265
  63. package/coverage/lcov-report/src/options.ts.html +0 -475
  64. package/coverage/lcov-report/src/path.ts.html +0 -268
  65. package/coverage/lcov-report/src/platform.ts.html +0 -112
  66. package/coverage/lcov-report/src/random.ts.html +0 -205
  67. package/coverage/lcov-report/src/remote_info.ts.html +0 -553
  68. package/coverage/lcov-report/src/stack_path.ts.html +0 -298
  69. package/coverage/lcov-report/src/string.ts.html +0 -382
  70. package/coverage/lcov-report/src/string_enum.ts.html +0 -208
  71. package/coverage/lcov-report/src/system_volume.ts.html +0 -301
  72. package/coverage/lcov-report/src/unc.ts.html +0 -274
  73. package/coverage/lcov-report/src/units.ts.html +0 -274
  74. package/coverage/lcov-report/src/uuid.ts.html +0 -157
  75. package/coverage/lcov-report/src/volume_health_status.ts.html +0 -259
  76. package/coverage/lcov-report/src/volume_metadata.ts.html +0 -787
  77. package/coverage/lcov-report/src/volume_mount_points.ts.html +0 -388
  78. package/coverage/lcov.info +0 -3581
  79. package/coverage/prettify.css +0 -1
  80. package/coverage/prettify.js +0 -2
  81. package/coverage/sort-arrow-sprite.png +0 -0
  82. package/coverage/sorter.js +0 -196
  83. package/coverage/src/array.ts.html +0 -217
  84. package/coverage/src/async.ts.html +0 -547
  85. package/coverage/src/debuglog.ts.html +0 -187
  86. package/coverage/src/defer.ts.html +0 -175
  87. package/coverage/src/dirname.ts.html +0 -124
  88. package/coverage/src/error.ts.html +0 -322
  89. package/coverage/src/fs.ts.html +0 -316
  90. package/coverage/src/glob.ts.html +0 -472
  91. package/coverage/src/hidden.ts.html +0 -724
  92. package/coverage/src/index.html +0 -521
  93. package/coverage/src/index.ts.html +0 -676
  94. package/coverage/src/linux/dev_disk.ts.html +0 -316
  95. package/coverage/src/linux/index.html +0 -146
  96. package/coverage/src/linux/mount_points.ts.html +0 -364
  97. package/coverage/src/linux/mtab.ts.html +0 -493
  98. package/coverage/src/mount_point.ts.html +0 -106
  99. package/coverage/src/number.ts.html +0 -148
  100. package/coverage/src/object.ts.html +0 -265
  101. package/coverage/src/options.ts.html +0 -475
  102. package/coverage/src/path.ts.html +0 -268
  103. package/coverage/src/platform.ts.html +0 -112
  104. package/coverage/src/random.ts.html +0 -205
  105. package/coverage/src/remote_info.ts.html +0 -553
  106. package/coverage/src/stack_path.ts.html +0 -298
  107. package/coverage/src/string.ts.html +0 -382
  108. package/coverage/src/string_enum.ts.html +0 -208
  109. package/coverage/src/system_volume.ts.html +0 -301
  110. package/coverage/src/unc.ts.html +0 -274
  111. package/coverage/src/units.ts.html +0 -274
  112. package/coverage/src/uuid.ts.html +0 -157
  113. package/coverage/src/volume_health_status.ts.html +0 -259
  114. package/coverage/src/volume_metadata.ts.html +0 -787
  115. package/coverage/src/volume_mount_points.ts.html +0 -388
  116. package/scripts/run-asan.sh +0 -92
@@ -243,7 +243,7 @@ This document outlines a comprehensive review of all C++ files in the fs-metadat
243
243
  3. **Memory Testing Infrastructure**
244
244
  - Created comprehensive memory testing documentation (`docs/MEMORY_TESTING.md`)
245
245
  - Improved ASan configuration with proper suppressions
246
- - Created standalone test runner (`scripts/run-asan.sh`)
246
+ - Created standalone test runner (`scripts/sanitizers-test.sh`)
247
247
  - Updated `scripts/check-memory.mjs` with better ASan support
248
248
  - All memory tests integrated into CI/CD
249
249
 
package/CHANGELOG.md CHANGED
@@ -14,7 +14,7 @@ Fixed for any bug fixes.
14
14
  Security in case of vulnerabilities.
15
15
  -->
16
16
 
17
- ## [0.5.0] - 2025-06-01
17
+ ## [0.6.0] - 2025-06-03
18
18
 
19
19
  ### Added
20
20
 
@@ -22,6 +22,8 @@ Security in case of vulnerabilities.
22
22
  - Thread safety tests for Windows platform
23
23
  - Platform-specific build scripts with automatic OS detection
24
24
  - Clang-tidy integration for C++ code analysis
25
+ - Worker thread helper for volume metadata operations
26
+ - NAPI_VERSION=9 definition for improved compatibility
25
27
 
26
28
  ### Breaking
27
29
 
@@ -32,6 +34,8 @@ Security in case of vulnerabilities.
32
34
  - Simplified ESM/CJS dual module support with unified build configuration
33
35
  - Enhanced test coverage with additional error handling and edge case tests
34
36
  - Updated all imports to use `node:` prefix for built-in modules
37
+ - Reorganized build and test scripts for better clarity
38
+ - Improved memory test workflow for cross-platform compatibility
35
39
 
36
40
  ### Fixed
37
41
 
@@ -41,6 +45,12 @@ Security in case of vulnerabilities.
41
45
  - Enhanced resource management with better validation for empty mount points
42
46
  - Made `SystemPathPatternsDefault` values visible in TypeScript typings
43
47
  - Improved test reliability across different CI environments
48
+ - Added Napi::HandleScope to OnOK and OnError methods for proper scope management
49
+ - Removed unnecessary std::move operations in worker implementations
50
+ - Updated filesystem metadata tests to verify type and existence instead of specific values
51
+ - Improved error handling and messages in various components
52
+ - Enhanced error message validation for file access in worker thread tests
53
+ - Updated tests to use healthy mount points for volume metadata retrieval
44
54
 
45
55
  ## [0.4.0] - 2025-01-09
46
56
 
package/CLAUDE.md CHANGED
@@ -15,6 +15,7 @@ This is @photostructure/fs-metadata - a cross-platform native Node.js module for
15
15
  - Timeout handling for unresponsive network volumes
16
16
  - ESM and CJS module support
17
17
  - Full TypeScript type definitions
18
+ - Worker threads support with proper context isolation
18
19
 
19
20
  ### Platform-Specific Notes
20
21
  - **Linux**: Optional GIO/GVfs mount support via Gnome libraries
@@ -29,7 +30,7 @@ This is @photostructure/fs-metadata - a cross-platform native Node.js module for
29
30
  npm install
30
31
 
31
32
  # Configure platform-specific build settings
32
- npm run configure
33
+ npm run configure:native
33
34
 
34
35
  # Build native bindings
35
36
  npm run node-gyp-rebuild
@@ -37,32 +38,32 @@ npm run node-gyp-rebuild
37
38
  # Create prebuilds for distribution
38
39
  npm run prebuild
39
40
 
40
- # Bundle TypeScript to dist/
41
- npm run bundle
41
+ # Assemble TypeScript to dist/
42
+ npm run build:dist
42
43
  ```
43
44
 
44
45
  ### Testing
45
46
  ```bash
46
47
  # Run all tests with coverage (includes memory tests on Linux)
47
- npm run tests
48
+ npm run test:all
48
49
 
49
50
  # Run CommonJS tests
50
- npm test cjs
51
+ npm test:cjs
51
52
 
52
53
  # Run ESM tests
53
- npm test esm
54
+ npm test:esm
54
55
 
55
56
  # Test memory leaks (JavaScript)
56
57
  npm run test:memory
57
58
 
58
59
  # Run valgrind memory analysis (Linux only)
59
- npm run test:valgrind
60
+ bash scripts/valgrind-test.sh
60
61
 
61
- # Run comprehensive memory tests (JavaScript + valgrind on Linux)
62
- npm run tests:memory
62
+ # Run AddressSanitizer and LeakSanitizer (Linux only)
63
+ bash scripts/sanitizers-test.sh
63
64
 
64
- # Run AddressSanitizer tests (Linux only)
65
- npm run asan
65
+ # Run comprehensive memory tests (JavaScript + valgrind + sanitizers)
66
+ npm run test:memory
66
67
 
67
68
  # Run a specific test file (no coverage)
68
69
  npm test volume_metadata
@@ -86,7 +87,7 @@ npm run fmt:cpp
86
87
  npm run fmt:ts
87
88
 
88
89
  # Type checking
89
- npm run compile
90
+ npm run build:ts
90
91
  ```
91
92
 
92
93
  ### Pre-commit
@@ -122,23 +123,29 @@ npm run docs
122
123
  - Provides prebuilt binaries via `prebuildify` for common platforms
123
124
  - Supports both ESM and CJS module formats
124
125
 
126
+ ### Cross-Module Compatibility
127
+ - **Directory Path Resolution**: Use `_dirname()` from `./dirname` instead of `__dirname`
128
+ - Works in both CommonJS and ESM contexts
129
+ - Handles Jest test environments correctly
130
+ - Example: `const dir = _dirname()` instead of `const dir = __dirname`
131
+
125
132
  ### Testing Strategy
126
133
  - Jest for both CJS and ESM test suites
127
134
  - Platform-specific test expectations handled via `isWindows`, `isMacOS`, `isLinux` helpers
128
135
  - Memory leak testing with garbage collection monitoring
129
136
  - Coverage thresholds: 80% for all metrics
130
137
 
131
- ### Memory Testing
132
- - JavaScript memory tests: `npm run test:memory` - uses GC and heap monitoring
133
- - Valgrind integration: `npm run test:valgrind` - runs on Linux only, checks for memory leaks
134
- - AddressSanitizer: `npm run asan` - runs on Linux only, detects memory errors and leaks (~2x faster than Valgrind)
135
- - Comprehensive memory tests: `npm run tests:memory` - runs all memory tests appropriate for the platform
136
- - Automated test runners: `scripts/valgrind-test.mjs` and `scripts/run-asan.sh`
137
- - CI/CD includes both valgrind and ASAN tests via `.github/workflows/memory-tests.yml`
138
- - Cross-platform memory check script: `scripts/check-memory.mjs` handles platform differences
139
- - Suppression files: `.valgrind.supp` (Valgrind), `.lsan-suppressions.txt` (LeakSanitizer)
140
- - Memory tests are integrated into `npm run tests` pipeline on Linux
141
- - See `docs/MEMORY_TESTING.md` for detailed memory testing guide
138
+ ### Testing File System Metadata
139
+ - **Important**: File system metadata like `available` space, `used` space, and other dynamic properties change continuously as other processes run on the machine
140
+ - Tests should **never** expect exact equality for these values between multiple calls
141
+ - **Do not** make range assertions (e.g., `available > 0` or `used < size`) because:
142
+ - Files can be created or deleted between calls (potentially gigabytes)
143
+ - The changes can be dramatic and unpredictable
144
+ - Instead, for dynamic metadata:
145
+ - Only verify the value exists and has the correct type
146
+ - Use `typeof result.available === 'number'` rather than range checks
147
+ - Focus on testing static properties (e.g., `size`, `mountFrom`, `fstype`) for exact equality
148
+ - Consider using snapshot testing only for stable properties
142
149
 
143
150
  ### Timeout Handling
144
151
  - Default timeout for volume operations to handle unresponsive network mounts
package/CONTRIBUTING.md CHANGED
@@ -54,18 +54,59 @@ into account both Windows and POSIX systems.
54
54
  **Why**: Windows Command Prompt/PowerShell parses the entire command line before execution, including the Unix-specific parts that would never run on Windows. Even though constructs like `node scripts/is-platform.mjs win32 || <unix-command>` would exit early on Windows, the shell still tries to parse the syntax after `||`.
55
55
 
56
56
  **Solution**: For platform-specific npm scripts that use shell operators:
57
+
57
58
  - Create a wrapper Node.js script that handles platform detection internally (see `scripts/clang-tidy.mjs`)
58
59
  - The wrapper can use `process.platform` or `os.platform()` to detect Windows and exit early
59
60
  - Unix-specific commands can then be spawned using `child_process.spawn()` with `sh -c`
60
61
 
61
62
  **Example**: The `clang-tidy` npm script was moved from:
63
+
62
64
  ```json
63
65
  "clang-tidy": "node scripts/is-platform.mjs win32 || (npm run configure && bear -- npm run node-gyp-rebuild && find src -name '*.cpp' -o -name '*.h' | grep -E '\\.(cpp|h)$' | grep -v -E '(windows|darwin)/' | xargs clang-tidy)"
64
66
  ```
65
67
 
66
68
  To:
69
+
67
70
  ```json
68
71
  "clang-tidy": "node scripts/clang-tidy.mjs"
69
72
  ```
70
73
 
71
74
  Where the script handles platform detection and command execution internally.
75
+
76
+ ## npm Script Naming Conventions
77
+
78
+ This project follows consistent naming patterns for npm scripts to improve discoverability and maintainability:
79
+
80
+ ### Action:Target Format
81
+
82
+ Scripts follow an `action:target` pattern where:
83
+
84
+ - **action**: The operation being performed (`build`, `clean`, `lint`, `test`)
85
+ - **target**: What the action operates on (`native`, `ts`, `dist`)
86
+
87
+ Examples:
88
+
89
+ - `build:native` - Build native C++ code
90
+ - `lint:ts` - Lint TypeScript code
91
+ - `clean:dist` - Clean distribution files
92
+
93
+ ### Parallel Execution
94
+
95
+ Actions that have multiple targets can be run in parallel using wildcards:
96
+
97
+ - `npm run clean` runs all `clean:*` scripts
98
+ - `npm run lint` runs all `lint:*` scripts
99
+ - Uses `run-p` from npm-run-all for parallel execution
100
+
101
+ ### Special Namespaces
102
+
103
+ - **memory:\*** - Memory testing scripts that should not run automatically with `test:*`
104
+ - `memory:test` - Comprehensive memory testing suite
105
+ - Run with `ENABLE_ASAN=1` to include sanitizer tests
106
+
107
+ ### Naming Guidelines
108
+
109
+ - Use explicit names to avoid ambiguity (e.g., `configure:native` instead of just `configure`)
110
+ - Group related scripts by action prefix for easy wildcard execution
111
+ - Avoid names that could cause npm lifecycle conflicts (e.g., `prebuild` vs `build`)
112
+ - Use descriptive suffixes that clearly indicate the target or purpose
package/binding.gyp CHANGED
@@ -16,7 +16,8 @@
16
16
  "<!(node -p \"require('node-addon-api').gyp\")"
17
17
  ],
18
18
  "defines": [
19
- "NAPI_CPP_EXCEPTIONS"
19
+ "NAPI_CPP_EXCEPTIONS",
20
+ "NAPI_VERSION=9"
20
21
  ],
21
22
  "conditions": [
22
23
  [