bare-ipc 1.0.0 → 1.0.1

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 (3) hide show
  1. package/index.js +45 -47
  2. package/lib/errors.js +3 -3
  3. package/package.json +5 -4
package/index.js CHANGED
@@ -2,70 +2,71 @@ const Pipe = require('bare-pipe')
2
2
  const { Duplex } = require('bare-stream')
3
3
  const errors = require('./lib/errors')
4
4
 
5
- const IPC = module.exports = exports = class IPC extends Duplex {
6
- constructor (port) {
7
- const {
8
- incoming,
9
- outgoing
10
- } = port
5
+ const IPC =
6
+ (module.exports =
7
+ exports =
8
+ class IPC extends Duplex {
9
+ constructor(port) {
10
+ const { incoming, outgoing } = port
11
11
 
12
- super()
12
+ super()
13
13
 
14
- this._incoming = new Pipe(incoming)
15
- this._outgoing = new Pipe(outgoing)
14
+ this._incoming = new Pipe(incoming)
15
+ this._outgoing = new Pipe(outgoing)
16
16
 
17
- this._pendingWrite = null
17
+ this._pendingWrite = null
18
18
 
19
- this._incoming
20
- .on('data', this._ondata.bind(this))
21
- .on('end', this._onend.bind(this))
19
+ this._incoming
20
+ .on('data', this._ondata.bind(this))
21
+ .on('end', this._onend.bind(this))
22
22
 
23
- this._outgoing
24
- .on('drain', this._ondrain.bind(this))
25
- }
23
+ this._outgoing.on('drain', this._ondrain.bind(this))
24
+ }
26
25
 
27
- _write (chunk, encoding, cb) {
28
- if (this._outgoing.write(chunk)) cb(null)
29
- else this._pendingWrite = cb
30
- }
26
+ _write(chunk, encoding, cb) {
27
+ if (this._outgoing.write(chunk)) cb(null)
28
+ else this._pendingWrite = cb
29
+ }
31
30
 
32
- _final (cb) {
33
- this._outgoing.end()
34
- cb(null)
35
- }
31
+ _final(cb) {
32
+ this._outgoing.end()
33
+ cb(null)
34
+ }
36
35
 
37
- _ondata (data) {
38
- this.push(data)
39
- }
36
+ _ondata(data) {
37
+ this.push(data)
38
+ }
40
39
 
41
- _onend () {
42
- this.push(null)
43
- }
40
+ _onend() {
41
+ this.push(null)
42
+ }
44
43
 
45
- _ondrain () {
46
- if (this._pendingWrite === null) return
47
- const cb = this._pendingWrite
48
- this._pendingWrite = null
49
- cb(null)
50
- }
51
- }
44
+ _ondrain() {
45
+ if (this._pendingWrite === null) return
46
+ const cb = this._pendingWrite
47
+ this._pendingWrite = null
48
+ cb(null)
49
+ }
50
+ })
52
51
 
53
52
  class IPCPort {
54
- constructor (incoming, outgoing) {
53
+ constructor(incoming, outgoing) {
55
54
  this.incoming = incoming
56
55
  this.outgoing = outgoing
57
56
  this.detached = false
58
57
  }
59
58
 
60
- connect () {
59
+ connect() {
61
60
  const ipc = new IPC(this)
62
61
  this.detached = true
63
62
  return ipc
64
63
  }
65
64
 
66
- [Symbol.for('bare.detach')] () {
65
+ [Symbol.for('bare.detach')]() {
67
66
  if (this.detached) {
68
- throw errors.ALREADY_CONNECTED('Port has already started receiving messages')
67
+ throw errors.ALREADY_CONNECTED(
68
+ 'Port has already started receiving messages'
69
+ )
69
70
  }
70
71
 
71
72
  this.detached = true
@@ -73,17 +74,14 @@ class IPCPort {
73
74
  return [this.incoming, this.outgoing]
74
75
  }
75
76
 
76
- static [Symbol.for('bare.attach')] ([incoming, outgoing]) {
77
+ static [Symbol.for('bare.attach')]([incoming, outgoing]) {
77
78
  return new this(incoming, outgoing)
78
79
  }
79
80
  }
80
81
 
81
- exports.open = function open (opts) {
82
+ exports.open = function open(opts) {
82
83
  const a = Pipe.pipe(opts)
83
84
  const b = Pipe.pipe(opts)
84
85
 
85
- return [
86
- new IPCPort(a[0], b[1], opts),
87
- new IPCPort(b[0], a[1], opts)
88
- ]
86
+ return [new IPCPort(a[0], b[1], opts), new IPCPort(b[0], a[1], opts)]
89
87
  }
package/lib/errors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = class IPCError extends Error {
2
- constructor (msg, code, fn = IPCError) {
2
+ constructor(msg, code, fn = IPCError) {
3
3
  super(`${code}: ${msg}`)
4
4
  this.code = code
5
5
 
@@ -8,11 +8,11 @@ module.exports = class IPCError extends Error {
8
8
  }
9
9
  }
10
10
 
11
- get name () {
11
+ get name() {
12
12
  return 'IPCError'
13
13
  }
14
14
 
15
- static ALREADY_CONNECTED (msg) {
15
+ static ALREADY_CONNECTED(msg) {
16
16
  return new IPCError(msg, 'ALREADY_CONNECTED', IPCError.ALREADY_CONNECTED)
17
17
  }
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ipc",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Lightweight pipe-based IPC for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -12,7 +12,7 @@
12
12
  "lib"
13
13
  ],
14
14
  "scripts": {
15
- "test": "standard && bare test.js"
15
+ "test": "prettier . --check && bare test.js"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",
@@ -25,11 +25,12 @@
25
25
  },
26
26
  "homepage": "https://github.com/holepunchto/bare-ipc#readme",
27
27
  "dependencies": {
28
- "bare-pipe": "^3.3.2",
28
+ "bare-pipe": "^4.0.0",
29
29
  "bare-stream": "^2.1.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "brittle": "^3.2.1",
33
- "standard": "^17.0.0"
33
+ "prettier": "^3.4.1",
34
+ "prettier-config-standard": "^7.0.0"
34
35
  }
35
36
  }