Skip to content

Commit 246501c

Browse files
authored
chore: bundle the browser and node entry points for packages/socket (#32726)
1 parent 4d904e2 commit 246501c

File tree

41 files changed

+196
-137
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+196
-137
lines changed

guides/esm-migration.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
#### Notes
1414

15-
When migrating some of these projects away from the `ts-node` entry [see `@packages/scaffold-config` example](https://github.com/cypress-io/cypress/blob/v15.2.0/packages/scaffold-config/index.js), it is somewhat difficult to make separate browser/node entries as the v8-snapshot [tsconfig.json](https://github.com/cypress-io/cypress/blob/v15.2.0/tooling/v8-snapshot/tsconfig.json) is using an older style of module resolution where the `exports` key inside a package's `package.json` is not well supported. Because of this, we need to find ways to bundle code that is needed internally in the browser vs in node without them being a part of the same bundle. This is a temporary work around until we are able to get every package being able to build as an ES Module, which as that point we can re assess how the Cypress binary is being built as well as v8-snapshots, and will allow us to reconfigure this packages to export content in a more proper fashion.
15+
When migrating some of these projects away from the `ts-node` entry [see `@packages/scaffold-config` example](https://github.com/cypress-io/cypress/blob/v15.2.0/packages/scaffold-config/index.js), it is somewhat difficult to make separate browser/node entries as the v8-snapshot [tsconfig.json](https://github.com/cypress-io/cypress/blob/v15.2.0/tooling/v8-snapshot/tsconfig.json) is using an older style of module resolution where the `exports` key inside a package's `package.json` is not well supported. Because of this, we need to find ways to bundle code that is needed internally in the browser vs in node without them being a part of the same bundle. This is a temporary work around until we are able to get every package being able to build as an ES Module, which as that point we can re assess how the Cypress binary is being built as well as v8-snapshots, and will allow us to reconfigure this packages to export content in a more proper fashion. We are currently doing something similar in the following packages:
16+
17+
* `@packages/scaffold-config`
18+
* `@packages/socket`
19+
* `@packages/telemetry`
1620

1721
#### Status
1822

@@ -63,7 +67,7 @@ When migrating some of these projects away from the `ts-node` entry [see `@packa
6367
- [x] packages/runner ✅ **COMPLETED**
6468
- [x] packages/scaffold-config ✅ **COMPLETED**
6569
- [ ] packages/server **PARTIAL** - many source/test files in JS. highest priority
66-
- [ ] packages/socket **PARTIAL** - entry point is JS. Tests are JS
70+
- [x] packages/socket **COMPLETED**
6771
- [x] packages/stderr-filtering ✅ **COMPLETED**
6872
- [x] packages/telemetry ✅ **COMPLETED**
6973
- [ ] packages/ts **PARTIAL** - ultimate goal is removal and likely not worth the effort to convert

packages/app/cypress/component/support/ctSupport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AutIframe } from '../../../src/runner/aut-iframe'
22
import { EventManager } from '../../../src/runner/event-manager'
3-
import type { Socket } from '@packages/socket/lib/browser'
3+
import type { Socket } from '@packages/socket/browser/client'
44

55
export const StubWebsocket = new Proxy<Socket>(Object.create(null), {
66
get: (obj, prop) => {

packages/app/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="../driver/types/internal-types-lite.d.ts" />
22

3-
import type { SocketShape } from '@packages/socket/lib/types'
3+
import type { SocketShape } from '@packages/socket/browser/client'
44
import type MobX from 'mobx'
55
import type { EventManager } from './src/runner/event-manager'
66

packages/app/src/runner/event-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { LocalBusEmitsMap, LocalBusEventMap, DriverToLocalBus, SocketToDriv
77
import type { RunState, CachedTestState, AutomationElementId, FileDetails, ReporterStartInfo, ReporterRunState } from '@packages/types'
88

99
import { logger } from './logger'
10-
import type { SocketShape } from '@packages/socket/lib/types'
10+
import type { SocketShape } from '@packages/socket/browser/client'
1111
import { automation, useRunnerUiStore, useSpecStore } from '../store'
1212
import { useScreenshotStore } from '../store/screenshot-store'
1313
import { useStudioStore } from '../store/studio-store'

packages/app/src/runner/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { getRunnerElement, empty } from './utils'
2222
import { IframeModel } from './iframe-model'
2323
import { AutIframe } from './aut-iframe'
2424
import { EventManager } from './event-manager'
25-
import { createWebsocket as createWebsocketIo } from '@packages/socket/lib/browser'
25+
import { createWebsocket as createWebsocketIo } from '@packages/socket/browser/client'
2626
import type { AutomationElementId } from '@packages/types'
2727
import { useSnapshotStore } from './snapshot-store'
2828
import { useStudioStore } from '../store/studio-store'

packages/data-context/src/actions/ServersActions.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import util from 'util'
22

33
import type { AddressInfo } from 'net'
44
import type { Server } from 'http'
5-
import type { SocketIONamespace, SocketIOServer } from '@packages/socket'
5+
import type { SocketIONamespace, SocketIOServer, CDPSocketServer } from '@packages/socket'
66
import type { DataContext } from '..'
7-
import type { CDPSocketServer } from '@packages/socket/lib/cdp-socket'
87

98
export class ServersActions {
109
constructor (private ctx: DataContext) {}

packages/data-context/src/data/coreDataShape.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import type { NexusGenObjects } from '../gen/nxs.gen'
44
// tslint:disable-next-line no-implicit-dependencies - electron dep needs to be defined
55
import type { App, BrowserWindow } from 'electron'
66
import type { ChildProcess } from 'child_process'
7-
import type { SocketIONamespace, SocketIOServer } from '@packages/socket'
7+
import type { SocketIONamespace, SocketIOServer, CDPSocketServer } from '@packages/socket'
88
import type { Server } from 'http'
99
import type { ErrorWrapperSource } from '@packages/errors'
1010
import type { EventCollectorSource, GitDataSource } from '../sources'
1111
import { machineId as getMachineId } from 'node-machine-id'
12-
import type { CDPSocketServer } from '@packages/socket/lib/cdp-socket'
1312

1413
export type Maybe<T> = T | null | undefined
1514

packages/extension/app/v2/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { client } from '@packages/socket/lib/browser'
1+
import { client } from '@packages/socket/browser/client'
22

33
export const connect = (host, path, extraOpts = {}) => {
44
return client(host, {

packages/extension/test/integration/v2/background_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require('../../spec_helper')
33
const _ = require('lodash')
44
const http = require('http')
5-
const socket = require('@packages/socket')
5+
const { SocketIOServer } = require('@packages/socket')
66
const mockRequire = require('mock-require')
77
const client = require('../../../app/v2/client')
88

@@ -38,7 +38,7 @@ describe('app/background', () => {
3838
global.window = {}
3939

4040
this.httpSrv = http.createServer()
41-
this.server = socket.server(this.httpSrv, { path: '/__socket' })
41+
this.server = new SocketIOServer(this.httpSrv, { path: '/__socket' })
4242

4343
const ws = {
4444
on: sinon.stub(),

packages/frontend-shared/src/graphql/urqlClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
} from '@urql/core'
1111
import { devtoolsExchange } from '@urql/devtools'
1212
import { useToast } from 'vue-toastification'
13-
import type { SocketShape } from '@packages/socket/lib/types'
14-
import { client } from '@packages/socket/lib/browser'
13+
import type { SocketShape } from '@packages/socket/browser/client'
14+
import { client } from '@packages/socket/browser/client'
1515
import { createClient as createWsClient } from 'graphql-ws'
1616

1717
import { cacheExchange as graphcacheExchange } from '@urql/exchange-graphcache'

0 commit comments

Comments
 (0)