jsii-diff 1.89.0 → 1.90.0

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.
@@ -0,0 +1,158 @@
1
+ # Changes jsii-diff considers breaking
2
+
3
+ jsii-diff considers a change breaking if there exists a program that would
4
+ successfully compile against a previous version of the library, but would fail
5
+ to compile against the new proposed version of the library.
6
+
7
+ Some rules are specific to one of TypeScript, Java, C#, Python and Go, but as a
8
+ jsii user you have to take all of these into account.
9
+
10
+ This document will go over the most common changes you want to make that jsii-diff
11
+ will consider breaking, why that is, and what to do about it.
12
+
13
+ ## Making properties optional
14
+
15
+ By far the most commonly asked question is: *Why am I not allowed to turn this required property into an optional property?*
16
+
17
+ The answer is:
18
+
19
+ > [!IMPORTANT]
20
+ > You are allowed to make *inputs* optional, but you are not allowed to make *outputs* optional.
21
+
22
+ This often manifests itself as a class that takes a struct, and then copies some of the values onto itself as properties. For example:
23
+
24
+ ```ts
25
+ interface DogOptions {
26
+ readonly name: string; // This 'name: string' is an INPUT
27
+ }
28
+
29
+ class Dog {
30
+ public readonly name: string; // This 'name: string' is an OUTPUT
31
+
32
+ constructor(options: DogOptions) {
33
+ this.name = options.name;
34
+ }
35
+ }
36
+ ```
37
+
38
+ You *are* allowed to make `DogOptions.name` optional! Someone could have written the program:
39
+
40
+ ```ts
41
+ // Still valid. 'name' takes either 'string' or 'undefined', and we are giving it a 'string'
42
+ new Dog({ name: 'Fido' });
43
+ ```
44
+
45
+ You are *not* allowed to make `Dog.name` optional though. Someone could have written the program:
46
+
47
+ ```ts
48
+ const d = new Dog({ name: 'Fido' });
49
+ console.log(d.name.toLowerCase());
50
+
51
+ // Not valid anymore after the type of `d.name` has changed into `string | undefined`.
52
+ // 'd.name' can be undefined, and we have to account for that with an `if`!
53
+ ```
54
+
55
+ ### Optional properties: how to solve
56
+
57
+ You'll have to make the input optional without making the output optional. That raises
58
+ the question, what do we do when we have to produce an output value that we don't have?
59
+ The simplest solution is to throw an exception:
60
+
61
+ ```ts
62
+ interface DogOptions {
63
+ readonly name?: string;
64
+ }
65
+
66
+ class Dog {
67
+ private readonly _name?: string;
68
+
69
+ constructor(options: DogOptions) {
70
+ this._name = options.name;
71
+ }
72
+
73
+ public get name(): string {
74
+ if (!this._name) {
75
+ throw new Error('Dog does not have a name');
76
+ }
77
+ return this._name;
78
+ }
79
+ }
80
+ ```
81
+
82
+ This doesn't break any existing users: all their Dogs will have names, so they will not hit the exception path.
83
+
84
+ For new users that fail to give their Dog a name, presumably they will be aware that their Dog doesn't have a name, so they can avoid trying to read it. If you want to give them a way to avoid the exception, add a `public get hasName(): boolean` field so they can test for the existence of the name before accessing it.
85
+
86
+ ## Changing types to superclass/subclass
87
+
88
+ When changing types involved in an operation, you run into a similar issue as with changing the optionality of a property:
89
+
90
+ > [!IMPORTANT]
91
+ > You are allowed to make *inputs* accept a supertype, but you are only allowed to make *outputs* return a subtype.
92
+
93
+ This manifests when you want to introduce a new common supertype from two or more existing types. For example,
94
+ let's say we have Dogs and Cats, and some operations that only work on some of them:
95
+
96
+ ```ts
97
+ class Dog { }
98
+ class Cat { }
99
+
100
+ function feed(animal: Cat): void;
101
+ function pet(animal: Dog): void;
102
+ function getFromKennel(name: string): Dog;
103
+ ```
104
+
105
+ We would like to clean up this code and introduce a new class, `Animal`, that will be a new supertype to both Dog and Cat:
106
+
107
+ ```ts
108
+ class Animal { }
109
+ class Dog extends Animal { }
110
+ class Cat extends Animal { }
111
+ ```
112
+
113
+ Now, what can we do with our operations? Can we make `feed` and `pet` accept an `Animal`?
114
+
115
+ ```ts
116
+ function feed(animal: Animal): void;
117
+ function pet(animal: Animal): void;
118
+
119
+ // Yes! Code from before still works:
120
+ feed(new Cat());
121
+ feed(new Dog());
122
+ ```
123
+
124
+ Can we make `getFromKennel()` return an `Animal`?
125
+
126
+ ```ts
127
+ function getFromKennel(name: string): Animal;
128
+
129
+ // NO! Someone could have written this, and this no longer compiles without an 'instanceof' check!
130
+ const d: Dog = getFromKennel('Fido');
131
+ ```
132
+
133
+ > [!WARNING]
134
+ > Depending on your definitions of `Dog`, `Cat` and `Animal`, the above code might actually compile just
135
+ > fine in TypeScript. That is because of TypeScript's [structural typing](https://www.typescriptlang.org/docs/handbook/type-compatibility.html),
136
+ > which doesn't (always) look at the name of the type, but just at the fields on it. If the fields are the
137
+ > same, TypeScript may consider the types "close enough" and allow the assignment. The above TypeScript
138
+ > behavior may make it possible to accidentally build APIs that can never be used in nominally typed
139
+ > languages like Java or C#. jsii-diff will do nominal checks on function signatures, but it cannot
140
+ > do nominal checks on function implementations.
141
+
142
+ ### Extracting a supertype: how to solve
143
+
144
+ `getFromKennel()` must keep returning a `Dog`, so we have to make an alternative function for the generic case and forward the implementation:
145
+
146
+ ```ts
147
+ function getAnimalFromKennel(name: string): Animal {
148
+ return /* ... */;
149
+ }
150
+
151
+ function getFromKennel(name: string): Dog {
152
+ const x = getAnimalFromKennel(name);
153
+ if (!(x instanceof Dog)) {
154
+ throw new Error(`I expected ${name} to be a Dog`);
155
+ }
156
+ return x;
157
+ }
158
+ ```
package/README.md CHANGED
@@ -126,6 +126,10 @@ abstract members yet.
126
126
  for subclassing, but treating them as such would limit the evolvability of
