Skip to content

Commit c64ae18

Browse files
authored
chore(web): bundle driver with the package CLOUDP-228421 (#5733)
* chore(web): bundle driver with the package * chore: update package-lock after merge * chore(web): always package dist with NODE_ENV=production * chore(web): ensure that component always gets new instance of globalAppRegistry on mount
1 parent d8559b9 commit c64ae18

File tree

25 files changed

+2143
-2550
lines changed

25 files changed

+2143
-2550
lines changed

package-lock.json

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

packages/compass-e2e-tests/helpers/compass.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ export async function startBrowser(
761761
...webdriverOptions,
762762
...wdioOptions,
763763
})) as CompassBrowser;
764-
await browser.navigateTo('http://localhost:8080/');
764+
await browser.navigateTo('http://localhost:7777/');
765765
const compass = new Compass(name, browser, {
766766
mode: 'web',
767767
writeCoverage: false,

packages/compass-web/.depcheckrc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ ignores:
1616
- 'events'
1717
- 'process'
1818
- 'util'
19-
# Already a dependency of mongodb-data-service -> devtools-connect, only
20-
# referenced in webpack for weird polyfilling reasons (see config)
21-
- 'resolve-mongodb-srv'
19+
# Not explicitly used, but helpful to have them in devDeps to make sure
20+
# compass-web is on the same version as other package in the monorepo
21+
- 'mongodb'
22+
- 'bson'
2223
ignore-patterns:
2324
- 'dist'

packages/compass-web/package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,10 @@
5353
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write ."
5454
},
5555
"peerDependencies": {
56-
"bson": "^6.2.0",
57-
"mongodb": "^6.5.0",
5856
"react": "^17.0.2",
5957
"react-dom": "^17.0.2"
6058
},
6159
"devDependencies": {
62-
"@gribnoysup/mongodb-browser": "^1.3.0",
6360
"@mongodb-js/atlas-service": "^0.16.0",
6461
"@mongodb-js/compass-aggregations": "^9.27.0",
6562
"@mongodb-js/compass-app-stores": "^7.11.0",
@@ -94,29 +91,38 @@
9491
"@types/react": "^17.0.5",
9592
"@types/react-dom": "^17.0.10",
9693
"@types/sinon-chai": "^3.2.5",
94+
"browser-process-hrtime": "^1.0.0",
95+
"bson": "^6.2.0",
9796
"buffer": "^6.0.3",
9897
"chai": "^4.3.6",
9998
"compass-preferences-model": "^2.19.0",
99+
"crypto-browserify": "^3.12.0",
100100
"debug": "^4.2.0",
101101
"depcheck": "^1.4.1",
102+
"dns-query": "^0.11.2",
102103
"electron": "^29.3.1",
103104
"eslint": "^7.25.0",
104105
"events": "^3.3.0",
105106
"express": "^4.19.2",
106107
"express-http-proxy": "^2.0.0",
107108
"hadron-app-registry": "^9.1.9",
109+
"is-ip": "^5.0.1",
108110
"mocha": "^10.2.0",
111+
"mongodb": "^6.5.0",
109112
"mongodb-connection-string-url": "^2.6.0",
110113
"mongodb-data-service": "^22.19.0",
111114
"mongodb-log-writer": "^1.3.0",
112115
"nyc": "^15.1.0",
116+
"os-browserify": "^0.3.0",
113117
"path-browserify": "^1.0.1",
114118
"prettier": "^2.7.1",
115119
"process": "^0.11.10",
116120
"readable-stream": "^4.5.0",
117121
"sinon": "^17.0.1",
122+
"timers-browserify": "^2.0.12",
118123
"util": "^0.12.5",
119124
"vm-browserify": "^1.1.2",
120-
"whatwg-url": "^13.0.0"
125+
"whatwg-url": "^13.0.0",
126+
"ws": "^8.16.0"
121127
}
122128
}

packages/compass-web/polyfills/@mongodb-js/compass-connection-import-export/index.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/compass-web/polyfills/crypto/index.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { query, lookupTxt } from 'dns-query';
2+
import { promisify } from 'util';
3+
4+
const dohEndpoints = process.env.COMPASS_WEB_DOH_ENDPOINT ?? [
5+
'dns.google',
6+
'dns.cloudflare.com',
7+
];
8+
9+
export function resolveSrv(
10+
hostname: string,
11+
cb: (err: null | any, answers?: any[]) => void
12+
) {
13+
query(
14+
{ question: { type: 'SRV', name: hostname } },
15+
{ endpoints: dohEndpoints }
16+
).then(({ answers }) => {
17+
const res =
18+
answers?.flatMap((answer) => {
19+
if (answer.type === 'SRV') {
20+
return {
21+
...answer.data,
22+
name: answer.data.target,
23+
};
24+
}
25+
return [];
26+
}) ?? [];
27+
cb(null, res);
28+
}, cb);
29+
}
30+
export function resolveTxt(
31+
hostname: string,
32+
cb: (err: null | any, answers?: string[][]) => void
33+
) {
34+
lookupTxt(hostname, { endpoints: dohEndpoints }).then(({ entries }) => {
35+
const res = entries.map((entry) => {
36+
return [entry.data];
37+
});
38+
cb(null, res);
39+
}, cb);
40+
}
41+
42+
export const promises = {
43+
resolveSrv: promisify(resolveSrv),
44+
resolveTxt: promisify(resolveTxt),
45+
};
46+
47+
export default {
48+
resolveSrv,
49+
resolveTxt,
50+
promises,
51+
};

