Skip to content

Commit 02281bd

Browse files
committed
chore(typescript): enable erasableSyntaxOnly for the whole repo
Inspired by mongodb-js/compass#7613
1 parent 3c88417 commit 02281bd

File tree

22 files changed

+130
-139
lines changed

22 files changed

+130
-139
lines changed

configs/tsconfig-mongosh/tsconfig.common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"noUnusedLocals": false,
1010
"noUnusedParameters": false,
1111
"noImplicitReturns": true,
12+
"erasableSyntaxOnly": true,
1213

1314
"declaration": true,
1415
"removeComments": true,

packages/async-rewriter2/src/error-codes.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @mongoshErrors
55
*/
6-
enum AsyncRewriterErrors {
6+
export const AsyncRewriterErrors = {
77
/**
88
* Signals the use of a Mongosh API call in a place where it is not supported.
99
* This occurs inside of constructors and (non-async) generator functions.
@@ -23,7 +23,7 @@ enum AsyncRewriterErrors {
2323
*
2424
* **Solution: Do not use calls directly in such functions. If necessary, place these calls in an inner 'async' function.**
2525
*/
26-
SyntheticPromiseInAlwaysSyncContext = 'ASYNC-10012',
26+
SyntheticPromiseInAlwaysSyncContext: 'ASYNC-10012',
2727
/**
2828
* Signals the iteration of a Mongosh API object in a place where it is not supported.
2929
* This occurs inside of constructors and (non-async) generator functions.
@@ -44,7 +44,5 @@ enum AsyncRewriterErrors {
4444
*
4545
* **Solution: Do not use calls directly in such functions. If necessary, place these calls in an inner 'async' function.**
4646
*/
47-
SyntheticAsyncIterableInAlwaysSyncContext = 'ASYNC-10013',
48-
}
49-
50-
export { AsyncRewriterErrors };
47+
SyntheticAsyncIterableInAlwaysSyncContext: 'ASYNC-10013',
48+
} as const;

packages/autocomplete/src/index.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { completer, BASE_COMPLETIONS } from './';
2-
import { signatures as shellSignatures, Topologies } from '@mongosh/shell-api';
2+
import { signatures as shellSignatures } from '@mongosh/shell-api';
33

44
import { expect } from 'chai';
55

