Skip to content

Commit

Permalink
Fix failed dependency and type error
Browse files Browse the repository at this point in the history
  • Loading branch information
yhatt committed Feb 17, 2025
1 parent 6edae7e commit da61806
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
40 changes: 15 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"fast-plist": "^0.1.3",
"get-stdin": "^9.0.0",
"globals": "^15.15.0",
"globby": "^14.1.0",
"globby": "~14.0.2",
"image-size": "^1.2.0",
"import-from": "^4.0.0",
"import-meta-resolve": "^4.1.0",
Expand Down
7 changes: 4 additions & 3 deletions src/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import crypto from 'node:crypto'
import path from 'node:path'
import { watch as chokidarWatch, type FSWatcher } from 'chokidar'
import { getPortPromise } from 'portfinder'
import WS, { type ServerOptions } from 'ws'
import { WebSocketServer } from 'ws'
import type { ServerOptions } from 'ws'
import { Converter, ConvertedCallback } from './converter'
import { isError } from './error'
import { File, FileType } from './file'
Expand Down Expand Up @@ -82,7 +83,7 @@ export class Watcher {
export class WatchNotifier {
listeners = new Map<string, Set<any>>()

private wss?: WS.Server
private wss?: WebSocketServer
private portNumber?: number

async port() {
Expand Down Expand Up @@ -112,7 +113,7 @@ export class WatchNotifier {
}

async start(opts: ServerOptions = {}) {
this.wss = new WS.Server({ ...opts, port: await this.port() })
this.wss = new WebSocketServer({ ...opts, port: await this.port() })
this.wss.on('connection', (ws, sock) => {
if (sock.url) {
const [, identifier] = sock.url.split('/')
Expand Down
10 changes: 6 additions & 4 deletions test/templates/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
*/
import { getPortPromise } from 'portfinder'
import ws from 'ws'
import { WebSocketServer } from 'ws'
import watch from '../../src/templates/watch/watch'

beforeEach(() => {
Expand All @@ -12,16 +12,18 @@ beforeEach(() => {
})

describe('Watch mode notifier on browser context', () => {
let server: ws.Server
let server: WebSocketServer
let infoSpy: jest.SpyInstance
let warnSpy: jest.SpyInstance

const createWSServer = async () => {
const port = await getPortPromise({ port: 37717 })

return new Promise<ws.Server>((res, rej) => {
return new Promise<WebSocketServer>((res, rej) => {
try {
const createdServer = new ws.Server({ port }, () => res(createdServer))
const createdServer = new WebSocketServer({ port }, () =>
res(createdServer)
)
} catch (e) {
rej(e)
}
Expand Down

0 comments on commit da61806

Please sign in to comment.