127
127
  libraries too much.
128
128
 
129
+ ## Help! jsii-diff is marking my changes as breaking
130
+
131
+ See [BREAKING_CHANGES.md](./BREAKING_CHANGES.md) for more information.
132
+
129
133
  ## License
130
134
 
131
135
  __jsii-diff__ is distributed under the
package/lib/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** The qualified version number for this JSII compiler. */
2
- export declare const VERSION = "1.89.0 (build 2f74b3e)";
2
+ export declare const VERSION = "1.90.0 (build d6bdb4d)";
3
3
  //# sourceMappingURL=version.d.ts.map
package/lib/version.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- // Generated at 2023-09-20T22:42:38Z by generate.sh
2
+ // Generated at 2023-10-06T20:47:36Z by generate.sh
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.VERSION = void 0;
5
5
  /** The qualified version number for this JSII compiler. */
6
- exports.VERSION = '1.89.0 (build 2f74b3e)';
6
+ exports.VERSION = '1.90.0 (build d6bdb4d)';
7
7
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsii-diff",
3
- "version": "1.89.0",
3
+ "version": "1.90.0",
4
4
  "description": "Assembly comparison for jsii",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -33,10 +33,10 @@
33
33
  "package": "package-js"
34
34
  },
35
35
  "dependencies": {
36
- "@jsii/check-node": "1.89.0",
37
- "@jsii/spec": "^1.89.0",
36
+ "@jsii/check-node": "1.90.0",
37
+ "@jsii/spec": "^1.90.0",
38
38
  "fs-extra": "^10.1.0",
39
- "jsii-reflect": "^1.89.0",
39
+ "jsii-reflect": "^1.90.0",
40
40
  "log4js": "^6.9.1",
41
41
  "yargs": "^16.2.0"
42
42
  },
@@ -44,7 +44,7 @@
44
44
  "@types/fs-extra": "^9.0.13",
45
45
  "@types/tar-fs": "^2.0.2",
46
46
  "jest-expect-message": "^1.1.3",
47
- "jsii": "^1.89.0",
48
- "jsii-build-tools": "^1.89.0"
47
+ "jsii": "^1.90.0",
48
+ "jsii-build-tools": "^1.90.0"
49
49
  }
50
50
  }