66
let collections: string[];
77
let databases: string[];
88
const standalone600 = {
9-
topology: () => Topologies.Standalone,
9+
topology: () => 'Standalone' as const,
1010
apiVersionInfo: () => undefined,
1111
connectionInfo: () => ({
1212
is_atlas: false,
@@ -18,7 +18,7 @@ const standalone600 = {
1818
getDatabaseCompletions: () => databases,
1919
};
2020
const standalone440 = {
21-
topology: () => Topologies.Standalone,
21+
topology: () => 'Standalone' as const,
2222
apiVersionInfo: () => undefined,
2323
connectionInfo: () => ({
2424
is_atlas: false,
@@ -30,7 +30,7 @@ const standalone440 = {
3030
getDatabaseCompletions: () => databases,
3131
};
3232
const apiStrictParams = {
33-
topology: () => Topologies.Standalone,
33+
topology: () => 'Standalone' as const,
3434
apiVersionInfo: () => ({
3535
version: '1',
3636
strict: true,
@@ -41,7 +41,7 @@ const apiStrictParams = {
4141
getDatabaseCompletions: () => databases,
4242
};
4343
const sharded440 = {
44-
topology: () => Topologies.Sharded,
44+
topology: () => 'Sharded' as const,
4545
apiVersionInfo: () => undefined,
4646
connectionInfo: () => ({
4747
is_atlas: false,
@@ -54,7 +54,7 @@ const sharded440 = {
5454
};
5555

5656
const standalone300 = {
57-
topology: () => Topologies.Standalone,
57+
topology: () => 'Standalone' as const,
5858
apiVersionInfo: () => undefined,
5959
connectionInfo: () => ({
6060
is_atlas: false,
@@ -66,7 +66,7 @@ const standalone300 = {
6666
getDatabaseCompletions: () => databases,
6767
};
6868
const datalake440 = {
69-
topology: () => Topologies.Sharded,
69+
topology: () => 'Sharded' as const,
7070
apiVersionInfo: () => undefined,
7171
connectionInfo: () => ({
7272
is_atlas: true,
@@ -79,7 +79,7 @@ const datalake440 = {
7979
};
8080

8181
const localAtlas600 = {
82-
topology: () => Topologies.Standalone,
82+
topology: () => 'Standalone' as const,
8383
apiVersionInfo: () => undefined,
8484
connectionInfo: () => ({
8585
is_atlas: false,
@@ -100,7 +100,7 @@ const noParams = {
100100
};
101101

102102
const emptyConnectionInfoParams = {
103-
topology: () => Topologies.Standalone,
103+
topology: () => 'Standalone' as const,
104104
apiVersionInfo: () => undefined,
105105
connectionInfo: () => ({}),
106106
getCollectionCompletionsForCurrentDb: () => collections,

packages/browser-runtime-core/src/autocompleter/shell-api-autocompleter.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { ShellApiAutocompleter } from './shell-api-autocompleter';
22
import { expect } from 'chai';
3-
import { Topologies } from '@mongosh/shell-api';
43
import type { AutocompleteParameters } from '@mongosh/autocomplete';
54
import type { AutocompletionContext } from '@mongodb-js/mongodb-ts-autocomplete';
65

76
const standalone440Parameters: AutocompleteParameters = {
8-
topology: () => Topologies.Standalone,
7+
topology: () => 'Standalone',
98
apiVersionInfo: () => undefined,
109
connectionInfo: () => ({
1110
is_atlas: false,

packages/build/src/barque.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ import tmp from 'tmp-promise';
1111
import util, { promisify } from 'util';
1212
import type { PackageVariant, Config } from './config';
1313
import semver from 'semver';
14-
import {
15-
getArch,
16-
getDistro,
17-
getDebArchName,
18-
getRPMArchName,
19-
Platform,
20-
} from './config';
14+
import { getArch, getDistro, getDebArchName, getRPMArchName } from './config';
2115
import { withRetries } from './helpers';
2216
import type {
2317
PPARepository,
@@ -120,7 +114,7 @@ export class Barque {
120114
private downloadedCuratorPromise: Promise<string> | undefined;
121115

122116
constructor(config: Config) {
123-
if (config.platform !== Platform.Linux) {
117+
if (config.platform !== 'linux') {
124118
throw new Error('Barque publishing is only supported on linux platforms');
125119
}
126120

packages/build/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface Config {
5050
notarySigningKeyName?: string;
5151
notaryAuthToken?: string;
5252
isCi?: boolean;
53-
platform?: string;
53+
platform?: NodeJS.Platform;
5454
execNodeVersion: string;
5555
packageVariant?: PackageVariant;
5656
repo: {

packages/build/src/config/platform.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,4 @@
44
* Different from 'BuildVariant': platform is extracted from os.platform() and
55
* build variant is the host evergreen is building on.
66
*/
7-
export enum Platform {
8-
Windows = 'win32',
9-
MacOs = 'darwin',
10-
Linux = 'linux',
11-
}
7+
export type Platform = 'win32' | 'darwin' | 'linux';

packages/build/src/evergreen/rest-api.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,21 @@ export interface EvergreenTask {
2222
}
2323

2424
export class EvergreenApi {
25+
public readonly apiBasepath: string;
26+
public readonly apiUser: string;
27+
public readonly apiKey: string;
28+
private readonly fetch: typeof fetchFn;
2529
constructor(
26-
public readonly apiBasepath: string,
27-
public readonly apiUser: string,
28-
public readonly apiKey: string,
29-
private readonly fetch: typeof fetchFn = fetchFn
30-
) {}
30+
apiBasepath: string,
31+
apiUser: string,
32+
apiKey: string,
33+
fetch: typeof fetchFn = fetchFn
34+
) {
35+
this.apiBasepath = apiBasepath;
36+
this.apiUser = apiUser;
37+
this.apiKey = apiKey;
38+
this.fetch = fetch;
39+
}
3140

3241
public static async fromUserConfiguration(
3342
pathToConfiguration = path.join(os.homedir(), '.evergreen.yml')

packages/build/src/homebrew/publish-to-homebrew.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ export type HomebrewPublisherConfig = {
1212
};
1313

1414
export class HomebrewPublisher {
15+
public config: HomebrewPublisherConfig;
1516
readonly npmPackageSha256: typeof npmPackageSha256Fn;
1617
readonly generateFormula: typeof generateUpdatedFormulaFn;
1718
readonly updateHomebrewFork: typeof updateHomebrewForkFn;
1819

1920
constructor(
20-
public config: HomebrewPublisherConfig,
21+
config: HomebrewPublisherConfig,
2122
{
2223
npmPackageSha256 = npmPackageSha256Fn,
2324
generateFormula = generateUpdatedFormulaFn,
2425
updateHomebrewFork = updateHomebrewForkFn,
2526
} = {}
2627
) {
28+
this.config = config;
2729
this.npmPackageSha256 = npmPackageSha256;
2830
this.generateFormula = generateFormula;
2931
this.updateHomebrewFork = updateHomebrewFork;

packages/build/src/publish-mongosh.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,38 @@ export async function publishMongosh(config: Config, octokit: Octokit) {
4848
}
4949

5050
export class MongoshPublisher {
51+
public config: Config;
52+
public barque: Barque;
53+
public mongoshGithubRepo: GithubRepo;
54+
public packagePublisher: PackagePublisher;
55+
public packageBumper: PackageBumper;
56+
public homebrewPublisher: HomebrewPublisher;
57+
5158
private readonly getEvergreenArtifactUrl: typeof getArtifactUrlFn;
5259
private readonly writeBuildInfo: typeof writeBuildInfoFn;
5360
private readonly createAndPublishDownloadCenterConfig: typeof createAndPublishDownloadCenterConfigFn;
5461
private readonly shouldDoPublicRelease: typeof shouldDoPublicReleaseFn;
5562

5663
constructor(
57-
public config: Config,
58-
public barque: Barque,
59-
public mongoshGithubRepo: GithubRepo,
60-
public packagePublisher: PackagePublisher,
61-
public packageBumper: PackageBumper,
62-
public homebrewPublisher: HomebrewPublisher,
64+
config: Config,
65+
barque: Barque,
66+
mongoshGithubRepo: GithubRepo,
67+
packagePublisher: PackagePublisher,
68+
packageBumper: PackageBumper,
69+
homebrewPublisher: HomebrewPublisher,
6370
{
6471
getEvergreenArtifactUrl = getArtifactUrlFn,
6572
writeBuildInfo = writeBuildInfoFn,
6673
createAndPublishDownloadCenterConfig = createAndPublishDownloadCenterConfigFn,
6774
shouldDoPublicRelease = shouldDoPublicReleaseFn,
6875
} = {}
6976
) {
77+
this.config = config;
78+
this.barque = barque;
79+
this.mongoshGithubRepo = mongoshGithubRepo;
80+
this.packagePublisher = packagePublisher;
81+
this.packageBumper = packageBumper;
82+
this.homebrewPublisher = homebrewPublisher;
7083
this.getEvergreenArtifactUrl = getEvergreenArtifactUrl;
7184
this.writeBuildInfo = writeBuildInfo;
7285
this.createAndPublishDownloadCenterConfig =

0 commit comments

Comments
 (0)