Skip to content

Commit 1753910

Browse files
author
Elad Ben-Israel
authored
feat(jsii): enforce peer dependencies (#294)
If a jsii module exposes a type from a dependency in it's public API, jsii now enforces that this dependency is also defined as a "peer" instead of a normal dependency. This tells npm that if a user of this module already installed a compatible verison of this dependency in their closure, npm will pick the one installed by the user (as a peer) instead of fetching another version. jsii will also flag these dependencies as "peer" in the jsii spec. At the moment, this won't have implications on generated language packages, but in environments that have support for peer dependencies, we should make sure the module's metadata reflects this idea as well. A utility called "jsii-fix-peers" is included. It will inspect .jsii and package.json and will add "peerDependencies" to package.json for all dependencies that have types in the public API. Related to aws/aws-cdk#979
1 parent 4d135cf commit 1753910

17 files changed

Lines changed: 221 additions & 28 deletions

File tree

package-lock.json

Lines changed: 12 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jsii-calc-base/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"dependencies": {
3535
"@scope/jsii-calc-base-of-base": "^0.7.8"
3636
},
37+
"peerDependencies": {
38+
"@scope/jsii-calc-base-of-base": "^0.7.8"
39+
},
3740
"author": {
3841
"name": "Amazon Web Services",
3942
"url": "https://aws.amazon.com",

packages/jsii-calc-base/test/assembly.jsii

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"dependencies": {
1111
"@scope/jsii-calc-base-of-base": {
12+
"peer": true,
1213
"targets": {
1314
"dotnet": {
1415
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -102,5 +103,5 @@
102103
}
103104
},
104105
"version": "0.7.8",
105-
"fingerprint": "G+ZeFV6LQWFdp9ZuDgqN4rS10q/JBHuy0Wo8qaTK/t8="
106+
"fingerprint": "K1rAUs6WiQ5lF08T46B8v/5UL8T8Ot59e0Nc8rh2jiQ="
106107
}

packages/jsii-calc-lib/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"dependencies": {
3535
"@scope/jsii-calc-base": "^0.7.8"
3636
},
37+
"peerDependencies": {
38+
"@scope/jsii-calc-base": "^0.7.8"
39+
},
3740
"author": {
3841
"name": "Amazon Web Services",
3942
"url": "https://aws.amazon.com",

packages/jsii-calc-lib/test/assembly.jsii

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@scope/jsii-calc-base": {
1212
"dependencies": {
1313
"@scope/jsii-calc-base-of-base": {
14+
"peer": true,
1415
"targets": {
1516
"dotnet": {
1617
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -30,6 +31,7 @@
3031
"version": "0.7.8"
3132
}
3233
},
34+
"peer": true,
3335
"targets": {
3436
"dotnet": {
3537
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace",
@@ -351,5 +353,5 @@
351353
}
352354
},
353355
"version": "0.7.8",
354-
"fingerprint": "HzcyHys0b9gFmP4dogeIJmGE6GVtrSo/P0S54Vd/X8U="
356+
"fingerprint": "ENH00UDSeTnXKpvD3/vp0k8zyd+KCHzc9QWB151/gM8="
355357
}

packages/jsii-calc/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
"@scope/jsii-calc-lib": "^0.7.8",
3636
"jsii-calc-bundled": "^0.7.8"
3737
},
38+
"peerDependencies": {
39+
"@scope/jsii-calc-base": "^0.7.8",
40+
"@scope/jsii-calc-lib": "^0.7.8"
41+
},
3842
"devDependencies": {
3943
"@types/node": "^8.10.37",
4044
"jsii": "^0.7.8",

packages/jsii-calc/test/assembly.jsii

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@scope/jsii-calc-base": {
3838
"dependencies": {
3939
"@scope/jsii-calc-base-of-base": {
40+
"peer": true,
4041
"targets": {
4142
"dotnet": {
4243
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -56,6 +57,7 @@
5657
"version": "0.7.8"
5758
}
5859
},
60+
"peer": true,
5961
"targets": {
6062
"dotnet": {
6163
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace",
@@ -79,6 +81,7 @@
7981
"@scope/jsii-calc-base": {
8082
"dependencies": {
8183
"@scope/jsii-calc-base-of-base": {
84+
"peer": true,
8285
"targets": {
8386
"dotnet": {
8487
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -98,6 +101,7 @@
98101
"version": "0.7.8"
99102
}
100103
},
104+
"peer": true,
101105
"targets": {
102106
"dotnet": {
103107
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace",
@@ -117,6 +121,7 @@
117121
"version": "0.7.8"
118122
}
119123
},
124+
"peer": true,
120125
"targets": {
121126
"dotnet": {
122127
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace",
@@ -3407,5 +3412,5 @@
34073412
}
34083413
},
34093414
"version": "0.7.8",
3410-
"fingerprint": "jHSXTzCSZbwYMvLKpeZB6SE8hNgYgt9/2JF1ihM41SI="
3415+
"fingerprint": "Xn7Rk17rqR3AaMx3+ssxT0GR1sCWwz0OGC+C8QuLI3A="
34113416
}

packages/jsii-pacmak/test/expected.jsii-calc-base/dotnet/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId/.jsii

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"dependencies": {
1111
"@scope/jsii-calc-base-of-base": {
12+
"peer": true,
1213
"targets": {
1314
"dotnet": {
1415
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -102,5 +103,5 @@
102103
}
103104
},
104105
"version": "0.7.8",
105-
"fingerprint": "G+ZeFV6LQWFdp9ZuDgqN4rS10q/JBHuy0Wo8qaTK/t8="
106+
"fingerprint": "K1rAUs6WiQ5lF08T46B8v/5UL8T8Ot59e0Nc8rh2jiQ="
106107
}

packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/.jsii

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@scope/jsii-calc-base": {
1212
"dependencies": {
1313
"@scope/jsii-calc-base-of-base": {
14+
"peer": true,
1415
"targets": {
1516
"dotnet": {
1617
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -30,6 +31,7 @@
3031
"version": "0.7.8"
3132
}
3233
},
34+
"peer": true,
3335
"targets": {
3436
"dotnet": {
3537
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace",
@@ -351,5 +353,5 @@
351353
}
352354
},
353355
"version": "0.7.8",
354-
"fingerprint": "HzcyHys0b9gFmP4dogeIJmGE6GVtrSo/P0S54Vd/X8U="
356+
"fingerprint": "ENH00UDSeTnXKpvD3/vp0k8zyd+KCHzc9QWB151/gM8="
355357
}

packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/.jsii

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@scope/jsii-calc-base": {
3838
"dependencies": {
3939
"@scope/jsii-calc-base-of-base": {
40+
"peer": true,
4041
"targets": {
4142
"dotnet": {
4243
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -56,6 +57,7 @@
5657
"version": "0.7.8"
5758
}
5859
},
60+
"peer": true,
5961
"targets": {
6062
"dotnet": {
6163
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace",
@@ -79,6 +81,7 @@
7981
"@scope/jsii-calc-base": {
8082
"dependencies": {
8183
"@scope/jsii-calc-base-of-base": {
84+
"peer": true,
8285
"targets": {
8386
"dotnet": {
8487
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseOfBaseNamespace",
@@ -98,6 +101,7 @@
98101
"version": "0.7.8"
99102
}
100103
},
104+
"peer": true,
101105
"targets": {
102106
"dotnet": {
103107
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.BaseNamespace",
@@ -117,6 +121,7 @@
117121
"version": "0.7.8"
118122
}
119123
},
124+
"peer": true,
120125
"targets": {
121126
"dotnet": {
122127
"namespace": "Amazon.JSII.Tests.CalculatorNamespace.LibNamespace",
@@ -3407,5 +3412,5 @@
34073412
}
34083413
},
34093414
"version": "0.7.8",
3410-
"fingerprint": "jHSXTzCSZbwYMvLKpeZB6SE8hNgYgt9/2JF1ihM41SI="
3415+
"fingerprint": "Xn7Rk17rqR3AaMx3+ssxT0GR1sCWwz0OGC+C8QuLI3A="
34113416
}

0 commit comments

Comments
 (0)