Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to TypeScript 4.6 #811

Merged
merged 15 commits into from
Mar 23, 2022
Merged
5 changes: 5 additions & 0 deletions .changeset/bright-rivers-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"skuba": patch
---

Jest.mergePreset: Allow additional props via type parameter
7 changes: 7 additions & 0 deletions .changeset/brown-experts-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"skuba": minor
---

deps: TypeScript 4.6

This major release includes breaking changes. See the [TypeScript 4.5](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/) and [TypeScript 4.6](https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/) announcements for more information.
25 changes: 25 additions & 0 deletions .changeset/red-cycles-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"skuba": minor
---

deps: ESLint 8 + eslint-config-seek 9

These major upgrades bundle new parser and plugin versions. See the [ESLint 8 guide](https://eslint.org/docs/8.0.0/user-guide/migrating-to-8.0.0) and [eslint-config-seek 9 release](https://github.com/seek-oss/eslint-config-seek/releases/tag/v9.0.0) for more details on the underlying changes.

We've introduced new linting rules like [@typescript-eslint/no-unsafe-argument](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-unsafe-argument.md), and resolved the following installation warning:

```console
babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
```

If you wish to relax some of the new rules, [extend](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files) your `.eslintrc.js` config:

```javascript
module.exports = {
extends: ["skuba"],
rules: {
// Demote new TypeScript ESLint rule from "error" to "warn".
"@typescript-eslint/no-unsafe-argument": "warn",
},
};
```
1 change: 1 addition & 0 deletions jest.config.int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Jest } from './src';

