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

chore: upgrade to typescript 4.8 #4115

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
"prettier"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
Expand Down Expand Up @@ -52,7 +51,6 @@
"jest/no-done-callback": "warn",
"jest/valid-title": "warn",
"jest/no-conditional-expect": "warn",
"jest/no-try-expect": "warn",
"jest/no-identical-title": "warn",
"@typescript-eslint/ban-ts-comment": "warn"
}
Expand Down
8,596 changes: 4,436 additions & 4,160 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,27 @@
"@types/cross-spawn": "^6.0.2",
"@types/express": "^4.17.13",
"@types/fs-extra": "^9.0.11",
"@types/jest": "^27.0.1",
"@types/jest": "^29.1.2",
"@types/lodash": "^4.14.161",
"@types/needle": "^2.0.4",
"@types/node": "^14.14.31",
"@types/sarif": "^2.1.2",
"@types/sinon": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"ajv": "^6.12.6",
"body-parser": "^1.19.0",
"conventional-changelog-cli": "^2.2.2",
"copy-webpack-plugin": "^9.0.1",
"cross-spawn": "^6.0.5",
"danger": "10.9.0",
"depcheck": "^1.4.3",
"eslint": "6.8.0",
"eslint-config-prettier": "^6.1.0",
"eslint-plugin-jest": "^24.4.0",
"eslint": "8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jest": "^27.1.1",
"express": "^4.17.1",
"fs-extra": "^9.1.0",
"jest": "^27.4.7",
"jest": "^29.1.2",
"lodash": "^4.17.20",
"mock-fs": "^4.13.0",
"nock": "^10.0.6",
Expand All @@ -166,10 +166,10 @@
"proxyquire": "^1.7.4",
"sinon": "^4.0.0",
"tap": "^12.6.1",
"ts-jest": "^27.0.4",
"ts-loader": "^9.0.2",
"ts-node": "^8.0.0",
"typescript": "^3.9.9",
"ts-jest": "^29.0.3",
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
"webpack": "^5.34.0",
"webpack-cli": "^4.6.0",
"webpack-license-plugin": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-alert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"@octokit/rest": "^18.0.5",
"@pagerduty/pdjs": "^2.2.0",
"@slack/webhook": "^5.0.3",
"typescript": "^4.0.2"
"typescript": "^4.8.4"
}
}
2 changes: 1 addition & 1 deletion packages/iac-cli-alert/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"license": "Apache-2.0",
"dependencies": {
"@slack/webhook": "^5.0.3",
"typescript": "^4.0.2"
"typescript": "^4.8.4"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function filterOutAppliedUpgrades(
const normalizedAppliedRemediation = upgradeChanges
.map((c) => {
if (c.success && c.from) {
const [pkgName, versionAndMore] = c.from?.split('@');
const [pkgName, versionAndMore] = c.from.split('@');
return `${standardizePackageName(pkgName)}@${versionAndMore}`;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export async function generateUpgrades(
// transitive and it could have come from a dev or prod dep
// since we can't tell right now let be pinned into production deps
upgrades.push(upgrade);
} else if (prodTopLevelDeps.includes(pkgName)) {
upgrades.push(upgrade);
} else if (entity.options.dev && devTopLevelDeps.includes(pkgName)) {
devUpgrades.push(upgrade);
} else {
Expand Down
6 changes: 5 additions & 1 deletion src/cli/commands/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import { findAndLoadPolicy } from '../../lib/policy';
import { DescribeRequiredArgumentError } from '../../lib/errors/describe-required-argument-error';
import help from './help';
import { DCTL_EXIT_CODES, runDriftCTL } from '../../lib/iac/drift/driftctl';
import { DescribeOptions } from '../../lib/iac/types';
import { PolicyOptions } from '../../lib/types';

export default async (...args: MethodArgs): Promise<any> => {
const { options } = processCommandArgs(...args);
const { options } = processCommandArgs<DescribeOptions & PolicyOptions>(
...args,
);

// Ensure that this describe command can only be runned when using `snyk iac describe`
// Avoid `snyk describe` direct usage
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function promiseOrCleanup<T>(
// Returns an array of Registry responses (one per every sub-project scanned), a single response,
// or an error message.
export default async function monitor(...args0: MethodArgs): Promise<any> {
const { options, paths } = processCommandArgs(...args0);
const { options, paths } = processCommandArgs<MonitorOptions>(...args0);
const results: Array<GoodResult | BadResult> = [];

if (options.id) {
Expand Down
3 changes: 2 additions & 1 deletion src/cli/commands/update-exclude-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import {
} from '../../lib/iac/drift';
import { Policy } from '../../lib/policy/find-and-load-policy';
import * as analytics from '../../lib/analytics';
import { GenDriftIgnoreOptions } from '../../lib/iac/types';

export default async (...args: MethodArgs): Promise<any> => {
const { options } = processCommandArgs(...args);
const { options } = processCommandArgs<GenDriftIgnoreOptions>(...args);

// Ensure that this update-exclude-policy command can only be runned when using `snyk iac update-exclude-policy`
// Avoid `snyk update-exclude-policy` direct usage
Expand Down
2 changes: 1 addition & 1 deletion src/lib/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function yarn(

method += ' ' + flags.join(' ');

return new Promise((resolve, reject) => {
return new Promise<void>((resolve, reject) => {
const cmd = 'yarn ' + method + ' ' + packages.join(' ');
if (!cwd) {
cwd = process.cwd();
Expand Down
5 changes: 5 additions & 0 deletions test/createJestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const createJestConfig = (config) => {
];

return {
snapshotFormat: {
// Jest 29 changed these defaults, see: https://jestjs.io/docs/upgrading-to-jest29#snapshot-format
escapeString: true,
printBasicPrototype: true,
},
preset: 'ts-jest',
testRegex: '\\.spec\\.ts$',
testPathIgnorePatterns: [...ignorePatterns],
Expand Down
4 changes: 2 additions & 2 deletions test/jest/acceptance/iac/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function startMockServer() {
const server = fakeServer(BASE_API, SNYK_TOKEN);

// Use port of 0 to find a free port.
await new Promise((resolve) => server.listen(0, resolve));
await new Promise<void>((resolve) => server.listen(0, resolve));

const SNYK_HOST = 'http://localhost:' + server.getPort();
const SNYK_API = SNYK_HOST + BASE_API;
Expand All @@ -37,7 +37,7 @@ export async function startMockServer() {
overrides?: Record<string, string>,
cwd?: string,
) => run(cmd, { ...env, ...overrides }, cwd),
teardown: async () => new Promise((resolve) => server.close(resolve)),
teardown: async () => new Promise<void>((resolve) => server.close(resolve)),
apiUrl: SNYK_API,
};
}
Expand Down
2 changes: 1 addition & 1 deletion test/jest/unit/cli/commands/test/iac/v2/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ describe('test', () => {
describe('with issues', () => {
it('throws the expected error', async () => {
// Act + Assert
await expect(test(['path/to/test'], {})).rejects.toThrowError(
await expect(test(['path/to/test'], {})).rejects.toThrow(
FoundIssuesError,
);
});
Expand Down
4 changes: 2 additions & 2 deletions test/jest/unit/iac/file-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('extractBundle', () => {
mockBundleStream.end();

await expect(extractBundlePromise).resolves.toEqual(undefined);
expect(tarSpy).toBeCalledWith({
expect(tarSpy).toHaveBeenCalledWith({
C: expect.stringMatching(LOCAL_POLICY_ENGINE_DIR),
});
expect(receivedBundleData).toEqual('zipped data');
Expand Down Expand Up @@ -83,6 +83,6 @@ describe('makeFileAndDirectoryGenerator', () => {

it('throws an error if the path provided is not a directory', () => {
const it = makeFileAndDirectoryGenerator('missing_path');
expect(() => Array.from(it)).toThrowError();
expect(() => Array.from(it)).toThrow();
});
});
3 changes: 1 addition & 2 deletions test/jest/unit/iac/usage-tracking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import {
trackUsage,
TestLimitReachedError,
} from '../../../../src/cli/commands/test/iac/local-execution/usage-tracking';
import { mocked } from 'ts-jest/utils';
import { NeedleResponse } from 'needle';
import { makeRequest } from '../../../../src/lib/request/request';
import { CustomError } from '../../../../src/lib/errors';

jest.mock('../../../../src/lib/request/request');
const mockedMakeRequest = mocked(makeRequest);
const mockedMakeRequest = jest.mocked(makeRequest);

const results = [
{
Expand Down
2 changes: 1 addition & 1 deletion test/jest/unit/lib/analytics/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('analytics module', () => {
args: argsFrom({}),
});

expect(requestSpy).toBeCalledTimes(1);
expect(requestSpy).toHaveBeenCalledTimes(1);
expect(requestSpy.mock.calls[0][0]).not.toHaveProperty(
'headers.authorization',
);
Expand Down
2 changes: 1 addition & 1 deletion test/jest/unit/lib/ecosystems/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('handleProcessingStatus fn', () => {
({ actual, expected }) => {
expect(() => {
handleProcessingStatus({ status: actual } as any);
}).toThrowError(new FailedToRunTestError(expected));
}).toThrow(new FailedToRunTestError(expected));
},
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('resolve and test facts', () => {
'project-lifecycle': 'development',
} as unknown) as Options);
expect(httpClientSpy).toHaveBeenCalledTimes(1);
expect(httpClientSpy).toBeCalledWith(
expect(httpClientSpy).toHaveBeenCalledWith(
expect.objectContaining({
body: expect.objectContaining({
tags: [
Expand Down
4 changes: 2 additions & 2 deletions test/jest/unit/lib/feature-flags/feature-flags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ describe('hasFeatureFlag fn', () => {

await expect(
hasFeatureFlag('test-ff', { path: 'test-path' }),
).rejects.toThrowError('Unauthorized');
).rejects.toThrow('Unauthorized');

jest.spyOn(request, 'makeRequest').mockResolvedValue({
body: { code: 403, error: 'Forbidden', ok: false },
} as any);
await expect(
hasFeatureFlag('test-ff', { path: 'test-path' }),
).rejects.toThrowError('Forbidden');
).rejects.toThrow('Forbidden');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ describe('lookupLocalPolicyEngine', () => {
await lookupLocalPolicyEngine(testConfig);

// Assert
expect(lookupLocalySpy).toBeCalledWith(
expect(lookupLocalySpy).toHaveBeenCalledWith(
testConfig.iacCachePath,
policyEngineFileName,
undefined,
expect.any(Function),
);
expect(isExeSpy).toBeCalledWith(cachedPolicyEnginePath);
expect(isExeSpy).toHaveBeenCalledWith(cachedPolicyEnginePath);
});

it('returns undefined when the policy engine is not present locally', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ describe('lookupLocalRulesBundle', () => {
await lookupLocalRulesBundle(testConfig);

// Assert
expect(lookupLocalySpy).toBeCalledWith(
expect(lookupLocalySpy).toHaveBeenCalledWith(
testConfig.iacCachePath,
rulesBundleName,
undefined,
expect.any(Function),
);
expect(isFileSpy).toBeCalledWith(cachedRulesBundlePath);
expect(isArchiveSpy).toBeCalledWith(cachedRulesBundlePath);
expect(isFileSpy).toHaveBeenCalledWith(cachedRulesBundlePath);
expect(isArchiveSpy).toHaveBeenCalledWith(cachedRulesBundlePath);
});

it('returns undefined when the rules bundle is not present locally', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ describe('fetchCacheResource', () => {
jest.spyOn(requestLib, 'makeRequest').mockRejectedValue(new Error());

// Act + Assert
await expect(
fetchCacheResource(testCacheResourceUrl),
).rejects.toThrowError();
await expect(fetchCacheResource(testCacheResourceUrl)).rejects.toThrow();
});
});
describe('when an error response is received', () => {
Expand Down
4 changes: 1 addition & 3 deletions test/jest/unit/npm-modules-parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { mocked } from 'ts-jest/utils';

import { parse } from '../../../src/lib/plugins/nodejs-plugin/npm-modules-parser';
import { getFileContents } from '../../../src/lib/get-file-contents';

jest.mock('../../../src/lib/get-file-contents');
const mockedGetFileContents = mocked(getFileContents, true);
const mockedGetFileContents = jest.mocked(getFileContents, {shallow: true});

afterEach(() => {
jest.clearAllMocks();
Expand Down
5 changes: 2 additions & 3 deletions test/jest/unit/python/snyk-test-pyproject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { mocked } from 'ts-jest/utils';
import { NeedleResponse } from 'needle';
import test from '../../../../src/cli/commands/test';
import { loadPlugin } from '../../../../src/lib/plugins/index';
Expand All @@ -11,8 +10,8 @@ import { getFixturePath } from '../../util/getFixturePath';
jest.mock('../../../../src/lib/plugins/index');
jest.mock('../../../../src/lib/request/request');

const mockedLoadPlugin = mocked(loadPlugin, true);
const mockedMakeRequest = mocked(makeRequest);
const mockedLoadPlugin = jest.mocked(loadPlugin, {shallow: true});
const mockedMakeRequest = jest.mocked(makeRequest);

describe('snyk test for python project', () => {
afterEach(() => {
Expand Down
8 changes: 3 additions & 5 deletions test/jest/unit/snyk-code/snyk-code-test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ describe('Test snyk code', () => {
code: true,
...options,
}),
).rejects.toThrowError(
/Authentication failed. Please check the API token on/,
);
).rejects.toThrow(/Authentication failed. Please check the API token on/);
});

it('should fail - when we do not support files', async () => {
Expand Down Expand Up @@ -610,7 +608,7 @@ describe('Test snyk code', () => {
// exit code 1
expect(error.code).toBe('VULNS');
expect(errMessage).toBe(expectedOutput);
expect(analyticSend).toBeCalledTimes(2);
expect(analyticSend).toHaveBeenCalledTimes(2);
}
});

Expand Down Expand Up @@ -858,7 +856,7 @@ describe('Test snyk code', () => {
sastSettings,
'test-id',
),
).rejects.toThrowError(
).rejects.toThrow(
'Missing configuration for Snyk Code Local Engine. Refer to our docs on https://docs.snyk.io/products/snyk-code/deployment-options/snyk-code-local-engine/cli-and-ide to learn more',
);
});
Expand Down
Loading