Skip to content

Commit 5a26679

Browse files
nbbeekengribnoysup
andauthored
fix(compass-web): bundle type definitions COMPASS-9733 (#7227)
Co-authored-by: Sergey Petushkov <[email protected]>
1 parent 1d36e9c commit 5a26679

File tree

15 files changed

+815
-12
lines changed

15 files changed

+815
-12
lines changed

package-lock.json

Lines changed: 631 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-connections/src/stores/store-context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function getConnectionsActions(dispatch: ConnectionsStore['dispatch']) {
117117
return dispatch(saveEditedConnectionInfo(connectionInfo));
118118
},
119119
cancelEditConnection: (connectionId: ConnectionId) => {
120-
return dispatch(cancelEditConnection(connectionId));
120+
dispatch(cancelEditConnection(connectionId));
121121
},
122122
toggleFavoritedConnectionStatus: (connectionId: ConnectionId) => {
123123
return dispatch(toggleConnectionFavoritedStatus(connectionId));

packages/compass-web/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.nyc-output
22
dist
3+
test/types
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3+
"mainEntryPointFilePath": "./dist/index.d.ts",
4+
"newlineKind": "lf",
5+
"bundledPackages": [
6+
"@mongodb-js/*",
7+
"@mongodb-js/mdb-experiment-js",
8+
"@mongodb-js/connection-info",
9+
"bson-transpilers",
10+
"compass-e2e-tests",
11+
"compass-preferences-model",
12+
"hadron-build",
13+
"hadron-document",
14+
"hadron-ipc",
15+
"hadron-type-checker",
16+
"mongodb-instance-model",
17+
"mongodb-explain-compat",
18+
"mongodb-query-util",
19+
"mongodb-data-service",
20+
"mongodb-database-model",
21+
"mongodb-collection-model",
22+
"mongodb-compass"
23+
],
24+
"compiler": {
25+
"tsconfigFilePath": "./tsconfig-build.json"
26+
},
27+
"dtsRollup": {
28+
"enabled": true,
29+
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
30+
},
31+
"apiReport": {
32+
"enabled": false
33+
},
34+
"docModel": {
35+
"enabled": false
36+
}
37+
}

packages/compass-web/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@
3333
".": "./src/index.tsx",
3434
"./package.json": "./package.json"
3535
},
36-
"types": "./dist/index.d.ts",
36+
"types": "./dist/compass-web.d.ts",
3737
"scripts": {
38+
"bootstrap": "npm run postcompile",
3839
"prepublishOnly": "npm run compile && compass-scripts check-exports-exist",
3940
"compile": "npm run webpack -- --mode production",
4041
"webpack": "webpack-compass",
4142
"postcompile": "npm run typescript",
4243
"typescript": "tsc -p tsconfig-build.json --emitDeclarationOnly",
44+
"posttypescript": "npm run api-extractor",
45+
"api-extractor": "api-extractor run --local",
46+
"postapi-extractor": "node scripts/clean-dts.mjs",
47+
"test-types": "cd test/types && npm install && npm test",
4348
"prestart": "npm run compile -w @mongodb-js/webpack-config-compass",
4449
"start": "electron ./scripts/electron-proxy.js",
4550
"analyze": "npm run webpack -- --mode production --analyze",
@@ -51,6 +56,7 @@
5156
"lint": "npm run eslint . && npm run prettier -- --check .",
5257
"depcheck": "depcheck",
5358
"check": "npm run typecheck && npm run lint && npm run depcheck",
59+
"postcheck": "npm run test-types",
5460
"check-ci": "npm run check",
5561
"test": "mocha",
5662
"test-cov": "nyc --compact=false --produce-source-map=false -x \"**/*.spec.*\" --reporter=lcov --reporter=text --reporter=html npm run test",
@@ -63,6 +69,7 @@
6369
"react-dom": "^17.0.2"
6470
},
6571
"devDependencies": {
72+
"@microsoft/api-extractor": "^7.52.11",
6673
"@mongodb-js/atlas-service": "^0.56.0",
6774
"@mongodb-js/compass-aggregations": "^9.73.0",
6875
"@mongodb-js/compass-app-registry": "^9.4.20",
@@ -88,6 +95,7 @@
8895
"@mongodb-js/compass-telemetry": "^1.14.0",
8996
"@mongodb-js/compass-welcome": "^0.69.0",
9097
"@mongodb-js/compass-workspaces": "^0.52.0",
98+
"@mongodb-js/connection-info": "^0.17.2",
9199
"@mongodb-js/connection-storage": "^0.46.0",
92100
"@mongodb-js/devtools-proxy-support": "^0.5.2",
93101
"@mongodb-js/eslint-config-compass": "^1.4.7",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
3+
import fs from 'node:fs/promises';
4+
import path from 'node:path';
5+
import url from 'node:url';
6+
7+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
8+
const distDir = path.join(__dirname, '..', 'dist');
9+
10+
await Promise.all(
11+
(
12+
await fs.readdir(distDir)
13+
)
14+
.filter((file) => file.endsWith('.d.ts') || file.endsWith('.d.ts.map'))
15+
.filter((file) => file !== 'compass-web.d.ts')
16+
.map((file) => fs.unlink(path.join(distDir, file)))
17+
);

packages/compass-web/src/entrypoint.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import AppRegistry, {
33
AppRegistryProvider,
44
GlobalAppRegistryProvider,
55
} from '@mongodb-js/compass-app-registry';
6-
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
6+
import type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
77
import { useConnectionActions } from '@mongodb-js/compass-connections/provider';
88
import { CompassInstanceStorePlugin } from '@mongodb-js/compass-app-stores';
9-
import type { OpenWorkspaceOptions } from '@mongodb-js/compass-workspaces';
9+
import type {
10+
CollectionTabInfo,
11+
OpenWorkspaceOptions,
12+
WorkspaceTab,
13+
} from '@mongodb-js/compass-workspaces';
1014
import WorkspacesPlugin, {
1115
WorkspacesProvider,
1216
} from '@mongodb-js/compass-workspaces';
@@ -63,6 +67,7 @@ import {
6367
CompassAssistantProvider,
6468
} from '@mongodb-js/compass-assistant';
6569

70+
/** @public */
6671
export type TrackFunction = (
6772
event: string,
6873
properties: Record<string, any>
@@ -91,7 +96,8 @@ type CompassWorkspaceProps = Pick<
9196
'onOpenConnectViaModal'
9297
>;
9398

94-
type CompassWebProps = {
99+
/** @public */
100+
export type CompassWebProps = {
95101
/**
96102
* App name to be passed with the connection string when connection to a
97103
* cluster (default: "Compass Web")
@@ -131,9 +137,12 @@ type CompassWebProps = {
131137
* communicate current workspace back to the parent component for example to
132138
* sync router with the current active workspace
133139
*/
134-
onActiveWorkspaceTabChange: React.ComponentProps<
135-
typeof WorkspacesPlugin
136-
>['onActiveWorkspaceTabChange'];
140+
onActiveWorkspaceTabChange<WS extends WorkspaceTab>(
141+
ws: WS | null,
142+
collectionInfo: WS extends { type: 'Collection' }
143+
? CollectionTabInfo | null
144+
: never
145+
): void;
137146

138147
/**
139148
* Set of initial preferences to override default values
@@ -159,9 +168,7 @@ type CompassWebProps = {
159168
* when the action is selected from the sidebar actions. Should be used to
160169
* show the Atlas Cloud "Connect" modal
161170
*/
162-
onOpenConnectViaModal?: (
163-
atlasMetadata: ConnectionInfo['atlasMetadata']
164-
) => void;
171+
onOpenConnectViaModal?: (atlasMetadata?: AtlasClusterMetadata) => void;
165172

166173
/**
167174
* Callback prop called when connections fail to load
@@ -259,6 +266,7 @@ const connectedContainerStyles = css({
259266
display: 'flex',
260267
});
261268

269+
/** @public */
262270
const CompassWeb = ({
263271
appName,
264272
orgId,

packages/compass-web/src/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
export { CompassWeb } from './entrypoint';
2+
export type { CompassWebProps, TrackFunction } from './entrypoint';
23
export * from './url-builder';
34
export type {
45
OpenWorkspaceOptions,
56
WorkspaceTab,
67
} from '@mongodb-js/compass-workspaces';
78

89
export { CompassExperimentationProvider } from '@mongodb-js/compass-telemetry';
10+
11+
export type { CollectionTabInfo } from '@mongodb-js/compass-workspaces';
12+
export type { AllPreferences } from 'compass-preferences-model/provider';
13+
export type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
14+
export type { LogFunction, LogMessage, DebugFunction } from './logger';

packages/compass-web/src/logger.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Writable } from 'stream';
44
import { mongoLogId } from '@mongodb-js/compass-logging/provider';
55
import { useRef } from 'react';
66

7+
/** @public */
78
export type LogMessage = {
89
id: number;
910
t: { $date: string };
@@ -13,8 +14,11 @@ export type LogMessage = {
1314
msg: string;
1415
attr?: any;
1516
};
17+
18+
/** @public */
1619
export type LogFunction = (message: LogMessage) => void;
1720

21+
/** @public */
1822
export type DebugFunction = (...args: any[]) => void;
1923

2024
type Debugger = Logger['debug'];

packages/compass-web/src/url-builder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ function getRouteFromCollectionSubTab(subTab: CollectionSubtab): string {
4949
}
5050
}
5151

52+
/** @public */
5253
export function getWorkspaceTabFromRoute(
5354
route: string
5455
): OpenWorkspaceOptions | null {
@@ -85,6 +86,7 @@ function buildAbsoluteURL(...parts: string[]) {
8586
);
8687
}
8788

89+
/** @public */
8890
export function getRouteFromWorkspaceTab(tab: WorkspaceTab | null) {
8991
let route: string;
9092
switch (tab?.type) {

0 commit comments

Comments
 (0)