Skip to content

Commit

Permalink
chore: upgrade to typescript 4.8
Browse files Browse the repository at this point in the history
Upgrade typescript from 3.9.10 to 4.8.4
Includes necessary upgrades to these packages as well:
@typescript-eslint/eslint-plugin
@typescript-eslint/parser
eslint
eslint-config-prettier
eslint-plugin-jest
jest
ts-jest
ts-loader
ts-node

Signed-off-by: Craig Andrews <candrews@integralblue.com>
  • Loading branch information
candrews committed Oct 7, 2022
1 parent 3507863 commit 9b345d6
Show file tree
Hide file tree
Showing 24 changed files with 4,465 additions and 4,212 deletions.
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,579 changes: 4,417 additions & 4,162 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@
"@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.0.4",
"express": "^4.17.1",
"fs-extra": "^9.1.0",
"jest": "^27.4.7",
"jest": "^29.0.3",
"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.2",
"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
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();
});
});
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
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
10 changes: 5 additions & 5 deletions test/jest/unit/validate-fix-command-is-supported.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('setDefaultTestOptions', () => {
.spyOn(featureFlags, 'isFeatureFlagSupportedForOrg')
.mockResolvedValue({ ok: false });
const options = { path: '/', showVulnPaths: 'all' as ShowVulnPaths };
await expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
await expect(validateFixCommandIsSupported(options)).rejects.toThrow(
'`snyk fix` is not supported',
);
});
Expand All @@ -31,7 +31,7 @@ describe('setDefaultTestOptions', () => {
.spyOn(featureFlags, 'isFeatureFlagSupportedForOrg')
.mockResolvedValue({ ok: false, code: 401, error: 'Invalid auth token' });
const options = { path: '/', showVulnPaths: 'all' as ShowVulnPaths };
await expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
await expect(validateFixCommandIsSupported(options)).rejects.toThrow(
AuthFailedError('Invalid auth token', 401),
);
});
Expand All @@ -45,7 +45,7 @@ describe('setDefaultTestOptions', () => {
showVulnPaths: 'all' as ShowVulnPaths,
unmanaged: true,
};
await expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
await expect(validateFixCommandIsSupported(options)).rejects.toThrow(
new FeatureNotSupportedByEcosystemError('snyk fix', 'cpp'),
);
});
Expand All @@ -59,7 +59,7 @@ describe('setDefaultTestOptions', () => {
showVulnPaths: 'all' as ShowVulnPaths,
docker: true,
};
await expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
await expect(validateFixCommandIsSupported(options)).rejects.toThrow(
new FeatureNotSupportedByEcosystemError('snyk fix', 'docker'),
);
});
Expand All @@ -73,7 +73,7 @@ describe('setDefaultTestOptions', () => {
showVulnPaths: 'all' as ShowVulnPaths,
code: true,
};
await expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
await expect(validateFixCommandIsSupported(options)).rejects.toThrow(
new FeatureNotSupportedByEcosystemError('snyk fix', 'code'),
);
});
Expand Down
1 change: 1 addition & 0 deletions tsconfig.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"sourceMap": true,
"resolveJsonModule": true,
"strict": true,
"useUnknownInCatchVariables": false,
"noImplicitAny": false, // Needed to compile tap and ansi-escapes
"composite": true
}
Expand Down

0 comments on commit 9b345d6

Please sign in to comment.