Skip to content

Commit

Permalink
chore: build all packages with TypeScript 4.6 (#3549)
Browse files Browse the repository at this point in the history
Use TypeScript 4.6 for building all packages, but continue to use
TypeScript 3.9 in the compiler and rosetta in order to avoid introducing
breaking changes.

Moved several "universal" devDependencies all the way to the root of the
mono-repository to minimize changes when updating these (`@types/jest`,
`jest`, `eslint`, etc...).

Some code changes were required due to the breaking changes introduced
between TypeScript 3.9 and 4.6, but nothing particularly substantial.
There seems to be an odd interaction between webpack and actually
importing `node:process`, so the `jsii/runtime` package switched to
using the global `process` value instead of importing the module.



---

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
  • Loading branch information
RomainMuller authored May 20, 2022
1 parent 9fd3c71 commit 4acff2c
Show file tree
Hide file tree
Showing 62 changed files with 805 additions and 1,116 deletions.
10 changes: 8 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ export function overriddenConfig(overrides: Config.InitialOptions) {
...Object.keys(original),
...Object.keys(override),
]);

// TypeScript appears to choke if we do the "as any" in the same
// expression as the key access, so we delcare surrogate varibales...
const originalAsAny = original as any;
const overrideAsAny = override as any;

for (const key of Array.from(allKeys).sort()) {
const originalValue: unknown = (original as any)[key];
const overrideValue: unknown = (override as any)[key];
const originalValue: unknown = originalAsAny[key];
const overrideValue: unknown = overrideAsAny[key];
if (originalValue == null) {
result[key] = overrideValue;
} else if (overrideValue == null) {
Expand Down
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@
"compliance": "(cd tools/jsii-compliance && yarn report)"
},
"devDependencies": {
"@jest/types": "^27.5.1",
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"@jest/types": "^28.1.0",
"@types/jest": "^27.5.1",
"@types/node": "^12.20.51",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"all-contributors-cli": "^6.20.0",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"jest-circus": "^27.5.1",
"jest-config": "^27.5.1",
"jest": "^28.1.0",
"jest-circus": "^28.1.0",
"jest-config": "^28.1.0",
"jest-expect-message": "^1.0.2",
"lerna": "^4.0.0",
"prettier": "^2.6.2",
"standard-version": "^9.3.2",
"standard-version": "^9.5.0",
"ts-node": "^10.7.0",
"typescript": "~3.9.10"
"typescript": "~4.6.4"
},
"repository": {
"type": "git",
Expand All @@ -48,5 +52,8 @@
"**/@fixtures/jsii-calc-bundled",
"**/@fixtures/jsii-calc-bundled/**"
]
},
"resolutions": {
"@types/prettier": "2.6.0"
}
}
2 changes: 1 addition & 1 deletion packages/@jsii/benchmarks/bin/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ interface ResultsJson {

(async () => {
/* eslint-disable-next-line @typescript-eslint/await-thenable */
const argv = yargs
const argv = await yargs
.command('$0', 'Runs jsii benchmark tests and displays results', (argv) =>
argv.option('output', {
type: 'string',
Expand Down
6 changes: 1 addition & 5 deletions packages/@jsii/benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
},
"devDependencies": {
"@types/glob": "^7.2.0",
"eslint": "^8.15.0",
"glob": "^8.0.1",
"jsii-calc": "^3.20.120",
"prettier": "^2.6.2",
"typescript": "~3.9.10"
"glob": "^8.0.1"
},
"scripts": {
"build": "tsc --build && npm run lint",
Expand Down
5 changes: 1 addition & 4 deletions packages/@jsii/check-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
"semver": "^7.3.7"
},
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/jest": "^27.5.0",
"@types/node": "^12.20.51",
"jest": "^27.5.1"
"@types/chalk": "^2.2.0"
}
}
4 changes: 1 addition & 3 deletions packages/@jsii/dotnet-runtime-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
},
"devDependencies": {
"@jsii/dotnet-runtime": "^0.0.0",
"@types/node": "^12.20.51",
"jsii-calc": "^3.20.120",
"jsii-pacmak": "^0.0.0",
"typescript": "~3.9.10"
"jsii-pacmak": "^0.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d47431ca_002Dca0b_002D43c9_002D8da0_002Ddd234b4d01fd/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;Amazon.JSII.Runtime.IntegrationTests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Project Location="/Users/rmuller/Development/aws/jsii/packages/@jsii/dotnet-runtime-test/test/Amazon.JSII.Runtime.IntegrationTests" Presentation="&amp;lt;Amazon.JSII.Runtime.IntegrationTests&amp;gt;" /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
4 changes: 1 addition & 3 deletions packages/@jsii/dotnet-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
},
"devDependencies": {
"@jsii/runtime": "^0.0.0",
"@types/node": "^12.20.51",
"@types/semver": "^7.3.9",
"jsii-build-tools": "^0.0.0",
"semver": "^7.3.7",
"typescript": "~3.9.10"
"semver": "^7.3.7"
}
}
2 changes: 1 addition & 1 deletion packages/@jsii/go-runtime-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"jsii-pacmak": "^0.0.0"
},
"dependencies": {
"fs-extra": "^9.1.0",
"fs-extra": "^10.1.0",
"@jsii/go-runtime": "^0.0.0"
}
}
9 changes: 2 additions & 7 deletions packages/@jsii/go-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/node": "^12.20.51",
"codemaker": "^0.0.0",
"eslint": "^8.15.0",
"fs-extra": "^9.1.0",
"fs-extra": "^10.1.0",
"jsii-build-tools": "^0.0.0",
"jsii-calc": "^3.20.120",
"prettier": "^2.6.2",
"ts-node": "^10.7.0",
"typescript": "~3.9.10"
"jsii-calc": "^3.20.120"
}
}
10 changes: 2 additions & 8 deletions packages/@jsii/integ-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"dependencies": {
"@octokit/rest": "^18.12.0",
"dotenv": "^8.6.0",
"fs-extra": "^9.1.0",
"jest": "^27.5.1",
"fs-extra": "^10.1.0",
"jsii": "^0.0.0",
"jsii-pacmak": "^0.0.0",
"jsii-rosetta": "^0.0.0",
Expand All @@ -29,11 +28,6 @@
"devDependencies": {
"@types/dotenv": "^8.2.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.5.0",
"@types/node": "^12.20.51",
"@types/tar": "^6.1.1",
"eslint": "^8.15.0",
"prettier": "^2.6.2",
"typescript": "~3.9.10"
"@types/tar": "^6.1.1"
}
}
4 changes: 1 addition & 3 deletions packages/@jsii/java-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
},
"devDependencies": {
"@jsii/runtime": "^0.0.0",
"@types/node": "^12.20.51",
"jsii-build-tools": "^0.0.0",
"typescript": "~3.9.10"
"jsii-build-tools": "^0.0.0"
}
}
10 changes: 2 additions & 8 deletions packages/@jsii/kernel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,16 @@
},
"dependencies": {
"@jsii/spec": "^0.0.0",
"fs-extra": "^9.1.0",
"fs-extra": "^10.1.0",
"tar": "^6.1.11"
},
"devDependencies": {
"@scope/jsii-calc-base": "^0.0.0",
"@scope/jsii-calc-lib": "^0.0.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.5.0",
"@types/node": "^12.20.51",
"@types/tar": "^6.1.1",
"eslint": "^8.15.0",
"jest": "^27.5.1",
"jest-expect-message": "^1.0.2",
"jsii-build-tools": "^0.0.0",
"jsii-calc": "^3.20.120",
"prettier": "^2.6.2",
"typescript": "~3.9.10"
"jsii-calc": "^3.20.120"
}
}
4 changes: 2 additions & 2 deletions packages/@jsii/kernel/src/kernel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ defineTest('async overrides: override a method', async (sandbox) => {
let callbackError;
try {
callbackResult = overrideCallback(cb.invoke!.args![0]);
} catch (e) {
} catch (e: any) {
callbackError = e.message;
}

Expand Down Expand Up @@ -1214,7 +1214,7 @@ defineTest(
expect(() => {
try {
sandbox.invoke({ objref: obj, method: 'throwError' });
} catch (error) {
} catch (error: any) {
const regexp =
/^\s*at Thrower\.doThrowError \(.*jsii[-_]calc.*\/lib\/compliance\.ts:\d+:\d+\)$/m;
expect(regexp.test(error.stack)).toBeTruthy(); // The stack trace includes the path to the original source file
Expand Down
4 changes: 2 additions & 2 deletions packages/@jsii/kernel/src/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ export class Kernel {
typeRef,
host,
);
} catch (e) {
} catch (e: any) {
// If no union (99% case), rethrow immediately to preserve stack trace
if (serTypes.length === 1) {
throw e;
Expand Down Expand Up @@ -1119,7 +1119,7 @@ export class Kernel {
for (const { serializationClass, typeRef } of serTypes) {
try {
return wire.SERIALIZERS[serializationClass].serialize(v, typeRef, host);
} catch (e) {
} catch (e: any) {
// If no union (99% case), rethrow immediately to preserve stack trace
if (serTypes.length === 1) {
throw e;
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/kernel/src/recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function recordInteraction(kernel: Kernel, inputOutputLogPath: string) {

logOutput({ ok: ret });
return ret;
} catch (e) {
} catch (e: any) {
logOutput({ error: e.message });
throw e;
}
Expand Down
6 changes: 2 additions & 4 deletions packages/@jsii/python-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
"@jsii/runtime": "^0.0.0"
},
"devDependencies": {
"fs-extra": "^9.1.0",
"fs-extra": "^10.1.0",
"jsii-build-tools": "^0.0.0",
"jsii-calc": "^3.20.120",
"jsii-pacmak": "^0.0.0",
"ts-node": "^10.7.0",
"typescript": "~3.9.10"
"jsii-pacmak": "^0.0.0"
}
}
17 changes: 8 additions & 9 deletions packages/@jsii/runtime/bin/jsii-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { spawn } from 'child_process';
import { error } from 'console';
import { constants as os } from 'os';
import { resolve } from 'path';
import { execArgv, execPath, exit, on, stdin, stdout } from 'process';
import { Duplex } from 'stream';

// Spawn another node process, with the following file descriptor setup:
Expand All @@ -13,8 +12,8 @@ import { Duplex } from 'stream';
// - FD#3 is the communication pipe to read jsii API messages
// - FD#4 is the communication pipe to write jsii API responses
const child = spawn(
execPath,
[...execArgv, resolve(__dirname, '..', 'lib', 'program.js')],
process.execPath,
[...process.execArgv, resolve(__dirname, '..', 'lib', 'program.js')],
{ stdio: ['ignore', 'pipe', 'pipe', 'pipe'] },
);

Expand All @@ -24,15 +23,15 @@ child.once('end', (code, signal) => {
if (signal != null) {
// Child was killed by signal, this is usually reflected by exiting with
// 128 + <signal code>
exit(128 + (os.signals[signal as keyof typeof os.signals] ?? 0));
process.exit(128 + (os.signals[signal as keyof typeof os.signals] ?? 0));
}
// Child exited, so we reflect it's exit code to our creator
exit(code);
process.exit(code);
});

child.once('error', (err) => {
console.error('Failed to spawn child process:', err.stack);
exit(-1);
process.exit(-1);
});

for (const signal of Object.keys(os.signals)) {
Expand All @@ -42,7 +41,7 @@ for (const signal of Object.keys(os.signals)) {
}

// Forward all signals to the child
on(signal as NodeJS.Signals, (sig) => child.kill(sig));
process.on(signal as NodeJS.Signals, (sig) => child.kill(sig));
}

//#endregion
Expand Down Expand Up @@ -77,8 +76,8 @@ child.stderr!.on('data', makeHandler('stderr'));

const commands: Duplex = (child.stdio as any)[3];
// Forwarding requests from this process' STDIN to the child's FD#3
stdin.pipe(commands);
process.stdin.pipe(commands);
// Forwarding responses from the child's FD#3 to this process' STDOUT
commands.pipe(stdout);
commands.pipe(process.stdout);

//#endregion
2 changes: 0 additions & 2 deletions packages/@jsii/runtime/lib/program.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as process from 'process';

import * as packageInfo from '../package.json';
import { KernelHost } from './host';
import { InputOutput } from './in-out';
Expand Down
2 changes: 1 addition & 1 deletion packages/@jsii/runtime/lib/sync-stdio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class SyncStdio {
while (offset < buffer.length) {
try {
offset += fs.writeSync(fd, buffer, offset);
} catch (e) {
} catch (e: any) {
// We might get EAGAIN if the file descriptor was not opened for
// blocking (O_SYNC) writes. In such cases, we'll keep trying until it
// succeeds. This shouldn't take long as the process on the other side
Expand Down
6 changes: 0 additions & 6 deletions packages/@jsii/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,9 @@
"devDependencies": {
"@scope/jsii-calc-base": "^0.0.0",
"@scope/jsii-calc-lib": "^0.0.0",
"@types/jest": "^27.5.0",
"@types/node": "^12.20.51",
"eslint": "^8.15.0",
"jest": "^27.5.1",
"jsii-build-tools": "^0.0.0",
"jsii-calc": "^3.20.120",
"prettier": "^2.6.2",
"source-map-loader": "^3.0.1",
"typescript": "~3.9.10",
"webpack": "^5.72.1",
"webpack-cli": "^4.9.2"
}
Expand Down
1 change: 0 additions & 1 deletion packages/@jsii/runtime/test/playback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as child from 'child_process';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as process from 'process';

import { IInputOutput, Input, KernelHost, Output } from '../lib';

Expand Down
6 changes: 0 additions & 6 deletions packages/@jsii/spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@
"jsonschema": "^1.4.0"
},
"devDependencies": {
"@types/jest": "^27.5.0",
"@types/node": "^12.20.51",
"eslint": "^8.15.0",
"jest": "^27.5.1",
"jsii-build-tools": "^0.0.0",
"prettier": "^2.6.2",
"typescript": "~3.9.10",
"typescript-json-schema": "^0.53.0"
}
}
4 changes: 1 addition & 3 deletions packages/@scope/jsii-calc-base-of-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
"devDependencies": {
"@types/node": "^12.20.51",
"jsii": "^0.0.0",
"jsii-build-tools": "^0.0.0",
"jsii-rosetta": "^0.0.0",
"prettier": "^2.6.2"
"jsii-rosetta": "^0.0.0"
},
"jsii": {
"outdir": "dist",
Expand Down
Loading

0 comments on commit 4acff2c

Please sign in to comment.