ssh-config 4.1.3 → 4.1.6

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/Readme.md CHANGED
@@ -108,12 +108,14 @@ config.find({ Host: 'example1' })
108
108
  config.find(line => line.param == 'Host' && line.value == 'example1')
109
109
  ```
110
110
 
111
- ### `.remove` sections by Host or other criteria
111
+ ### `.remove` sections by Host / Match or function
112
112
 
113
113
  To remove sections, we can pass the section to `.remove(opts)`.
114
114
 
115
115
  ```js
116
116
  config.remove({ Host: 'example1' })
117
+ // or the ES2015 Array.prototype.find
118
+ config.remove(line => line.param == 'Host' && line.value == 'example1')
117
119
  ```
118
120
 
119
121
  ### `.append` sections
@@ -121,7 +123,7 @@ config.remove({ Host: 'example1' })
121
123
  Since the parsed config is a sub class of Array, you can append new sections with methods like `.push` or `.concat`.
122
124
 
123
125
  ```js
124
- config.push(SSHConfig.parse(`
126
+ config.push(...SSHConfig.parse(`
125
127
  Host ness
126
128
  HostName lochness.com
127
129
  User dinosaur
package/index.js CHANGED
@@ -79,7 +79,7 @@ class SSHConfig extends Array {
79
79
  }
80
80
 
81
81
  /**
82
- * find section by Host or Match
82
+ * find section by Host / Match or function
83
83
  */
84
84
  find(opts = {}) {
85
85
  if (typeof opts === 'function') return super.find(opts)
@@ -92,17 +92,22 @@ class SSHConfig extends Array {
92
92
  }
93
93
 
94
94
  /**
95
- * Remove section
95
+ * Remove section by Host / Match or function
96
96
  */
97
97
  remove(opts = {}) {
98
- if (!(opts && ('Host' in opts || 'Match' in opts))) {
99
- throw new Error('Can only remove by Host or Match')
100
- }
98
+ let index;
99
+
100
+ if (typeof opts === 'function') {
101
+ index = super.findIndex(opts);
101
102
 
102
- const index = typeof opts === 'function'
103
- ? super.findIndex(opts)
104
- : super.findIndex(line => compare(line, opts))
103
+ } else if (!(opts && ('Host' in opts || 'Match' in opts))) {
104
+ throw new Error('Can only remove by Host or Match');
105
105
 
106
+ } else {
107
+ index = super.findIndex(line => compare(line, opts));
108
+
109
+ }
110
+
106
111
  if (index >= 0) return this.splice(index, 1)
107
112
  }
108
113
 
@@ -457,6 +462,10 @@ class SSHConfig extends Array {
457
462
  config.push(node)
458
463
  config = node.config = new SSHConfig()
459
464
  }
465
+ else if (node.type === DIRECTIVE && !node.param) {
466
+ // blank lines at file end
467
+ config[config.length - 1].after += node.before
468
+ }
460
469
  else {
461
470
  config.push(node)
462
471
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ssh-config",
3
3
  "description": "SSH config parser and stringifier",
4
- "version": "4.1.3",
4
+ "version": "4.1.6",
5
5
  "author": "Chen Yangjian (https://www.cyj.me)",
6
6
  "repository": {
7
7
  "type": "git",
@@ -13,15 +13,19 @@
13
13
  "types"
14
14
  ],
15
15
  "devDependencies": {
16
+ "@types/mocha": "^9.1.0",
17
+ "@types/node": "^17.0.23",
16
18
  "eslint": "^7.17.0",
17
19
  "heredoc": "^1.3.1",
18
20
  "mocha": "^8.2.1",
19
- "nyc": "^15.1.0"
21
+ "nyc": "^15.1.0",
22
+ "typescript": "^4.6.3"
20
23
  },
21
24
  "scripts": {
22
25
  "lint": "eslint .",
23
- "test": "mocha --exit",
24
- "test:coverage": "nyc mocha --exit && nyc report --reporter=lcov"
26
+ "pretest": "tsc",
27
+ "test": "NODE_OPTIONS=--enable-source-maps mocha --exit --recursive",
28
+ "test:coverage": "nyc mocha --exit --recursive && nyc report --reporter=lcov"
25
29
  },
26
30
  "engine": {
27
31
  "node": ">= 10.0.0"
package/types/index.d.ts CHANGED
@@ -13,7 +13,7 @@ interface Directive {
13
13
  }
14
14
 
15
15
  interface Section extends Directive {
16
- config: SSHConfig;
16
+ config: SSHConfig<Line>;
17
17
  }
18
18
 
19
19
  interface Comment {
@@ -21,21 +21,26 @@ interface Comment {
21
21
  content: string;
22
22
  }
23
23
 
24
- type Line = Directive | Comment;
24
+ type Line = Section | Directive | Comment;
25
25
 
26
- export default class SSHConfig extends Array {
27
- static parse(text: string): SSHConfig;
28
- static stringify(config: SSHConfig): string;
26
+ declare class SSHConfig<T> extends Array<T> {
27
+ static parse(text: string): SSHConfig<Line>;
28
+ static stringify(config: SSHConfig<Line>): string;
29
+
30
+ static DIRECTIVE: ELine.DIRECTIVE;
31
+ static COMMENT: ELine.COMMENT;
29
32
 
30
33
  toString(): string;
31
34
 
32
35
  compute(host: string): Record<string, string>;
33
36
 
34
- find(predicate: (value: any, index: number, obj: any[]) => any);
37
+ find<T>(this: SSHConfig<T>, predicate: (line: T, index: number, config: T[]) => boolean): T;
35
38
  find(options: Record<string, string>): Line | Section;
36
39
 
37
40
  remove(options: Record<string, string>): Line | Section;
38
41
 
39
- append(options: Record<string, string>): SSHConfig;
40
- prepend(options: Record<string, string>): SSHConfig;
42
+ append(options: Record<string, string>): SSHConfig<Line>;
43
+ prepend(options: Record<string, string>): SSHConfig<Line>;
41
44
  }
45
+
46
+ export default class extends SSHConfig<Line> {}
package/History.md DELETED
@@ -1,187 +0,0 @@
1
- 4.1.3 / 2022-03-11
2
- ==================
3
-
4
- ## What's Changed
5
- * fix: IdentityAgent should be quoted if necessary by @cyjake in https://github.com/cyjake/ssh-config/pull/52
6
-
7
-
8
- **Full Changelog**: https://github.com/cyjake/ssh-config/compare/v4.1.2...v4.1.3
9
-
10
- 4.1.2 / 2022-01-20
11
- ==================
12
-
13
- ## What's Changed
14
- * docs: types field in package.json by @cyjake in https://github.com/cyjake/ssh-config/pull/50
15
-
16
-
17
- **Full Changelog**: https://github.com/cyjake/ssh-config/compare/v4.1.1...v4.1.2
18
-
19
- 4.1.1 / 2021-10-21
20
- ==================
21
-
22
- ## What's Changed
23
- * docs: `.prepend` and type definitions by @cyjake in https://github.com/cyjake/ssh-config/pull/47
24
- * fix: improper parsing of ProxyCommand with quotation marks by @tanhakabir in https://github.com/cyjake/ssh-config/pull/48
25
-
26
-
27
- **Full Changelog**: https://github.com/cyjake/ssh-config/compare/v4.1.0...v4.1.1
28
-
29
- 4.1.0 / 2021-10-20
30
- ==================
31
-
32
- ## What's Changed
33
- * test: switching to github actions by @cyjake in https://github.com/cyjake/ssh-config/pull/44
34
- * feat: add prepend function to prepend options onto config by @tanhakabir in https://github.com/cyjake/ssh-config/pull/45
35
- * build: switch to codecov by @cyjake in https://github.com/cyjake/ssh-config/pull/46
36
-
37
- ## New Contributors
38
- * @tanhakabir made her first contribution in https://github.com/cyjake/ssh-config/pull/45
39
-
40
- **Full Changelog**: https://github.com/cyjake/ssh-config/compare/v4.0.6...v4.1.0
41
-
42
- 4.0.6 / 2021-05-11
43
- ==================
44
-
45
- * fix: IdentityFile parameter value should be quoted if contains space
46
-
47
-
48
- 4.0.5 / 2021-01-08
49
- ==================
50
-
51
- * fix: multiple LocalForward values should be formartted into multiple lines
52
-
53
-
54
- 4.0.4 / 2020-09-01
55
- ==================
56
-
57
- * fix: should not quote directives like LocalForward (#38)
58
-
59
-
60
- 4.0.3 / 2020-08-24
61
- ==================
62
-
63
- * fix: quote values that contain white spaces (36)
64
-
65
-
66
- 4.0.2 / 2020-02-09
67
- ==================
68
-
69
- * fix: 'compute' fails when hosts contain regex chars #34 @roblourens
70
-
71
-
72
- 4.0.1 / 2020-02-01
73
- ==================
74
-
75
- * Fix: parsing `Host` values with trailing spaces
76
-
77
-
78
- 4.0.0 / 2020-01-09
79
- ==================
80
-
81
- * Fix: allow forwarding directives (and `CertificateFile`) to have multiple values (#30)
82
-
83
-
84
- 3.0.1 / 2020-01-07
85
- ==================
86
-
87
- * Fix: append new section to empty config (#27)
88
-
89
-
90
- 3.0.0 / 2019-12-12
91
- ==================
92
-
93
- * Breaking: prefer to separate sections with `\n\n` (#23, #24)
94
- * Breaking: drop `SSHConfig.find()`, please use `SSHConfig.prototype.find()` instead
95
-
96
-
97
- 2.0.0 / 2019-10-08
98
- ==================
99
-
100
- * Breaking: parse `Host` values as an Array to hold multiple patterns
101
- * Breaking: an extra line break will always be added when `.append()`ing config
102
- * Fix: `Host` can contain spaces if quoted with double quotes
103
- * Fix: quoted values can contain double quotes once they are escaped with backslash
104
- * Fix: escape + when converting patterns to regexp
105
- * Fix: parameter/value pairs separated with tab charactor
106
-
107
-
108
- 1.1.6 / 2019-04-02
109
- ==================
110
-
111
- * Fix: appending to empty config
112
-
113
-
114
- 1.1.5 / 2018-12-06
115
- ==================
116
-
117
- * Fix: auto insert newline when `.append()`ing existing config without trailing newlines. #15
118
-
119
-
120
- 1.1.3 / 2017-09-25
121
- ==================
122
-
123
- * Fix: appended config shall comply with existing style, otherwhise default to two spaces. Also an extra linebreak is added after the last line.
124
-
125
-
126
- 1.1.2 / 2017-09-22
127
- ==================
128
-
129
- * Fix: nagate patterns shall be matched first and fail early
130
-
131
-
132
- 1.1.1 / 2017-09-13
133
- ==================
134
-
135
- * Fix: values of `IdentityFile` will now be quoted if contain space.
136
- * Fix: quoted values will have their double quotations stripped while parsed, which is a slightly breaking behavior but I think a patch version will just be fine.
137
-
138
-
139
- 1.1.0 / 2017-09-07
140
- ==================
141
-
142
- * New: `config.append({ Host: '*' })`
143
-
144
- Allow appending sections via `config.append({ ... })` method. Closes #12.
145
-
146
-
147
- 1.0.1 / 2017-02-06
148
- ==================
149
-
150
- * Fix: trim spaces at value beginning and endding
151
- * Fix: make example east more compact
152
-
153
-
154
- 1.0.0 / 2016-05-05
155
- ==================
156
-
157
- * Fix: updated readme to be reflect 1.x changes
158
- * Breaking: parse into a simple ast
159
-
160
- This is a breaking change. The parse result is now a subclass of Array instead of vanila Object.
161
-
162
-
163
- 0.2.1 / 2015-11-17
164
- ==================
165
-
166
- * Fix: code style and one more test case
167
- * Merge pull request #7 from petemill/fix-leading-newline
168
- * Only add a newline between sections if there are previous lines. Fixes https://github.com/dotnil/ssh-config/issues/6
169
-
170
-
171
- 0.2.0 / 2015-07-07
172
- ==================
173
-
174
- * Added converage with istanbul
175
- * Added .append, .find, and .remove; fixes #4
176
- * Added documentations about said methods
177
- * Added badges about npm downloads, version, and build status
178
- * Added .travis.yml
179
- * Implemented .query and support pattern matching (poorly)
180
-
181
-
182
- 0.1.0 / 2015-01-12
183
- ==================
184
-
185
- * Init repo
186
- * Implemented `.parse` and `.stringify`
187
-
@@ -1,10 +0,0 @@
1
- import SSHConfig from './index';
2
-
3
- const config = SSHConfig.parse(`
4
- IdentityFile ~/.ssh/id_rsa
5
-
6
- Host ness
7
- HostName lochness.com
8
- `);
9
-
10
- console.log(config.toString());