aneka 0.15.0 → 0.16.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.
package/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-07-01
4
+
5
+ - [0.16.0] Add ```getGlobalModuleDir()```
6
+
3
7
  ## 2026-06-24
4
8
 
5
9
  - [0.15.0] Add documentations & tests
package/index.js CHANGED
@@ -32,6 +32,7 @@ import parseKvString from './src/parse-kv-string.js'
32
32
  import without from './src/without.js'
33
33
  import textToArray from './src/text-to-array.js'
34
34
  import getCallerFilename from './src/get-caller-filename.js'
35
+ import getGlobalModuleDir from './src/get-global-module-dir.js'
35
36
 
36
37
  export {
37
38
  arrangeArray,
@@ -45,6 +46,7 @@ export {
45
46
  filterIndex,
46
47
  generateId,
47
48
  getCallerFilename,
49
+ getGlobalModuleDir,
48
50
  getIndex,
49
51
  getKeyByValue,
50
52
  includes,
@@ -83,6 +85,7 @@ export default {
83
85
  filterIndex,
84
86
  generateId,
85
87
  getCallerFilename,
88
+ getGlobalModuleDir,
86
89
  getIndex,
87
90
  getKeyByValue,
88
91
  includes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Some usefull function helper for daily use",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,20 @@
1
+ import path from 'path'
2
+ import resolvePath from './resolve-path.js'
3
+
4
+ /**
5
+ * Get the node global module directory.
6
+ *
7
+ * @returns {string} Absolute path to the global module directory
8
+ */
9
+ function getGlobalModuleDir () {
10
+ const execDir = path.dirname(process.execPath)
11
+ if (process.platform === 'win32') {
12
+ const appDataPath = process.env.APPDATA
13
+ ? path.join(process.env.APPDATA, 'npm', 'node_modules')
14
+ : null
15
+ return resolvePath(appDataPath || path.join(execDir, 'node_modules'))
16
+ }
17
+ return resolvePath(path.join(execDir, '..', 'lib', 'node_modules'))
18
+ }
19
+
20
+ export default getGlobalModuleDir
@@ -0,0 +1,51 @@
1
+ /* eslint-env mocha */
2
+ import { expect } from 'chai'
3
+ import path from 'path'
4
+ import fn from '../src/get-global-module-dir.js'
5
+
6
+ const originalPlatformDesc = Object.getOwnPropertyDescriptor(process, 'platform')
7
+ const originalExecPathDesc = Object.getOwnPropertyDescriptor(process, 'execPath')
8
+ const originalAppData = process.env.APPDATA
9
+
10
+ function setProcessProp (name, value) {
11
+ Object.defineProperty(process, name, {
12
+ value,
13
+ configurable: true
14
+ })
15
+ }
16
+
17
+ describe('getGlobalModuleDir', function () {
18
+ afterEach(function () {
19
+ if (originalPlatformDesc) Object.defineProperty(process, 'platform', originalPlatformDesc)
20
+ if (originalExecPathDesc) Object.defineProperty(process, 'execPath', originalExecPathDesc)
21
+
22
+ if (originalAppData === undefined) delete process.env.APPDATA
23
+ else process.env.APPDATA = originalAppData
24
+ })
25
+
26
+ it('returns lib/node_modules for non-win32 platforms', function () {
27
+ setProcessProp('platform', 'linux')
28
+ setProcessProp('execPath', '/opt/node/bin/node')
29
+
30
+ const result = fn()
31
+ expect(result).to.equal(path.resolve('/opt/node/lib/node_modules'))
32
+ })
33
+
34
+ it('uses APPDATA on win32 when provided', function () {
35
+ setProcessProp('platform', 'win32')
36
+ setProcessProp('execPath', '/Program Files/nodejs/node.exe')
37
+ process.env.APPDATA = '/Users/test/AppData/Roaming'
38
+
39
+ const result = fn()
40
+ expect(result).to.equal(path.resolve('/Users/test/AppData/Roaming/npm/node_modules'))
41
+ })
42
+
43
+ it('falls back to exec directory on win32 when APPDATA is missing', function () {
44
+ setProcessProp('platform', 'win32')
45
+ setProcessProp('execPath', '/Program Files/nodejs/node.exe')
46
+ delete process.env.APPDATA
47
+
48
+ const result = fn()
49
+ expect(result).to.equal(path.resolve('/Program Files/nodejs/node_modules'))
50
+ })
51
+ })