Skip to content

Commit f82e0ac

Browse files
authored
feat: intersection types (#4929)
Add support for intersection types to the rest of the jsii toolkit. This is currently using a prerelease version of the jsii compiler drafted here: aws/jsii-compiler#2325 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
1 parent df85a80 commit f82e0ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2233
-402
lines changed

packages/@jsii/kernel/src/kernel.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import * as onExit from './on-exit';
1212
import * as wire from './serialization';
1313
import * as tar from './tar-cache';
1414

15+
export const ASSEMBLY_SUPPORTED_FEATURES: spec.JsiiFeature[] = [
16+
'intersection-types',
17+
];
18+
1519
export const enum JsiiErrorType {
1620
JSII_FAULT = '@jsii/kernel.Fault',
1721
RUNTIME_ERROR = '@jsii/kernel.RuntimeError',
@@ -156,7 +160,12 @@ export class Kernel {
156160
let assmSpec: spec.Assembly;
157161
try {
158162
assmSpec = this.#debugTime(
159-
() => spec.loadAssemblyFromPath(packageDir, this.validateAssemblies),
163+
() =>
164+
spec.loadAssemblyFromPath(
165+
packageDir,
166+
this.validateAssemblies,
167+
ASSEMBLY_SUPPORTED_FEATURES,
168+
),
160169
`loadAssemblyFromPath(${packageDir})`,
161170
);
162171
} catch (e: any) {

packages/@jsii/runtime/test/kernel-host.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { api } from '@jsii/kernel';
1+
import { api, ASSEMBLY_SUPPORTED_FEATURES } from '@jsii/kernel';
22
import * as spec from '@jsii/spec';
33
import { loadAssemblyFromPath } from '@jsii/spec';
44
import * as child from 'child_process';
@@ -89,6 +89,9 @@ function loadRequest(library: string): api.LoadRequest {
8989
function loadAssembly(): spec.Assembly {
9090
return loadAssemblyFromPath(
9191
path.resolve(require.resolve(`${library}/package.json`), '..'),
92+
true,
93+
// Features that the kernel we are wrapping supports
94+
ASSEMBLY_SUPPORTED_FEATURES,
9295
);
9396
}
9497

packages/@jsii/spec/src/assembly-utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as path from 'path';
33
import * as zlib from 'zlib';
44

55
import {
6-
ALL_TYPESYSTEM_ENFORCED_FEATURES,
76
Assembly,
87
SPEC_FILE_NAME,
98
SPEC_FILE_NAME_COMPRESSED,
@@ -123,13 +122,13 @@ const failNoReadfileProvided = (filename: string) => {
123122
* @param assemblyBuffer buffer containing SPEC_FILE_NAME contents
124123
* @param readFile a callback to use for reading additional support files
125124
* @param validate whether or not to validate the assembly
126-
* @param supportedFeatures the set of supported features (default: all features enforced by the type system)
125+
* @param supportedFeatures the set of supported features (default: no new features since the first jsii release)
127126
*/
128127
export function loadAssemblyFromBuffer(
129128
assemblyBuffer: Buffer,
130129
readFile: (filename: string) => Buffer = failNoReadfileProvided,
131130
validate = true,
132-
supportedFeatures: string[] = ALL_TYPESYSTEM_ENFORCED_FEATURES,
131+
supportedFeatures: string[] = [],
133132
): Assembly {
134133
let contents = JSON.parse(assemblyBuffer.toString('utf-8'));
135134

@@ -148,7 +147,7 @@ export function loadAssemblyFromBuffer(
148147
);
149148
if (unsupported.length > 0) {
150149
throw new Error(
151-
`This jsii tool cannot load the given assembly; using unsupported feature(s): ${unsupported.join(', ')}`,
150+
`This jsii tool cannot load the given assembly; using unsupported feature(s): ${unsupported.join(', ')} (supported features: ${supportedFeatures.join(', ')})`,
152151
);
153152
}
154153

packages/@jsii/spec/src/assembly.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,35 +1094,6 @@ export function describeTypeReference(type?: TypeReference): string {
10941094
*/
10951095
export type JsiiFeature = 'intersection-types' | 'class-covariant-overrides';
10961096

1097-
/**
1098-
* For every feature, is it enforced by the type system?
1099-
*
1100-
* Effectively: if a jsii tools links against the most recent version of the
1101-
* spec, is the TypeScript type system going to ensure that they must have
1102-
* support for a given new feature, through exhaustiveness checking?
1103-
*
1104-
* (This map also forces completeness, so we are guaranteed to have a string
1105-
* value for every possible `JsiiFeature` type branch).
1106-
*/
1107-
const IS_FEATURE_TYPESYSTEM_ENFORCED: Record<JsiiFeature, boolean> = {
1108-
'intersection-types': true,
1109-
'class-covariant-overrides': false,
1110-
};
1111-
1112-
/**
1113-
* A list of all jsii extension features
1114-
*/
1115-
export const ALL_FEATURES = Object.keys(IS_FEATURE_TYPESYSTEM_ENFORCED);
1116-
1117-
/**
1118-
* A list of all jsii extension features
1119-
*/
1120-
export const ALL_TYPESYSTEM_ENFORCED_FEATURES = Object.entries(
1121-
IS_FEATURE_TYPESYSTEM_ENFORCED,
1122-
)
1123-
.filter(([_, v]) => v)
1124-
.map(([k, _]) => k);
1125-
11261097
/**
11271098
* Determines whether an entity is deprecated.
11281099
*

packages/@scope/jsii-calc-base-of-base/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"test:update": "yarn build && UPDATE_DIFF=1 yarn test"
3131
},
3232
"devDependencies": {
33-
"jsii": "5.9.1",
33+
"jsii": "5.9.6",
3434
"jsii-build-tools": "^0.0.0",
35-
"jsii-rosetta": "^5.9.1"
35+
"jsii-rosetta": "^5.9.6"
3636
},
3737
"jsii": {
3838
"outdir": "dist",

packages/@scope/jsii-calc-base-of-base/test/assembly.jsii

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"description": "An example transitive dependency for jsii-calc.",
1111
"homepage": "https://github.com/aws/jsii",
12-
"jsiiVersion": "5.9.1",
12+
"jsiiVersion": "5.9.6",
1313
"license": "Apache-2.0",
1414
"metadata": {
1515
"jsii": {
@@ -169,5 +169,5 @@
169169
}
170170
},
171171
"version": "2.1.1",
172-
"fingerprint": "aYxN6OFk7UbVs1sLXw8gQJwhedbyv9+wGNPYiMZsxsM="
172+
"fingerprint": "xT3ki285s4Oa3XH7pWYl1ZcUwKM/TNBnRDafyUmYtHI="
173173
}

packages/@scope/jsii-calc-base/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
"@scope/jsii-calc-base-of-base": "^2.1.1"
3636
},
3737
"devDependencies": {
38-
"jsii": "5.9.1",
38+
"jsii": "5.9.6",
3939
"jsii-build-tools": "^0.0.0",
40-
"jsii-rosetta": "^5.9.1"
40+
"jsii-rosetta": "^5.9.6"
4141
},
4242
"jsii": {
4343
"metadata": {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"description": "An example direct dependency for jsii-calc.",
4141
"homepage": "https://github.com/aws/jsii",
42-
"jsiiVersion": "5.9.1",
42+
"jsiiVersion": "5.9.6",
4343
"license": "Apache-2.0",
4444
"metadata": {
4545
"jsii": {
@@ -210,5 +210,5 @@
210210
}
211211
},
212212
"version": "0.0.0",
213-
"fingerprint": "Tkv4XtmzLBHjpoCQIvmDQWCZzcfyvXQvT70VAeVAjx8="
213+
"fingerprint": "uC/anzvNeUVZQRLakfLl74E6VUDzG7IrE8IlleLhl0E="
214214
}

packages/@scope/jsii-calc-lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
"@scope/jsii-calc-base-of-base": "^2.1.1"
4040
},
4141
"devDependencies": {
42-
"jsii": "5.9.1",
42+
"jsii": "5.9.6",
4343
"jsii-build-tools": "^0.0.0",
44-
"jsii-rosetta": "^5.9.1"
44+
"jsii-rosetta": "^5.9.6"
4545
},
4646
"jsii": {
4747
"outdir": "dist",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"stability": "deprecated"
7272
},
7373
"homepage": "https://github.com/aws/jsii",
74-
"jsiiVersion": "5.9.1",
74+
"jsiiVersion": "5.9.6",
7575
"license": "Apache-2.0",
7676
"metadata": {
7777
"jsii": {
@@ -1164,5 +1164,5 @@
11641164
}
11651165
},
11661166
"version": "0.0.0",
1167-
"fingerprint": "H6wdtGhqwOcKK1OUW9voxYuUdStSr5JX3ikW5avTfrk="
1167+
"fingerprint": "8chnxF4yP6o6nmn+pwW/moRmLso8MgyFcPoNyGJhA+Y="
11681168
}

0 commit comments

Comments
 (0)