-
Notifications
You must be signed in to change notification settings - Fork 109
feat: enhance QR code plugin with web environment support and middleware integration #1816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PupilTong
wants to merge
1
commit into
lynx-family:main
Choose a base branch
from
PupilTong:p/hw/web-qrcode-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+168
−67
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| "@lynx-js/qrcode-rsbuild-plugin": patch | ||
| --- | ||
|
|
||
| feat: support web platform preview | ||
|
|
||
| use rspeedy settings to enable Lynx Web Platform preview | ||
|
|
||
| ```js | ||
| // rspeedy configurations | ||
| environments:{ | ||
| web:{}, | ||
| lynx:{} | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
|
|
||
| import type { EnvironmentContext, RsbuildPlugin } from '@rsbuild/core' | ||
|
|
||
| import { createWebVirtualFilesMiddleware } from '@lynx-js/web-rsbuild-server-middleware' | ||
|
|
||
| import { registerConsoleShortcuts } from './shortcuts.js' | ||
|
|
||
| /** | ||
|
|
@@ -101,8 +103,13 @@ export function pluginQRCode( | |
| name: 'lynx:rsbuild:qrcode', | ||
| pre: ['lynx:rsbuild:api'], | ||
| setup(api) { | ||
| api.onBeforeStartDevServer(({ environments, server }) => { | ||
| if (environments['web']) { | ||
| server.middlewares.use(createWebVirtualFilesMiddleware('/web')) | ||
| } | ||
| }) | ||
| api.onAfterStartProdServer(async ({ environments, port }) => { | ||
| await main(environments['lynx'], port) | ||
| await main(environments, port) | ||
| }) | ||
|
|
||
| let printedQRCode = false | ||
|
|
@@ -122,7 +129,7 @@ export function pluginQRCode( | |
|
|
||
| printedQRCode = true | ||
|
|
||
| await main(environments['lynx'], api.context.devServer.port) | ||
| await main(environments, api.context.devServer.port) | ||
| }) | ||
|
|
||
| api.modifyRsbuildConfig((config) => { | ||
|
|
@@ -138,23 +145,20 @@ export function pluginQRCode( | |
| }) | ||
|
|
||
| async function main( | ||
| environmentContext: EnvironmentContext | undefined, | ||
| environments: Record<string, EnvironmentContext>, | ||
| port: number, | ||
| ) { | ||
| if (!environmentContext) { | ||
| // Not lynx environment, skip print QRCode | ||
| return | ||
| } | ||
|
|
||
| const entries = Object.keys(environmentContext.entry) | ||
|
|
||
| if (entries.length === 0) { | ||
| const lynxEntries = Object.keys(environments['lynx']?.entry ?? {}) | ||
| const webEntries = Object.keys(environments['web']?.entry ?? {}) | ||
| if (lynxEntries.length === 0 && webEntries.length === 0) { | ||
| // Not lynx or web environment, skip print | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: the comment does not match the condition. |
||
| return | ||
| } | ||
|
|
||
| const unregister = await registerConsoleShortcuts( | ||
| { | ||
| entries, | ||
| entries: lynxEntries, | ||
| webEntries, | ||
| api, | ||
| port, | ||
| schema, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Fix missing dependency/exports for web middleware import
Type-check fails: Cannot find module '@lynx-js/web-rsbuild-server-middleware'. Ensure the package is part of the workspace, exported correctly, and added as a dependency of this plugin. If the package exposes a node entry, import it explicitly.
Apply one of:
Or add dependency and proper exports/types to the workspace package.
Run this script to verify dependency wiring and exports:
🏁 Script executed:
Length of output: 225
Expose a node entry and type declarations from @lynx-js/web-rsbuild-server-middleware
🧰 Tools
🪛 GitHub Check: code-style-check
[failure] 13-13:
Cannot find module '@lynx-js/web-rsbuild-server-middleware' or its corresponding type declarations.
🤖 Prompt for AI Agents