@cloud-cli/dns 2.0.2 → 2.0.3

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/dist/index.js CHANGED
@@ -42,14 +42,8 @@ function addDnsConfig() {
42
42
  Object.assign(dnsConfig, getConfig('dns'));
43
43
  }
44
44
  function save(list) {
45
- const targets = list.reduce((all, next) => {
46
- var _a;
47
- all[_a = next.target] || (all[_a] = []);
48
- all[next.target].push(next.domain);
49
- return all;
50
- }, {});
51
- const txt = Object.entries(targets).map(([ip, domains]) => `${ip} ${domains.join(' ')}`);
52
- fs.writeFileSync(filePath, txt.join('\n').trim());
45
+ let lines = list.map(next => next.target + ' ' + next.domain);
46
+ fs.writeFileSync(filePath, lines.join('\n').trim());
53
47
  }
54
48
  export function parseDNSLine(line) {
55
49
  const [ip, ...domains] = line.split(/\s+/);
@@ -59,12 +59,11 @@ describe('dns', () => {
59
59
  dns.add({ domain: 'foo', target: '2.3.4.5' });
60
60
  dns.add({ domain: 'bar', target: '2.3.4.5' });
61
61
  dns.add({ domain: 'baz' });
62
- const lines = ['2.3.4.5 foo bar', '127.0.0.1 baz'];
63
62
  expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo');
64
- expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo bar');
65
- expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), lines.join('\n'));
63
+ expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo\n2.3.4.5 bar');
64
+ expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo\n2.3.4.5 bar\n127.0.0.1 baz');
66
65
  dns.remove({ domain: 'baz' });
67
- expect(text).toBe(lines[0]);
66
+ expect(text).toBe('2.3.4.5 foo\n2.3.4.5 bar');
68
67
  });
69
68
  describe('reload', () => {
70
69
  it('should reload the DNS service', async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-cli/dns",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
package/src/index.spec.ts CHANGED
@@ -73,14 +73,12 @@ describe('dns', () => {
73
73
  dns.add({ domain: 'bar', target: '2.3.4.5' });
74
74
  dns.add({ domain: 'baz' });
75
75
 
76
- const lines = ['2.3.4.5 foo bar', '127.0.0.1 baz'];
77
-
78
76
  expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo');
79
- expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo bar');
80
- expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), lines.join('\n'));
77
+ expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo\n2.3.4.5 bar');
78
+ expect(fs.writeFileSync).toHaveBeenCalledWith(expect.any(String), '2.3.4.5 foo\n2.3.4.5 bar\n127.0.0.1 baz');
81
79
 
82
80
  dns.remove({ domain: 'baz' });
83
- expect(text).toBe(lines[0]);
81
+ expect(text).toBe('2.3.4.5 foo\n2.3.4.5 bar');
84
82
  });
85
83
 
86
84
  describe('reload', () => {
package/src/index.ts CHANGED
@@ -64,15 +64,8 @@ function addDnsConfig() {
64
64
  }
65
65
 
66
66
  function save(list: DomainAndTarget[]) {
67
- const targets: Record<string, string[]> = list.reduce((all, next) => {
68
- all[next.target] ||= [];
69
- all[next.target].push(next.domain);
70
- return all;
71
- }, {});
72
-
73
- const txt = Object.entries(targets).map(([ip, domains]) => `${ip} ${domains.join(' ')}`);
74
-
75
- fs.writeFileSync(filePath, txt.join('\n').trim());
67
+ let lines = list.map(next => next.target + ' ' + next.domain);
68
+ fs.writeFileSync(filePath, lines.join('\n').trim());
76
69
  }
77
70
 
78
71
  export function parseDNSLine(line: string): DomainAndTarget[] {