-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: miniprogram #107
feat: miniprogram #107
Conversation
🦋 Changeset detectedLatest commit: 7972b83 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis update introduces several modifications to the "zxing-wasm" package. It expands the accepted input types for the Changes
Sequence Diagram(s)sequenceDiagram
participant BM as Build-Miniprogram Script
participant R as rimraf Module
participant V as Vite
participant FS as File System
BM->>R: Remove "dist/miniprogram" directory
BM->>V: Invoke Vite build with miniprogram config
V-->>BM: Return build completion
BM->>FS: Write package.json to "dist/miniprogram"
sequenceDiagram
participant U as User
participant RR as readBarcodes Function
U->>RR: Call readBarcodes(input)
alt Input is ArrayBuffer/Uint8Array
RR->>RR: Process as binary data
else Input is Blob
RR->>RR: Convert Blob to ArrayBuffer
else Input is ImageData
RR->>RR: Process ImageData
else
RR->>U: Throw TypeError (invalid input)
end
RR-->>U: Return barcode result
Possibly related PRs
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
commit: |
861f4b6
to
a6ef074
Compare
b7c1847
to
a6ef074
Compare
a6ef074
to
cb62d4f
Compare
cb62d4f
to
86e32f9
Compare
8bcec64
to
bd18e82
Compare
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/share.ts (2)
312-351
: Refine input type checks for typed arrays.Currently, the code checks
"buffer" in input
to identifyUint8Array
, but it may accept other typed arrays unintentionally (e.g.,Float32Array
). Restricting the logic to actualUint8Array
or using aninstanceof
check ensures clarity for consumers and consistent behavior for the WASM module.
405-447
: Polyfill remains incomplete.The minimal Blob polyfill may be sufficient for basic use; however, it lacks support for slicing, streaming, and text reading. If advanced blob capabilities are needed, consider replacing this stub or surfacing a clear error message. I'm happy to help implement a more complete polyfill if needed.
.changeset/pink-tips-unite.md (1)
1-6
: Consider enhancing the changeset message.While the message captures the main feature, it could be more descriptive about the input type changes.
--- "zxing-wasm": minor --- -Support WeChat Mini Program. +Support WeChat Mini Program and expand readBarcodes input types (ArrayBuffer, Uint8Array).README.md (1)
339-362
: Addition of WeChat Mini Program Usage Notes
The new section detailing usage in WeChat mini programs is very useful. However, please consider the following improvements:
Accessibility Improvement: The inline image on line 340 (used as an icon) should include an
alt
attribute to satisfy accessibility standards and markdownlint (MD045). For example, update:-<img src="https://github.com/user-attachments/assets/7d8f3337-dd9c-43ec-aab4-8d4e72d32867" width="16" height="16"> +<img src="https://github.com/user-attachments/assets/7d8f3337-dd9c-43ec-aab4-8d4e72d32867" width="16" height="16" alt="Mini Program Icon">Formatting Detail: There appears to be a blank line within a blockquote (as flagged by markdownlint MD028, possibly around line 341). Consider removing any extraneous blank lines inside the blockquote to ensure consistent formatting.
These are minor nitpicks to improve readability and maintain compliance with style guidelines.
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
340-340: Images should have alternate text (alt text)
null(MD045, no-alt-text)
362-362: Blank line inside blockquote
null(MD028, no-blanks-blockquote)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
tests/samples/qrcode/wikipedia.png
is excluded by!**/*.png
📒 Files selected for processing (10)
.changeset/pink-tips-unite.md
(1 hunks).changeset/pretty-ravens-send.md
(1 hunks)README.md
(2 hunks)package.json
(3 hunks)scripts/build-cjs.ts
(1 hunks)scripts/build-miniprogram.ts
(1 hunks)src/full/index.ts
(1 hunks)src/reader/index.ts
(1 hunks)src/share.ts
(6 hunks)tests/unit.test.ts
(2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md
340-340: Images should have alternate text (alt text)
null
(MD045, no-alt-text)
362-362: Blank line inside blockquote
null
(MD028, no-blanks-blockquote)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: preview-release
- GitHub Check: test
- GitHub Check: preview-release
🔇 Additional comments (13)
src/share.ts (3)
86-130
: Consider verifying environment detection and behavior for non-Vite setups.You're relying on
import.meta.env.MODE
andimport.meta.env.PROD
to detect the runtime environment, throwing an error for Mini Program users. While this is valid in many Vite-based projects, ensure it's clearly documented that a build system supplying these variables is mandatory. Otherwise, fallback logic or environment checks outside of Vite might be needed to provide a smooth developer experience.
290-290
: Good documentation update.Expanding the docstring to reference all supported input types simplifies onboarding for new developers.
300-300
: Expanded parameter types look correct.Allowing
Blob | ArrayBuffer | Uint8Array | ImageData
in the signature aligns with the doc comment and broadens input compatibility.scripts/build-cjs.ts (1)
2-7
: Pre-build cleanup is a solid step.Using
rimraf
to remove the olddist/cjs
directory helps prevent conflicts with stale artifacts. This is a best practice to ensure a clean build output.scripts/build-miniprogram.ts (1)
1-42
: New miniprogram build step looks good.Defining a dedicated build process with a distinct
mode: "miniprogram"
and output directory provides clarity and maintainability. Note that outputting CommonJS may remain necessary for now, but consider verifying future compatibility in case the WeChat environment evolves to support ESM natively.src/reader/index.ts (1)
75-80
: LGTM! Input type expansion enhances compatibility.The expansion of input types to include
ArrayBuffer
andUint8Array
improves compatibility with various environments, particularly WeChat Mini Program, while maintaining backward compatibility.src/full/index.ts (1)
76-81
: LGTM! Consistent type expansion across modules.The input type expansion matches the changes in reader/index.ts, maintaining API consistency between the full and reader modules.
tests/unit.test.ts (1)
189-246
: LGTM! Comprehensive test coverage for all input types.Excellent test suite that:
- Covers all supported input types (ArrayBuffer, Blob, File, Uint8Array, ImageData)
- Uses real QR code data
- Verifies both result presence and content accuracy
.changeset/pretty-ravens-send.md (1)
1-6
: Changeset Format Looks Good
The changeset correctly describes the update ("AcceptArrayBuffer
andUint8Array
as input types inreadBarcodes
") and uses the expected format.package.json (3)
12-12
: New Miniprogram Export Entry Added
The new"miniprogram": "./dist/miniprogram"
export entry is properly added. This aligns with introducing a dedicated build for WeChat mini programs.
175-176
: Integration of Miniprogram Build Process
The addition of the"build:miniprogram": "tsx ./scripts/build-miniprogram.ts"
script and its integration into the overall"build"
command ensures the miniprogram output is built alongside other modules. Please verify that the referenced script (scripts/build-miniprogram.ts
) exists and works as expected.
194-194
: New Dev Dependency Added
The new dev dependency"@napi-rs/canvas": "^0.1.67"
appears to support additional miniprogram or graphics-related functionality. Ensure that it is compatible with your project and that its inclusion is well documented in any relevant project documentation.README.md (1)
133-133
: Updated Documentation forreadBarcodes
Input Types
The documentation now reflects thatreadBarcodes
acceptsArrayBuffer
andUint8Array
along with other types. This is clear and informative for users.
Summary by CodeRabbit
New Features
Documentation
Tests