codify-plugin-lib 1.0.15 → 1.0.17

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.
@@ -12,4 +12,5 @@ export declare class ChangeSet {
12
12
  static createForNullCurrentConfig(desiredConfig: ResourceConfig): ChangeSet;
13
13
  static calculateParameterChangeSet(prev: ResourceConfig, next: ResourceConfig): ParameterChange[];
14
14
  static combineResourceOperations(prev: ResourceOperation, next: ResourceOperation): ResourceOperation;
15
+ static isSame(a: unknown, b: unknown): boolean;
15
16
  }
@@ -39,7 +39,7 @@ class ChangeSet {
39
39
  delete filteredPrev[k];
40
40
  continue;
41
41
  }
42
- if (filteredPrev[k] !== filteredNext[k]) {
42
+ if (!ChangeSet.isSame(filteredPrev[k], filteredNext[k])) {
43
43
  parameterChangeSet.push({
44
44
  name: k,
45
45
  previousValue: v,
@@ -84,5 +84,13 @@ class ChangeSet {
84
84
  const indexNext = orderOfOperations.indexOf(next);
85
85
  return orderOfOperations[Math.max(indexPrev, indexNext)];
86
86
  }
87
+ static isSame(a, b) {
88
+ if (Array.isArray(a) && Array.isArray(b)) {
89
+ const sortedPrev = a.map((x) => x).sort();
90
+ const sortedNext = b.map((x) => x).sort();
91
+ return JSON.stringify(sortedPrev) === JSON.stringify(sortedNext);
92
+ }
93
+ return a === b;
94
+ }
87
95
  }
88
96
  exports.ChangeSet = ChangeSet;
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { SpawnOptions } from 'child_process';
3
3
  export declare enum SpawnStatus {
4
- SUCCESS = 0,
5
- ERROR = 1
4
+ SUCCESS = "success",
5
+ ERROR = "error"
6
6
  }
7
7
  export interface SpawnResult {
8
8
  status: SpawnStatus;
@@ -7,13 +7,17 @@ exports.isDebug = exports.codifySpawn = exports.SpawnStatus = void 0;
7
7
  const promise_spawn_1 = __importDefault(require("@npmcli/promise-spawn"));
8
8
  var SpawnStatus;
9
9
  (function (SpawnStatus) {
10
- SpawnStatus[SpawnStatus["SUCCESS"] = 0] = "SUCCESS";
11
- SpawnStatus[SpawnStatus["ERROR"] = 1] = "ERROR";
10
+ SpawnStatus["SUCCESS"] = "success";
11
+ SpawnStatus["ERROR"] = "error";
12
12
  })(SpawnStatus || (exports.SpawnStatus = SpawnStatus = {}));
13
13
  async function codifySpawn(cmd, args, opts, extras) {
14
14
  try {
15
15
  const stdio = isDebug() ? 'inherit' : 'pipe';
16
16
  const result = await (0, promise_spawn_1.default)(cmd, args ?? [], { ...opts, stdio, stdioString: true, shell: true }, extras);
17
+ if (isDebug()) {
18
+ console.log(`codifySpawn result for: ${cmd}`);
19
+ console.log(JSON.stringify(result, null, 2));
20
+ }
17
21
  const status = (result.code === 0 && !result.stderr)
18
22
  ? SpawnStatus.SUCCESS
19
23
  : SpawnStatus.ERROR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -74,6 +74,38 @@ describe('Change set tests', () => {
74
74
  expect(cs[0].operation).to.eq(ParameterOperation.NOOP);
75
75
  })
76
76
 
77
+ it ('handles simple arrays', () => {
78
+ const before = {
79
+ type: 'config',
80
+ propA: ['a', 'b', 'c'],
81
+ }
82
+
83
+ const after = {
84
+ type: 'config',
85
+ propA: ['b', 'a', 'c'],
86
+ }
87
+
88
+ const cs = ChangeSet.calculateParameterChangeSet(before, after);
89
+ expect(cs.length).to.eq(1);
90
+ expect(cs[0].operation).to.eq(ParameterOperation.NOOP);
91
+ })
92
+
93
+ it ('handles simple arrays', () => {
94
+ const before = {
95
+ type: 'config',
96
+ propA: ['a', 'b'],
97
+ }
98
+
99
+ const after = {
100
+ type: 'config',
101
+ propA: ['b', 'a', 'c'],
102
+ }
103
+
104
+ const cs = ChangeSet.calculateParameterChangeSet(before, after);
105
+ expect(cs.length).to.eq(1);
106
+ expect(cs[0].operation).to.eq(ParameterOperation.MODIFY);
107
+ })
108
+
77
109
  it ('determines the order of operations 1', () => {
78
110
  const op1 = ResourceOperation.MODIFY;
79
111
  const op2 = ResourceOperation.CREATE
@@ -97,4 +129,39 @@ describe('Change set tests', () => {
97
129
  const opResult = ChangeSet.combineResourceOperations(op1, op2);
98
130
  expect(opResult).to.eq(ResourceOperation.MODIFY);
99
131
  })
132
+
133
+ it('correctly determines array equality', () => {
134
+ const arrA = ['a', 'b', 'd'];
135
+ const arrB = ['a', 'b', 'd'];
136
+
137
+ expect(ChangeSet.isSame(arrA, arrB)).to.be.true;
138
+ })
139
+
140
+ it('correctly determines array equality 2', () => {
141
+ const arrA = ['a', 'b'];
142
+ const arrB = ['a', 'b', 'd'];
143
+
144
+ expect(ChangeSet.isSame(arrA, arrB)).to.be.false;
145
+ })
146
+
147
+ it('correctly determines array equality 3', () => {
148
+ const arrA = ['b', 'a', 'd'];
149
+ const arrB = ['a', 'b', 'd'];
150
+
151
+ expect(ChangeSet.isSame(arrA, arrB)).to.be.true;
152
+ })
153
+
154
+ it('correctly determines array equality 4', () => {
155
+ const arrA = [{ key1: 'a' }, { key1: 'a' }, { key1: 'a' }];
156
+ const arrB = [{ key1: 'a' }, { key1: 'a' }, { key1: 'b' }];
157
+
158
+ expect(ChangeSet.isSame(arrA, arrB)).to.be.false;
159
+ })
160
+
161
+ it('correctly determines array equality 5', () => {
162
+ const arrA = [{ key1: 'b' }, { key1: 'a' }, { key1: 'a' }];
163
+ const arrB = [{ key1: 'a' }, { key1: 'a' }, { key1: 'b' }];
164
+
165
+ expect(ChangeSet.isSame(arrA, arrB)).to.be.false;
166
+ })
100
167
  })
@@ -60,7 +60,7 @@ export class ChangeSet {
60
60
  continue;
61
61
  }
62
62
 
63
- if (filteredPrev[k] !== filteredNext[k]) {
63
+ if (!ChangeSet.isSame(filteredPrev[k], filteredNext[k])) {
64
64
  parameterChangeSet.push({
65
65
  name: k,
66
66
  previousValue: v,
@@ -114,4 +114,15 @@ export class ChangeSet {
114
114
 
115
115
  return orderOfOperations[Math.max(indexPrev, indexNext)];
116
116
  }
117
+
118
+ static isSame(a: unknown, b: unknown): boolean {
119
+ if (Array.isArray(a) && Array.isArray(b)) {
120
+ const sortedPrev = a.map((x) => x).sort();
121
+ const sortedNext = b.map((x) => x).sort();
122
+
123
+ return JSON.stringify(sortedPrev) === JSON.stringify(sortedNext);
124
+ }
125
+
126
+ return a === b;
127
+ }
117
128
  }
@@ -2,8 +2,8 @@ import promiseSpawn from '@npmcli/promise-spawn';
2
2
  import { SpawnOptions } from 'child_process';
3
3
 
4
4
  export enum SpawnStatus {
5
- SUCCESS,
6
- ERROR,
5
+ SUCCESS = 'success',
6
+ ERROR = 'error',
7
7
  }
8
8
 
9
9
  export interface SpawnResult {
@@ -31,6 +31,11 @@ export async function codifySpawn(
31
31
  extras
32
32
  );
33
33
 
34
+ if (isDebug()) {
35
+ console.log(`codifySpawn result for: ${cmd}`);
36
+ console.log(JSON.stringify(result, null, 2))
37
+ }
38
+
34
39
  const status = (result.code === 0 && !result.stderr)
35
40
  ? SpawnStatus.SUCCESS
36
41
  : SpawnStatus.ERROR;
@@ -48,5 +53,5 @@ export async function codifySpawn(
48
53
  }
49
54
 
50
55
  export function isDebug(): boolean {
51
- return process.env.DEBUG != null && process.env.DEBUG.includes('codify');
56
+ return process.env.DEBUG != null && process.env.DEBUG.includes('codify'); // TODO: replace with debug library
52
57
  }