node-datachannel 0.3.1 → 0.3.2
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/.github/workflows/lint.yml +22 -0
- package/CMakeLists.txt +2 -2
- package/examples/client-server/client-benchmark.js +43 -32
- package/examples/client-server/client-periodic.js +30 -14
- package/examples/client-server/client.js +6 -5
- package/examples/client-server/package-lock.json +183 -44
- package/examples/client-server/signaling-server.js +3 -5
- package/examples/media/media.js +9 -9
- package/lib/index.d.ts +100 -100
- package/node_modules/lru-cache/package.json +2 -4
- package/node_modules/minimist/package.json +0 -1
- package/node_modules/node-abi/node_modules/semver/README.md +3 -1
- package/node_modules/node-abi/node_modules/semver/bin/semver.js +19 -9
- package/node_modules/node-abi/node_modules/semver/classes/comparator.js +3 -2
- package/node_modules/node-abi/node_modules/semver/classes/index.js +1 -1
- package/node_modules/node-abi/node_modules/semver/classes/range.js +31 -22
- package/node_modules/node-abi/node_modules/semver/classes/semver.js +1 -1
- package/node_modules/node-abi/node_modules/semver/functions/cmp.js +8 -4
- package/node_modules/node-abi/node_modules/semver/functions/coerce.js +3 -2
- package/node_modules/node-abi/node_modules/semver/functions/inc.js +4 -1
- package/node_modules/node-abi/node_modules/semver/functions/parse.js +1 -1
- package/node_modules/node-abi/node_modules/semver/internal/constants.js +2 -2
- package/node_modules/node-abi/node_modules/semver/internal/identifiers.js +1 -1
- package/node_modules/node-abi/node_modules/semver/internal/parse-options.js +3 -3
- package/node_modules/node-abi/node_modules/semver/internal/re.js +3 -3
- package/node_modules/node-abi/node_modules/semver/package.json +51 -18
- package/node_modules/node-abi/node_modules/semver/ranges/min-version.js +2 -1
- package/node_modules/node-abi/node_modules/semver/ranges/outside.js +1 -1
- package/node_modules/node-abi/node_modules/semver/ranges/simplify.js +15 -12
- package/node_modules/node-abi/node_modules/semver/ranges/subset.js +53 -31
- package/node_modules/npmlog/node_modules/are-we-there-yet/package.json +10 -10
- package/node_modules/npmlog/package.json +1 -1
- package/node_modules/tar-stream/node_modules/bl/.travis.yml +4 -3
- package/node_modules/tar-stream/node_modules/bl/BufferList.js +1 -1
- package/node_modules/tar-stream/node_modules/bl/package.json +10 -10
- package/node_modules/tar-stream/node_modules/bl/test/test.js +20 -2
- package/node_modules/wide-align/LICENSE +0 -0
- package/node_modules/wide-align/README.md +0 -0
- package/node_modules/wide-align/align.js +0 -0
- package/node_modules/wide-align/package.json +14 -14
- package/package.json +2 -2
- package/src/data-channel-wrapper.cpp +69 -53
- package/src/data-channel-wrapper.h +0 -1
- package/src/media-track-wrapper.cpp +91 -52
- package/src/media-track-wrapper.h +0 -1
- package/src/peer-connection-wrapper.cpp +106 -70
- package/src/peer-connection-wrapper.h +0 -2
- package/test/connectivity.js +18 -17
- package/test/test.js +22 -30
- package/node_modules/node-abi/node_modules/semver/CHANGELOG.md +0 -111
package/examples/media/media.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
1
2
|
const nodeDataChannel = require('../../lib/index');
|
|
2
|
-
const readline = require(
|
|
3
|
+
const readline = require('readline');
|
|
3
4
|
var dgram = require('dgram');
|
|
4
5
|
|
|
5
6
|
var client = dgram.createSocket('udp4');
|
|
@@ -7,7 +8,7 @@ var client = dgram.createSocket('udp4');
|
|
|
7
8
|
// Read Line Interface
|
|
8
9
|
const rl = readline.createInterface({
|
|
9
10
|
input: process.stdin,
|
|
10
|
-
output: process.stdout
|
|
11
|
+
output: process.stdout,
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
// Init Logger
|
|
@@ -21,7 +22,7 @@ peerConnection.onStateChange((state) => {
|
|
|
21
22
|
peerConnection.onGatheringStateChange((state) => {
|
|
22
23
|
// console.log('GatheringState: ', state);
|
|
23
24
|
|
|
24
|
-
if(state == 'complete'){
|
|
25
|
+
if (state == 'complete') {
|
|
25
26
|
let desc = peerConnection.localDescription();
|
|
26
27
|
console.log('');
|
|
27
28
|
console.log('## Please copy the offer below to the web page:');
|
|
@@ -31,14 +32,13 @@ peerConnection.onGatheringStateChange((state) => {
|
|
|
31
32
|
rl.question('## Please copy/paste the answer provided by the browser: \n', (sdp) => {
|
|
32
33
|
let sdpObj = JSON.parse(sdp);
|
|
33
34
|
peerConnection.setRemoteDescription(sdpObj.sdp, sdpObj.type);
|
|
34
|
-
console.log(track.isOpen())
|
|
35
|
+
console.log(track.isOpen());
|
|
35
36
|
rl.close();
|
|
36
|
-
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
let video = new nodeDataChannel.Video('video','RecvOnly');
|
|
41
|
+
let video = new nodeDataChannel.Video('video', 'RecvOnly');
|
|
42
42
|
video.addH264Codec(96);
|
|
43
43
|
video.setBitrate(3000);
|
|
44
44
|
|
|
@@ -46,9 +46,9 @@ let track = peerConnection.addTrack(video);
|
|
|
46
46
|
let session = new nodeDataChannel.RtcpReceivingSession();
|
|
47
47
|
|
|
48
48
|
track.setMediaHandler(session);
|
|
49
|
-
track.onMessage((msg)=>{
|
|
50
|
-
client.send(msg,5000,'127.0.0.1',(err,n)=>{
|
|
51
|
-
if(err) console.log(err,n);
|
|
49
|
+
track.onMessage((msg) => {
|
|
50
|
+
client.send(msg, 5000, '127.0.0.1', (err, n) => {
|
|
51
|
+
if (err) console.log(err, n);
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
|
package/lib/index.d.ts
CHANGED
|
@@ -103,124 +103,124 @@ export const enum Direction {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export class RtcpReceivingSession {
|
|
106
|
-
requestBitrate
|
|
107
|
-
requestKeyframe
|
|
106
|
+
requestBitrate(bitRate: number): void;
|
|
107
|
+
requestKeyframe(): boolean;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
export class Audio {
|
|
111
111
|
constructor(mid: string, dir: Direction);
|
|
112
|
-
addAudioCodec
|
|
113
|
-
addOpusCodec
|
|
114
|
-
|
|
115
|
-
direction
|
|
116
|
-
generateSdp
|
|
117
|
-
mid
|
|
118
|
-
setDirection
|
|
119
|
-
description
|
|
120
|
-
removeFormat
|
|
121
|
-
addSSRC
|
|
122
|
-
removeSSRC
|
|
123
|
-
replaceSSRC
|
|
124
|
-
hasSSRC
|
|
125
|
-
getSSRCs
|
|
126
|
-
getCNameForSsrc
|
|
127
|
-
setBitrate
|
|
128
|
-
getBitrate
|
|
129
|
-
hasPayloadType
|
|
130
|
-
addRTXCodec
|
|
131
|
-
addRTPMap
|
|
132
|
-
parseSdpLine
|
|
112
|
+
addAudioCodec(payloadType: number, codec: string, profile?: string): void;
|
|
113
|
+
addOpusCodec(payloadType: number, profile?: string): string;
|
|
114
|
+
|
|
115
|
+
direction(): Direction;
|
|
116
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
117
|
+
mid(): string;
|
|
118
|
+
setDirection(dir: Direction): void;
|
|
119
|
+
description(): string;
|
|
120
|
+
removeFormat(fmt: string): void;
|
|
121
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
122
|
+
removeSSRC(ssrc: number): void;
|
|
123
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
124
|
+
hasSSRC(ssrc: number): boolean;
|
|
125
|
+
getSSRCs(): number[];
|
|
126
|
+
getCNameForSsrc(ssrc: number): string;
|
|
127
|
+
setBitrate(bitRate: number): void;
|
|
128
|
+
getBitrate(): number;
|
|
129
|
+
hasPayloadType(payloadType: number): boolean;
|
|
130
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
131
|
+
addRTPMap(): void;
|
|
132
|
+
parseSdpLine(line: string): void;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
export class Video {
|
|
136
136
|
constructor(mid: string, dir: Direction);
|
|
137
|
-
addVideoCodec
|
|
138
|
-
addH264Codec
|
|
139
|
-
addVP8Codec
|
|
140
|
-
addVP9Codec
|
|
141
|
-
|
|
142
|
-
direction
|
|
143
|
-
generateSdp
|
|
144
|
-
mid
|
|
145
|
-
setDirection
|
|
146
|
-
description
|
|
147
|
-
removeFormat
|
|
148
|
-
addSSRC
|
|
149
|
-
removeSSRC
|
|
150
|
-
replaceSSRC
|
|
151
|
-
hasSSRC
|
|
152
|
-
getSSRCs
|
|
153
|
-
getCNameForSsrc
|
|
154
|
-
setBitrate
|
|
155
|
-
getBitrate
|
|
156
|
-
hasPayloadType
|
|
157
|
-
addRTXCodec
|
|
158
|
-
addRTPMap
|
|
159
|
-
parseSdpLine
|
|
137
|
+
addVideoCodec(payloadType: number, codec: string, profile?: string): void;
|
|
138
|
+
addH264Codec(payloadType: number, profile?: string): void;
|
|
139
|
+
addVP8Codec(payloadType: number): void;
|
|
140
|
+
addVP9Codec(payloadType: number): void;
|
|
141
|
+
|
|
142
|
+
direction(): Direction;
|
|
143
|
+
generateSdp(eol: string, addr: string, port: number): string;
|
|
144
|
+
mid(): string;
|
|
145
|
+
setDirection(dir: Direction): void;
|
|
146
|
+
description(): string;
|
|
147
|
+
removeFormat(fmt: string): void;
|
|
148
|
+
addSSRC(ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
149
|
+
removeSSRC(ssrc: number): void;
|
|
150
|
+
replaceSSRC(oldSsrc: number, ssrc: number, name?: string, msid?: string, trackID?: string): void;
|
|
151
|
+
hasSSRC(ssrc: number): boolean;
|
|
152
|
+
getSSRCs(): number[];
|
|
153
|
+
getCNameForSsrc(ssrc: number): string;
|
|
154
|
+
setBitrate(bitRate: number): void;
|
|
155
|
+
getBitrate(): number;
|
|
156
|
+
hasPayloadType(payloadType: number): boolean;
|
|
157
|
+
addRTXCodec(payloadType: number, originalPayloadType: number, clockRate: number): void;
|
|
158
|
+
addRTPMap(): void;
|
|
159
|
+
parseSdpLine(line: string): void;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
export class Track {
|
|
163
|
-
direction
|
|
164
|
-
mid
|
|
165
|
-
type
|
|
166
|
-
close
|
|
167
|
-
sendMessage
|
|
168
|
-
sendMessageBinary
|
|
169
|
-
isOpen
|
|
170
|
-
isClosed
|
|
171
|
-
bufferedAmount
|
|
172
|
-
maxMessageSize
|
|
173
|
-
setBufferedAmountLowThreshold
|
|
174
|
-
requestKeyframe
|
|
175
|
-
setMediaHandler
|
|
176
|
-
onOpen
|
|
177
|
-
onClosed
|
|
178
|
-
onError
|
|
179
|
-
onMessage
|
|
163
|
+
direction(): Direction;
|
|
164
|
+
mid(): string;
|
|
165
|
+
type(): string;
|
|
166
|
+
close(): void;
|
|
167
|
+
sendMessage(msg: string): boolean;
|
|
168
|
+
sendMessageBinary(buffer: Buffer): boolean;
|
|
169
|
+
isOpen(): boolean;
|
|
170
|
+
isClosed(): boolean;
|
|
171
|
+
bufferedAmount(): number;
|
|
172
|
+
maxMessageSize(): number;
|
|
173
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
174
|
+
requestKeyframe(): boolean;
|
|
175
|
+
setMediaHandler(handler: RtcpReceivingSession): void;
|
|
176
|
+
onOpen(cb: () => void): void;
|
|
177
|
+
onClosed(cb: () => void): void;
|
|
178
|
+
onError(cb: (err: string) => void): void;
|
|
179
|
+
onMessage(cb: (msg: Buffer) => void): void;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
export class DataChannel {
|
|
183
|
-
close
|
|
184
|
-
getLabel
|
|
185
|
-
getId
|
|
186
|
-
getProtocol
|
|
187
|
-
sendMessage
|
|
188
|
-
sendMessageBinary
|
|
189
|
-
isOpen
|
|
190
|
-
bufferedAmount
|
|
191
|
-
maxMessageSize
|
|
192
|
-
setBufferedAmountLowThreshold
|
|
193
|
-
onOpen
|
|
194
|
-
onClosed
|
|
195
|
-
onError
|
|
196
|
-
onBufferedAmountLow
|
|
197
|
-
onMessage
|
|
183
|
+
close(): void;
|
|
184
|
+
getLabel(): string;
|
|
185
|
+
getId(): number;
|
|
186
|
+
getProtocol(): string;
|
|
187
|
+
sendMessage(msg: string): boolean;
|
|
188
|
+
sendMessageBinary(buffer: Buffer): boolean;
|
|
189
|
+
isOpen(): boolean;
|
|
190
|
+
bufferedAmount(): number;
|
|
191
|
+
maxMessageSize(): number;
|
|
192
|
+
setBufferedAmountLowThreshold(newSize: number): void;
|
|
193
|
+
onOpen(cb: () => void): void;
|
|
194
|
+
onClosed(cb: () => void): void;
|
|
195
|
+
onError(cb: (err: string) => void): void;
|
|
196
|
+
onBufferedAmountLow(cb: () => void): void;
|
|
197
|
+
onMessage(cb: (msg: string | Buffer) => void): void;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
export class PeerConnection {
|
|
201
201
|
constructor(peerName: string, config: RtcConfig);
|
|
202
|
-
close
|
|
203
|
-
setLocalDescription
|
|
204
|
-
setRemoteDescription
|
|
205
|
-
localDescription
|
|
206
|
-
addRemoteCandidate
|
|
207
|
-
createDataChannel
|
|
208
|
-
addTrack
|
|
209
|
-
hasMedia
|
|
210
|
-
state
|
|
211
|
-
signalingState
|
|
212
|
-
gatheringState
|
|
213
|
-
onLocalDescription
|
|
214
|
-
onLocalCandidate
|
|
215
|
-
onStateChange
|
|
216
|
-
onSignalingStateChange: (state:
|
|
217
|
-
onGatheringStateChange: (state:
|
|
218
|
-
onDataChannel
|
|
219
|
-
onTrack
|
|
220
|
-
bytesSent
|
|
221
|
-
bytesReceived
|
|
222
|
-
rtt
|
|
223
|
-
getSelectedCandidatePair
|
|
202
|
+
close(): void;
|
|
203
|
+
setLocalDescription(type?: DescriptionType): void;
|
|
204
|
+
setRemoteDescription(sdp: string, type: DescriptionType): void;
|
|
205
|
+
localDescription(): { type: string; sdp: string } | null;
|
|
206
|
+
addRemoteCandidate(candidate: string, mid: string): void;
|
|
207
|
+
createDataChannel(label: string, config?: DataChannelInitConfig): DataChannel;
|
|
208
|
+
addTrack(media: Video | Audio): Track;
|
|
209
|
+
hasMedia(): boolean;
|
|
210
|
+
state(): string;
|
|
211
|
+
signalingState(): string;
|
|
212
|
+
gatheringState(): string;
|
|
213
|
+
onLocalDescription(cb: (sdp: string, type: DescriptionType) => void): void;
|
|
214
|
+
onLocalCandidate(cb: (candidate: string, mid: string) => void): void;
|
|
215
|
+
onStateChange(cb: (state: string) => void): void;
|
|
216
|
+
onSignalingStateChange(cb: (state: string) => void): void;
|
|
217
|
+
onGatheringStateChange(cb: (state: string) => void): void;
|
|
218
|
+
onDataChannel(cb: (dc: DataChannel) => void): void;
|
|
219
|
+
onTrack(cb: (track: Track) => void): void;
|
|
220
|
+
bytesSent(): number;
|
|
221
|
+
bytesReceived(): number;
|
|
222
|
+
rtt(): number;
|
|
223
|
+
getSelectedCandidatePair(): { local: SelectedCandidateInfo; remote: SelectedCandidateInfo } | null;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
export class DataChannelStream extends stream.Duplex {
|
|
@@ -22,10 +22,8 @@
|
|
|
22
22
|
"fetchSpec": "6.0.0"
|
|
23
23
|
},
|
|
24
24
|
"_requiredBy": [
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"/jest-snapshot/semver",
|
|
28
|
-
"/node-abi/semver"
|
|
25
|
+
"/node-abi/semver",
|
|
26
|
+
"/semver"
|
|
29
27
|
],
|
|
30
28
|
"_resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
|
31
29
|
"_spec": "6.0.0",
|
|
@@ -264,7 +264,9 @@ provided tuple parts.
|
|
|
264
264
|
Any of `X`, `x`, or `*` may be used to "stand in" for one of the
|
|
265
265
|
numeric values in the `[major, minor, patch]` tuple.
|
|
266
266
|
|
|
267
|
-
* `*` := `>=0.0.0` (Any version satisfies
|
|
267
|
+
* `*` := `>=0.0.0` (Any non-prerelease version satisfies, unless
|
|
268
|
+
`includePrerelease` is specified, in which case any version at all
|
|
269
|
+
satisfies)
|
|
268
270
|
* `1.x` := `>=1.0.0 <2.0.0-0` (Matching major version)
|
|
269
271
|
* `1.2.x` := `>=1.2.0 <1.3.0-0` (Matching major and minor versions)
|
|
270
272
|
|
|
@@ -27,16 +27,19 @@ const semver = require('../')
|
|
|
27
27
|
|
|
28
28
|
let reverse = false
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
let options = {}
|
|
31
31
|
|
|
32
32
|
const main = () => {
|
|
33
|
-
if (!argv.length)
|
|
33
|
+
if (!argv.length) {
|
|
34
|
+
return help()
|
|
35
|
+
}
|
|
34
36
|
while (argv.length) {
|
|
35
37
|
let a = argv.shift()
|
|
36
38
|
const indexOfEqualSign = a.indexOf('=')
|
|
37
39
|
if (indexOfEqualSign !== -1) {
|
|
40
|
+
const value = a.slice(indexOfEqualSign + 1)
|
|
38
41
|
a = a.slice(0, indexOfEqualSign)
|
|
39
|
-
argv.unshift(
|
|
42
|
+
argv.unshift(value)
|
|
40
43
|
}
|
|
41
44
|
switch (a) {
|
|
42
45
|
case '-rv': case '-rev': case '--rev': case '--reverse':
|
|
@@ -85,26 +88,31 @@ const main = () => {
|
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
|
|
89
92
|
|
|
90
93
|
versions = versions.map((v) => {
|
|
91
94
|
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
|
|
92
95
|
}).filter((v) => {
|
|
93
96
|
return semver.valid(v)
|
|
94
97
|
})
|
|
95
|
-
if (!versions.length)
|
|
96
|
-
|
|
98
|
+
if (!versions.length) {
|
|
99
|
+
return fail()
|
|
100
|
+
}
|
|
101
|
+
if (inc && (versions.length !== 1 || range.length)) {
|
|
102
|
+
return failInc()
|
|
103
|
+
}
|
|
97
104
|
|
|
98
105
|
for (let i = 0, l = range.length; i < l; i++) {
|
|
99
106
|
versions = versions.filter((v) => {
|
|
100
107
|
return semver.satisfies(v, range[i], options)
|
|
101
108
|
})
|
|
102
|
-
if (!versions.length)
|
|
109
|
+
if (!versions.length) {
|
|
110
|
+
return fail()
|
|
111
|
+
}
|
|
103
112
|
}
|
|
104
113
|
return success(versions)
|
|
105
114
|
}
|
|
106
115
|
|
|
107
|
-
|
|
108
116
|
const failInc = () => {
|
|
109
117
|
console.error('--inc can only be used on a single version with no range')
|
|
110
118
|
fail()
|
|
@@ -120,7 +128,9 @@ const success = () => {
|
|
|
120
128
|
return semver.clean(v, options)
|
|
121
129
|
}).map((v) => {
|
|
122
130
|
return inc ? semver.inc(v, inc, options, identifier) : v
|
|
123
|
-
}).forEach((v, i, _) => {
|
|
131
|
+
}).forEach((v, i, _) => {
|
|
132
|
+
console.log(v)
|
|
133
|
+
})
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
const help = () => console.log(
|
|
@@ -4,6 +4,7 @@ class Comparator {
|
|
|
4
4
|
static get ANY () {
|
|
5
5
|
return ANY
|
|
6
6
|
}
|
|
7
|
+
|
|
7
8
|
constructor (comp, options) {
|
|
8
9
|
options = parseOptions(options)
|
|
9
10
|
|
|
@@ -80,7 +81,7 @@ class Comparator {
|
|
|
80
81
|
if (!options || typeof options !== 'object') {
|
|
81
82
|
options = {
|
|
82
83
|
loose: !!options,
|
|
83
|
-
includePrerelease: false
|
|
84
|
+
includePrerelease: false,
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -128,7 +129,7 @@ class Comparator {
|
|
|
128
129
|
module.exports = Comparator
|
|
129
130
|
|
|
130
131
|
const parseOptions = require('../internal/parse-options')
|
|
131
|
-
const {re, t} = require('../internal/re')
|
|
132
|
+
const { re, t } = require('../internal/re')
|
|
132
133
|
const cmp = require('../functions/cmp')
|
|
133
134
|
const debug = require('../internal/debug')
|
|
134
135
|
const SemVer = require('./semver')
|
|
@@ -29,9 +29,9 @@ class Range {
|
|
|
29
29
|
// First, split based on boolean or ||
|
|
30
30
|
this.raw = range
|
|
31
31
|
this.set = range
|
|
32
|
-
.split(
|
|
32
|
+
.split('||')
|
|
33
33
|
// map the range to a 2d array of comparators
|
|
34
|
-
.map(
|
|
34
|
+
.map(r => this.parseRange(r.trim()))
|
|
35
35
|
// throw out any comparator lists that are empty
|
|
36
36
|
// this generally means that it was not a valid range, which is allowed
|
|
37
37
|
// in loose mode, but will still throw if the WHOLE range is invalid.
|
|
@@ -46,9 +46,9 @@ class Range {
|
|
|
46
46
|
// keep the first one, in case they're all null sets
|
|
47
47
|
const first = this.set[0]
|
|
48
48
|
this.set = this.set.filter(c => !isNullSet(c[0]))
|
|
49
|
-
if (this.set.length === 0)
|
|
49
|
+
if (this.set.length === 0) {
|
|
50
50
|
this.set = [first]
|
|
51
|
-
else if (this.set.length > 1) {
|
|
51
|
+
} else if (this.set.length > 1) {
|
|
52
52
|
// if we have any that are *, then the range is just *
|
|
53
53
|
for (const c of this.set) {
|
|
54
54
|
if (c.length === 1 && isAny(c[0])) {
|
|
@@ -84,8 +84,9 @@ class Range {
|
|
|
84
84
|
const memoOpts = Object.keys(this.options).join(',')
|
|
85
85
|
const memoKey = `parseRange:${memoOpts}:${range}`
|
|
86
86
|
const cached = cache.get(memoKey)
|
|
87
|
-
if (cached)
|
|
87
|
+
if (cached) {
|
|
88
88
|
return cached
|
|
89
|
+
}
|
|
89
90
|
|
|
90
91
|
const loose = this.options.loose
|
|
91
92
|
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
@@ -94,7 +95,7 @@ class Range {
|
|
|
94
95
|
debug('hyphen replace', range)
|
|
95
96
|
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
96
97
|
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
|
|
97
|
-
debug('comparator trim', range
|
|
98
|
+
debug('comparator trim', range)
|
|
98
99
|
|
|
99
100
|
// `~ 1.2.3` => `~1.2.3`
|
|
100
101
|
range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
|
|
@@ -108,30 +109,37 @@ class Range {
|
|
|
108
109
|
// At this point, the range is completely trimmed and
|
|
109
110
|
// ready to be split into comparators.
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
const rangeList = range
|
|
112
|
+
let rangeList = range
|
|
113
113
|
.split(' ')
|
|
114
114
|
.map(comp => parseComparator(comp, this.options))
|
|
115
115
|
.join(' ')
|
|
116
116
|
.split(/\s+/)
|
|
117
117
|
// >=0.0.0 is equivalent to *
|
|
118
118
|
.map(comp => replaceGTE0(comp, this.options))
|
|
119
|
+
|
|
120
|
+
if (loose) {
|
|
119
121
|
// in loose mode, throw out any that are not valid comparators
|
|
120
|
-
.filter(
|
|
121
|
-
|
|
122
|
+
rangeList = rangeList.filter(comp => {
|
|
123
|
+
debug('loose invalid filter', comp, this.options)
|
|
124
|
+
return !!comp.match(re[t.COMPARATORLOOSE])
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
debug('range list', rangeList)
|
|
122
128
|
|
|
123
129
|
// if any comparators are the null set, then replace with JUST null set
|
|
124
130
|
// if more than one comparator, remove any * comparators
|
|
125
131
|
// also, don't include the same comparator more than once
|
|
126
|
-
const l = rangeList.length
|
|
127
132
|
const rangeMap = new Map()
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
const comparators = rangeList.map(comp => new Comparator(comp, this.options))
|
|
134
|
+
for (const comp of comparators) {
|
|
135
|
+
if (isNullSet(comp)) {
|
|
130
136
|
return [comp]
|
|
137
|
+
}
|
|
131
138
|
rangeMap.set(comp.value, comp)
|
|
132
139
|
}
|
|
133
|
-
if (rangeMap.size > 1 && rangeMap.has(''))
|
|
140
|
+
if (rangeMap.size > 1 && rangeMap.has('')) {
|
|
134
141
|
rangeMap.delete('')
|
|
142
|
+
}
|
|
135
143
|
|
|
136
144
|
const result = [...rangeMap.values()]
|
|
137
145
|
cache.set(memoKey, result)
|
|
@@ -196,7 +204,7 @@ const {
|
|
|
196
204
|
t,
|
|
197
205
|
comparatorTrimReplace,
|
|
198
206
|
tildeTrimReplace,
|
|
199
|
-
caretTrimReplace
|
|
207
|
+
caretTrimReplace,
|
|
200
208
|
} = require('../internal/re')
|
|
201
209
|
|
|
202
210
|
const isNullSet = c => c.value === '<0.0.0-0'
|
|
@@ -245,8 +253,8 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
|
|
|
245
253
|
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
|
|
246
254
|
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
|
|
247
255
|
const replaceTildes = (comp, options) =>
|
|
248
|
-
comp.trim().split(/\s+/).map((
|
|
249
|
-
return replaceTilde(
|
|
256
|
+
comp.trim().split(/\s+/).map((c) => {
|
|
257
|
+
return replaceTilde(c, options)
|
|
250
258
|
}).join(' ')
|
|
251
259
|
|
|
252
260
|
const replaceTilde = (comp, options) => {
|
|
@@ -284,8 +292,8 @@ const replaceTilde = (comp, options) => {
|
|
|
284
292
|
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
|
285
293
|
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
|
286
294
|
const replaceCarets = (comp, options) =>
|
|
287
|
-
comp.trim().split(/\s+/).map((
|
|
288
|
-
return replaceCaret(
|
|
295
|
+
comp.trim().split(/\s+/).map((c) => {
|
|
296
|
+
return replaceCaret(c, options)
|
|
289
297
|
}).join(' ')
|
|
290
298
|
|
|
291
299
|
const replaceCaret = (comp, options) => {
|
|
@@ -343,8 +351,8 @@ const replaceCaret = (comp, options) => {
|
|
|
343
351
|
|
|
344
352
|
const replaceXRanges = (comp, options) => {
|
|
345
353
|
debug('replaceXRanges', comp, options)
|
|
346
|
-
return comp.split(/\s+/).map((
|
|
347
|
-
return replaceXRange(
|
|
354
|
+
return comp.split(/\s+/).map((c) => {
|
|
355
|
+
return replaceXRange(c, options)
|
|
348
356
|
}).join(' ')
|
|
349
357
|
}
|
|
350
358
|
|
|
@@ -405,8 +413,9 @@ const replaceXRange = (comp, options) => {
|
|
|
405
413
|
}
|
|
406
414
|
}
|
|
407
415
|
|
|
408
|
-
if (gtlt === '<')
|
|
416
|
+
if (gtlt === '<') {
|
|
409
417
|
pr = '-0'
|
|
418
|
+
}
|
|
410
419
|
|
|
411
420
|
ret = `${gtlt + M}.${m}.${p}${pr}`
|
|
412
421
|
} else if (xm) {
|
|
@@ -265,7 +265,7 @@ class SemVer {
|
|
|
265
265
|
if (identifier) {
|
|
266
266
|
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
|
267
267
|
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
|
268
|
-
if (this.prerelease[0] ===
|
|
268
|
+
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
|
269
269
|
if (isNaN(this.prerelease[1])) {
|
|
270
270
|
this.prerelease = [identifier, 0]
|
|
271
271
|
}
|
|
@@ -8,17 +8,21 @@ const lte = require('./lte')
|
|
|
8
8
|
const cmp = (a, op, b, loose) => {
|
|
9
9
|
switch (op) {
|
|
10
10
|
case '===':
|
|
11
|
-
if (typeof a === 'object')
|
|
11
|
+
if (typeof a === 'object') {
|
|
12
12
|
a = a.version
|
|
13
|
-
|
|
13
|
+
}
|
|
14
|
+
if (typeof b === 'object') {
|
|
14
15
|
b = b.version
|
|
16
|
+
}
|
|
15
17
|
return a === b
|
|
16
18
|
|
|
17
19
|
case '!==':
|
|
18
|
-
if (typeof a === 'object')
|
|
20
|
+
if (typeof a === 'object') {
|
|
19
21
|
a = a.version
|
|
20
|
-
|
|
22
|
+
}
|
|
23
|
+
if (typeof b === 'object') {
|
|
21
24
|
b = b.version
|
|
25
|
+
}
|
|
22
26
|
return a !== b
|
|
23
27
|
|
|
24
28
|
case '':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const SemVer = require('../classes/semver')
|
|
2
2
|
const parse = require('./parse')
|
|
3
|
-
const {re, t} = require('../internal/re')
|
|
3
|
+
const { re, t } = require('../internal/re')
|
|
4
4
|
|
|
5
5
|
const coerce = (version, options) => {
|
|
6
6
|
if (version instanceof SemVer) {
|
|
@@ -43,8 +43,9 @@ const coerce = (version, options) => {
|
|
|
43
43
|
re[t.COERCERTL].lastIndex = -1
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
if (match === null)
|
|
46
|
+
if (match === null) {
|
|
47
47
|
return null
|
|
48
|
+
}
|
|
48
49
|
|
|
49
50
|
return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options)
|
|
50
51
|
}
|
|
@@ -7,7 +7,10 @@ const inc = (version, release, options, identifier) => {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
try {
|
|
10
|
-
return new SemVer(
|
|
10
|
+
return new SemVer(
|
|
11
|
+
version instanceof SemVer ? version.version : version,
|
|
12
|
+
options
|
|
13
|
+
).inc(release, identifier).version
|
|
11
14
|
} catch (er) {
|
|
12
15
|
return null
|
|
13
16
|
}
|
|
@@ -4,7 +4,7 @@ const SEMVER_SPEC_VERSION = '2.0.0'
|
|
|
4
4
|
|
|
5
5
|
const MAX_LENGTH = 256
|
|
6
6
|
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
|
|
7
|
-
|
|
7
|
+
/* istanbul ignore next */ 9007199254740991
|
|
8
8
|
|
|
9
9
|
// Max safe segment length for coercion.
|
|
10
10
|
const MAX_SAFE_COMPONENT_LENGTH = 16
|
|
@@ -13,5 +13,5 @@ module.exports = {
|
|
|
13
13
|
SEMVER_SPEC_VERSION,
|
|
14
14
|
MAX_LENGTH,
|
|
15
15
|
MAX_SAFE_INTEGER,
|
|
16
|
-
MAX_SAFE_COMPONENT_LENGTH
|
|
16
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
17
17
|
}
|