export default Jest.mergePreset({
coveragePathIgnorePatterns: ['<rootDir>/integration/', '<rootDir>/template/'],
resolver: '<rootDir>/jest/resolver.js',
setupFiles: ['<rootDir>/jest.setup.ts'],
testPathIgnorePatterns: ['<rootDir>/template/', '/test\\.ts'],
watchPathIgnorePatterns: [
Expand Down
23 changes: 23 additions & 0 deletions jest/resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// https://github.com/typescript-eslint/typescript-eslint/blob/v5.16.0/tests/jest-resolver.js
// https://github.com/typescript-eslint/typescript-eslint/issues/4210#issuecomment-981203332

/* @ts-check */

// temporary workaround - https://github.com/facebook/jest/issues/9771#issuecomment-871585234
const resolver = require('enhanced-resolve').create.sync({
conditionNames: ['require', 'node', 'default'],
extensions: ['.js', '.json', '.node', '.ts', '.tsx'],
});

/**
* @param request {unknown}
* @param options {{ defaultResolver(...args: unknown[]): unknown, basedir: unknown }}
* @returns {unknown}
*/
module.exports = function (request, options) {
// list global module that must be resolved by defaultResolver here
if (['fs', 'http', 'path'].includes(request)) {
return options.defaultResolver(request, options);
}
return resolver(options.basedir, request);
};
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"dotenv": "^16.0.0",
"ejs": "^3.1.6",
"enquirer": "^2.3.6",
"eslint": "^7.27.0",
"eslint-config-skuba": "1.0.15",
"eslint": "^8.11.0",
"eslint-config-skuba": "1.0.16",
"execa": "^5.0.0",
"fdir": "^5.0.0",
"fs-extra": "^10.0.0",
Expand Down Expand Up @@ -44,7 +44,7 @@
"ts-node-dev": "^2.0.0-0",
"tsconfig-paths": "^3.11.0",
"tsconfig-seek": "1.0.2",
"typescript": "~4.4.4"
"typescript": "~4.6.2"
},
"description": "SEEK development toolkit for backend applications and packages",
"devDependencies": {
Expand All @@ -60,6 +60,7 @@
"@types/npm-which": "3.0.1",
"@types/picomatch": "2.3.0",
"@types/supertest": "2.0.11",
"enhanced-resolve": "5.9.2",
"express": "4.17.3",
"jsonfile": "6.1.0",
"koa": "2.13.4",
Expand Down
19 changes: 13 additions & 6 deletions src/api/jest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import type { Config } from '@jest/types';
import jestPreset from '../../../jest-preset';
import { mergeRaw } from '../../cli/configure/processing/record';

type Props = Pick<
Config.InitialOptions,
/**
* Set of Jest options that are recommended and supported for customisation.
*
* While we technically accept anything compatible with `Config.InitialOptions`,
* these are tacitly endorsed for our use cases and receive IntelliSense.
*/
type DefaultOptions =
| 'collectCoverage'
| 'collectCoverageFrom'
| 'collectCoverageOnlyFrom'
Expand All @@ -21,13 +26,15 @@ type Props = Pick<
| 'testEnvironment'
| 'testPathIgnorePatterns'
| 'testTimeout'
| 'watchPathIgnorePatterns'
>;
| 'watchPathIgnorePatterns';

/**
* Merge additional Jest options into the **skuba** preset.
*
* This concatenates array options like `testPathIgnorePatterns`.
*/
export const mergePreset = (props: Props): Config.InitialOptions =>
mergeRaw(jestPreset, props);
export const mergePreset = <
AdditionalOptions extends keyof Config.InitialOptions,
>(
options: Pick<Config.InitialOptions, AdditionalOptions | DefaultOptions>,
): Config.InitialOptions => mergeRaw(jestPreset, options);
3 changes: 2 additions & 1 deletion src/cli/configure/modules/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export const tsconfigModule = async ({
const hasLibStar = exclude.includes('lib*/**/*');

outputData.exclude = exclude.filter(
(pattern) => !(hasLibStar && ['lib', 'lib/**/*'].includes(pattern)),
(pattern: unknown) =>
!(hasLibStar && new Set<unknown>(['lib', 'lib/**/*']).has(pattern)),
);
}

Expand Down
1 change: 1 addition & 0 deletions src/cli/configure/processing/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const createImportFromExpression = (
factory.createNamedImports(
importNames.map((importName) =>
factory.createImportSpecifier(
false,
undefined,
factory.createIdentifier(importName),
),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/lint/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class StreamInterceptor extends stream.Transform {
}

_transform(
chunk: any,
chunk: Uint8Array,
_encoding: BufferEncoding,
callback: stream.TransformCallback,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class YarnSpamFilter extends stream.Transform {
silenced = false;

_transform(
chunk: any,
chunk: Uint8Array,
_encoding: BufferEncoding,
callback: stream.TransformCallback,
) {
Expand All @@ -41,7 +41,7 @@ class YarnSpamFilter extends stream.Transform {

class YarnWarningFilter extends stream.Transform {
_transform(
chunk: any,
chunk: Uint8Array,
_encoding: BufferEncoding,
callback: stream.TransformCallback,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const postWorkerOutput = <Input, Output>(
process.exit(1);
}

fn(workerData)
fn(workerData as Input)
.then((output) => port.postMessage(output))
.catch((err) => {
logger.err(err);
Expand Down
6 changes: 4 additions & 2 deletions src/wrapper/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const createRequestListenerFromFunction =
const data: Buffer[] = [];

req
.on('data', (chunk) => data.push(chunk))
.on('data', (chunk: Buffer) => data.push(chunk))
.on('end', () => resolve(Buffer.concat(data).toString()))
.on('error', (err) => reject(err));
});
Expand All @@ -42,7 +42,9 @@ export const createRequestListenerFromFunction =
const jsonRequest: unknown = requestBody ? JSON.parse(requestBody) : [];

// Pass a non-array request body as the first parameter
const args = Array.isArray(jsonRequest) ? jsonRequest : [jsonRequest];
const args: unknown[] = Array.isArray(jsonRequest)
? jsonRequest
: [jsonRequest];

const response: unknown = await fn(...args);

Expand Down
4 changes: 1 addition & 3 deletions template/express-rest-api/src/api/smokeTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Handler } from 'express';
/**
* Tests connectivity to ensure appropriate access and network configuration.
*/
export const smokeTestHandler: Handler = async (_req, res) => {
await Promise.all([]);

export const smokeTestHandler: Handler = (_req, res) => {
res.send('');
};
Loading