node-datachannel 0.2.2 → 0.3.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 (130) hide show
  1. package/.editorconfig +12 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.js +8 -0
  4. package/.github/FUNDING.yml +2 -0
  5. package/.github/workflows/build-linux.yml +5 -3
  6. package/.github/workflows/build-mac.yml +1 -1
  7. package/.github/workflows/build-win.yml +4 -10
  8. package/.prettierrc.js +7 -0
  9. package/CMakeLists.txt +8 -2
  10. package/README.md +4 -4
  11. package/lib/datachannel-stream.js +97 -0
  12. package/lib/index.d.ts +60 -53
  13. package/lib/index.js +5 -2
  14. package/node_modules/decompress-response/index.d.ts +14 -21
  15. package/node_modules/decompress-response/index.js +34 -16
  16. package/node_modules/decompress-response/license +1 -1
  17. package/node_modules/decompress-response/package.json +23 -17
  18. package/node_modules/decompress-response/readme.md +2 -6
  19. package/node_modules/detect-libc/README.md +124 -42
  20. package/node_modules/detect-libc/index.d.ts +11 -0
  21. package/node_modules/detect-libc/lib/detect-libc.js +166 -80
  22. package/node_modules/detect-libc/lib/process.js +16 -0
  23. package/node_modules/detect-libc/package.json +20 -19
  24. package/node_modules/{semver → lru-cache}/LICENSE +0 -0
  25. package/node_modules/lru-cache/README.md +166 -0
  26. package/node_modules/lru-cache/index.js +334 -0
  27. package/node_modules/lru-cache/node_modules/yallist/LICENSE +15 -0
  28. package/node_modules/lru-cache/node_modules/yallist/README.md +204 -0
  29. package/node_modules/lru-cache/node_modules/yallist/iterator.js +8 -0
  30. package/node_modules/lru-cache/node_modules/yallist/package.json +65 -0
  31. package/node_modules/lru-cache/node_modules/yallist/yallist.js +426 -0
  32. package/node_modules/lru-cache/package.json +75 -0
  33. package/node_modules/mimic-response/index.d.ts +2 -2
  34. package/node_modules/mimic-response/index.js +41 -2
  35. package/node_modules/mimic-response/package.json +17 -17
  36. package/node_modules/mimic-response/readme.md +22 -1
  37. package/node_modules/minimist/index.js +6 -2
  38. package/node_modules/minimist/package.json +10 -10
  39. package/node_modules/minimist/readme.markdown +4 -1
  40. package/node_modules/minimist/test/proto.js +16 -0
  41. package/node_modules/node-abi/.circleci/config.yml +63 -0
  42. package/node_modules/node-abi/.releaserc.json +9 -0
  43. package/node_modules/node-abi/abi_registry.json +45 -3
  44. package/node_modules/node-abi/index.js +5 -2
  45. package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +111 -0
  46. package/node_modules/node-abi/node_modules/semver/LICENSE +15 -0
  47. package/node_modules/{semver → node-abi/node_modules/semver}/README.md +180 -26
  48. package/node_modules/node-abi/node_modules/semver/bin/semver.js +173 -0
  49. package/node_modules/node-abi/node_modules/semver/classes/comparator.js +135 -0
  50. package/node_modules/node-abi/node_modules/semver/classes/index.js +5 -0
  51. package/node_modules/node-abi/node_modules/semver/classes/range.js +510 -0
  52. package/node_modules/node-abi/node_modules/semver/classes/semver.js +287 -0
  53. package/node_modules/node-abi/node_modules/semver/functions/clean.js +6 -0
  54. package/node_modules/node-abi/node_modules/semver/functions/cmp.js +48 -0
  55. package/node_modules/node-abi/node_modules/semver/functions/coerce.js +51 -0
  56. package/node_modules/node-abi/node_modules/semver/functions/compare-build.js +7 -0
  57. package/node_modules/node-abi/node_modules/semver/functions/compare-loose.js +3 -0
  58. package/node_modules/node-abi/node_modules/semver/functions/compare.js +5 -0
  59. package/node_modules/node-abi/node_modules/semver/functions/diff.js +23 -0
  60. package/node_modules/node-abi/node_modules/semver/functions/eq.js +3 -0
  61. package/node_modules/node-abi/node_modules/semver/functions/gt.js +3 -0
  62. package/node_modules/node-abi/node_modules/semver/functions/gte.js +3 -0
  63. package/node_modules/node-abi/node_modules/semver/functions/inc.js +15 -0
  64. package/node_modules/node-abi/node_modules/semver/functions/lt.js +3 -0
  65. package/node_modules/node-abi/node_modules/semver/functions/lte.js +3 -0
  66. package/node_modules/node-abi/node_modules/semver/functions/major.js +3 -0
  67. package/node_modules/node-abi/node_modules/semver/functions/minor.js +3 -0
  68. package/node_modules/node-abi/node_modules/semver/functions/neq.js +3 -0
  69. package/node_modules/node-abi/node_modules/semver/functions/parse.js +33 -0
  70. package/node_modules/node-abi/node_modules/semver/functions/patch.js +3 -0
  71. package/node_modules/node-abi/node_modules/semver/functions/prerelease.js +6 -0
  72. package/node_modules/node-abi/node_modules/semver/functions/rcompare.js +3 -0
  73. package/node_modules/node-abi/node_modules/semver/functions/rsort.js +3 -0
  74. package/node_modules/node-abi/node_modules/semver/functions/satisfies.js +10 -0
  75. package/node_modules/node-abi/node_modules/semver/functions/sort.js +3 -0
  76. package/node_modules/node-abi/node_modules/semver/functions/valid.js +6 -0
  77. package/node_modules/node-abi/node_modules/semver/index.js +48 -0
  78. package/node_modules/node-abi/node_modules/semver/internal/constants.js +17 -0
  79. package/node_modules/node-abi/node_modules/semver/internal/debug.js +9 -0
  80. package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +23 -0
  81. package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +11 -0
  82. package/node_modules/node-abi/node_modules/semver/internal/re.js +182 -0
  83. package/node_modules/{semver → node-abi/node_modules/semver}/package.json +32 -23
  84. package/node_modules/node-abi/node_modules/semver/preload.js +2 -0
  85. package/node_modules/{semver → node-abi/node_modules/semver}/range.bnf +0 -0
  86. package/node_modules/node-abi/node_modules/semver/ranges/gtr.js +4 -0
  87. package/node_modules/node-abi/node_modules/semver/ranges/intersects.js +7 -0
  88. package/node_modules/node-abi/node_modules/semver/ranges/ltr.js +4 -0
  89. package/node_modules/node-abi/node_modules/semver/ranges/max-satisfying.js +25 -0
  90. package/node_modules/node-abi/node_modules/semver/ranges/min-satisfying.js +24 -0
  91. package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +60 -0
  92. package/node_modules/node-abi/node_modules/semver/ranges/outside.js +80 -0
  93. package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +44 -0
  94. package/node_modules/node-abi/node_modules/semver/ranges/subset.js +222 -0
  95. package/node_modules/node-abi/node_modules/semver/ranges/to-comparators.js +8 -0
  96. package/node_modules/node-abi/node_modules/semver/ranges/valid.js +11 -0
  97. package/node_modules/node-abi/package.json +21 -17
  98. package/node_modules/node-abi/test/index.js +7 -15
  99. package/node_modules/prebuild-install/CHANGELOG.md +24 -7
  100. package/node_modules/prebuild-install/README.md +24 -4
  101. package/node_modules/prebuild-install/asset.js +10 -10
  102. package/node_modules/prebuild-install/bin.js +13 -13
  103. package/node_modules/prebuild-install/download.js +22 -22
  104. package/node_modules/prebuild-install/log.js +4 -4
  105. package/node_modules/prebuild-install/package.json +18 -19
  106. package/node_modules/prebuild-install/proxy.js +10 -10
  107. package/node_modules/prebuild-install/rc.js +12 -12
  108. package/node_modules/prebuild-install/util.js +14 -14
  109. package/node_modules/simple-get/.github/dependabot.yml +15 -0
  110. package/node_modules/simple-get/.github/workflows/ci.yml +23 -0
  111. package/node_modules/simple-get/README.md +17 -3
  112. package/node_modules/simple-get/index.js +9 -0
  113. package/node_modules/simple-get/package.json +27 -13
  114. package/package.json +15 -6
  115. package/src/data-channel-wrapper.cpp +56 -22
  116. package/src/data-channel-wrapper.h +3 -0
  117. package/src/media-audio-wrapper.cpp +7 -7
  118. package/src/media-track-wrapper.cpp +40 -21
  119. package/src/media-track-wrapper.h +2 -0
  120. package/src/media-video-wrapper.cpp +5 -5
  121. package/src/peer-connection-wrapper.cpp +48 -27
  122. package/src/peer-connection-wrapper.h +2 -0
  123. package/test/connectivity.js +6 -6
  124. package/test/test.js +46 -1
  125. package/node_modules/detect-libc/.npmignore +0 -7
  126. package/node_modules/detect-libc/bin/detect-libc.js +0 -18
  127. package/node_modules/node-abi/.travis.yml +0 -17
  128. package/node_modules/semver/CHANGELOG.md +0 -39
  129. package/node_modules/semver/bin/semver +0 -160
  130. package/node_modules/semver/semver.js +0 -1483