packages/compass-web/polyfills/fs/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ export const promises = {
22
chmod() {
33
return Promise.resolve();
44
},
5+
access() {
6+
return Promise.reject(new Error('Not supported in browser environment'));
7+
},
8+
readFile() {
9+
return Promise.reject(new Error('Not supported in browser environment'));
10+
},
511
};
612
export function rmSync() {
713
// noop
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { promises } from 'fs';
2+
export default promises;
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import { ipVersion } from 'is-ip';
2+
import { Duplex } from 'stream';
3+
4+
const PROXY_PORT = process.env.COMPASS_WEB_WS_PROXY_PORT
5+
? Number(process.env.COMPASS_WEB_WS_PROXY_PORT)
6+
: 1337;
7+
8+
/**
9+
* net.Socket interface that works over the WebSocket connection. For now, only
10+
* used when running compass-web in a local sandbox, mms has their own
11+
* implementation
12+
*/
13+
class Socket extends Duplex {
14+
private _ws: WebSocket | null = null;
15+
private _setOptions: {
16+
setKeepAlive?: { enabled?: boolean; initialDelay?: number };
17+
setTimeout?: { timeout?: number };
18+
setNoDelay?: { noDelay?: boolean };
19+
} = {};
20+
constructor() {
21+
super();
22+
}
23+
connect(options: { host: string; port: number; tls?: boolean }) {
24+
this._ws = new WebSocket(`ws://localhost:${PROXY_PORT}`);
25+
this._ws.binaryType = 'arraybuffer';
26+
this._ws.addEventListener(
27+
'open',
28+
() => {
29+
const connectMsg = JSON.stringify({
30+
connectOptions: options,
31+
setOptions: this._setOptions,
32+
});
33+
setTimeout(() => {
34+
this._ws?.send(connectMsg);
35+
});
36+
},
37+
{ once: true }
38+
);
39+
this._ws.addEventListener('close', () => {
40+
this.emit('close');
41+
});
42+
this._ws.addEventListener('error', () => {
43+
this.emit('error', 'WebSocket connection was closed due to an error');
44+
});
45+
this._ws.addEventListener(
46+
'message',
47+
({ data }: MessageEvent<string | ArrayBuffer>) => {
48+
if (typeof data === 'string') {
49+
try {
50+
const { evt, error } = JSON.parse(data) as {
51+
evt: string;
52+
error?: Error;
53+
};
54+
setTimeout(() => {
55+
this.emit(
56+
evt,
57+
evt === 'error' ? Object.assign(new Error(), error) : undefined
58+
);
59+
});
60+
} catch (err) {
61+
// eslint-disable-next-line no-console
62+
console.error('error parsing proxy message "%s":', data, err);
63+
}
64+
} else {
65+
setTimeout(() => {
66+
this.emit('data', Buffer.from(data));
67+
});
68+
}
69+
}
70+
);
71+
return this;
72+
}
73+
_read() {
74+
// noop
75+
}
76+
_write(chunk: ArrayBufferLike, _encoding: BufferEncoding, cb: () => void) {
77+
this._ws?.send(chunk);
78+
setTimeout(() => {
79+
cb();
80+
});
81+
}
82+
destroy() {
83+
this._ws?.close();
84+
return this;
85+
}
86+
end(fn?: () => void) {
87+
if (this._ws?.readyState === this._ws?.CLOSED) {
88+
setTimeout(() => {
89+
fn?.();
90+
});
91+
return this;
92+
}
93+
this._ws?.addEventListener(
94+
'close',
95+
() => {
96+
fn?.();
97+
},
98+
{ once: true }
99+
);
100+
this._ws?.close();
101+
return this;
102+
}
103+
setKeepAlive(enabled = false, initialDelay = 0) {
104+
this._setOptions.setKeepAlive = { enabled, initialDelay };
105+
return this;
106+
}
107+
setTimeout(timeout: number, cb?: () => void) {
108+
this._setOptions.setTimeout = { timeout };
109+
if (cb) {
110+
this.once('timeout', cb);
111+
}
112+
return this;
113+
}
114+
setNoDelay(noDelay = true) {
115+
this._setOptions.setNoDelay = { noDelay };
116+
return this;
117+
}
118+
}
119+
120+
export { isIPv4, isIPv6 } from 'is-ip';
121+
export const isIP = (input: string) => ipVersion(input) ?? 0;
122+
export const createConnection = (options: { host: string; port: number }) => {
123+
const socket = new Socket();
124+
setTimeout(() => {
125+
socket.connect(options);
126+
});
127+
return socket;
128+
};

0 commit comments

Comments
 (0)