Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/crazy-jeans-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/rspeedy": patch
---

Fix the "lynx.getJSModule is not a function" error on Web platform
18 changes: 13 additions & 5 deletions packages/rspeedy/core/src/plugins/dev.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import color from 'picocolors'
import type { Dev } from '../config/dev/index.js'
import type { Server } from '../config/server/index.js'
import { debug } from '../debug.js'
import { isLynx } from '../utils/is-lynx.js'
import { ProvidePlugin } from '../webpack/ProvidePlugin.js'

export function pluginDev(
Expand Down Expand Up @@ -147,13 +148,9 @@ export function pluginDev(
)
.end()
.end()
.plugin('lynx.hmr.provide')
.plugin('lynx.hmr.provide.dev_server_client')
.use(ProvidePlugin, [
{
WebSocket: [
options?.client?.websocketTransport ?? require.resolve('@lynx-js/websocket'),
'default',
],
__webpack_dev_server_client__: [
require.resolve(
'./client/hmr/WebSocketClient.js',
Expand All @@ -166,6 +163,17 @@ export function pluginDev(
}
])
.end()
if (isLynx(environment)) {
chain.plugin('lynx.hmr.provide.websocket')
.use(ProvidePlugin, [{
WebSocket: [
options?.client?.websocketTransport
?? require.resolve('@lynx-js/websocket'),
'default',
],
}])
.end()
Comment thread
PupilTong marked this conversation as resolved.
}
})
},
}
Expand Down
29 changes: 27 additions & 2 deletions packages/rspeedy/core/test/plugins/dev.plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ describe('Plugins - Dev', () => {

expect(vi.isMockFunction(ProvidePlugin)).toBe(true)
expect(vi.mocked(ProvidePlugin)).toBeCalled()
expect(ProvidePlugin).toBeCalledWith({
expect(ProvidePlugin).toHaveBeenCalledWith({
WebSocket: [require.resolve('@lynx-js/websocket'), 'default'],
})
expect(ProvidePlugin).toHaveBeenCalledWith({
__webpack_dev_server_client__: [
require.resolve('../../client/hmr/WebSocketClient.js'),
'default',
Expand All @@ -99,6 +101,27 @@ describe('Plugins - Dev', () => {
)
})

test('no Websocket class injected for web', async () => {
const rsbuild = await createStubRspeedy({
environments: {
web: {},
},
})

await rsbuild.unwrapConfig()

const { ProvidePlugin } = await import('../../src/webpack/ProvidePlugin.js')

expect(vi.isMockFunction(ProvidePlugin)).toBe(true)
expect(vi.mocked(ProvidePlugin)).toBeCalled()
expect(ProvidePlugin).toBeCalledWith({
__webpack_dev_server_client__: [
require.resolve('../../client/hmr/WebSocketClient.js'),
'default',
],
})
})
Comment thread
PupilTong marked this conversation as resolved.

test('not inject entry and provide variables in production', async () => {
vi.stubEnv('NODE_ENV', 'production')
const rsbuild = await createStubRspeedy({})
Expand Down Expand Up @@ -501,8 +524,10 @@ describe('Plugins - Dev', () => {

const { ProvidePlugin } = await import('../../src/webpack/ProvidePlugin.js')

expect(ProvidePlugin).toBeCalledWith({
expect(ProvidePlugin).toHaveBeenCalledWith({
WebSocket: ['/foo', 'default'],
})
expect(ProvidePlugin).toHaveBeenCalledWith({
__webpack_dev_server_client__: [
require.resolve('../../client/hmr/WebSocketClient.js'),
'default',
Expand Down
Loading