@@ -1,59 +1,60 @@
1
1
  {
2
2
  "_args": [
3
3
  [
4
- "decompress-response@4.2.1",
4
+ "decompress-response@6.0.0",
5
5
  "/home/runner/work/node-datachannel/node-datachannel"
6
6
  ]
7
7
  ],
8
- "_from": "decompress-response@4.2.1",
9
- "_id": "decompress-response@4.2.1",
8
+ "_from": "decompress-response@6.0.0",
9
+ "_id": "decompress-response@6.0.0",
10
10
  "_inBundle": false,
11
- "_integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==",
11
+ "_integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==",
12
12
  "_location": "/decompress-response",
13
13
  "_phantomChildren": {},
14
14
  "_requested": {
15
15
  "type": "version",
16
16
  "registry": true,
17
- "raw": "decompress-response@4.2.1",
17
+ "raw": "decompress-response@6.0.0",
18
18
  "name": "decompress-response",
19
19
  "escapedName": "decompress-response",
20
- "rawSpec": "4.2.1",
20
+ "rawSpec": "6.0.0",
21
21
  "saveSpec": null,
22
- "fetchSpec": "4.2.1"
22
+ "fetchSpec": "6.0.0"
23
23
  },
24
24
  "_requiredBy": [
25
25
  "/simple-get"
26
26
  ],
27
- "_resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz",
28
- "_spec": "4.2.1",
27
+ "_resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz",
28
+ "_spec": "6.0.0",
29
29
  "_where": "/home/runner/work/node-datachannel/node-datachannel",
30
30
  "author": {
31
31
  "name": "Sindre Sorhus",
32
32
  "email": "sindresorhus@gmail.com",
33
- "url": "sindresorhus.com"
33
+ "url": "https://sindresorhus.com"
34
34
  },
35
35
  "bugs": {
36
36
  "url": "https://github.com/sindresorhus/decompress-response/issues"
37
37
  },
38
38
  "dependencies": {
39
- "mimic-response": "^2.0.0"
39
+ "mimic-response": "^3.1.0"
40
40
  },
41
41
  "description": "Decompress a HTTP response if needed",
42
42
  "devDependencies": {
43
- "@types/node": "^12.7.1",
43
+ "@types/node": "^14.0.1",
44
44
  "ava": "^2.2.0",
45
45
  "get-stream": "^5.0.0",
46
- "pify": "^4.0.1",
47
- "tsd": "^0.7.1",
48
- "xo": "^0.24.0"
46
+ "pify": "^5.0.0",
47
+ "tsd": "^0.11.0",
48
+ "xo": "^0.30.0"
49
49
  },
50
50
  "engines": {
51
- "node": ">=8"
51
+ "node": ">=10"
52
52
  },
53
53
  "files": [
54
54
  "index.js",
55
55
  "index.d.ts"
56
56
  ],
57
+ "funding": "https://github.com/sponsors/sindresorhus",
57
58
  "homepage": "https://github.com/sindresorhus/decompress-response#readme",
58
59
  "keywords": [
59
60
  "decompress",
@@ -81,5 +82,10 @@
81
82
  "scripts": {
82
83
  "test": "xo && ava && tsd"
83
84
  },
84
- "version": "4.2.1"
85
+ "version": "6.0.0",
86
+ "xo": {
87
+ "rules": {
88
+ "@typescript-eslint/prefer-readonly-parameter-types": "off"
89
+ }
90
+ }
85
91
  }
@@ -1,4 +1,4 @@
1
- # decompress-response [![Build Status](https://travis-ci.org/sindresorhus/decompress-response.svg?branch=master)](https://travis-ci.org/sindresorhus/decompress-response)
1
+ # decompress-response [![Build Status](https://travis-ci.com/sindresorhus/decompress-response.svg?branch=master)](https://travis-ci.com/sindresorhus/decompress-response)
2
2
 
3
3
  > Decompress a HTTP response if needed
4
4
 
@@ -6,14 +6,12 @@ Decompresses the [response](https://nodejs.org/api/http.html#http_class_http_inc
6
6
 
7
7
  Used by [`got`](https://github.com/sindresorhus/got).
8
8
 
9
-
10
9
  ## Install
11
10
 
12
11
  ```
13
12
  $ npm install decompress-response
14
13
  ```
15
14
 
16
-
17
15
  ## Usage
18
16
 
19
17
  ```js
@@ -25,7 +23,6 @@ http.get('https://sindresorhus.com', response => {
25
23
  });
26
24
  ```
27
25
 
28
-
29
26
  ## API
30
27
 
31
28
  ### decompressResponse(response)
@@ -38,12 +35,11 @@ Type: [`http.IncomingMessage`](https://nodejs.org/api/http.html#http_class_http_
38
35
 
39
36
  The HTTP incoming stream with compressed data.
40
37
 
41
-
42
38
  ---
43
39
 
44
40
  <div align="center">
45
41
  <b>
46
- <a href="https://tidelift.com/subscription/pkg/npm-unzip-response?utm_source=npm-unzip-response&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
42
+ <a href="https://tidelift.com/subscription/pkg/npm-decompress-response?utm_source=npm-decompress-response&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
47
43
  </b>
48
44
  <br>
49
45
  <sub>
@@ -1,16 +1,15 @@
1
1
  # detect-libc
2
2
 
3
- Node.js module to detect the C standard library (libc) implementation
4
- family and version in use on a given Linux system.
3
+ Node.js module to detect details of the C standard library (libc)
4
+ implementation provided by a given Linux system.
5
5
 
6
- Provides a value suitable for use with the `LIBC` option of
7
- [prebuild](https://www.npmjs.com/package/prebuild),
8
- [prebuild-ci](https://www.npmjs.com/package/prebuild-ci) and
9
- [prebuild-install](https://www.npmjs.com/package/prebuild-install),
10
- therefore allowing build and provision of pre-compiled binaries
11
- for musl-based Linux e.g. Alpine as well as glibc-based.
6
+ Currently supports detection of GNU glibc and MUSL libc.
12
7
 
13
- Currently supports libc detection of `glibc` and `musl`.
8
+ Provides asychronous and synchronous functions for the
9
+ family (e.g. `glibc`, `musl`) and version (e.g. `1.23`, `1.2.3`).
10
+
11
+ For previous v1.x releases, please see the
12
+ [v1](https://github.com/lovell/detect-libc/tree/v1) branch.
14
13
 
15
14
  ## Install
16
15
 
@@ -18,54 +17,137 @@ Currently supports libc detection of `glibc` and `musl`.
18
17
  npm install detect-libc
19
18
  ```
20
19
 
21
- ## Usage
20
+ ## API
21
+
22
+ ### GLIBC
23
+
24
+ ```ts
25
+ const GLIBC: string = 'glibc';
26
+ ```
27
+
28
+ A String constant containing the value `glibc`.
29
+
30
+ ### MUSL
31
+
32
+ ```ts
33
+ const MUSL: string = 'musl';
34
+ ```
35
+
36
+ A String constant containing the value `musl`.
37
+
38
+ ### family
39
+
40
+ ```ts
41
+ function family(): Promise<string | null>;
42
+ ```
43
+
44
+ Resolves asychronously with:
22
45
 
23
- ### API
46
+ * `glibc` or `musl` when the libc family can be determined
47
+ * `null` when the libc family cannot be determined
48
+ * `null` when run on a non-Linux platform
24
49
 
25
50
  ```js
26
- const { GLIBC, MUSL, family, version, isNonGlibcLinux } = require('detect-libc');
51
+ const { family, GLIBC, MUSL } = require('detect-libc');
52
+
53
+ switch (await family()) {
54
+ case GLIBC: ...
55
+ case MUSL: ...
56
+ case null: ...
57
+ }
27
58
  ```
28
59
 
29
- * `GLIBC` is a String containing the value "glibc" for comparison with `family`.
30
- * `MUSL` is a String containing the value "musl" for comparison with `family`.
31
- * `family` is a String representing the system libc family.
32
- * `version` is a String representing the system libc version number.
33
- * `isNonGlibcLinux` is a Boolean representing whether the system is a non-glibc Linux, e.g. Alpine.
60
+ ### familySync
34
61
 
35
- ### detect-libc command line tool
62
+ ```ts
63
+ function familySync(): string | null;
64
+ ```
36
65
 
37
- When run on a Linux system with a non-glibc libc,
38
- the child command will be run with the `LIBC` environment variable
39
- set to the relevant value.
66
+ Synchronous version of `family()`.
40
67
 
41
- On all other platforms will run the child command as-is.
68
+ ```js
69
+ const { familySync, GLIBC, MUSL } = require('detect-libc');
42
70
 
43
- The command line feature requires `spawnSync` provided by Node v0.12+.
71
+ switch (familySync()) {
72
+ case GLIBC: ...
73
+ case MUSL: ...
74
+ case null: ...
75
+ }
76
+ ```
44
77
 
45
- ```sh
46
- detect-libc child-command
78
+ ### version
79
+
80
+ ```ts
81
+ function version(): Promise<string | null>;
82
+ ```
83
+
84
+ Resolves asychronously with:
85
+
86
+ * The version when it can be determined
87
+ * `null` when the libc family cannot be determined
88
+ * `null` when run on a non-Linux platform
89
+
90
+ ```js
91
+ const { version } = require('detect-libc');
92
+
93
+ const v = await version();
94
+ if (v) {
95
+ const [major, minor, patch] = v.split('.');
96
+ }
97
+ ```
98
+
99
+ ### versionSync
100
+
101
+ ```ts
102
+ function versionSync(): string | null;
103
+ ```
104
+
105
+ Synchronous version of `version()`.
106
+
107
+ ```js
108
+ const { versionSync } = require('detect-libc');
109
+
110
+ const v = versionSync();
111
+ if (v) {
112
+ const [major, minor, patch] = v.split('.');
113
+ }
114
+ ```
115
+
116
+ ### isNonGlibcLinux
117
+
118
+ ```ts
119
+ function isNonGlibcLinux(): Promise<boolean>;
47
120
  ```
48
121
 
49
- ## Integrating with prebuild
50
-
51
- ```json
52
- "scripts": {
53
- "install": "detect-libc prebuild-install || node-gyp rebuild",
54
- "test": "mocha && detect-libc prebuild-ci"
55
- },
56
- "dependencies": {
57
- "detect-libc": "^1.0.2",
58
- "prebuild-install": "^2.2.0"
59
- },
60
- "devDependencies": {
61
- "prebuild": "^6.2.1",
62
- "prebuild-ci": "^2.2.3"
63
- }
122
+ Resolves asychronously with:
123
+
124
+ * `false` when the libc family is `glibc`
125
+ * `true` when the libc family is not `glibc`
126
+ * `false` when run on a non-Linux platform
127
+
128
+ ```js
129
+ const { isNonGlibcLinux } = require('detect-libc');
130
+
131
+ if (await isNonGlibcLinux()) { ... }
132
+ ```
133
+
134
+ ### isNonGlibcLinuxSync
135
+
136
+ ```ts
137
+ function isNonGlibcLinuxSync(): boolean;
138
+ ```
139
+
140
+ Synchronous version of `isNonGlibcLinux()`.
141
+
142
+ ```js
143
+ const { isNonGlibcLinuxSync } = require('detect-libc');
144
+
145
+ if (isNonGlibcLinuxSync()) { ... }
64
146
  ```
65
147
 
66
- ## Licence
148
+ ## Licensing
67
149
 
68
- Copyright 2017 Lovell Fuller
150
+ Copyright 2017, 2022 Lovell Fuller
69
151
 
70
152
  Licensed under the Apache License, Version 2.0 (the "License");
71
153
  you may not use this file except in compliance with the License.
@@ -0,0 +1,11 @@
1
+ export const GLIBC: 'glibc';
2
+ export const MUSL: 'musl';
3
+
4
+ export function family(): Promise<string | null>;
5
+ export function familySync(): string | null;
6
+
7
+ export function isNonGlibcLinux(): Promise<boolean>;
8
+ export function isNonGlibcLinuxSync(): boolean;
9
+
10
+ export function version(): Promise<string | null>;
11
+ export function versionSync(): string | null;
@@ -1,92 +1,178 @@
1
1
  'use strict';
2
2
 
3
- var platform = require('os').platform();
4
- var spawnSync = require('child_process').spawnSync;
5
- var readdirSync = require('fs').readdirSync;
3
+ const childProcess = require('child_process');
4
+ const { isLinux, getReport } = require('./process');
6
5
 
7
- var GLIBC = 'glibc';
8
- var MUSL = 'musl';
6
+ const command = 'getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true';
7
+ let commandOut = '';
9
8
 
10
- var spawnOptions = {
11
- encoding: 'utf8',
12
- env: process.env
9
+ const safeCommand = () => {
10
+ if (!commandOut) {
11
+ return new Promise((resolve) => {
12
+ childProcess.exec(command, (err, out) => {
13
+ commandOut = err ? ' ' : out;
14
+ resolve(commandOut);
15
+ });
16
+ });
17
+ }
18
+ return commandOut;
19
+ };
20
+
21
+ const safeCommandSync = () => {
22
+ if (!commandOut) {
23
+ try {
24
+ commandOut = childProcess.execSync(command, { encoding: 'utf8' });
25
+ } catch (_err) {
26
+ commandOut = ' ';
27
+ }
28
+ }
29
+ return commandOut;
30
+ };
31
+
32
+ /**
33
+ * A String constant containing the value `glibc`.
34
+ * @type {string}
35
+ * @public
36
+ */
37
+ const GLIBC = 'glibc';
38
+
39
+ /**
40
+ * A String constant containing the value `musl`.
41
+ * @type {string}
42
+ * @public
43
+ */
44
+ const MUSL = 'musl';
45
+
46
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-');
47
+
48
+ const familyFromReport = () => {
49
+ const report = getReport();
50
+ if (report.header && report.header.glibcVersionRuntime) {
51
+ return GLIBC;
52
+ }
53
+ if (Array.isArray(report.sharedObjects)) {
54
+ if (report.sharedObjects.some(isFileMusl)) {
55
+ return MUSL;
56
+ }
57
+ }
58
+ return null;
59
+ };
60
+
61
+ const familyFromCommand = (out) => {
62
+ const [getconf, ldd1] = out.split(/[\r\n]+/);
63
+ if (getconf && getconf.includes(GLIBC)) {
64
+ return GLIBC;
65
+ }
66
+ if (ldd1 && ldd1.includes(MUSL)) {
67
+ return MUSL;
68
+ }
69
+ return null;
13
70
  };
14
71
 
15
- if (!spawnSync) {
16
- spawnSync = function () {
17
- return { status: 126, stdout: '', stderr: '' };
18
- };
19
- }
20
-
21
- function contains (needle) {
22
- return function (haystack) {
23
- return haystack.indexOf(needle) !== -1;
24
- };
25
- }
26
-
27
- function versionFromMuslLdd (out) {
28
- return out.split(/[\r\n]+/)[1].trim().split(/\s/)[1];
29
- }
30
-
31
- function safeReaddirSync (path) {
32
- try {
33
- return readdirSync(path);
34
- } catch (e) {}
35
- return [];
36
- }
37
-
38
- var family = '';
39
- var version = '';
40
- var method = '';
41
-
42
- if (platform === 'linux') {
43
- // Try getconf
44
- var glibc = spawnSync('getconf', ['GNU_LIBC_VERSION'], spawnOptions);
45
- if (glibc.status === 0) {
46
- family = GLIBC;
47
- version = glibc.stdout.trim().split(' ')[1];
48
- method = 'getconf';
49
- } else {
50
- // Try ldd
51
- var ldd = spawnSync('ldd', ['--version'], spawnOptions);
52
- if (ldd.status === 0 && ldd.stdout.indexOf(MUSL) !== -1) {
53
- family = MUSL;
54
- version = versionFromMuslLdd(ldd.stdout);
55
- method = 'ldd';
56
- } else if (ldd.status === 1 && ldd.stderr.indexOf(MUSL) !== -1) {
57
- family = MUSL;
58
- version = versionFromMuslLdd(ldd.stderr);
59
- method = 'ldd';
60
- } else {
61
- // Try filesystem (family only)
62
- var lib = safeReaddirSync('/lib');
63
- if (lib.some(contains('-linux-gnu'))) {
64
- family = GLIBC;
65
- method = 'filesystem';
66
- } else if (lib.some(contains('libc.musl-'))) {
67
- family = MUSL;
68
- method = 'filesystem';
69
- } else if (lib.some(contains('ld-musl-'))) {
70
- family = MUSL;
71
- method = 'filesystem';
72
- } else {
73
- var usrSbin = safeReaddirSync('/usr/sbin');
74
- if (usrSbin.some(contains('glibc'))) {
75
- family = GLIBC;
76
- method = 'filesystem';
77
- }
78
- }
72
+ /**
73
+ * Resolves with the libc family when it can be determined, `null` otherwise.
74
+ * @returns {Promise<?string>}
75
+ */
76
+ const family = async () => {
77
+ let family = null;
78
+ if (isLinux()) {
79
+ family = familyFromReport();
80
+ if (!family) {
81
+ const out = await safeCommand();
82
+ family = familyFromCommand(out);
79
83
  }
80
84
  }
81
- }
85
+ return family;
86
+ };
82
87
 
83
- var isNonGlibcLinux = (family !== '' && family !== GLIBC);
88
+ /**
89
+ * Returns the libc family when it can be determined, `null` otherwise.
90
+ * @returns {?string}
91
+ */
92
+ const familySync = () => {
93
+ let family = null;
94
+ if (isLinux()) {
95
+ family = familyFromReport();
96
+ if (!family) {
97
+ const out = safeCommandSync();
98
+ family = familyFromCommand(out);
99
+ }
100
+ }
101
+ return family;
102
+ };
103
+
104
+ /**
105
+ * Resolves `true` only when the platform is Linux and the libc family is not `glibc`.
106
+ * @returns {Promise<boolean>}
107
+ */
108
+ const isNonGlibcLinux = async () => isLinux() && await family() !== GLIBC;
109
+
110
+ /**
111
+ * Returns `true` only when the platform is Linux and the libc family is not `glibc`.
112
+ * @returns {boolean}
113
+ */
114
+ const isNonGlibcLinuxSync = () => isLinux() && familySync() !== GLIBC;
115
+
116
+ const versionFromReport = () => {
117
+ const report = getReport();
118
+ if (report.header && report.header.glibcVersionRuntime) {
119
+ return report.header.glibcVersionRuntime;
120
+ }
121
+ return null;
122
+ };
123
+
124
+ const versionSuffix = (s) => s.trim().split(/\s+/)[1];
125
+
126
+ const versionFromCommand = (out) => {
127
+ const [getconf, ldd1, ldd2] = out.split(/[\r\n]+/);
128
+ if (getconf && getconf.includes(GLIBC)) {
129
+ return versionSuffix(getconf);
130
+ }
131
+ if (ldd1 && ldd2 && ldd1.includes(MUSL)) {
132
+ return versionSuffix(ldd2);
133
+ }
134
+ return null;
135
+ };
136
+
137
+ /**
138
+ * Resolves with the libc version when it can be determined, `null` otherwise.
139
+ * @returns {Promise<?string>}
140
+ */
141
+ const version = async () => {
142
+ let version = null;
143
+ if (isLinux()) {
144
+ version = versionFromReport();
145
+ if (!version) {
146
+ const out = await safeCommand();
147
+ version = versionFromCommand(out);
148
+ }
149
+ }
150
+ return version;
151
+ };
152
+
153
+ /**
154
+ * Returns the libc version when it can be determined, `null` otherwise.
155
+ * @returns {?string}
156
+ */
157
+ const versionSync = () => {
158
+ let version = null;
159
+ if (isLinux()) {
160
+ version = versionFromReport();
161
+ if (!version) {
162
+ const out = safeCommandSync();
163
+ version = versionFromCommand(out);
164
+ }
165
+ }
166
+ return version;
167
+ };
84
168
 
85
169
  module.exports = {
86
- GLIBC: GLIBC,
87
- MUSL: MUSL,
88
- family: family,
89
- version: version,
90
- method: method,
91
- isNonGlibcLinux: isNonGlibcLinux
170
+ GLIBC,
171
+ MUSL,
172
+ family,
173
+ familySync,
174
+ isNonGlibcLinux,
175
+ isNonGlibcLinuxSync,
176
+ version,
177
+ versionSync
92
178
  };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const isLinux = () => process.platform === 'linux';
4
+
5
+ let report = null;
6
+ const getReport = () => {
7
+ if (!report) {
8
+ /* istanbul ignore next */
9
+ report = isLinux() && process.report
10
+ ? process.report.getReport()
11
+ : {};
12
+ }
13
+ return report;
14
+ };
15
+
16
+ module.exports = { isLinux, getReport };